1 ///////////////////////////////////////////////////////////////////////////////
3 // Name: src/aui/auibar.cpp
4 // Purpose: wxaui: wx advanced user interface - docking window manager
5 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/statline.h"
29 #include "wx/dcbuffer.h"
32 #include "wx/settings.h"
35 #include "wx/aui/auibar.h"
36 #include "wx/aui/framemanager.h"
39 #include "wx/osx/private.h"
42 #include "wx/arrimpl.cpp"
43 WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray
)
46 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
47 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
48 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
49 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
50 wxDEFINE_EVENT( wxEVT_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent
);
53 IMPLEMENT_CLASS(wxAuiToolBar
, wxControl
)
54 IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent
, wxEvent
)
57 // missing wxITEM_* items
60 wxITEM_CONTROL
= wxITEM_MAX
,
65 const int BUTTON_DROPDOWN_WIDTH
= 10;
68 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
69 const wxColour
& color
);
71 static wxColor
GetBaseColor()
74 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
75 wxColor baseColour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
77 wxColor baseColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
80 // the baseColour is too pale to use as our base colour,
81 // so darken it a bit --
82 if ((255-baseColour
.Red()) +
83 (255-baseColour
.Green()) +
84 (255-baseColour
.Blue()) < 60)
86 baseColour
= baseColour
.ChangeLightness(92);
94 class ToolbarCommandCapture
: public wxEvtHandler
98 ToolbarCommandCapture() { m_lastId
= 0; }
99 int GetCommandId() const { return m_lastId
; }
101 bool ProcessEvent(wxEvent
& evt
)
103 if (evt
.GetEventType() == wxEVT_MENU
)
105 m_lastId
= evt
.GetId();
109 if (GetNextHandler())
110 return GetNextHandler()->ProcessEvent(evt
);
121 static const unsigned char
122 DISABLED_TEXT_GREY_HUE
= wxColour::AlphaBlend(0, 255, 0.4);
123 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
124 DISABLED_TEXT_GREY_HUE
,
125 DISABLED_TEXT_GREY_HUE
);
127 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
129 m_baseColour
= GetBaseColor();
132 m_textOrientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
133 m_highlightColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
139 wxColor darker1Colour
= m_baseColour
.ChangeLightness(85);
140 wxColor darker2Colour
= m_baseColour
.ChangeLightness(75);
141 wxColor darker3Colour
= m_baseColour
.ChangeLightness(60);
142 wxColor darker4Colour
= m_baseColour
.ChangeLightness(50);
143 wxColor darker5Colour
= m_baseColour
.ChangeLightness(40);
145 m_gripperPen1
= wxPen(darker5Colour
);
146 m_gripperPen2
= wxPen(darker3Colour
);
147 m_gripperPen3
= *wxWHITE_PEN
;
149 static const unsigned char buttonDropdownBits
[] = { 0xe0, 0xf1, 0xfb };
150 static const unsigned char overflowBits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
152 m_buttonDropDownBmp
= wxAuiBitmapFromBits(buttonDropdownBits
, 5, 3,
154 m_disabledButtonDropDownBmp
= wxAuiBitmapFromBits(
155 buttonDropdownBits
, 5, 3,
156 wxColor(128,128,128));
157 m_overflowBmp
= wxAuiBitmapFromBits(overflowBits
, 7, 6, *wxBLACK
);
158 m_disabledOverflowBmp
= wxAuiBitmapFromBits(overflowBits
, 7, 6, wxColor(128,128,128));
160 m_font
= *wxNORMAL_FONT
;
163 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
165 m_font
= *wxNORMAL_FONT
;
169 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
171 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
174 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
179 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
184 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
186 m_textOrientation
= orientation
;
189 unsigned int wxAuiDefaultToolBarArt::GetFlags()
194 wxFont
wxAuiDefaultToolBarArt::GetFont()
199 int wxAuiDefaultToolBarArt::GetTextOrientation()
201 return m_textOrientation
;
204 void wxAuiDefaultToolBarArt::DrawBackground(
206 wxWindow
* WXUNUSED(wnd
),
211 wxColour startColour
= m_baseColour
.ChangeLightness(150);
212 wxColour endColour
= m_baseColour
.ChangeLightness(90);
213 dc
.GradientFillLinear(rect
, startColour
, endColour
, wxSOUTH
);
216 void wxAuiDefaultToolBarArt::DrawPlainBackground(wxDC
& dc
,
217 wxWindow
* WXUNUSED(wnd
),
223 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
225 dc
.DrawRectangle(rect
.GetX() - 1, rect
.GetY() - 1,
226 rect
.GetWidth() + 2, rect
.GetHeight() + 1);
229 void wxAuiDefaultToolBarArt::DrawLabel(
231 wxWindow
* WXUNUSED(wnd
),
232 const wxAuiToolBarItem
& item
,
236 dc
.SetTextForeground(*wxBLACK
);
238 // we only care about the text height here since the text
239 // will get cropped based on the width of the item
240 int textWidth
= 0, textHeight
= 0;
241 dc
.GetTextExtent(wxT("ABCDHgj"), &textWidth
, &textHeight
);
243 // set the clipping region
244 wxRect clipRect
= rect
;
246 dc
.SetClippingRegion(clipRect
);
250 textY
= rect
.y
+ (rect
.height
-textHeight
)/2;
251 dc
.DrawText(item
.GetLabel(), textX
, textY
);
252 dc
.DestroyClippingRegion();
256 void wxAuiDefaultToolBarArt::DrawButton(
258 wxWindow
* WXUNUSED(wnd
),
259 const wxAuiToolBarItem
& item
,
262 int textWidth
= 0, textHeight
= 0;
264 if (m_flags
& wxAUI_TB_TEXT
)
270 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
272 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
275 int bmpX
= 0, bmpY
= 0;
276 int textX
= 0, textY
= 0;
278 if (m_textOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
282 (item
.GetBitmap().GetWidth()/2);
285 ((rect
.height
-textHeight
)/2) -
286 (item
.GetBitmap().GetHeight()/2);
288 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
289 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
291 else if (m_textOrientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
297 (item
.GetBitmap().GetHeight()/2);
299 textX
= bmpX
+ 3 + item
.GetBitmap().GetWidth();
306 if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
))
308 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
310 dc
.SetPen(wxPen(m_highlightColour
));
311 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(150)));
312 dc
.DrawRectangle(rect
);
314 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
316 dc
.SetPen(wxPen(m_highlightColour
));
317 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
319 // draw an even lighter background for checked item hovers (since
320 // the hover background is the same color as the check background)
321 if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
322 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(180)));
324 dc
.DrawRectangle(rect
);
326 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
328 // it's important to put this code in an else statement after the
329 // hover, otherwise hovers won't draw properly for checked items
330 dc
.SetPen(wxPen(m_highlightColour
));
331 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
332 dc
.DrawRectangle(rect
);
337 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
338 bmp
= item
.GetDisabledBitmap();
340 bmp
= item
.GetBitmap();
343 dc
.DrawBitmap(bmp
, bmpX
, bmpY
, true);
345 // set the item's text color based on if it is disabled
346 dc
.SetTextForeground(*wxBLACK
);
347 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
348 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
350 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
352 dc
.DrawText(item
.GetLabel(), textX
, textY
);
357 void wxAuiDefaultToolBarArt::DrawDropDownButton(
359 wxWindow
* WXUNUSED(wnd
),
360 const wxAuiToolBarItem
& item
,
363 int textWidth
= 0, textHeight
= 0, textX
= 0, textY
= 0;
364 int bmpX
= 0, bmpY
= 0, dropBmpX
= 0, dropBmpY
= 0;
366 wxRect buttonRect
= wxRect(rect
.x
,
368 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
370 wxRect dropDownRect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
372 BUTTON_DROPDOWN_WIDTH
+1,
375 if (m_flags
& wxAUI_TB_TEXT
)
380 if (m_flags
& wxAUI_TB_TEXT
)
382 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
386 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
391 dropBmpX
= dropDownRect
.x
+
392 (dropDownRect
.width
/2) -
393 (m_buttonDropDownBmp
.GetWidth()/2);
394 dropBmpY
= dropDownRect
.y
+
395 (dropDownRect
.height
/2) -
396 (m_buttonDropDownBmp
.GetHeight()/2);
399 if (m_textOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
401 bmpX
= buttonRect
.x
+
402 (buttonRect
.width
/2) -
403 (item
.GetBitmap().GetWidth()/2);
404 bmpY
= buttonRect
.y
+
405 ((buttonRect
.height
-textHeight
)/2) -
406 (item
.GetBitmap().GetHeight()/2);
408 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
409 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
411 else if (m_textOrientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
417 (item
.GetBitmap().GetHeight()/2);
419 textX
= bmpX
+ 3 + item
.GetBitmap().GetWidth();
426 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
428 dc
.SetPen(wxPen(m_highlightColour
));
429 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(140)));
430 dc
.DrawRectangle(buttonRect
);
432 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
433 dc
.DrawRectangle(dropDownRect
);
435 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
438 dc
.SetPen(wxPen(m_highlightColour
));
439 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
440 dc
.DrawRectangle(buttonRect
);
441 dc
.DrawRectangle(dropDownRect
);
443 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
445 // Notice that this branch must come after the hover one to ensure the
446 // correct appearance when the mouse hovers over a checked item.m_
447 dc
.SetPen(wxPen(m_highlightColour
));
448 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
449 dc
.DrawRectangle(buttonRect
);
450 dc
.DrawRectangle(dropDownRect
);
455 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
457 bmp
= item
.GetDisabledBitmap();
458 dropbmp
= m_disabledButtonDropDownBmp
;
462 bmp
= item
.GetBitmap();
463 dropbmp
= m_buttonDropDownBmp
;
469 dc
.DrawBitmap(bmp
, bmpX
, bmpY
, true);
470 dc
.DrawBitmap(dropbmp
, dropBmpX
, dropBmpY
, true);
472 // set the item's text color based on if it is disabled
473 dc
.SetTextForeground(*wxBLACK
);
474 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
475 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
477 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
479 dc
.DrawText(item
.GetLabel(), textX
, textY
);
483 void wxAuiDefaultToolBarArt::DrawControlLabel(
485 wxWindow
* WXUNUSED(wnd
),
486 const wxAuiToolBarItem
& item
,
489 if (!(m_flags
& wxAUI_TB_TEXT
))
492 if (m_textOrientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
495 int textX
= 0, textY
= 0;
496 int textWidth
= 0, textHeight
= 0;
501 if (m_flags
& wxAUI_TB_TEXT
)
503 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
507 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
509 // don't draw the label if it is wider than the item width
510 if (textWidth
> rect
.width
)
513 // set the label's text color
514 dc
.SetTextForeground(*wxBLACK
);
516 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
517 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
519 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
521 dc
.DrawText(item
.GetLabel(), textX
, textY
);
525 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
527 wxWindow
* WXUNUSED(wnd
),
528 const wxAuiToolBarItem
& item
)
532 // get label's height
533 int width
= 0, height
= 0;
534 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
537 width
= item
.GetMinSize().GetWidth();
541 // no width specified, measure the text ourselves
542 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
545 return wxSize(width
, height
);
548 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
550 wxWindow
* WXUNUSED(wnd
),
551 const wxAuiToolBarItem
& item
)
553 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
554 return wxSize(16,16);
556 int width
= item
.GetBitmap().GetWidth();
557 int height
= item
.GetBitmap().GetHeight();
559 if (m_flags
& wxAUI_TB_TEXT
)
564 if (m_textOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
566 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
569 if ( !item
.GetLabel().empty() )
571 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
572 width
= wxMax(width
, tx
+6);
575 else if ( m_textOrientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
576 !item
.GetLabel().empty() )
578 width
+= 3; // space between left border and bitmap
579 width
+= 3; // space between bitmap and text
581 if ( !item
.GetLabel().empty() )
583 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
585 height
= wxMax(height
, ty
);
590 // if the tool has a dropdown button, add it to the width
591 if (item
.HasDropDown())
592 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
594 return wxSize(width
, height
);
597 void wxAuiDefaultToolBarArt::DrawSeparator(
599 wxWindow
* WXUNUSED(wnd
),
602 bool horizontal
= true;
603 if (m_flags
& wxAUI_TB_VERTICAL
)
610 rect
.x
+= (rect
.width
/2);
612 int new_height
= (rect
.height
*3)/4;
613 rect
.y
+= (rect
.height
/2) - (new_height
/2);
614 rect
.height
= new_height
;
618 rect
.y
+= (rect
.height
/2);
620 int new_width
= (rect
.width
*3)/4;
621 rect
.x
+= (rect
.width
/2) - (new_width
/2);
622 rect
.width
= new_width
;
625 wxColour startColour
= m_baseColour
.ChangeLightness(80);
626 wxColour endColour
= m_baseColour
.ChangeLightness(80);
627 dc
.GradientFillLinear(rect
, startColour
, endColour
, horizontal
? wxSOUTH
: wxEAST
);
630 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
631 wxWindow
* WXUNUSED(wnd
),
639 if (m_flags
& wxAUI_TB_VERTICAL
)
641 x
= rect
.x
+ (i
*4) + 5;
643 if (x
> rect
.GetWidth()-5)
649 y
= rect
.y
+ (i
*4) + 5;
650 if (y
> rect
.GetHeight()-5)
654 dc
.SetPen(m_gripperPen1
);
656 dc
.SetPen(m_gripperPen2
);
657 dc
.DrawPoint(x
, y
+1);
658 dc
.DrawPoint(x
+1, y
);
659 dc
.SetPen(m_gripperPen3
);
660 dc
.DrawPoint(x
+2, y
+1);
661 dc
.DrawPoint(x
+2, y
+2);
662 dc
.DrawPoint(x
+1, y
+2);
669 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
674 if (state
& wxAUI_BUTTON_STATE_HOVER
||
675 state
& wxAUI_BUTTON_STATE_PRESSED
)
677 wxColor light_gray_bg
= m_highlightColour
.ChangeLightness(170);
679 if (m_flags
& wxAUI_TB_VERTICAL
)
681 dc
.SetPen(wxPen(m_highlightColour
));
682 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
683 dc
.SetPen(wxPen(light_gray_bg
));
684 dc
.SetBrush(wxBrush(light_gray_bg
));
685 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
689 dc
.SetPen(wxPen(m_highlightColour
));
690 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
691 dc
.SetPen(wxPen(light_gray_bg
));
692 dc
.SetBrush(wxBrush(light_gray_bg
));
693 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
697 int x
= rect
.x
+1+(rect
.width
-m_overflowBmp
.GetWidth())/2;
698 int y
= rect
.y
+1+(rect
.height
-m_overflowBmp
.GetHeight())/2;
699 dc
.DrawBitmap(m_overflowBmp
, x
, y
, true);
702 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
706 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separatorSize
;
707 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripperSize
;
708 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflowSize
;
713 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
717 case wxAUI_TBART_SEPARATOR_SIZE
: m_separatorSize
= size
; break;
718 case wxAUI_TBART_GRIPPER_SIZE
: m_gripperSize
= size
; break;
719 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflowSize
= size
; break;
723 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
724 const wxAuiToolBarItemArray
& items
)
728 size_t items_added
= 0;
730 size_t i
, count
= items
.GetCount();
731 for (i
= 0; i
< count
; ++i
)
733 wxAuiToolBarItem
& item
= items
.Item(i
);
735 if (item
.GetKind() == wxITEM_NORMAL
)
737 wxString text
= item
.GetShortHelp();
739 text
= item
.GetLabel();
744 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
746 m
->SetBitmap(item
.GetBitmap());
750 else if (item
.GetKind() == wxITEM_SEPARATOR
)
753 menuPopup
.AppendSeparator();
757 // find out where to put the popup menu of window items
758 wxPoint pt
= ::wxGetMousePosition();
759 pt
= wnd
->ScreenToClient(pt
);
761 // find out the screen coordinate at the bottom of the tab ctrl
762 wxRect cli_rect
= wnd
->GetClientRect();
763 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
765 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
766 wnd
->PushEventHandler(cc
);
767 wnd
->PopupMenu(&menuPopup
, pt
);
768 int command
= cc
->GetCommandId();
769 wnd
->PopEventHandler(true);
777 static wxOrientation
GetOrientation(long& style
)
779 switch (style
& wxAUI_ORIENTATION_MASK
)
781 case wxAUI_TB_HORIZONTAL
:
783 case wxAUI_TB_VERTICAL
:
786 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
793 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
794 EVT_SIZE(wxAuiToolBar::OnSize
)
795 EVT_IDLE(wxAuiToolBar::OnIdle
)
796 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
797 EVT_PAINT(wxAuiToolBar::OnPaint
)
798 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
799 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
800 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
801 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
802 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
803 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
804 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
805 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
806 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
807 EVT_MOTION(wxAuiToolBar::OnMotion
)
808 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
809 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
810 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
813 void wxAuiToolBar::Init()
815 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
818 m_sizerElementCount
= 0;
819 m_actionPos
= wxDefaultPosition
;
822 m_art
= new wxAuiDefaultToolBarArt
;
824 m_toolBorderPadding
= 3;
825 m_toolTextOrientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
826 m_gripperSizerItem
= NULL
;
827 m_overflowSizerItem
= NULL
;
829 m_gripperVisible
= false;
830 m_overflowVisible
= false;
832 m_orientation
= wxHORIZONTAL
;
835 bool wxAuiToolBar::Create(wxWindow
* parent
,
841 style
= style
|wxBORDER_NONE
;
843 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
846 m_windowStyle
= style
;
848 m_gripperVisible
= (style
& wxAUI_TB_GRIPPER
) ? true : false;
849 m_overflowVisible
= (style
& wxAUI_TB_OVERFLOW
) ? true : false;
851 m_orientation
= GetOrientation(style
);
852 if (m_orientation
== wxBOTH
)
854 m_orientation
= wxHORIZONTAL
;
857 SetMargins(5, 5, 2, 2);
858 SetFont(*wxNORMAL_FONT
);
860 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
861 if (style
& wxAUI_TB_HORZ_LAYOUT
)
862 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
863 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
868 wxAuiToolBar::~wxAuiToolBar()
874 void wxAuiToolBar::SetWindowStyleFlag(long style
)
876 GetOrientation(style
); // assert if style is invalid
877 wxCHECK_RET(IsPaneValid(style
),
878 "window settings and pane settings are incompatible");
880 wxControl::SetWindowStyleFlag(style
);
882 m_windowStyle
= style
;
889 if (m_windowStyle
& wxAUI_TB_GRIPPER
)
890 m_gripperVisible
= true;
892 m_gripperVisible
= false;
895 if (m_windowStyle
& wxAUI_TB_OVERFLOW
)
896 m_overflowVisible
= true;
898 m_overflowVisible
= false;
900 if (style
& wxAUI_TB_HORZ_LAYOUT
)
901 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
903 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
906 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
915 m_art
->SetTextOrientation(m_toolTextOrientation
);
919 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
927 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
928 const wxString
& label
,
929 const wxBitmap
& bitmap
,
930 const wxString
& shortHelp_string
,
933 return AddTool(tool_id
,
944 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
945 const wxString
& label
,
946 const wxBitmap
& bitmap
,
947 const wxBitmap
& disabledBitmap
,
949 const wxString
& shortHelpString
,
950 const wxString
& longHelpString
,
951 wxObject
* WXUNUSED(client_data
))
953 wxAuiToolBarItem item
;
954 item
.m_window
= NULL
;
955 item
.m_label
= label
;
956 item
.m_bitmap
= bitmap
;
957 item
.m_disabledBitmap
= disabledBitmap
;
958 item
.m_shortHelp
= shortHelpString
;
959 item
.m_longHelp
= longHelpString
;
960 item
.m_active
= true;
961 item
.m_dropDown
= false;
962 item
.m_spacerPixels
= 0;
963 item
.m_toolId
= tool_id
;
965 item
.m_proportion
= 0;
967 item
.m_sizerItem
= NULL
;
968 item
.m_minSize
= wxDefaultSize
;
970 item
.m_sticky
= false;
972 if (item
.m_toolId
== wxID_ANY
)
973 item
.m_toolId
= wxNewId();
975 if (!item
.m_disabledBitmap
.IsOk())
977 // no disabled bitmap specified, we need to make one
978 if (item
.m_bitmap
.IsOk())
980 item
.m_disabledBitmap
= item
.m_bitmap
.ConvertToDisabled();
984 return &m_items
.Last();
987 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
988 const wxString
& label
)
990 wxAuiToolBarItem item
;
991 item
.m_window
= (wxWindow
*)control
;
992 item
.m_label
= label
;
993 item
.m_bitmap
= wxNullBitmap
;
994 item
.m_disabledBitmap
= wxNullBitmap
;
995 item
.m_active
= true;
996 item
.m_dropDown
= false;
997 item
.m_spacerPixels
= 0;
998 item
.m_toolId
= control
->GetId();
1000 item
.m_proportion
= 0;
1001 item
.m_kind
= wxITEM_CONTROL
;
1002 item
.m_sizerItem
= NULL
;
1003 item
.m_minSize
= control
->GetEffectiveMinSize();
1004 item
.m_userData
= 0;
1005 item
.m_sticky
= false;
1008 return &m_items
.Last();
1011 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1012 const wxString
& label
,
1015 wxSize min_size
= wxDefaultSize
;
1019 wxAuiToolBarItem item
;
1020 item
.m_window
= NULL
;
1021 item
.m_label
= label
;
1022 item
.m_bitmap
= wxNullBitmap
;
1023 item
.m_disabledBitmap
= wxNullBitmap
;
1024 item
.m_active
= true;
1025 item
.m_dropDown
= false;
1026 item
.m_spacerPixels
= 0;
1027 item
.m_toolId
= tool_id
;
1029 item
.m_proportion
= 0;
1030 item
.m_kind
= wxITEM_LABEL
;
1031 item
.m_sizerItem
= NULL
;
1032 item
.m_minSize
= min_size
;
1033 item
.m_userData
= 0;
1034 item
.m_sticky
= false;
1036 if (item
.m_toolId
== wxID_ANY
)
1037 item
.m_toolId
= wxNewId();
1040 return &m_items
.Last();
1043 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1045 wxAuiToolBarItem item
;
1046 item
.m_window
= NULL
;
1047 item
.m_label
= wxEmptyString
;
1048 item
.m_bitmap
= wxNullBitmap
;
1049 item
.m_disabledBitmap
= wxNullBitmap
;
1050 item
.m_active
= true;
1051 item
.m_dropDown
= false;
1054 item
.m_proportion
= 0;
1055 item
.m_kind
= wxITEM_SEPARATOR
;
1056 item
.m_sizerItem
= NULL
;
1057 item
.m_minSize
= wxDefaultSize
;
1058 item
.m_userData
= 0;
1059 item
.m_sticky
= false;
1062 return &m_items
.Last();
1065 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1067 wxAuiToolBarItem item
;
1068 item
.m_window
= NULL
;
1069 item
.m_label
= wxEmptyString
;
1070 item
.m_bitmap
= wxNullBitmap
;
1071 item
.m_disabledBitmap
= wxNullBitmap
;
1072 item
.m_active
= true;
1073 item
.m_dropDown
= false;
1074 item
.m_spacerPixels
= pixels
;
1077 item
.m_proportion
= 0;
1078 item
.m_kind
= wxITEM_SPACER
;
1079 item
.m_sizerItem
= NULL
;
1080 item
.m_minSize
= wxDefaultSize
;
1081 item
.m_userData
= 0;
1082 item
.m_sticky
= false;
1085 return &m_items
.Last();
1088 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1090 wxAuiToolBarItem item
;
1091 item
.m_window
= NULL
;
1092 item
.m_label
= wxEmptyString
;
1093 item
.m_bitmap
= wxNullBitmap
;
1094 item
.m_disabledBitmap
= wxNullBitmap
;
1095 item
.m_active
= true;
1096 item
.m_dropDown
= false;
1097 item
.m_spacerPixels
= 0;
1100 item
.m_proportion
= proportion
;
1101 item
.m_kind
= wxITEM_SPACER
;
1102 item
.m_sizerItem
= NULL
;
1103 item
.m_minSize
= wxDefaultSize
;
1104 item
.m_userData
= 0;
1105 item
.m_sticky
= false;
1108 return &m_items
.Last();
1111 void wxAuiToolBar::Clear()
1114 m_sizerElementCount
= 0;
1117 bool wxAuiToolBar::DeleteTool(int tool_id
)
1119 int idx
= GetToolIndex(tool_id
);
1120 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1122 m_items
.RemoveAt(idx
);
1130 bool wxAuiToolBar::DeleteByIndex(int idx
)
1132 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1134 m_items
.RemoveAt(idx
);
1143 wxControl
* wxAuiToolBar::FindControl(int id
)
1145 wxWindow
* wnd
= FindWindow(id
);
1146 return (wxControl
*)wnd
;
1149 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1152 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1154 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1155 if (item
.m_toolId
== tool_id
)
1162 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1165 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1167 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1169 if (!item
.m_sizerItem
)
1172 wxRect rect
= item
.m_sizerItem
->GetRect();
1173 if (rect
.Contains(x
,y
))
1175 // if the item doesn't fit on the toolbar, return NULL
1176 if (!GetToolFitsByIndex(i
))
1186 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1189 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1191 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1193 if (!item
.m_sizerItem
)
1196 wxRect rect
= item
.m_sizerItem
->GetRect();
1198 // apply tool packing
1200 rect
.width
+= m_toolPacking
;
1202 if (rect
.Contains(x
,y
))
1204 // if the item doesn't fit on the toolbar, return NULL
1205 if (!GetToolFitsByIndex(i
))
1215 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1220 if (idx
>= (int)m_items
.size())
1223 return &(m_items
[idx
]);
1226 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1228 // TODO: wxToolBar compatibility
1231 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1233 // TODO: wxToolBar compatibility
1234 return wxSize(16,15);
1237 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1239 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1243 item
->m_proportion
= proportion
;
1246 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1248 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1252 return item
->m_proportion
;
1255 void wxAuiToolBar::SetToolSeparation(int separation
)
1258 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1261 int wxAuiToolBar::GetToolSeparation() const
1264 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1270 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1272 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1276 item
->SetHasDropDown(dropdown
);
1279 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1281 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1285 return item
->HasDropDown();
1288 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1290 // ignore separators
1294 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1298 if (item
->m_sticky
== sticky
)
1301 item
->m_sticky
= sticky
;
1307 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1309 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1313 return item
->m_sticky
;
1319 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1321 m_toolBorderPadding
= padding
;
1324 int wxAuiToolBar::GetToolBorderPadding() const
1326 return m_toolBorderPadding
;
1329 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1331 m_toolTextOrientation
= orientation
;
1335 m_art
->SetTextOrientation(orientation
);
1339 int wxAuiToolBar::GetToolTextOrientation() const
1341 return m_toolTextOrientation
;
1344 void wxAuiToolBar::SetToolPacking(int packing
)
1346 m_toolPacking
= packing
;
1349 int wxAuiToolBar::GetToolPacking() const
1351 return m_toolPacking
;
1355 void wxAuiToolBar::SetOrientation(int orientation
)
1357 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1358 orientation
== wxVERTICAL
,
1359 "invalid orientation value");
1360 if (orientation
!= m_orientation
)
1362 m_orientation
= wxOrientation(orientation
);
1367 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1370 m_leftPadding
= left
;
1372 m_rightPadding
= right
;
1376 m_bottomPadding
= bottom
;
1379 bool wxAuiToolBar::GetGripperVisible() const
1381 return m_gripperVisible
;
1384 void wxAuiToolBar::SetGripperVisible(bool visible
)
1386 m_gripperVisible
= visible
;
1388 m_windowStyle
|= wxAUI_TB_GRIPPER
;
1390 m_windowStyle
&= ~wxAUI_TB_GRIPPER
;
1396 bool wxAuiToolBar::GetOverflowVisible() const
1398 return m_overflowVisible
;
1401 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1403 m_overflowVisible
= visible
;
1405 m_windowStyle
|= wxAUI_TB_OVERFLOW
;
1407 m_windowStyle
&= ~wxAUI_TB_OVERFLOW
;
1411 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1413 bool res
= wxWindow::SetFont(font
);
1417 m_art
->SetFont(font
);
1424 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1426 if (pitem
&& (pitem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
))
1429 wxAuiToolBarItem
* former_hover
= NULL
;
1432 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1434 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1435 if (item
.m_state
& wxAUI_BUTTON_STATE_HOVER
)
1436 former_hover
= &item
;
1437 item
.m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1442 pitem
->m_state
|= wxAUI_BUTTON_STATE_HOVER
;
1445 if (former_hover
!= pitem
)
1452 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1454 wxAuiToolBarItem
* former_item
= NULL
;
1457 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1459 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1460 if (item
.m_state
& wxAUI_BUTTON_STATE_PRESSED
)
1461 former_item
= &item
;
1462 item
.m_state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1467 pitem
->m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1468 pitem
->m_state
|= wxAUI_BUTTON_STATE_PRESSED
;
1471 if (former_item
!= pitem
)
1478 void wxAuiToolBar::RefreshOverflowState()
1480 if (!m_overflowSizerItem
)
1482 m_overflowState
= 0;
1486 int overflow_state
= 0;
1488 wxRect overflow_rect
= GetOverflowRect();
1491 // find out the mouse's current position
1492 wxPoint pt
= ::wxGetMousePosition();
1493 pt
= this->ScreenToClient(pt
);
1495 // find out if the mouse cursor is inside the dropdown rectangle
1496 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1498 if (::wxGetMouseState().LeftIsDown())
1499 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1501 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1504 if (overflow_state
!= m_overflowState
)
1506 m_overflowState
= overflow_state
;
1511 m_overflowState
= overflow_state
;
1514 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1516 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1518 if (tool
&& (tool
->m_kind
== wxITEM_CHECK
|| tool
->m_kind
== wxITEM_RADIO
))
1520 if (tool
->m_kind
== wxITEM_RADIO
)
1523 idx
= GetToolIndex(tool_id
);
1524 count
= (int)m_items
.GetCount();
1526 if (idx
>= 0 && idx
< count
)
1528 for (i
= idx
+ 1; i
< count
; ++i
)
1530 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1532 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1534 for (i
= idx
- 1; i
>= 0; i
--)
1536 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1538 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1542 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1544 else if (tool
->m_kind
== wxITEM_CHECK
)
1547 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1549 tool
->m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1554 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1556 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1560 if ( (tool
->m_kind
!= wxITEM_CHECK
) && (tool
->m_kind
!= wxITEM_RADIO
) )
1563 return (tool
->m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1569 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1571 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1576 tool
->m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1578 tool
->m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1582 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1584 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1587 return (tool
->m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1592 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1594 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1595 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1597 return wxEmptyString
;
1599 return tool
->m_label
;
1602 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1604 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1607 tool
->m_label
= label
;
1611 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1613 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1614 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1616 return wxNullBitmap
;
1618 return tool
->m_bitmap
;
1621 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1623 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1626 tool
->m_bitmap
= bitmap
;
1630 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1632 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1633 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1635 return wxEmptyString
;
1637 return tool
->m_shortHelp
;
1640 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1642 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1645 tool
->m_shortHelp
= help_string
;
1649 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1651 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1652 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1654 return wxEmptyString
;
1656 return tool
->m_longHelp
;
1659 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1661 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1664 tool
->m_longHelp
= help_string
;
1668 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1669 const wxAuiToolBarItemArray
& append
)
1671 m_customOverflowPrepend
= prepend
;
1672 m_customOverflowAppend
= append
;
1675 // get size of hint rectangle for a particular dock location
1676 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1678 switch (dock_direction
)
1680 case wxAUI_DOCK_TOP
:
1681 case wxAUI_DOCK_BOTTOM
:
1682 return m_horzHintSize
;
1683 case wxAUI_DOCK_RIGHT
:
1684 case wxAUI_DOCK_LEFT
:
1685 return m_vertHintSize
;
1687 wxFAIL_MSG("invalid dock location value");
1689 return wxDefaultSize
;
1692 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1694 return IsPaneValid(m_windowStyle
, pane
);
1697 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1699 if (style
& wxAUI_TB_HORIZONTAL
)
1701 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1706 else if (style
& wxAUI_TB_VERTICAL
)
1708 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1716 bool wxAuiToolBar::IsPaneValid(long style
) const
1718 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1721 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1726 void wxAuiToolBar::SetArtFlags() const
1728 unsigned int artflags
= m_windowStyle
& ~wxAUI_ORIENTATION_MASK
;
1729 if (m_orientation
== wxVERTICAL
)
1731 artflags
|= wxAUI_TB_VERTICAL
;
1733 m_art
->SetFlags(artflags
);
1736 size_t wxAuiToolBar::GetToolCount() const
1738 return m_items
.size();
1741 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1743 // this will prevent us from returning the index of the
1744 // first separator in the toolbar since its id is equal to -1
1748 size_t i
, count
= m_items
.GetCount();
1749 for (i
= 0; i
< count
; ++i
)
1751 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1752 if (item
.m_toolId
== tool_id
)
1759 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1761 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1764 if (!m_items
[tool_idx
].m_sizerItem
)
1768 GetClientSize(&cli_w
, &cli_h
);
1770 wxRect rect
= m_items
[tool_idx
].m_sizerItem
->GetRect();
1772 if (m_orientation
== wxVERTICAL
)
1774 // take the dropdown size into account
1775 if (m_overflowVisible
)
1776 cli_h
-= m_overflowSizerItem
->GetSize().y
;
1778 if (rect
.y
+rect
.height
< cli_h
)
1783 // take the dropdown size into account
1784 if (m_overflowVisible
)
1785 cli_w
-= m_overflowSizerItem
->GetSize().x
;
1787 if (rect
.x
+rect
.width
< cli_w
)
1795 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1797 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1800 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1802 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1803 if (tool
&& tool
->m_sizerItem
)
1805 return tool
->m_sizerItem
->GetRect();
1811 bool wxAuiToolBar::GetToolBarFits() const
1813 if (m_items
.GetCount() == 0)
1815 // empty toolbar always 'fits'
1819 // entire toolbar content fits if the last tool fits
1820 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1823 bool wxAuiToolBar::Realize()
1825 wxClientDC
dc(this);
1829 // calculate hint sizes for both horizontal and vertical
1830 // in the order that leaves toolbar in correct final state
1831 bool retval
= false;
1832 if (m_orientation
== wxHORIZONTAL
)
1834 if (RealizeHelper(dc
, false))
1836 m_vertHintSize
= GetSize();
1837 if (RealizeHelper(dc
, true))
1839 m_horzHintSize
= GetSize();
1846 if (RealizeHelper(dc
, true))
1848 m_horzHintSize
= GetSize();
1849 if (RealizeHelper(dc
, false))
1851 m_vertHintSize
= GetSize();
1861 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1863 // create the new sizer to add toolbar elements to
1864 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1867 int separatorSize
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1868 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1869 if (gripperSize
> 0 && m_gripperVisible
)
1872 m_gripperSizerItem
= sizer
->Add(gripperSize
, 1, 0, wxEXPAND
);
1874 m_gripperSizerItem
= sizer
->Add(1, gripperSize
, 0, wxEXPAND
);
1878 m_gripperSizerItem
= NULL
;
1881 // add "left" padding
1882 if (m_leftPadding
> 0)
1885 sizer
->Add(m_leftPadding
, 1);
1887 sizer
->Add(1, m_leftPadding
);
1891 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1893 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1894 wxSizerItem
* m_sizerItem
= NULL
;
1896 switch (item
.m_kind
)
1900 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1901 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1902 size
.y
+ (m_toolBorderPadding
*2),
1907 sizer
->AddSpacer(m_toolPacking
);
1917 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1918 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1919 size
.y
+ (m_toolBorderPadding
*2),
1925 sizer
->AddSpacer(m_toolPacking
);
1931 case wxITEM_SEPARATOR
:
1934 m_sizerItem
= sizer
->Add(separatorSize
, 1, 0, wxEXPAND
);
1936 m_sizerItem
= sizer
->Add(1, separatorSize
, 0, wxEXPAND
);
1941 sizer
->AddSpacer(m_toolPacking
);
1948 if (item
.m_proportion
> 0)
1949 m_sizerItem
= sizer
->AddStretchSpacer(item
.m_proportion
);
1951 m_sizerItem
= sizer
->Add(item
.m_spacerPixels
, 1);
1954 case wxITEM_CONTROL
:
1956 //m_sizerItem = sizer->Add(item.m_window, item.m_proportion, wxEXPAND);
1957 wxSizerItem
* ctrl_m_sizerItem
;
1959 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1960 vert_sizer
->AddStretchSpacer(1);
1961 ctrl_m_sizerItem
= vert_sizer
->Add(item
.m_window
, 0, wxEXPAND
);
1962 vert_sizer
->AddStretchSpacer(1);
1963 if ( (m_windowStyle
& wxAUI_TB_TEXT
) &&
1964 m_toolTextOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1965 !item
.GetLabel().empty() )
1967 wxSize s
= GetLabelSize(item
.GetLabel());
1968 vert_sizer
->Add(1, s
.y
);
1972 m_sizerItem
= sizer
->Add(vert_sizer
, item
.m_proportion
, wxEXPAND
);
1974 wxSize min_size
= item
.m_minSize
;
1977 // proportional items will disappear from the toolbar if
1978 // their min width is not set to something really small
1979 if (item
.m_proportion
!= 0)
1984 if (min_size
.IsFullySpecified())
1986 m_sizerItem
->SetMinSize(min_size
);
1987 ctrl_m_sizerItem
->SetMinSize(min_size
);
1993 sizer
->AddSpacer(m_toolPacking
);
1998 item
.m_sizerItem
= m_sizerItem
;
2001 // add "right" padding
2002 if (m_rightPadding
> 0)
2005 sizer
->Add(m_rightPadding
, 1);
2007 sizer
->Add(1, m_rightPadding
);
2010 // add drop down area
2011 m_overflowSizerItem
= NULL
;
2013 if (m_windowStyle
& wxAUI_TB_OVERFLOW
)
2015 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2016 if (overflow_size
> 0 && m_overflowVisible
)
2019 m_overflowSizerItem
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2021 m_overflowSizerItem
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2025 m_overflowSizerItem
= NULL
;
2030 // the outside sizer helps us apply the "top" and "bottom" padding
2031 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2033 // add "top" padding
2034 if (m_topPadding
> 0)
2037 outside_sizer
->Add(1, m_topPadding
);
2039 outside_sizer
->Add(m_topPadding
, 1);
2042 // add the sizer that contains all of the toolbar elements
2043 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2045 // add "bottom" padding
2046 if (m_bottomPadding
> 0)
2049 outside_sizer
->Add(1, m_bottomPadding
);
2051 outside_sizer
->Add(m_bottomPadding
, 1);
2054 delete m_sizer
; // remove old sizer
2055 m_sizer
= outside_sizer
;
2057 // calculate the rock-bottom minimum size
2058 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2060 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2061 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2062 item
.m_sizerItem
->SetMinSize(0,0);
2065 m_absoluteMinSize
= m_sizer
->GetMinSize();
2067 // reset the min sizes to what they were
2068 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2070 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2071 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2072 item
.m_sizerItem
->SetMinSize(item
.m_minSize
);
2076 wxSize size
= m_sizer
->GetMinSize();
2077 m_minWidth
= size
.x
;
2078 m_minHeight
= size
.y
;
2080 if ((m_windowStyle
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2082 wxSize curSize
= GetClientSize();
2083 wxSize new_size
= GetMinSize();
2084 if (new_size
!= curSize
)
2086 SetClientSize(new_size
);
2090 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2095 wxSize curSize
= GetClientSize();
2096 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2102 int wxAuiToolBar::GetOverflowState() const
2104 return m_overflowState
;
2107 wxRect
wxAuiToolBar::GetOverflowRect() const
2109 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2110 wxRect overflow_rect
= m_overflowSizerItem
->GetRect();
2111 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2113 if (m_orientation
== wxVERTICAL
)
2115 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2116 overflow_rect
.x
= 0;
2117 overflow_rect
.width
= cli_rect
.width
;
2118 overflow_rect
.height
= overflow_size
;
2122 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2123 overflow_rect
.y
= 0;
2124 overflow_rect
.width
= overflow_size
;
2125 overflow_rect
.height
= cli_rect
.height
;
2128 return overflow_rect
;
2131 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2133 wxClientDC
dc(this);
2136 int textWidth
= 0, textHeight
= 0;
2140 // get the text height
2141 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
2143 // get the text width
2144 dc
.GetTextExtent(label
, &textWidth
, &ty
);
2146 return wxSize(textWidth
, textHeight
);
2150 void wxAuiToolBar::DoIdleUpdate()
2152 wxEvtHandler
* handler
= GetEventHandler();
2154 bool need_refresh
= false;
2157 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2159 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2161 if (item
.m_toolId
== -1)
2164 wxUpdateUIEvent
evt(item
.m_toolId
);
2165 evt
.SetEventObject(this);
2167 if (handler
->ProcessEvent(evt
))
2169 if (evt
.GetSetEnabled())
2173 is_enabled
= item
.m_window
->IsThisEnabled();
2175 is_enabled
= (item
.m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2177 bool new_enabled
= evt
.GetEnabled();
2178 if (new_enabled
!= is_enabled
)
2182 item
.m_window
->Enable(new_enabled
);
2187 item
.m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2189 item
.m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
2191 need_refresh
= true;
2195 if (evt
.GetSetChecked())
2197 // make sure we aren't checking an item that can't be
2198 if (item
.m_kind
!= wxITEM_CHECK
&& item
.m_kind
!= wxITEM_RADIO
)
2201 bool is_checked
= (item
.m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2202 bool new_checked
= evt
.GetChecked();
2204 if (new_checked
!= is_checked
)
2207 item
.m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
2209 item
.m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2211 need_refresh
= true;
2226 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2229 GetClientSize(&x
, &y
);
2231 if (((x
>= y
) && m_absoluteMinSize
.x
> x
) ||
2232 ((y
> x
) && m_absoluteMinSize
.y
> y
))
2234 // hide all flexible items
2236 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2238 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2239 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_sizerItem
->IsShown())
2241 item
.m_sizerItem
->Show(false);
2242 item
.m_sizerItem
->SetProportion(0);
2248 // show all flexible items
2250 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2252 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2253 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && !item
.m_sizerItem
->IsShown())
2255 item
.m_sizerItem
->Show(true);
2256 item
.m_sizerItem
->SetProportion(item
.m_proportion
);
2261 m_sizer
->SetDimension(0, 0, x
, y
);
2266 // idle events aren't sent while user is resizing frame (why?),
2267 // but resizing toolbar here causes havoc,
2268 // so force idle handler to run after size handling complete
2269 QueueEvent(new wxIdleEvent
);
2274 void wxAuiToolBar::DoSetSize(int x
,
2280 wxSize parent_size
= GetParent()->GetClientSize();
2281 if (x
+ width
> parent_size
.x
)
2282 width
= wxMax(0, parent_size
.x
- x
);
2283 if (y
+ height
> parent_size
.y
)
2284 height
= wxMax(0, parent_size
.y
- y
);
2286 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2290 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2292 // if orientation doesn't match dock, fix it
2293 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2296 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2297 // pane state member is public, so it might have been changed
2298 // without going through wxPaneInfo::SetFlag() check
2299 bool ok
= pane
.IsOk();
2300 wxCHECK2_MSG(!ok
|| IsPaneValid(m_windowStyle
, pane
), ok
= false,
2301 "window settings and pane settings are incompatible");
2304 wxOrientation newOrientation
= m_orientation
;
2305 if (pane
.IsDocked())
2307 switch (pane
.dock_direction
)
2309 case wxAUI_DOCK_TOP
:
2310 case wxAUI_DOCK_BOTTOM
:
2311 newOrientation
= wxHORIZONTAL
;
2313 case wxAUI_DOCK_LEFT
:
2314 case wxAUI_DOCK_RIGHT
:
2315 newOrientation
= wxVERTICAL
;
2318 wxFAIL_MSG("invalid dock location value");
2321 else if (pane
.IsResizable() &&
2322 GetOrientation(m_windowStyle
) == wxBOTH
)
2324 // changing orientation in OnSize causes havoc
2326 GetClientSize(&x
, &y
);
2330 newOrientation
= wxHORIZONTAL
;
2334 newOrientation
= wxVERTICAL
;
2337 if (newOrientation
!= m_orientation
)
2339 SetOrientation(newOrientation
);
2341 if (newOrientation
== wxHORIZONTAL
)
2343 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2347 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2349 if (pane
.IsDocked())
2351 pane
.floating_size
= wxDefaultSize
;
2355 SetSize(GetParent()->GetClientSize());
2364 void wxAuiToolBar::UpdateWindowUI(long flags
)
2366 if ( flags
& wxUPDATE_UI_FROMIDLE
)
2371 wxControl::UpdateWindowUI(flags
);
2374 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2376 wxAutoBufferedPaintDC
dc(this);
2377 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2380 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2382 if (m_windowStyle
& wxAUI_TB_PLAIN_BACKGROUND
)
2383 m_art
->DrawPlainBackground(dc
, this, cli_rect
);
2385 m_art
->DrawBackground(dc
, this, cli_rect
);
2387 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2388 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2390 // paint the gripper
2391 if (gripperSize
> 0 && m_gripperSizerItem
)
2393 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2395 gripper_rect
.width
= gripperSize
;
2397 gripper_rect
.height
= gripperSize
;
2398 m_art
->DrawGripper(dc
, this, gripper_rect
);
2401 // calculated how far we can draw items
2404 last_extent
= cli_rect
.width
;
2406 last_extent
= cli_rect
.height
;
2407 if (m_overflowVisible
)
2408 last_extent
-= dropdown_size
;
2410 // paint each individual tool
2411 size_t i
, count
= m_items
.GetCount();
2412 for (i
= 0; i
< count
; ++i
)
2414 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2416 if (!item
.m_sizerItem
)
2419 wxRect item_rect
= item
.m_sizerItem
->GetRect();
2422 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2423 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2428 switch ( item
.m_kind
)
2431 // draw a regular or dropdown button
2432 if (!item
.m_dropDown
)
2433 m_art
->DrawButton(dc
, this, item
, item_rect
);
2435 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2440 // draw a toggle button
2441 m_art
->DrawButton(dc
, this, item
, item_rect
);
2444 case wxITEM_SEPARATOR
:
2446 m_art
->DrawSeparator(dc
, this, item_rect
);
2450 // draw a text label only
2451 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2454 case wxITEM_CONTROL
:
2455 // draw the control's label
2456 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2460 // fire a signal to see if the item wants to be custom-rendered
2461 OnCustomRender(dc
, item
, item_rect
);
2464 // paint the overflow button
2465 if (dropdown_size
> 0 && m_overflowSizerItem
)
2467 wxRect dropDownRect
= GetOverflowRect();
2468 m_art
->DrawOverflowButton(dc
, this, dropDownRect
, m_overflowState
);
2472 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2477 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2479 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2481 if (m_gripperSizerItem
)
2483 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2484 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2487 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2491 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2492 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2494 // gripper was clicked
2495 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2500 if (m_overflowSizerItem
)
2502 wxRect overflow_rect
= GetOverflowRect();
2505 m_overflowVisible
&&
2506 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2508 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2509 e
.SetEventObject(this);
2511 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2512 bool processed
= GetEventHandler()->ProcessEvent(e
);
2521 wxAuiToolBarItemArray overflow_items
;
2524 // add custom overflow prepend items, if any
2525 count
= m_customOverflowPrepend
.GetCount();
2526 for (i
= 0; i
< count
; ++i
)
2527 overflow_items
.Add(m_customOverflowPrepend
[i
]);
2529 // only show items that don't fit in the dropdown
2530 count
= m_items
.GetCount();
2531 for (i
= 0; i
< count
; ++i
)
2533 if (!GetToolFitsByIndex(i
))
2534 overflow_items
.Add(m_items
[i
]);
2537 // add custom overflow append items, if any
2538 count
= m_customOverflowAppend
.GetCount();
2539 for (i
= 0; i
< count
; ++i
)
2540 overflow_items
.Add(m_customOverflowAppend
[i
]);
2542 int res
= m_art
->ShowDropDown(this, overflow_items
);
2543 m_overflowState
= 0;
2547 wxCommandEvent
event(wxEVT_MENU
, res
);
2548 event
.SetEventObject(this);
2549 GetParent()->GetEventHandler()->ProcessEvent(event
);
2558 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2559 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2563 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2565 m_actionPos
= wxPoint(-1,-1);
2566 m_actionItem
= NULL
;
2572 // fire the tool dropdown event
2573 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_TOOL_DROPDOWN
, m_actionItem
->m_toolId
);
2574 e
.SetEventObject(this);
2575 e
.SetToolId(m_actionItem
->m_toolId
);
2577 int mouse_x
= evt
.GetX();
2578 wxRect rect
= m_actionItem
->m_sizerItem
->GetRect();
2579 const bool dropDownHit
= m_actionItem
->m_dropDown
&&
2580 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2581 mouse_x
< (rect
.x
+rect
.width
);
2582 e
.SetDropDownClicked(dropDownHit
);
2584 e
.SetClickPoint(evt
.GetPosition());
2585 e
.SetItemRect(rect
);
2587 // we only set the 'pressed button' state if we hit the actual button
2588 // and not just the drop-down
2589 SetPressedItem(dropDownHit
? 0 : m_actionItem
);
2593 m_actionPos
= wxPoint(-1,-1);
2594 m_actionItem
= NULL
;
2597 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2600 // Ensure hovered item is really ok, as mouse may have moved during
2602 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2603 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2609 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2614 SetPressedItem(NULL
);
2616 wxAuiToolBarItem
* hitItem
;
2617 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2618 SetHoverItem(hitItem
);
2622 // TODO: it would make sense to send out an 'END_DRAG' event here,
2623 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2626 // OnCaptureLost() will be called now and this will reset all our state
2627 // tracking variables
2632 if (m_actionItem
&& hitItem
== m_actionItem
)
2636 wxCommandEvent
e(wxEVT_MENU
, m_actionItem
->m_toolId
);
2637 e
.SetEventObject(this);
2639 if (hitItem
->m_kind
== wxITEM_CHECK
|| hitItem
->m_kind
== wxITEM_RADIO
)
2641 const bool toggle
= !(m_actionItem
->m_state
& wxAUI_BUTTON_STATE_CHECKED
);
2643 ToggleTool(m_actionItem
->m_toolId
, toggle
);
2645 // repaint immediately
2652 // we have to release the mouse *before* sending the event, because
2653 // we don't know what a handler might do. It could open up a popup
2654 // menu for example and that would make us lose our capture anyway.
2658 GetEventHandler()->ProcessEvent(e
);
2660 // Ensure hovered item is really ok, as mouse may have moved during
2662 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2663 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2672 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2674 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2676 if (m_gripperSizerItem
)
2678 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2679 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2683 if (m_overflowSizerItem
&& m_art
)
2685 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2686 if (dropdown_size
> 0 &&
2687 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2689 evt
.m_y
< cli_rect
.height
)
2695 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2696 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2698 if (m_actionItem
&& m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2700 m_actionPos
= wxPoint(-1,-1);
2701 m_actionItem
= NULL
;
2708 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2710 wxAuiToolBarItem
* hitItem
;
2711 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2713 if (m_actionItem
&& hitItem
== m_actionItem
)
2715 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_RIGHT_CLICK
, m_actionItem
->m_toolId
);
2716 e
.SetEventObject(this);
2717 e
.SetToolId(m_actionItem
->m_toolId
);
2718 e
.SetClickPoint(m_actionPos
);
2719 GetEventHandler()->ProcessEvent(e
);
2724 // right-clicked on the invalid area of the toolbar
2725 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_RIGHT_CLICK
, -1);
2726 e
.SetEventObject(this);
2728 e
.SetClickPoint(m_actionPos
);
2729 GetEventHandler()->ProcessEvent(e
);
2733 // reset member variables
2734 m_actionPos
= wxPoint(-1,-1);
2735 m_actionItem
= NULL
;
2738 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2740 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2742 if (m_gripperSizerItem
)
2744 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2745 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2749 if (m_overflowSizerItem
&& m_art
)
2751 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2752 if (dropdown_size
> 0 &&
2753 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2755 evt
.m_y
< cli_rect
.height
)
2761 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2762 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2766 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2768 m_actionPos
= wxPoint(-1,-1);
2769 m_actionItem
= NULL
;
2777 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2779 wxAuiToolBarItem
* hitItem
;
2780 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2782 if (m_actionItem
&& hitItem
== m_actionItem
)
2784 if (hitItem
->m_kind
== wxITEM_NORMAL
)
2786 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_MIDDLE_CLICK
, m_actionItem
->m_toolId
);
2787 e
.SetEventObject(this);
2788 e
.SetToolId(m_actionItem
->m_toolId
);
2789 e
.SetClickPoint(m_actionPos
);
2790 GetEventHandler()->ProcessEvent(e
);
2795 // reset member variables
2796 m_actionPos
= wxPoint(-1,-1);
2797 m_actionItem
= NULL
;
2800 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2802 const bool button_pressed
= HasCapture();
2804 // start a drag event
2805 if (!m_dragging
&& button_pressed
&&
2806 abs(evt
.GetX() - m_actionPos
.x
) + abs(evt
.GetY() - m_actionPos
.y
) > 5)
2808 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2809 // event sent sometime in the future (see OnLeftUp())
2810 wxAuiToolBarEvent
e(wxEVT_AUITOOLBAR_BEGIN_DRAG
, GetId());
2811 e
.SetEventObject(this);
2812 e
.SetToolId(m_actionItem
->m_toolId
);
2813 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2821 wxAuiToolBarItem
* hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2824 // if we have a button pressed we want it to be shown in 'depressed'
2825 // state unless we move the mouse outside the button, then we want it
2826 // to show as just 'highlighted'
2827 if (hitItem
== m_actionItem
)
2828 SetPressedItem(m_actionItem
);
2831 SetPressedItem(NULL
);
2832 SetHoverItem(m_actionItem
);
2837 SetHoverItem(hitItem
);
2839 // tooltips handling
2840 wxAuiToolBarItem
* packingHitItem
;
2841 packingHitItem
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2844 if (packingHitItem
!= m_tipItem
)
2846 m_tipItem
= packingHitItem
;
2848 if ( !packingHitItem
->m_shortHelp
.empty() )
2849 SetToolTip(packingHitItem
->m_shortHelp
);
2860 // figure out the dropdown button state (are we hovering or pressing it?)
2861 RefreshOverflowState();
2865 void wxAuiToolBar::DoResetMouseState()
2867 RefreshOverflowState();
2869 SetPressedItem(NULL
);
2873 // we have to reset those here, because the mouse-up handlers which do
2874 // it usually won't be called if we let go of a mouse button while we
2875 // are outside of the window
2876 m_actionPos
= wxPoint(-1,-1);
2877 m_actionItem
= NULL
;
2880 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2888 DoResetMouseState();
2891 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2895 DoResetMouseState();
2898 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2900 wxCursor cursor
= wxNullCursor
;
2902 if (m_gripperSizerItem
)
2904 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2905 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2907 cursor
= wxCursor(wxCURSOR_SIZING
);
2911 evt
.SetCursor(cursor
);