1 /////////////////////////////////////////////////////////////////////////////// 
   3 // Name:        src/aui/auibar.cpp 
   4 // Purpose:     wxaui: wx advanced user interface - docking window manager 
   5 // Author:      Benjamin I. Williams 
   9 // Copyright:   (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved 
  10 // Licence:     wxWindows Library Licence, Version 3.1 
  11 /////////////////////////////////////////////////////////////////////////////// 
  13 // ============================================================================ 
  15 // ============================================================================ 
  17 // ---------------------------------------------------------------------------- 
  19 // ---------------------------------------------------------------------------- 
  21 #include "wx/wxprec.h" 
  29 #include "wx/statline.h" 
  30 #include "wx/dcbuffer.h" 
  33 #include "wx/settings.h" 
  36 #include "wx/aui/auibar.h" 
  37 #include "wx/aui/framemanager.h" 
  40 #include "wx/osx/private.h" 
  43 #include "wx/arrimpl.cpp" 
  44 WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray
) 
  47 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent 
); 
  48 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent 
); 
  49 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent 
); 
  50 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent 
); 
  51 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent 
); 
  54 IMPLEMENT_CLASS(wxAuiToolBar
, wxControl
) 
  55 IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent
, wxEvent
) 
  58 // missing wxITEM_* items 
  61     wxITEM_CONTROL 
= wxITEM_MAX
, 
  66 const int BUTTON_DROPDOWN_WIDTH 
= 10; 
  69 wxBitmap 
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
, 
  70                              const wxColour
& color
); 
  72 static wxColor 
GetBaseColor() 
  75 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON 
  76     wxColor baseColour 
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
)); 
  78     wxColor baseColour 
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
); 
  81     // the baseColour is too pale to use as our base colour, 
  82     // so darken it a bit -- 
  83     if ((255-baseColour
.Red()) + 
  84         (255-baseColour
.Green()) + 
  85         (255-baseColour
.Blue()) < 60) 
  87         baseColour 
= baseColour
.ChangeLightness(92); 
  95 class ToolbarCommandCapture 
: public wxEvtHandler
 
  99     ToolbarCommandCapture() { m_lastId 
= 0; } 
 100     int GetCommandId() const { return m_lastId
; } 
 102     bool ProcessEvent(wxEvent
& evt
) 
 104         if (evt
.GetEventType() == wxEVT_MENU
) 
 106             m_lastId 
= evt
.GetId(); 
 110         if (GetNextHandler()) 
 111             return GetNextHandler()->ProcessEvent(evt
); 
 122 static const unsigned char 
 123     DISABLED_TEXT_GREY_HUE 
= wxColour::AlphaBlend(0, 255, 0.4); 
 124 const wxColour 
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
, 
 125                                    DISABLED_TEXT_GREY_HUE
, 
 126                                    DISABLED_TEXT_GREY_HUE
); 
 128 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt() 
 130     m_baseColour 
= GetBaseColor(); 
 133     m_textOrientation 
= wxAUI_TBTOOL_TEXT_BOTTOM
; 
 134     m_highlightColour 
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
); 
 140     wxColor darker1Colour 
= m_baseColour
.ChangeLightness(85); 
 141     wxColor darker2Colour 
= m_baseColour
.ChangeLightness(75); 
 142     wxColor darker3Colour 
= m_baseColour
.ChangeLightness(60); 
 143     wxColor darker4Colour 
= m_baseColour
.ChangeLightness(50); 
 144     wxColor darker5Colour 
= m_baseColour
.ChangeLightness(40); 
 146     m_gripperPen1 
= wxPen(darker5Colour
); 
 147     m_gripperPen2 
= wxPen(darker3Colour
); 
 148     m_gripperPen3 
= *wxWHITE_PEN
; 
 150     static const unsigned char buttonDropdownBits
[] = { 0xe0, 0xf1, 0xfb }; 
 151     static const unsigned char overflowBits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 }; 
 153     m_buttonDropDownBmp 
= wxAuiBitmapFromBits(buttonDropdownBits
, 5, 3, 
 155     m_disabledButtonDropDownBmp 
= wxAuiBitmapFromBits( 
 156                                                 buttonDropdownBits
, 5, 3, 
 157                                                 wxColor(128,128,128)); 
 158     m_overflowBmp 
= wxAuiBitmapFromBits(overflowBits
, 7, 6, *wxBLACK
); 
 159     m_disabledOverflowBmp 
= wxAuiBitmapFromBits(overflowBits
, 7, 6, wxColor(128,128,128)); 
 161     m_font 
= *wxNORMAL_FONT
; 
 164 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt() 
 166     m_font 
= *wxNORMAL_FONT
; 
 170 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone() 
 172     return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
); 
 175 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
) 
 180 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
) 
 185 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
) 
 187     m_textOrientation 
= orientation
; 
 190 unsigned int wxAuiDefaultToolBarArt::GetFlags() 
 195 wxFont 
wxAuiDefaultToolBarArt::GetFont() 
 200 int wxAuiDefaultToolBarArt::GetTextOrientation() 
 202     return m_textOrientation
; 
 205 void wxAuiDefaultToolBarArt::DrawBackground( 
 207                                     wxWindow
* WXUNUSED(wnd
), 
 212     wxColour startColour 
= m_baseColour
.ChangeLightness(150); 
 213     wxColour endColour 
= m_baseColour
.ChangeLightness(90); 
 214     dc
.GradientFillLinear(rect
, startColour
, endColour
, wxSOUTH
); 
 217 void wxAuiDefaultToolBarArt::DrawPlainBackground(wxDC
& dc
, 
 218                                                    wxWindow
* WXUNUSED(wnd
), 
 224     dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)); 
 226     dc
.DrawRectangle(rect
.GetX() - 1, rect
.GetY() - 1, 
 227                      rect
.GetWidth() + 2, rect
.GetHeight() + 1); 
 230 void wxAuiDefaultToolBarArt::DrawLabel( 
 232                                     wxWindow
* WXUNUSED(wnd
), 
 233                                     const wxAuiToolBarItem
& item
, 
 237     dc
.SetTextForeground(*wxBLACK
); 
 239     // we only care about the text height here since the text 
 240     // will get cropped based on the width of the item 
 241     int textWidth 
= 0, textHeight 
= 0; 
 242     dc
.GetTextExtent(wxT("ABCDHgj"), &textWidth
, &textHeight
); 
 244     // set the clipping region 
 245     wxRect clipRect 
= rect
; 
 247     dc
.SetClippingRegion(clipRect
); 
 251     textY 
= rect
.y 
+ (rect
.height
-textHeight
)/2; 
 252     dc
.DrawText(item
.GetLabel(), textX
, textY
); 
 253     dc
.DestroyClippingRegion(); 
 257 void wxAuiDefaultToolBarArt::DrawButton( 
 259                                     wxWindow
* WXUNUSED(wnd
), 
 260                                     const wxAuiToolBarItem
& item
, 
 263     int textWidth 
= 0, textHeight 
= 0; 
 265     if (m_flags 
& wxAUI_TB_TEXT
) 
 271         dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
); 
 273         dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
); 
 276     int bmpX 
= 0, bmpY 
= 0; 
 277     int textX 
= 0, textY 
= 0; 
 279     if (m_textOrientation 
== wxAUI_TBTOOL_TEXT_BOTTOM
) 
 283                 (item
.GetBitmap().GetWidth()/2); 
 286                 ((rect
.height
-textHeight
)/2) - 
 287                 (item
.GetBitmap().GetHeight()/2); 
 289         textX 
= rect
.x 
+ (rect
.width
/2) - (textWidth
/2) + 1; 
 290         textY 
= rect
.y 
+ rect
.height 
- textHeight 
- 1; 
 292     else if (m_textOrientation 
== wxAUI_TBTOOL_TEXT_RIGHT
) 
 298                 (item
.GetBitmap().GetHeight()/2); 
 300         textX 
= bmpX 
+ 3 + item
.GetBitmap().GetWidth(); 
 307     if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)) 
 309         if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
) 
 311             dc
.SetPen(wxPen(m_highlightColour
)); 
 312             dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(150))); 
 313             dc
.DrawRectangle(rect
); 
 315         else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky()) 
 317             dc
.SetPen(wxPen(m_highlightColour
)); 
 318             dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170))); 
 320             // draw an even lighter background for checked item hovers (since 
 321             // the hover background is the same color as the check background) 
 322             if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
) 
 323                 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(180))); 
 325             dc
.DrawRectangle(rect
); 
 327         else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
) 
 329             // it's important to put this code in an else statement after the 
 330             // hover, otherwise hovers won't draw properly for checked items 
 331             dc
.SetPen(wxPen(m_highlightColour
)); 
 332             dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170))); 
 333             dc
.DrawRectangle(rect
); 
 338     if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
) 
 339         bmp 
= item
.GetDisabledBitmap(); 
 341         bmp 
= item
.GetBitmap(); 
 344         dc
.DrawBitmap(bmp
, bmpX
, bmpY
, true); 
 346     // set the item's text color based on if it is disabled 
 347     dc
.SetTextForeground(*wxBLACK
); 
 348     if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
) 
 349         dc
.SetTextForeground(DISABLED_TEXT_COLOR
); 
 351     if ( (m_flags 
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() ) 
 353         dc
.DrawText(item
.GetLabel(), textX
, textY
); 
 358 void wxAuiDefaultToolBarArt::DrawDropDownButton( 
 360                                     wxWindow
* WXUNUSED(wnd
), 
 361                                     const wxAuiToolBarItem
& item
, 
 364     int textWidth 
= 0, textHeight 
= 0, textX 
= 0, textY 
= 0; 
 365     int bmpX 
= 0, bmpY 
= 0, dropBmpX 
= 0, dropBmpY 
= 0; 
 367     wxRect buttonRect 
= wxRect(rect
.x
, 
 369                                 rect
.width
-BUTTON_DROPDOWN_WIDTH
, 
 371     wxRect dropDownRect 
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1, 
 373                                   BUTTON_DROPDOWN_WIDTH
+1, 
 376     if (m_flags 
& wxAUI_TB_TEXT
) 
 381         if (m_flags 
& wxAUI_TB_TEXT
) 
 383             dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
); 
 387         dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
); 
 392     dropBmpX 
= dropDownRect
.x 
+ 
 393                 (dropDownRect
.width
/2) - 
 394                 (m_buttonDropDownBmp
.GetWidth()/2); 
 395     dropBmpY 
= dropDownRect
.y 
+ 
 396                 (dropDownRect
.height
/2) - 
 397                 (m_buttonDropDownBmp
.GetHeight()/2); 
 400     if (m_textOrientation 
== wxAUI_TBTOOL_TEXT_BOTTOM
) 
 402         bmpX 
= buttonRect
.x 
+ 
 403                 (buttonRect
.width
/2) - 
 404                 (item
.GetBitmap().GetWidth()/2); 
 405         bmpY 
= buttonRect
.y 
+ 
 406                 ((buttonRect
.height
-textHeight
)/2) - 
 407                 (item
.GetBitmap().GetHeight()/2); 
 409         textX 
= rect
.x 
+ (rect
.width
/2) - (textWidth
/2) + 1; 
 410         textY 
= rect
.y 
+ rect
.height 
- textHeight 
- 1; 
 412     else if (m_textOrientation 
== wxAUI_TBTOOL_TEXT_RIGHT
) 
 418                 (item
.GetBitmap().GetHeight()/2); 
 420         textX 
= bmpX 
+ 3 + item
.GetBitmap().GetWidth(); 
 427     if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
) 
 429         dc
.SetPen(wxPen(m_highlightColour
)); 
 430         dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(140))); 
 431         dc
.DrawRectangle(buttonRect
); 
 433         dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170))); 
 434         dc
.DrawRectangle(dropDownRect
); 
 436     else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER 
|| 
 439         dc
.SetPen(wxPen(m_highlightColour
)); 
 440         dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170))); 
 441         dc
.DrawRectangle(buttonRect
); 
 442         dc
.DrawRectangle(dropDownRect
); 
 444     else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
) 
 446         // Notice that this branch must come after the hover one to ensure the 
 447         // correct appearance when the mouse hovers over a checked item.m_ 
 448         dc
.SetPen(wxPen(m_highlightColour
)); 
 449         dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170))); 
 450         dc
.DrawRectangle(buttonRect
); 
 451         dc
.DrawRectangle(dropDownRect
); 
 456     if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
) 
 458         bmp 
= item
.GetDisabledBitmap(); 
 459         dropbmp 
= m_disabledButtonDropDownBmp
; 
 463         bmp 
= item
.GetBitmap(); 
 464         dropbmp 
= m_buttonDropDownBmp
; 
 470     dc
.DrawBitmap(bmp
, bmpX
, bmpY
, true); 
 471     dc
.DrawBitmap(dropbmp
, dropBmpX
, dropBmpY
, true); 
 473     // set the item's text color based on if it is disabled 
 474     dc
.SetTextForeground(*wxBLACK
); 
 475     if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
) 
 476         dc
.SetTextForeground(DISABLED_TEXT_COLOR
); 
 478     if ( (m_flags 
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() ) 
 480         dc
.DrawText(item
.GetLabel(), textX
, textY
); 
 484 void wxAuiDefaultToolBarArt::DrawControlLabel( 
 486                                     wxWindow
* WXUNUSED(wnd
), 
 487                                     const wxAuiToolBarItem
& item
, 
 490     if (!(m_flags 
& wxAUI_TB_TEXT
)) 
 493     if (m_textOrientation 
!= wxAUI_TBTOOL_TEXT_BOTTOM
) 
 496     int textX 
= 0, textY 
= 0; 
 497     int textWidth 
= 0, textHeight 
= 0; 
 502     if (m_flags 
& wxAUI_TB_TEXT
) 
 504         dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
); 
 508     dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
); 
 510     // don't draw the label if it is wider than the item width 
 511     if (textWidth 
> rect
.width
) 
 514     // set the label's text color 
 515     dc
.SetTextForeground(*wxBLACK
); 
 517     textX 
= rect
.x 
+ (rect
.width
/2) - (textWidth
/2) + 1; 
 518     textY 
= rect
.y 
+ rect
.height 
- textHeight 
- 1; 
 520     if ( (m_flags 
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() ) 
 522         dc
.DrawText(item
.GetLabel(), textX
, textY
); 
 526 wxSize 
wxAuiDefaultToolBarArt::GetLabelSize( 
 528                                         wxWindow
* WXUNUSED(wnd
), 
 529                                         const wxAuiToolBarItem
& item
) 
 533     // get label's height 
 534     int width 
= 0, height 
= 0; 
 535     dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
); 
 538     width 
= item
.GetMinSize().GetWidth(); 
 542         // no width specified, measure the text ourselves 
 543         width 
= dc
.GetTextExtent(item
.GetLabel()).GetX(); 
 546     return wxSize(width
, height
); 
 549 wxSize 
wxAuiDefaultToolBarArt::GetToolSize( 
 551                                         wxWindow
* WXUNUSED(wnd
), 
 552                                         const wxAuiToolBarItem
& item
) 
 554     if (!item
.GetBitmap().IsOk() && !(m_flags 
& wxAUI_TB_TEXT
)) 
 555         return wxSize(16,16); 
 557     int width 
= item
.GetBitmap().GetWidth(); 
 558     int height 
= item
.GetBitmap().GetHeight(); 
 560     if (m_flags 
& wxAUI_TB_TEXT
) 
 565         if (m_textOrientation 
== wxAUI_TBTOOL_TEXT_BOTTOM
) 
 567             dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
); 
 570             if ( !item
.GetLabel().empty() ) 
 572                 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
); 
 573                 width 
= wxMax(width
, tx
+6); 
 576         else if ( m_textOrientation 
== wxAUI_TBTOOL_TEXT_RIGHT 
&& 
 577                   !item
.GetLabel().empty() ) 
 579             width 
+= 3; // space between left border and bitmap 
 580             width 
+= 3; // space between bitmap and text 
 582             if ( !item
.GetLabel().empty() ) 
 584                 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
); 
 586                 height 
= wxMax(height
, ty
); 
 591     // if the tool has a dropdown button, add it to the width 
 592     if (item
.HasDropDown()) 
 593         width 
+= (BUTTON_DROPDOWN_WIDTH
+4); 
 595     return wxSize(width
, height
); 
 598 void wxAuiDefaultToolBarArt::DrawSeparator( 
 600                                     wxWindow
* WXUNUSED(wnd
), 
 603     bool horizontal 
= true; 
 604     if (m_flags 
& wxAUI_TB_VERTICAL
) 
 611         rect
.x 
+= (rect
.width
/2); 
 613         int new_height 
= (rect
.height
*3)/4; 
 614         rect
.y 
+= (rect
.height
/2) - (new_height
/2); 
 615         rect
.height 
= new_height
; 
 619         rect
.y 
+= (rect
.height
/2); 
 621         int new_width 
= (rect
.width
*3)/4; 
 622         rect
.x 
+= (rect
.width
/2) - (new_width
/2); 
 623         rect
.width 
= new_width
; 
 626     wxColour startColour 
= m_baseColour
.ChangeLightness(80); 
 627     wxColour endColour 
= m_baseColour
.ChangeLightness(80); 
 628     dc
.GradientFillLinear(rect
, startColour
, endColour
, horizontal 
? wxSOUTH 
: wxEAST
); 
 631 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
, 
 632                                     wxWindow
* WXUNUSED(wnd
), 
 640         if (m_flags 
& wxAUI_TB_VERTICAL
) 
 642             x 
= rect
.x 
+ (i
*4) + 5; 
 644             if (x 
> rect
.GetWidth()-5) 
 650             y 
= rect
.y 
+ (i
*4) + 5; 
 651             if (y 
> rect
.GetHeight()-5) 
 655         dc
.SetPen(m_gripperPen1
); 
 657         dc
.SetPen(m_gripperPen2
); 
 658         dc
.DrawPoint(x
, y
+1); 
 659         dc
.DrawPoint(x
+1, y
); 
 660         dc
.SetPen(m_gripperPen3
); 
 661         dc
.DrawPoint(x
+2, y
+1); 
 662         dc
.DrawPoint(x
+2, y
+2); 
 663         dc
.DrawPoint(x
+1, y
+2); 
 670 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
, 
 675     if (state 
& wxAUI_BUTTON_STATE_HOVER 
|| 
 676         state 
& wxAUI_BUTTON_STATE_PRESSED
) 
 678         wxColor light_gray_bg 
= m_highlightColour
.ChangeLightness(170); 
 680         if (m_flags 
& wxAUI_TB_VERTICAL
) 
 682             dc
.SetPen(wxPen(m_highlightColour
)); 
 683             dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
); 
 684             dc
.SetPen(wxPen(light_gray_bg
)); 
 685             dc
.SetBrush(wxBrush(light_gray_bg
)); 
 686             dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
); 
 690             dc
.SetPen(wxPen(m_highlightColour
)); 
 691             dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
); 
 692             dc
.SetPen(wxPen(light_gray_bg
)); 
 693             dc
.SetBrush(wxBrush(light_gray_bg
)); 
 694             dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
); 
 698     int x 
= rect
.x
+1+(rect
.width
-m_overflowBmp
.GetWidth())/2; 
 699     int y 
= rect
.y
+1+(rect
.height
-m_overflowBmp
.GetHeight())/2; 
 700     dc
.DrawBitmap(m_overflowBmp
, x
, y
, true); 
 703 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
) 
 707         case wxAUI_TBART_SEPARATOR_SIZE
: return m_separatorSize
; 
 708         case wxAUI_TBART_GRIPPER_SIZE
:   return m_gripperSize
; 
 709         case wxAUI_TBART_OVERFLOW_SIZE
:  return m_overflowSize
; 
 714 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
) 
 718         case wxAUI_TBART_SEPARATOR_SIZE
: m_separatorSize 
= size
; break; 
 719         case wxAUI_TBART_GRIPPER_SIZE
:   m_gripperSize 
= size
; break; 
 720         case wxAUI_TBART_OVERFLOW_SIZE
:  m_overflowSize 
= size
; break; 
 724 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
, 
 725                                          const wxAuiToolBarItemArray
& items
) 
 729     size_t items_added 
= 0; 
 731     size_t i
, count 
= items
.GetCount(); 
 732     for (i 
= 0; i 
< count
; ++i
) 
 734         wxAuiToolBarItem
& item 
= items
.Item(i
); 
 736         if (item
.GetKind() == wxITEM_NORMAL
) 
 738             wxString text 
= item
.GetShortHelp(); 
 740                 text 
= item
.GetLabel(); 
 745             wxMenuItem
* m 
=  new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp()); 
 747             m
->SetBitmap(item
.GetBitmap()); 
 751         else if (item
.GetKind() == wxITEM_SEPARATOR
) 
 754                 menuPopup
.AppendSeparator(); 
 758     // find out where to put the popup menu of window items 
 759     wxPoint pt 
= ::wxGetMousePosition(); 
 760     pt 
= wnd
->ScreenToClient(pt
); 
 762     // find out the screen coordinate at the bottom of the tab ctrl 
 763     wxRect cli_rect 
= wnd
->GetClientRect(); 
 764     pt
.y 
= cli_rect
.y 
+ cli_rect
.height
; 
 766     ToolbarCommandCapture
* cc 
= new ToolbarCommandCapture
; 
 767     wnd
->PushEventHandler(cc
); 
 768     wnd
->PopupMenu(&menuPopup
, pt
); 
 769     int command 
= cc
->GetCommandId(); 
 770     wnd
->PopEventHandler(true); 
 778 static wxOrientation 
GetOrientation(long& style
) 
 780     switch (style 
& wxAUI_ORIENTATION_MASK
) 
 782         case wxAUI_TB_HORIZONTAL
: 
 784         case wxAUI_TB_VERTICAL
: 
 787             wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)"); 
 794 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
) 
 795     EVT_SIZE(wxAuiToolBar::OnSize
) 
 796     EVT_IDLE(wxAuiToolBar::OnIdle
) 
 797     EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
) 
 798     EVT_PAINT(wxAuiToolBar::OnPaint
) 
 799     EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
) 
 800     EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
) 
 801     EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
) 
 802     EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
) 
 803     EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
) 
 804     EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
) 
 805     EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
) 
 806     EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
) 
 807     EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
) 
 808     EVT_MOTION(wxAuiToolBar::OnMotion
) 
 809     EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
) 
 810     EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
) 
 811     EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
) 
 814 void wxAuiToolBar::Init() 
 816     m_sizer 
= new wxBoxSizer(wxHORIZONTAL
); 
 819     m_sizerElementCount 
= 0; 
 820     m_actionPos 
= wxDefaultPosition
; 
 823     m_art 
= new wxAuiDefaultToolBarArt
; 
 825     m_toolBorderPadding 
= 3; 
 826     m_toolTextOrientation 
= wxAUI_TBTOOL_TEXT_BOTTOM
; 
 827     m_gripperSizerItem 
= NULL
; 
 828     m_overflowSizerItem 
= NULL
; 
 830     m_gripperVisible 
= false; 
 831     m_overflowVisible 
= false; 
 833     m_orientation 
= wxHORIZONTAL
; 
 836 bool wxAuiToolBar::Create(wxWindow
* parent
, 
 842     style 
= style
|wxBORDER_NONE
; 
 844     if (!wxControl::Create(parent
, id
, pos
, size
, style
)) 
 847     m_windowStyle 
= style
; 
 849     m_gripperVisible  
= (style 
& wxAUI_TB_GRIPPER
) ? true : false; 
 850     m_overflowVisible 
= (style 
& wxAUI_TB_OVERFLOW
) ? true : false; 
 852     m_orientation 
= GetOrientation(style
); 
 853     if (m_orientation 
== wxBOTH
) 
 855         m_orientation 
= wxHORIZONTAL
; 
 858     SetMargins(5, 5, 2, 2); 
 859     SetFont(*wxNORMAL_FONT
); 
 861     SetExtraStyle(wxWS_EX_PROCESS_IDLE
); 
 862     if (style 
& wxAUI_TB_HORZ_LAYOUT
) 
 863         SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
); 
 864     SetBackgroundStyle(wxBG_STYLE_CUSTOM
); 
 869 wxAuiToolBar::~wxAuiToolBar() 
 875 void wxAuiToolBar::SetWindowStyleFlag(long style
) 
 877     GetOrientation(style
);      // assert if style is invalid 
 878     wxCHECK_RET(IsPaneValid(style
), 
 879                 "window settings and pane settings are incompatible"); 
 881     wxControl::SetWindowStyleFlag(style
); 
 883     m_windowStyle 
= style
; 
 890     if (m_windowStyle 
& wxAUI_TB_GRIPPER
) 
 891         m_gripperVisible 
= true; 
 893         m_gripperVisible 
= false; 
 896     if (m_windowStyle 
& wxAUI_TB_OVERFLOW
) 
 897         m_overflowVisible 
= true; 
 899         m_overflowVisible 
= false; 
 901     if (style 
& wxAUI_TB_HORZ_LAYOUT
) 
 902         SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
); 
 904         SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
); 
 907 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
) 
 916         m_art
->SetTextOrientation(m_toolTextOrientation
); 
 920 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const 
 928 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
, 
 929                            const wxString
& label
, 
 930                            const wxBitmap
& bitmap
, 
 931                            const wxString
& shortHelp_string
, 
 934     return AddTool(tool_id
, 
 945 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
, 
 946                            const wxString
& label
, 
 947                            const wxBitmap
& bitmap
, 
 948                            const wxBitmap
& disabledBitmap
, 
 950                            const wxString
& shortHelpString
, 
 951                            const wxString
& longHelpString
, 
 952                            wxObject
* WXUNUSED(client_data
)) 
 954     wxAuiToolBarItem item
; 
 955     item
.m_window 
= NULL
; 
 956     item
.m_label 
= label
; 
 957     item
.m_bitmap 
= bitmap
; 
 958     item
.m_disabledBitmap 
= disabledBitmap
; 
 959     item
.m_shortHelp 
= shortHelpString
; 
 960     item
.m_longHelp 
= longHelpString
; 
 961     item
.m_active 
= true; 
 962     item
.m_dropDown 
= false; 
 963     item
.m_spacerPixels 
= 0; 
 964     item
.m_toolId 
= tool_id
; 
 966     item
.m_proportion 
= 0; 
 968     item
.m_sizerItem 
= NULL
; 
 969     item
.m_minSize 
= wxDefaultSize
; 
 971     item
.m_sticky 
= false; 
 973     if (item
.m_toolId 
== wxID_ANY
) 
 974         item
.m_toolId 
= wxNewId(); 
 976     if (!item
.m_disabledBitmap
.IsOk()) 
 978         // no disabled bitmap specified, we need to make one 
 979         if (item
.m_bitmap
.IsOk()) 
 981             item
.m_disabledBitmap 
= item
.m_bitmap
.ConvertToDisabled(); 
 985     return &m_items
.Last(); 
 988 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
, 
 989                               const wxString
& label
) 
 991     wxAuiToolBarItem item
; 
 992     item
.m_window 
= (wxWindow
*)control
; 
 993     item
.m_label 
= label
; 
 994     item
.m_bitmap 
= wxNullBitmap
; 
 995     item
.m_disabledBitmap 
= wxNullBitmap
; 
 996     item
.m_active 
= true; 
 997     item
.m_dropDown 
= false; 
 998     item
.m_spacerPixels 
= 0; 
 999     item
.m_toolId 
= control
->GetId(); 
1001     item
.m_proportion 
= 0; 
1002     item
.m_kind 
= wxITEM_CONTROL
; 
1003     item
.m_sizerItem 
= NULL
; 
1004     item
.m_minSize 
= control
->GetEffectiveMinSize(); 
1005     item
.m_userData 
= 0; 
1006     item
.m_sticky 
= false; 
1009     return &m_items
.Last(); 
1012 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
, 
1013                             const wxString
& label
, 
1016     wxSize min_size 
= wxDefaultSize
; 
1020     wxAuiToolBarItem item
; 
1021     item
.m_window 
= NULL
; 
1022     item
.m_label 
= label
; 
1023     item
.m_bitmap 
= wxNullBitmap
; 
1024     item
.m_disabledBitmap 
= wxNullBitmap
; 
1025     item
.m_active 
= true; 
1026     item
.m_dropDown 
= false; 
1027     item
.m_spacerPixels 
= 0; 
1028     item
.m_toolId 
= tool_id
; 
1030     item
.m_proportion 
= 0; 
1031     item
.m_kind 
= wxITEM_LABEL
; 
1032     item
.m_sizerItem 
= NULL
; 
1033     item
.m_minSize 
= min_size
; 
1034     item
.m_userData 
= 0; 
1035     item
.m_sticky 
= false; 
1037     if (item
.m_toolId 
== wxID_ANY
) 
1038         item
.m_toolId 
= wxNewId(); 
1041     return &m_items
.Last(); 
1044 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator() 
1046     wxAuiToolBarItem item
; 
1047     item
.m_window 
= NULL
; 
1048     item
.m_label 
= wxEmptyString
; 
1049     item
.m_bitmap 
= wxNullBitmap
; 
1050     item
.m_disabledBitmap 
= wxNullBitmap
; 
1051     item
.m_active 
= true; 
1052     item
.m_dropDown 
= false; 
1055     item
.m_proportion 
= 0; 
1056     item
.m_kind 
= wxITEM_SEPARATOR
; 
1057     item
.m_sizerItem 
= NULL
; 
1058     item
.m_minSize 
= wxDefaultSize
; 
1059     item
.m_userData 
= 0; 
1060     item
.m_sticky 
= false; 
1063     return &m_items
.Last(); 
1066 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
) 
1068     wxAuiToolBarItem item
; 
1069     item
.m_window 
= NULL
; 
1070     item
.m_label 
= wxEmptyString
; 
1071     item
.m_bitmap 
= wxNullBitmap
; 
1072     item
.m_disabledBitmap 
= wxNullBitmap
; 
1073     item
.m_active 
= true; 
1074     item
.m_dropDown 
= false; 
1075     item
.m_spacerPixels 
= pixels
; 
1078     item
.m_proportion 
= 0; 
1079     item
.m_kind 
= wxITEM_SPACER
; 
1080     item
.m_sizerItem 
= NULL
; 
1081     item
.m_minSize 
= wxDefaultSize
; 
1082     item
.m_userData 
= 0; 
1083     item
.m_sticky 
= false; 
1086     return &m_items
.Last(); 
1089 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
) 
1091     wxAuiToolBarItem item
; 
1092     item
.m_window 
= NULL
; 
1093     item
.m_label 
= wxEmptyString
; 
1094     item
.m_bitmap 
= wxNullBitmap
; 
1095     item
.m_disabledBitmap 
= wxNullBitmap
; 
1096     item
.m_active 
= true; 
1097     item
.m_dropDown 
= false; 
1098     item
.m_spacerPixels 
= 0; 
1101     item
.m_proportion 
= proportion
; 
1102     item
.m_kind 
= wxITEM_SPACER
; 
1103     item
.m_sizerItem 
= NULL
; 
1104     item
.m_minSize 
= wxDefaultSize
; 
1105     item
.m_userData 
= 0; 
1106     item
.m_sticky 
= false; 
1109     return &m_items
.Last(); 
1112 void wxAuiToolBar::Clear() 
1115     m_sizerElementCount 
= 0; 
1118 bool wxAuiToolBar::DeleteTool(int tool_id
) 
1120     int idx 
= GetToolIndex(tool_id
); 
1121     if (idx 
>= 0 && idx 
< (int)m_items
.GetCount()) 
1123         m_items
.RemoveAt(idx
); 
1131 bool wxAuiToolBar::DeleteByIndex(int idx
) 
1133     if (idx 
>= 0 && idx 
< (int)m_items
.GetCount()) 
1135         m_items
.RemoveAt(idx
); 
1144 wxControl
* wxAuiToolBar::FindControl(int id
) 
1146     wxWindow
* wnd 
= FindWindow(id
); 
1147     return (wxControl
*)wnd
; 
1150 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const 
1153     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1155         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1156         if (item
.m_toolId 
== tool_id
) 
1163 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const 
1166     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1168         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1170         if (!item
.m_sizerItem
) 
1173         wxRect rect 
= item
.m_sizerItem
->GetRect(); 
1174         if (rect
.Contains(x
,y
)) 
1176             // if the item doesn't fit on the toolbar, return NULL 
1177             if (!GetToolFitsByIndex(i
)) 
1187 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const 
1190     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1192         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1194         if (!item
.m_sizerItem
) 
1197         wxRect rect 
= item
.m_sizerItem
->GetRect(); 
1199         // apply tool packing 
1201             rect
.width 
+= m_toolPacking
; 
1203         if (rect
.Contains(x
,y
)) 
1205             // if the item doesn't fit on the toolbar, return NULL 
1206             if (!GetToolFitsByIndex(i
)) 
1216 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const 
1221     if (idx 
>= (int)m_items
.size()) 
1224     return &(m_items
[idx
]); 
1227 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
)) 
1229     // TODO: wxToolBar compatibility 
1232 wxSize 
wxAuiToolBar::GetToolBitmapSize() const 
1234     // TODO: wxToolBar compatibility 
1235     return wxSize(16,15); 
1238 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
) 
1240     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1244     item
->m_proportion 
= proportion
; 
1247 int wxAuiToolBar::GetToolProportion(int tool_id
) const 
1249     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1253     return item
->m_proportion
; 
1256 void wxAuiToolBar::SetToolSeparation(int separation
) 
1259         m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
); 
1262 int wxAuiToolBar::GetToolSeparation() const 
1265         return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
); 
1271 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
) 
1273     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1277     item
->SetHasDropDown(dropdown
); 
1280 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const 
1282     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1286     return item
->HasDropDown(); 
1289 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
) 
1291     // ignore separators 
1295     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1299     if (item
->m_sticky 
== sticky
) 
1302     item
->m_sticky 
= sticky
; 
1308 bool wxAuiToolBar::GetToolSticky(int tool_id
) const 
1310     wxAuiToolBarItem
* item 
= FindTool(tool_id
); 
1314     return item
->m_sticky
; 
1320 void wxAuiToolBar::SetToolBorderPadding(int padding
) 
1322     m_toolBorderPadding 
= padding
; 
1325 int wxAuiToolBar::GetToolBorderPadding() const 
1327     return m_toolBorderPadding
; 
1330 void wxAuiToolBar::SetToolTextOrientation(int orientation
) 
1332     m_toolTextOrientation 
= orientation
; 
1336         m_art
->SetTextOrientation(orientation
); 
1340 int wxAuiToolBar::GetToolTextOrientation() const 
1342     return m_toolTextOrientation
; 
1345 void wxAuiToolBar::SetToolPacking(int packing
) 
1347     m_toolPacking 
= packing
; 
1350 int wxAuiToolBar::GetToolPacking() const 
1352     return m_toolPacking
; 
1356 void wxAuiToolBar::SetOrientation(int orientation
) 
1358     wxCHECK_RET(orientation 
== wxHORIZONTAL 
|| 
1359                 orientation 
== wxVERTICAL
, 
1360                 "invalid orientation value"); 
1361     if (orientation 
!= m_orientation
) 
1363         m_orientation 
= wxOrientation(orientation
); 
1368 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
) 
1371         m_leftPadding 
= left
; 
1373         m_rightPadding 
= right
; 
1377         m_bottomPadding 
= bottom
; 
1380 bool wxAuiToolBar::GetGripperVisible() const 
1382     return m_gripperVisible
; 
1385 void wxAuiToolBar::SetGripperVisible(bool visible
) 
1387     m_gripperVisible 
= visible
; 
1389         m_windowStyle 
|= wxAUI_TB_GRIPPER
; 
1391         m_windowStyle 
&= ~wxAUI_TB_GRIPPER
; 
1397 bool wxAuiToolBar::GetOverflowVisible() const 
1399     return m_overflowVisible
; 
1402 void wxAuiToolBar::SetOverflowVisible(bool visible
) 
1404     m_overflowVisible 
= visible
; 
1406         m_windowStyle 
|= wxAUI_TB_OVERFLOW
; 
1408         m_windowStyle 
&= ~wxAUI_TB_OVERFLOW
; 
1412 bool wxAuiToolBar::SetFont(const wxFont
& font
) 
1414     bool res 
= wxWindow::SetFont(font
); 
1418         m_art
->SetFont(font
); 
1425 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
) 
1427     if (pitem 
&& (pitem
->m_state 
& wxAUI_BUTTON_STATE_DISABLED
)) 
1430     wxAuiToolBarItem
* former_hover 
= NULL
; 
1433     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1435         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1436         if (item
.m_state 
& wxAUI_BUTTON_STATE_HOVER
) 
1437             former_hover 
= &item
; 
1438         item
.m_state 
&= ~wxAUI_BUTTON_STATE_HOVER
; 
1443         pitem
->m_state 
|= wxAUI_BUTTON_STATE_HOVER
; 
1446     if (former_hover 
!= pitem
) 
1453 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
) 
1455     wxAuiToolBarItem
* former_item 
= NULL
; 
1458     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1460         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1461         if (item
.m_state 
& wxAUI_BUTTON_STATE_PRESSED
) 
1462             former_item 
= &item
; 
1463         item
.m_state 
&= ~wxAUI_BUTTON_STATE_PRESSED
; 
1468         pitem
->m_state 
&= ~wxAUI_BUTTON_STATE_HOVER
; 
1469         pitem
->m_state 
|= wxAUI_BUTTON_STATE_PRESSED
; 
1472     if (former_item 
!= pitem
) 
1479 void wxAuiToolBar::RefreshOverflowState() 
1481     if (!m_overflowSizerItem
) 
1483         m_overflowState 
= 0; 
1487     int overflow_state 
= 0; 
1489     wxRect overflow_rect 
= GetOverflowRect(); 
1492     // find out the mouse's current position 
1493     wxPoint pt 
= ::wxGetMousePosition(); 
1494     pt 
= this->ScreenToClient(pt
); 
1496     // find out if the mouse cursor is inside the dropdown rectangle 
1497     if (overflow_rect
.Contains(pt
.x
, pt
.y
)) 
1499         if (::wxGetMouseState().LeftIsDown()) 
1500             overflow_state 
= wxAUI_BUTTON_STATE_PRESSED
; 
1502             overflow_state 
= wxAUI_BUTTON_STATE_HOVER
; 
1505     if (overflow_state 
!= m_overflowState
) 
1507         m_overflowState 
= overflow_state
; 
1512     m_overflowState 
= overflow_state
; 
1515 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
) 
1517     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1519     if (tool 
&& (tool
->m_kind 
== wxITEM_CHECK 
|| tool
->m_kind 
== wxITEM_RADIO
)) 
1521         if (tool
->m_kind 
== wxITEM_RADIO
) 
1524             idx 
= GetToolIndex(tool_id
); 
1525             count 
= (int)m_items
.GetCount(); 
1527             if (idx 
>= 0 && idx 
< count
) 
1529                 for (i 
= idx 
+ 1; i 
< count
; ++i
) 
1531                     if (m_items
[i
].m_kind 
!= wxITEM_RADIO
) 
1533                     m_items
[i
].m_state 
&= ~wxAUI_BUTTON_STATE_CHECKED
; 
1535                 for (i 
= idx 
- 1; i 
>= 0; i
--) 
1537                     if (m_items
[i
].m_kind 
!= wxITEM_RADIO
) 
1539                     m_items
[i
].m_state 
&= ~wxAUI_BUTTON_STATE_CHECKED
; 
1543             tool
->m_state 
|= wxAUI_BUTTON_STATE_CHECKED
; 
1545          else if (tool
->m_kind 
== wxITEM_CHECK
) 
1548                 tool
->m_state 
|= wxAUI_BUTTON_STATE_CHECKED
; 
1550                 tool
->m_state 
&= ~wxAUI_BUTTON_STATE_CHECKED
; 
1555 bool wxAuiToolBar::GetToolToggled(int tool_id
) const 
1557     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1561         if ( (tool
->m_kind 
!= wxITEM_CHECK
) && (tool
->m_kind 
!= wxITEM_RADIO
) ) 
1564         return (tool
->m_state 
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false; 
1570 void wxAuiToolBar::EnableTool(int tool_id
, bool state
) 
1572     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1577             tool
->m_state 
&= ~wxAUI_BUTTON_STATE_DISABLED
; 
1579             tool
->m_state 
|= wxAUI_BUTTON_STATE_DISABLED
; 
1583 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const 
1585     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1588         return (tool
->m_state 
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true; 
1593 wxString 
wxAuiToolBar::GetToolLabel(int tool_id
) const 
1595     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1596     wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array")); 
1598         return wxEmptyString
; 
1600     return tool
->m_label
; 
1603 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
) 
1605     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1608         tool
->m_label 
= label
; 
1612 wxBitmap 
wxAuiToolBar::GetToolBitmap(int tool_id
) const 
1614     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1615     wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array")); 
1617         return wxNullBitmap
; 
1619     return tool
->m_bitmap
; 
1622 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
) 
1624     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1627         tool
->m_bitmap 
= bitmap
; 
1631 wxString 
wxAuiToolBar::GetToolShortHelp(int tool_id
) const 
1633     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1634     wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array")); 
1636         return wxEmptyString
; 
1638     return tool
->m_shortHelp
; 
1641 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
) 
1643     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1646         tool
->m_shortHelp 
= help_string
; 
1650 wxString 
wxAuiToolBar::GetToolLongHelp(int tool_id
) const 
1652     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1653     wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array")); 
1655         return wxEmptyString
; 
1657     return tool
->m_longHelp
; 
1660 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
) 
1662     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1665         tool
->m_longHelp 
= help_string
; 
1669 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
, 
1670                                           const wxAuiToolBarItemArray
& append
) 
1672     m_customOverflowPrepend 
= prepend
; 
1673     m_customOverflowAppend 
= append
; 
1676 // get size of hint rectangle for a particular dock location 
1677 wxSize 
wxAuiToolBar::GetHintSize(int dock_direction
) const 
1679     switch (dock_direction
) 
1681         case wxAUI_DOCK_TOP
: 
1682         case wxAUI_DOCK_BOTTOM
: 
1683             return m_horzHintSize
; 
1684         case wxAUI_DOCK_RIGHT
: 
1685         case wxAUI_DOCK_LEFT
: 
1686             return m_vertHintSize
; 
1688             wxFAIL_MSG("invalid dock location value"); 
1690     return wxDefaultSize
; 
1693 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const 
1695     return IsPaneValid(m_windowStyle
, pane
); 
1698 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
) 
1700     if (style 
& wxAUI_TB_HORIZONTAL
) 
1702         if (pane
.IsLeftDockable() || pane
.IsRightDockable()) 
1707     else if (style 
& wxAUI_TB_VERTICAL
) 
1709         if (pane
.IsTopDockable() || pane
.IsBottomDockable()) 
1717 bool wxAuiToolBar::IsPaneValid(long style
) const 
1719     wxAuiManager
* manager 
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this)); 
1722         return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this))); 
1727 void wxAuiToolBar::SetArtFlags() const 
1729     unsigned int artflags 
= m_windowStyle 
& ~wxAUI_ORIENTATION_MASK
; 
1730     if (m_orientation 
== wxVERTICAL
) 
1732         artflags 
|= wxAUI_TB_VERTICAL
; 
1734     m_art
->SetFlags(artflags
); 
1737 size_t wxAuiToolBar::GetToolCount() const 
1739     return m_items
.size(); 
1742 int wxAuiToolBar::GetToolIndex(int tool_id
) const 
1744     // this will prevent us from returning the index of the 
1745     // first separator in the toolbar since its id is equal to -1 
1749     size_t i
, count 
= m_items
.GetCount(); 
1750     for (i 
= 0; i 
< count
; ++i
) 
1752         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1753         if (item
.m_toolId 
== tool_id
) 
1760 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const 
1762     if (tool_idx 
< 0 || tool_idx 
>= (int)m_items
.GetCount()) 
1765     if (!m_items
[tool_idx
].m_sizerItem
) 
1769     GetClientSize(&cli_w
, &cli_h
); 
1771     wxRect rect 
= m_items
[tool_idx
].m_sizerItem
->GetRect(); 
1773     if (m_orientation 
== wxVERTICAL
) 
1775         // take the dropdown size into account 
1776         if (m_overflowVisible
) 
1777             cli_h 
-= m_overflowSizerItem
->GetSize().y
; 
1779         if (rect
.y
+rect
.height 
< cli_h
) 
1784         // take the dropdown size into account 
1785         if (m_overflowVisible
) 
1786             cli_w 
-= m_overflowSizerItem
->GetSize().x
; 
1788         if (rect
.x
+rect
.width 
< cli_w
) 
1796 bool wxAuiToolBar::GetToolFits(int tool_id
) const 
1798     return GetToolFitsByIndex(GetToolIndex(tool_id
)); 
1801 wxRect 
wxAuiToolBar::GetToolRect(int tool_id
) const 
1803     wxAuiToolBarItem
* tool 
= FindTool(tool_id
); 
1804     if (tool 
&& tool
->m_sizerItem
) 
1806         return tool
->m_sizerItem
->GetRect(); 
1812 bool wxAuiToolBar::GetToolBarFits() const 
1814     if (m_items
.GetCount() == 0) 
1816         // empty toolbar always 'fits' 
1820     // entire toolbar content fits if the last tool fits 
1821     return GetToolFitsByIndex(m_items
.GetCount() - 1); 
1824 bool wxAuiToolBar::Realize() 
1826     wxClientDC 
dc(this); 
1830     // calculate hint sizes for both horizontal and vertical 
1831     // in the order that leaves toolbar in correct final state 
1832     bool retval 
= false; 
1833     if (m_orientation 
== wxHORIZONTAL
) 
1835         if (RealizeHelper(dc
, false)) 
1837             m_vertHintSize 
= GetSize(); 
1838             if (RealizeHelper(dc
, true)) 
1840                 m_horzHintSize 
= GetSize(); 
1847         if (RealizeHelper(dc
, true)) 
1849             m_horzHintSize 
= GetSize(); 
1850             if (RealizeHelper(dc
, false)) 
1852                 m_vertHintSize 
= GetSize(); 
1862 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
) 
1864     // create the new sizer to add toolbar elements to 
1865     wxBoxSizer
* sizer 
= new wxBoxSizer(horizontal 
? wxHORIZONTAL 
: wxVERTICAL
); 
1868     int separatorSize 
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
); 
1869     int gripperSize 
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
); 
1870     if (gripperSize 
> 0 && m_gripperVisible
) 
1873             m_gripperSizerItem 
= sizer
->Add(gripperSize
, 1, 0, wxEXPAND
); 
1875             m_gripperSizerItem 
= sizer
->Add(1, gripperSize
, 0, wxEXPAND
); 
1879         m_gripperSizerItem 
= NULL
; 
1882     // add "left" padding 
1883     if (m_leftPadding 
> 0) 
1886             sizer
->Add(m_leftPadding
, 1); 
1888             sizer
->Add(1, m_leftPadding
); 
1892     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
1894         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
1895         wxSizerItem
* m_sizerItem 
= NULL
; 
1897         switch (item
.m_kind
) 
1901                 wxSize size 
= m_art
->GetLabelSize(dc
, this, item
); 
1902                 m_sizerItem 
= sizer
->Add(size
.x 
+ (m_toolBorderPadding
*2), 
1903                                         size
.y 
+ (m_toolBorderPadding
*2), 
1908                     sizer
->AddSpacer(m_toolPacking
); 
1918                 wxSize size 
= m_art
->GetToolSize(dc
, this, item
); 
1919                 m_sizerItem 
= sizer
->Add(size
.x 
+ (m_toolBorderPadding
*2), 
1920                                         size
.y 
+ (m_toolBorderPadding
*2), 
1926                     sizer
->AddSpacer(m_toolPacking
); 
1932             case wxITEM_SEPARATOR
: 
1935                     m_sizerItem 
= sizer
->Add(separatorSize
, 1, 0, wxEXPAND
); 
1937                     m_sizerItem 
= sizer
->Add(1, separatorSize
, 0, wxEXPAND
); 
1942                     sizer
->AddSpacer(m_toolPacking
); 
1949                 if (item
.m_proportion 
> 0) 
1950                     m_sizerItem 
= sizer
->AddStretchSpacer(item
.m_proportion
); 
1952                     m_sizerItem 
= sizer
->Add(item
.m_spacerPixels
, 1); 
1955             case wxITEM_CONTROL
: 
1957                 //m_sizerItem = sizer->Add(item.m_window, item.m_proportion, wxEXPAND); 
1958                 wxSizerItem
* ctrl_m_sizerItem
; 
1960                 wxBoxSizer
* vert_sizer 
= new wxBoxSizer(wxVERTICAL
); 
1961                 vert_sizer
->AddStretchSpacer(1); 
1962                 ctrl_m_sizerItem 
= vert_sizer
->Add(item
.m_window
, 0, wxEXPAND
); 
1963                 vert_sizer
->AddStretchSpacer(1); 
1964                 if ( (m_windowStyle 
& wxAUI_TB_TEXT
) && 
1965                      m_toolTextOrientation 
== wxAUI_TBTOOL_TEXT_BOTTOM 
&& 
1966                      !item
.GetLabel().empty() ) 
1968                     wxSize s 
= GetLabelSize(item
.GetLabel()); 
1969                     vert_sizer
->Add(1, s
.y
); 
1973                 m_sizerItem 
= sizer
->Add(vert_sizer
, item
.m_proportion
, wxEXPAND
); 
1975                 wxSize min_size 
= item
.m_minSize
; 
1978                 // proportional items will disappear from the toolbar if 
1979                 // their min width is not set to something really small 
1980                 if (item
.m_proportion 
!= 0) 
1985                 if (min_size
.IsFullySpecified()) 
1987                     m_sizerItem
->SetMinSize(min_size
); 
1988                     ctrl_m_sizerItem
->SetMinSize(min_size
); 
1994                     sizer
->AddSpacer(m_toolPacking
); 
1999         item
.m_sizerItem 
= m_sizerItem
; 
2002     // add "right" padding 
2003     if (m_rightPadding 
> 0) 
2006             sizer
->Add(m_rightPadding
, 1); 
2008             sizer
->Add(1, m_rightPadding
); 
2011     // add drop down area 
2012     m_overflowSizerItem 
= NULL
; 
2014     if (m_windowStyle 
& wxAUI_TB_OVERFLOW
) 
2016         int overflow_size 
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
); 
2017         if (overflow_size 
> 0 && m_overflowVisible
) 
2020                 m_overflowSizerItem 
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
); 
2022                 m_overflowSizerItem 
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
); 
2026             m_overflowSizerItem 
= NULL
; 
2031     // the outside sizer helps us apply the "top" and "bottom" padding 
2032     wxBoxSizer
* outside_sizer 
= new wxBoxSizer(horizontal 
? wxVERTICAL 
: wxHORIZONTAL
); 
2034     // add "top" padding 
2035     if (m_topPadding 
> 0) 
2038             outside_sizer
->Add(1, m_topPadding
); 
2040             outside_sizer
->Add(m_topPadding
, 1); 
2043     // add the sizer that contains all of the toolbar elements 
2044     outside_sizer
->Add(sizer
, 1, wxEXPAND
); 
2046     // add "bottom" padding 
2047     if (m_bottomPadding 
> 0) 
2050             outside_sizer
->Add(1, m_bottomPadding
); 
2052             outside_sizer
->Add(m_bottomPadding
, 1); 
2055     delete m_sizer
; // remove old sizer 
2056     m_sizer 
= outside_sizer
; 
2058     // calculate the rock-bottom minimum size 
2059     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
2061         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2062         if (item
.m_sizerItem 
&& item
.m_proportion 
> 0 && item
.m_minSize
.IsFullySpecified()) 
2063             item
.m_sizerItem
->SetMinSize(0,0); 
2066     m_absoluteMinSize 
= m_sizer
->GetMinSize(); 
2068     // reset the min sizes to what they were 
2069     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
2071         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2072         if (item
.m_sizerItem 
&& item
.m_proportion 
> 0 && item
.m_minSize
.IsFullySpecified()) 
2073             item
.m_sizerItem
->SetMinSize(item
.m_minSize
); 
2077     wxSize size 
= m_sizer
->GetMinSize(); 
2078     m_minWidth 
= size
.x
; 
2079     m_minHeight 
= size
.y
; 
2081     if ((m_windowStyle 
& wxAUI_TB_NO_AUTORESIZE
) == 0) 
2083         wxSize curSize 
= GetClientSize(); 
2084         wxSize new_size 
= GetMinSize(); 
2085         if (new_size 
!= curSize
) 
2087             SetClientSize(new_size
); 
2091             m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
); 
2096         wxSize curSize 
= GetClientSize(); 
2097         m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
); 
2103 int wxAuiToolBar::GetOverflowState() const 
2105     return m_overflowState
; 
2108 wxRect 
wxAuiToolBar::GetOverflowRect() const 
2110     wxRect 
cli_rect(wxPoint(0,0), GetClientSize()); 
2111     wxRect overflow_rect 
= m_overflowSizerItem
->GetRect(); 
2112     int overflow_size 
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
); 
2114     if (m_orientation 
== wxVERTICAL
) 
2116         overflow_rect
.y 
= cli_rect
.height 
- overflow_size
; 
2117         overflow_rect
.x 
= 0; 
2118         overflow_rect
.width 
= cli_rect
.width
; 
2119         overflow_rect
.height 
= overflow_size
; 
2123         overflow_rect
.x 
= cli_rect
.width 
- overflow_size
; 
2124         overflow_rect
.y 
= 0; 
2125         overflow_rect
.width 
= overflow_size
; 
2126         overflow_rect
.height 
= cli_rect
.height
; 
2129     return overflow_rect
; 
2132 wxSize 
wxAuiToolBar::GetLabelSize(const wxString
& label
) 
2134     wxClientDC 
dc(this); 
2137     int textWidth 
= 0, textHeight 
= 0; 
2141     // get the text height 
2142     dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
); 
2144     // get the text width 
2145     dc
.GetTextExtent(label
, &textWidth
, &ty
); 
2147     return wxSize(textWidth
, textHeight
); 
2151 void wxAuiToolBar::DoIdleUpdate() 
2153     wxEvtHandler
* handler 
= GetEventHandler(); 
2155     bool need_refresh 
= false; 
2158     for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
2160         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2162         if (item
.m_toolId 
== -1) 
2165         wxUpdateUIEvent 
evt(item
.m_toolId
); 
2166         evt
.SetEventObject(this); 
2168         if (handler
->ProcessEvent(evt
)) 
2170             if (evt
.GetSetEnabled()) 
2174                     is_enabled 
= item
.m_window
->IsThisEnabled(); 
2176                     is_enabled 
= (item
.m_state 
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true; 
2178                 bool new_enabled 
= evt
.GetEnabled(); 
2179                 if (new_enabled 
!= is_enabled
) 
2183                         item
.m_window
->Enable(new_enabled
); 
2188                             item
.m_state 
&= ~wxAUI_BUTTON_STATE_DISABLED
; 
2190                             item
.m_state 
|= wxAUI_BUTTON_STATE_DISABLED
; 
2192                     need_refresh 
= true; 
2196             if (evt
.GetSetChecked()) 
2198                 // make sure we aren't checking an item that can't be 
2199                 if (item
.m_kind 
!= wxITEM_CHECK 
&& item
.m_kind 
!= wxITEM_RADIO
) 
2202                 bool is_checked 
= (item
.m_state 
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false; 
2203                 bool new_checked 
= evt
.GetChecked(); 
2205                 if (new_checked 
!= is_checked
) 
2208                         item
.m_state 
|= wxAUI_BUTTON_STATE_CHECKED
; 
2210                         item
.m_state 
&= ~wxAUI_BUTTON_STATE_CHECKED
; 
2212                     need_refresh 
= true; 
2227 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
)) 
2230     GetClientSize(&x
, &y
); 
2232     if (((x 
>= y
) && m_absoluteMinSize
.x 
> x
) || 
2233         ((y 
> x
) && m_absoluteMinSize
.y 
> y
)) 
2235         // hide all flexible items 
2237         for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
2239             wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2240             if (item
.m_sizerItem 
&& item
.m_proportion 
> 0 && item
.m_sizerItem
->IsShown()) 
2242                 item
.m_sizerItem
->Show(false); 
2243                 item
.m_sizerItem
->SetProportion(0); 
2249         // show all flexible items 
2251         for (i 
= 0, count 
= m_items
.GetCount(); i 
< count
; ++i
) 
2253             wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2254             if (item
.m_sizerItem 
&& item
.m_proportion 
> 0 && !item
.m_sizerItem
->IsShown()) 
2256                 item
.m_sizerItem
->Show(true); 
2257                 item
.m_sizerItem
->SetProportion(item
.m_proportion
); 
2262     m_sizer
->SetDimension(0, 0, x
, y
); 
2267     // idle events aren't sent while user is resizing frame (why?), 
2268     // but resizing toolbar here causes havoc, 
2269     // so force idle handler to run after size handling complete 
2270     QueueEvent(new wxIdleEvent
); 
2275 void wxAuiToolBar::DoSetSize(int x
, 
2281     wxSize parent_size 
= GetParent()->GetClientSize(); 
2282     if (x 
+ width 
> parent_size
.x
) 
2283         width 
= wxMax(0, parent_size
.x 
- x
); 
2284     if (y 
+ height 
> parent_size
.y
) 
2285         height 
= wxMax(0, parent_size
.y 
- y
); 
2287     wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
); 
2291 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
) 
2293     // if orientation doesn't match dock, fix it 
2294     wxAuiManager
* manager 
= wxAuiManager::GetManager(this); 
2297         wxAuiPaneInfo
& pane 
= manager
->GetPane(this); 
2298         // pane state member is public, so it might have been changed 
2299         // without going through wxPaneInfo::SetFlag() check 
2300         bool ok 
= pane
.IsOk(); 
2301         wxCHECK2_MSG(!ok 
|| IsPaneValid(m_windowStyle
, pane
), ok 
= false, 
2302                     "window settings and pane settings are incompatible"); 
2305             wxOrientation newOrientation 
= m_orientation
; 
2306             if (pane
.IsDocked()) 
2308                 switch (pane
.dock_direction
) 
2310                     case wxAUI_DOCK_TOP
: 
2311                     case wxAUI_DOCK_BOTTOM
: 
2312                         newOrientation 
= wxHORIZONTAL
; 
2314                     case wxAUI_DOCK_LEFT
: 
2315                     case wxAUI_DOCK_RIGHT
: 
2316                         newOrientation 
= wxVERTICAL
; 
2319                         wxFAIL_MSG("invalid dock location value"); 
2322             else if (pane
.IsResizable() && 
2323                     GetOrientation(m_windowStyle
) == wxBOTH
) 
2325                 // changing orientation in OnSize causes havoc 
2327                 GetClientSize(&x
, &y
); 
2331                     newOrientation 
= wxHORIZONTAL
; 
2335                     newOrientation 
= wxVERTICAL
; 
2338             if (newOrientation 
!= m_orientation
) 
2340                 SetOrientation(newOrientation
); 
2342                 if (newOrientation 
== wxHORIZONTAL
) 
2344                     pane
.best_size 
= GetHintSize(wxAUI_DOCK_TOP
); 
2348                     pane
.best_size 
= GetHintSize(wxAUI_DOCK_LEFT
); 
2350                 if (pane
.IsDocked()) 
2352                     pane
.floating_size 
= wxDefaultSize
; 
2356                     SetSize(GetParent()->GetClientSize()); 
2365 void wxAuiToolBar::UpdateWindowUI(long flags
) 
2367     if ( flags 
& wxUPDATE_UI_FROMIDLE 
) 
2372     wxControl::UpdateWindowUI(flags
); 
2375 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
)) 
2377     wxAutoBufferedPaintDC 
dc(this); 
2378     wxRect 
cli_rect(wxPoint(0,0), GetClientSize()); 
2381     bool horizontal 
= m_orientation 
== wxHORIZONTAL
; 
2383     if (m_windowStyle 
& wxAUI_TB_PLAIN_BACKGROUND
) 
2384         m_art
->DrawPlainBackground(dc
, this, cli_rect
); 
2386         m_art
->DrawBackground(dc
, this, cli_rect
); 
2388     int gripperSize 
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
); 
2389     int dropdown_size 
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
); 
2391     // paint the gripper 
2392     if (gripperSize 
> 0 && m_gripperSizerItem
) 
2394         wxRect gripper_rect 
= m_gripperSizerItem
->GetRect(); 
2396             gripper_rect
.width 
= gripperSize
; 
2398             gripper_rect
.height 
= gripperSize
; 
2399         m_art
->DrawGripper(dc
, this, gripper_rect
); 
2402     // calculated how far we can draw items 
2405         last_extent 
= cli_rect
.width
; 
2407         last_extent 
= cli_rect
.height
; 
2408     if (m_overflowVisible
) 
2409         last_extent 
-= dropdown_size
; 
2411     // paint each individual tool 
2412     size_t i
, count 
= m_items
.GetCount(); 
2413     for (i 
= 0; i 
< count
; ++i
) 
2415         wxAuiToolBarItem
& item 
= m_items
.Item(i
); 
2417         if (!item
.m_sizerItem
) 
2420         wxRect item_rect 
= item
.m_sizerItem
->GetRect(); 
2423         if ((horizontal  
&& item_rect
.x 
+ item_rect
.width 
>= last_extent
) || 
2424             (!horizontal 
&& item_rect
.y 
+ item_rect
.height 
>= last_extent
)) 
2429         switch ( item
.m_kind 
) 
2432                 // draw a regular or dropdown button 
2433                 if (!item
.m_dropDown
) 
2434                     m_art
->DrawButton(dc
, this, item
, item_rect
); 
2436                     m_art
->DrawDropDownButton(dc
, this, item
, item_rect
); 
2441                 // draw a toggle button 
2442                 m_art
->DrawButton(dc
, this, item
, item_rect
); 
2445             case wxITEM_SEPARATOR
: 
2447                 m_art
->DrawSeparator(dc
, this, item_rect
); 
2451                 // draw a text label only 
2452                 m_art
->DrawLabel(dc
, this, item
, item_rect
); 
2455             case wxITEM_CONTROL
: 
2456                 // draw the control's label 
2457                 m_art
->DrawControlLabel(dc
, this, item
, item_rect
); 
2461         // fire a signal to see if the item wants to be custom-rendered 
2462         OnCustomRender(dc
, item
, item_rect
); 
2465     // paint the overflow button 
2466     if (dropdown_size 
> 0 && m_overflowSizerItem
) 
2468         wxRect dropDownRect 
= GetOverflowRect(); 
2469         m_art
->DrawOverflowButton(dc
, this, dropDownRect
, m_overflowState
); 
2473 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
)) 
2478 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
) 
2480     wxRect 
cli_rect(wxPoint(0,0), GetClientSize()); 
2482     if (m_gripperSizerItem
) 
2484         wxRect gripper_rect 
= m_gripperSizerItem
->GetRect(); 
2485         if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY())) 
2488             wxAuiManager
* manager 
= wxAuiManager::GetManager(this); 
2492             int x_drag_offset 
= evt
.GetX() - gripper_rect
.GetX(); 
2493             int y_drag_offset 
= evt
.GetY() - gripper_rect
.GetY(); 
2495             // gripper was clicked 
2496             manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
)); 
2501     if (m_overflowSizerItem
) 
2503         wxRect overflow_rect 
= GetOverflowRect(); 
2506             m_overflowVisible 
&& 
2507             overflow_rect
.Contains(evt
.m_x
, evt
.m_y
)) 
2509             wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_OVERFLOW_CLICK
, -1); 
2510             e
.SetEventObject(this); 
2512             e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY())); 
2513             bool processed 
= GetEventHandler()->ProcessEvent(e
); 
2522                 wxAuiToolBarItemArray overflow_items
; 
2525                 // add custom overflow prepend items, if any 
2526                 count 
= m_customOverflowPrepend
.GetCount(); 
2527                 for (i 
= 0; i 
< count
; ++i
) 
2528                     overflow_items
.Add(m_customOverflowPrepend
[i
]); 
2530                 // only show items that don't fit in the dropdown 
2531                 count 
= m_items
.GetCount(); 
2532                 for (i 
= 0; i 
< count
; ++i
) 
2534                     if (!GetToolFitsByIndex(i
)) 
2535                         overflow_items
.Add(m_items
[i
]); 
2538                 // add custom overflow append items, if any 
2539                 count 
= m_customOverflowAppend
.GetCount(); 
2540                 for (i 
= 0; i 
< count
; ++i
) 
2541                     overflow_items
.Add(m_customOverflowAppend
[i
]); 
2543                 int res 
= m_art
->ShowDropDown(this, overflow_items
); 
2544                 m_overflowState 
= 0; 
2548                     wxCommandEvent 
event(wxEVT_MENU
, res
); 
2549                     event
.SetEventObject(this); 
2550                     GetParent()->GetEventHandler()->ProcessEvent(event
); 
2559     m_actionPos 
= wxPoint(evt
.GetX(), evt
.GetY()); 
2560     m_actionItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2564         if (m_actionItem
->m_state 
& wxAUI_BUTTON_STATE_DISABLED
) 
2566             m_actionPos 
= wxPoint(-1,-1); 
2567             m_actionItem 
= NULL
; 
2573         // fire the tool dropdown event 
2574         wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_TOOL_DROPDOWN
, m_actionItem
->m_toolId
); 
2575         e
.SetEventObject(this); 
2576         e
.SetToolId(m_actionItem
->m_toolId
); 
2578         int mouse_x 
= evt
.GetX(); 
2579         wxRect rect 
= m_actionItem
->m_sizerItem
->GetRect(); 
2580         const bool dropDownHit 
= m_actionItem
->m_dropDown 
&& 
2581                                  mouse_x 
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) && 
2582                                  mouse_x 
< (rect
.x
+rect
.width
); 
2583         e
.SetDropDownClicked(dropDownHit
); 
2585         e
.SetClickPoint(evt
.GetPosition()); 
2586         e
.SetItemRect(rect
); 
2588         // we only set the 'pressed button' state if we hit the actual button 
2589         // and not just the drop-down 
2590         SetPressedItem(dropDownHit 
? 0 : m_actionItem
); 
2594             m_actionPos 
= wxPoint(-1,-1); 
2595             m_actionItem 
= NULL
; 
2598         if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped()) 
2601         // Ensure hovered item is really ok, as mouse may have moved during 
2603         wxPoint cursor_pos_after_evt 
= ScreenToClient(wxGetMousePosition()); 
2604         SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
)); 
2610 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
) 
2615     SetPressedItem(NULL
); 
2617     wxAuiToolBarItem
* hitItem
; 
2618     hitItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2619     SetHoverItem(hitItem
); 
2623         // TODO: it would make sense to send out an 'END_DRAG' event here, 
2624         // otherwise a client would never know what to do with the 'BEGIN_DRAG' 
2627         // OnCaptureLost() will be called now and this will reset all our state 
2628         // tracking variables 
2633         if (m_actionItem 
&& hitItem 
== m_actionItem
) 
2637             wxCommandEvent 
e(wxEVT_MENU
, m_actionItem
->m_toolId
); 
2638             e
.SetEventObject(this); 
2640             if (hitItem
->m_kind 
== wxITEM_CHECK 
|| hitItem
->m_kind 
== wxITEM_RADIO
) 
2642                 const bool toggle 
= !(m_actionItem
->m_state 
& wxAUI_BUTTON_STATE_CHECKED
); 
2644                 ToggleTool(m_actionItem
->m_toolId
, toggle
); 
2646                 // repaint immediately 
2653             // we have to release the mouse *before* sending the event, because 
2654             // we don't know what a handler might do. It could open up a popup 
2655             // menu for example and that would make us lose our capture anyway. 
2659             GetEventHandler()->ProcessEvent(e
); 
2661             // Ensure hovered item is really ok, as mouse may have moved during 
2663             wxPoint cursor_pos_after_evt 
= ScreenToClient(wxGetMousePosition()); 
2664             SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
)); 
2673 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
) 
2675     wxRect 
cli_rect(wxPoint(0,0), GetClientSize()); 
2677     if (m_gripperSizerItem
) 
2679         wxRect gripper_rect 
= m_gripperSizerItem
->GetRect(); 
2680         if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY())) 
2684     if (m_overflowSizerItem 
&& m_art
) 
2686         int dropdown_size 
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
); 
2687         if (dropdown_size 
> 0 && 
2688             evt
.m_x 
> cli_rect
.width 
- dropdown_size 
&& 
2690             evt
.m_y 
< cli_rect
.height
) 
2696     m_actionPos 
= wxPoint(evt
.GetX(), evt
.GetY()); 
2697     m_actionItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2699     if (m_actionItem 
&& m_actionItem
->m_state 
& wxAUI_BUTTON_STATE_DISABLED
) 
2701         m_actionPos 
= wxPoint(-1,-1); 
2702         m_actionItem 
= NULL
; 
2709 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
) 
2711     wxAuiToolBarItem
* hitItem
; 
2712     hitItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2714     if (m_actionItem 
&& hitItem 
== m_actionItem
) 
2716         wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_RIGHT_CLICK
, m_actionItem
->m_toolId
); 
2717         e
.SetEventObject(this); 
2718         e
.SetToolId(m_actionItem
->m_toolId
); 
2719         e
.SetClickPoint(m_actionPos
); 
2720         GetEventHandler()->ProcessEvent(e
); 
2725         // right-clicked on the invalid area of the toolbar 
2726         wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_RIGHT_CLICK
, -1); 
2727         e
.SetEventObject(this); 
2729         e
.SetClickPoint(m_actionPos
); 
2730         GetEventHandler()->ProcessEvent(e
); 
2734     // reset member variables 
2735     m_actionPos 
= wxPoint(-1,-1); 
2736     m_actionItem 
= NULL
; 
2739 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
) 
2741     wxRect 
cli_rect(wxPoint(0,0), GetClientSize()); 
2743     if (m_gripperSizerItem
) 
2745         wxRect gripper_rect 
= m_gripperSizerItem
->GetRect(); 
2746         if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY())) 
2750     if (m_overflowSizerItem 
&& m_art
) 
2752         int dropdown_size 
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
); 
2753         if (dropdown_size 
> 0 && 
2754             evt
.m_x 
> cli_rect
.width 
- dropdown_size 
&& 
2756             evt
.m_y 
< cli_rect
.height
) 
2762     m_actionPos 
= wxPoint(evt
.GetX(), evt
.GetY()); 
2763     m_actionItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2767         if (m_actionItem
->m_state 
& wxAUI_BUTTON_STATE_DISABLED
) 
2769             m_actionPos 
= wxPoint(-1,-1); 
2770             m_actionItem 
= NULL
; 
2778 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
) 
2780     wxAuiToolBarItem
* hitItem
; 
2781     hitItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2783     if (m_actionItem 
&& hitItem 
== m_actionItem
) 
2785         if (hitItem
->m_kind 
== wxITEM_NORMAL
) 
2787             wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_MIDDLE_CLICK
, m_actionItem
->m_toolId
); 
2788             e
.SetEventObject(this); 
2789             e
.SetToolId(m_actionItem
->m_toolId
); 
2790             e
.SetClickPoint(m_actionPos
); 
2791             GetEventHandler()->ProcessEvent(e
); 
2796     // reset member variables 
2797     m_actionPos 
= wxPoint(-1,-1); 
2798     m_actionItem 
= NULL
; 
2801 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
) 
2803     const bool button_pressed 
= HasCapture(); 
2805     // start a drag event 
2806     if (!m_dragging 
&& button_pressed 
&& 
2807         abs(evt
.GetX() - m_actionPos
.x
) + abs(evt
.GetY() - m_actionPos
.y
) > 5) 
2809         // TODO: sending this event only makes sense if there is an 'END_DRAG' 
2810         // event sent sometime in the future (see OnLeftUp()) 
2811         wxAuiToolBarEvent 
e(wxEVT_AUITOOLBAR_BEGIN_DRAG
, GetId()); 
2812         e
.SetEventObject(this); 
2813         e
.SetToolId(m_actionItem
->m_toolId
); 
2814         m_dragging 
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped(); 
2822     wxAuiToolBarItem
* hitItem 
= FindToolByPosition(evt
.GetX(), evt
.GetY()); 
2825         // if we have a button pressed we want it to be shown in 'depressed' 
2826         // state unless we move the mouse outside the button, then we want it 
2827         // to show as just 'highlighted' 
2828         if (hitItem 
== m_actionItem
) 
2829             SetPressedItem(m_actionItem
); 
2832             SetPressedItem(NULL
); 
2833             SetHoverItem(m_actionItem
); 
2838         SetHoverItem(hitItem
); 
2840         // tooltips handling 
2841         wxAuiToolBarItem
* packingHitItem
; 
2842         packingHitItem 
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY()); 
2845             if (packingHitItem 
!= m_tipItem
) 
2847                 m_tipItem 
= packingHitItem
; 
2849                 if ( !packingHitItem
->m_shortHelp
.empty() ) 
2850                     SetToolTip(packingHitItem
->m_shortHelp
); 
2861         // figure out the dropdown button state (are we hovering or pressing it?) 
2862         RefreshOverflowState(); 
2866 void wxAuiToolBar::DoResetMouseState() 
2868     RefreshOverflowState(); 
2870     SetPressedItem(NULL
); 
2874     // we have to reset those here, because the mouse-up handlers which do 
2875     // it usually won't be called if we let go of a mouse button while we 
2876     // are outside of the window 
2877     m_actionPos 
= wxPoint(-1,-1); 
2878     m_actionItem 
= NULL
; 
2881 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
) 
2889     DoResetMouseState(); 
2892 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
)) 
2896     DoResetMouseState(); 
2899 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
) 
2901     wxCursor cursor 
= wxNullCursor
; 
2903     if (m_gripperSizerItem
) 
2905         wxRect gripper_rect 
= m_gripperSizerItem
->GetRect(); 
2906         if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY())) 
2908             cursor 
= wxCursor(wxCURSOR_SIZING
); 
2912     evt
.SetCursor(cursor
);