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 wxColor
GetBaseColor()
75 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
76 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
78 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
81 // the base_colour is too pale to use as our base colour,
82 // so darken it a bit --
83 if ((255-base_colour
.Red()) +
84 (255-base_colour
.Green()) +
85 (255-base_colour
.Blue()) < 60)
87 base_colour
= base_colour
.ChangeLightness(92);
95 class ToolbarCommandCapture
: public wxEvtHandler
99 ToolbarCommandCapture() { m_last_id
= 0; }
100 int GetCommandId() const { return m_last_id
; }
102 bool ProcessEvent(wxEvent
& evt
)
104 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
106 m_last_id
= evt
.GetId();
110 if (GetNextHandler())
111 return GetNextHandler()->ProcessEvent(evt
);
122 static const unsigned char
123 DISABLED_TEXT_GREY_HUE
= wxColour::AlphaBlend(0, 255, 0.4);
124 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
125 DISABLED_TEXT_GREY_HUE
,
126 DISABLED_TEXT_GREY_HUE
);
128 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
130 m_base_colour
= GetBaseColor();
133 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
134 m_highlight_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
136 m_separator_size
= 7;
138 m_overflow_size
= 16;
140 wxColor darker1_colour
= m_base_colour
.ChangeLightness(85);
141 wxColor darker2_colour
= m_base_colour
.ChangeLightness(75);
142 wxColor darker3_colour
= m_base_colour
.ChangeLightness(60);
143 wxColor darker4_colour
= m_base_colour
.ChangeLightness(50);
144 wxColor darker5_colour
= m_base_colour
.ChangeLightness(40);
146 m_gripper_pen1
= wxPen(darker5_colour
);
147 m_gripper_pen2
= wxPen(darker3_colour
);
148 m_gripper_pen3
= *wxWHITE_PEN
;
150 static const unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
151 static const unsigned char overflow_bits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
153 m_button_dropdown_bmp
= wxAuiBitmapFromBits(button_dropdown_bits
, 5, 3,
155 m_disabled_button_dropdown_bmp
= wxAuiBitmapFromBits(
156 button_dropdown_bits
, 5, 3,
157 wxColor(128,128,128));
158 m_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, *wxBLACK
);
159 m_disabled_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, wxColor(128,128,128));
161 m_font
= *wxNORMAL_FONT
;
164 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
166 m_font
= *wxNORMAL_FONT
;
170 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
172 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
175 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
180 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
185 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
187 m_text_orientation
= orientation
;
190 unsigned int wxAuiDefaultToolBarArt::GetFlags()
195 wxFont
wxAuiDefaultToolBarArt::GetFont()
200 int wxAuiDefaultToolBarArt::GetTextOrientation()
202 return m_text_orientation
;
205 void wxAuiDefaultToolBarArt::DrawBackground(
207 wxWindow
* WXUNUSED(wnd
),
212 wxColour start_colour
= m_base_colour
.ChangeLightness(150);
213 wxColour end_colour
= m_base_colour
.ChangeLightness(90);
214 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
217 void wxAuiDefaultToolBarArt::DrawLabel(
219 wxWindow
* WXUNUSED(wnd
),
220 const wxAuiToolBarItem
& item
,
224 dc
.SetTextForeground(*wxBLACK
);
226 // we only care about the text height here since the text
227 // will get cropped based on the width of the item
228 int text_width
= 0, text_height
= 0;
229 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
231 // set the clipping region
232 wxRect clip_rect
= rect
;
233 clip_rect
.width
-= 1;
234 dc
.SetClippingRegion(clip_rect
);
238 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
239 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
240 dc
.DestroyClippingRegion();
244 void wxAuiDefaultToolBarArt::DrawButton(
246 wxWindow
* WXUNUSED(wnd
),
247 const wxAuiToolBarItem
& item
,
250 int text_width
= 0, text_height
= 0;
252 if (m_flags
& wxAUI_TB_TEXT
)
258 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
260 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
263 int bmp_x
= 0, bmp_y
= 0;
264 int text_x
= 0, text_y
= 0;
266 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
270 (item
.GetBitmap().GetWidth()/2);
273 ((rect
.height
-text_height
)/2) -
274 (item
.GetBitmap().GetHeight()/2);
276 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
277 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
279 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
285 (item
.GetBitmap().GetHeight()/2);
287 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
294 if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
))
296 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
298 dc
.SetPen(wxPen(m_highlight_colour
));
299 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(150)));
300 dc
.DrawRectangle(rect
);
302 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
304 dc
.SetPen(wxPen(m_highlight_colour
));
305 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
307 // draw an even lighter background for checked item hovers (since
308 // the hover background is the same color as the check background)
309 if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
310 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(180)));
312 dc
.DrawRectangle(rect
);
314 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
316 // it's important to put this code in an else statment after the
317 // hover, otherwise hovers won't draw properly for checked items
318 dc
.SetPen(wxPen(m_highlight_colour
));
319 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
320 dc
.DrawRectangle(rect
);
325 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
326 bmp
= item
.GetDisabledBitmap();
328 bmp
= item
.GetBitmap();
331 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
333 // set the item's text color based on if it is disabled
334 dc
.SetTextForeground(*wxBLACK
);
335 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
336 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
338 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
340 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
345 void wxAuiDefaultToolBarArt::DrawDropDownButton(
347 wxWindow
* WXUNUSED(wnd
),
348 const wxAuiToolBarItem
& item
,
351 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
352 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
354 wxRect button_rect
= wxRect(rect
.x
,
356 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
358 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
360 BUTTON_DROPDOWN_WIDTH
+1,
363 if (m_flags
& wxAUI_TB_TEXT
)
368 if (m_flags
& wxAUI_TB_TEXT
)
370 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
374 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
379 dropbmp_x
= dropdown_rect
.x
+
380 (dropdown_rect
.width
/2) -
381 (m_button_dropdown_bmp
.GetWidth()/2);
382 dropbmp_y
= dropdown_rect
.y
+
383 (dropdown_rect
.height
/2) -
384 (m_button_dropdown_bmp
.GetHeight()/2);
387 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
389 bmp_x
= button_rect
.x
+
390 (button_rect
.width
/2) -
391 (item
.GetBitmap().GetWidth()/2);
392 bmp_y
= button_rect
.y
+
393 ((button_rect
.height
-text_height
)/2) -
394 (item
.GetBitmap().GetHeight()/2);
396 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
397 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
399 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
405 (item
.GetBitmap().GetHeight()/2);
407 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
414 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
416 dc
.SetPen(wxPen(m_highlight_colour
));
417 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(140)));
418 dc
.DrawRectangle(button_rect
);
420 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
421 dc
.DrawRectangle(dropdown_rect
);
423 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
426 dc
.SetPen(wxPen(m_highlight_colour
));
427 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
428 dc
.DrawRectangle(button_rect
);
429 dc
.DrawRectangle(dropdown_rect
);
431 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
433 // Notice that this branch must come after the hover one to ensure the
434 // correct appearance when the mouse hovers over a checked item.
435 dc
.SetPen(wxPen(m_highlight_colour
));
436 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
437 dc
.DrawRectangle(button_rect
);
438 dc
.DrawRectangle(dropdown_rect
);
443 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
445 bmp
= item
.GetDisabledBitmap();
446 dropbmp
= m_disabled_button_dropdown_bmp
;
450 bmp
= item
.GetBitmap();
451 dropbmp
= m_button_dropdown_bmp
;
457 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
458 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
460 // set the item's text color based on if it is disabled
461 dc
.SetTextForeground(*wxBLACK
);
462 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
463 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
465 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
467 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
471 void wxAuiDefaultToolBarArt::DrawControlLabel(
473 wxWindow
* WXUNUSED(wnd
),
474 const wxAuiToolBarItem
& item
,
477 if (!(m_flags
& wxAUI_TB_TEXT
))
480 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
483 int text_x
= 0, text_y
= 0;
484 int text_width
= 0, text_height
= 0;
489 if (m_flags
& wxAUI_TB_TEXT
)
491 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
495 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
497 // don't draw the label if it is wider than the item width
498 if (text_width
> rect
.width
)
501 // set the label's text color
502 dc
.SetTextForeground(*wxBLACK
);
504 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
505 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
507 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
509 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
513 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
515 wxWindow
* WXUNUSED(wnd
),
516 const wxAuiToolBarItem
& item
)
520 // get label's height
521 int width
= 0, height
= 0;
522 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
525 width
= item
.GetMinSize().GetWidth();
529 // no width specified, measure the text ourselves
530 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
533 return wxSize(width
, height
);
536 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
538 wxWindow
* WXUNUSED(wnd
),
539 const wxAuiToolBarItem
& item
)
541 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
542 return wxSize(16,16);
544 int width
= item
.GetBitmap().GetWidth();
545 int height
= item
.GetBitmap().GetHeight();
547 if (m_flags
& wxAUI_TB_TEXT
)
552 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
554 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
557 if ( !item
.GetLabel().empty() )
559 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
560 width
= wxMax(width
, tx
+6);
563 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
564 !item
.GetLabel().empty() )
566 width
+= 3; // space between left border and bitmap
567 width
+= 3; // space between bitmap and text
569 if ( !item
.GetLabel().empty() )
571 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
573 height
= wxMax(height
, ty
);
578 // if the tool has a dropdown button, add it to the width
579 if (item
.HasDropDown())
580 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
582 return wxSize(width
, height
);
585 void wxAuiDefaultToolBarArt::DrawSeparator(
587 wxWindow
* WXUNUSED(wnd
),
590 bool horizontal
= true;
591 if (m_flags
& wxAUI_TB_VERTICAL
)
598 rect
.x
+= (rect
.width
/2);
600 int new_height
= (rect
.height
*3)/4;
601 rect
.y
+= (rect
.height
/2) - (new_height
/2);
602 rect
.height
= new_height
;
606 rect
.y
+= (rect
.height
/2);
608 int new_width
= (rect
.width
*3)/4;
609 rect
.x
+= (rect
.width
/2) - (new_width
/2);
610 rect
.width
= new_width
;
613 wxColour start_colour
= m_base_colour
.ChangeLightness(80);
614 wxColour end_colour
= m_base_colour
.ChangeLightness(80);
615 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
618 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
619 wxWindow
* WXUNUSED(wnd
),
627 if (m_flags
& wxAUI_TB_VERTICAL
)
629 x
= rect
.x
+ (i
*4) + 5;
631 if (x
> rect
.GetWidth()-5)
637 y
= rect
.y
+ (i
*4) + 5;
638 if (y
> rect
.GetHeight()-5)
642 dc
.SetPen(m_gripper_pen1
);
644 dc
.SetPen(m_gripper_pen2
);
645 dc
.DrawPoint(x
, y
+1);
646 dc
.DrawPoint(x
+1, y
);
647 dc
.SetPen(m_gripper_pen3
);
648 dc
.DrawPoint(x
+2, y
+1);
649 dc
.DrawPoint(x
+2, y
+2);
650 dc
.DrawPoint(x
+1, y
+2);
657 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
662 if (state
& wxAUI_BUTTON_STATE_HOVER
||
663 state
& wxAUI_BUTTON_STATE_PRESSED
)
665 wxRect cli_rect
= wnd
->GetClientRect();
666 wxColor light_gray_bg
= m_highlight_colour
.ChangeLightness(170);
668 if (m_flags
& wxAUI_TB_VERTICAL
)
670 dc
.SetPen(wxPen(m_highlight_colour
));
671 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
672 dc
.SetPen(wxPen(light_gray_bg
));
673 dc
.SetBrush(wxBrush(light_gray_bg
));
674 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
678 dc
.SetPen(wxPen(m_highlight_colour
));
679 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
680 dc
.SetPen(wxPen(light_gray_bg
));
681 dc
.SetBrush(wxBrush(light_gray_bg
));
682 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
686 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
687 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
688 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
691 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
695 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
696 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
697 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
702 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
706 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
; break;
707 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
; break;
708 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
; break;
712 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
713 const wxAuiToolBarItemArray
& items
)
717 size_t items_added
= 0;
719 size_t i
, count
= items
.GetCount();
720 for (i
= 0; i
< count
; ++i
)
722 wxAuiToolBarItem
& item
= items
.Item(i
);
724 if (item
.GetKind() == wxITEM_NORMAL
)
726 wxString text
= item
.GetShortHelp();
728 text
= item
.GetLabel();
733 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
735 m
->SetBitmap(item
.GetBitmap());
739 else if (item
.GetKind() == wxITEM_SEPARATOR
)
742 menuPopup
.AppendSeparator();
746 // find out where to put the popup menu of window items
747 wxPoint pt
= ::wxGetMousePosition();
748 pt
= wnd
->ScreenToClient(pt
);
750 // find out the screen coordinate at the bottom of the tab ctrl
751 wxRect cli_rect
= wnd
->GetClientRect();
752 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
754 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
755 wnd
->PushEventHandler(cc
);
756 wnd
->PopupMenu(&menuPopup
, pt
);
757 int command
= cc
->GetCommandId();
758 wnd
->PopEventHandler(true);
766 static wxOrientation
GetOrientation(long& style
)
768 switch (style
& wxAUI_ORIENTATION_MASK
)
770 case wxAUI_TB_HORIZONTAL
:
772 case wxAUI_TB_VERTICAL
:
775 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
782 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
783 EVT_SIZE(wxAuiToolBar::OnSize
)
784 EVT_IDLE(wxAuiToolBar::OnIdle
)
785 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
786 EVT_PAINT(wxAuiToolBar::OnPaint
)
787 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
788 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
789 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
790 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
791 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
792 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
793 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
794 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
795 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
796 EVT_MOTION(wxAuiToolBar::OnMotion
)
797 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
798 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
799 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
803 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
805 const wxPoint
& position
,
812 style
| wxBORDER_NONE
)
814 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
816 m_button_height
= -1;
817 m_sizer_element_count
= 0;
818 m_action_pos
= wxPoint(-1,-1);
819 m_action_item
= NULL
;
821 m_art
= new wxAuiDefaultToolBarArt
;
823 m_tool_border_padding
= 3;
824 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
825 m_gripper_sizer_item
= NULL
;
826 m_overflow_sizer_item
= NULL
;
828 m_orientation
= GetOrientation(style
);
829 if (m_orientation
== wxBOTH
)
831 m_orientation
= wxHORIZONTAL
;
833 m_style
= style
| wxBORDER_NONE
;
834 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
835 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
836 m_overflow_state
= 0;
837 SetMargins(5, 5, 2, 2);
838 SetFont(*wxNORMAL_FONT
);
840 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
841 if (style
& wxAUI_TB_HORZ_LAYOUT
)
842 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
843 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
847 wxAuiToolBar::~wxAuiToolBar()
853 void wxAuiToolBar::SetWindowStyleFlag(long style
)
855 GetOrientation(style
); // assert if style is invalid
856 wxCHECK_RET(IsPaneValid(style
),
857 "window settings and pane settings are incompatible");
859 wxControl::SetWindowStyleFlag(style
);
868 if (m_style
& wxAUI_TB_GRIPPER
)
869 m_gripper_visible
= true;
871 m_gripper_visible
= false;
874 if (m_style
& wxAUI_TB_OVERFLOW
)
875 m_overflow_visible
= true;
877 m_overflow_visible
= false;
879 if (style
& wxAUI_TB_HORZ_LAYOUT
)
880 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
882 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
885 long wxAuiToolBar::GetWindowStyleFlag() const
890 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
899 m_art
->SetTextOrientation(m_tool_text_orientation
);
903 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
911 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
912 const wxString
& label
,
913 const wxBitmap
& bitmap
,
914 const wxString
& short_help_string
,
917 return AddTool(tool_id
,
928 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
929 const wxString
& label
,
930 const wxBitmap
& bitmap
,
931 const wxBitmap
& disabled_bitmap
,
933 const wxString
& short_help_string
,
934 const wxString
& long_help_string
,
935 wxObject
* WXUNUSED(client_data
))
937 wxAuiToolBarItem item
;
940 item
.bitmap
= bitmap
;
941 item
.disabled_bitmap
= disabled_bitmap
;
942 item
.short_help
= short_help_string
;
943 item
.long_help
= long_help_string
;
945 item
.dropdown
= false;
946 item
.spacer_pixels
= 0;
947 item
.toolid
= tool_id
;
951 item
.sizer_item
= NULL
;
952 item
.min_size
= wxDefaultSize
;
956 if (item
.toolid
== wxID_ANY
)
957 item
.toolid
= wxNewId();
959 if (!item
.disabled_bitmap
.IsOk())
961 // no disabled bitmap specified, we need to make one
962 if (item
.bitmap
.IsOk())
964 item
.disabled_bitmap
= item
.bitmap
.ConvertToDisabled();
968 return &m_items
.Last();
971 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
972 const wxString
& label
)
974 wxAuiToolBarItem item
;
975 item
.window
= (wxWindow
*)control
;
977 item
.bitmap
= wxNullBitmap
;
978 item
.disabled_bitmap
= wxNullBitmap
;
980 item
.dropdown
= false;
981 item
.spacer_pixels
= 0;
982 item
.toolid
= control
->GetId();
985 item
.kind
= wxITEM_CONTROL
;
986 item
.sizer_item
= NULL
;
987 item
.min_size
= control
->GetEffectiveMinSize();
992 return &m_items
.Last();
995 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
996 const wxString
& label
,
999 wxSize min_size
= wxDefaultSize
;
1003 wxAuiToolBarItem item
;
1006 item
.bitmap
= wxNullBitmap
;
1007 item
.disabled_bitmap
= wxNullBitmap
;
1009 item
.dropdown
= false;
1010 item
.spacer_pixels
= 0;
1011 item
.toolid
= tool_id
;
1013 item
.proportion
= 0;
1014 item
.kind
= wxITEM_LABEL
;
1015 item
.sizer_item
= NULL
;
1016 item
.min_size
= min_size
;
1018 item
.sticky
= false;
1020 if (item
.toolid
== wxID_ANY
)
1021 item
.toolid
= wxNewId();
1024 return &m_items
.Last();
1027 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1029 wxAuiToolBarItem item
;
1031 item
.label
= wxEmptyString
;
1032 item
.bitmap
= wxNullBitmap
;
1033 item
.disabled_bitmap
= wxNullBitmap
;
1035 item
.dropdown
= false;
1038 item
.proportion
= 0;
1039 item
.kind
= wxITEM_SEPARATOR
;
1040 item
.sizer_item
= NULL
;
1041 item
.min_size
= wxDefaultSize
;
1043 item
.sticky
= false;
1046 return &m_items
.Last();
1049 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1051 wxAuiToolBarItem item
;
1053 item
.label
= wxEmptyString
;
1054 item
.bitmap
= wxNullBitmap
;
1055 item
.disabled_bitmap
= wxNullBitmap
;
1057 item
.dropdown
= false;
1058 item
.spacer_pixels
= pixels
;
1061 item
.proportion
= 0;
1062 item
.kind
= wxITEM_SPACER
;
1063 item
.sizer_item
= NULL
;
1064 item
.min_size
= wxDefaultSize
;
1066 item
.sticky
= false;
1069 return &m_items
.Last();
1072 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1074 wxAuiToolBarItem item
;
1076 item
.label
= wxEmptyString
;
1077 item
.bitmap
= wxNullBitmap
;
1078 item
.disabled_bitmap
= wxNullBitmap
;
1080 item
.dropdown
= false;
1081 item
.spacer_pixels
= 0;
1084 item
.proportion
= proportion
;
1085 item
.kind
= wxITEM_SPACER
;
1086 item
.sizer_item
= NULL
;
1087 item
.min_size
= wxDefaultSize
;
1089 item
.sticky
= false;
1092 return &m_items
.Last();
1095 void wxAuiToolBar::Clear()
1098 m_sizer_element_count
= 0;
1101 bool wxAuiToolBar::DeleteTool(int tool_id
)
1103 int idx
= GetToolIndex(tool_id
);
1104 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1106 m_items
.RemoveAt(idx
);
1114 bool wxAuiToolBar::DeleteByIndex(int idx
)
1116 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1118 m_items
.RemoveAt(idx
);
1127 wxControl
* wxAuiToolBar::FindControl(int id
)
1129 wxWindow
* wnd
= FindWindow(id
);
1130 return (wxControl
*)wnd
;
1133 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1136 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1138 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1139 if (item
.toolid
== tool_id
)
1146 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1149 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1151 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1153 if (!item
.sizer_item
)
1156 wxRect rect
= item
.sizer_item
->GetRect();
1157 if (rect
.Contains(x
,y
))
1159 // if the item doesn't fit on the toolbar, return NULL
1160 if (!GetToolFitsByIndex(i
))
1170 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1173 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1175 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1177 if (!item
.sizer_item
)
1180 wxRect rect
= item
.sizer_item
->GetRect();
1182 // apply tool packing
1184 rect
.width
+= m_tool_packing
;
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::FindToolByIndex(int idx
) const
1204 if (idx
>= (int)m_items
.size())
1207 return &(m_items
[idx
]);
1210 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1212 // TODO: wxToolBar compatibility
1215 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1217 // TODO: wxToolBar compatibility
1218 return wxSize(16,15);
1221 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1223 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1227 item
->proportion
= proportion
;
1230 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1232 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1236 return item
->proportion
;
1239 void wxAuiToolBar::SetToolSeparation(int separation
)
1242 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1245 int wxAuiToolBar::GetToolSeparation() const
1248 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1254 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1256 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1260 item
->dropdown
= dropdown
;
1263 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1265 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1269 return item
->dropdown
;
1272 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1274 // ignore separators
1278 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1282 if (item
->sticky
== sticky
)
1285 item
->sticky
= sticky
;
1291 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1293 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1297 return item
->sticky
;
1303 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1305 m_tool_border_padding
= padding
;
1308 int wxAuiToolBar::GetToolBorderPadding() const
1310 return m_tool_border_padding
;
1313 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1315 m_tool_text_orientation
= orientation
;
1319 m_art
->SetTextOrientation(orientation
);
1323 int wxAuiToolBar::GetToolTextOrientation() const
1325 return m_tool_text_orientation
;
1328 void wxAuiToolBar::SetToolPacking(int packing
)
1330 m_tool_packing
= packing
;
1333 int wxAuiToolBar::GetToolPacking() const
1335 return m_tool_packing
;
1339 void wxAuiToolBar::SetOrientation(int orientation
)
1341 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1342 orientation
== wxVERTICAL
,
1343 "invalid orientation value");
1344 if (orientation
!= m_orientation
)
1346 m_orientation
= wxOrientation(orientation
);
1351 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1354 m_left_padding
= left
;
1356 m_right_padding
= right
;
1358 m_top_padding
= top
;
1360 m_bottom_padding
= bottom
;
1363 bool wxAuiToolBar::GetGripperVisible() const
1365 return m_gripper_visible
;
1368 void wxAuiToolBar::SetGripperVisible(bool visible
)
1370 m_gripper_visible
= visible
;
1372 m_style
|= wxAUI_TB_GRIPPER
;
1374 m_style
&= ~wxAUI_TB_GRIPPER
;
1380 bool wxAuiToolBar::GetOverflowVisible() const
1382 return m_overflow_visible
;
1385 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1387 m_overflow_visible
= visible
;
1389 m_style
|= wxAUI_TB_OVERFLOW
;
1391 m_style
&= ~wxAUI_TB_OVERFLOW
;
1395 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1397 bool res
= wxWindow::SetFont(font
);
1401 m_art
->SetFont(font
);
1408 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1410 wxAuiToolBarItem
* former_hover
= NULL
;
1413 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1415 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1416 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1417 former_hover
= &item
;
1418 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1423 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1426 if (former_hover
!= pitem
)
1433 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1435 wxAuiToolBarItem
* former_item
= NULL
;
1438 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1440 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1441 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1442 former_item
= &item
;
1443 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1448 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1449 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1452 if (former_item
!= pitem
)
1459 void wxAuiToolBar::RefreshOverflowState()
1461 if (!m_overflow_sizer_item
)
1463 m_overflow_state
= 0;
1467 int overflow_state
= 0;
1469 wxRect overflow_rect
= GetOverflowRect();
1472 // find out the mouse's current position
1473 wxPoint pt
= ::wxGetMousePosition();
1474 pt
= this->ScreenToClient(pt
);
1476 // find out if the mouse cursor is inside the dropdown rectangle
1477 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1479 if (::wxGetMouseState().LeftIsDown())
1480 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1482 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1485 if (overflow_state
!= m_overflow_state
)
1487 m_overflow_state
= overflow_state
;
1492 m_overflow_state
= overflow_state
;
1495 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1497 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1499 if (tool
&& (tool
->kind
== wxITEM_CHECK
|| tool
->kind
== wxITEM_RADIO
))
1501 if (tool
->kind
== wxITEM_RADIO
)
1504 idx
= GetToolIndex(tool_id
);
1505 count
= (int)m_items
.GetCount();
1507 if (idx
>= 0 && idx
< count
)
1509 for (i
= idx
+ 1; i
< count
; ++i
)
1511 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1513 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1515 for (i
= idx
- 1; i
>= 0; i
--)
1517 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1519 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1523 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1525 else if (tool
->kind
== wxITEM_CHECK
)
1528 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1530 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1535 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1537 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1541 if ( (tool
->kind
!= wxITEM_CHECK
) && (tool
->kind
!= wxITEM_RADIO
) )
1544 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1550 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1552 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1557 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1559 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1563 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1565 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1568 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1573 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1575 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1576 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1578 return wxEmptyString
;
1583 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1585 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1588 tool
->label
= label
;
1592 wxBitmap
wxAuiToolBar::GetToolBitmap(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 wxNullBitmap
;
1599 return tool
->bitmap
;
1602 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1604 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1607 tool
->bitmap
= bitmap
;
1611 wxString
wxAuiToolBar::GetToolShortHelp(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 wxEmptyString
;
1618 return tool
->short_help
;
1621 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1623 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1626 tool
->short_help
= help_string
;
1630 wxString
wxAuiToolBar::GetToolLongHelp(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
->long_help
;
1640 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1642 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1645 tool
->long_help
= help_string
;
1649 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1650 const wxAuiToolBarItemArray
& append
)
1652 m_custom_overflow_prepend
= prepend
;
1653 m_custom_overflow_append
= append
;
1656 // get size of hint rectangle for a particular dock location
1657 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1659 switch (dock_direction
)
1661 case wxAUI_DOCK_TOP
:
1662 case wxAUI_DOCK_BOTTOM
:
1663 return m_horzHintSize
;
1664 case wxAUI_DOCK_RIGHT
:
1665 case wxAUI_DOCK_LEFT
:
1666 return m_vertHintSize
;
1668 wxCHECK_MSG(false, wxDefaultSize
, "invalid dock location value");
1672 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1674 return IsPaneValid(m_style
, pane
);
1677 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1679 if (style
& wxAUI_TB_HORIZONTAL
)
1681 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1686 else if (style
& wxAUI_TB_VERTICAL
)
1688 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1696 bool wxAuiToolBar::IsPaneValid(long style
) const
1698 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1701 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1706 void wxAuiToolBar::SetArtFlags() const
1708 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1709 if (m_orientation
== wxVERTICAL
)
1711 artflags
|= wxAUI_TB_VERTICAL
;
1713 m_art
->SetFlags(artflags
);
1716 size_t wxAuiToolBar::GetToolCount() const
1718 return m_items
.size();
1721 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1723 // this will prevent us from returning the index of the
1724 // first separator in the toolbar since its id is equal to -1
1728 size_t i
, count
= m_items
.GetCount();
1729 for (i
= 0; i
< count
; ++i
)
1731 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1732 if (item
.toolid
== tool_id
)
1739 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1741 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1744 if (!m_items
[tool_idx
].sizer_item
)
1748 GetClientSize(&cli_w
, &cli_h
);
1750 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1752 if (m_orientation
== wxVERTICAL
)
1754 // take the dropdown size into account
1755 if (m_overflow_visible
)
1756 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1758 if (rect
.y
+rect
.height
< cli_h
)
1763 // take the dropdown size into account
1764 if (m_overflow_visible
)
1765 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1767 if (rect
.x
+rect
.width
< cli_w
)
1775 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1777 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1780 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1782 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1783 if (tool
&& tool
->sizer_item
)
1785 return tool
->sizer_item
->GetRect();
1791 bool wxAuiToolBar::GetToolBarFits() const
1793 if (m_items
.GetCount() == 0)
1795 // empty toolbar always 'fits'
1799 // entire toolbar content fits if the last tool fits
1800 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1803 bool wxAuiToolBar::Realize()
1805 wxClientDC
dc(this);
1809 // calculate hint sizes for both horizontal and vertical
1810 // in the order that leaves toolbar in correct final state
1811 bool retval
= false;
1812 if (m_orientation
== wxHORIZONTAL
)
1814 if (RealizeHelper(dc
, false))
1816 m_vertHintSize
= GetSize();
1817 if (RealizeHelper(dc
, true))
1819 m_horzHintSize
= GetSize();
1826 if (RealizeHelper(dc
, true))
1828 m_horzHintSize
= GetSize();
1829 if (RealizeHelper(dc
, false))
1831 m_vertHintSize
= GetSize();
1841 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1843 // create the new sizer to add toolbar elements to
1844 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1847 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1848 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1849 if (gripper_size
> 0 && m_gripper_visible
)
1852 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1854 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1858 m_gripper_sizer_item
= NULL
;
1861 // add "left" padding
1862 if (m_left_padding
> 0)
1865 sizer
->Add(m_left_padding
, 1);
1867 sizer
->Add(1, m_left_padding
);
1871 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1873 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1874 wxSizerItem
* sizer_item
= NULL
;
1880 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1881 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1882 size
.y
+ (m_tool_border_padding
*2),
1887 sizer
->AddSpacer(m_tool_packing
);
1897 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1898 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1899 size
.y
+ (m_tool_border_padding
*2),
1905 sizer
->AddSpacer(m_tool_packing
);
1911 case wxITEM_SEPARATOR
:
1914 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1916 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1921 sizer
->AddSpacer(m_tool_packing
);
1928 if (item
.proportion
> 0)
1929 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1931 sizer_item
= sizer
->Add(item
.spacer_pixels
, 1);
1934 case wxITEM_CONTROL
:
1936 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1937 wxSizerItem
* ctrl_sizer_item
;
1939 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1940 vert_sizer
->AddStretchSpacer(1);
1941 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1942 vert_sizer
->AddStretchSpacer(1);
1943 if ( (m_style
& wxAUI_TB_TEXT
) &&
1944 m_tool_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1945 !item
.GetLabel().empty() )
1947 wxSize s
= GetLabelSize(item
.GetLabel());
1948 vert_sizer
->Add(1, s
.y
);
1952 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1954 wxSize min_size
= item
.min_size
;
1957 // proportional items will disappear from the toolbar if
1958 // their min width is not set to something really small
1959 if (item
.proportion
!= 0)
1964 if (min_size
.IsFullySpecified())
1966 sizer_item
->SetMinSize(min_size
);
1967 ctrl_sizer_item
->SetMinSize(min_size
);
1973 sizer
->AddSpacer(m_tool_packing
);
1978 item
.sizer_item
= sizer_item
;
1981 // add "right" padding
1982 if (m_right_padding
> 0)
1985 sizer
->Add(m_right_padding
, 1);
1987 sizer
->Add(1, m_right_padding
);
1990 // add drop down area
1991 m_overflow_sizer_item
= NULL
;
1993 if (m_style
& wxAUI_TB_OVERFLOW
)
1995 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1996 if (overflow_size
> 0 && m_overflow_visible
)
1999 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2001 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2005 m_overflow_sizer_item
= NULL
;
2010 // the outside sizer helps us apply the "top" and "bottom" padding
2011 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2013 // add "top" padding
2014 if (m_top_padding
> 0)
2017 outside_sizer
->Add(1, m_top_padding
);
2019 outside_sizer
->Add(m_top_padding
, 1);
2022 // add the sizer that contains all of the toolbar elements
2023 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2025 // add "bottom" padding
2026 if (m_bottom_padding
> 0)
2029 outside_sizer
->Add(1, m_bottom_padding
);
2031 outside_sizer
->Add(m_bottom_padding
, 1);
2034 delete m_sizer
; // remove old sizer
2035 m_sizer
= outside_sizer
;
2037 // calculate the rock-bottom minimum size
2038 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2040 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2041 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2042 item
.sizer_item
->SetMinSize(0,0);
2045 m_absolute_min_size
= m_sizer
->GetMinSize();
2047 // reset the min sizes to what they were
2048 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2050 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2051 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2052 item
.sizer_item
->SetMinSize(item
.min_size
);
2056 wxSize size
= m_sizer
->GetMinSize();
2057 m_minWidth
= size
.x
;
2058 m_minHeight
= size
.y
;
2060 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2062 wxSize cur_size
= GetClientSize();
2063 wxSize new_size
= GetMinSize();
2064 if (new_size
!= cur_size
)
2066 SetClientSize(new_size
);
2070 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2075 wxSize cur_size
= GetClientSize();
2076 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2082 int wxAuiToolBar::GetOverflowState() const
2084 return m_overflow_state
;
2087 wxRect
wxAuiToolBar::GetOverflowRect() const
2089 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2090 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
2091 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2093 if (m_orientation
== wxVERTICAL
)
2095 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2096 overflow_rect
.x
= 0;
2097 overflow_rect
.width
= cli_rect
.width
;
2098 overflow_rect
.height
= overflow_size
;
2102 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2103 overflow_rect
.y
= 0;
2104 overflow_rect
.width
= overflow_size
;
2105 overflow_rect
.height
= cli_rect
.height
;
2108 return overflow_rect
;
2111 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2113 wxClientDC
dc(this);
2116 int text_width
= 0, text_height
= 0;
2120 // get the text height
2121 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
2123 // get the text width
2124 dc
.GetTextExtent(label
, &text_width
, &ty
);
2126 return wxSize(text_width
, text_height
);
2130 void wxAuiToolBar::DoIdleUpdate()
2132 wxEvtHandler
* handler
= GetEventHandler();
2134 bool need_refresh
= false;
2137 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2139 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2141 if (item
.toolid
== -1)
2144 wxUpdateUIEvent
evt(item
.toolid
);
2145 evt
.SetEventObject(this);
2147 if (handler
->ProcessEvent(evt
))
2149 if (evt
.GetSetEnabled())
2153 is_enabled
= item
.window
->IsEnabled();
2155 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2157 bool new_enabled
= evt
.GetEnabled();
2158 if (new_enabled
!= is_enabled
)
2162 item
.window
->Enable(new_enabled
);
2167 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2169 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2171 need_refresh
= true;
2175 if (evt
.GetSetChecked())
2177 // make sure we aren't checking an item that can't be
2178 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2181 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2182 bool new_checked
= evt
.GetChecked();
2184 if (new_checked
!= is_checked
)
2187 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2189 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2191 need_refresh
= true;
2206 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2209 GetClientSize(&x
, &y
);
2211 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2212 ((y
> x
) && m_absolute_min_size
.y
> y
))
2214 // hide all flexible items
2216 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2218 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2219 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2221 item
.sizer_item
->Show(false);
2222 item
.sizer_item
->SetProportion(0);
2228 // show all flexible items
2230 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2232 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2233 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2235 item
.sizer_item
->Show(true);
2236 item
.sizer_item
->SetProportion(item
.proportion
);
2241 m_sizer
->SetDimension(0, 0, x
, y
);
2246 // idle events aren't sent while user is resizing frame (why?),
2247 // but resizing toolbar here causes havoc,
2248 // so force idle handler to run after size handling complete
2249 QueueEvent(new wxIdleEvent
);
2254 void wxAuiToolBar::DoSetSize(int x
,
2260 wxSize parent_size
= GetParent()->GetClientSize();
2261 if (x
+ width
> parent_size
.x
)
2262 width
= wxMax(0, parent_size
.x
- x
);
2263 if (y
+ height
> parent_size
.y
)
2264 height
= wxMax(0, parent_size
.y
- y
);
2266 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2270 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2272 // if orientation doesn't match dock, fix it
2273 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2276 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2277 // pane state member is public, so it might have been changed
2278 // without going through wxPaneInfo::SetFlag() check
2279 bool ok
= pane
.IsOk();
2280 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2281 "window settings and pane settings are incompatible");
2284 wxOrientation newOrientation
= m_orientation
;
2285 if (pane
.IsDocked())
2287 switch (pane
.dock_direction
)
2289 case wxAUI_DOCK_TOP
:
2290 case wxAUI_DOCK_BOTTOM
:
2291 newOrientation
= wxHORIZONTAL
;
2293 case wxAUI_DOCK_LEFT
:
2294 case wxAUI_DOCK_RIGHT
:
2295 newOrientation
= wxVERTICAL
;
2298 wxFAIL_MSG("invalid dock location value");
2301 else if (pane
.IsResizable() &&
2302 GetOrientation(m_style
) == wxBOTH
)
2304 // changing orientation in OnSize causes havoc
2306 GetClientSize(&x
, &y
);
2310 newOrientation
= wxHORIZONTAL
;
2314 newOrientation
= wxVERTICAL
;
2317 if (newOrientation
!= m_orientation
)
2319 SetOrientation(newOrientation
);
2321 if (newOrientation
== wxHORIZONTAL
)
2323 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2327 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2329 if (pane
.IsDocked())
2331 pane
.floating_size
= wxDefaultSize
;
2335 SetSize(GetParent()->GetClientSize());
2346 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2348 wxAutoBufferedPaintDC
dc(this);
2349 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2352 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2355 m_art
->DrawBackground(dc
, this, cli_rect
);
2357 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2358 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2360 // paint the gripper
2361 if (gripper_size
> 0 && m_gripper_sizer_item
)
2363 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2365 gripper_rect
.width
= gripper_size
;
2367 gripper_rect
.height
= gripper_size
;
2368 m_art
->DrawGripper(dc
, this, gripper_rect
);
2371 // calculated how far we can draw items
2374 last_extent
= cli_rect
.width
;
2376 last_extent
= cli_rect
.height
;
2377 if (m_overflow_visible
)
2378 last_extent
-= dropdown_size
;
2380 // paint each individual tool
2381 size_t i
, count
= m_items
.GetCount();
2382 for (i
= 0; i
< count
; ++i
)
2384 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2386 if (!item
.sizer_item
)
2389 wxRect item_rect
= item
.sizer_item
->GetRect();
2392 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2393 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2398 if (item
.kind
== wxITEM_SEPARATOR
)
2401 m_art
->DrawSeparator(dc
, this, item_rect
);
2403 else if (item
.kind
== wxITEM_LABEL
)
2405 // draw a text label only
2406 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2408 else if (item
.kind
== wxITEM_NORMAL
)
2410 // draw a regular button or dropdown button
2412 m_art
->DrawButton(dc
, this, item
, item_rect
);
2414 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2416 else if (item
.kind
== wxITEM_CHECK
)
2418 // draw either a regular or dropdown toggle button
2420 m_art
->DrawButton(dc
, this, item
, item_rect
);
2422 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2424 else if (item
.kind
== wxITEM_RADIO
)
2426 // draw a toggle button
2427 m_art
->DrawButton(dc
, this, item
, item_rect
);
2429 else if (item
.kind
== wxITEM_CONTROL
)
2431 // draw the control's label
2432 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2435 // fire a signal to see if the item wants to be custom-rendered
2436 OnCustomRender(dc
, item
, item_rect
);
2439 // paint the overflow button
2440 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2442 wxRect dropdown_rect
= GetOverflowRect();
2443 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2447 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2452 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2454 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2456 if (m_gripper_sizer_item
)
2458 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2459 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2462 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2466 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2467 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2469 // gripper was clicked
2470 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2475 if (m_overflow_sizer_item
)
2477 wxRect overflow_rect
= GetOverflowRect();
2480 m_overflow_visible
&&
2481 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2483 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2484 e
.SetEventObject(this);
2486 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2487 bool processed
= GetEventHandler()->ProcessEvent(e
);
2496 wxAuiToolBarItemArray overflow_items
;
2499 // add custom overflow prepend items, if any
2500 count
= m_custom_overflow_prepend
.GetCount();
2501 for (i
= 0; i
< count
; ++i
)
2502 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2504 // only show items that don't fit in the dropdown
2505 count
= m_items
.GetCount();
2506 for (i
= 0; i
< count
; ++i
)
2508 if (!GetToolFitsByIndex(i
))
2509 overflow_items
.Add(m_items
[i
]);
2512 // add custom overflow append items, if any
2513 count
= m_custom_overflow_append
.GetCount();
2514 for (i
= 0; i
< count
; ++i
)
2515 overflow_items
.Add(m_custom_overflow_append
[i
]);
2517 int res
= m_art
->ShowDropDown(this, overflow_items
);
2518 m_overflow_state
= 0;
2522 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2523 e
.SetEventObject(this);
2524 GetParent()->GetEventHandler()->ProcessEvent(e
);
2533 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2534 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2538 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2540 m_action_pos
= wxPoint(-1,-1);
2541 m_action_item
= NULL
;
2547 // fire the tool dropdown event
2548 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->toolid
);
2549 e
.SetEventObject(this);
2550 e
.SetToolId(m_action_item
->toolid
);
2552 int mouse_x
= evt
.GetX();
2553 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2554 const bool dropDownHit
= m_action_item
->dropdown
&&
2555 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2556 mouse_x
< (rect
.x
+rect
.width
);
2557 e
.SetDropDownClicked(dropDownHit
);
2559 e
.SetClickPoint(evt
.GetPosition());
2560 e
.SetItemRect(rect
);
2562 // we only set the 'pressed button' state if we hit the actual button
2563 // and not just the drop-down
2564 SetPressedItem(dropDownHit
? 0 : m_action_item
);
2568 m_action_pos
= wxPoint(-1,-1);
2569 m_action_item
= NULL
;
2572 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2579 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2584 SetPressedItem(NULL
);
2586 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2587 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2589 SetHoverItem(hit_item
);
2594 // TODO: it would make sense to send out an 'END_DRAG' event here,
2595 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2598 // OnCaptureLost() will be called now and this will reset all our state
2599 // tracking variables
2604 wxAuiToolBarItem
* hit_item
;
2605 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2607 if (m_action_item
&& hit_item
== m_action_item
)
2611 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->toolid
);
2612 e
.SetEventObject(this);
2614 if (hit_item
->kind
== wxITEM_CHECK
|| hit_item
->kind
== wxITEM_RADIO
)
2616 const bool toggle
= !(m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
);
2618 ToggleTool(m_action_item
->toolid
, toggle
);
2620 // repaint immediately
2627 // we have to release the mouse *before* sending the event, because
2628 // we don't know what a handler might do. It could open up a popup
2629 // menu for example and that would make us lose our capture anyway.
2633 GetEventHandler()->ProcessEvent(e
);
2641 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2643 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2645 if (m_gripper_sizer_item
)
2647 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2648 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2652 if (m_overflow_sizer_item
)
2654 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2655 if (dropdown_size
> 0 &&
2656 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2658 evt
.m_y
< cli_rect
.height
&&
2665 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2666 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2668 if (m_action_item
&& m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2670 m_action_pos
= wxPoint(-1,-1);
2671 m_action_item
= NULL
;
2678 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2680 wxAuiToolBarItem
* hit_item
;
2681 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2683 if (m_action_item
&& hit_item
== m_action_item
)
2685 if (hit_item
->kind
== wxITEM_NORMAL
)
2687 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->toolid
);
2688 e
.SetEventObject(this);
2689 e
.SetToolId(m_action_item
->toolid
);
2690 e
.SetClickPoint(m_action_pos
);
2691 GetEventHandler()->ProcessEvent(e
);
2697 // right-clicked on the invalid area of the toolbar
2698 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2699 e
.SetEventObject(this);
2701 e
.SetClickPoint(m_action_pos
);
2702 GetEventHandler()->ProcessEvent(e
);
2706 // reset member variables
2707 m_action_pos
= wxPoint(-1,-1);
2708 m_action_item
= NULL
;
2711 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2713 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2715 if (m_gripper_sizer_item
)
2717 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2718 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2722 if (m_overflow_sizer_item
)
2724 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2725 if (dropdown_size
> 0 &&
2726 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2728 evt
.m_y
< cli_rect
.height
&&
2735 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2736 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2740 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2742 m_action_pos
= wxPoint(-1,-1);
2743 m_action_item
= NULL
;
2751 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2753 wxAuiToolBarItem
* hit_item
;
2754 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2756 if (m_action_item
&& hit_item
== m_action_item
)
2758 if (hit_item
->kind
== wxITEM_NORMAL
)
2760 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->toolid
);
2761 e
.SetEventObject(this);
2762 e
.SetToolId(m_action_item
->toolid
);
2763 e
.SetClickPoint(m_action_pos
);
2764 GetEventHandler()->ProcessEvent(e
);
2769 // reset member variables
2770 m_action_pos
= wxPoint(-1,-1);
2771 m_action_item
= NULL
;
2774 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2776 const bool button_pressed
= HasCapture();
2778 // start a drag event
2779 if (!m_dragging
&& button_pressed
&&
2780 abs(evt
.GetX() - m_action_pos
.x
) + abs(evt
.GetY() - m_action_pos
.y
) > 5)
2782 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2783 // event sent sometime in the future (see OnLeftUp())
2784 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2785 e
.SetEventObject(this);
2786 e
.SetToolId(m_action_item
->toolid
);
2787 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2795 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2798 // if we have a button pressed we want it to be shown in 'depressed'
2799 // state unless we move the mouse outside the button, then we want it
2800 // to show as just 'highlighted'
2801 if (hit_item
== m_action_item
)
2802 SetPressedItem(m_action_item
);
2805 SetPressedItem(NULL
);
2806 SetHoverItem(m_action_item
);
2811 if (hit_item
&& (hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2814 SetHoverItem(hit_item
);
2816 // tooltips handling
2817 wxAuiToolBarItem
* packing_hit_item
;
2818 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2819 if (packing_hit_item
)
2821 if (packing_hit_item
!= m_tip_item
)
2823 m_tip_item
= packing_hit_item
;
2825 if ( !packing_hit_item
->short_help
.empty() )
2826 SetToolTip(packing_hit_item
->short_help
);
2837 // figure out the dropdown button state (are we hovering or pressing it?)
2838 RefreshOverflowState();
2842 void wxAuiToolBar::DoResetMouseState()
2844 RefreshOverflowState();
2846 SetPressedItem(NULL
);
2850 // we have to reset those here, because the mouse-up handlers which do
2851 // it usually won't be called if we let go of a mouse button while we
2852 // are outside of the window
2853 m_action_pos
= wxPoint(-1,-1);
2854 m_action_item
= NULL
;
2857 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2865 DoResetMouseState();
2868 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2872 DoResetMouseState();
2875 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2877 wxCursor cursor
= wxNullCursor
;
2879 if (m_gripper_sizer_item
)
2881 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2882 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2884 cursor
= wxCursor(wxCURSOR_SIZING
);
2888 evt
.SetCursor(cursor
);