1
2 /******************************************************************************
3 *
4 * Copyright (C) 2004-2007, The Gentee Group. All rights reserved.
5 * This file is part of the Gentee open source project - http://www.gentee.com.
6 *
7 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
8 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
9 * ACCEPTANCE OF THE AGREEMENT.
10 *
11 * ID: viseditor.proplist 30.07.07 0.0.A.
12 *
13 * Author: Alexander Krivonogov ( gentee )
14 *
15 ******************************************************************************/
16
17 /*
18 define {
19 PI_SIMPLE = 0x000
20 PI_UPDOWN = 0x001
21 PI_DLG = 0x002
22 PI_SEL = 0x100
23
24 PI_DEFVAL = 0x1000000
25 PI_LIST = 0x1000
26 }
27 */
28 type evparProp <inherit=evparEvent>
29 {
30 ustr name
31 ustr value
32 }
33
34 type evProp <inherit=evEvent>
35 {
36 }
37
38 method evProp evProp.init
39 {
40 this.eventtypeid = evparProp
41 return this
42 }
43
44
45 type vSDraw <inherit = vCtrl>
46 {
47 ustr pCaption
48 uint off
49 }
50
51
52 method uint vSDraw.wmpaint <alias=vSDraw_wmpaint>( winmsg wmsg )
53 {
54 uint hdc
55 PAINTSTRUCT ps
56 RECT rect
57
58 hdc = BeginPaint( this.hwnd, ps )
59 rect.left = this.clloc.left
60 rect.right = this.clloc.width
61 rect.top = this.clloc.top
62 rect.bottom = this.clloc.height
63 DrawEdge( hdc,
64 rect,
65 $BDR_SUNKENOUTER,
66 $BF_LEFT | $BF_RIGHT | $BF_TOP | $BF_BOTTOM )
67 SelectObject( hdc, GetStockObject( $DEFAULT_GUI_FONT ) )
68 SetBkMode( hdc, $TRANSPARENT )
69 SetTextColor( hdc, GetSysColor( $COLOR_HIGHLIGHT ) )
70 rect.left +=5
71 rect.top ++
72 DrawText( hdc, this.pCaption.ptr(), -1, rect, $DT_LEFT | $DT_SINGLELINE )
73 MoveToEx( hdc, this.off, 0, 0->POINT )
74 LineTo( hdc, this.off, this.Height )
75 EndPaint( this.hwnd, ps )
76 return 0
77 }
78
79
80
81 method vSDraw vSDraw.mCreateWin <alias=vSDraw_mCreateWin>()
82 {
83 this.CreateWin( "GVForm".ustr(), 0,
84 $WS_CHILD | $WS_VISIBLE | $WS_CLIPCHILDREN | $WS_CLIPSIBLINGS | $WS_OVERLAPPED)
85 this.prevwndproc = -1
86 this->vCtrl.mCreateWin()
87 //this.prevwndproc = 0
88 this.WinMsg( $WM_SETFONT, GetStockObject( $DEFAULT_GUI_FONT ) )
89 return this
90 }
91
92 property str vSDraw.Caption <result>
93 {
94 result = this.pCaption
95 }
96
97 property vSDraw.Caption( ustr val )
98 {
99 this.pCaption = val
100 InvalidateRect( this.hwnd, 0->RECT, 1 )
101 }
102
103 type vPropList <inherit=vCtrl>
104 {
105 uint ncount //Количество строк
106 uint nfirst //Первая строка
107 uint nviscount //Количество видимых строк
108 uint nheight //Высота строки
109 uint ncur //Номер текущей строки
110 uint nleftwidth//Ширина левой части
111 vSDraw curprop
112 vEdit ed
113 vBtnSys bs
114 uint sysfont
115 uint pen
116 arr ar of PropItem
117 evProp onPropSet
118 evEvent ongetlist
119 evEvent ondblclick
120 vComboBox cb
121 uint prevcap
122 ustr lastprop
123 //arr
124 }
125
126 define {
127 SETFIRST_ABS = 0
128 SETFIRST_OFF = 1
129 SETFIRST_PAGE = 2
130 }
131
132 method vPropList.calccur( )
133 {
134 this.curprop.Top = ( this.ncur - this.nfirst ) * this.nheight
135 }
136
137 method vPropList.setfirst( uint flag, int pos )
138 {
139 int newpos = this.nfirst
140 switch flag {
141 case $SETFIRST_ABS {
142 if pos == -1 {
143 newpos = this.ncount
144 }
145 else {
146 newpos = pos
147 }
148 }
149 case $SETFIRST_OFF {
150 newpos += pos
151 }
152 case $SETFIRST_PAGE {
153 newpos += this.nviscount * pos
154 }
155 }
156 newpos = min( ?(newpos < 0, 0, newpos ), this.ncount - this.nviscount )
157 if newpos != this.nfirst
158 {
159 this.nfirst = newpos
160 SetScrollPos( this.hwnd, $SB_VERT, this.nfirst, 1 )
161 InvalidateRect( this.hwnd, 0->RECT, 1 )
162 this.calccur()
163 }
164 }
165
166 method vPropList.propset()
167 {
168 evparProp ep
169 ep.name = this.curprop.Caption
170 ep.value = this.ed.Text
171 this.onPropSet.run( ep )
172 }
173
174 method vPropList.setcur( uint val, uint flgstate )
175 {
176 if val >= this.ncount : val = -1
177 if val != this.ncur && val != -1
178 {
179 if this.ed.Changed
180 {
181 this.ed.Changed = 0
182 this.propset()
183 }
184
185 this.ncur = val
186 this.curprop.Visible = 0
187 this.calccur()
188 this.curprop.Caption = this.ar[this.ncur].Name//"temp \( this.ncur)"
189 this.ed.Text = this.ar[this.ncur].Value
190
191 if this.ar[this.ncur].Flags & $PI_LIST
192 {
193 this.bs.Width = this.nheight
194 }
195 else : this.bs.Width = 0
196 this.ed.Width = this.clloc.width - this.ed.Left - this.bs.Width
197 this.bs.Left = this.clloc.width - this.bs.Width
198 if flgstate
199 {
200 this.lastprop = this.ar[this.ncur].Name
201 }
202 //SetFocus( this.ed.hwnd )
203
204 this.curprop.Visible = 1
205 //SendMessage( this.ed.hwnd, $EM_SETSEL, 0, -1 )
206 this.ed.SelAll()
207 }
208 if this.ncur < this.nfirst
209 {
210 this.setfirst( $SETFIRST_ABS, this.ncur )
211 }
212 elif this.ncur >= this.nfirst + this.nviscount
213 {
214 this.setfirst( $SETFIRST_ABS, this.ncur - this.nviscount + 1 )
215 }
216 }
217
218
219 method vPropList.calcviscount()
220 {
221 if !this.nheight : return
222 this.nviscount = min( this.clloc.height / this.nheight, this.ncount )
223
224
225 // EnableScrollBar( this.hwnd, $SB_VERT, $ESB_ENABLE_BOTH)
226 if this.nviscount == this.ncount
227 {
228 //st.fMask = $SIF_RANGE | $SIF_PAGE;
229 //st.nMax = 0;
230 //st.nPage = 0;
231 //ShowScrollBar( this.hwnd, $SB_VERT, 0 )
232 SCROLLINFO si
233 //ShowScrollBar( this.hwnd, $SB_VERT, 1 )
234 si.cbSize = sizeof( SCROLLINFO )
235 si.fMask = $SIF_RANGE | $SIF_PAGE | $SIF_POS
236 si.nMin = 0
237 si.nMax = 0//this.ncount-1// - this.nviscount
238 si.nPage = 0//this.nviscount
239 si.nPos = 0;
240 SetScrollInfo( this.hwnd, $SB_VERT, si, 1 )
241 }
242 else
243 {
244
245 SCROLLINFO si
246 //ShowScrollBar( this.hwnd, $SB_VERT, 1 )
247 si.cbSize = sizeof( SCROLLINFO )
248 si.fMask = $SIF_RANGE | $SIF_PAGE | $SIF_POS
249 si.nMin = 0
250 si.nMax = this.ncount-1// - this.nviscount
251 si.nPage = this.nviscount
252 si.nPos = this.nfirst//0;
253 SetScrollInfo( this.hwnd, $SB_VERT, si, 1 )
254
255 }
256 this.setfirst( $SETFIRST_ABS, this.nfirst )
257
258 }
259
260 method vPropList.setcount( uint new )
261 {
262 this.ncount = new
263 this.nfirst = 0
264 this.calcviscount()
265 }
266
267
268 /*method uint vPropList.findprop( str name )
269 {
270 fornum i = 0, *this.ar
271 {
272 if this.ar[i].name == name
273 {
274 return i
275 }
276 }
277 }*/
278
279 method vPropList.setar( arr ar of PropItem )
280 {
281 uint i, ncur
282 this.ar.clear()
283 this.ar.expand( *ar )
284
285 this.ncur = -1
286 fornum i=0, *ar
287 {
288 //print( "\(ar[i].name) \(this.lastprop) \(ar[i].name >= this.lastprop)\n" )
289 if ar[i].Name == this.lastprop : ncur = i
290 this.ar[i].Name = ar[i].Name
291 this.ar[i].Value = ar[i].Value
292 this.ar[i].Flags = ar[i].Flags
293 }
294
295 this.ed.Changed = 0
296 //this.nfirst = 0
297 this.ncount = *ar
298 this.calcviscount()
299 if this.ncount
300 {
301 this.setcur( ncur, 0 )
302 this.curprop.Visible = 1
303 }
304 else
305 {
306 this.curprop.Visible = 0
307 }
308 InvalidateRect( this.hwnd, 0->RECT, 1 )
309 }
310
311 method uint vPropList.edkey <alias=proplist_edkey>( /*vComp sender,*/ evparKey ek )
312 {
313 if ek.evktype == $evkDown
314 {
315 switch ek.key
316 {
317 case 0x0d
318 {
319 if ek.mstate & $mstCtrl :this.ondblclick.run()
320 else : this.propset()
321 return 0
322 }
323 case 0x1B
324 {
325 this.ed.Text = this.ar[this.ncur].Value
326 SendMessage( this.ed.hwnd, $EM_SETSEL, 0, -1 )
327 return 0
328 }
329 case 0x26//Вверх
330 {
331 this.setcur( this.ncur - 1, 1 )
332 return 0
333 }
334 case 0x28//Вниз
335 {
336 if ek.mstate & $mstAlt
337 {
338 this.ongetlist.run()
339 // this.pl.start()
340 }
341 else : this.setcur( this.ncur + 1, 1 )
342 return 0
343 }
344 }
345 }
346 return 1
347 }
348
349 method uint vPropList.edmouse <alias=proplist_edmouse>( /*vComp sender,*/ evparMouse evm )
350 {
351 if evm.evmtype == $evmLDbl
352 {
353 this.ondblclick.run()
354 }
355 return 1
356 }
357
358 method uint vPropList.edfocus <alias=proplist_edfocus>( evparValUint eu )
359 {
360 if !eu.val && this.ed.Changed: this.propset()
361 return 1
362 }
363
364
365 method uint vPropList.bsclick <alias=proplist_bsclick>( evparEvent ev )
366 {
367 this.ongetlist.run()
368 this.cb.DropDown()
369 return 0
370 }
371
372 method uint vPropList.cbcloseup<alias=proplist_cbcloseup>( evparEvent ev )
373 {
374 //print( "CLOSE\n" )
375 this.bs.Push = 0
376 return 0
377 }
378
379 method uint vPropList.plselect <alias=proplist_plselect>( eventstr ev )
380 {
381 evparProp ep
382 this.ed.Text = ev.val.ustr()
383 ep.name = this.curprop.Caption
384 ep.value = this.ed.Text
385 this.onPropSet.run( ep )
386 return 0
387 }
388
389
390 method vPropList vPropList.mCreateWin <alias=vPropList_mCreateWin>()
391 {
392
393 // this->vSDraw.mCreateWin()
394 .CreateWin( "GVForm".ustr(), /*$WS_EX_STATICEDGE*/0,
395 $WS_CHILD | $WS_VISIBLE | $WS_CLIPCHILDREN | $WS_CLIPSIBLINGS | $WS_OVERLAPPED )
396 // setxpstyle( this.hwnd )
397 this.prevwndproc = -1
398 this->vCtrl.mCreateWin()
399 //this.prevwndproc = 0
400
401 this.WinMsg( $WM_SETFONT, GetStockObject( $DEFAULT_GUI_FONT ) )
402
403 this.sysfont = GetStockObject( $DEFAULT_GUI_FONT )
404 this.pen = CreatePen( $PS_SOLID, 1, GetSysColor($COLOR_INACTIVECAPTION))//$COLOR_WINDOWFRAME) )
405 uint hdc = GetDC( this.hwnd )
406 SelectObject( hdc, this.sysfont )
407 TEXTMETRIC tm
408 GetTextMetrics( hdc, tm )
409 ReleaseDC( this.hwnd, hdc )
410
411 this.nheight = tm.tmHeight + 2
412 this.setcount( 0 )
413 this.nleftwidth = 90
414 this.ncur = -1
415
416 // this->vPanel.Border = $brdLowered
417
418
419 this.curprop.Owner = this
420 this.curprop.Top = 0
421 this.curprop.Width =100
422 this.curprop.Height = this.nheight + 1
423 this.curprop.off = this.nleftwidth
424
425
426 this.curprop.VertAlign = $alvTop
427 this.curprop.HorzAlign = $alhClient
428 this.curprop.Name = "x"
429
430 this.ed.Owner = this.curprop
431 this.ed.Left = this.nleftwidth + 1
432 this.ed.Top = 1//0
433 this.ed.Height = this.nheight
434 this.ed.VertAlign = $alvTop
435 this.ed.HorzAlign = $alhLeft
436 this.ed.Border = 0
437
438 this.ed.OnKey.Set( this, proplist_edkey )
439 this.ed.onfocus.Set( this, proplist_edfocus )
440 this.ed.OnMouse.Set( this, proplist_edmouse )
441 this.curprop.OnMouse.Set( this, proplist_edmouse )
442
443 this.bs.Owner = this.curprop
444 this.bs.VertAlign = $alvTop
445 this.bs.HorzAlign = $alhLeft
446 this.bs.Width = this.nheight - 1
447 this.bs.Height = this.nheight - 1
448
449 this.bs.Top = 1
450 this.bs.onclick.Set( this, proplist_bsclick )
451 //? this.bs.onmouse.set( this, proplist_bsmouse )
452
453 this.cb.Owner = this.curprop
454 //this.cb.Height = 10
455 this.cb.Style = $cbsDropDownList
456 this.cb.Left = this.ed.Left - 1
457 this.cb.Top = this.curprop.Height - this.cb.Height
458 this.cb.onselect.Set( this, proplist_plselect )
459 this.cb.oncloseup.Set( this, proplist_cbcloseup )
460 this.cb.Visible = 0
461 return this
462 }
463
464 method vPropList.mPosChanged <alias=vPropList_mPosChanged> (evparEvent ev )
465 {
466 this->vCtrl.mPosChanged( ev )
467 this.ed.Width = this.clloc.width - this.ed.Left - this.bs.Width
468 this.cb.Width = this.clloc.width - this.cb.Left
469 this.bs.Left = this.clloc.width - this.bs.Width
470 this.calcviscount()
471 }
472
473 method uint vPropList.wmpaint <alias=vPropList_wmpaint>(winmsg wmsg)
474 {
475 uint hdc
476 PAINTSTRUCT ps
477 RECT rect
478 str temp
479
480 hdc = BeginPaint( this.hwnd, ps )
481
482 SetBkMode( hdc, $TRANSPARENT )
483 uint i
484 SelectObject( hdc, this.sysfont )
485 SelectObject( hdc, this.pen )
486
487 rect.top = 0
488 SetTextColor( hdc, GetSysColor( $COLOR_WINDOWTEXT ) )
489 fornum i=0, this.nviscount
490 {
491 rect.right = this.nleftwidth
492 rect.bottom = rect.top + this.nheight
493 rect.top++
494 rect.left = 5
495 DrawText( hdc, this.ar[i+ this.nfirst].Name.ptr(), -1, rect, $DT_LEFT | $DT_SINGLELINE )
496 rect.left = this.nleftwidth + 2
497 rect.right = this.clloc.width
498 rect.top++
499 DrawText( hdc, this.ar[i+ this.nfirst].Value.ptr(), -1, rect, $DT_LEFT | $DT_SINGLELINE )
500 rect.top--
501 rect.top--
502 MoveToEx( hdc, 0, rect.bottom, 0->POINT )
503 LineTo( hdc, rect.right, rect.bottom )
504 rect.top += this.nheight
505 }
506 MoveToEx( hdc, this.nleftwidth, 0, 0->POINT )
507 LineTo( hdc, this.nleftwidth, this.clloc.height )
508 EndPaint( this.hwnd, ps )
509
510 return 0
511 }
512
513 method uint vPropList.wmlbuttondown <alias=vPropList_wmlbuttondown>(winmsgmouse wmsg)
514 {
515 uint n = wmsg.y / this.nheight
516 if n < this.nviscount
517 {
518 this.setcur( n + this.nfirst, 1 )
519 SetFocus( this.ed.hwnd )
520 }
521 return 0
522 }
523
524 method uint vPropList.wmmousewheel <alias=vPropList_wmmousewheel>(winmsg wmsg)
525 {
526 if ((&wmsg->winmsgsh.wparhi)->short ) > 0 : this.setfirst( $SETFIRST_OFF, -3 )
527 else : this.setfirst( $SETFIRST_OFF, 3 )
528 return 0
529 }
530
531 method uint vPropList.wmvscroll <alias=vPropList_wmvscroll>(winmsg wmsg)
532 {
533 uint nScrollCode = wmsg->winmsgsh.wparlo
534 uint npos = wmsg->winmsgsh.wparhi
535 switch nScrollCode
536 {
537 case $SB_LINEUP {
538 this.setfirst( $SETFIRST_OFF, -1 )
539 }
540 case $SB_LINEDOWN {
541 this.setfirst( $SETFIRST_OFF, 1 )
542 }
543 case $SB_PAGEUP {
544 this.setfirst( $SETFIRST_PAGE, -1 )
545 }
546 case $SB_PAGEDOWN {
547 this.setfirst( $SETFIRST_PAGE, 1 )
548 }
549 case $SB_THUMBTRACK {
550 SCROLLINFO si
551 si.cbSize = sizeof( SCROLLINFO )
552 si.fMask = $SIF_TRACKPOS
553 GetScrollInfo( this.hwnd, $SB_VERT, si )
554 this.setfirst( $SETFIRST_ABS, si.nTrackPos )
555 }
556 }
557 return 0
558 }
559
560
561 method vSDraw vSDraw.init( )
562 {
563 this.pTypeId = vSDraw
564 this.pCanContain = 1
565
566 return this
567 }
568
569 method vPropList vPropList.init( )
570 {
571 //print( "vPropList.init 1\n" )
572 this.pTypeId = vPropList
573 this.pCanContain = 1
574 //this.flgXPStyle = 1
575 //print( "vPropList.init 2\n" )
576 return this
577 }
578
579 func init_vPropList <entry>()
580 {
581 regcomp( vSDraw, "vSDraw", vCtrl, $vCtrl_last,
582 %{ %{$mCreateWin, vSDraw_mCreateWin}//,
583 //%{$mWinCmd, vBtn_mWinCmd}
584 },
585 %{ %{$WM_PAINT, vSDraw_wmpaint }
586 })
587
588 regcomp( vPropList, "vPropList", vCtrl, $vCtrl_last,
589 %{ %{$mCreateWin, vPropList_mCreateWin},
590 %{$mPosChanged, vPropList_mPosChanged}
591 },
592 %{ %{$WM_PAINT, vPropList_wmpaint },
593 %{$WM_LBUTTONDOWN, vPropList_wmlbuttondown },
594 %{$WM_MOUSEWHEEL, vPropList_wmmousewheel },
595 %{$WM_VSCROLL, vPropList_wmvscroll }
596 })
597 }