1 ///////////////////////////////////////////////////////////////////////////////
3 // Name: src/aui/dockart.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();
368 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
370 // set the item's text color based on if it is disabled
371 dc
.SetTextForeground(*wxBLACK
);
372 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
373 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
375 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
377 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
382 void wxAuiDefaultToolBarArt::DrawDropDownButton(
384 wxWindow
* WXUNUSED(wnd
),
385 const wxAuiToolBarItem
& item
,
388 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
389 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
391 wxRect button_rect
= wxRect(rect
.x
,
393 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
395 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
397 BUTTON_DROPDOWN_WIDTH
+1,
400 if (m_flags
& wxAUI_TB_TEXT
)
405 if (m_flags
& wxAUI_TB_TEXT
)
407 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
411 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
416 dropbmp_x
= dropdown_rect
.x
+
417 (dropdown_rect
.width
/2) -
418 (m_button_dropdown_bmp
.GetWidth()/2);
419 dropbmp_y
= dropdown_rect
.y
+
420 (dropdown_rect
.height
/2) -
421 (m_button_dropdown_bmp
.GetHeight()/2);
424 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
426 bmp_x
= button_rect
.x
+
427 (button_rect
.width
/2) -
428 (item
.GetBitmap().GetWidth()/2);
429 bmp_y
= button_rect
.y
+
430 ((button_rect
.height
-text_height
)/2) -
431 (item
.GetBitmap().GetHeight()/2);
433 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
434 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
436 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
442 (item
.GetBitmap().GetHeight()/2);
444 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
451 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
453 dc
.SetPen(wxPen(m_highlight_colour
));
454 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(140)));
455 dc
.DrawRectangle(button_rect
);
457 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
458 dc
.DrawRectangle(dropdown_rect
);
460 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
463 dc
.SetPen(wxPen(m_highlight_colour
));
464 dc
.SetBrush(wxBrush(m_highlight_colour
.ChangeLightness(170)));
465 dc
.DrawRectangle(button_rect
);
466 dc
.DrawRectangle(dropdown_rect
);
471 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
473 bmp
= item
.GetDisabledBitmap();
474 dropbmp
= m_disabled_button_dropdown_bmp
;
478 bmp
= item
.GetBitmap();
479 dropbmp
= m_button_dropdown_bmp
;
485 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
486 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
488 // set the item's text color based on if it is disabled
489 dc
.SetTextForeground(*wxBLACK
);
490 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
491 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
493 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
495 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
499 void wxAuiDefaultToolBarArt::DrawControlLabel(
501 wxWindow
* WXUNUSED(wnd
),
502 const wxAuiToolBarItem
& item
,
505 if (!(m_flags
& wxAUI_TB_TEXT
))
508 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
511 int text_x
= 0, text_y
= 0;
512 int text_width
= 0, text_height
= 0;
517 if (m_flags
& wxAUI_TB_TEXT
)
519 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
523 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
525 // don't draw the label if it is wider than the item width
526 if (text_width
> rect
.width
)
529 // set the label's text color
530 dc
.SetTextForeground(*wxBLACK
);
532 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
533 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
535 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
537 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
541 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
543 wxWindow
* WXUNUSED(wnd
),
544 const wxAuiToolBarItem
& item
)
548 // get label's height
549 int width
= 0, height
= 0;
550 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
553 width
= item
.GetMinSize().GetWidth();
557 // no width specified, measure the text ourselves
558 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
561 return wxSize(width
, height
);
564 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
566 wxWindow
* WXUNUSED(wnd
),
567 const wxAuiToolBarItem
& item
)
569 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
570 return wxSize(16,16);
572 int width
= item
.GetBitmap().GetWidth();
573 int height
= item
.GetBitmap().GetHeight();
575 if (m_flags
& wxAUI_TB_TEXT
)
580 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
582 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
585 if ( !item
.GetLabel().empty() )
587 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
588 width
= wxMax(width
, tx
+6);
591 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
592 !item
.GetLabel().empty() )
594 width
+= 3; // space between left border and bitmap
595 width
+= 3; // space between bitmap and text
597 if ( !item
.GetLabel().empty() )
599 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
601 height
= wxMax(height
, ty
);
606 // if the tool has a dropdown button, add it to the width
607 if (item
.HasDropDown())
608 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
610 return wxSize(width
, height
);
613 void wxAuiDefaultToolBarArt::DrawSeparator(
615 wxWindow
* WXUNUSED(wnd
),
618 bool horizontal
= true;
619 if (m_flags
& wxAUI_TB_VERTICAL
)
626 rect
.x
+= (rect
.width
/2);
628 int new_height
= (rect
.height
*3)/4;
629 rect
.y
+= (rect
.height
/2) - (new_height
/2);
630 rect
.height
= new_height
;
634 rect
.y
+= (rect
.height
/2);
636 int new_width
= (rect
.width
*3)/4;
637 rect
.x
+= (rect
.width
/2) - (new_width
/2);
638 rect
.width
= new_width
;
641 wxColour start_colour
= m_base_colour
.ChangeLightness(80);
642 wxColour end_colour
= m_base_colour
.ChangeLightness(80);
643 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
646 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
647 wxWindow
* WXUNUSED(wnd
),
655 if (m_flags
& wxAUI_TB_VERTICAL
)
657 x
= rect
.x
+ (i
*4) + 5;
659 if (x
> rect
.GetWidth()-5)
665 y
= rect
.y
+ (i
*4) + 5;
666 if (y
> rect
.GetHeight()-5)
670 dc
.SetPen(m_gripper_pen1
);
672 dc
.SetPen(m_gripper_pen2
);
673 dc
.DrawPoint(x
, y
+1);
674 dc
.DrawPoint(x
+1, y
);
675 dc
.SetPen(m_gripper_pen3
);
676 dc
.DrawPoint(x
+2, y
+1);
677 dc
.DrawPoint(x
+2, y
+2);
678 dc
.DrawPoint(x
+1, y
+2);
685 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
690 if (state
& wxAUI_BUTTON_STATE_HOVER
||
691 state
& wxAUI_BUTTON_STATE_PRESSED
)
693 wxRect cli_rect
= wnd
->GetClientRect();
694 wxColor light_gray_bg
= m_highlight_colour
.ChangeLightness(170);
696 if (m_flags
& wxAUI_TB_VERTICAL
)
698 dc
.SetPen(wxPen(m_highlight_colour
));
699 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
700 dc
.SetPen(wxPen(light_gray_bg
));
701 dc
.SetBrush(wxBrush(light_gray_bg
));
702 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
706 dc
.SetPen(wxPen(m_highlight_colour
));
707 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
708 dc
.SetPen(wxPen(light_gray_bg
));
709 dc
.SetBrush(wxBrush(light_gray_bg
));
710 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
714 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
715 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
716 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
719 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
723 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
724 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
725 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
730 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
734 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
; break;
735 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
; break;
736 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
; break;
740 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
741 const wxAuiToolBarItemArray
& items
)
745 size_t items_added
= 0;
747 size_t i
, count
= items
.GetCount();
748 for (i
= 0; i
< count
; ++i
)
750 wxAuiToolBarItem
& item
= items
.Item(i
);
752 if (item
.GetKind() == wxITEM_NORMAL
)
754 wxString text
= item
.GetShortHelp();
756 text
= item
.GetLabel();
761 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
763 m
->SetBitmap(item
.GetBitmap());
767 else if (item
.GetKind() == wxITEM_SEPARATOR
)
770 menuPopup
.AppendSeparator();
774 // find out where to put the popup menu of window items
775 wxPoint pt
= ::wxGetMousePosition();
776 pt
= wnd
->ScreenToClient(pt
);
778 // find out the screen coordinate at the bottom of the tab ctrl
779 wxRect cli_rect
= wnd
->GetClientRect();
780 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
782 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
783 wnd
->PushEventHandler(cc
);
784 wnd
->PopupMenu(&menuPopup
, pt
);
785 int command
= cc
->GetCommandId();
786 wnd
->PopEventHandler(true);
794 static wxOrientation
GetOrientation(long& style
)
796 switch (style
& wxAUI_ORIENTATION_MASK
)
798 case wxAUI_TB_HORIZONTAL
:
800 case wxAUI_TB_VERTICAL
:
803 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
810 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
811 EVT_SIZE(wxAuiToolBar::OnSize
)
812 EVT_IDLE(wxAuiToolBar::OnIdle
)
813 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
814 EVT_PAINT(wxAuiToolBar::OnPaint
)
815 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
816 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
817 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
818 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
819 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
820 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
821 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
822 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
823 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
824 EVT_MOTION(wxAuiToolBar::OnMotion
)
825 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
826 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
827 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
831 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
833 const wxPoint
& position
,
840 style
| wxBORDER_NONE
)
842 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
844 m_button_height
= -1;
845 m_sizer_element_count
= 0;
846 m_action_pos
= wxPoint(-1,-1);
847 m_action_item
= NULL
;
849 m_art
= new wxAuiDefaultToolBarArt
;
851 m_tool_border_padding
= 3;
852 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
853 m_gripper_sizer_item
= NULL
;
854 m_overflow_sizer_item
= NULL
;
856 m_orientation
= GetOrientation(style
);
857 if (m_orientation
== wxBOTH
)
859 m_orientation
= wxHORIZONTAL
;
861 m_style
= style
| wxBORDER_NONE
;
862 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
863 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
864 m_overflow_state
= 0;
865 SetMargins(5, 5, 2, 2);
866 SetFont(*wxNORMAL_FONT
);
868 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
869 if (style
& wxAUI_TB_HORZ_LAYOUT
)
870 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
871 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
875 wxAuiToolBar::~wxAuiToolBar()
881 void wxAuiToolBar::SetWindowStyleFlag(long style
)
883 GetOrientation(style
); // assert if style is invalid
884 wxCHECK_RET(IsPaneValid(style
),
885 "window settings and pane settings are incompatible");
887 wxControl::SetWindowStyleFlag(style
);
896 if (m_style
& wxAUI_TB_GRIPPER
)
897 m_gripper_visible
= true;
899 m_gripper_visible
= false;
902 if (m_style
& wxAUI_TB_OVERFLOW
)
903 m_overflow_visible
= true;
905 m_overflow_visible
= false;
907 if (style
& wxAUI_TB_HORZ_LAYOUT
)
908 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
910 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
913 long wxAuiToolBar::GetWindowStyleFlag() const
918 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
927 m_art
->SetTextOrientation(m_tool_text_orientation
);
931 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
939 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
940 const wxString
& label
,
941 const wxBitmap
& bitmap
,
942 const wxString
& short_help_string
,
945 return AddTool(tool_id
,
956 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
957 const wxString
& label
,
958 const wxBitmap
& bitmap
,
959 const wxBitmap
& disabled_bitmap
,
961 const wxString
& short_help_string
,
962 const wxString
& long_help_string
,
963 wxObject
* WXUNUSED(client_data
))
965 wxAuiToolBarItem item
;
968 item
.bitmap
= bitmap
;
969 item
.disabled_bitmap
= disabled_bitmap
;
970 item
.short_help
= short_help_string
;
971 item
.long_help
= long_help_string
;
973 item
.dropdown
= false;
974 item
.spacer_pixels
= 0;
975 item
.toolid
= tool_id
;
979 item
.sizer_item
= NULL
;
980 item
.min_size
= wxDefaultSize
;
984 if (item
.toolid
== wxID_ANY
)
985 item
.toolid
= wxNewId();
987 if (!item
.disabled_bitmap
.IsOk())
989 // no disabled bitmap specified, we need to make one
990 if (item
.bitmap
.IsOk())
992 //wxImage img = item.bitmap.ConvertToImage();
993 //wxImage grey_version = img.ConvertToGreyscale();
994 //item.disabled_bitmap = wxBitmap(grey_version);
995 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
999 return &m_items
.Last();
1002 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
1003 const wxString
& label
)
1005 wxAuiToolBarItem item
;
1006 item
.window
= (wxWindow
*)control
;
1008 item
.bitmap
= wxNullBitmap
;
1009 item
.disabled_bitmap
= wxNullBitmap
;
1011 item
.dropdown
= false;
1012 item
.spacer_pixels
= 0;
1013 item
.toolid
= control
->GetId();
1015 item
.proportion
= 0;
1016 item
.kind
= wxITEM_CONTROL
;
1017 item
.sizer_item
= NULL
;
1018 item
.min_size
= control
->GetEffectiveMinSize();
1020 item
.sticky
= false;
1023 return &m_items
.Last();
1026 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1027 const wxString
& label
,
1030 wxSize min_size
= wxDefaultSize
;
1034 wxAuiToolBarItem item
;
1037 item
.bitmap
= wxNullBitmap
;
1038 item
.disabled_bitmap
= wxNullBitmap
;
1040 item
.dropdown
= false;
1041 item
.spacer_pixels
= 0;
1042 item
.toolid
= tool_id
;
1044 item
.proportion
= 0;
1045 item
.kind
= wxITEM_LABEL
;
1046 item
.sizer_item
= NULL
;
1047 item
.min_size
= min_size
;
1049 item
.sticky
= false;
1051 if (item
.toolid
== wxID_ANY
)
1052 item
.toolid
= wxNewId();
1055 return &m_items
.Last();
1058 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1060 wxAuiToolBarItem item
;
1062 item
.label
= wxEmptyString
;
1063 item
.bitmap
= wxNullBitmap
;
1064 item
.disabled_bitmap
= wxNullBitmap
;
1066 item
.dropdown
= false;
1069 item
.proportion
= 0;
1070 item
.kind
= wxITEM_SEPARATOR
;
1071 item
.sizer_item
= NULL
;
1072 item
.min_size
= wxDefaultSize
;
1074 item
.sticky
= false;
1077 return &m_items
.Last();
1080 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1082 wxAuiToolBarItem item
;
1084 item
.label
= wxEmptyString
;
1085 item
.bitmap
= wxNullBitmap
;
1086 item
.disabled_bitmap
= wxNullBitmap
;
1088 item
.dropdown
= false;
1089 item
.spacer_pixels
= pixels
;
1092 item
.proportion
= 0;
1093 item
.kind
= wxITEM_SPACER
;
1094 item
.sizer_item
= NULL
;
1095 item
.min_size
= wxDefaultSize
;
1097 item
.sticky
= false;
1100 return &m_items
.Last();
1103 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1105 wxAuiToolBarItem item
;
1107 item
.label
= wxEmptyString
;
1108 item
.bitmap
= wxNullBitmap
;
1109 item
.disabled_bitmap
= wxNullBitmap
;
1111 item
.dropdown
= false;
1112 item
.spacer_pixels
= 0;
1115 item
.proportion
= proportion
;
1116 item
.kind
= wxITEM_SPACER
;
1117 item
.sizer_item
= NULL
;
1118 item
.min_size
= wxDefaultSize
;
1120 item
.sticky
= false;
1123 return &m_items
.Last();
1126 void wxAuiToolBar::Clear()
1129 m_sizer_element_count
= 0;
1132 bool wxAuiToolBar::DeleteTool(int tool_id
)
1134 int idx
= GetToolIndex(tool_id
);
1135 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1137 m_items
.RemoveAt(idx
);
1145 bool wxAuiToolBar::DeleteByIndex(int idx
)
1147 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1149 m_items
.RemoveAt(idx
);
1158 wxControl
* wxAuiToolBar::FindControl(int id
)
1160 wxWindow
* wnd
= FindWindow(id
);
1161 return (wxControl
*)wnd
;
1164 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1167 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1169 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1170 if (item
.toolid
== tool_id
)
1177 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1180 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1182 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1184 if (!item
.sizer_item
)
1187 wxRect rect
= item
.sizer_item
->GetRect();
1188 if (rect
.Contains(x
,y
))
1190 // if the item doesn't fit on the toolbar, return NULL
1191 if (!GetToolFitsByIndex(i
))
1201 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1204 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1206 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1208 if (!item
.sizer_item
)
1211 wxRect rect
= item
.sizer_item
->GetRect();
1213 // apply tool packing
1215 rect
.width
+= m_tool_packing
;
1217 if (rect
.Contains(x
,y
))
1219 // if the item doesn't fit on the toolbar, return NULL
1220 if (!GetToolFitsByIndex(i
))
1230 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1235 if (idx
>= (int)m_items
.size())
1238 return &(m_items
[idx
]);
1241 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1243 // TODO: wxToolBar compatibility
1246 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1248 // TODO: wxToolBar compatibility
1249 return wxSize(16,15);
1252 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1254 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1258 item
->proportion
= proportion
;
1261 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1263 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1267 return item
->proportion
;
1270 void wxAuiToolBar::SetToolSeparation(int separation
)
1273 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1276 int wxAuiToolBar::GetToolSeparation() const
1279 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1285 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1287 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1291 item
->dropdown
= dropdown
;
1294 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1296 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1300 return item
->dropdown
;
1303 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1305 // ignore separators
1309 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1313 if (item
->sticky
== sticky
)
1316 item
->sticky
= sticky
;
1322 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1324 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1328 return item
->sticky
;
1334 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1336 m_tool_border_padding
= padding
;
1339 int wxAuiToolBar::GetToolBorderPadding() const
1341 return m_tool_border_padding
;
1344 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1346 m_tool_text_orientation
= orientation
;
1350 m_art
->SetTextOrientation(orientation
);
1354 int wxAuiToolBar::GetToolTextOrientation() const
1356 return m_tool_text_orientation
;
1359 void wxAuiToolBar::SetToolPacking(int packing
)
1361 m_tool_packing
= packing
;
1364 int wxAuiToolBar::GetToolPacking() const
1366 return m_tool_packing
;
1370 void wxAuiToolBar::SetOrientation(int orientation
)
1372 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1373 orientation
== wxVERTICAL
,
1374 "invalid orientation value");
1375 if (orientation
!= m_orientation
)
1377 m_orientation
= wxOrientation(orientation
);
1382 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1385 m_left_padding
= left
;
1387 m_right_padding
= right
;
1389 m_top_padding
= top
;
1391 m_bottom_padding
= bottom
;
1394 bool wxAuiToolBar::GetGripperVisible() const
1396 return m_gripper_visible
;
1399 void wxAuiToolBar::SetGripperVisible(bool visible
)
1401 m_gripper_visible
= visible
;
1403 m_style
|= wxAUI_TB_GRIPPER
;
1405 m_style
&= ~wxAUI_TB_GRIPPER
;
1411 bool wxAuiToolBar::GetOverflowVisible() const
1413 return m_overflow_visible
;
1416 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1418 m_overflow_visible
= visible
;
1420 m_style
|= wxAUI_TB_OVERFLOW
;
1422 m_style
&= ~wxAUI_TB_OVERFLOW
;
1426 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1428 bool res
= wxWindow::SetFont(font
);
1432 m_art
->SetFont(font
);
1439 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1441 wxAuiToolBarItem
* former_hover
= NULL
;
1444 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1446 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1447 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1448 former_hover
= &item
;
1449 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1454 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1457 if (former_hover
!= pitem
)
1464 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1466 wxAuiToolBarItem
* former_item
= NULL
;
1469 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1471 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1472 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1473 former_item
= &item
;
1474 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1479 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1480 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1483 if (former_item
!= pitem
)
1490 void wxAuiToolBar::RefreshOverflowState()
1492 if (!m_overflow_sizer_item
)
1494 m_overflow_state
= 0;
1498 int overflow_state
= 0;
1500 wxRect overflow_rect
= GetOverflowRect();
1503 // find out the mouse's current position
1504 wxPoint pt
= ::wxGetMousePosition();
1505 pt
= this->ScreenToClient(pt
);
1507 // find out if the mouse cursor is inside the dropdown rectangle
1508 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1510 if (::wxGetMouseState().LeftIsDown())
1511 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1513 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1516 if (overflow_state
!= m_overflow_state
)
1518 m_overflow_state
= overflow_state
;
1523 m_overflow_state
= overflow_state
;
1526 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1528 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1530 if (tool
&& (tool
->kind
== wxITEM_CHECK
|| tool
->kind
== wxITEM_RADIO
))
1532 if (tool
->kind
== wxITEM_RADIO
)
1535 idx
= GetToolIndex(tool_id
);
1536 count
= (int)m_items
.GetCount();
1538 if (idx
>= 0 && idx
< count
)
1540 for (i
= idx
; i
< count
; ++i
)
1542 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1544 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1546 for (i
= idx
; i
> 0; i
--)
1548 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1550 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1554 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1556 else if (tool
->kind
== wxITEM_CHECK
)
1559 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1561 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1566 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1568 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1572 if ( (tool
->kind
!= wxITEM_CHECK
) && (tool
->kind
!= wxITEM_RADIO
) )
1575 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1581 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1583 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1588 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1590 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1594 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1596 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1599 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1604 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1606 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1607 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1609 return wxEmptyString
;
1614 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1616 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1619 tool
->label
= label
;
1623 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1625 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1626 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1628 return wxNullBitmap
;
1630 return tool
->bitmap
;
1633 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1635 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1638 tool
->bitmap
= bitmap
;
1642 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1644 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1645 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1647 return wxEmptyString
;
1649 return tool
->short_help
;
1652 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1654 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1657 tool
->short_help
= help_string
;
1661 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1663 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1664 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1666 return wxEmptyString
;
1668 return tool
->long_help
;
1671 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1673 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1676 tool
->long_help
= help_string
;
1680 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1681 const wxAuiToolBarItemArray
& append
)
1683 m_custom_overflow_prepend
= prepend
;
1684 m_custom_overflow_append
= append
;
1687 // get size of hint rectangle for a particular dock location
1688 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1690 switch (dock_direction
)
1692 case wxAUI_DOCK_TOP
:
1693 case wxAUI_DOCK_BOTTOM
:
1694 return m_horzHintSize
;
1695 case wxAUI_DOCK_RIGHT
:
1696 case wxAUI_DOCK_LEFT
:
1697 return m_vertHintSize
;
1699 wxCHECK_MSG(false, wxDefaultSize
, "invalid dock location value");
1703 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1705 return IsPaneValid(m_style
, pane
);
1708 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1710 if (style
& wxAUI_TB_HORIZONTAL
)
1712 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1717 else if (style
& wxAUI_TB_VERTICAL
)
1719 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1727 bool wxAuiToolBar::IsPaneValid(long style
) const
1729 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1732 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1737 void wxAuiToolBar::SetArtFlags() const
1739 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1740 if (m_orientation
== wxVERTICAL
)
1742 artflags
|= wxAUI_TB_VERTICAL
;
1744 m_art
->SetFlags(artflags
);
1747 size_t wxAuiToolBar::GetToolCount() const
1749 return m_items
.size();
1752 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1754 // this will prevent us from returning the index of the
1755 // first separator in the toolbar since its id is equal to -1
1759 size_t i
, count
= m_items
.GetCount();
1760 for (i
= 0; i
< count
; ++i
)
1762 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1763 if (item
.toolid
== tool_id
)
1770 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1772 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1775 if (!m_items
[tool_idx
].sizer_item
)
1779 GetClientSize(&cli_w
, &cli_h
);
1781 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1783 if (m_orientation
== wxVERTICAL
)
1785 // take the dropdown size into account
1786 if (m_overflow_visible
)
1787 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1789 if (rect
.y
+rect
.height
< cli_h
)
1794 // take the dropdown size into account
1795 if (m_overflow_visible
)
1796 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1798 if (rect
.x
+rect
.width
< cli_w
)
1806 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1808 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1811 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1813 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1814 if (tool
&& tool
->sizer_item
)
1816 return tool
->sizer_item
->GetRect();
1822 bool wxAuiToolBar::GetToolBarFits() const
1824 if (m_items
.GetCount() == 0)
1826 // empty toolbar always 'fits'
1830 // entire toolbar content fits if the last tool fits
1831 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1834 bool wxAuiToolBar::Realize()
1836 wxClientDC
dc(this);
1840 // calculate hint sizes for both horizontal and vertical
1841 // in the order that leaves toolbar in correct final state
1842 bool retval
= false;
1843 if (m_orientation
== wxHORIZONTAL
)
1845 if (RealizeHelper(dc
, false))
1847 m_vertHintSize
= GetSize();
1848 if (RealizeHelper(dc
, true))
1850 m_horzHintSize
= GetSize();
1857 if (RealizeHelper(dc
, true))
1859 m_horzHintSize
= GetSize();
1860 if (RealizeHelper(dc
, false))
1862 m_vertHintSize
= GetSize();
1872 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1874 // create the new sizer to add toolbar elements to
1875 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1878 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1879 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1880 if (gripper_size
> 0 && m_gripper_visible
)
1883 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1885 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1889 m_gripper_sizer_item
= NULL
;
1892 // add "left" padding
1893 if (m_left_padding
> 0)
1896 sizer
->Add(m_left_padding
, 1);
1898 sizer
->Add(1, m_left_padding
);
1902 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1904 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1905 wxSizerItem
* sizer_item
= NULL
;
1911 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1912 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1913 size
.y
+ (m_tool_border_padding
*2),
1918 sizer
->AddSpacer(m_tool_packing
);
1928 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1929 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1930 size
.y
+ (m_tool_border_padding
*2),
1936 sizer
->AddSpacer(m_tool_packing
);
1942 case wxITEM_SEPARATOR
:
1945 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1947 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1952 sizer
->AddSpacer(m_tool_packing
);
1959 if (item
.proportion
> 0)
1960 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1962 sizer_item
= sizer
->Add(item
.spacer_pixels
, 1);
1965 case wxITEM_CONTROL
:
1967 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1968 wxSizerItem
* ctrl_sizer_item
;
1970 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1971 vert_sizer
->AddStretchSpacer(1);
1972 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1973 vert_sizer
->AddStretchSpacer(1);
1974 if ( (m_style
& wxAUI_TB_TEXT
) &&
1975 m_tool_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1976 !item
.GetLabel().empty() )
1978 wxSize s
= GetLabelSize(item
.GetLabel());
1979 vert_sizer
->Add(1, s
.y
);
1983 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1985 wxSize min_size
= item
.min_size
;
1988 // proportional items will disappear from the toolbar if
1989 // their min width is not set to something really small
1990 if (item
.proportion
!= 0)
1995 if (min_size
.IsFullySpecified())
1997 sizer_item
->SetMinSize(min_size
);
1998 ctrl_sizer_item
->SetMinSize(min_size
);
2004 sizer
->AddSpacer(m_tool_packing
);
2009 item
.sizer_item
= sizer_item
;
2012 // add "right" padding
2013 if (m_right_padding
> 0)
2016 sizer
->Add(m_right_padding
, 1);
2018 sizer
->Add(1, m_right_padding
);
2021 // add drop down area
2022 m_overflow_sizer_item
= NULL
;
2024 if (m_style
& wxAUI_TB_OVERFLOW
)
2026 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2027 if (overflow_size
> 0 && m_overflow_visible
)
2030 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2032 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2036 m_overflow_sizer_item
= NULL
;
2041 // the outside sizer helps us apply the "top" and "bottom" padding
2042 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2044 // add "top" padding
2045 if (m_top_padding
> 0)
2048 outside_sizer
->Add(1, m_top_padding
);
2050 outside_sizer
->Add(m_top_padding
, 1);
2053 // add the sizer that contains all of the toolbar elements
2054 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2056 // add "bottom" padding
2057 if (m_bottom_padding
> 0)
2060 outside_sizer
->Add(1, m_bottom_padding
);
2062 outside_sizer
->Add(m_bottom_padding
, 1);
2065 delete m_sizer
; // remove old sizer
2066 m_sizer
= outside_sizer
;
2068 // calculate the rock-bottom minimum size
2069 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2071 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2072 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2073 item
.sizer_item
->SetMinSize(0,0);
2076 m_absolute_min_size
= m_sizer
->GetMinSize();
2078 // reset the min sizes to what they were
2079 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2081 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2082 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2083 item
.sizer_item
->SetMinSize(item
.min_size
);
2087 wxSize size
= m_sizer
->GetMinSize();
2088 m_minWidth
= size
.x
;
2089 m_minHeight
= size
.y
;
2091 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2093 wxSize cur_size
= GetClientSize();
2094 wxSize new_size
= GetMinSize();
2095 if (new_size
!= cur_size
)
2097 SetClientSize(new_size
);
2101 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2106 wxSize cur_size
= GetClientSize();
2107 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2113 int wxAuiToolBar::GetOverflowState() const
2115 return m_overflow_state
;
2118 wxRect
wxAuiToolBar::GetOverflowRect() const
2120 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2121 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
2122 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2124 if (m_orientation
== wxVERTICAL
)
2126 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2127 overflow_rect
.x
= 0;
2128 overflow_rect
.width
= cli_rect
.width
;
2129 overflow_rect
.height
= overflow_size
;
2133 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2134 overflow_rect
.y
= 0;
2135 overflow_rect
.width
= overflow_size
;
2136 overflow_rect
.height
= cli_rect
.height
;
2139 return overflow_rect
;
2142 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2144 wxClientDC
dc(this);
2147 int text_width
= 0, text_height
= 0;
2151 // get the text height
2152 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
2154 // get the text width
2155 dc
.GetTextExtent(label
, &text_width
, &ty
);
2157 return wxSize(text_width
, text_height
);
2161 void wxAuiToolBar::DoIdleUpdate()
2163 wxEvtHandler
* handler
= GetEventHandler();
2165 bool need_refresh
= false;
2168 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2170 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2172 if (item
.toolid
== -1)
2175 wxUpdateUIEvent
evt(item
.toolid
);
2176 evt
.SetEventObject(this);
2178 if (handler
->ProcessEvent(evt
))
2180 if (evt
.GetSetEnabled())
2184 is_enabled
= item
.window
->IsEnabled();
2186 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2188 bool new_enabled
= evt
.GetEnabled();
2189 if (new_enabled
!= is_enabled
)
2193 item
.window
->Enable(new_enabled
);
2198 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2200 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2202 need_refresh
= true;
2206 if (evt
.GetSetChecked())
2208 // make sure we aren't checking an item that can't be
2209 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2212 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2213 bool new_checked
= evt
.GetChecked();
2215 if (new_checked
!= is_checked
)
2218 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2220 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2222 need_refresh
= true;
2237 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2240 GetClientSize(&x
, &y
);
2242 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2243 ((y
> x
) && m_absolute_min_size
.y
> y
))
2245 // hide all flexible items
2247 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2249 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2250 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2252 item
.sizer_item
->Show(false);
2253 item
.sizer_item
->SetProportion(0);
2259 // show all flexible items
2261 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2263 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2264 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2266 item
.sizer_item
->Show(true);
2267 item
.sizer_item
->SetProportion(item
.proportion
);
2272 m_sizer
->SetDimension(0, 0, x
, y
);
2277 // idle events aren't sent while user is resizing frame (why?),
2278 // but resizing toolbar here causes havoc,
2279 // so force idle handler to run after size handling complete
2280 QueueEvent(new wxIdleEvent
);
2285 void wxAuiToolBar::DoSetSize(int x
,
2291 wxSize parent_size
= GetParent()->GetClientSize();
2292 if (x
+ width
> parent_size
.x
)
2293 width
= wxMax(0, parent_size
.x
- x
);
2294 if (y
+ height
> parent_size
.y
)
2295 height
= wxMax(0, parent_size
.y
- y
);
2297 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2301 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2303 // if orientation doesn't match dock, fix it
2304 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2307 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2308 // pane state member is public, so it might have been changed
2309 // without going through wxPaneInfo::SetFlag() check
2310 bool ok
= pane
.IsOk();
2311 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2312 "window settings and pane settings are incompatible");
2315 wxOrientation newOrientation
= m_orientation
;
2316 if (pane
.IsDocked())
2318 switch (pane
.dock_direction
)
2320 case wxAUI_DOCK_TOP
:
2321 case wxAUI_DOCK_BOTTOM
:
2322 newOrientation
= wxHORIZONTAL
;
2324 case wxAUI_DOCK_LEFT
:
2325 case wxAUI_DOCK_RIGHT
:
2326 newOrientation
= wxVERTICAL
;
2329 wxFAIL_MSG("invalid dock location value");
2332 else if (pane
.IsResizable() &&
2333 GetOrientation(m_style
) == wxBOTH
)
2335 // changing orientation in OnSize causes havoc
2337 GetClientSize(&x
, &y
);
2341 newOrientation
= wxHORIZONTAL
;
2345 newOrientation
= wxVERTICAL
;
2348 if (newOrientation
!= m_orientation
)
2350 SetOrientation(newOrientation
);
2352 if (newOrientation
== wxHORIZONTAL
)
2354 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2358 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2360 if (pane
.IsDocked())
2362 pane
.floating_size
= wxDefaultSize
;
2366 SetSize(GetParent()->GetClientSize());
2377 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2379 wxAutoBufferedPaintDC
dc(this);
2380 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2383 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2386 m_art
->DrawBackground(dc
, this, cli_rect
);
2388 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2389 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2391 // paint the gripper
2392 if (gripper_size
> 0 && m_gripper_sizer_item
)
2394 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2396 gripper_rect
.width
= gripper_size
;
2398 gripper_rect
.height
= gripper_size
;
2399 m_art
->DrawGripper(dc
, this, gripper_rect
);
2402 // calculated how far we can draw items
2405 last_extent
= cli_rect
.width
;
2407 last_extent
= cli_rect
.height
;
2408 if (m_overflow_visible
)
2409 last_extent
-= dropdown_size
;
2411 // paint each individual tool
2412 size_t i
, count
= m_items
.GetCount();
2413 for (i
= 0; i
< count
; ++i
)
2415 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2417 if (!item
.sizer_item
)
2420 wxRect item_rect
= item
.sizer_item
->GetRect();
2423 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2424 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2429 if (item
.kind
== wxITEM_SEPARATOR
)
2432 m_art
->DrawSeparator(dc
, this, item_rect
);
2434 else if (item
.kind
== wxITEM_LABEL
)
2436 // draw a text label only
2437 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2439 else if (item
.kind
== wxITEM_NORMAL
)
2441 // draw a regular button or dropdown button
2443 m_art
->DrawButton(dc
, this, item
, item_rect
);
2445 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2447 else if (item
.kind
== wxITEM_CHECK
)
2449 // draw a toggle button
2450 m_art
->DrawButton(dc
, this, item
, item_rect
);
2452 else if (item
.kind
== wxITEM_RADIO
)
2454 // draw a toggle button
2455 m_art
->DrawButton(dc
, this, item
, item_rect
);
2457 else if (item
.kind
== wxITEM_CONTROL
)
2459 // draw the control's label
2460 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2463 // fire a signal to see if the item wants to be custom-rendered
2464 OnCustomRender(dc
, item
, item_rect
);
2467 // paint the overflow button
2468 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2470 wxRect dropdown_rect
= GetOverflowRect();
2471 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2475 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2480 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2482 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2484 if (m_gripper_sizer_item
)
2486 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2487 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2490 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2494 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2495 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2497 // gripper was clicked
2498 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2503 if (m_overflow_sizer_item
)
2505 wxRect overflow_rect
= GetOverflowRect();
2508 m_overflow_visible
&&
2509 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2511 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2512 e
.SetEventObject(this);
2514 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2515 bool processed
= GetEventHandler()->ProcessEvent(e
);
2524 wxAuiToolBarItemArray overflow_items
;
2527 // add custom overflow prepend items, if any
2528 count
= m_custom_overflow_prepend
.GetCount();
2529 for (i
= 0; i
< count
; ++i
)
2530 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2532 // only show items that don't fit in the dropdown
2533 count
= m_items
.GetCount();
2534 for (i
= 0; i
< count
; ++i
)
2536 if (!GetToolFitsByIndex(i
))
2537 overflow_items
.Add(m_items
[i
]);
2540 // add custom overflow append items, if any
2541 count
= m_custom_overflow_append
.GetCount();
2542 for (i
= 0; i
< count
; ++i
)
2543 overflow_items
.Add(m_custom_overflow_append
[i
]);
2545 int res
= m_art
->ShowDropDown(this, overflow_items
);
2546 m_overflow_state
= 0;
2550 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2551 e
.SetEventObject(this);
2552 GetParent()->GetEventHandler()->ProcessEvent(e
);
2561 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2562 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2566 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2568 m_action_pos
= wxPoint(-1,-1);
2569 m_action_item
= NULL
;
2575 // fire the tool dropdown event
2576 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->toolid
);
2577 e
.SetEventObject(this);
2578 e
.SetToolId(m_action_item
->toolid
);
2580 int mouse_x
= evt
.GetX();
2581 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2582 const bool dropDownHit
= m_action_item
->dropdown
&&
2583 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2584 mouse_x
< (rect
.x
+rect
.width
);
2585 e
.SetDropDownClicked(dropDownHit
);
2587 e
.SetClickPoint(evt
.GetPosition());
2588 e
.SetItemRect(rect
);
2590 // we only set the 'pressed button' state if we hit the actual button
2591 // and not just the drop-down
2592 SetPressedItem(dropDownHit
? 0 : m_action_item
);
2596 m_action_pos
= wxPoint(-1,-1);
2597 m_action_item
= NULL
;
2600 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2607 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2612 SetPressedItem(NULL
);
2614 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2615 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2617 SetHoverItem(hit_item
);
2622 // TODO: it would make sense to send out an 'END_DRAG' event here,
2623 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2626 // OnCaptureLost() will be called now and this will reset all our state
2627 // tracking variables
2632 wxAuiToolBarItem
* hit_item
;
2633 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2635 if (m_action_item
&& hit_item
== m_action_item
)
2639 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->toolid
);
2640 e
.SetEventObject(this);
2642 if (hit_item
->kind
== wxITEM_CHECK
|| hit_item
->kind
== wxITEM_RADIO
)
2644 const bool toggle
= !(m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
);
2646 ToggleTool(m_action_item
->toolid
, toggle
);
2648 // repaint immediately
2655 // we have to release the mouse *before* sending the event, because
2656 // we don't know what a handler might do. It could open up a popup
2657 // menu for example and that would make us lose our capture anyway.
2661 GetEventHandler()->ProcessEvent(e
);
2669 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2671 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2673 if (m_gripper_sizer_item
)
2675 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2676 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2680 if (m_overflow_sizer_item
)
2682 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2683 if (dropdown_size
> 0 &&
2684 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2686 evt
.m_y
< cli_rect
.height
&&
2693 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2694 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2696 if (m_action_item
&& m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2698 m_action_pos
= wxPoint(-1,-1);
2699 m_action_item
= NULL
;
2706 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2708 wxAuiToolBarItem
* hit_item
;
2709 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2711 if (m_action_item
&& hit_item
== m_action_item
)
2713 if (hit_item
->kind
== wxITEM_NORMAL
)
2715 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->toolid
);
2716 e
.SetEventObject(this);
2717 e
.SetToolId(m_action_item
->toolid
);
2718 e
.SetClickPoint(m_action_pos
);
2719 GetEventHandler()->ProcessEvent(e
);
2725 // right-clicked on the invalid area of the toolbar
2726 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2727 e
.SetEventObject(this);
2729 e
.SetClickPoint(m_action_pos
);
2730 GetEventHandler()->ProcessEvent(e
);
2734 // reset member variables
2735 m_action_pos
= wxPoint(-1,-1);
2736 m_action_item
= NULL
;
2739 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2741 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2743 if (m_gripper_sizer_item
)
2745 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2746 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2750 if (m_overflow_sizer_item
)
2752 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2753 if (dropdown_size
> 0 &&
2754 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2756 evt
.m_y
< cli_rect
.height
&&
2763 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2764 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2768 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2770 m_action_pos
= wxPoint(-1,-1);
2771 m_action_item
= NULL
;
2779 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2781 wxAuiToolBarItem
* hit_item
;
2782 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2784 if (m_action_item
&& hit_item
== m_action_item
)
2786 if (hit_item
->kind
== wxITEM_NORMAL
)
2788 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->toolid
);
2789 e
.SetEventObject(this);
2790 e
.SetToolId(m_action_item
->toolid
);
2791 e
.SetClickPoint(m_action_pos
);
2792 GetEventHandler()->ProcessEvent(e
);
2797 // reset member variables
2798 m_action_pos
= wxPoint(-1,-1);
2799 m_action_item
= NULL
;
2802 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2804 const bool button_pressed
= HasCapture();
2806 // start a drag event
2807 if (!m_dragging
&& button_pressed
&&
2808 abs(evt
.GetX() - m_action_pos
.x
) + abs(evt
.GetY() - m_action_pos
.y
) > 5)
2810 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2811 // event sent sometime in the future (see OnLeftUp())
2812 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2813 e
.SetEventObject(this);
2814 e
.SetToolId(m_action_item
->toolid
);
2815 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2823 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2826 // if we have a button pressed we want it to be shown in 'depressed'
2827 // state unless we move the mouse outside the button, then we want it
2828 // to show as just 'highlighted'
2829 if (hit_item
== m_action_item
)
2830 SetPressedItem(m_action_item
);
2833 SetPressedItem(NULL
);
2834 SetHoverItem(m_action_item
);
2839 if (hit_item
&& (hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2842 SetHoverItem(hit_item
);
2844 // tooltips handling
2845 wxAuiToolBarItem
* packing_hit_item
;
2846 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2847 if (packing_hit_item
)
2849 if (packing_hit_item
!= m_tip_item
)
2851 m_tip_item
= packing_hit_item
;
2853 if ( !packing_hit_item
->short_help
.empty() )
2854 SetToolTip(packing_hit_item
->short_help
);
2865 // figure out the dropdown button state (are we hovering or pressing it?)
2866 RefreshOverflowState();
2870 void wxAuiToolBar::DoResetMouseState()
2872 RefreshOverflowState();
2874 SetPressedItem(NULL
);
2878 // we have to reset those here, because the mouse-up handlers which do
2879 // it usually won't be called if we let go of a mouse button while we
2880 // are outside of the window
2881 m_action_pos
= wxPoint(-1,-1);
2882 m_action_item
= NULL
;
2885 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2893 DoResetMouseState();
2896 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2900 DoResetMouseState();
2903 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2905 wxCursor cursor
= wxNullCursor
;
2907 if (m_gripper_sizer_item
)
2909 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2910 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2912 cursor
= wxCursor(wxCURSOR_SIZING
);
2916 evt
.SetCursor(cursor
);