1 /******************************************************************************
2 *
3 * Copyright (C) 2004-2007, 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 * ID: vis.edit 17.07.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 /* Компонента vEdit, порождена от vCtrl
17 События
18 onChange - изменение текста
19 */
20 type vEdit <inherit = vCtrl>
21 {
22 //Hidden fields
23 uint fNewText
24 uint pBorder
25 uint pChanged
26 uint pReadOnly
27 ustr pText
28 uint pPassword
29 uint pMaxLen
30 uint pMultiline
31 uint pWordWrap
32 uint pScrollBars
33
34 //Events
35 evEvent OnChange
36 }
37
38
39 define {
40 //Режим отображения полос прокрутки ScrollBars
41 sbNone = 0
42 sbHorz = 1
43 sbVert = 2
44 sbBoth = 3
45 }
46
47 /*------------------------------------------------------------------------------
48 Public methods
49 */
50
51 /*Метод Sel( uint start, uint len )
52 Выделить часть текста
53 start - позизия начала выделения
54 len - длина выделения в символах
55 */
56 method vEdit.Sel( uint start, uint len )
57 {
58 this.WinMsg( $EM_SETSEL, start, start + len )
59 }
60
61 /*Метод SelAll()
62 Выделить весь текст
63 */
64 method vEdit.SelAll()
65 {
66 this.Sel( 0, -1 )
67 }
68
69
70 /*------------------------------------------------------------------------------
71 Properties
72 */
73 /* Свойство uint ReadOnly - Get Set
74 Усотанавливает или определяет можно ли изменять текст
75 1 - текст изменять нельзя
76 0 - текст изменять можно
77 */
78 property uint vEdit.ReadOnly
79 {
80 return this.pReadOnly
81 }
82
83 property vEdit.ReadOnly( uint val )
84 {
85 if val != this.pReadOnly
86 {
87 this.pReadOnly = 1
88 this.WinMsg( $EM_SETREADONLY, val )
89 }
90 }
91
92 /*Свойство ustr Text - Get Set
93 Получить, установить редактируемый текст
94 */
95 method vEdit.iSetText()
96 {
97 SetWindowText( this.hwnd, .pText.ptr() )
98 }
99
100 method vEdit.iGetText()
101 {
102 uint res = GetWindowTextLength( this.hwnd )
103 .pText.reserve( res + 1 )
104 GetWindowText( this.hwnd, .pText.ptr(), res + 1 )
105 .pText.setlen( res )
106 }
107
108 property ustr vEdit.Text <result>
109 {
110 result = .pText
111 }
112
113 property vEdit.Text( ustr val )
114 {
115 if val != .pText
116 {
117 .pText = val
118 this.fNewText = 1
119 .iSetText()
120 this.fNewText = 0
121 }
122 }
123
124 /*Свойство ustr MaxLen - Get Set
125 Получить, установить максимальную длину текста в символах
126 */
127 method vEdit.iSetMaxLen()
128 {
129 this.WinMsg( $EM_LIMITTEXT, .pMaxLen )
130 }
131
132 property uint vEdit.MaxLen
133 {
134 return this.pMaxLen//this.WinMsg( $EM_GETLIMITTEXT )
135 }
136
137 property vEdit.MaxLen( uint val )
138 {
139 if .pMaxLen != val
140 {
141 .pMaxLen = val
142 .iSetMaxLen()
143 }
144 }
145
146 /*Свойство ustr Password - Get Set
147 Получить, установить режим ввода пароля
148 1 - режим ввода пароля включен
149 0 - режим ввода параоля отключен
150 */
151 property uint vEdit.Password
152 {
153 return .pPassword
154 }
155
156 property vEdit.Password( uint val )
157 {
158 if .pPassword != val
159 {
160 .pPassword = val
161 this.WinMsg( $EM_SETPASSWORDCHAR, ?( val,'*', 0 ))
162 InvalidateRect( this.hwnd, 0->RECT, 1 )
163 }
164 }
165
166 /*Свойство ustr Border - Get Set
167 Установить, получить наличие рамки у поля ввода
168 1 - рамка есть
169 0 - рамки нет
170 */
171 property vEdit.Border( uint val )
172 {
173 .pBorder = val
174 uint style = GetWindowLong( this.hwnd, $GWL_EXSTYLE )
175 if val : style |= $WS_EX_CLIENTEDGE
176 else : style &= ~$WS_EX_CLIENTEDGE
177 SetWindowLong( this.hwnd, $GWL_EXSTYLE, style )
178 SetWindowPos( this.hwnd, 0, 0, 0, 0, 0, $SWP_FRAMECHANGED |
179 $SWP_NOACTIVATE | $SWP_NOZORDER | $SWP_NOMOVE | $SWP_NOSIZE )
180 }
181
182 property uint vEdit.Border
183 {
184 return .pBorder
185 }
186
187
188 /*Свойство ustr SelStart - Get Set
189 Получить, установить начало выделенного текста
190 */
191 property uint vEdit.SelStart
192 {
193 uint start
194 this.WinMsg( $EM_GETSEL, &start, 0 )
195 return start
196 }
197
198 property vEdit.SelStart( uint val )
199 {
200 this.Sel( val, 0 )
201 }
202
203 /*Свойство ustr SelLen - Get Set
204 Получить, установить длину выделенного текста
205 */
206 property uint vEdit.SelLen
207 {
208 uint start, end
209 this.WinMsg( $EM_GETSEL, &start, &end )
210 return end - start
211 }
212
213 property vEdit.SelLen( uint val )
214 {
215 this.Sel( this.SelStart, val )
216 }
217
218 /*Свойство ustr SelStart - Get
219 Получить выделенный текст
220 */
221 property ustr vEdit.SelText<result>
222 {
223 uint start, end
224 this.WinMsg( $EM_GETSEL, &start, &end )
225 result.substr( this.Text, start, end-start )
226 }
227
228
229 /*Свойство uint Changed - Get, Set
230 Получить, установить признак изменения текста
231 */
232 property uint vEdit.Changed
233 {
234 return this.pChanged
235 }
236
237 property vEdit.Changed( uint val )
238 {
239 this.pChanged = val
240 }
241
242
243 /*Свойство uint Multiline - Get, Set
244 Получить, установить многострочный режим
245 */
246 property uint vEdit.Multiline
247 {
248 return this.pMultiline
249 }
250
251 property vEdit.Multiline( uint val )
252 {
253 if this.pMultiline != val
254 {
255 this.pMultiline = val
256 .Virtual( $mReCreateWin )
257 }
258 }
259
260 /*Свойство uint WordWrap - Get, Set
261 Получить, установить режим переноса по словам, работает при Multiline = 1
262 */
263 property uint vEdit.WordWrap
264 {
265 return this.pWordWrap
266 }
267
268 property vEdit.WordWrap( uint val )
269 {
270 if this.pWordWrap != val
271 {
272 this.pWordWrap = val
273 .Virtual( $mReCreateWin )
274 }
275 }
276
277
278 /*Свойство uint ScrollBars - Get, Set
279 Получить, установить режим отображения полос прокрутки
280 */
281 property uint vEdit.ScrollBars
282 {
283 return this.pScrollBars
284 }
285
286 property vEdit.ScrollBars( uint val )
287 {
288 if this.pScrollBars != val
289 {
290 this.pScrollBars = val
291 .Virtual( $mReCreateWin )
292 }
293 }
294
295 /*------------------------------------------------------------------------------
296 Virtual methods
297 */
298 method vEdit vEdit.mCreateWin <alias=vEdit_mWin>()
299 {
300 uint exstyle
301 uint style = /*$ES_AUTOHSCROLL |*/ $WS_CHILD | $WS_VISIBLE | $WS_CLIPSIBLINGS
302 if .pBorder : exstyle |= $WS_EX_CLIENTEDGE
303 if .pReadOnly : style |= $ES_READONLY
304 if .pPassword : style |= $ES_PASSWORD
305 if .pMultiline
306 {
307 style |= $ES_WANTRETURN | $ES_MULTILINE | $ES_AUTOVSCROLL
308 if !.pWordWrap : style |= $ES_AUTOHSCROLL
309 }
310 else : style |= $ES_AUTOHSCROLL
311 if .pScrollBars & $sbHorz : style |= $WS_HSCROLL
312 if .pScrollBars & $sbVert : style |= $WS_VSCROLL
313
314 .CreateWin( "EDIT".ustr(), exstyle, style )
315 this->vCtrl.mCreateWin()
316 .iSetMaxLen()
317 .iSetText()
318 return this
319 }
320
321 method uint vEdit.mWinCmd <alias=vEdit_mWinCmd>( uint ntfcmd, uint id )
322 {
323 if ntfcmd == $EN_CHANGE
324 {
325 this.pChanged = !this.fNewText
326 .iGetText()
327 this.OnChange.run()
328 }
329 return 0
330 }
331
332 method vEdit.mFocus <alias=vEdit_mFocus> ( evparValUint eu )
333 {
334 this->vCtrl.mFocus( eu )
335 if !.pMultiline && eu.val && !( GetKeyState($VK_LBUTTON) & 0x1000 )
336 {
337 this.SelAll()
338 }
339 }
340
341 /*Виртуальный метод uint vEdit.mSetName - Установка заголовка в режиме проектирования
342 */
343 method uint vEdit.mSetName <alias=vEdit_mSetName>( str newname )
344 {
345 ifdef $DESIGNING {
346 if !.p_loading && .Text == .Name
347 {
348 .Text = newname.ustr()
349 }
350 }
351 return 1
352 }
353
354 /*------------------------------------------------------------------------------
355 Registration
356 */
357 method vEdit vEdit.init( )
358 {
359 this.pTypeId = vEdit
360
361 this.pBorder = 1
362 this.pTabStop = 1
363 this.pCanFocus = 1
364 this.loc.width = 100
365 this.loc.height = 25
366 this.pMaxLen = 0x8000
367 return this
368 }
369
370 func init_vEdit <entry>()
371 {
372 regcomp( vEdit, "vEdit", vCtrl, $vCtrl_last,
373 %{ %{ $mCreateWin, vEdit_mWin },
374 %{ $mWinCmd, vEdit_mWinCmd },
375 %{ $mFocus, vEdit_mFocus },
376 %{ $mSetName, vEdit_mSetName }
377 },
378 0->collection )
379
380 ifdef $DESIGNING {
381 cm.AddComp( vEdit, 1, "Windows", "edit" )
382
383 cm.AddProps( vEdit, %{
384 "TabOrder" , uint , 0,
385 "Text" , ustr , 0,
386 "MaxLen" , uint , 0,
387 "Border" , uint , 1,
388 "Password" , uint , 0,
389 "Multiline", uint , 0,
390 "WordWrap" , uint , 0,
391 "ScrollBars", uint , 0
392 })
393
394 cm.AddEvents( vEdit, %{
395 "OnChange" , "evparEvent"
396 })
397
398 cm.AddPropVals( vEdit, "ScrollBars", %{
399 "sbNone", $sbNone,
400 "sbHorz", $sbHorz,
401 "sbVert", $sbVert,
402 "sbBoth", $sbBoth
403 })
404 }
405 }