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.toolbar 01.04.08 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 /* Компонента vToolBar, порождена от vCtrl
17 */
18 /*! В перспективе:
19 */
20 type vToolBar <inherit = vCtrl>
21 {
22 //Hidden Fields
23 ustr pImageList
24 uint ptrImageList
25 uint iNumIml
26 uint pShowCaption
27 uint pWrapable
28 uint pShowDivider
29 uint pAutoSize
30
31 //Events
32
33 }
34
35 include {
36 "toolbaritem.g"
37 }
38
39 define {
40 //ShowCaption values:
41 tscNone = 0 //Не показывать подписи к кнопкам
42 tscRight = 1 //Подписи справа
43 tscBottom = 2 //Подписи снизу
44 //tscAsHint = 3 //Не показывать подписи но использовать их как подсказки
45 }
46
47 /*------------------------------------------------------------------------------
48 Internal Methods
49 */
50 /*Метод vToolBar.iUpdateImageList()
51 Обновить ImageList
52 */
53 method vToolBar.iUpdateImageList()
54 {
55 .ptrImageList = &.GetImageList( .pImageList, &.iNumIml )
56 // print( "iUpdateImageList \(.ptrImageList ) \(&.pImageList)\n" )
57 if .ptrImageList
58 {
59
60 // print( "im \(.ptrImageList->ImageList.arrIml[0].hIml )\n" )
61 .WinMsg( $TB_SETIMAGELIST, 0, .ptrImageList->ImageList.arrIml[.iNumIml].hIml )
62 }
63 else
64 {
65 .WinMsg( $TB_SETIMAGELIST, 0, 0 )
66 }
67 InvalidateRect( this.hwnd, 0->RECT, 1 )
68 }
69
70 /*Метод vToolBar.iUpdateSize()
71 Пересчитать размеры левого и правого объекта
72 */
73 /*method vToolBar.iUpdateSize()
74 {
75 uint width = ?( .pOrientation == $soVertical, this.Width, this.Height ) -
76 .pToolBarWidth
77
78 .pDistance = width - max( int( width - .pDistance ), int( .pRightMinSize ) )
79 .pDistance = max( int( .pDistance ), int( .pLeftMinSize ) )
80 .pDistance = min( width, int( .pDistance ))
81
82 if *.Comps && .Comps[0]->vComp.TypeIs( vCtrl )
83 {
84 uint left as .Comps[0]->vCtrl
85 left.HorzAlign = $alhLeft
86 left.VertAlign = $alvTop
87 left.flgNoPosChanging = 0
88 left.Left = 0
89 left.Top = 0
90 if .pOrientation == $soVertical
91 {
92 left.Height = this.Height
93 left.Width = .pDistance
94 }
95 else
96 {
97 left.Height = .pDistance
98 left.Width = .Width
99 }
100 left.flgNoPosChanging = 1
101 }
102 if *.Comps > 1 && .Comps[1]->vComp.TypeIs( vCtrl )
103 {
104 uint right as .Comps[1]->vCtrl
105 right.HorzAlign = $alhLeft
106 right.VertAlign = $alvTop
107 right.flgNoPosChanging = 0
108
109 if .pOrientation == $soVertical
110 {
111 right.Top = 0
112 right.Left = .pDistance + .pToolBarWidth
113 right.Height = this.Height
114 right.Width = .Width - .pDistance - .pToolBarWidth
115 }
116 else
117 {
118 right.Top = .pDistance + .pToolBarWidth
119 right.Left = 0
120 right.Width = this.Width
121 right.Height = .Height - .pDistance - .pToolBarWidth
122 }
123 right.flgNoPosChanging = 1
124 }
125 }*/
126
127 /*------------------------------------------------------------------------------
128 Properties
129 */
130 /* Свойство str vPicture.ImageList - Get Set
131 Устанавливает или получает имя списка картинок
132 */
133 property ustr vToolBar.ImageList <result>
134 {
135 result = this.pImageList
136 }
137
138 property vToolBar.ImageList( ustr val )
139 {
140 if val != this.pImageList
141 {
142 this.pImageList = val
143 .Virtual( $mLangChanged )
144 //.iUpdateImageList()
145 }
146 }
147
148 /* Свойство str vToolBar.ShowCaption - Get Set
149 Режим отображения заголовков
150 */
151 property uint vToolBar.ShowCaption
152 {
153 return this.pShowCaption
154 }
155
156 property vToolBar.ShowCaption( uint val )
157 {
158 if val != this.pShowCaption
159 {
160 this.pShowCaption = val
161 .Virtual( $mReCreateWin )
162 /* uint style = .WinMsg( $TB_GETSTYLE )
163 style &= ~( $TBSTYLE_LIST | $TBSTYLE_TRANSPARENT )
164 switch val
165 {
166 case $tscRight: style |= $TBSTYLE_LIST
167 case $tscBottom: style |= $TBSTYLE_TRANSPARENT
168 }
169 .WinMsg( $TB_SETSTYLE, 0, style )
170 */
171 }
172 }
173
174 /* Свойство str vToolBar.Wrapable - Get Set
175 Режим отображения заголовков
176 */
177 property uint vToolBar.Wrapable
178 {
179 return this.pWrapable
180 }
181
182 property vToolBar.Wrapable( uint val )
183 {
184 if val != this.pWrapable
185 {
186 this.pWrapable = val
187 .Virtual( $mReCreateWin )
188 }
189 }
190
191
192 /* Свойство str vToolBar.ShowDivider - Get Set
193 Режим отображения заголовков
194 */
195 property uint vToolBar.ShowDivider
196 {
197 return this.pShowDivider
198 }
199
200 property vToolBar.ShowDivider( uint val )
201 {
202 if val != this.pShowDivider
203 {
204 this.pShowDivider = val
205 .Virtual( $mReCreateWin )
206 }
207 }
208
209 /* Свойство str vToolBar.AutoSize - Get Set
210 Режим отображения заголовков
211 */
212 property uint vToolBar.AutoSize
213 {
214 return this.pAutoSize
215 }
216
217 property vToolBar.AutoSize( uint val )
218 {
219 if val != this.pAutoSize
220 {
221 this.pAutoSize = val
222 .Virtual( $mReCreateWin )
223 }
224 }
225
226 /*------------------------------------------------------------------------------
227 Virtual Methods
228 */
229 /*Виртуальный метод vToolBar vToolBar.mCreateWin
230 Создание окна
231 */
232 method vToolBar vToolBar.mCreateWin <alias=vToolBar_mCreateWin>()
233 {
234 //.Visible = 0
235 uint style = $WS_CHILD | $WS_VISIBLE | $WS_CLIPCHILDREN |
236 /*$WS_CLIPSIBLINGS |*/ $CCS_NOPARENTALIGN | $TBSTYLE_FLAT |
237 $WS_OVERLAPPED | $CCS_NOMOVEY
238 //if !.p_designing : style |=
239 if .pWrapable : style |= $TBSTYLE_WRAPABLE
240 switch .pShowCaption
241 {
242 case $tscRight: style |= $TBSTYLE_LIST
243 case $tscBottom: style |= $TBSTYLE_TRANSPARENT
244 }
245 if !.pShowDivider : style |= $CCS_NODIVIDER
246 if !.pAutoSize : style |= $CCS_NORESIZE
247
248 .CreateWin( "ToolbarWindow32".ustr(), 0, style )
249 this->vCtrl.mCreateWin()
250 .WinMsg( $TB_BUTTONSTRUCTSIZE, sizeof( TBBUTTON ) )
251 .WinMsg( $TB_SETEXTENDEDSTYLE, 0, $TBSTYLE_EX_DRAWDDARROWS )
252 .WinMsg( $TB_SETTOOLTIPS, this.GetForm()->vForm.hwndTip )
253 .WinMsg( $TB_SETINDENT, 2 )
254 /*SetWindowPos( .hwnd, 0, 0, 0, .Width, .Height-1, $SWP_NOACTIVATE | $SWP_NOMOVE |
255 $SWP_NOZORDER)*/
256 /*SetWindowPos( .hwnd, 0, 0, 0, .Width, .Height, $SWP_NOACTIVATE | $SWP_NOMOVE |
257 $SWP_NOZORDER)*/
258 //.WinMsg( $TB_SETMAXTEXTROWS, 1 )
259 //.WinMsg( $TB_SETBUTTONWIDTH, 0,0x400040 )
260 //.WinMsg( $TB_SETBUTTONSIZE, 0, 0x100010 )
261 //.Visible = 1
262 return this
263 }
264
265 /*Виртуальный метод vToolBar.mInsert
266 Вставка дочерних элементов
267 */
268
269 method vToolBar.AddButton( vToolBarItem newcomp, uint idx )
270 {
271 TBBUTTON tb
272 tb.iBitmap = -1
273 tb.fsStyle = $TBSTYLE_BUTTON
274 tb.fsState = 4
275 tb.dwData = &newcomp
276 tb.idCommand = idx//&newcomp
277 //if newcomp.pStyle == $tbsSeparator : tb.idCommand = -1
278 if .pShowCaption == $tscRight ||
279 .pShowCaption == $tscBottom : tb.iString = "".ustr().ptr()
280 .WinMsg( $TB_INSERTBUTTON, idx, &tb )
281 }
282
283 method vToolBar.mInsert <alias=vToolBar_mInsert>( vComp newcomp )
284 {
285 if newcomp.TypeIs( vToolBarItem )
286 {
287 this->vCtrl.mInsert( newcomp )
288 .AddButton( newcomp->vToolBarItem, *.Comps - 1 )
289
290 // print( "insert \( &newcomp )\n" )
291 }
292 }
293
294 method vToolBar.mReCreateWin <alias=vToolBar_mReCreateWin> ()
295 {
296 uint i
297 this->vCtrl.mReCreateWin()
298
299 .Virtual( $mLangChanged )
300 fornum i = 0, .pCtrls
301 {
302 .AddButton( .Comps[i]->vToolBarItem, i )
303 .Comps[i]->vToolBarItem.iUpdate()
304 }
305 //.iUpdateImageList()
306 }
307
308 /*Виртуальный метод vToolBar.mRemove
309 Удаление дочерних элементов
310 */
311 method vToolBar.mRemove <alias=vToolBar_mRemove>( vComp item )
312 {
313 if item.TypeIs( vToolBarItem )
314 {
315 //print( "remove\n" )
316 .WinMsg( $TB_DELETEBUTTON, .WinMsg( $TB_COMMANDTOINDEX, item->vVirtCtrl.cidx/*&item*/ ) )
317 }
318 this->vCtrl.mRemove( item )
319 }
320
321
322 type NMCUSTOMDRAWINFO {
323 NMHDR hdr;
324 uint dwDrawStage;
325 uint hdc;
326 RECT rc;
327 uint dwItemSpec;
328 uint uItemState;
329 uint lItemlParam;
330 }
331
332 /*Виртуальный метод vToolBar.mWinNtf
333 Обработка сообщения WM_COMMAND
334 */
335 method uint vToolBar.mWinCmd <alias=vToolBar_mWinCmd>( uint ntfcmd, uint id )
336 {
337 if id < *.Comps
338 {
339 uint item as .Comps[id]->vToolBarItem
340 if item.pTBIStyle == $tbsAsRadioBtn
341 {
342 item.Checked = 1
343 }
344 elif item.pTBIStyle == $tbsAsCheckBox
345 {
346 item.Checked = !item.pChecked//( .WinMsg( $BM_GETCHECK ) == $BST_CHECKED )
347 }
348 evparEvent ev
349 ev.sender = &item
350 item.OnClick.Run( ev )
351 }
352 return 0
353 }
354
355 /*Виртуальный метод vToolBar.mWinNtf
356 Обработка сообщения WM_NOTIFY
357 */
358 method uint vToolBar.mWinNtf <alias=vToolBar_mWinNtf >( NMHDR ntf )
359 {
360 switch ntf.code
361 {
362 case $NM_CLICK
363 {
364 /*uint ntftb = &ntf
365 ntftb as NMTOOLBAR
366 if ntftb.iItem && ntftb.iItem !=-1
367 {
368 if ntftb.iItem->vToolBarItem.pTBIStyle == $tbsAsRadioBtn
369 {
370 ntftb.iItem->vToolBarItem.Checked = 1
371
372 }
373 elif ntftb.iItem->vToolBarItem.pTBIStyle == $tbsAsCheckBox
374 {
375 ntftb.iItem->vToolBarItem.Checked = !ntftb.iItem->vToolBarItem.pChecked//( .WinMsg( $BM_GETCHECK ) == $BST_CHECKED )
376 }
377 //print( "Click \(ntf.idFrom) \(ntf.code) \(ntftb.iItem)\n" )
378 evparEvent ev
379 ev.sender = ntftb.iItem
380 ntftb.iItem->vToolBarItem.OnClick.Run( ev )
381 }*/
382 }
383 case $TBN_DROPDOWN
384 {
385
386 uint ntftb as (&ntf)->NMTOOLBAR
387 //ntftb as NMTOOLBAR
388 uint item as .Comps[ntftb.iItem]->vToolBarItem
389 //if //ntftb.iItem && ntftb.iItem !=-1
390 {
391 if /*ntftb.iItem->vToolBarItem*/item.pDropDownMenu
392 {
393 POINT pnt
394 pnt.x = item.Left//ntftb.iItem->vToolBarItem.Left
395 pnt.y = item.Top + item.Height//ntftb.iItem->vToolBarItem.Top + ntftb.iItem->vToolBarItem.Height
396 ClientToScreen( this.hwnd, pnt )
397 /*ntftb.iItem->vToolBarItem*/item.DropDownMenu.Show( pnt.x, pnt.y )
398 }
399 }
400 }
401 case $NM_CUSTOMDRAW
402 {
403 if !isThemed
404 {
405 uint ntftb = &ntf
406 ntftb as NMCUSTOMDRAWINFO
407 FillRect( ntftb.hdc, ntftb.rc, GetSysColorBrush($COLOR_BTNFACE) )
408 }
409 }
410 }
411 return 0
412 }
413
414
415 /*Виртуальный метод vToolBar.mLangChanged - Изменение текущего языка
416 */
417 method vToolBar.mLangChanged <alias=vToolBar_mLangChanged>()
418 {
419 .iUpdateImageList()
420 this->vCtrl.mLangChanged()
421 }
422
423 method vToolBar.mGetHint <alias=vToolBar_mGetHint>( uint id, lpar, ustr resstr )
424 {
425 uint item as this.Comps[id]->vToolBarItem//id->vToolBarItem
426 if !*item.pHint.Text( this ) //.pShowCaption == $tscAsHint &&
427 {
428 resstr = item.pCaption.Text( this )
429 }
430 else :resstr = item.pHint.Text( this )
431 }
432
433 /*Виртуальный метод vToolBar.mPosChanging
434 Изменение размеров
435 */
436 /*method vToolBar.mPosChanging <alias=vToolBar_mPosChanging>( eventpos evp )
437 {
438 this->vCtrl.mPosChanging( evp )
439 switch .pFixedPart
440 {
441 case $sfpRight
442 {
443 .pDistance += evp.loc.width - .Width
444 }
445 case $sfpNone
446 {
447 .pDistance = uint( .pProportion * double( evp.loc.width ) )
448 }
449 }
450 .iUpdateSize()
451 }
452 */
453 /*Виртуальный метод vToolBar.mMouse
454 Сообщения от мышки
455 */
456 /*method uint vToolBar.mMouse <alias=vToolBar_mMouse> ( evparMouse ev )
457 {
458 switch ev.evmtype
459 {
460 case $evmMove
461 {
462 if .fDrag
463 {
464 .Distance = ?( .pOrientation == $soVertical, ev.x, ev.y )
465 }
466 }
467 case $evmLDown
468 {
469 if !.fDrag
470 {
471 .fDrag = 1
472 SetCapture( .hwnd )
473 }
474 }
475 case $evmLUp
476 {
477 if .fDrag : ReleaseCapture()
478 }
479 }
480
481 if .pOrientation == $soVertical
482 {
483 if ev.x > .pDistance && ev.x <= .pDistance + .pToolBarWidth
484 {
485 SetCursor( App.cursorSizeWE )
486 }
487 }
488 else
489 {
490 if ev.y > .pDistance && ev.y <= .pDistance + .pToolBarWidth
491 {
492 SetCursor( App.cursorSizeNS )
493 }
494 }
495 return this->vCtrl.mMouse( ev )
496 }
497 */
498
499 /*------------------------------------------------------------------------------
500 Windows messages
501 */
502
503 /*------------------------------------------------------------------------------
504 Registration
505 */
506 /*Системный метод vToolBar vToolBar.init
507 Инициализация объекта
508 */
509 method vToolBar vToolBar.init( )
510 {
511 this.pTypeId = vToolBar
512 this.pCanContain = 1
513 this.loc.width = 200
514 this.loc.height = 100
515 return this
516 }
517
518 method vToolBarItem vToolBarItem.init( )
519 {
520 this.pTypeId = vToolBarItem
521 this.loc.left = 0
522 this.loc.top = 0
523 this.loc.width = 100
524 this.loc.height = 100
525 this.pImageIndex = -1
526 return this
527 }
528
529 //Функция регистрации
530 func init_vToolBar <entry>()
531 {
532 regcomp( vToolBar, "vToolBar", vCtrl, $vCtrl_last,
533 %{ %{$mCreateWin, vToolBar_mCreateWin},
534 %{$mReCreateWin,vToolBar_mReCreateWin},
535 %{$mInsert, vToolBar_mInsert },
536 %{$mRemove, vToolBar_mRemove },
537 %{$mLangChanged,vToolBar_mLangChanged},
538 %{$mWinNtf, vToolBar_mWinNtf },
539 %{$mGetHint, vToolBar_mGetHint },
540 %{$mWinCmd, vToolBar_mWinCmd }
541 },
542 0->collection
543 /*%{ %{$WM_CAPTURECHANGED, vToolBar_wmcapturechanged }
544 }*/)
545
546 regcomp( vToolBarItem, "vToolBarItem", vVirtCtrl, $vVirtCtrl_last,
547 %{ %{$mCreateWin, vToolBarItem_mCreateWin},
548 %{$mPosUpdate, vToolBarItem_mPosUpdate},
549 %{$mSetVisible, vToolBarItem_mSetVisible},
550 %{$mSetEnabled, vToolBarItem_mSetEnabled},
551 %{$mLangChanged,vToolBarItem_mLangChanged},
552 %{$mSetName, vToolBarItem_mSetName}
553 },
554 //0->collection,
555 0->collection
556 /*%{ %{$WM_CAPTURECHANGED, vToolBar_wmcapturechanged }
557 }*/)
558
559 ifdef $DESIGNING {
560 cm.AddComp( vToolBar, 1, "Windows", "toolbar" )
561 cm.AddProps( vToolBar, %{
562 "ImageList", ustr, 0,
563 "ShowCaption", uint, 0,
564 "Wrapable", uint, 0,
565 "ShowDivider", uint, 0,
566 "AutoSize", uint, 0
567 })
568
569 cm.AddPropVals( vToolBar, "ShowCaption", %{
570 "tscNone", $tscNone,
571 "tscRight", $tscRight,
572 "tscBottom",$tscBottom/*,
573 "tscAsHint",$tscAsHint*/
574 })
575
576 cm.AddComp( vToolBarItem )
577 cm.AddProps( vToolBarItem, %{
578 "TBIStyle", uint, 0,
579 "Caption", ustr, 0,
580 "Checked", uint, 0,
581 "ImageId", ustr, 0,
582 "DropDownMenu", vPopupMenu, $PROP_LOADAFTERCREATE
583 })
584
585 cm.AddPropVals( vToolBarItem, "TBIStyle", %{
586 "tbsButton", $tbsButton,
587 "tbsSeparator", $tbsSeparator,
588 "tbsDropDown", $tbsDropDown,
589 "tbsAsCheckBox", $tbsAsCheckBox,
590 "tbsAsRadioBtn", $tbsAsRadioBtn
591 })
592
593 cm.AddEvents( vToolBarItem, %{
594 "OnClick" , "evparEvent"
595 })
596 }
597
598 }