1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE 
  18     #include "wx/settings.h" 
  19     #include "wx/window.h" 
  22     #include "wx/dcclient.h" 
  23     #include "wx/dcmemory.h" 
  26 #include "wx/tooltip.h" 
  27 #include "wx/toolbar.h" 
  29 bool                                wxToolBar::m_bInitialized 
= FALSE
; 
  31 // ---------------------------------------------------------------------------- 
  33 // ---------------------------------------------------------------------------- 
  35 class wxToolBarTool 
: public wxToolBarToolBase
 
  38     inline wxToolBarTool( wxToolBar
*      pTbar
 
  40                          ,const wxString
& rsLabel
 
  41                          ,const wxBitmap
& rBitmap1
 
  42                          ,const wxBitmap
& rBitmap2
 
  44                          ,wxObject
*       pClientData
 
  45                          ,const wxString
& rsShortHelpString
 
  46                          ,const wxString
& rsLongHelpString
 
  47                         ) : wxToolBarToolBase( pTbar
 
  60     inline wxToolBarTool( wxToolBar
* pTbar
 
  62                         ) : wxToolBarToolBase( pTbar
 
  68     void SetSize(const wxSize
& rSize
) 
  74     wxCoord 
GetWidth(void) const { return m_vWidth
; } 
  75     wxCoord 
GetHeight(void) const { return m_vHeight
; } 
  81 }; // end of CLASS wxToolBarTool 
  83 // ---------------------------------------------------------------------------- 
  85 // ---------------------------------------------------------------------------- 
  87 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
) 
  89 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
) 
  90     EVT_SIZE(wxToolBar::OnSize
) 
  91     EVT_PAINT(wxToolBar::OnPaint
) 
  92     EVT_KILL_FOCUS(wxToolBar::OnKillFocus
) 
  93     EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
) 
  94     EVT_TIMER(-1, wxToolBar::OnTimer
) 
  97 // ============================================================================ 
  99 // ============================================================================ 
 101 // ---------------------------------------------------------------------------- 
 102 // tool bar tools creation 
 103 // ---------------------------------------------------------------------------- 
 105 wxToolBarToolBase
* wxToolBar::CreateTool( 
 107 , const wxString
&                   rsLabel
 
 108 , const wxBitmap
&                   rBmpNormal
 
 109 , const wxBitmap
&                   rBmpDisabled
 
 111 , wxObject
*                         pClientData
 
 112 , const wxString
&                   rsShortHelp
 
 113 , const wxString
&                   rsLongHelp
 
 116     return new wxToolBarTool( this 
 126 } // end of wxToolBarSimple::CreateTool 
 128 wxToolBarToolBase 
*wxToolBar::CreateTool( 
 132     return new wxToolBarTool( this 
 135 } // end of wxToolBarSimple::CreateTool 
 137 // ---------------------------------------------------------------------------- 
 138 // wxToolBarSimple creation 
 139 // ---------------------------------------------------------------------------- 
 141 void wxToolBar::Init() 
 143     m_nCurrentRowsOrColumns 
= 0; 
 145     m_vLastX 
= m_vLastY 
= 0; 
 146     m_vMaxWidth 
= m_vMaxHeight 
= 0; 
 147     m_nPressedTool 
= m_nCurrentTool 
= -1; 
 148     m_vXPos 
= m_vYPos 
= -1; 
 149     m_vTextX 
= m_vTextY 
= 0; 
 152     m_toolSeparation 
= 5; 
 155     m_defaultHeight 
= 15; 
 158 } // end of wxToolBar::Init 
 160 wxToolBarToolBase
* wxToolBar::DoAddTool( 
 162 , const wxString
&                   rsLabel
 
 163 , const wxBitmap
&                   rBitmap
 
 164 , const wxBitmap
&                   rBmpDisabled
 
 166 , const wxString
&                   rsShortHelp
 
 167 , const wxString
&                   rsLongHelp
 
 168 , wxObject
*                         pClientData
 
 174     // Rememeber the position for DoInsertTool() 
 179     return wxToolBarBase::DoAddTool( vId
 
 190 } // end of wxToolBar::DoAddTool 
 192 bool wxToolBar::DeleteTool( 
 196     bool                            bOk 
= wxToolBarBase::DeleteTool(nId
); 
 203 } // end of wxToolBar::DeleteTool 
 205 bool wxToolBar::DeleteToolByPos( 
 209     bool                            bOk 
= wxToolBarBase::DeleteToolByPos(nPos
); 
 216 } // end of wxToolBar::DeleteTool 
 218 wxToolBarToolBase
* wxToolBar::InsertControl( 
 220 , wxControl
*                        pControl
 
 223     wxToolBarToolBase
*              pTool 
= wxToolBarBase::InsertControl( nPos
 
 232 } // end of wxToolBar::InsertControl 
 234 wxToolBarToolBase
* wxToolBar::InsertSeparator( 
 238     wxToolBarToolBase
*              pTool 
= wxToolBarBase::InsertSeparator(nPos
); 
 246 } // end of wxToolBar::InsertSeparator 
 248 wxToolBarToolBase
* wxToolBar::InsertTool( 
 251 , const wxString
&                   rsLabel
 
 252 , const wxBitmap
&                   rBitmap
 
 253 , const wxBitmap
&                   rBmpDisabled
 
 255 , const wxString
&                   rsShortHelp
 
 256 , const wxString
&                   rsLongHelp
 
 257 , wxObject
*                         pClientData
 
 260     wxToolBarToolBase
*              pTool 
= wxToolBarBase::InsertTool( nPos
 
 276 } // end of wxToolBar::InsertTool 
 278 bool wxToolBar::DoInsertTool( 
 279   size_t                            WXUNUSED(nPos
) 
 280 , wxToolBarToolBase
*                pToolBase
 
 283     wxToolBarTool
*                  pTool 
= (wxToolBarTool 
*)pToolBase
; 
 285     pTool
->m_vX 
= m_vXPos
; 
 286     if (pTool
->m_vX 
== -1) 
 287         pTool
->m_vX 
= m_xMargin
; 
 289     pTool
->m_vY 
= m_vYPos
; 
 290     if (pTool
->m_vY 
== -1) 
 291         pTool
->m_vX 
= m_yMargin
; 
 293     pTool
->SetSize(GetToolSize()); 
 295     if (pTool
->IsButton()) 
 298         // Calculate reasonable max size in case Layout() not called 
 300         if ((pTool
->m_vX 
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
) 
 301             m_vMaxWidth 
= (wxCoord
)((pTool
->m_vX 
+ pTool
->GetWidth() + m_xMargin
)); 
 303         if ((pTool
->m_vY 
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
) 
 304             m_vMaxHeight 
= (wxCoord
)((pTool
->m_vY 
+ pTool
->GetHeight() + m_yMargin
)); 
 307 } // end of wxToolBar::DoInsertTool 
 309 bool wxToolBar::DoDeleteTool( 
 310   size_t                            WXUNUSED(nPos
) 
 311 , wxToolBarToolBase
*                pTool
 
 317 } // end of wxToolBar::DoDeleteTool 
 319 bool wxToolBar::Create( 
 322 , const wxPoint
&                    rPos
 
 323 , const wxSize
&                     rSize
 
 325 , const wxString
&                   rsName
 
 328     if ( !wxWindow::Create( pParent
 
 337     // Set it to grey (or other 3D face colour) 
 338     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
)); 
 339     SetFont(*wxSMALL_FONT
); 
 341     if (GetWindowStyleFlag() & wxTB_VERTICAL
) 
 346         m_maxRows 
= 32000;      // a lot 
 355         m_maxCols 
= 32000;      // a lot 
 357     SetCursor(*wxSTANDARD_CURSOR
); 
 360     // The toolbar's tools, if they have labels and the winTB_TEXT 
 361     // style is set, then we need to take into account the size of 
 362     // the text when drawing tool bitmaps and the text 
 364     if (HasFlag(wxTB_TEXT
)) 
 366         wxClientDC                  
vDC(this); 
 368         vDC
.SetFont(GetFont()); 
 369         vDC
.GetTextExtent( wxT("XXXX") 
 380     int                             nWidth  
= rSize
.x
; 
 381     int                             nHeight 
= rSize
.y
; 
 383     if (lStyle 
& wxTB_HORIZONTAL
) 
 387             nWidth 
= pParent
->GetClientSize().x
; 
 391             if (lStyle 
& wxTB_TEXT
) 
 392                 nHeight 
= m_defaultHeight 
+ m_vTextY
; 
 394                 nHeight 
= m_defaultHeight
; 
 401             nHeight 
= pParent
->GetClientSize().y
; 
 405             if (lStyle 
& wxTB_TEXT
) 
 406                 nWidth 
= m_vTextX 
+ (int)(m_vTextX
/2); // a little margin 
 408                 nWidth 
= m_defaultWidth 
+ (int)(m_defaultWidth
/2); // a little margin 
 422 } // end of wxToolBar::Create 
 424 wxToolBar::~wxToolBar() 
 431 } // end of wxToolBar::~wxToolBar 
 433 bool wxToolBar::Realize() 
 435     int                             nMaxToolWidth  
= 0; 
 436     int                             nMaxToolHeight 
= 0; 
 438     m_nCurrentRowsOrColumns 
= 0; 
 439     m_vLastX               
= m_xMargin
; 
 440     m_vLastY               
= m_yMargin
; 
 446     // Find the maximum tool width and height 
 448     wxToolBarToolsList::compatibility_iterator     node 
= m_tools
.GetFirst(); 
 452         wxToolBarTool
*              pTool 
= (wxToolBarTool 
*)node
->GetData(); 
 454         if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty()) 
 457             // Set the height according to the font and the border size 
 459             if (pTool
->GetWidth() > m_vTextX
) 
 460                 nMaxToolWidth 
= pTool
->GetWidth() + 4; 
 462                 nMaxToolWidth 
= m_vTextX
; 
 463             if (pTool
->GetHeight() + m_vTextY 
> nMaxToolHeight
) 
 464                 nMaxToolHeight 
= pTool
->GetHeight() + m_vTextY
; 
 468             if (pTool
->GetWidth() > nMaxToolWidth 
) 
 469                 nMaxToolWidth 
= pTool
->GetWidth() + 4; 
 470             if (pTool
->GetHeight() > nMaxToolHeight
) 
 471                 nMaxToolHeight 
= pTool
->GetHeight(); 
 473         node 
= node
->GetNext(); 
 476     wxCoord                         vTbWidth 
= 0L; 
 477     wxCoord                         vTbHeight 
= 0L; 
 482     if (vTbHeight 
< nMaxToolHeight
) 
 489         if (GetParent()->IsKindOf(CLASSINFO(wxFrame
))) 
 491             wxFrame
*            pFrame 
= wxDynamicCast(GetParent(), wxFrame
); 
 494                 pFrame
->PositionToolBar(); 
 498     int                             nSeparatorSize 
= m_toolSeparation
; 
 500     node 
= m_tools
.GetFirst(); 
 503         wxToolBarTool
*              pTool 
= (wxToolBarTool 
*)node
->GetData(); 
 505         if (pTool
->IsSeparator()) 
 507             if (GetWindowStyleFlag() & wxTB_HORIZONTAL
) 
 509                 pTool
->m_vX 
= m_vLastX 
+ nSeparatorSize
; 
 510                 pTool
->m_vHeight 
= m_defaultHeight 
+ m_vTextY
; 
 511                 if (m_nCurrentRowsOrColumns 
>= m_maxCols
) 
 512                     m_vLastY 
+= nSeparatorSize
; 
 514                     m_vLastX 
+= nSeparatorSize 
* 4; 
 518                 pTool
->m_vY 
= m_vLastY 
+ nSeparatorSize
; 
 519                 pTool
->m_vHeight 
= m_defaultHeight 
+ m_vTextY
; 
 520                 if (m_nCurrentRowsOrColumns 
>= m_maxRows
) 
 521                     m_vLastX 
+= nSeparatorSize
; 
 523                     m_vLastY 
+= nSeparatorSize 
* 4; 
 526         else if (pTool
->IsButton()) 
 528             if (GetWindowStyleFlag() & wxTB_HORIZONTAL
) 
 530                 if (m_nCurrentRowsOrColumns 
>= m_maxCols
) 
 532                     m_nCurrentRowsOrColumns 
= 0; 
 533                     m_vLastX                
= m_xMargin
; 
 534                     m_vLastY               
+= nMaxToolHeight 
+ m_toolPacking
; 
 536                 pTool
->m_vX 
= m_vLastX 
+ (nMaxToolWidth 
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2))); 
 537                 if (HasFlag(wxTB_TEXT
)) 
 538                     pTool
->m_vY 
= m_vLastY 
+ nSeparatorSize 
- 2; // just bit of adjustment 
 540                     pTool
->m_vY 
= m_vLastY 
+ (nMaxToolHeight 
- (int)(pTool
->GetHeight()/2)); 
 541                 m_vLastX 
+= nMaxToolWidth 
+ m_toolPacking 
+ m_toolSeparation
; 
 545                 if (m_nCurrentRowsOrColumns 
>= m_maxRows
) 
 547                     m_nCurrentRowsOrColumns 
= 0; 
 548                     m_vLastX               
+= (nMaxToolWidth 
+ m_toolPacking
); 
 549                     m_vLastY                
= m_yMargin
; 
 551                 pTool
->m_vX 
= m_vLastX 
+ pTool
->GetWidth(); 
 552                 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull()) 
 553                     pTool
->m_vY 
= m_vLastY 
+ (nMaxToolHeight 
- m_vTextY
) + m_toolPacking
; 
 555                     pTool
->m_vY 
= m_vLastY 
+ (nMaxToolHeight 
- (int)(pTool
->GetHeight()/2)); 
 556                 m_vLastY 
+= nMaxToolHeight 
+ m_toolPacking 
+ m_toolSeparation
; 
 558             m_nCurrentRowsOrColumns
++; 
 562             // TODO: support the controls 
 565         if (m_vLastX 
> m_maxWidth
) 
 566             m_maxWidth 
= m_vLastX
; 
 567         if (m_vLastY 
> m_maxHeight
) 
 568             m_maxHeight 
= m_vLastY
; 
 570         node 
= node
->GetNext(); 
 573     if ( GetWindowStyleFlag() & wxTB_HORIZONTAL 
) 
 574         m_maxWidth 
+= nMaxToolWidth
; 
 576         m_maxHeight 
+= nMaxToolHeight
; 
 578     m_maxWidth 
+= m_xMargin
; 
 579     m_maxHeight 
+= m_yMargin
; 
 580     m_bInitialized 
= TRUE
; 
 582 } // end of wxToolBar::Realize 
 584 // ---------------------------------------------------------------------------- 
 586 // ---------------------------------------------------------------------------- 
 588 void wxToolBar::OnPaint ( 
 589   wxPaintEvent
&                     WXUNUSED(rEvent
) 
 596     static int                      nCount 
= 0; 
 599     // Prevent reentry of OnPaint which would cause wxMemoryDC errors. 
 605     ::WinFillRect(vDc
.GetHPS(), &vDc
.m_vRclPaint
, GetBackgroundColour().GetPixel()); 
 606     for ( wxToolBarToolsList::compatibility_iterator node 
= m_tools
.GetFirst(); 
 608           node 
= node
->GetNext() ) 
 610         wxToolBarTool
*              pTool 
= (wxToolBarTool
*)node
->GetData(); 
 612         if (pTool
->IsButton() ) 
 613             DrawTool(vDc
, pTool
); 
 614         if (pTool
->IsSeparator()) 
 616             wxColour 
gray85(85, 85, 85); 
 617             wxPen 
vDarkGreyPen( gray85
, 1, wxSOLID 
); 
 623             vDc
.SetPen(vDarkGreyPen
); 
 624             if (HasFlag(wxTB_TEXT
)) 
 626                 if (HasFlag(wxTB_HORIZONTAL
)) 
 629                     nY 
= pTool
->m_vY 
- (m_vTextY 
- 6); 
 630                     nHeight 
= (m_vTextY 
- 2) + pTool
->GetHeight(); 
 634                     nX 
= pTool
->m_vX 
+ m_xMargin 
+ 10; 
 635                     nY 
= pTool
->m_vY 
+ m_vTextY 
+ m_toolSeparation
; 
 636                     nWidth 
= pTool
->GetWidth() > m_vTextX 
? pTool
->GetWidth() : m_vTextX
; 
 643                 if (HasFlag(wxTB_HORIZONTAL
)) 
 644                     nHeight 
= pTool
->GetHeight() - 2; 
 647                     nX 
+= m_xMargin 
+ 10; 
 648                     nY 
+=  m_yMargin 
+ m_toolSeparation
; 
 649                     nWidth 
= pTool
->GetWidth(); 
 652             vDc
.DrawLine(nX
, nY
, nX 
+ nWidth
, nY 
+ nHeight
); 
 656 } // end of wxToolBar::OnPaint 
 658 void wxToolBar::OnSize ( 
 659   wxSizeEvent
&                      WXUNUSED(rEvent
) 
 662 #if wxUSE_CONSTRAINTS 
 666 } // end of wxToolBar::OnSize 
 668 void wxToolBar::OnKillFocus( 
 669   wxFocusEvent
&                     WXUNUSED(rEvent
) 
 672     OnMouseEnter(m_nPressedTool 
= m_nCurrentTool 
= -1); 
 673 } // end of wxToolBar::OnKillFocus 
 675 void wxToolBar::OnMouseEvent( 
 683     HPOINTER                        hPtr 
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
); 
 685     ::WinSetPointer(HWND_DESKTOP
, hPtr
); 
 686     ::WinQueryPointerPos(HWND_DESKTOP
, &vPoint
); 
 687     hWnd 
= ::WinWindowFromPoint(HWND_DESKTOP
, &vPoint
, TRUE
); 
 688     if (hWnd 
!= (HWND
)GetHwnd()) 
 694     rEvent
.GetPosition(&vX
, &vY
); 
 696     wxToolBarTool
*            pTool 
= (wxToolBarTool 
*)FindToolForPosition( vX
 
 700     if (rEvent
.LeftDown()) 
 712         if (m_nCurrentTool 
> -1) 
 714             if (rEvent
.LeftIsDown()) 
 715                 SpringUpButton(m_nCurrentTool
); 
 716             pTool 
= (wxToolBarTool 
*)FindById(m_nCurrentTool
); 
 717             if (pTool 
&& !pTool
->IsToggled()) 
 728     if (!rEvent
.IsButton()) 
 730         if (pTool
->GetId() != m_nCurrentTool
) 
 733             // If the left button is kept down and moved over buttons, 
 734             // press those buttons. 
 736             if (rEvent
.LeftIsDown() && pTool
->IsEnabled()) 
 738                 SpringUpButton(m_nCurrentTool
); 
 739                 if (pTool
->CanBeToggled()) 
 745             wxToolBarTool
*          pOldTool 
= (wxToolBarTool
*)FindById(m_nCurrentTool
); 
 747             if (pOldTool 
&& !pTool
->IsToggled()) 
 751             m_nCurrentTool 
= pTool
->GetId(); 
 752             OnMouseEnter(m_nCurrentTool
); 
 753             if (!pTool
->GetShortHelp().empty()) 
 757                 m_pToolTip 
= new wxToolTip(pTool
->GetShortHelp()); 
 758                 m_vXMouse 
= (wxCoord
)vPoint
.x
; 
 759                 m_vYMouse 
= (wxCoord
)vPoint
.y
; 
 760                 m_vToolTimer
.Start(1000L, TRUE
); 
 762             if (!pTool
->IsToggled()) 
 768     // Left button pressed. 
 769     if (rEvent
.LeftDown() && pTool
->IsEnabled()) 
 771         if (pTool
->CanBeToggled()) 
 777     else if (rEvent
.RightDown()) 
 779         OnRightClick( pTool
->GetId() 
 786     // Left Button Released.  Only this action confirms selection. 
 787     // If the button is enabled and it is not a toggle tool and it is 
 788     // in the pressed state, then raise the button and call OnLeftClick. 
 790     if (rEvent
.LeftUp() && pTool
->IsEnabled() ) 
 793         // Pass the OnLeftClick event to tool 
 795         if (!OnLeftClick( pTool
->GetId() 
 796                          ,pTool
->IsToggled()) && 
 797                           pTool
->CanBeToggled()) 
 800             // If it was a toggle, and OnLeftClick says No Toggle allowed, 
 801             // then change it back 
 807 } // end of wxToolBar::OnMouseEvent 
 809 // ---------------------------------------------------------------------------- 
 811 // ---------------------------------------------------------------------------- 
 813 void wxToolBar::DrawTool( 
 814   wxToolBarToolBase
*                pTool
 
 817     wxClientDC                      
vDc(this); 
 822 } // end of wxToolBar::DrawTool 
 824 void wxToolBar::DrawTool( 
 826 , wxToolBarToolBase
*                pToolBase
 
 829     wxToolBarTool
* pTool 
= (wxToolBarTool 
*)pToolBase
; 
 830     wxColour 
gray85( 85,85,85 ); 
 831     wxPen 
vDarkGreyPen( gray85
, 1, wxSOLID 
); 
 832     wxBitmap vBitmap 
= pTool
->GetNormalBitmap(); 
 833     bool bUseMask 
= FALSE
; 
 834     wxMask
* pMask 
= NULL
; 
 840     if ((pMask 
= vBitmap
.GetMask()) != NULL
) 
 841         if (pMask
->GetMaskBitmap() != NULLHANDLE
) 
 844     if (!pTool
->IsToggled()) 
 846         LowerTool(pTool
, FALSE
); 
 847         if (!pTool
->IsEnabled()) 
 849             wxColour 
vColor(wxT("GREY")); 
 851             rDc
.SetTextForeground(vColor
); 
 852             if (!pTool
->GetDisabledBitmap().Ok()) 
 853                 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
 
 854                                                          ,(long)GetBackgroundColour().GetPixel() 
 856             rDc
.DrawBitmap( pTool
->GetDisabledBitmap() 
 864             rDc
.SetTextForeground(*wxBLACK
); 
 865             rDc
.DrawBitmap( vBitmap
 
 871         if (m_windowStyle 
& wxTB_3DBUTTONS
) 
 875         if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull()) 
 879             wxCoord                 vLeft 
= pTool
->m_vX 
- (int)(pTool
->GetWidth()/2); 
 881             rDc
.SetFont(GetFont()); 
 882             rDc
.GetTextExtent( pTool
->GetLabel() 
 886             if (pTool
->GetWidth() > vX
) // large tools 
 888                 vLeft 
= pTool
->m_vX 
+ (pTool
->GetWidth() - vX
); 
 890                 rDc
.DrawText( pTool
->GetLabel() 
 897                 vLeft 
+= (wxCoord
)((m_vTextX 
- vX
)/2); 
 898                 rDc
.DrawText( pTool
->GetLabel() 
 900                              ,pTool
->m_vY 
+ m_vTextY 
+ 4 // a bit of margin 
 907         wxColour 
vColor(wxT("GREY")); 
 910         rDc
.SetTextForeground(vColor
); 
 911         if (!pTool
->GetDisabledBitmap().Ok()) 
 912             pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
 
 913                                                      ,(long)GetBackgroundColour().GetPixel() 
 915         rDc
.DrawBitmap( pTool
->GetDisabledBitmap() 
 920         if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull()) 
 924             wxCoord                 vLeft 
= pTool
->m_vX 
- (int)(pTool
->GetWidth()/2); 
 926             rDc
.SetFont(GetFont()); 
 927             rDc
.GetTextExtent( pTool
->GetLabel() 
 931             vLeft 
+= (wxCoord
)((m_vTextX 
- vX
)/2); 
 932             rDc
.DrawText( pTool
->GetLabel() 
 934                          ,pTool
->m_vY 
+ m_vTextY 
+ 4 // a bit of margin 
 938 } // end of wxToolBar::DrawTool 
 940 // ---------------------------------------------------------------------------- 
 942 // ---------------------------------------------------------------------------- 
 944 void wxToolBar::SetRows( 
 948     wxCHECK_RET( nRows 
!= 0, _T("max number of rows must be > 0") ); 
 950     m_maxCols 
= (GetToolsCount() + nRows 
- 1) / nRows
; 
 952 } // end of wxToolBar::SetRows 
 954 wxToolBarToolBase
* wxToolBar::FindToolForPosition( 
 959     wxCoord                         vTBarHeight 
= 0; 
 964     vY 
= vTBarHeight 
- vY
; 
 965     wxToolBarToolsList::compatibility_iterator node 
= m_tools
.GetFirst(); 
 968         wxToolBarTool
*              pTool 
= (wxToolBarTool 
*)node
->GetData(); 
 970         if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull()) 
 972             if ((vX 
>= (pTool
->m_vX 
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) && 
 973                 (vY 
>= (pTool
->m_vY 
- 2)) && 
 974                 (vX 
<= (pTool
->m_vX 
+ pTool
->GetWidth())) && 
 975                 (vY 
<= (pTool
->m_vY 
+ pTool
->GetHeight() + m_vTextY 
+ 2))) 
 982             if ((vX 
>= pTool
->m_vX
) && 
 983                 (vY 
>= pTool
->m_vY
) && 
 984                 (vX 
<= (pTool
->m_vX 
+ pTool
->GetWidth())) && 
 985                 (vY 
<= (pTool
->m_vY 
+ pTool
->GetHeight()))) 
 990         node 
= node
->GetNext(); 
 992     return (wxToolBarToolBase 
*)NULL
; 
 993 } // end of wxToolBar::FindToolForPosition 
 995 // ---------------------------------------------------------------------------- 
 996 // tool state change handlers 
 997 // ---------------------------------------------------------------------------- 
 999 void wxToolBar::DoEnableTool( 
1000   wxToolBarToolBase
*                pTool
 
1001 , bool                              WXUNUSED(bEnable
) 
1005 } // end of wxToolBar::DoEnableTool 
1007 void wxToolBar::DoToggleTool( 
1008   wxToolBarToolBase
*                pTool
 
1009 , bool                              WXUNUSED(bToggle
) 
1013 } // end of wxToolBar::DoToggleTool 
1015 void wxToolBar::DoSetToggle( 
1016   wxToolBarToolBase
*                WXUNUSED(pTool
) 
1017 , bool                              WXUNUSED(bToggle
) 
1021 } // end of wxToolBar::DoSetToggle 
1024 // Okay, so we've left the tool we're in ... we must check if the tool we're 
1025 // leaving was a 'sprung push button' and if so, spring it back to the up 
1028 void wxToolBar::SpringUpButton( 
1032     wxToolBarToolBase
*              pTool 
= FindById(vId
); 
1034     if (pTool 
&& pTool
->CanBeToggled()) 
1036         if (pTool
->IsToggled()) 
1041 } // end of wxToolBar::SpringUpButton 
1043 // ---------------------------------------------------------------------------- 
1045 // ---------------------------------------------------------------------------- 
1047 void wxToolBar::LowerTool ( wxToolBarToolBase
* pToolBase
, 
1050     wxToolBarTool
*                  pTool 
= (wxToolBarTool
*)pToolBase
; 
1055     wxColour 
gray85( 85,85,85 ); 
1056     wxPen 
vDarkGreyPen( gray85
, 1, wxSOLID 
); 
1057     wxPen 
vClearPen( GetBackgroundColour(), 1, wxSOLID 
); 
1058     wxClientDC 
vDC(this); 
1063     if (pTool
->IsSeparator()) 
1067     // We only do this for flat toolbars 
1069     if (!HasFlag(wxTB_FLAT
)) 
1072     if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty()) 
1074         if (pTool
->GetWidth() > m_vTextX
) 
1076             vX 
= pTool
->m_vX 
- 2; 
1077             vWidth 
= pTool
->GetWidth() + 4; 
1081             vX 
= pTool
->m_vX 
- (wxCoord
)(pTool
->GetWidth()/2); 
1082             vWidth 
= m_vTextX 
+ 4; 
1084         vY 
= pTool
->m_vY 
- 2; 
1085         vHeight 
= pTool
->GetHeight() + m_vTextY 
+ 2; 
1089         vX 
= pTool
->m_vX 
- 2; 
1090         vY 
= pTool
->m_vY 
- 2; 
1091         vWidth 
= pTool
->GetWidth() + 4; 
1092         vHeight 
= pTool
->GetHeight() + 4; 
1096         vDC
.SetPen(*wxWHITE_PEN
); 
1097         vDC
.DrawLine(vX 
+ vWidth
, vY 
+ vHeight
, vX
, vY 
+ vHeight
); 
1098         vDC
.DrawLine(vX 
+ vWidth
, vY
, vX 
+ vWidth
, vY 
+ vHeight
); 
1099         vDC
.SetPen(vDarkGreyPen
); 
1100         vDC
.DrawLine(vX
, vY
, vX 
+ vWidth
, vY
); 
1101         vDC
.DrawLine(vX
, vY 
+ vHeight
, vX
, vY
); 
1105         vDC
.SetPen(vClearPen
); 
1106         vDC
.DrawLine(vX 
+ vWidth
, vY 
+ vHeight
, vX
, vY 
+ vHeight
); 
1107         vDC
.DrawLine(vX 
+ vWidth
, vY
, vX 
+ vWidth
, vY 
+ vHeight
); 
1108         vDC
.DrawLine(vX
, vY
, vX 
+ vWidth
, vY
); 
1109         vDC
.DrawLine(vX
, vY 
+ vHeight
, vX
, vY
); 
1111 } // end of WinGuiBase_CToolBarTool::LowerTool 
1113 void wxToolBar::RaiseTool ( wxToolBarToolBase
* pToolBase
, 
1116     wxToolBarTool
* pTool 
= (wxToolBarTool
*)pToolBase
; 
1121     wxColour 
gray85( 85,85,85 ); 
1122     wxPen 
vDarkGreyPen( gray85
, 1, wxSOLID 
); 
1123     wxPen 
vClearPen( GetBackgroundColour(), 1, wxSOLID 
); 
1124     wxClientDC 
vDC(this); 
1129     if (pTool
->IsSeparator()) 
1132     if (!pTool
->IsEnabled()) 
1136     // We only do this for flat toolbars 
1138     if (!HasFlag(wxTB_FLAT
)) 
1141     if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty()) 
1143         if (pTool
->GetWidth() > m_vTextX
) 
1145             vX 
= pTool
->m_vX 
- 2; 
1146             vWidth 
= pTool
->GetWidth() + 4; 
1150             vX 
= pTool
->m_vX 
- (wxCoord
)(pTool
->GetWidth()/2); 
1151             vWidth 
= m_vTextX 
+ 4; 
1153         vY 
= pTool
->m_vY 
- 2; 
1154         vHeight 
= pTool
->GetHeight() + m_vTextY 
+ 2; 
1158         vX 
= pTool
->m_vX 
- 2; 
1159         vY 
= pTool
->m_vY 
- 2; 
1160         vWidth 
= pTool
->GetWidth() + 4; 
1161         vHeight 
= pTool
->GetHeight() + 4; 
1165         vDC
.SetPen(vDarkGreyPen
); 
1166         vDC
.DrawLine(vX 
+ vWidth
, vY 
+ vHeight
, vX
, vY 
+ vHeight
); 
1167         vDC
.DrawLine(vX 
+ vWidth
, vY
, vX 
+ vWidth
, vY 
+ vHeight
); 
1168         vDC
.SetPen(*wxWHITE_PEN
); 
1169         vDC
.DrawLine(vX
, vY
, vX 
+ vWidth
, vY
); 
1170         vDC
.DrawLine(vX
, vY 
+ vHeight
, vX
, vY
); 
1174         vDC
.SetPen(vClearPen
); 
1175         vDC
.DrawLine(vX 
+ vWidth
, vY 
+ vHeight
, vX
, vY 
+ vHeight
); 
1176         vDC
.DrawLine(vX 
+ vWidth
, vY
, vX 
+ vWidth
, vY 
+ vHeight
); 
1177         vDC
.DrawLine(vX
, vY
, vX 
+ vWidth
, vY
); 
1178         vDC
.DrawLine(vX
, vY 
+ vHeight
, vX
, vY
); 
1180 } // end of wxToolBar::RaiseTool 
1182 void wxToolBar::OnTimer ( 
1183   wxTimerEvent
&                     rEvent
 
1186     if (rEvent
.GetId() == m_vToolTimer
.GetTimerId()) 
1188         wxPoint                     
vPos( m_vXMouse
 
1192         m_pToolTip
->DisplayToolTipWindow(vPos
); 
1193         m_vToolTimer
.Stop(); 
1194         m_vToolExpTimer
.Start(4000L, TRUE
); 
1196     else if (rEvent
.GetId() == m_vToolExpTimer
.GetTimerId()) 
1198         m_pToolTip
->HideToolTipWindow(); 
1199         GetParent()->Refresh(); 
1200         m_vToolExpTimer
.Stop(); 
1202 } // end of wxToolBar::OnTimer 
1204 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE