EnglishРусский  

   ..

   clipboard.g

Данный проект закрыт! Создан новый скриптовый язык с тем же именем. Всё доступно на GitHub.
Также попробуйте нашу open source кроссплатформенную программу для создания и управления скриптами.

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\lib\clipboard\clipboard.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2008, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * Author: Alexey Krivonogov ( gentee )
 11 *
 12 ******************************************************************************/
 13 
 14 /*-----------------------------------------------------------------------------
 15 * Id: clipboard L "Clipboard"
 16 * 
 17 * Summary: These functions are used to work with the Windows clipboard. 
 18            For using this library, it is
 19            required to specify the file clipboard.g (from lib\clipboard
 20            subfolder) with include command. #srcg[
 21 |include : $"...\gentee\lib\clipboard\clipboard.g"]   
 22 *
 23 * List: *,clipboard_gettext,clipboard_empty,clipboard_settext,
 24         *#lng/methods#,buf_getclip,buf_setclip,str_getclip,str_setclip,
 25         ustr_getclip,ustr_setclip
 26 * 
 27 -----------------------------------------------------------------------------*/
 28 
 29 define <export>
 30 {
 31    CF_TEXT            = 1
 32    CF_BITMAP          = 2
 33    CF_METAFILEPICT    = 3
 34    CF_SYLK            = 4
 35    CF_DIF             = 5
 36    CF_TIFF            = 6
 37    CF_OEMTEXT         = 7
 38    CF_DIB             = 8
 39    CF_PALETTE         = 9
 40    CF_UNICODETEXT     = 13   
 41    CF_LOCALE          = 16
 42 }
 43 
 44 define
 45 {
 46    GMEM_FIXED         = 0x0000
 47    GMEM_MOVEABLE      = 0x0002
 48    GMEM_NOCOMPACT     = 0x0010
 49    GMEM_NODISCARD     = 0x0020
 50    GMEM_ZEROINIT      = 0x0040
 51    GMEM_MODIFY        = 0x0080
 52    GMEM_DISCARDABLE   = 0x0100
 53 }
 54 
 55 import "kernel32.dll"
 56 {
 57    uint GlobalAlloc( uint, uint )
 58    uint GlobalFree( uint )
 59    uint GlobalLock( uint )
 60    uint GlobalSize( uint )
 61    uint GlobalUnlock( uint )
 62    uint GetUserDefaultLCID()
 63 }
 64 
 65 import "user32.dll" 
 66 {
 67  	uint  CloseClipboard( )
 68    uint  EmptyClipboard( )
 69    uint  GetClipboardData( uint )
 70    uint  OpenClipboard( uint )
 71    uint  SetClipboardData( uint, uint )
 72 }
 73 
 74 /*-----------------------------------------------------------------------------
 75 * Id: buf_getclip F2
 76 * 
 77 * Summary: Copy the clipboard data to buf variable.
 78 *  
 79 * Params: cftype - The type of the clipboard data.
 80 *
 81 * Return: #lng/retf# 
 82 *
 83 -----------------------------------------------------------------------------*/
 84 
 85 method uint buf.getclip( uint cftype )
 86 {
 87    uint hmem ptr len ret
 88    		
 89 	OpenClipboard( 0 )
 90    
 91    if hmem = GetClipboardData( cftype )
 92    {
 93       len = GlobalSize( hmem )   
 94       ptr = GlobalLock( hmem )      
 95       this.copy( ptr, len )
 96       GlobalUnlock( ptr )      
 97    }
 98    CloseClipboard( )
 99    return hmem
100 }
101 
102 /*-----------------------------------------------------------------------------
103 * Id: str_getclip F3
104 * 
105 * Summary: Copy the clipboard data to str variable if the clipboard contains 
106            text data.
107 *  
108 * Return: #lng/retf# 
109 *
110 -----------------------------------------------------------------------------*/
111 
112 method uint str.getclip()
113 {
114    return this.getclip( $CF_TEXT )
115 }
116 
117 /*-----------------------------------------------------------------------------
118 * Id: clipboard_gettext F
119 *
120 * Summary: Gets a string from the clipboard.
121 *
122 * Params: data - Result string.    
123 *  
124 * Return: #lng/retpar( data ) 
125 *
126 -----------------------------------------------------------------------------*/
127 func str clipboard_gettext( str data )
128 {
129    data.getclip()
130    return data
131 }
132 
133 /*-----------------------------------------------------------------------------
134 * Id: clipboard_empty F1
135 *
136 * Summary: Clear the clipboard.
137 *
138 * Return: #lng/retf# 
139 *
140 -----------------------------------------------------------------------------*/
141 
142 func uint clipboard_empty
143 {
144    if OpenClipboard( 0 )
145    {
146       EmptyClipboard()
147       CloseClipboard()
148       return 1
149    }
150    return 0
151 }
152 
153 /*-----------------------------------------------------------------------------
154 * Id: ustr_getclip F3
155 * 
156 * Summary: Copy the clipboard data to unicode str variable if the clipboard 
157            contains unicode text data.
158 *  
159 * Return: #lng/retf# 
160 *
161 -----------------------------------------------------------------------------*/
162 
163 method uint ustr.getclip()
164 {
165    return this.getclip( $CF_UNICODETEXT )
166 }
167 
168 /*-----------------------------------------------------------------------------
169 * Id: buf_setclip F2
170 * 
171 * Summary: Copy the data of the buf variable to the clipboard.
172 *  
173 * Params: cftype - The type of the buf data.
174           locale - Locale identifier. It can be 0.
175 *
176 * Return: #lng/retf# 
177 *
178 -----------------------------------------------------------------------------*/
179 
180 method uint buf.setclip( uint cftype locale )
181 {
182    uint ret
183    uint hmem ptr hmeml
184    
185 	if !OpenClipboard( 0 ) : return 0
186    hmem = GlobalAlloc( $GMEM_MOVEABLE, *this )
187    hmeml = GlobalAlloc( $GMEM_MOVEABLE, 4 )
188    if hmem && hmeml
189    {   
190       ptr = GlobalLock( hmem )      
191       mcopy( ptr, this.ptr(), *this )
192       EmptyClipboard( )
193       if ( locale )
194       {  
195          GlobalLock( hmeml )->uint = locale
196          SetClipboardData( $CF_LOCALE, hmeml )
197       }
198       ret = SetClipboardData( cftype, hmem )
199    }
200    GlobalUnlock( hmeml )   
201    GlobalUnlock( hmem )      
202 	CloseClipboard( )	
203    return ret
204 }
205 
206 /*-----------------------------------------------------------------------------
207 * Id: str_setclip F3
208 * 
209 * Summary: Copy a string to the clipboard.
210 *  
211 * Return: #lng/retf# 
212 *
213 -----------------------------------------------------------------------------*/
214 
215 method uint str.setclip()
216 {
217    return this->buf.setclip( $CF_TEXT, GetUserDefaultLCID() )   
218 }
219 
220 /*-----------------------------------------------------------------------------
221 * Id: clipboard_settext F
222 *
223 * Summary: Copies a string into the clipboard.
224 *
225 * Params: data - The string for copying into the clipboard.    
226 *  
227 * Return: #lng/retf# 
228 *
229 -----------------------------------------------------------------------------*/
230 
231 func uint clipboard_settext( str data )
232 {
233    return data.setclip()      
234 }
235 
236 /*-----------------------------------------------------------------------------
237 ** Id: ustr_setclip F3
238 * 
239 * Summary: Copy a unicode string to the clipboard.
240 *  
241 * Return: #lng/retf# 
242 *
243 -----------------------------------------------------------------------------*/
244 
245 method uint ustr.setclip()
246 {
247    return this->buf.setclip( $CF_UNICODETEXT, GetUserDefaultLCID() ) 
248 }
249 
250 
251 
252 
Редактировать