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
)
802 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
804 const wxPoint
& position
,
811 style
| wxBORDER_NONE
)
813 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
816 m_sizerElementCount
= 0;
817 m_actionPos
= wxPoint(-1,-1);
820 m_art
= new wxAuiDefaultToolBarArt
;
822 m_toolBorderPadding
= 3;
823 m_toolTextOrientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
824 m_gripperSizerItem
= NULL
;
825 m_overflowSizerItem
= NULL
;
827 m_orientation
= GetOrientation(style
);
828 if (m_orientation
== wxBOTH
)
830 m_orientation
= wxHORIZONTAL
;
832 m_style
= style
| wxBORDER_NONE
;
833 m_gripperVisible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
834 m_overflowVisible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
836 SetMargins(5, 5, 2, 2);
837 SetFont(*wxNORMAL_FONT
);
839 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
840 if (style
& wxAUI_TB_HORZ_LAYOUT
)
841 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
842 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
846 wxAuiToolBar::~wxAuiToolBar()
852 void wxAuiToolBar::SetWindowStyleFlag(long style
)
854 GetOrientation(style
); // assert if style is invalid
855 wxCHECK_RET(IsPaneValid(style
),
856 "window settings and pane settings are incompatible");
858 wxControl::SetWindowStyleFlag(style
);
867 if (m_style
& wxAUI_TB_GRIPPER
)
868 m_gripperVisible
= true;
870 m_gripperVisible
= false;
873 if (m_style
& wxAUI_TB_OVERFLOW
)
874 m_overflowVisible
= true;
876 m_overflowVisible
= false;
878 if (style
& wxAUI_TB_HORZ_LAYOUT
)
879 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
881 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
884 long wxAuiToolBar::GetWindowStyleFlag() const
889 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
898 m_art
->SetTextOrientation(m_toolTextOrientation
);
902 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
910 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
911 const wxString
& label
,
912 const wxBitmap
& bitmap
,
913 const wxString
& shortHelp_string
,
916 return AddTool(tool_id
,
927 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
928 const wxString
& label
,
929 const wxBitmap
& bitmap
,
930 const wxBitmap
& disabledBitmap
,
932 const wxString
& shortHelpString
,
933 const wxString
& longHelpString
,
934 wxObject
* WXUNUSED(client_data
))
936 wxAuiToolBarItem item
;
937 item
.m_window
= NULL
;
938 item
.m_label
= label
;
939 item
.m_bitmap
= bitmap
;
940 item
.m_disabledBitmap
= disabledBitmap
;
941 item
.m_shortHelp
= shortHelpString
;
942 item
.m_longHelp
= longHelpString
;
943 item
.m_active
= true;
944 item
.m_dropDown
= false;
945 item
.m_spacerPixels
= 0;
946 item
.m_toolId
= tool_id
;
948 item
.m_proportion
= 0;
950 item
.m_sizerItem
= NULL
;
951 item
.m_minSize
= wxDefaultSize
;
953 item
.m_sticky
= false;
955 if (item
.m_toolId
== wxID_ANY
)
956 item
.m_toolId
= wxNewId();
958 if (!item
.m_disabledBitmap
.IsOk())
960 // no disabled bitmap specified, we need to make one
961 if (item
.m_bitmap
.IsOk())
963 item
.m_disabledBitmap
= item
.m_bitmap
.ConvertToDisabled();
967 return &m_items
.Last();
970 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
971 const wxString
& label
)
973 wxAuiToolBarItem item
;
974 item
.m_window
= (wxWindow
*)control
;
975 item
.m_label
= label
;
976 item
.m_bitmap
= wxNullBitmap
;
977 item
.m_disabledBitmap
= wxNullBitmap
;
978 item
.m_active
= true;
979 item
.m_dropDown
= false;
980 item
.m_spacerPixels
= 0;
981 item
.m_toolId
= control
->GetId();
983 item
.m_proportion
= 0;
984 item
.m_kind
= wxITEM_CONTROL
;
985 item
.m_sizerItem
= NULL
;
986 item
.m_minSize
= control
->GetEffectiveMinSize();
988 item
.m_sticky
= false;
991 return &m_items
.Last();
994 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
995 const wxString
& label
,
998 wxSize min_size
= wxDefaultSize
;
1002 wxAuiToolBarItem item
;
1003 item
.m_window
= NULL
;
1004 item
.m_label
= label
;
1005 item
.m_bitmap
= wxNullBitmap
;
1006 item
.m_disabledBitmap
= wxNullBitmap
;
1007 item
.m_active
= true;
1008 item
.m_dropDown
= false;
1009 item
.m_spacerPixels
= 0;
1010 item
.m_toolId
= tool_id
;
1012 item
.m_proportion
= 0;
1013 item
.m_kind
= wxITEM_LABEL
;
1014 item
.m_sizerItem
= NULL
;
1015 item
.m_minSize
= min_size
;
1016 item
.m_userData
= 0;
1017 item
.m_sticky
= false;
1019 if (item
.m_toolId
== wxID_ANY
)
1020 item
.m_toolId
= wxNewId();
1023 return &m_items
.Last();
1026 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1028 wxAuiToolBarItem item
;
1029 item
.m_window
= NULL
;
1030 item
.m_label
= wxEmptyString
;
1031 item
.m_bitmap
= wxNullBitmap
;
1032 item
.m_disabledBitmap
= wxNullBitmap
;
1033 item
.m_active
= true;
1034 item
.m_dropDown
= false;
1037 item
.m_proportion
= 0;
1038 item
.m_kind
= wxITEM_SEPARATOR
;
1039 item
.m_sizerItem
= NULL
;
1040 item
.m_minSize
= wxDefaultSize
;
1041 item
.m_userData
= 0;
1042 item
.m_sticky
= false;
1045 return &m_items
.Last();
1048 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1050 wxAuiToolBarItem item
;
1051 item
.m_window
= NULL
;
1052 item
.m_label
= wxEmptyString
;
1053 item
.m_bitmap
= wxNullBitmap
;
1054 item
.m_disabledBitmap
= wxNullBitmap
;
1055 item
.m_active
= true;
1056 item
.m_dropDown
= false;
1057 item
.m_spacerPixels
= pixels
;
1060 item
.m_proportion
= 0;
1061 item
.m_kind
= wxITEM_SPACER
;
1062 item
.m_sizerItem
= NULL
;
1063 item
.m_minSize
= wxDefaultSize
;
1064 item
.m_userData
= 0;
1065 item
.m_sticky
= false;
1068 return &m_items
.Last();
1071 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1073 wxAuiToolBarItem item
;
1074 item
.m_window
= NULL
;
1075 item
.m_label
= wxEmptyString
;
1076 item
.m_bitmap
= wxNullBitmap
;
1077 item
.m_disabledBitmap
= wxNullBitmap
;
1078 item
.m_active
= true;
1079 item
.m_dropDown
= false;
1080 item
.m_spacerPixels
= 0;
1083 item
.m_proportion
= proportion
;
1084 item
.m_kind
= wxITEM_SPACER
;
1085 item
.m_sizerItem
= NULL
;
1086 item
.m_minSize
= wxDefaultSize
;
1087 item
.m_userData
= 0;
1088 item
.m_sticky
= false;
1091 return &m_items
.Last();
1094 void wxAuiToolBar::Clear()
1097 m_sizerElementCount
= 0;
1100 bool wxAuiToolBar::DeleteTool(int tool_id
)
1102 int idx
= GetToolIndex(tool_id
);
1103 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1105 m_items
.RemoveAt(idx
);
1113 bool wxAuiToolBar::DeleteByIndex(int idx
)
1115 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1117 m_items
.RemoveAt(idx
);
1126 wxControl
* wxAuiToolBar::FindControl(int id
)
1128 wxWindow
* wnd
= FindWindow(id
);
1129 return (wxControl
*)wnd
;
1132 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1135 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1137 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1138 if (item
.m_toolId
== tool_id
)
1145 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1148 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1150 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1152 if (!item
.m_sizerItem
)
1155 wxRect rect
= item
.m_sizerItem
->GetRect();
1156 if (rect
.Contains(x
,y
))
1158 // if the item doesn't fit on the toolbar, return NULL
1159 if (!GetToolFitsByIndex(i
))
1169 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1172 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1174 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1176 if (!item
.m_sizerItem
)
1179 wxRect rect
= item
.m_sizerItem
->GetRect();
1181 // apply tool packing
1183 rect
.width
+= m_toolPacking
;
1185 if (rect
.Contains(x
,y
))
1187 // if the item doesn't fit on the toolbar, return NULL
1188 if (!GetToolFitsByIndex(i
))
1198 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1203 if (idx
>= (int)m_items
.size())
1206 return &(m_items
[idx
]);
1209 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1211 // TODO: wxToolBar compatibility
1214 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1216 // TODO: wxToolBar compatibility
1217 return wxSize(16,15);
1220 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1222 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1226 item
->m_proportion
= proportion
;
1229 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1231 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1235 return item
->m_proportion
;
1238 void wxAuiToolBar::SetToolSeparation(int separation
)
1241 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1244 int wxAuiToolBar::GetToolSeparation() const
1247 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1253 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1255 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1259 item
->m_dropDown
= dropdown
;
1262 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1264 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1268 return item
->m_dropDown
;
1271 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1273 // ignore separators
1277 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1281 if (item
->m_sticky
== sticky
)
1284 item
->m_sticky
= sticky
;
1290 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1292 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1296 return item
->m_sticky
;
1302 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1304 m_toolBorderPadding
= padding
;
1307 int wxAuiToolBar::GetToolBorderPadding() const
1309 return m_toolBorderPadding
;
1312 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1314 m_toolTextOrientation
= orientation
;
1318 m_art
->SetTextOrientation(orientation
);
1322 int wxAuiToolBar::GetToolTextOrientation() const
1324 return m_toolTextOrientation
;
1327 void wxAuiToolBar::SetToolPacking(int packing
)
1329 m_toolPacking
= packing
;
1332 int wxAuiToolBar::GetToolPacking() const
1334 return m_toolPacking
;
1338 void wxAuiToolBar::SetOrientation(int orientation
)
1340 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1341 orientation
== wxVERTICAL
,
1342 "invalid orientation value");
1343 if (orientation
!= m_orientation
)
1345 m_orientation
= wxOrientation(orientation
);
1350 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1353 m_leftPadding
= left
;
1355 m_rightPadding
= right
;
1359 m_bottomPadding
= bottom
;
1362 bool wxAuiToolBar::GetGripperVisible() const
1364 return m_gripperVisible
;
1367 void wxAuiToolBar::SetGripperVisible(bool visible
)
1369 m_gripperVisible
= visible
;
1371 m_style
|= wxAUI_TB_GRIPPER
;
1373 m_style
&= ~wxAUI_TB_GRIPPER
;
1379 bool wxAuiToolBar::GetOverflowVisible() const
1381 return m_overflowVisible
;
1384 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1386 m_overflowVisible
= visible
;
1388 m_style
|= wxAUI_TB_OVERFLOW
;
1390 m_style
&= ~wxAUI_TB_OVERFLOW
;
1394 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1396 bool res
= wxWindow::SetFont(font
);
1400 m_art
->SetFont(font
);
1407 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1409 if (pitem
&& (pitem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
))
1412 wxAuiToolBarItem
* former_hover
= NULL
;
1415 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1417 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1418 if (item
.m_state
& wxAUI_BUTTON_STATE_HOVER
)
1419 former_hover
= &item
;
1420 item
.m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1425 pitem
->m_state
|= wxAUI_BUTTON_STATE_HOVER
;
1428 if (former_hover
!= pitem
)
1435 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1437 wxAuiToolBarItem
* former_item
= NULL
;
1440 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1442 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1443 if (item
.m_state
& wxAUI_BUTTON_STATE_PRESSED
)
1444 former_item
= &item
;
1445 item
.m_state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1450 pitem
->m_state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1451 pitem
->m_state
|= wxAUI_BUTTON_STATE_PRESSED
;
1454 if (former_item
!= pitem
)
1461 void wxAuiToolBar::RefreshOverflowState()
1463 if (!m_overflowSizerItem
)
1465 m_overflowState
= 0;
1469 int overflow_state
= 0;
1471 wxRect overflow_rect
= GetOverflowRect();
1474 // find out the mouse's current position
1475 wxPoint pt
= ::wxGetMousePosition();
1476 pt
= this->ScreenToClient(pt
);
1478 // find out if the mouse cursor is inside the dropdown rectangle
1479 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1481 if (::wxGetMouseState().LeftIsDown())
1482 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1484 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1487 if (overflow_state
!= m_overflowState
)
1489 m_overflowState
= overflow_state
;
1494 m_overflowState
= overflow_state
;
1497 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1499 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1501 if (tool
&& (tool
->m_kind
== wxITEM_CHECK
|| tool
->m_kind
== wxITEM_RADIO
))
1503 if (tool
->m_kind
== wxITEM_RADIO
)
1506 idx
= GetToolIndex(tool_id
);
1507 count
= (int)m_items
.GetCount();
1509 if (idx
>= 0 && idx
< count
)
1511 for (i
= idx
+ 1; i
< count
; ++i
)
1513 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1515 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1517 for (i
= idx
- 1; i
>= 0; i
--)
1519 if (m_items
[i
].m_kind
!= wxITEM_RADIO
)
1521 m_items
[i
].m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1525 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1527 else if (tool
->m_kind
== wxITEM_CHECK
)
1530 tool
->m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
1532 tool
->m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1537 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1539 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1543 if ( (tool
->m_kind
!= wxITEM_CHECK
) && (tool
->m_kind
!= wxITEM_RADIO
) )
1546 return (tool
->m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1552 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1554 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1559 tool
->m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1561 tool
->m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1565 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1567 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1570 return (tool
->m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1575 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1577 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1578 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1580 return wxEmptyString
;
1582 return tool
->m_label
;
1585 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1587 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1590 tool
->m_label
= label
;
1594 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1596 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1597 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1599 return wxNullBitmap
;
1601 return tool
->m_bitmap
;
1604 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1606 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1609 tool
->m_bitmap
= bitmap
;
1613 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1615 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1616 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1618 return wxEmptyString
;
1620 return tool
->m_shortHelp
;
1623 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1625 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1628 tool
->m_shortHelp
= help_string
;
1632 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1634 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1635 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1637 return wxEmptyString
;
1639 return tool
->m_longHelp
;
1642 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1644 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1647 tool
->m_longHelp
= help_string
;
1651 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1652 const wxAuiToolBarItemArray
& append
)
1654 m_customOverflowPrepend
= prepend
;
1655 m_customOverflowAppend
= append
;
1658 // get size of hint rectangle for a particular dock location
1659 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1661 switch (dock_direction
)
1663 case wxAUI_DOCK_TOP
:
1664 case wxAUI_DOCK_BOTTOM
:
1665 return m_horzHintSize
;
1666 case wxAUI_DOCK_RIGHT
:
1667 case wxAUI_DOCK_LEFT
:
1668 return m_vertHintSize
;
1670 wxFAIL_MSG("invalid dock location value");
1672 return wxDefaultSize
;
1675 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1677 return IsPaneValid(m_style
, pane
);
1680 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1682 if (style
& wxAUI_TB_HORIZONTAL
)
1684 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1689 else if (style
& wxAUI_TB_VERTICAL
)
1691 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1699 bool wxAuiToolBar::IsPaneValid(long style
) const
1701 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1704 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1709 void wxAuiToolBar::SetArtFlags() const
1711 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1712 if (m_orientation
== wxVERTICAL
)
1714 artflags
|= wxAUI_TB_VERTICAL
;
1716 m_art
->SetFlags(artflags
);
1719 size_t wxAuiToolBar::GetToolCount() const
1721 return m_items
.size();
1724 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1726 // this will prevent us from returning the index of the
1727 // first separator in the toolbar since its id is equal to -1
1731 size_t i
, count
= m_items
.GetCount();
1732 for (i
= 0; i
< count
; ++i
)
1734 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1735 if (item
.m_toolId
== tool_id
)
1742 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1744 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1747 if (!m_items
[tool_idx
].m_sizerItem
)
1751 GetClientSize(&cli_w
, &cli_h
);
1753 wxRect rect
= m_items
[tool_idx
].m_sizerItem
->GetRect();
1755 if (m_orientation
== wxVERTICAL
)
1757 // take the dropdown size into account
1758 if (m_overflowVisible
)
1759 cli_h
-= m_overflowSizerItem
->GetSize().y
;
1761 if (rect
.y
+rect
.height
< cli_h
)
1766 // take the dropdown size into account
1767 if (m_overflowVisible
)
1768 cli_w
-= m_overflowSizerItem
->GetSize().x
;
1770 if (rect
.x
+rect
.width
< cli_w
)
1778 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1780 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1783 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1785 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1786 if (tool
&& tool
->m_sizerItem
)
1788 return tool
->m_sizerItem
->GetRect();
1794 bool wxAuiToolBar::GetToolBarFits() const
1796 if (m_items
.GetCount() == 0)
1798 // empty toolbar always 'fits'
1802 // entire toolbar content fits if the last tool fits
1803 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1806 bool wxAuiToolBar::Realize()
1808 wxClientDC
dc(this);
1812 // calculate hint sizes for both horizontal and vertical
1813 // in the order that leaves toolbar in correct final state
1814 bool retval
= false;
1815 if (m_orientation
== wxHORIZONTAL
)
1817 if (RealizeHelper(dc
, false))
1819 m_vertHintSize
= GetSize();
1820 if (RealizeHelper(dc
, true))
1822 m_horzHintSize
= GetSize();
1829 if (RealizeHelper(dc
, true))
1831 m_horzHintSize
= GetSize();
1832 if (RealizeHelper(dc
, false))
1834 m_vertHintSize
= GetSize();
1844 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1846 // create the new sizer to add toolbar elements to
1847 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1850 int separatorSize
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1851 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1852 if (gripperSize
> 0 && m_gripperVisible
)
1855 m_gripperSizerItem
= sizer
->Add(gripperSize
, 1, 0, wxEXPAND
);
1857 m_gripperSizerItem
= sizer
->Add(1, gripperSize
, 0, wxEXPAND
);
1861 m_gripperSizerItem
= NULL
;
1864 // add "left" padding
1865 if (m_leftPadding
> 0)
1868 sizer
->Add(m_leftPadding
, 1);
1870 sizer
->Add(1, m_leftPadding
);
1874 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1876 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1877 wxSizerItem
* m_sizerItem
= NULL
;
1879 switch (item
.m_kind
)
1883 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1884 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1885 size
.y
+ (m_toolBorderPadding
*2),
1890 sizer
->AddSpacer(m_toolPacking
);
1900 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1901 m_sizerItem
= sizer
->Add(size
.x
+ (m_toolBorderPadding
*2),
1902 size
.y
+ (m_toolBorderPadding
*2),
1908 sizer
->AddSpacer(m_toolPacking
);
1914 case wxITEM_SEPARATOR
:
1917 m_sizerItem
= sizer
->Add(separatorSize
, 1, 0, wxEXPAND
);
1919 m_sizerItem
= sizer
->Add(1, separatorSize
, 0, wxEXPAND
);
1924 sizer
->AddSpacer(m_toolPacking
);
1931 if (item
.m_proportion
> 0)
1932 m_sizerItem
= sizer
->AddStretchSpacer(item
.m_proportion
);
1934 m_sizerItem
= sizer
->Add(item
.m_spacerPixels
, 1);
1937 case wxITEM_CONTROL
:
1939 //m_sizerItem = sizer->Add(item.m_window, item.m_proportion, wxEXPAND);
1940 wxSizerItem
* ctrl_m_sizerItem
;
1942 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1943 vert_sizer
->AddStretchSpacer(1);
1944 ctrl_m_sizerItem
= vert_sizer
->Add(item
.m_window
, 0, wxEXPAND
);
1945 vert_sizer
->AddStretchSpacer(1);
1946 if ( (m_style
& wxAUI_TB_TEXT
) &&
1947 m_toolTextOrientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1948 !item
.GetLabel().empty() )
1950 wxSize s
= GetLabelSize(item
.GetLabel());
1951 vert_sizer
->Add(1, s
.y
);
1955 m_sizerItem
= sizer
->Add(vert_sizer
, item
.m_proportion
, wxEXPAND
);
1957 wxSize min_size
= item
.m_minSize
;
1960 // proportional items will disappear from the toolbar if
1961 // their min width is not set to something really small
1962 if (item
.m_proportion
!= 0)
1967 if (min_size
.IsFullySpecified())
1969 m_sizerItem
->SetMinSize(min_size
);
1970 ctrl_m_sizerItem
->SetMinSize(min_size
);
1976 sizer
->AddSpacer(m_toolPacking
);
1981 item
.m_sizerItem
= m_sizerItem
;
1984 // add "right" padding
1985 if (m_rightPadding
> 0)
1988 sizer
->Add(m_rightPadding
, 1);
1990 sizer
->Add(1, m_rightPadding
);
1993 // add drop down area
1994 m_overflowSizerItem
= NULL
;
1996 if (m_style
& wxAUI_TB_OVERFLOW
)
1998 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1999 if (overflow_size
> 0 && m_overflowVisible
)
2002 m_overflowSizerItem
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2004 m_overflowSizerItem
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2008 m_overflowSizerItem
= NULL
;
2013 // the outside sizer helps us apply the "top" and "bottom" padding
2014 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2016 // add "top" padding
2017 if (m_topPadding
> 0)
2020 outside_sizer
->Add(1, m_topPadding
);
2022 outside_sizer
->Add(m_topPadding
, 1);
2025 // add the sizer that contains all of the toolbar elements
2026 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2028 // add "bottom" padding
2029 if (m_bottomPadding
> 0)
2032 outside_sizer
->Add(1, m_bottomPadding
);
2034 outside_sizer
->Add(m_bottomPadding
, 1);
2037 delete m_sizer
; // remove old sizer
2038 m_sizer
= outside_sizer
;
2040 // calculate the rock-bottom minimum size
2041 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2043 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2044 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2045 item
.m_sizerItem
->SetMinSize(0,0);
2048 m_absoluteMinSize
= m_sizer
->GetMinSize();
2050 // reset the min sizes to what they were
2051 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2053 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2054 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_minSize
.IsFullySpecified())
2055 item
.m_sizerItem
->SetMinSize(item
.m_minSize
);
2059 wxSize size
= m_sizer
->GetMinSize();
2060 m_minWidth
= size
.x
;
2061 m_minHeight
= size
.y
;
2063 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2065 wxSize curSize
= GetClientSize();
2066 wxSize new_size
= GetMinSize();
2067 if (new_size
!= curSize
)
2069 SetClientSize(new_size
);
2073 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2078 wxSize curSize
= GetClientSize();
2079 m_sizer
->SetDimension(0, 0, curSize
.x
, curSize
.y
);
2085 int wxAuiToolBar::GetOverflowState() const
2087 return m_overflowState
;
2090 wxRect
wxAuiToolBar::GetOverflowRect() const
2092 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2093 wxRect overflow_rect
= m_overflowSizerItem
->GetRect();
2094 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2096 if (m_orientation
== wxVERTICAL
)
2098 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2099 overflow_rect
.x
= 0;
2100 overflow_rect
.width
= cli_rect
.width
;
2101 overflow_rect
.height
= overflow_size
;
2105 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2106 overflow_rect
.y
= 0;
2107 overflow_rect
.width
= overflow_size
;
2108 overflow_rect
.height
= cli_rect
.height
;
2111 return overflow_rect
;
2114 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2116 wxClientDC
dc(this);
2119 int textWidth
= 0, textHeight
= 0;
2123 // get the text height
2124 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &textHeight
);
2126 // get the text width
2127 dc
.GetTextExtent(label
, &textWidth
, &ty
);
2129 return wxSize(textWidth
, textHeight
);
2133 void wxAuiToolBar::DoIdleUpdate()
2135 wxEvtHandler
* handler
= GetEventHandler();
2137 bool need_refresh
= false;
2140 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2142 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2144 if (item
.m_toolId
== -1)
2147 wxUpdateUIEvent
evt(item
.m_toolId
);
2148 evt
.SetEventObject(this);
2150 if (handler
->ProcessEvent(evt
))
2152 if (evt
.GetSetEnabled())
2156 is_enabled
= item
.m_window
->IsThisEnabled();
2158 is_enabled
= (item
.m_state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2160 bool new_enabled
= evt
.GetEnabled();
2161 if (new_enabled
!= is_enabled
)
2165 item
.m_window
->Enable(new_enabled
);
2170 item
.m_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2172 item
.m_state
|= wxAUI_BUTTON_STATE_DISABLED
;
2174 need_refresh
= true;
2178 if (evt
.GetSetChecked())
2180 // make sure we aren't checking an item that can't be
2181 if (item
.m_kind
!= wxITEM_CHECK
&& item
.m_kind
!= wxITEM_RADIO
)
2184 bool is_checked
= (item
.m_state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2185 bool new_checked
= evt
.GetChecked();
2187 if (new_checked
!= is_checked
)
2190 item
.m_state
|= wxAUI_BUTTON_STATE_CHECKED
;
2192 item
.m_state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2194 need_refresh
= true;
2209 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2212 GetClientSize(&x
, &y
);
2214 if (((x
>= y
) && m_absoluteMinSize
.x
> x
) ||
2215 ((y
> x
) && m_absoluteMinSize
.y
> y
))
2217 // hide all flexible items
2219 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2221 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2222 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && item
.m_sizerItem
->IsShown())
2224 item
.m_sizerItem
->Show(false);
2225 item
.m_sizerItem
->SetProportion(0);
2231 // show all flexible items
2233 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2235 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2236 if (item
.m_sizerItem
&& item
.m_proportion
> 0 && !item
.m_sizerItem
->IsShown())
2238 item
.m_sizerItem
->Show(true);
2239 item
.m_sizerItem
->SetProportion(item
.m_proportion
);
2244 m_sizer
->SetDimension(0, 0, x
, y
);
2249 // idle events aren't sent while user is resizing frame (why?),
2250 // but resizing toolbar here causes havoc,
2251 // so force idle handler to run after size handling complete
2252 QueueEvent(new wxIdleEvent
);
2257 void wxAuiToolBar::DoSetSize(int x
,
2263 wxSize parent_size
= GetParent()->GetClientSize();
2264 if (x
+ width
> parent_size
.x
)
2265 width
= wxMax(0, parent_size
.x
- x
);
2266 if (y
+ height
> parent_size
.y
)
2267 height
= wxMax(0, parent_size
.y
- y
);
2269 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2273 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2275 // if orientation doesn't match dock, fix it
2276 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2279 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2280 // pane state member is public, so it might have been changed
2281 // without going through wxPaneInfo::SetFlag() check
2282 bool ok
= pane
.IsOk();
2283 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2284 "window settings and pane settings are incompatible");
2287 wxOrientation newOrientation
= m_orientation
;
2288 if (pane
.IsDocked())
2290 switch (pane
.dock_direction
)
2292 case wxAUI_DOCK_TOP
:
2293 case wxAUI_DOCK_BOTTOM
:
2294 newOrientation
= wxHORIZONTAL
;
2296 case wxAUI_DOCK_LEFT
:
2297 case wxAUI_DOCK_RIGHT
:
2298 newOrientation
= wxVERTICAL
;
2301 wxFAIL_MSG("invalid dock location value");
2304 else if (pane
.IsResizable() &&
2305 GetOrientation(m_style
) == wxBOTH
)
2307 // changing orientation in OnSize causes havoc
2309 GetClientSize(&x
, &y
);
2313 newOrientation
= wxHORIZONTAL
;
2317 newOrientation
= wxVERTICAL
;
2320 if (newOrientation
!= m_orientation
)
2322 SetOrientation(newOrientation
);
2324 if (newOrientation
== wxHORIZONTAL
)
2326 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2330 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2332 if (pane
.IsDocked())
2334 pane
.floating_size
= wxDefaultSize
;
2338 SetSize(GetParent()->GetClientSize());
2347 void wxAuiToolBar::UpdateWindowUI(long flags
)
2349 if ( flags
& wxUPDATE_UI_FROMIDLE
)
2354 wxControl::UpdateWindowUI(flags
);
2357 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2359 wxAutoBufferedPaintDC
dc(this);
2360 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2363 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2366 m_art
->DrawBackground(dc
, this, cli_rect
);
2368 int gripperSize
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2369 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2371 // paint the gripper
2372 if (gripperSize
> 0 && m_gripperSizerItem
)
2374 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2376 gripper_rect
.width
= gripperSize
;
2378 gripper_rect
.height
= gripperSize
;
2379 m_art
->DrawGripper(dc
, this, gripper_rect
);
2382 // calculated how far we can draw items
2385 last_extent
= cli_rect
.width
;
2387 last_extent
= cli_rect
.height
;
2388 if (m_overflowVisible
)
2389 last_extent
-= dropdown_size
;
2391 // paint each individual tool
2392 size_t i
, count
= m_items
.GetCount();
2393 for (i
= 0; i
< count
; ++i
)
2395 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2397 if (!item
.m_sizerItem
)
2400 wxRect item_rect
= item
.m_sizerItem
->GetRect();
2403 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2404 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2409 if (item
.m_kind
== wxITEM_SEPARATOR
)
2412 m_art
->DrawSeparator(dc
, this, item_rect
);
2414 else if (item
.m_kind
== wxITEM_LABEL
)
2416 // draw a text label only
2417 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2419 else if (item
.m_kind
== wxITEM_NORMAL
)
2421 // draw a regular button or dropdown button
2422 if (!item
.m_dropDown
)
2423 m_art
->DrawButton(dc
, this, item
, item_rect
);
2425 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2427 else if (item
.m_kind
== wxITEM_CHECK
)
2429 // draw either a regular or dropdown toggle button
2430 if (!item
.m_dropDown
)
2431 m_art
->DrawButton(dc
, this, item
, item_rect
);
2433 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2435 else if (item
.m_kind
== wxITEM_RADIO
)
2437 // draw a toggle button
2438 m_art
->DrawButton(dc
, this, item
, item_rect
);
2440 else if (item
.m_kind
== wxITEM_CONTROL
)
2442 // draw the control's label
2443 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2446 // fire a signal to see if the item wants to be custom-rendered
2447 OnCustomRender(dc
, item
, item_rect
);
2450 // paint the overflow button
2451 if (dropdown_size
> 0 && m_overflowSizerItem
)
2453 wxRect dropDownRect
= GetOverflowRect();
2454 m_art
->DrawOverflowButton(dc
, this, dropDownRect
, m_overflowState
);
2458 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2463 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2465 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2467 if (m_gripperSizerItem
)
2469 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2470 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2473 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2477 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2478 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2480 // gripper was clicked
2481 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2486 if (m_overflowSizerItem
)
2488 wxRect overflow_rect
= GetOverflowRect();
2491 m_overflowVisible
&&
2492 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2494 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2495 e
.SetEventObject(this);
2497 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2498 bool processed
= GetEventHandler()->ProcessEvent(e
);
2507 wxAuiToolBarItemArray overflow_items
;
2510 // add custom overflow prepend items, if any
2511 count
= m_customOverflowPrepend
.GetCount();
2512 for (i
= 0; i
< count
; ++i
)
2513 overflow_items
.Add(m_customOverflowPrepend
[i
]);
2515 // only show items that don't fit in the dropdown
2516 count
= m_items
.GetCount();
2517 for (i
= 0; i
< count
; ++i
)
2519 if (!GetToolFitsByIndex(i
))
2520 overflow_items
.Add(m_items
[i
]);
2523 // add custom overflow append items, if any
2524 count
= m_customOverflowAppend
.GetCount();
2525 for (i
= 0; i
< count
; ++i
)
2526 overflow_items
.Add(m_customOverflowAppend
[i
]);
2528 int res
= m_art
->ShowDropDown(this, overflow_items
);
2529 m_overflowState
= 0;
2533 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2534 e
.SetEventObject(this);
2535 GetParent()->GetEventHandler()->ProcessEvent(e
);
2544 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2545 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2549 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2551 m_actionPos
= wxPoint(-1,-1);
2552 m_actionItem
= NULL
;
2558 // fire the tool dropdown event
2559 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_actionItem
->m_toolId
);
2560 e
.SetEventObject(this);
2561 e
.SetToolId(m_actionItem
->m_toolId
);
2563 int mouse_x
= evt
.GetX();
2564 wxRect rect
= m_actionItem
->m_sizerItem
->GetRect();
2565 const bool dropDownHit
= m_actionItem
->m_dropDown
&&
2566 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2567 mouse_x
< (rect
.x
+rect
.width
);
2568 e
.SetDropDownClicked(dropDownHit
);
2570 e
.SetClickPoint(evt
.GetPosition());
2571 e
.SetItemRect(rect
);
2573 // we only set the 'pressed button' state if we hit the actual button
2574 // and not just the drop-down
2575 SetPressedItem(dropDownHit
? 0 : m_actionItem
);
2579 m_actionPos
= wxPoint(-1,-1);
2580 m_actionItem
= NULL
;
2583 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2586 // Ensure hovered item is really ok, as mouse may have moved during
2588 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2589 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2595 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2600 SetPressedItem(NULL
);
2602 wxAuiToolBarItem
* hitItem
;
2603 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2604 SetHoverItem(hitItem
);
2608 // TODO: it would make sense to send out an 'END_DRAG' event here,
2609 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2612 // OnCaptureLost() will be called now and this will reset all our state
2613 // tracking variables
2618 if (m_actionItem
&& hitItem
== m_actionItem
)
2622 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_actionItem
->m_toolId
);
2623 e
.SetEventObject(this);
2625 if (hitItem
->m_kind
== wxITEM_CHECK
|| hitItem
->m_kind
== wxITEM_RADIO
)
2627 const bool toggle
= !(m_actionItem
->m_state
& wxAUI_BUTTON_STATE_CHECKED
);
2629 ToggleTool(m_actionItem
->m_toolId
, toggle
);
2631 // repaint immediately
2638 // we have to release the mouse *before* sending the event, because
2639 // we don't know what a handler might do. It could open up a popup
2640 // menu for example and that would make us lose our capture anyway.
2644 GetEventHandler()->ProcessEvent(e
);
2646 // Ensure hovered item is really ok, as mouse may have moved during
2648 wxPoint cursor_pos_after_evt
= ScreenToClient(wxGetMousePosition());
2649 SetHoverItem(FindToolByPosition(cursor_pos_after_evt
.x
, cursor_pos_after_evt
.y
));
2658 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2660 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2662 if (m_gripperSizerItem
)
2664 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2665 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2669 if (m_overflowSizerItem
&& m_art
)
2671 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2672 if (dropdown_size
> 0 &&
2673 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2675 evt
.m_y
< cli_rect
.height
)
2681 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2682 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2684 if (m_actionItem
&& m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2686 m_actionPos
= wxPoint(-1,-1);
2687 m_actionItem
= NULL
;
2694 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2696 wxAuiToolBarItem
* hitItem
;
2697 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2699 if (m_actionItem
&& hitItem
== m_actionItem
)
2701 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_actionItem
->m_toolId
);
2702 e
.SetEventObject(this);
2703 e
.SetToolId(m_actionItem
->m_toolId
);
2704 e
.SetClickPoint(m_actionPos
);
2705 GetEventHandler()->ProcessEvent(e
);
2710 // right-clicked on the invalid area of the toolbar
2711 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2712 e
.SetEventObject(this);
2714 e
.SetClickPoint(m_actionPos
);
2715 GetEventHandler()->ProcessEvent(e
);
2719 // reset member variables
2720 m_actionPos
= wxPoint(-1,-1);
2721 m_actionItem
= NULL
;
2724 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2726 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2728 if (m_gripperSizerItem
)
2730 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2731 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2735 if (m_overflowSizerItem
&& m_art
)
2737 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2738 if (dropdown_size
> 0 &&
2739 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2741 evt
.m_y
< cli_rect
.height
)
2747 m_actionPos
= wxPoint(evt
.GetX(), evt
.GetY());
2748 m_actionItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2752 if (m_actionItem
->m_state
& wxAUI_BUTTON_STATE_DISABLED
)
2754 m_actionPos
= wxPoint(-1,-1);
2755 m_actionItem
= NULL
;
2763 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2765 wxAuiToolBarItem
* hitItem
;
2766 hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2768 if (m_actionItem
&& hitItem
== m_actionItem
)
2770 if (hitItem
->m_kind
== wxITEM_NORMAL
)
2772 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_actionItem
->m_toolId
);
2773 e
.SetEventObject(this);
2774 e
.SetToolId(m_actionItem
->m_toolId
);
2775 e
.SetClickPoint(m_actionPos
);
2776 GetEventHandler()->ProcessEvent(e
);
2781 // reset member variables
2782 m_actionPos
= wxPoint(-1,-1);
2783 m_actionItem
= NULL
;
2786 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2788 const bool button_pressed
= HasCapture();
2790 // start a drag event
2791 if (!m_dragging
&& button_pressed
&&
2792 abs(evt
.GetX() - m_actionPos
.x
) + abs(evt
.GetY() - m_actionPos
.y
) > 5)
2794 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2795 // event sent sometime in the future (see OnLeftUp())
2796 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2797 e
.SetEventObject(this);
2798 e
.SetToolId(m_actionItem
->m_toolId
);
2799 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2807 wxAuiToolBarItem
* hitItem
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2810 // if we have a button pressed we want it to be shown in 'depressed'
2811 // state unless we move the mouse outside the button, then we want it
2812 // to show as just 'highlighted'
2813 if (hitItem
== m_actionItem
)
2814 SetPressedItem(m_actionItem
);
2817 SetPressedItem(NULL
);
2818 SetHoverItem(m_actionItem
);
2823 SetHoverItem(hitItem
);
2825 // tooltips handling
2826 wxAuiToolBarItem
* packingHitItem
;
2827 packingHitItem
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2830 if (packingHitItem
!= m_tipItem
)
2832 m_tipItem
= packingHitItem
;
2834 if ( !packingHitItem
->m_shortHelp
.empty() )
2835 SetToolTip(packingHitItem
->m_shortHelp
);
2846 // figure out the dropdown button state (are we hovering or pressing it?)
2847 RefreshOverflowState();
2851 void wxAuiToolBar::DoResetMouseState()
2853 RefreshOverflowState();
2855 SetPressedItem(NULL
);
2859 // we have to reset those here, because the mouse-up handlers which do
2860 // it usually won't be called if we let go of a mouse button while we
2861 // are outside of the window
2862 m_actionPos
= wxPoint(-1,-1);
2863 m_actionItem
= NULL
;
2866 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2874 DoResetMouseState();
2877 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2881 DoResetMouseState();
2884 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2886 wxCursor cursor
= wxNullCursor
;
2888 if (m_gripperSizerItem
)
2890 wxRect gripper_rect
= m_gripperSizerItem
->GetRect();
2891 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2893 cursor
= wxCursor(wxCURSOR_SIZING
);
2897 evt
.SetCursor(cursor
);