EnglishРусский  

   ..

   addustr.g

   app.g

   btn.g

   btnpic.g

   comp.g

   ctrl.g

   ctrlci.g

   dialogs.g

   dlgbtns.g

   edit.g

   events.g

   fonts.g

   form.g

   gray.g

   grey.g

   header.g

   images.g

   label.g

   labeled.g

   locustr.g

   menu.g

   panel.g

   picture.g

   styles.g

   tab.g

   tabitem.g

   tabpage.g

   timer.g

   toolbar.g

   tray.g

   url.g

   vis.g

   viswin.g

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

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