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 baseColour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
78 wxColor baseColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
81 // the baseColour is too pale to use as our base colour,
82 // so darken it a bit --
83 if ((255-baseColour
.Red()) +
84 (255-baseColour
.Green()) +
85 (255-baseColour
.Blue()) < 60)
87 baseColour
= baseColour
.ChangeLightness(92);
95 class ToolbarCommandCapture
: public wxEvtHandler
99 ToolbarCommandCapture() { m_lastId
= 0; }
100 int GetCommandId() const { return m_lastId
; }
102 bool ProcessEvent(wxEvent
& evt
)
104 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
106 m_lastId
= evt
.GetId();
110 if (GetNextHandler())
111 return GetNextHandler()->ProcessEvent(evt
);
122 static const unsigned char
123 DISABLED_TEXT_GREY_HUE
= wxColour::AlphaBlend(0, 255, 0.4);
124 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
125 DISABLED_TEXT_GREY_HUE
,
126 DISABLED_TEXT_GREY_HUE
);
128 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
130 m_baseColour
= GetBaseColor();
133 m_textOrientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
134 m_highlightColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
140 wxColor darker1Colour
= m_baseColour
.ChangeLightness(85);
141 wxColor darker2Colour
= m_baseColour
.ChangeLightness(75);
142 wxColor darker3Colour
= m_baseColour
.ChangeLightness(60);
143 wxColor darker4Colour
= m_baseColour
.ChangeLightness(50);
144 wxColor darker5Colour
= m_baseColour
.ChangeLightness(40);
146 m_gripperPen1
= wxPen(darker5Colour
);
147 m_gripperPen2
= wxPen(darker3Colour
);
148 m_gripperPen3
= *wxWHITE_PEN
;
150 static const unsigned char buttonDropdownBits
[] = { 0xe0, 0xf1, 0xfb };
151 static const unsigned char overflowBits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
153 m_buttonDropDownBmp
= wxAuiBitmapFromBits(buttonDropdownBits
, 5, 3,
155 m_disabledButtonDropDownBmp
= wxAuiBitmapFromBits(
156 buttonDropdownBits
, 5, 3,
157 wxColor(128,128,128));
158 m_overflowBmp
= wxAuiBitmapFromBits(overflowBits
, 7, 6, *wxBLACK
);
159 m_disabledOverflowBmp
= wxAuiBitmapFromBits(overflowBits
, 7, 6, wxColor(128,128,128));
161 m_font
= *wxNORMAL_FONT
;
164 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
166 m_font
= *wxNORMAL_FONT
;
170 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
172 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
175 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
180 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
185 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
187 m_textOrientation
= orientation
;
190 unsigned int wxAuiDefaultToolBarArt::GetFlags()
195 wxFont
wxAuiDefaultToolBarArt::GetFont()
200 int wxAuiDefaultToolBarArt::GetTextOrientation()
202 return m_textOrientation
;
205 void wxAuiDefaultToolBarArt::DrawBackground(
207 wxWindow
* WXUNUSED(wnd
),
212 wxColour startColour
= m_baseColour
.ChangeLightness(150);
213 wxColour endColour
= m_baseColour
.ChangeLightness(90);
214 dc
.GradientFillLinear(rect
, startColour
, endColour
, wxSOUTH
);
217 void wxAuiDefaultToolBarArt::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 textWidth
= 0, textHeight
= 0;
229 dc
.GetTextExtent(wxT("ABCDHgj"), &textWidth
, &textHeight
);
231 // set the clipping region
232 wxRect clipRect
= rect
;
234 dc
.SetClippingRegion(clipRect
);
238 textY
= rect
.y
+ (rect
.height
-textHeight
)/2;
239 dc
.DrawText(item
.GetLabel(), textX
, textY
);
240 dc
.DestroyClippingRegion();
244 void wxAuiDefaultToolBarArt::DrawButton(
246 wxWindow
* WXUNUSED(wnd
),
247 const wxAuiToolBarItem
& item
,
250 int textWidth
= 0, textHeight
= 0;
252 if (m_flags
& wxAUI_TB_TEXT
)
258 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
260 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
263 int bmpX
= 0, bmpY
= 0;
264 int textX
= 0, textY
= 0;
266 if (m_textOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
270 (item
.GetBitmap().GetWidth()/2);
273 ((rect
.height
-textHeight
)/2) -
274 (item
.GetBitmap().GetHeight()/2);
276 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
277 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
279 else if (m_textOrientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
285 (item
.GetBitmap().GetHeight()/2);
287 textX
= bmpX
+ 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_highlightColour
));
299 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(150)));
300 dc
.DrawRectangle(rect
);
302 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
304 dc
.SetPen(wxPen(m_highlightColour
));
305 dc
.SetBrush(wxBrush(m_highlightColour
.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_highlightColour
.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_highlightColour
));
319 dc
.SetBrush(wxBrush(m_highlightColour
.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
, bmpX
, bmpY
, 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(), textX
, textY
);
345 void wxAuiDefaultToolBarArt::DrawDropDownButton(
347 wxWindow
* WXUNUSED(wnd
),
348 const wxAuiToolBarItem
& item
,
351 int textWidth
= 0, textHeight
= 0, textX
= 0, textY
= 0;
352 int bmpX
= 0, bmpY
= 0, dropBmpX
= 0, dropBmpY
= 0;
354 wxRect buttonRect
= wxRect(rect
.x
,
356 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
358 wxRect dropDownRect
= 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
, &textHeight
);
374 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
379 dropBmpX
= dropDownRect
.x
+
380 (dropDownRect
.width
/2) -
381 (m_buttonDropDownBmp
.GetWidth()/2);
382 dropBmpY
= dropDownRect
.y
+
383 (dropDownRect
.height
/2) -
384 (m_buttonDropDownBmp
.GetHeight()/2);
387 if (m_textOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
389 bmpX
= buttonRect
.x
+
390 (buttonRect
.width
/2) -
391 (item
.GetBitmap().GetWidth()/2);
392 bmpY
= buttonRect
.y
+
393 ((buttonRect
.height
-textHeight
)/2) -
394 (item
.GetBitmap().GetHeight()/2);
396 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
397 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
399 else if (m_textOrientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
405 (item
.GetBitmap().GetHeight()/2);
407 textX
= bmpX
+ 3 + item
.GetBitmap().GetWidth();
414 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
416 dc
.SetPen(wxPen(m_highlightColour
));
417 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(140)));
418 dc
.DrawRectangle(buttonRect
);
420 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
421 dc
.DrawRectangle(dropDownRect
);
423 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
426 dc
.SetPen(wxPen(m_highlightColour
));
427 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
428 dc
.DrawRectangle(buttonRect
);
429 dc
.DrawRectangle(dropDownRect
);
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.m_
435 dc
.SetPen(wxPen(m_highlightColour
));
436 dc
.SetBrush(wxBrush(m_highlightColour
.ChangeLightness(170)));
437 dc
.DrawRectangle(buttonRect
);
438 dc
.DrawRectangle(dropDownRect
);
443 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
445 bmp
= item
.GetDisabledBitmap();
446 dropbmp
= m_disabledButtonDropDownBmp
;
450 bmp
= item
.GetBitmap();
451 dropbmp
= m_buttonDropDownBmp
;
457 dc
.DrawBitmap(bmp
, bmpX
, bmpY
, true);
458 dc
.DrawBitmap(dropbmp
, dropBmpX
, dropBmpY
, 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(), textX
, textY
);
471 void wxAuiDefaultToolBarArt::DrawControlLabel(
473 wxWindow
* WXUNUSED(wnd
),
474 const wxAuiToolBarItem
& item
,
477 if (!(m_flags
& wxAUI_TB_TEXT
))
480 if (m_textOrientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
483 int textX
= 0, textY
= 0;
484 int textWidth
= 0, textHeight
= 0;
489 if (m_flags
& wxAUI_TB_TEXT
)
491 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
495 dc
.GetTextExtent(item
.GetLabel(), &textWidth
, &ty
);
497 // don't draw the label if it is wider than the item width
498 if (textWidth
> rect
.width
)
501 // set the label's text color
502 dc
.SetTextForeground(*wxBLACK
);
504 textX
= rect
.x
+ (rect
.width
/2) - (textWidth
/2) + 1;
505 textY
= rect
.y
+ rect
.height
- textHeight
- 1;
507 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
509 dc
.DrawText(item
.GetLabel(), textX
, textY
);
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_textOrientation
== 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_textOrientation
== 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 startColour
= m_baseColour
.ChangeLightness(80);
614 wxColour endColour
= m_baseColour
.ChangeLightness(80);
615 dc
.GradientFillLinear(rect
, startColour
, endColour
, 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_gripperPen1
);
644 dc
.SetPen(m_gripperPen2
);
645 dc
.DrawPoint(x
, y
+1);
646 dc
.DrawPoint(x
+1, y
);
647 dc
.SetPen(m_gripperPen3
);
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 wxColor light_gray_bg
= m_highlightColour
.ChangeLightness(170);
667 if (m_flags
& wxAUI_TB_VERTICAL
)
669 dc
.SetPen(wxPen(m_highlightColour
));
670 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
671 dc
.SetPen(wxPen(light_gray_bg
));
672 dc
.SetBrush(wxBrush(light_gray_bg
));
673 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
677 dc
.SetPen(wxPen(m_highlightColour
));
678 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
679 dc
.SetPen(wxPen(light_gray_bg
));
680 dc
.SetBrush(wxBrush(light_gray_bg
));
681 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
685 int x
= rect
.x
+1+(rect
.width
-m_overflowBmp
.GetWidth())/2;
686 int y
= rect
.y
+1+(rect
.height
-m_overflowBmp
.GetHeight())/2;
687 dc
.DrawBitmap(m_overflowBmp
, x
, y
, true);
690 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
694 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separatorSize
;
695 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripperSize
;
696 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflowSize
;
701 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
705 case wxAUI_TBART_SEPARATOR_SIZE
: m_separatorSize
= size
; break;
706 case wxAUI_TBART_GRIPPER_SIZE
: m_gripperSize
= size
; break;
707 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflowSize
= size
; break;
711 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
712 const wxAuiToolBarItemArray
& items
)
716 size_t items_added
= 0;
718 size_t i
, count
= items
.GetCount();
719 for (i
= 0; i
< count
; ++i
)
721 wxAuiToolBarItem
& item
= items
.Item(i
);
723 if (item
.GetKind() == wxITEM_NORMAL
)
725 wxString text
= item
.GetShortHelp();
727 text
= item
.GetLabel();
732 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
734 m
->SetBitmap(item
.GetBitmap());
738 else if (item
.GetKind() == wxITEM_SEPARATOR
)
741 menuPopup
.AppendSeparator();
745 // find out where to put the popup menu of window items
746 wxPoint pt
= ::wxGetMousePosition();
747 pt
= wnd
->ScreenToClient(pt
);
749 // find out the screen coordinate at the bottom of the tab ctrl
750 wxRect cli_rect
= wnd
->GetClientRect();
751 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
753 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
754 wnd
->PushEventHandler(cc
);
755 wnd
->PopupMenu(&menuPopup
, pt
);
756 int command
= cc
->GetCommandId();
757 wnd
->PopEventHandler(true);
765 static wxOrientation
GetOrientation(long& style
)
767 switch (style
& wxAUI_ORIENTATION_MASK
)
769 case wxAUI_TB_HORIZONTAL
:
771 case wxAUI_TB_VERTICAL
:
774 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
781 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
782 EVT_SIZE(wxAuiToolBar::OnSize
)
783 EVT_IDLE(wxAuiToolBar::OnIdle
)
784 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
785 EVT_PAINT(wxAuiToolBar::OnPaint
)
786 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
787 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
788 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
789 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
790 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
791 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
792 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
793 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
794 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
795 EVT_MOTION(wxAuiToolBar::OnMotion
)
796 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
797 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
798 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
801 void wxAuiToolBar::Init()
803 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
806 m_sizerElementCount
= 0;
807 m_actionPos
= wxPoint(-1,-1);
810 m_art
= new wxAuiDefaultToolBarArt
;
812 m_toolBorderPadding
= 3;
813 m_toolTextOrientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
814 m_gripperSizerItem
= NULL
;
815 m_overflowSizerItem
= NULL
;
817 m_gripperVisible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
818 m_overflowVisible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
822 bool wxAuiToolBar::Create(wxWindow
* parent
,
828 style
= style
|wxBORDER_NONE
;
830 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
834 m_orientation
= GetOrientation(style
);
835 if (m_orientation
== wxBOTH
)
837 m_orientation
= wxHORIZONTAL
;
840 SetMargins(5, 5, 2, 2);
841 SetFont(*wxNORMAL_FONT
);
843 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
844 if (style
& wxAUI_TB_HORZ_LAYOUT
)
845 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
846 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
851 wxAuiToolBar::~wxAuiToolBar()
857 void wxAuiToolBar::SetWindowStyleFlag(long style
)
859 GetOrientation(style
); // assert if style is invalid
860 wxCHECK_RET(IsPaneValid(style
),
861 "window settings and pane settings are incompatible");
863 wxControl::SetWindowStyleFlag(style
);
872 if (m_style
& wxAUI_TB_GRIPPER
)
873 m_gripperVisible
= true;
875 m_gripperVisible
= false;
878 if (m_style
& wxAUI_TB_OVERFLOW
)
879 m_overflowVisible
= true;
881 m_overflowVisible
= false;
883 if (style
& wxAUI_TB_HORZ_LAYOUT
)
884 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
886 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
889 long wxAuiToolBar::GetWindowStyleFlag() const
894 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
903 m_art
->SetTextOrientation(m_toolTextOrientation
);
907 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
915 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
916 const wxString
& label
,
917 const wxBitmap
& bitmap
,
918 const wxString
& shortHelp_string
,
921 return AddTool(tool_id
,
932 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
933 const wxString
& label
,
934 const wxBitmap
& bitmap
,
935 const wxBitmap
& disabledBitmap
,
937 const wxString
& shortHelpString
,
938 const wxString
& longHelpString
,
939 wxObject
* WXUNUSED(client_data
))
941 wxAuiToolBarItem item
;
942 item
.m_window
= NULL
;
943 item
.m_label
= label
;
944 item
.m_bitmap
= bitmap
;
945 item
.m_disabledBitmap
= disabledBitmap
;
946 item
.m_shortHelp
= shortHelpString
;
947 item
.m_longHelp
= longHelpString
;
948 item
.m_active
= true;
949 item
.m_dropDown
= false;
950 item
.m_spacerPixels
= 0;
951 item
.m_toolId
= tool_id
;
953 item
.m_proportion
= 0;
955 item
.m_sizerItem
= NULL
;
956 item
.m_minSize
= wxDefaultSize
;
958 item
.m_sticky
= false;
960 if (item
.m_toolId
== wxID_ANY
)
961 item
.m_toolId
= wxNewId();
963 if (!item
.m_disabledBitmap
.IsOk())
965 // no disabled bitmap specified, we need to make one
966 if (item
.m_bitmap
.IsOk())
968 item
.m_disabledBitmap
= item
.m_bitmap
.ConvertToDisabled();
972 return &m_items
.Last();
975 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
976 const wxString
& label
)
978 wxAuiToolBarItem item
;
979 item
.m_window
= (wxWindow
*)control
;
980 item
.m_label
= label
;
981 item
.m_bitmap
= wxNullBitmap
;
982 item
.m_disabledBitmap
= wxNullBitmap
;
983 item
.m_active
= true;
984 item
.m_dropDown
= false;
985 item
.m_spacerPixels
= 0;
986 item
.m_toolId
= control
->GetId();
988 item
.m_proportion
= 0;
989 item
.m_kind
= wxITEM_CONTROL
;
990 item
.m_sizerItem
= NULL
;
991 item
.m_minSize
= control
->GetEffectiveMinSize();
993 item
.m_sticky
= false;
996 return &m_items
.Last();
999 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1000 const wxString
& label
,
1003 wxSize min_size
= wxDefaultSize
;
1007 wxAuiToolBarItem item
;
1008 item
.m_window
= NULL
;
1009 item
.m_label
= label
;
1010 item
.m_bitmap
= wxNullBitmap
;
1011 item
.m_disabledBitmap
= wxNullBitmap
;
1012 item
.m_active
= true;
1013 item
.m_dropDown
= false;
1014 item
.m_spacerPixels
= 0;
1015 item
.m_toolId
= tool_id
;
1017 item
.m_proportion
= 0;
1018 item
.m_kind
= wxITEM_LABEL
;
1019 item
.m_sizerItem
= NULL
;
1020 item
.m_minSize
= min_size
;
1021 item
.m_userData
= 0;
1022 item
.m_sticky
= false;
1024 if (item
.m_toolId
== wxID_ANY
)
1025 item
.m_toolId
= wxNewId();
1028 return &m_items
.Last();
1031 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1033 wxAuiToolBarItem item
;
1034 item
.m_window
= NULL
;
1035 item
.m_label
= wxEmptyString
;
1036 item
.m_bitmap
= wxNullBitmap
;
1037 item
.m_disabledBitmap
= wxNullBitmap
;
1038 item
.m_active
= true;
1039 item
.m_dropDown
= false;
1042 item
.m_proportion
= 0;
1043 item
.m_kind
= wxITEM_SEPARATOR
;
1044 item
.m_sizerItem
= NULL
;
1045 item
.m_minSize
= wxDefaultSize
;
1046 item
.m_userData
= 0;
1047 item
.m_sticky
= false;
1050 return &m_items
.Last();
1053 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1055 wxAuiToolBarItem item
;
1056 item
.m_window
= NULL
;
1057 item
.m_label
= wxEmptyString
;
1058 item
.m_bitmap
= wxNullBitmap
;
1059 item
.m_disabledBitmap
= wxNullBitmap
;
1060 item
.m_active
= true;
1061 item
.m_dropDown
= false;
1062 item
.m_spacerPixels
= pixels
;
1065 item
.m_proportion
= 0;
1066 item
.m_kind
= wxITEM_SPACER
;
1067 item
.m_sizerItem
= NULL
;
1068 item
.m_minSize
= wxDefaultSize
;
1069 item
.m_userData
= 0;
1070 item
.m_sticky
= false;
1073 return &m_items
.Last();
1076 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1078 wxAuiToolBarItem item
;
1079 item
.m_window
= NULL
;
1080 item
.m_label
= wxEmptyString
;
1081 item
.m_bitmap
= wxNullBitmap
;
1082 item
.m_disabledBitmap
= wxNullBitmap
;
1083 item
.m_active
= true;
1084 item
.m_dropDown
= false;
1085 item
.m_spacerPixels
= 0;
1088 item
.m_proportion
= proportion
;
1089 item
.m_kind
= wxITEM_SPACER
;
1090 item
.m_sizerItem
= NULL
;
1091 item
.m_minSize
= wxDefaultSize
;
1092 item
.m_userData
= 0;
1093 item
.m_sticky
= false;
1096 return &m_items
.Last();
1099 void wxAuiToolBar::Clear()
1102 m_sizerElementCount
= 0;
1105 bool wxAuiToolBar::DeleteTool(int tool_id
)
1107 int idx
= GetToolIndex(tool_id
);
1108 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1110 m_items
.RemoveAt(idx
);
1118 bool wxAuiToolBar::DeleteByIndex(int idx
)
1120 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1122 m_items
.RemoveAt(idx
);
1131 wxControl
* wxAuiToolBar::FindControl(int id
)
1133 wxWindow
* wnd
= FindWindow(id
);
1134 return (wxControl
*)wnd
;
1137 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1140 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1142 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1143 if (item
.m_toolId
== tool_id
)
1150 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1153 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1155 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1157 if (!item
.m_sizerItem
)
1160 wxRect rect
= item
.m_sizerItem
->GetRect();
1161 if (rect
.Contains(x
,y
))
1163 // if the item doesn't fit on the toolbar, return NULL
1164 if (!GetToolFitsByIndex(i
))
1174 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1177 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1179 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1181 if (!item
.m_sizerItem
)
1184 wxRect rect
= item
.m_sizerItem
->GetRect();
1186 // apply tool packing
1188 rect
.width
+= m_toolPacking
;
1190 if (rect
.Contains(x
,y
))
1192 // if the item doesn't fit on the toolbar, return NULL
1193 if (!GetToolFitsByIndex(i
))
1203 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1208 if (idx
>= (int)m_items
.size())
1211 return &(m_items
[idx
]);
1214 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1216 // TODO: wxToolBar compatibility
1219 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1221 // TODO: wxToolBar compatibility
1222 return wxSize(16,15);
1225 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1227 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1231 item
->m_proportion
= proportion
;
1234 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1236 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1240 return item
->m_proportion
;
1243 void wxAuiToolBar::SetToolSeparation(int separation
)
1246 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1249 int wxAuiToolBar::GetToolSeparation() const
1252 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1258 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1260 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1264 item
->m_dropDown
= dropdown
;
1267 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1269 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1273 return item
->m_dropDown
;
1276 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1278 // ignore separators
1282 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1286 if (item
->m_sticky
== sticky
)
1289 item
->m_sticky
= sticky
;
1295 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1297 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1301 return item
->m_sticky
;
1307 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1309 m_toolBorderPadding
= padding
;
1312 int wxAuiToolBar::GetToolBorderPadding() const
1314 return m_toolBorderPadding
;
1317 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1319 m_toolTextOrientation
= orientation
;
1323 m_art
->SetTextOrientation(orientation
);
1327 int wxAuiToolBar::GetToolTextOrientation() const
1329 return m_toolTextOrientation
;
1332 void wxAuiToolBar::SetToolPacking(int packing
)
1334 m_toolPacking
= packing
;
1337 int wxAuiToolBar::GetToolPacking() const
1339 return m_toolPacking
;
1343 void wxAuiToolBar::SetOrientation(int orientation
)
1345 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1346 orientation
== wxVERTICAL
,
1347 "invalid orientation value");
1348 if (orientation
!= m_orientation
)
1350 m_orientation
= wxOrientation(orientation
);
1355 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1358 m_leftPadding
= left
;
1360 m_rightPadding
= right
;
1364 m_bottomPadding
= bottom
;
1367 bool wxAuiToolBar::GetGripperVisible() const
1369 return m_gripperVisible
;
1372 void wxAuiToolBar::SetGripperVisible(bool visible
)
1374 m_gripperVisible
= visible
;
1376 m_style
|= wxAUI_TB_GRIPPER
;
1378 m_style
&= ~wxAUI_TB_GRIPPER
;
1384 bool wxAuiToolBar::GetOverflowVisible() const
1386 return m_overflowVisible
;
1389 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1391 m_overflowVisible
= visible
;
1393 m_style
|= wxAUI_TB_OVERFLOW
;
1395 m_style
&= ~wxAUI_TB_OVERFLOW
;
1399 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1401 bool res
= wxWindow::SetFont(font
);
1405 m_art
->SetFont(font
);
1412 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1414 if (pitem
&& (pitem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
))
1417 wxAuiToolBarItem
* former_hover
= NULL
;
1420 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1422 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1423 if (item
.m_state
& wxAUI_BUTTON_STATE_HOVER
)
1424 former_hover
= &item
;
1425 item
.m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1430 pitem
->m_state
|= wxAUI_BUTTON_STATE_HOVER
;
1433 if (former_hover
!= pitem
)
1440 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1442 wxAuiToolBarItem
* former_item
= NULL
;
1445 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1447 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1448 if (item
.m_state
& wxAUI_BUTTON_STATE_PRESSED
)
1449 former_item
= &item
;
1450 item
.m_state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1455 pitem
->m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1456 pitem
->m_state
|= wxAUI_BUTTON_STATE_PRESSED
;
1459 if (former_item
!= pitem
)
1466 void wxAuiToolBar::RefreshOverflowState()
1468 if (!m_overflowSizerItem
)
1470 m_overflowState
= 0;
1474 int overflow_state
= 0;
1476 wxRect overflow_rect
= GetOverflowRect();
1479 // find out the mouse's current position
1480 wxPoint pt
= ::wxGetMousePosition();
1481 pt
= this->ScreenToClient(pt
);
1483 // find out if the mouse cursor is inside the dropdown rectangle
1484 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1486 if (::wxGetMouseState().LeftIsDown())
1487 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1489 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1492 if (overflow_state
!= m_overflowState
)
1494 m_overflowState
= overflow_state
;
1499 m_overflowState
= overflow_state
;
1502 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1504 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1506 if (tool
&& (tool
->m_kind
== wxITEM_CHECK
|| tool
->m_kind
== wxITEM_RADIO
))
1508 if (tool
->m_kind
== wxITEM_RADIO
)
1511 idx
= GetToolIndex(tool_id
);
1512 count
= (int)m_items
.GetCount();
1514 if (idx
>= 0 && idx
< count
)
1516 for (i
= idx
+ 1; i
< count
; ++i
)
1518 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1520 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1522 for (i
= idx
- 1; i
>= 0; i
--)
1524 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1526 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1530 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1532 else if (tool
->m_kind
== wxITEM_CHECK
)
1535 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1537 tool
->m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1542 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1544 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1548 if ( (tool
->m_kind
!= wxITEM_CHECK
) && (tool
->m_kind
!= wxITEM_RADIO
) )
1551 return (tool
->m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1557 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1559 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1564 tool
->m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1566 tool
->m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1570 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1572 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1575 return (tool
->m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1580 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1582 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1583 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1585 return wxEmptyString
;
1587 return tool
->m_label
;
1590 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1592 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1595 tool
->m_label
= label
;
1599 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1601 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1602 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1604 return wxNullBitmap
;
1606 return tool
->m_bitmap
;
1609 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1611 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1614 tool
->m_bitmap
= bitmap
;
1618 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1620 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1621 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1623 return wxEmptyString
;
1625 return tool
->m_shortHelp
;
1628 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1630 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1633 tool
->m_shortHelp
= help_string
;
1637 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1639 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1640 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1642 return wxEmptyString
;
1644 return tool
->m_longHelp
;
1647 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1649 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1652 tool
->m_longHelp
= help_string
;
1656 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1657 const wxAuiToolBarItemArray
& append
)
1659 m_customOverflowPrepend
= prepend
;
1660 m_customOverflowAppend
= append
;
1663 // get size of hint rectangle for a particular dock location
1664 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1666 switch (dock_direction
)
1668 case wxAUI_DOCK_TOP
:
1669 case wxAUI_DOCK_BOTTOM
:
1670 return m_horzHintSize
;
1671 case wxAUI_DOCK_RIGHT
:
1672 case wxAUI_DOCK_LEFT
:
1673 return m_vertHintSize
;
1675 wxFAIL_MSG("invalid dock location value");
1677 return wxDefaultSize
;
1680 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1682 return IsPaneValid(m_style
, pane
);
1685 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1687 if (style
& wxAUI_TB_HORIZONTAL
)
1689 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1694 else if (style
& wxAUI_TB_VERTICAL
)
1696 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1704 bool wxAuiToolBar::IsPaneValid(long style
) const
1706 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1709 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1714 void wxAuiToolBar::SetArtFlags() const
1716 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1717 if (m_orientation
== wxVERTICAL
)
1719 artflags
|= wxAUI_TB_VERTICAL
;
1721 m_art
->SetFlags(artflags
);
1724 size_t wxAuiToolBar::GetToolCount() const
1726 return m_items
.size();
1729 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1731 // this will prevent us from returning the index of the
1732 // first separator in the toolbar since its id is equal to -1
1736 size_t i
, count
= m_items
.GetCount();
1737 for (i
= 0; i
< count
; ++i
)
1739 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1740 if (item
.m_toolId
== tool_id
)
1747 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1749 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1752 if (!m_items
[tool_idx
].m_sizerItem
)
1756 GetClientSize(&cli_w
, &cli_h
);
1758 wxRect rect
= m_items
[tool_idx
].m_sizerItem
->GetRect();
1760 if (m_orientation
== wxVERTICAL
)
1762 // take the dropdown size into account
1763 if (m_overflowVisible
)
1764 cli_h
-= m_overflowSizerItem
->GetSize().y
;
1766 if (rect
.y
+rect
.height
< cli_h
)
1771 // take the dropdown size into account
1772 if (m_overflowVisible
)
1773 cli_w
-= m_overflowSizerItem
->GetSize().x
;
1775 if (rect
.x
+rect
.width
< cli_w
)
1783 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1785 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1788 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1790 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1791 if (tool
&& tool
->m_sizerItem
)
1793 return tool
->m_sizerItem
->GetRect();
1799 bool wxAuiToolBar::GetToolBarFits() const
1801 if (m_items
.GetCount() == 0)
1803 // empty toolbar always 'fits'
1807 // entire toolbar content fits if the last tool fits
1808 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1811 bool wxAuiToolBar::Realize()
1813 wxClientDC
dc(this);
1817 // calculate hint sizes for both horizontal and vertical
1818 // in the order that leaves toolbar in correct final state
1819 bool retval
= false;
1820 if (m_orientation
== wxHORIZONTAL
)
1822 if (RealizeHelper(dc
, false))
1824 m_vertHintSize
= GetSize();
1825 if (RealizeHelper(dc
, true))
1827 m_horzHintSize
= GetSize();
1834 if (RealizeHelper(dc
, true))
1836 m_horzHintSize
= GetSize();
1837 if (RealizeHelper(dc
, false))
1839 m_vertHintSize
= GetSize();
1849 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1851 // create the new sizer to add toolbar elements to
1852 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1855 int separatorSize
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1856 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1857 if (gripperSize
> 0 && m_gripperVisible
)
1860 m_gripperSizerItem
= sizer
->Add(gripperSize
, 1, 0, wxEXPAND
);
1862 m_gripperSizerItem
= sizer
->Add(1, gripperSize
, 0, wxEXPAND
);
1866 m_gripperSizerItem
= NULL
;
1869 // add "left" padding
1870 if (m_leftPadding
> 0)
1873 sizer
->Add(m_leftPadding
, 1);
1875 sizer
->Add(1, m_leftPadding
);
1879 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1881 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1882 wxSizerItem
* m_sizerItem
= NULL
;
1884 switch (item
.m_kind
)
1888 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1889 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1890 size
.y
+ (m_toolBorderPadding
*2),
1895 sizer
->AddSpacer(m_toolPacking
);
1905 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1906 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1907 size
.y
+ (m_toolBorderPadding
*2),
1913 sizer
->AddSpacer(m_toolPacking
);
1919 case wxITEM_SEPARATOR
:
1922 m_sizerItem
= sizer
->Add(separatorSize
, 1, 0, wxEXPAND
);
1924 m_sizerItem
= sizer
->Add(1, separatorSize
, 0, wxEXPAND
);
1929 sizer
->AddSpacer(m_toolPacking
);
1936 if (item
.m_proportion
> 0)
1937 m_sizerItem
= sizer
->AddStretchSpacer(item
.m_proportion
);
1939 m_sizerItem
= sizer
->Add(item
.m_spacerPixels
, 1);
1942 case wxITEM_CONTROL
:
1944 //m_sizerItem = sizer->Add(item.m_window, item.m_proportion, wxEXPAND);
1945 wxSizerItem
* ctrl_m_sizerItem
;
1947 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1948 vert_sizer
->AddStretchSpacer(1);
1949 ctrl_m_sizerItem
= vert_sizer
->Add(item
.m_window
, 0, wxEXPAND
);
1950 vert_sizer
->AddStretchSpacer(1);
1951 if ( (m_style
& wxAUI_TB_TEXT
) &&
1952 m_toolTextOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1953 !item
.GetLabel().empty() )
1955 wxSize s
= GetLabelSize(item
.GetLabel());
1956 vert_sizer
->Add(1, s
.y
);
1960 m_sizerItem
= sizer
->Add(vert_sizer
, item
.m_proportion
, wxEXPAND
);
1962 wxSize min_size
= item
.m_minSize
;
1965 // proportional items will disappear from the toolbar if
1966 // their min width is not set to something really small
1967 if (item
.m_proportion
!= 0)
1972 if (min_size
.IsFullySpecified())
1974 m_sizerItem
->SetMinSize(min_size
);
1975 ctrl_m_sizerItem
->SetMinSize(min_size
);
1981 sizer
->AddSpacer(m_toolPacking
);
1986 item
.m_sizerItem
= m_sizerItem
;
1989 // add "right" padding
1990 if (m_rightPadding
> 0)
1993 sizer
->Add(m_rightPadding
, 1);
1995 sizer
->Add(1, m_rightPadding
);
1998 // add drop down area
1999 m_overflowSizerItem
= NULL
;
2001 if (m_style
& wxAUI_TB_OVERFLOW
)
2003 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2004 if (overflow_size
> 0 && m_overflowVisible
)
2007 m_overflowSizerItem
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2009 m_overflowSizerItem
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2013 m_overflowSizerItem
= NULL
;
2018 // the outside sizer helps us apply the "top" and "bottom" padding
2019 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2021 // add "top" padding
2022 if (m_topPadding
> 0)
2025 outside_sizer
->Add(1, m_topPadding
);
2027 outside_sizer
->Add(m_topPadding
, 1);
2030 // add the sizer that contains all of the toolbar elements
2031 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2033 // add "bottom" padding
2034 if (m_bottomPadding
> 0)
2037 outside_sizer
->Add(1, m_bottomPadding
);
2039 outside_sizer
->Add(m_bottomPadding
, 1);
2042 delete m_sizer
; // remove old sizer
2043 m_sizer
= outside_sizer
;
2045 // calculate the rock-bottom minimum size
2046 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2048 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2049 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2050 item
.m_sizerItem
->SetMinSize(0,0);
2053 m_absoluteMinSize
= m_sizer
->GetMinSize();
2055 // reset the min sizes to what they were
2056 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2058 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2059 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2060 item
.m_sizerItem
->SetMinSize(item
.m_minSize
);
2064 wxSize size
= m_sizer
->GetMinSize();
2065 m_minWidth
= size
.x
;
2066 m_minHeight
= size
.y
;
2068 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2070 wxSize curSize
= GetClientSize();
2071 wxSize new_size
= GetMinSize();
2072 if (new_size
!= curSize
)
2074 SetClientSize(new_size
);
2078 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2083 wxSize curSize
= GetClientSize();
2084 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2090 int wxAuiToolBar::GetOverflowState() const
2092 return m_overflowState
;
2095 wxRect
wxAuiToolBar::GetOverflowRect() const
2097 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2098 wxRect overflow_rect
= m_overflowSizerItem
->GetRect();
2099 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2101 if (m_orientation
== wxVERTICAL
)
2103 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2104 overflow_rect
.x
= 0;
2105 overflow_rect
.width
= cli_rect
.width
;
2106 overflow_rect
.height
= overflow_size
;
2110 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2111 overflow_rect
.y
= 0;
2112 overflow_rect
.width
= overflow_size
;
2113 overflow_rect
.height
= cli_rect
.height
;
2116 return overflow_rect
;
2119 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2121 wxClientDC
dc(this);
2124 int textWidth
= 0, textHeight
= 0;
2128 // get the text height
2129 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
2131 // get the text width
2132 dc
.GetTextExtent(label
, &textWidth
, &ty
);
2134 return wxSize(textWidth
, textHeight
);
2138 void wxAuiToolBar::DoIdleUpdate()
2140 wxEvtHandler
* handler
= GetEventHandler();
2142 bool need_refresh
= false;
2145 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2147 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2149 if (item
.m_toolId
== -1)
2152 wxUpdateUIEvent
evt(item
.m_toolId
);
2153 evt
.SetEventObject(this);
2155 if (handler
->ProcessEvent(evt
))
2157 if (evt
.GetSetEnabled())
2161 is_enabled
= item
.m_window
->IsThisEnabled();
2163 is_enabled
= (item
.m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2165 bool new_enabled
= evt
.GetEnabled();
2166 if (new_enabled
!= is_enabled
)
2170 item
.m_window
->Enable(new_enabled
);
2175 item
.m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2177 item
.m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
2179 need_refresh
= true;
2183 if (evt
.GetSetChecked())
2185 // make sure we aren't checking an item that can't be
2186 if (item
.m_kind
!= wxITEM_CHECK
&& item
.m_kind
!= wxITEM_RADIO
)
2189 bool is_checked
= (item
.m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2190 bool new_checked
= evt
.GetChecked();
2192 if (new_checked
!= is_checked
)
2195 item
.m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
2197 item
.m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2199 need_refresh
= true;
2214 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2217 GetClientSize(&x
, &y
);
2219 if (((x
>= y
) && m_absoluteMinSize
.x
> x
) ||
2220 ((y
> x
) && m_absoluteMinSize
.y
> y
))
2222 // hide all flexible items
2224 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2226 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2227 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_sizerItem
->IsShown())
2229 item
.m_sizerItem
->Show(false);
2230 item
.m_sizerItem
->SetProportion(0);
2236 // show all flexible items
2238 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2240 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2241 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && !item
.m_sizerItem
->IsShown())
2243 item
.m_sizerItem
->Show(true);
2244 item
.m_sizerItem
->SetProportion(item
.m_proportion
);
2249 m_sizer
->SetDimension(0, 0, x
, y
);
2254 // idle events aren't sent while user is resizing frame (why?),
2255 // but resizing toolbar here causes havoc,
2256 // so force idle handler to run after size handling complete
2257 QueueEvent(new wxIdleEvent
);
2262 void wxAuiToolBar::DoSetSize(int x
,
2268 wxSize parent_size
= GetParent()->GetClientSize();
2269 if (x
+ width
> parent_size
.x
)
2270 width
= wxMax(0, parent_size
.x
- x
);
2271 if (y
+ height
> parent_size
.y
)
2272 height
= wxMax(0, parent_size
.y
- y
);
2274 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2278 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2280 // if orientation doesn't match dock, fix it
2281 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2284 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2285 // pane state member is public, so it might have been changed
2286 // without going through wxPaneInfo::SetFlag() check
2287 bool ok
= pane
.IsOk();
2288 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2289 "window settings and pane settings are incompatible");
2292 wxOrientation newOrientation
= m_orientation
;
2293 if (pane
.IsDocked())
2295 switch (pane
.dock_direction
)
2297 case wxAUI_DOCK_TOP
:
2298 case wxAUI_DOCK_BOTTOM
:
2299 newOrientation
= wxHORIZONTAL
;
2301 case wxAUI_DOCK_LEFT
:
2302 case wxAUI_DOCK_RIGHT
:
2303 newOrientation
= wxVERTICAL
;
2306 wxFAIL_MSG("invalid dock location value");
2309 else if (pane
.IsResizable() &&
2310 GetOrientation(m_style
) == wxBOTH
)
2312 // changing orientation in OnSize causes havoc
2314 GetClientSize(&x
, &y
);
2318 newOrientation
= wxHORIZONTAL
;
2322 newOrientation
= wxVERTICAL
;
2325 if (newOrientation
!= m_orientation
)
2327 SetOrientation(newOrientation
);
2329 if (newOrientation
== wxHORIZONTAL
)
2331 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2335 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2337 if (pane
.IsDocked())
2339 pane
.floating_size
= wxDefaultSize
;
2343 SetSize(GetParent()->GetClientSize());
2352 void wxAuiToolBar::UpdateWindowUI(long flags
)
2354 if ( flags
& wxUPDATE_UI_FROMIDLE
)
2359 wxControl::UpdateWindowUI(flags
);
2362 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2364 wxAutoBufferedPaintDC
dc(this);
2365 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2368 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2371 m_art
->DrawBackground(dc
, this, cli_rect
);
2373 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2374 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2376 // paint the gripper
2377 if (gripperSize
> 0 && m_gripperSizerItem
)
2379 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2381 gripper_rect
.width
= gripperSize
;
2383 gripper_rect
.height
= gripperSize
;
2384 m_art
->DrawGripper(dc
, this, gripper_rect
);
2387 // calculated how far we can draw items
2390 last_extent
= cli_rect
.width
;
2392 last_extent
= cli_rect
.height
;
2393 if (m_overflowVisible
)
2394 last_extent
-= dropdown_size
;
2396 // paint each individual tool
2397 size_t i
, count
= m_items
.GetCount();
2398 for (i
= 0; i
< count
; ++i
)
2400 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2402 if (!item
.m_sizerItem
)
2405 wxRect item_rect
= item
.m_sizerItem
->GetRect();
2408 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2409 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2414 if (item
.m_kind
== wxITEM_SEPARATOR
)
2417 m_art
->DrawSeparator(dc
, this, item_rect
);
2419 else if (item
.m_kind
== wxITEM_LABEL
)
2421 // draw a text label only
2422 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2424 else if (item
.m_kind
== wxITEM_NORMAL
)
2426 // draw a regular button or dropdown button
2427 if (!item
.m_dropDown
)
2428 m_art
->DrawButton(dc
, this, item
, item_rect
);
2430 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2432 else if (item
.m_kind
== wxITEM_CHECK
)
2434 // draw either a regular or dropdown toggle button
2435 if (!item
.m_dropDown
)
2436 m_art
->DrawButton(dc
, this, item
, item_rect
);
2438 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2440 else if (item
.m_kind
== wxITEM_RADIO
)
2442 // draw a toggle button
2443 m_art
->DrawButton(dc
, this, item
, item_rect
);
2445 else if (item
.m_kind
== wxITEM_CONTROL
)
2447 // draw the control's label
2448 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2451 // fire a signal to see if the item wants to be custom-rendered
2452 OnCustomRender(dc
, item
, item_rect
);
2455 // paint the overflow button
2456 if (dropdown_size
> 0 && m_overflowSizerItem
)
2458 wxRect dropDownRect
= GetOverflowRect();
2459 m_art
->DrawOverflowButton(dc
, this, dropDownRect
, m_overflowState
);
2463 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2468 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2470 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2472 if (m_gripperSizerItem
)
2474 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2475 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2478 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2482 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2483 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2485 // gripper was clicked
2486 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2491 if (m_overflowSizerItem
)
2493 wxRect overflow_rect
= GetOverflowRect();
2496 m_overflowVisible
&&
2497 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2499 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2500 e
.SetEventObject(this);
2502 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2503 bool processed
= GetEventHandler()->ProcessEvent(e
);
2512 wxAuiToolBarItemArray overflow_items
;
2515 // add custom overflow prepend items, if any
2516 count
= m_customOverflowPrepend
.GetCount();
2517 for (i
= 0; i
< count
; ++i
)
2518 overflow_items
.Add(m_customOverflowPrepend
[i
]);
2520 // only show items that don't fit in the dropdown
2521 count
= m_items
.GetCount();
2522 for (i
= 0; i
< count
; ++i
)
2524 if (!GetToolFitsByIndex(i
))
2525 overflow_items
.Add(m_items
[i
]);
2528 // add custom overflow append items, if any
2529 count
= m_customOverflowAppend
.GetCount();
2530 for (i
= 0; i
< count
; ++i
)
2531 overflow_items
.Add(m_customOverflowAppend
[i
]);
2533 int res
= m_art
->ShowDropDown(this, overflow_items
);
2534 m_overflowState
= 0;
2538 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, res
);
2539 event
.SetEventObject(this);
2540 GetParent()->GetEventHandler()->ProcessEvent(event
);
2549 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2550 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2554 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2556 m_actionPos
= wxPoint(-1,-1);
2557 m_actionItem
= NULL
;
2563 // fire the tool dropdown event
2564 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_actionItem
->m_toolId
);
2565 e
.SetEventObject(this);
2566 e
.SetToolId(m_actionItem
->m_toolId
);
2568 int mouse_x
= evt
.GetX();
2569 wxRect rect
= m_actionItem
->m_sizerItem
->GetRect();
2570 const bool dropDownHit
= m_actionItem
->m_dropDown
&&
2571 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2572 mouse_x
< (rect
.x
+rect
.width
);
2573 e
.SetDropDownClicked(dropDownHit
);
2575 e
.SetClickPoint(evt
.GetPosition());
2576 e
.SetItemRect(rect
);
2578 // we only set the 'pressed button' state if we hit the actual button
2579 // and not just the drop-down
2580 SetPressedItem(dropDownHit
? 0 : m_actionItem
);
2584 m_actionPos
= wxPoint(-1,-1);
2585 m_actionItem
= NULL
;
2588 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2591 // Ensure hovered item is really ok, as mouse may have moved during
2593 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2594 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2600 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2605 SetPressedItem(NULL
);
2607 wxAuiToolBarItem
* hitItem
;
2608 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2609 SetHoverItem(hitItem
);
2613 // TODO: it would make sense to send out an 'END_DRAG' event here,
2614 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2617 // OnCaptureLost() will be called now and this will reset all our state
2618 // tracking variables
2623 if (m_actionItem
&& hitItem
== m_actionItem
)
2627 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_actionItem
->m_toolId
);
2628 e
.SetEventObject(this);
2630 if (hitItem
->m_kind
== wxITEM_CHECK
|| hitItem
->m_kind
== wxITEM_RADIO
)
2632 const bool toggle
= !(m_actionItem
->m_state
& wxAUI_BUTTON_STATE_CHECKED
);
2634 ToggleTool(m_actionItem
->m_toolId
, toggle
);
2636 // repaint immediately
2643 // we have to release the mouse *before* sending the event, because
2644 // we don't know what a handler might do. It could open up a popup
2645 // menu for example and that would make us lose our capture anyway.
2649 GetEventHandler()->ProcessEvent(e
);
2651 // Ensure hovered item is really ok, as mouse may have moved during
2653 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2654 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2663 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2665 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2667 if (m_gripperSizerItem
)
2669 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2670 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2674 if (m_overflowSizerItem
&& m_art
)
2676 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2677 if (dropdown_size
> 0 &&
2678 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2680 evt
.m_y
< cli_rect
.height
)
2686 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2687 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2689 if (m_actionItem
&& m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2691 m_actionPos
= wxPoint(-1,-1);
2692 m_actionItem
= NULL
;
2699 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2701 wxAuiToolBarItem
* hitItem
;
2702 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2704 if (m_actionItem
&& hitItem
== m_actionItem
)
2706 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_actionItem
->m_toolId
);
2707 e
.SetEventObject(this);
2708 e
.SetToolId(m_actionItem
->m_toolId
);
2709 e
.SetClickPoint(m_actionPos
);
2710 GetEventHandler()->ProcessEvent(e
);
2715 // right-clicked on the invalid area of the toolbar
2716 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2717 e
.SetEventObject(this);
2719 e
.SetClickPoint(m_actionPos
);
2720 GetEventHandler()->ProcessEvent(e
);
2724 // reset member variables
2725 m_actionPos
= wxPoint(-1,-1);
2726 m_actionItem
= NULL
;
2729 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2731 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2733 if (m_gripperSizerItem
)
2735 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2736 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2740 if (m_overflowSizerItem
&& m_art
)
2742 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2743 if (dropdown_size
> 0 &&
2744 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2746 evt
.m_y
< cli_rect
.height
)
2752 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2753 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2757 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2759 m_actionPos
= wxPoint(-1,-1);
2760 m_actionItem
= NULL
;
2768 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2770 wxAuiToolBarItem
* hitItem
;
2771 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2773 if (m_actionItem
&& hitItem
== m_actionItem
)
2775 if (hitItem
->m_kind
== wxITEM_NORMAL
)
2777 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_actionItem
->m_toolId
);
2778 e
.SetEventObject(this);
2779 e
.SetToolId(m_actionItem
->m_toolId
);
2780 e
.SetClickPoint(m_actionPos
);
2781 GetEventHandler()->ProcessEvent(e
);
2786 // reset member variables
2787 m_actionPos
= wxPoint(-1,-1);
2788 m_actionItem
= NULL
;
2791 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2793 const bool button_pressed
= HasCapture();
2795 // start a drag event
2796 if (!m_dragging
&& button_pressed
&&
2797 abs(evt
.GetX() - m_actionPos
.x
) + abs(evt
.GetY() - m_actionPos
.y
) > 5)
2799 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2800 // event sent sometime in the future (see OnLeftUp())
2801 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2802 e
.SetEventObject(this);
2803 e
.SetToolId(m_actionItem
->m_toolId
);
2804 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2812 wxAuiToolBarItem
* hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2815 // if we have a button pressed we want it to be shown in 'depressed'
2816 // state unless we move the mouse outside the button, then we want it
2817 // to show as just 'highlighted'
2818 if (hitItem
== m_actionItem
)
2819 SetPressedItem(m_actionItem
);
2822 SetPressedItem(NULL
);
2823 SetHoverItem(m_actionItem
);
2828 SetHoverItem(hitItem
);
2830 // tooltips handling
2831 wxAuiToolBarItem
* packingHitItem
;
2832 packingHitItem
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2835 if (packingHitItem
!= m_tipItem
)
2837 m_tipItem
= packingHitItem
;
2839 if ( !packingHitItem
->m_shortHelp
.empty() )
2840 SetToolTip(packingHitItem
->m_shortHelp
);
2851 // figure out the dropdown button state (are we hovering or pressing it?)
2852 RefreshOverflowState();
2856 void wxAuiToolBar::DoResetMouseState()
2858 RefreshOverflowState();
2860 SetPressedItem(NULL
);
2864 // we have to reset those here, because the mouse-up handlers which do
2865 // it usually won't be called if we let go of a mouse button while we
2866 // are outside of the window
2867 m_actionPos
= wxPoint(-1,-1);
2868 m_actionItem
= NULL
;
2871 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2879 DoResetMouseState();
2882 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2886 DoResetMouseState();
2889 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2891 wxCursor cursor
= wxNullCursor
;
2893 if (m_gripperSizerItem
)
2895 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2896 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2898 cursor
= wxCursor(wxCURSOR_SIZING
);
2902 evt
.SetCursor(cursor
);