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_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
48 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
49 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
50 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
51 wxDEFINE_EVENT( wxEVT_COMMAND_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 wxBitmap
MakeDisabledBitmap(wxBitmap
& bmp
)
74 wxImage image
= bmp
.ConvertToImage();
77 mr
= image
.GetMaskRed();
78 mg
= image
.GetMaskGreen();
79 mb
= image
.GetMaskBlue();
81 unsigned char* data
= image
.GetData();
82 int width
= image
.GetWidth();
83 int height
= image
.GetHeight();
84 bool has_mask
= image
.HasMask();
86 for (int y
= height
-1; y
>= 0; --y
)
88 for (int x
= width
-1; x
>= 0; --x
)
90 data
= image
.GetData() + (y
*(width
*3))+(x
*3);
91 unsigned char* r
= data
;
92 unsigned char* g
= data
+1;
93 unsigned char* b
= data
+2;
95 if (has_mask
&& *r
== mr
&& *g
== mg
&& *b
== mb
)
98 *r
= wxColour::AlphaBlend(*r
, 255, 0.4);
99 *g
= wxColour::AlphaBlend(*g
, 255, 0.4);
100 *b
= wxColour::AlphaBlend(*b
, 255, 0.4);
104 return wxBitmap(image
);
107 static wxColor
GetBaseColor()
110 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
111 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
113 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
116 // the base_colour is too pale to use as our base colour,
117 // so darken it a bit --
118 if ((255-base_colour
.Red()) +
119 (255-base_colour
.Green()) +
120 (255-base_colour
.Blue()) < 60)
122 base_colour
= base_colour
.ChangeLightness(92);
130 class ToolbarCommandCapture
: public wxEvtHandler
134 ToolbarCommandCapture() { m_last_id
= 0; }
135 int GetCommandId() const { return m_last_id
; }
137 bool ProcessEvent(wxEvent
& evt
)
139 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
141 m_last_id
= evt
.GetId();
145 if (GetNextHandler())
146 return GetNextHandler()->ProcessEvent(evt
);
157 static const unsigned char
158 DISABLED_TEXT_GREY_HUE
= wxColour::AlphaBlend(0, 255, 0.4);
159 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
160 DISABLED_TEXT_GREY_HUE
,
161 DISABLED_TEXT_GREY_HUE
);
163 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
165 m_base_colour
= GetBaseColor();
168 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
169 m_highlight_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
171 m_separator_size
= 7;
173 m_overflow_size
= 16;
175 wxColor darker1_colour
= m_base_colour
.ChangeLightness(85);
176 wxColor darker2_colour
= m_base_colour
.ChangeLightness(75);
177 wxColor darker3_colour
= m_base_colour
.ChangeLightness(60);
178 wxColor darker4_colour
= m_base_colour
.ChangeLightness(50);
179 wxColor darker5_colour
= m_base_colour
.ChangeLightness(40);
181 m_gripper_pen1
= wxPen(darker5_colour
);
182 m_gripper_pen2
= wxPen(darker3_colour
);
183 m_gripper_pen3
= *wxWHITE_PEN
;
185 static const unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
186 static const unsigned char overflow_bits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
188 m_button_dropdown_bmp
= wxAuiBitmapFromBits(button_dropdown_bits
, 5, 3,
190 m_disabled_button_dropdown_bmp
= wxAuiBitmapFromBits(
191 button_dropdown_bits
, 5, 3,
192 wxColor(128,128,128));
193 m_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, *wxBLACK
);
194 m_disabled_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, wxColor(128,128,128));
196 m_font
= *wxNORMAL_FONT
;
199 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
201 m_font
= *wxNORMAL_FONT
;
205 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
207 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
210 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
215 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
220 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
222 m_text_orientation
= orientation
;
225 unsigned int wxAuiDefaultToolBarArt::GetFlags()
230 wxFont
wxAuiDefaultToolBarArt::GetFont()
235 int wxAuiDefaultToolBarArt::GetTextOrientation()
237 return m_text_orientation
;
240 void wxAuiDefaultToolBarArt::DrawBackground(
242 wxWindow
* WXUNUSED(wnd
),
247 wxColour start_colour
= m_base_colour
.ChangeLightness(150);
248 wxColour end_colour
= m_base_colour
.ChangeLightness(90);
249 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
252 void wxAuiDefaultToolBarArt::DrawLabel(
254 wxWindow
* WXUNUSED(wnd
),
255 const wxAuiToolBarItem
& item
,
259 dc
.SetTextForeground(*wxBLACK
);
261 // we only care about the text height here since the text
262 // will get cropped based on the width of the item
263 int text_width
= 0, text_height
= 0;
264 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
266 // set the clipping region
267 wxRect clip_rect
= rect
;
268 clip_rect
.width
-= 1;
269 dc
.SetClippingRegion(clip_rect
);
273 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
274 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
275 dc
.DestroyClippingRegion();
279 void wxAuiDefaultToolBarArt::DrawButton(
281 wxWindow
* WXUNUSED(wnd
),
282 const wxAuiToolBarItem
& item
,
285 int text_width
= 0, text_height
= 0;
287 if (m_flags
& wxAUI_TB_TEXT
)
293 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
295 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
298 int bmp_x
= 0, bmp_y
= 0;
299 int text_x
= 0, text_y
= 0;
301 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
305 (item
.GetBitmap().GetWidth()/2);
308 ((rect
.height
-text_height
)/2) -
309 (item
.GetBitmap().GetHeight()/2);
311 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
312 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
314 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
320 (item
.GetBitmap().GetHeight()/2);
322 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
329 if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
))
331 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
333 dc
.SetPen(wxPen(m_highlight_colour
));
334 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(150)));
335 dc
.DrawRectangle(rect
);
337 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
339 dc
.SetPen(wxPen(m_highlight_colour
));
340 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
342 // draw an even lighter background for checked item hovers (since
343 // the hover background is the same color as the check background)
344 if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
345 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(180)));
347 dc
.DrawRectangle(rect
);
349 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
351 // it's important to put this code in an else statment after the
352 // hover, otherwise hovers won't draw properly for checked items
353 dc
.SetPen(wxPen(m_highlight_colour
));
354 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
355 dc
.DrawRectangle(rect
);
360 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
361 bmp
= item
.GetDisabledBitmap();
363 bmp
= item
.GetBitmap();
366 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
368 // set the item's text color based on if it is disabled
369 dc
.SetTextForeground(*wxBLACK
);
370 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
371 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
373 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
375 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
380 void wxAuiDefaultToolBarArt::DrawDropDownButton(
382 wxWindow
* WXUNUSED(wnd
),
383 const wxAuiToolBarItem
& item
,
386 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
387 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
389 wxRect button_rect
= wxRect(rect
.x
,
391 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
393 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
395 BUTTON_DROPDOWN_WIDTH
+1,
398 if (m_flags
& wxAUI_TB_TEXT
)
403 if (m_flags
& wxAUI_TB_TEXT
)
405 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
409 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
414 dropbmp_x
= dropdown_rect
.x
+
415 (dropdown_rect
.width
/2) -
416 (m_button_dropdown_bmp
.GetWidth()/2);
417 dropbmp_y
= dropdown_rect
.y
+
418 (dropdown_rect
.height
/2) -
419 (m_button_dropdown_bmp
.GetHeight()/2);
422 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
424 bmp_x
= button_rect
.x
+
425 (button_rect
.width
/2) -
426 (item
.GetBitmap().GetWidth()/2);
427 bmp_y
= button_rect
.y
+
428 ((button_rect
.height
-text_height
)/2) -
429 (item
.GetBitmap().GetHeight()/2);
431 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
432 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
434 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
440 (item
.GetBitmap().GetHeight()/2);
442 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
449 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
451 dc
.SetPen(wxPen(m_highlight_colour
));
452 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(140)));
453 dc
.DrawRectangle(button_rect
);
455 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
456 dc
.DrawRectangle(dropdown_rect
);
458 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
461 dc
.SetPen(wxPen(m_highlight_colour
));
462 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
463 dc
.DrawRectangle(button_rect
);
464 dc
.DrawRectangle(dropdown_rect
);
469 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
471 bmp
= item
.GetDisabledBitmap();
472 dropbmp
= m_disabled_button_dropdown_bmp
;
476 bmp
= item
.GetBitmap();
477 dropbmp
= m_button_dropdown_bmp
;
483 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
484 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
486 // set the item's text color based on if it is disabled
487 dc
.SetTextForeground(*wxBLACK
);
488 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
489 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
491 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
493 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
497 void wxAuiDefaultToolBarArt::DrawControlLabel(
499 wxWindow
* WXUNUSED(wnd
),
500 const wxAuiToolBarItem
& item
,
503 if (!(m_flags
& wxAUI_TB_TEXT
))
506 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
509 int text_x
= 0, text_y
= 0;
510 int text_width
= 0, text_height
= 0;
515 if (m_flags
& wxAUI_TB_TEXT
)
517 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
521 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
523 // don't draw the label if it is wider than the item width
524 if (text_width
> rect
.width
)
527 // set the label's text color
528 dc
.SetTextForeground(*wxBLACK
);
530 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
531 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
533 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
535 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
539 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
541 wxWindow
* WXUNUSED(wnd
),
542 const wxAuiToolBarItem
& item
)
546 // get label's height
547 int width
= 0, height
= 0;
548 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
551 width
= item
.GetMinSize().GetWidth();
555 // no width specified, measure the text ourselves
556 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
559 return wxSize(width
, height
);
562 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
564 wxWindow
* WXUNUSED(wnd
),
565 const wxAuiToolBarItem
& item
)
567 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
568 return wxSize(16,16);
570 int width
= item
.GetBitmap().GetWidth();
571 int height
= item
.GetBitmap().GetHeight();
573 if (m_flags
& wxAUI_TB_TEXT
)
578 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
580 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
583 if ( !item
.GetLabel().empty() )
585 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
586 width
= wxMax(width
, tx
+6);
589 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
590 !item
.GetLabel().empty() )
592 width
+= 3; // space between left border and bitmap
593 width
+= 3; // space between bitmap and text
595 if ( !item
.GetLabel().empty() )
597 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
599 height
= wxMax(height
, ty
);
604 // if the tool has a dropdown button, add it to the width
605 if (item
.HasDropDown())
606 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
608 return wxSize(width
, height
);
611 void wxAuiDefaultToolBarArt::DrawSeparator(
613 wxWindow
* WXUNUSED(wnd
),
616 bool horizontal
= true;
617 if (m_flags
& wxAUI_TB_VERTICAL
)
624 rect
.x
+= (rect
.width
/2);
626 int new_height
= (rect
.height
*3)/4;
627 rect
.y
+= (rect
.height
/2) - (new_height
/2);
628 rect
.height
= new_height
;
632 rect
.y
+= (rect
.height
/2);
634 int new_width
= (rect
.width
*3)/4;
635 rect
.x
+= (rect
.width
/2) - (new_width
/2);
636 rect
.width
= new_width
;
639 wxColour start_colour
= m_base_colour
.ChangeLightness(80);
640 wxColour end_colour
= m_base_colour
.ChangeLightness(80);
641 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
644 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
645 wxWindow
* WXUNUSED(wnd
),
653 if (m_flags
& wxAUI_TB_VERTICAL
)
655 x
= rect
.x
+ (i
*4) + 5;
657 if (x
> rect
.GetWidth()-5)
663 y
= rect
.y
+ (i
*4) + 5;
664 if (y
> rect
.GetHeight()-5)
668 dc
.SetPen(m_gripper_pen1
);
670 dc
.SetPen(m_gripper_pen2
);
671 dc
.DrawPoint(x
, y
+1);
672 dc
.DrawPoint(x
+1, y
);
673 dc
.SetPen(m_gripper_pen3
);
674 dc
.DrawPoint(x
+2, y
+1);
675 dc
.DrawPoint(x
+2, y
+2);
676 dc
.DrawPoint(x
+1, y
+2);
683 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
688 if (state
& wxAUI_BUTTON_STATE_HOVER
||
689 state
& wxAUI_BUTTON_STATE_PRESSED
)
691 wxRect cli_rect
= wnd
->GetClientRect();
692 wxColor light_gray_bg
= m_highlight_colour
.ChangeLightness(170);
694 if (m_flags
& wxAUI_TB_VERTICAL
)
696 dc
.SetPen(wxPen(m_highlight_colour
));
697 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
698 dc
.SetPen(wxPen(light_gray_bg
));
699 dc
.SetBrush(wxBrush(light_gray_bg
));
700 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
704 dc
.SetPen(wxPen(m_highlight_colour
));
705 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
706 dc
.SetPen(wxPen(light_gray_bg
));
707 dc
.SetBrush(wxBrush(light_gray_bg
));
708 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
712 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
713 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
714 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
717 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
721 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
722 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
723 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
728 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
732 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
; break;
733 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
; break;
734 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
; break;
738 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
739 const wxAuiToolBarItemArray
& items
)
743 size_t items_added
= 0;
745 size_t i
, count
= items
.GetCount();
746 for (i
= 0; i
< count
; ++i
)
748 wxAuiToolBarItem
& item
= items
.Item(i
);
750 if (item
.GetKind() == wxITEM_NORMAL
)
752 wxString text
= item
.GetShortHelp();
754 text
= item
.GetLabel();
759 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
761 m
->SetBitmap(item
.GetBitmap());
765 else if (item
.GetKind() == wxITEM_SEPARATOR
)
768 menuPopup
.AppendSeparator();
772 // find out where to put the popup menu of window items
773 wxPoint pt
= ::wxGetMousePosition();
774 pt
= wnd
->ScreenToClient(pt
);
776 // find out the screen coordinate at the bottom of the tab ctrl
777 wxRect cli_rect
= wnd
->GetClientRect();
778 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
780 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
781 wnd
->PushEventHandler(cc
);
782 wnd
->PopupMenu(&menuPopup
, pt
);
783 int command
= cc
->GetCommandId();
784 wnd
->PopEventHandler(true);
792 static wxOrientation
GetOrientation(long& style
)
794 switch (style
& wxAUI_ORIENTATION_MASK
)
796 case wxAUI_TB_HORIZONTAL
:
798 case wxAUI_TB_VERTICAL
:
801 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
808 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
809 EVT_SIZE(wxAuiToolBar::OnSize
)
810 EVT_IDLE(wxAuiToolBar::OnIdle
)
811 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
812 EVT_PAINT(wxAuiToolBar::OnPaint
)
813 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
814 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
815 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
816 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
817 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
818 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
819 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
820 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
821 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
822 EVT_MOTION(wxAuiToolBar::OnMotion
)
823 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
824 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
825 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
829 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
831 const wxPoint
& position
,
838 style
| wxBORDER_NONE
)
840 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
842 m_button_height
= -1;
843 m_sizer_element_count
= 0;
844 m_action_pos
= wxPoint(-1,-1);
845 m_action_item
= NULL
;
847 m_art
= new wxAuiDefaultToolBarArt
;
849 m_tool_border_padding
= 3;
850 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
851 m_gripper_sizer_item
= NULL
;
852 m_overflow_sizer_item
= NULL
;
854 m_orientation
= GetOrientation(style
);
855 if (m_orientation
== wxBOTH
)
857 m_orientation
= wxHORIZONTAL
;
859 m_style
= style
| wxBORDER_NONE
;
860 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
861 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
862 m_overflow_state
= 0;
863 SetMargins(5, 5, 2, 2);
864 SetFont(*wxNORMAL_FONT
);
866 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
867 if (style
& wxAUI_TB_HORZ_LAYOUT
)
868 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
869 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
873 wxAuiToolBar::~wxAuiToolBar()
879 void wxAuiToolBar::SetWindowStyleFlag(long style
)
881 GetOrientation(style
); // assert if style is invalid
882 wxCHECK_RET(IsPaneValid(style
),
883 "window settings and pane settings are incompatible");
885 wxControl::SetWindowStyleFlag(style
);
894 if (m_style
& wxAUI_TB_GRIPPER
)
895 m_gripper_visible
= true;
897 m_gripper_visible
= false;
900 if (m_style
& wxAUI_TB_OVERFLOW
)
901 m_overflow_visible
= true;
903 m_overflow_visible
= false;
905 if (style
& wxAUI_TB_HORZ_LAYOUT
)
906 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
908 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
911 long wxAuiToolBar::GetWindowStyleFlag() const
916 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
925 m_art
->SetTextOrientation(m_tool_text_orientation
);
929 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
937 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
938 const wxString
& label
,
939 const wxBitmap
& bitmap
,
940 const wxString
& short_help_string
,
943 return AddTool(tool_id
,
954 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
955 const wxString
& label
,
956 const wxBitmap
& bitmap
,
957 const wxBitmap
& disabled_bitmap
,
959 const wxString
& short_help_string
,
960 const wxString
& long_help_string
,
961 wxObject
* WXUNUSED(client_data
))
963 wxAuiToolBarItem item
;
966 item
.bitmap
= bitmap
;
967 item
.disabled_bitmap
= disabled_bitmap
;
968 item
.short_help
= short_help_string
;
969 item
.long_help
= long_help_string
;
971 item
.dropdown
= false;
972 item
.spacer_pixels
= 0;
973 item
.toolid
= tool_id
;
977 item
.sizer_item
= NULL
;
978 item
.min_size
= wxDefaultSize
;
982 if (item
.toolid
== wxID_ANY
)
983 item
.toolid
= wxNewId();
985 if (!item
.disabled_bitmap
.IsOk())
987 // no disabled bitmap specified, we need to make one
988 if (item
.bitmap
.IsOk())
990 //wxImage img = item.bitmap.ConvertToImage();
991 //wxImage grey_version = img.ConvertToGreyscale();
992 //item.disabled_bitmap = wxBitmap(grey_version);
993 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
997 return &m_items
.Last();
1000 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
1001 const wxString
& label
)
1003 wxAuiToolBarItem item
;
1004 item
.window
= (wxWindow
*)control
;
1006 item
.bitmap
= wxNullBitmap
;
1007 item
.disabled_bitmap
= wxNullBitmap
;
1009 item
.dropdown
= false;
1010 item
.spacer_pixels
= 0;
1011 item
.toolid
= control
->GetId();
1013 item
.proportion
= 0;
1014 item
.kind
= wxITEM_CONTROL
;
1015 item
.sizer_item
= NULL
;
1016 item
.min_size
= control
->GetEffectiveMinSize();
1018 item
.sticky
= false;
1021 return &m_items
.Last();
1024 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1025 const wxString
& label
,
1028 wxSize min_size
= wxDefaultSize
;
1032 wxAuiToolBarItem item
;
1035 item
.bitmap
= wxNullBitmap
;
1036 item
.disabled_bitmap
= wxNullBitmap
;
1038 item
.dropdown
= false;
1039 item
.spacer_pixels
= 0;
1040 item
.toolid
= tool_id
;
1042 item
.proportion
= 0;
1043 item
.kind
= wxITEM_LABEL
;
1044 item
.sizer_item
= NULL
;
1045 item
.min_size
= min_size
;
1047 item
.sticky
= false;
1049 if (item
.toolid
== wxID_ANY
)
1050 item
.toolid
= wxNewId();
1053 return &m_items
.Last();
1056 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1058 wxAuiToolBarItem item
;
1060 item
.label
= wxEmptyString
;
1061 item
.bitmap
= wxNullBitmap
;
1062 item
.disabled_bitmap
= wxNullBitmap
;
1064 item
.dropdown
= false;
1067 item
.proportion
= 0;
1068 item
.kind
= wxITEM_SEPARATOR
;
1069 item
.sizer_item
= NULL
;
1070 item
.min_size
= wxDefaultSize
;
1072 item
.sticky
= false;
1075 return &m_items
.Last();
1078 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1080 wxAuiToolBarItem item
;
1082 item
.label
= wxEmptyString
;
1083 item
.bitmap
= wxNullBitmap
;
1084 item
.disabled_bitmap
= wxNullBitmap
;
1086 item
.dropdown
= false;
1087 item
.spacer_pixels
= pixels
;
1090 item
.proportion
= 0;
1091 item
.kind
= wxITEM_SPACER
;
1092 item
.sizer_item
= NULL
;
1093 item
.min_size
= wxDefaultSize
;
1095 item
.sticky
= false;
1098 return &m_items
.Last();
1101 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1103 wxAuiToolBarItem item
;
1105 item
.label
= wxEmptyString
;
1106 item
.bitmap
= wxNullBitmap
;
1107 item
.disabled_bitmap
= wxNullBitmap
;
1109 item
.dropdown
= false;
1110 item
.spacer_pixels
= 0;
1113 item
.proportion
= proportion
;
1114 item
.kind
= wxITEM_SPACER
;
1115 item
.sizer_item
= NULL
;
1116 item
.min_size
= wxDefaultSize
;
1118 item
.sticky
= false;
1121 return &m_items
.Last();
1124 void wxAuiToolBar::Clear()
1127 m_sizer_element_count
= 0;
1130 bool wxAuiToolBar::DeleteTool(int tool_id
)
1132 int idx
= GetToolIndex(tool_id
);
1133 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1135 m_items
.RemoveAt(idx
);
1143 bool wxAuiToolBar::DeleteByIndex(int idx
)
1145 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1147 m_items
.RemoveAt(idx
);
1156 wxControl
* wxAuiToolBar::FindControl(int id
)
1158 wxWindow
* wnd
= FindWindow(id
);
1159 return (wxControl
*)wnd
;
1162 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1165 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1167 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1168 if (item
.toolid
== tool_id
)
1175 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1178 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1180 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1182 if (!item
.sizer_item
)
1185 wxRect rect
= item
.sizer_item
->GetRect();
1186 if (rect
.Contains(x
,y
))
1188 // if the item doesn't fit on the toolbar, return NULL
1189 if (!GetToolFitsByIndex(i
))
1199 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1202 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1204 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1206 if (!item
.sizer_item
)
1209 wxRect rect
= item
.sizer_item
->GetRect();
1211 // apply tool packing
1213 rect
.width
+= m_tool_packing
;
1215 if (rect
.Contains(x
,y
))
1217 // if the item doesn't fit on the toolbar, return NULL
1218 if (!GetToolFitsByIndex(i
))
1228 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1233 if (idx
>= (int)m_items
.size())
1236 return &(m_items
[idx
]);
1239 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1241 // TODO: wxToolBar compatibility
1244 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1246 // TODO: wxToolBar compatibility
1247 return wxSize(16,15);
1250 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1252 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1256 item
->proportion
= proportion
;
1259 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1261 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1265 return item
->proportion
;
1268 void wxAuiToolBar::SetToolSeparation(int separation
)
1271 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1274 int wxAuiToolBar::GetToolSeparation() const
1277 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1283 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1285 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1289 item
->dropdown
= dropdown
;
1292 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1294 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1298 return item
->dropdown
;
1301 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1303 // ignore separators
1307 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1311 if (item
->sticky
== sticky
)
1314 item
->sticky
= sticky
;
1320 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1322 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1326 return item
->sticky
;
1332 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1334 m_tool_border_padding
= padding
;
1337 int wxAuiToolBar::GetToolBorderPadding() const
1339 return m_tool_border_padding
;
1342 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1344 m_tool_text_orientation
= orientation
;
1348 m_art
->SetTextOrientation(orientation
);
1352 int wxAuiToolBar::GetToolTextOrientation() const
1354 return m_tool_text_orientation
;
1357 void wxAuiToolBar::SetToolPacking(int packing
)
1359 m_tool_packing
= packing
;
1362 int wxAuiToolBar::GetToolPacking() const
1364 return m_tool_packing
;
1368 void wxAuiToolBar::SetOrientation(int orientation
)
1370 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1371 orientation
== wxVERTICAL
,
1372 "invalid orientation value");
1373 if (orientation
!= m_orientation
)
1375 m_orientation
= wxOrientation(orientation
);
1380 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1383 m_left_padding
= left
;
1385 m_right_padding
= right
;
1387 m_top_padding
= top
;
1389 m_bottom_padding
= bottom
;
1392 bool wxAuiToolBar::GetGripperVisible() const
1394 return m_gripper_visible
;
1397 void wxAuiToolBar::SetGripperVisible(bool visible
)
1399 m_gripper_visible
= visible
;
1401 m_style
|= wxAUI_TB_GRIPPER
;
1403 m_style
&= ~wxAUI_TB_GRIPPER
;
1409 bool wxAuiToolBar::GetOverflowVisible() const
1411 return m_overflow_visible
;
1414 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1416 m_overflow_visible
= visible
;
1418 m_style
|= wxAUI_TB_OVERFLOW
;
1420 m_style
&= ~wxAUI_TB_OVERFLOW
;
1424 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1426 bool res
= wxWindow::SetFont(font
);
1430 m_art
->SetFont(font
);
1437 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1439 wxAuiToolBarItem
* former_hover
= NULL
;
1442 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1444 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1445 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1446 former_hover
= &item
;
1447 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1452 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1455 if (former_hover
!= pitem
)
1462 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1464 wxAuiToolBarItem
* former_item
= NULL
;
1467 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1469 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1470 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1471 former_item
= &item
;
1472 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1477 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1478 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1481 if (former_item
!= pitem
)
1488 void wxAuiToolBar::RefreshOverflowState()
1490 if (!m_overflow_sizer_item
)
1492 m_overflow_state
= 0;
1496 int overflow_state
= 0;
1498 wxRect overflow_rect
= GetOverflowRect();
1501 // find out the mouse's current position
1502 wxPoint pt
= ::wxGetMousePosition();
1503 pt
= this->ScreenToClient(pt
);
1505 // find out if the mouse cursor is inside the dropdown rectangle
1506 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1508 if (::wxGetMouseState().LeftIsDown())
1509 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1511 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1514 if (overflow_state
!= m_overflow_state
)
1516 m_overflow_state
= overflow_state
;
1521 m_overflow_state
= overflow_state
;
1524 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1526 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1528 if (tool
&& (tool
->kind
== wxITEM_CHECK
|| tool
->kind
== wxITEM_RADIO
))
1530 if (tool
->kind
== wxITEM_RADIO
)
1533 idx
= GetToolIndex(tool_id
);
1534 count
= (int)m_items
.GetCount();
1536 if (idx
>= 0 && idx
< count
)
1538 for (i
= idx
; i
< count
; ++i
)
1540 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1542 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1544 for (i
= idx
; i
> 0; i
--)
1546 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1548 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1552 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1554 else if (tool
->kind
== wxITEM_CHECK
)
1557 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1559 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1564 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1566 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1570 if ( (tool
->kind
!= wxITEM_CHECK
) && (tool
->kind
!= wxITEM_RADIO
) )
1573 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1579 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1581 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1586 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1588 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1592 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1594 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1597 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1602 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1604 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1605 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1607 return wxEmptyString
;
1612 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1614 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1617 tool
->label
= label
;
1621 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1623 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1624 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1626 return wxNullBitmap
;
1628 return tool
->bitmap
;
1631 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1633 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1636 tool
->bitmap
= bitmap
;
1640 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1642 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1643 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1645 return wxEmptyString
;
1647 return tool
->short_help
;
1650 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1652 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1655 tool
->short_help
= help_string
;
1659 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1661 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1662 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1664 return wxEmptyString
;
1666 return tool
->long_help
;
1669 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1671 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1674 tool
->long_help
= help_string
;
1678 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1679 const wxAuiToolBarItemArray
& append
)
1681 m_custom_overflow_prepend
= prepend
;
1682 m_custom_overflow_append
= append
;
1685 // get size of hint rectangle for a particular dock location
1686 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1688 switch (dock_direction
)
1690 case wxAUI_DOCK_TOP
:
1691 case wxAUI_DOCK_BOTTOM
:
1692 return m_horzHintSize
;
1693 case wxAUI_DOCK_RIGHT
:
1694 case wxAUI_DOCK_LEFT
:
1695 return m_vertHintSize
;
1697 wxCHECK_MSG(false, wxDefaultSize
, "invalid dock location value");
1701 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1703 return IsPaneValid(m_style
, pane
);
1706 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1708 if (style
& wxAUI_TB_HORIZONTAL
)
1710 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1715 else if (style
& wxAUI_TB_VERTICAL
)
1717 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1725 bool wxAuiToolBar::IsPaneValid(long style
) const
1727 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1730 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1735 void wxAuiToolBar::SetArtFlags() const
1737 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1738 if (m_orientation
== wxVERTICAL
)
1740 artflags
|= wxAUI_TB_VERTICAL
;
1742 m_art
->SetFlags(artflags
);
1745 size_t wxAuiToolBar::GetToolCount() const
1747 return m_items
.size();
1750 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1752 // this will prevent us from returning the index of the
1753 // first separator in the toolbar since its id is equal to -1
1757 size_t i
, count
= m_items
.GetCount();
1758 for (i
= 0; i
< count
; ++i
)
1760 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1761 if (item
.toolid
== tool_id
)
1768 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1770 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1773 if (!m_items
[tool_idx
].sizer_item
)
1777 GetClientSize(&cli_w
, &cli_h
);
1779 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1781 if (m_orientation
== wxVERTICAL
)
1783 // take the dropdown size into account
1784 if (m_overflow_visible
)
1785 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1787 if (rect
.y
+rect
.height
< cli_h
)
1792 // take the dropdown size into account
1793 if (m_overflow_visible
)
1794 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1796 if (rect
.x
+rect
.width
< cli_w
)
1804 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1806 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1809 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1811 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1812 if (tool
&& tool
->sizer_item
)
1814 return tool
->sizer_item
->GetRect();
1820 bool wxAuiToolBar::GetToolBarFits() const
1822 if (m_items
.GetCount() == 0)
1824 // empty toolbar always 'fits'
1828 // entire toolbar content fits if the last tool fits
1829 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1832 bool wxAuiToolBar::Realize()
1834 wxClientDC
dc(this);
1838 // calculate hint sizes for both horizontal and vertical
1839 // in the order that leaves toolbar in correct final state
1840 bool retval
= false;
1841 if (m_orientation
== wxHORIZONTAL
)
1843 if (RealizeHelper(dc
, false))
1845 m_vertHintSize
= GetSize();
1846 if (RealizeHelper(dc
, true))
1848 m_horzHintSize
= GetSize();
1855 if (RealizeHelper(dc
, true))
1857 m_horzHintSize
= GetSize();
1858 if (RealizeHelper(dc
, false))
1860 m_vertHintSize
= GetSize();
1870 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1872 // create the new sizer to add toolbar elements to
1873 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1876 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1877 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1878 if (gripper_size
> 0 && m_gripper_visible
)
1881 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1883 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1887 m_gripper_sizer_item
= NULL
;
1890 // add "left" padding
1891 if (m_left_padding
> 0)
1894 sizer
->Add(m_left_padding
, 1);
1896 sizer
->Add(1, m_left_padding
);
1900 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1902 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1903 wxSizerItem
* sizer_item
= NULL
;
1909 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1910 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1911 size
.y
+ (m_tool_border_padding
*2),
1916 sizer
->AddSpacer(m_tool_packing
);
1926 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1927 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1928 size
.y
+ (m_tool_border_padding
*2),
1934 sizer
->AddSpacer(m_tool_packing
);
1940 case wxITEM_SEPARATOR
:
1943 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1945 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1950 sizer
->AddSpacer(m_tool_packing
);
1957 if (item
.proportion
> 0)
1958 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1960 sizer_item
= sizer
->Add(item
.spacer_pixels
, 1);
1963 case wxITEM_CONTROL
:
1965 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1966 wxSizerItem
* ctrl_sizer_item
;
1968 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1969 vert_sizer
->AddStretchSpacer(1);
1970 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1971 vert_sizer
->AddStretchSpacer(1);
1972 if ( (m_style
& wxAUI_TB_TEXT
) &&
1973 m_tool_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1974 !item
.GetLabel().empty() )
1976 wxSize s
= GetLabelSize(item
.GetLabel());
1977 vert_sizer
->Add(1, s
.y
);
1981 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1983 wxSize min_size
= item
.min_size
;
1986 // proportional items will disappear from the toolbar if
1987 // their min width is not set to something really small
1988 if (item
.proportion
!= 0)
1993 if (min_size
.IsFullySpecified())
1995 sizer_item
->SetMinSize(min_size
);
1996 ctrl_sizer_item
->SetMinSize(min_size
);
2002 sizer
->AddSpacer(m_tool_packing
);
2007 item
.sizer_item
= sizer_item
;
2010 // add "right" padding
2011 if (m_right_padding
> 0)
2014 sizer
->Add(m_right_padding
, 1);
2016 sizer
->Add(1, m_right_padding
);
2019 // add drop down area
2020 m_overflow_sizer_item
= NULL
;
2022 if (m_style
& wxAUI_TB_OVERFLOW
)
2024 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2025 if (overflow_size
> 0 && m_overflow_visible
)
2028 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2030 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2034 m_overflow_sizer_item
= NULL
;
2039 // the outside sizer helps us apply the "top" and "bottom" padding
2040 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2042 // add "top" padding
2043 if (m_top_padding
> 0)
2046 outside_sizer
->Add(1, m_top_padding
);
2048 outside_sizer
->Add(m_top_padding
, 1);
2051 // add the sizer that contains all of the toolbar elements
2052 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2054 // add "bottom" padding
2055 if (m_bottom_padding
> 0)
2058 outside_sizer
->Add(1, m_bottom_padding
);
2060 outside_sizer
->Add(m_bottom_padding
, 1);
2063 delete m_sizer
; // remove old sizer
2064 m_sizer
= outside_sizer
;
2066 // calculate the rock-bottom minimum size
2067 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2069 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2070 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2071 item
.sizer_item
->SetMinSize(0,0);
2074 m_absolute_min_size
= m_sizer
->GetMinSize();
2076 // reset the min sizes to what they were
2077 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2079 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2080 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2081 item
.sizer_item
->SetMinSize(item
.min_size
);
2085 wxSize size
= m_sizer
->GetMinSize();
2086 m_minWidth
= size
.x
;
2087 m_minHeight
= size
.y
;
2089 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2091 wxSize cur_size
= GetClientSize();
2092 wxSize new_size
= GetMinSize();
2093 if (new_size
!= cur_size
)
2095 SetClientSize(new_size
);
2099 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2104 wxSize cur_size
= GetClientSize();
2105 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2111 int wxAuiToolBar::GetOverflowState() const
2113 return m_overflow_state
;
2116 wxRect
wxAuiToolBar::GetOverflowRect() const
2118 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2119 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
2120 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2122 if (m_orientation
== wxVERTICAL
)
2124 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2125 overflow_rect
.x
= 0;
2126 overflow_rect
.width
= cli_rect
.width
;
2127 overflow_rect
.height
= overflow_size
;
2131 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2132 overflow_rect
.y
= 0;
2133 overflow_rect
.width
= overflow_size
;
2134 overflow_rect
.height
= cli_rect
.height
;
2137 return overflow_rect
;
2140 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2142 wxClientDC
dc(this);
2145 int text_width
= 0, text_height
= 0;
2149 // get the text height
2150 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
2152 // get the text width
2153 dc
.GetTextExtent(label
, &text_width
, &ty
);
2155 return wxSize(text_width
, text_height
);
2159 void wxAuiToolBar::DoIdleUpdate()
2161 wxEvtHandler
* handler
= GetEventHandler();
2163 bool need_refresh
= false;
2166 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2168 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2170 if (item
.toolid
== -1)
2173 wxUpdateUIEvent
evt(item
.toolid
);
2174 evt
.SetEventObject(this);
2176 if (handler
->ProcessEvent(evt
))
2178 if (evt
.GetSetEnabled())
2182 is_enabled
= item
.window
->IsEnabled();
2184 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2186 bool new_enabled
= evt
.GetEnabled();
2187 if (new_enabled
!= is_enabled
)
2191 item
.window
->Enable(new_enabled
);
2196 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2198 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2200 need_refresh
= true;
2204 if (evt
.GetSetChecked())
2206 // make sure we aren't checking an item that can't be
2207 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2210 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2211 bool new_checked
= evt
.GetChecked();
2213 if (new_checked
!= is_checked
)
2216 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2218 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2220 need_refresh
= true;
2235 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2238 GetClientSize(&x
, &y
);
2240 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2241 ((y
> x
) && m_absolute_min_size
.y
> y
))
2243 // hide all flexible items
2245 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2247 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2248 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2250 item
.sizer_item
->Show(false);
2251 item
.sizer_item
->SetProportion(0);
2257 // show all flexible items
2259 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2261 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2262 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2264 item
.sizer_item
->Show(true);
2265 item
.sizer_item
->SetProportion(item
.proportion
);
2270 m_sizer
->SetDimension(0, 0, x
, y
);
2275 // idle events aren't sent while user is resizing frame (why?),
2276 // but resizing toolbar here causes havoc,
2277 // so force idle handler to run after size handling complete
2278 QueueEvent(new wxIdleEvent
);
2283 void wxAuiToolBar::DoSetSize(int x
,
2289 wxSize parent_size
= GetParent()->GetClientSize();
2290 if (x
+ width
> parent_size
.x
)
2291 width
= wxMax(0, parent_size
.x
- x
);
2292 if (y
+ height
> parent_size
.y
)
2293 height
= wxMax(0, parent_size
.y
- y
);
2295 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2299 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2301 // if orientation doesn't match dock, fix it
2302 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2305 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2306 // pane state member is public, so it might have been changed
2307 // without going through wxPaneInfo::SetFlag() check
2308 bool ok
= pane
.IsOk();
2309 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2310 "window settings and pane settings are incompatible");
2313 wxOrientation newOrientation
= m_orientation
;
2314 if (pane
.IsDocked())
2316 switch (pane
.dock_direction
)
2318 case wxAUI_DOCK_TOP
:
2319 case wxAUI_DOCK_BOTTOM
:
2320 newOrientation
= wxHORIZONTAL
;
2322 case wxAUI_DOCK_LEFT
:
2323 case wxAUI_DOCK_RIGHT
:
2324 newOrientation
= wxVERTICAL
;
2327 wxFAIL_MSG("invalid dock location value");
2330 else if (pane
.IsResizable() &&
2331 GetOrientation(m_style
) == wxBOTH
)
2333 // changing orientation in OnSize causes havoc
2335 GetClientSize(&x
, &y
);
2339 newOrientation
= wxHORIZONTAL
;
2343 newOrientation
= wxVERTICAL
;
2346 if (newOrientation
!= m_orientation
)
2348 SetOrientation(newOrientation
);
2350 if (newOrientation
== wxHORIZONTAL
)
2352 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2356 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2358 if (pane
.IsDocked())
2360 pane
.floating_size
= wxDefaultSize
;
2364 SetSize(GetParent()->GetClientSize());
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
;
2384 m_art
->DrawBackground(dc
, this, cli_rect
);
2386 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2387 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2389 // paint the gripper
2390 if (gripper_size
> 0 && m_gripper_sizer_item
)
2392 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2394 gripper_rect
.width
= gripper_size
;
2396 gripper_rect
.height
= gripper_size
;
2397 m_art
->DrawGripper(dc
, this, gripper_rect
);
2400 // calculated how far we can draw items
2403 last_extent
= cli_rect
.width
;
2405 last_extent
= cli_rect
.height
;
2406 if (m_overflow_visible
)
2407 last_extent
-= dropdown_size
;
2409 // paint each individual tool
2410 size_t i
, count
= m_items
.GetCount();
2411 for (i
= 0; i
< count
; ++i
)
2413 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2415 if (!item
.sizer_item
)
2418 wxRect item_rect
= item
.sizer_item
->GetRect();
2421 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2422 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2427 if (item
.kind
== wxITEM_SEPARATOR
)
2430 m_art
->DrawSeparator(dc
, this, item_rect
);
2432 else if (item
.kind
== wxITEM_LABEL
)
2434 // draw a text label only
2435 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2437 else if (item
.kind
== wxITEM_NORMAL
)
2439 // draw a regular button or dropdown button
2441 m_art
->DrawButton(dc
, this, item
, item_rect
);
2443 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2445 else if (item
.kind
== wxITEM_CHECK
)
2447 // draw a toggle button
2448 m_art
->DrawButton(dc
, this, item
, item_rect
);
2450 else if (item
.kind
== wxITEM_RADIO
)
2452 // draw a toggle button
2453 m_art
->DrawButton(dc
, this, item
, item_rect
);
2455 else if (item
.kind
== wxITEM_CONTROL
)
2457 // draw the control's label
2458 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_overflow_sizer_item
)
2468 wxRect dropdown_rect
= GetOverflowRect();
2469 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2473 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2478 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2480 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2482 if (m_gripper_sizer_item
)
2484 wxRect gripper_rect
= m_gripper_sizer_item
->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_overflow_sizer_item
)
2503 wxRect overflow_rect
= GetOverflowRect();
2506 m_overflow_visible
&&
2507 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2509 wxAuiToolBarEvent
e(wxEVT_COMMAND_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_custom_overflow_prepend
.GetCount();
2527 for (i
= 0; i
< count
; ++i
)
2528 overflow_items
.Add(m_custom_overflow_prepend
[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_custom_overflow_append
.GetCount();
2540 for (i
= 0; i
< count
; ++i
)
2541 overflow_items
.Add(m_custom_overflow_append
[i
]);
2543 int res
= m_art
->ShowDropDown(this, overflow_items
);
2544 m_overflow_state
= 0;
2548 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2549 e
.SetEventObject(this);
2550 GetParent()->GetEventHandler()->ProcessEvent(e
);
2559 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2560 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2564 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2566 m_action_pos
= wxPoint(-1,-1);
2567 m_action_item
= NULL
;
2573 // fire the tool dropdown event
2574 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->toolid
);
2575 e
.SetEventObject(this);
2576 e
.SetToolId(m_action_item
->toolid
);
2578 int mouse_x
= evt
.GetX();
2579 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2580 const bool dropDownHit
= m_action_item
->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_action_item
);
2594 m_action_pos
= wxPoint(-1,-1);
2595 m_action_item
= NULL
;
2598 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2605 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2610 SetPressedItem(NULL
);
2612 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2613 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2615 SetHoverItem(hit_item
);
2620 // TODO: it would make sense to send out an 'END_DRAG' event here,
2621 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2624 // OnCaptureLost() will be called now and this will reset all our state
2625 // tracking variables
2630 wxAuiToolBarItem
* hit_item
;
2631 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2633 if (m_action_item
&& hit_item
== m_action_item
)
2637 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->toolid
);
2638 e
.SetEventObject(this);
2640 if (hit_item
->kind
== wxITEM_CHECK
|| hit_item
->kind
== wxITEM_RADIO
)
2642 const bool toggle
= !(m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
);
2644 ToggleTool(m_action_item
->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
);
2667 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2669 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2671 if (m_gripper_sizer_item
)
2673 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2674 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2678 if (m_overflow_sizer_item
)
2680 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2681 if (dropdown_size
> 0 &&
2682 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2684 evt
.m_y
< cli_rect
.height
&&
2691 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2692 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2694 if (m_action_item
&& m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2696 m_action_pos
= wxPoint(-1,-1);
2697 m_action_item
= NULL
;
2704 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2706 wxAuiToolBarItem
* hit_item
;
2707 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2709 if (m_action_item
&& hit_item
== m_action_item
)
2711 if (hit_item
->kind
== wxITEM_NORMAL
)
2713 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->toolid
);
2714 e
.SetEventObject(this);
2715 e
.SetToolId(m_action_item
->toolid
);
2716 e
.SetClickPoint(m_action_pos
);
2717 GetEventHandler()->ProcessEvent(e
);
2723 // right-clicked on the invalid area of the toolbar
2724 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2725 e
.SetEventObject(this);
2727 e
.SetClickPoint(m_action_pos
);
2728 GetEventHandler()->ProcessEvent(e
);
2732 // reset member variables
2733 m_action_pos
= wxPoint(-1,-1);
2734 m_action_item
= NULL
;
2737 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2739 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2741 if (m_gripper_sizer_item
)
2743 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2744 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2748 if (m_overflow_sizer_item
)
2750 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2751 if (dropdown_size
> 0 &&
2752 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2754 evt
.m_y
< cli_rect
.height
&&
2761 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2762 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2766 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2768 m_action_pos
= wxPoint(-1,-1);
2769 m_action_item
= NULL
;
2777 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2779 wxAuiToolBarItem
* hit_item
;
2780 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2782 if (m_action_item
&& hit_item
== m_action_item
)
2784 if (hit_item
->kind
== wxITEM_NORMAL
)
2786 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->toolid
);
2787 e
.SetEventObject(this);
2788 e
.SetToolId(m_action_item
->toolid
);
2789 e
.SetClickPoint(m_action_pos
);
2790 GetEventHandler()->ProcessEvent(e
);
2795 // reset member variables
2796 m_action_pos
= wxPoint(-1,-1);
2797 m_action_item
= 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_action_pos
.x
) + abs(evt
.GetY() - m_action_pos
.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_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2811 e
.SetEventObject(this);
2812 e
.SetToolId(m_action_item
->toolid
);
2813 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2821 wxAuiToolBarItem
* hit_item
= 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 (hit_item
== m_action_item
)
2828 SetPressedItem(m_action_item
);
2831 SetPressedItem(NULL
);
2832 SetHoverItem(m_action_item
);
2837 if (hit_item
&& (hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2840 SetHoverItem(hit_item
);
2842 // tooltips handling
2843 wxAuiToolBarItem
* packing_hit_item
;
2844 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2845 if (packing_hit_item
)
2847 if (packing_hit_item
!= m_tip_item
)
2849 m_tip_item
= packing_hit_item
;
2851 if ( !packing_hit_item
->short_help
.empty() )
2852 SetToolTip(packing_hit_item
->short_help
);
2863 // figure out the dropdown button state (are we hovering or pressing it?)
2864 RefreshOverflowState();
2868 void wxAuiToolBar::DoResetMouseState()
2870 RefreshOverflowState();
2872 SetPressedItem(NULL
);
2876 // we have to reset those here, because the mouse-up handlers which do
2877 // it usually won't be called if we let go of a mouse button while we
2878 // are outside of the window
2879 m_action_pos
= wxPoint(-1,-1);
2880 m_action_item
= NULL
;
2883 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2891 DoResetMouseState();
2894 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2898 DoResetMouseState();
2901 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2903 wxCursor cursor
= wxNullCursor
;
2905 if (m_gripper_sizer_item
)
2907 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2908 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2910 cursor
= wxCursor(wxCURSOR_SIZING
);
2914 evt
.SetCursor(cursor
);