1 ///////////////////////////////////////////////////////////////////////////////
3 // Name: src/aui/dockart.cpp
4 // Purpose: wxaui: wx advanced user interface - docking window manager
5 // Author: Benjamin I. Williams
9 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
10 // Licence: wxWindows Library Licence, Version 3.1
11 ///////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
29 #include "wx/statline.h"
30 #include "wx/dcbuffer.h"
33 #include "wx/settings.h"
36 #include "wx/aui/auibar.h"
37 #include "wx/aui/framemanager.h"
40 #include "wx/osx/private.h"
43 #include "wx/arrimpl.cpp"
44 WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray
)
47 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
48 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
49 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
50 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
51 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent
);
54 IMPLEMENT_CLASS(wxAuiToolBar
, wxControl
)
55 IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent
, wxEvent
)
58 // missing wxITEM_* items
61 wxITEM_CONTROL
= wxITEM_MAX
,
66 const int BUTTON_DROPDOWN_WIDTH
= 10;
69 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
70 const wxColour
& color
);
72 unsigned char wxAuiBlendColour(unsigned char fg
, unsigned char bg
, double alpha
);
73 wxColor
wxAuiStepColour(const wxColor
& c
, int percent
);
75 static wxBitmap
MakeDisabledBitmap(wxBitmap
& bmp
)
77 wxImage image
= bmp
.ConvertToImage();
80 mr
= image
.GetMaskRed();
81 mg
= image
.GetMaskGreen();
82 mb
= image
.GetMaskBlue();
84 unsigned char* data
= image
.GetData();
85 int width
= image
.GetWidth();
86 int height
= image
.GetHeight();
87 bool has_mask
= image
.HasMask();
89 for (int y
= height
-1; y
>= 0; --y
)
91 for (int x
= width
-1; x
>= 0; --x
)
93 data
= image
.GetData() + (y
*(width
*3))+(x
*3);
94 unsigned char* r
= data
;
95 unsigned char* g
= data
+1;
96 unsigned char* b
= data
+2;
98 if (has_mask
&& *r
== mr
&& *g
== mg
&& *b
== mb
)
101 *r
= wxAuiBlendColour(*r
, 255, 0.4);
102 *g
= wxAuiBlendColour(*g
, 255, 0.4);
103 *b
= wxAuiBlendColour(*b
, 255, 0.4);
107 return wxBitmap(image
);
110 static wxColor
GetBaseColor()
113 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
114 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
116 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
119 // the base_colour is too pale to use as our base colour,
120 // so darken it a bit --
121 if ((255-base_colour
.Red()) +
122 (255-base_colour
.Green()) +
123 (255-base_colour
.Blue()) < 60)
125 base_colour
= wxAuiStepColour(base_colour
, 92);
133 class ToolbarCommandCapture
: public wxEvtHandler
137 ToolbarCommandCapture() { m_last_id
= 0; }
138 int GetCommandId() const { return m_last_id
; }
140 bool ProcessEvent(wxEvent
& evt
)
142 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
144 m_last_id
= evt
.GetId();
148 if (GetNextHandler())
149 return GetNextHandler()->ProcessEvent(evt
);
160 static const unsigned char
161 DISABLED_TEXT_GREY_HUE
= wxAuiBlendColour(0, 255, 0.4);
162 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
163 DISABLED_TEXT_GREY_HUE
,
164 DISABLED_TEXT_GREY_HUE
);
166 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
168 m_base_colour
= GetBaseColor();
171 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
172 m_highlight_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
174 m_separator_size
= 7;
176 m_overflow_size
= 16;
178 wxColor darker1_colour
= wxAuiStepColour(m_base_colour
, 85);
179 wxColor darker2_colour
= wxAuiStepColour(m_base_colour
, 75);
180 wxColor darker3_colour
= wxAuiStepColour(m_base_colour
, 60);
181 wxColor darker4_colour
= wxAuiStepColour(m_base_colour
, 50);
182 wxColor darker5_colour
= wxAuiStepColour(m_base_colour
, 40);
184 m_gripper_pen1
= wxPen(darker5_colour
);
185 m_gripper_pen2
= wxPen(darker3_colour
);
186 m_gripper_pen3
= *wxWHITE_PEN
;
188 static const unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
189 static const unsigned char overflow_bits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
191 m_button_dropdown_bmp
= wxAuiBitmapFromBits(button_dropdown_bits
, 5, 3,
193 m_disabled_button_dropdown_bmp
= wxAuiBitmapFromBits(
194 button_dropdown_bits
, 5, 3,
195 wxColor(128,128,128));
196 m_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, *wxBLACK
);
197 m_disabled_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, wxColor(128,128,128));
199 m_font
= *wxNORMAL_FONT
;
202 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
204 m_font
= *wxNORMAL_FONT
;
208 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
210 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
213 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
218 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
223 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
225 m_text_orientation
= orientation
;
228 unsigned int wxAuiDefaultToolBarArt::GetFlags()
233 wxFont
wxAuiDefaultToolBarArt::GetFont()
238 int wxAuiDefaultToolBarArt::GetTextOrientation()
240 return m_text_orientation
;
243 void wxAuiDefaultToolBarArt::DrawBackground(
245 wxWindow
* WXUNUSED(wnd
),
250 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 150);
251 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 90);
252 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
255 void wxAuiDefaultToolBarArt::DrawLabel(
257 wxWindow
* WXUNUSED(wnd
),
258 const wxAuiToolBarItem
& item
,
262 dc
.SetTextForeground(*wxBLACK
);
264 // we only care about the text height here since the text
265 // will get cropped based on the width of the item
266 int text_width
= 0, text_height
= 0;
267 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
269 // set the clipping region
270 wxRect clip_rect
= rect
;
271 clip_rect
.width
-= 1;
272 dc
.SetClippingRegion(clip_rect
);
276 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
277 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
278 dc
.DestroyClippingRegion();
282 void wxAuiDefaultToolBarArt::DrawButton(
284 wxWindow
* WXUNUSED(wnd
),
285 const wxAuiToolBarItem
& item
,
288 int text_width
= 0, text_height
= 0;
290 if (m_flags
& wxAUI_TB_TEXT
)
296 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
298 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
301 int bmp_x
= 0, bmp_y
= 0;
302 int text_x
= 0, text_y
= 0;
304 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
308 (item
.GetBitmap().GetWidth()/2);
311 ((rect
.height
-text_height
)/2) -
312 (item
.GetBitmap().GetHeight()/2);
314 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
315 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
317 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
323 (item
.GetBitmap().GetHeight()/2);
325 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
332 if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
))
334 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
336 dc
.SetPen(wxPen(m_highlight_colour
));
337 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 150)));
338 dc
.DrawRectangle(rect
);
340 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
342 dc
.SetPen(wxPen(m_highlight_colour
));
343 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
345 // draw an even lighter background for checked item hovers (since
346 // the hover background is the same color as the check background)
347 if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
348 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 180)));
350 dc
.DrawRectangle(rect
);
352 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
354 // it's important to put this code in an else statment after the
355 // hover, otherwise hovers won't draw properly for checked items
356 dc
.SetPen(wxPen(m_highlight_colour
));
357 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
358 dc
.DrawRectangle(rect
);
363 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
364 bmp
= item
.GetDisabledBitmap();
366 bmp
= item
.GetBitmap();
371 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
373 // set the item's text color based on if it is disabled
374 dc
.SetTextForeground(*wxBLACK
);
375 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
376 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
378 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
380 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
385 void wxAuiDefaultToolBarArt::DrawDropDownButton(
387 wxWindow
* WXUNUSED(wnd
),
388 const wxAuiToolBarItem
& item
,
391 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
392 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
394 wxRect button_rect
= wxRect(rect
.x
,
396 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
398 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
400 BUTTON_DROPDOWN_WIDTH
+1,
403 if (m_flags
& wxAUI_TB_TEXT
)
408 if (m_flags
& wxAUI_TB_TEXT
)
410 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
414 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
419 dropbmp_x
= dropdown_rect
.x
+
420 (dropdown_rect
.width
/2) -
421 (m_button_dropdown_bmp
.GetWidth()/2);
422 dropbmp_y
= dropdown_rect
.y
+
423 (dropdown_rect
.height
/2) -
424 (m_button_dropdown_bmp
.GetHeight()/2);
427 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
429 bmp_x
= button_rect
.x
+
430 (button_rect
.width
/2) -
431 (item
.GetBitmap().GetWidth()/2);
432 bmp_y
= button_rect
.y
+
433 ((button_rect
.height
-text_height
)/2) -
434 (item
.GetBitmap().GetHeight()/2);
436 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
437 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
439 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
445 (item
.GetBitmap().GetHeight()/2);
447 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
454 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
456 dc
.SetPen(wxPen(m_highlight_colour
));
457 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 140)));
458 dc
.DrawRectangle(button_rect
);
460 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
461 dc
.DrawRectangle(dropdown_rect
);
463 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
466 dc
.SetPen(wxPen(m_highlight_colour
));
467 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
468 dc
.DrawRectangle(button_rect
);
469 dc
.DrawRectangle(dropdown_rect
);
474 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
476 bmp
= item
.GetDisabledBitmap();
477 dropbmp
= m_disabled_button_dropdown_bmp
;
481 bmp
= item
.GetBitmap();
482 dropbmp
= m_button_dropdown_bmp
;
488 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
489 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
491 // set the item's text color based on if it is disabled
492 dc
.SetTextForeground(*wxBLACK
);
493 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
494 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
496 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
498 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
502 void wxAuiDefaultToolBarArt::DrawControlLabel(
504 wxWindow
* WXUNUSED(wnd
),
505 const wxAuiToolBarItem
& item
,
508 if (!(m_flags
& wxAUI_TB_TEXT
))
511 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
514 int text_x
= 0, text_y
= 0;
515 int text_width
= 0, text_height
= 0;
520 if (m_flags
& wxAUI_TB_TEXT
)
522 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
526 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
528 // don't draw the label if it is wider than the item width
529 if (text_width
> rect
.width
)
532 // set the label's text color
533 dc
.SetTextForeground(*wxBLACK
);
535 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
536 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
538 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
540 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
544 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
546 wxWindow
* WXUNUSED(wnd
),
547 const wxAuiToolBarItem
& item
)
551 // get label's height
552 int width
= 0, height
= 0;
553 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
556 width
= item
.GetMinSize().GetWidth();
560 // no width specified, measure the text ourselves
561 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
564 return wxSize(width
, height
);
567 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
569 wxWindow
* WXUNUSED(wnd
),
570 const wxAuiToolBarItem
& item
)
572 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
573 return wxSize(16,16);
575 int width
= item
.GetBitmap().GetWidth();
576 int height
= item
.GetBitmap().GetHeight();
578 if (m_flags
& wxAUI_TB_TEXT
)
583 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
585 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
588 if ( !item
.GetLabel().empty() )
590 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
591 width
= wxMax(width
, tx
+6);
594 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
595 !item
.GetLabel().empty() )
597 width
+= 3; // space between left border and bitmap
598 width
+= 3; // space between bitmap and text
600 if ( !item
.GetLabel().empty() )
602 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
604 height
= wxMax(height
, ty
);
609 // if the tool has a dropdown button, add it to the width
610 if (item
.HasDropDown())
611 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
613 return wxSize(width
, height
);
616 void wxAuiDefaultToolBarArt::DrawSeparator(
618 wxWindow
* WXUNUSED(wnd
),
621 bool horizontal
= true;
622 if (m_flags
& wxAUI_TB_VERTICAL
)
629 rect
.x
+= (rect
.width
/2);
631 int new_height
= (rect
.height
*3)/4;
632 rect
.y
+= (rect
.height
/2) - (new_height
/2);
633 rect
.height
= new_height
;
637 rect
.y
+= (rect
.height
/2);
639 int new_width
= (rect
.width
*3)/4;
640 rect
.x
+= (rect
.width
/2) - (new_width
/2);
641 rect
.width
= new_width
;
644 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 80);
645 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 80);
646 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
649 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
650 wxWindow
* WXUNUSED(wnd
),
658 if (m_flags
& wxAUI_TB_VERTICAL
)
660 x
= rect
.x
+ (i
*4) + 5;
662 if (x
> rect
.GetWidth()-5)
668 y
= rect
.y
+ (i
*4) + 5;
669 if (y
> rect
.GetHeight()-5)
673 dc
.SetPen(m_gripper_pen1
);
675 dc
.SetPen(m_gripper_pen2
);
676 dc
.DrawPoint(x
, y
+1);
677 dc
.DrawPoint(x
+1, y
);
678 dc
.SetPen(m_gripper_pen3
);
679 dc
.DrawPoint(x
+2, y
+1);
680 dc
.DrawPoint(x
+2, y
+2);
681 dc
.DrawPoint(x
+1, y
+2);
688 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
693 if (state
& wxAUI_BUTTON_STATE_HOVER
||
694 state
& wxAUI_BUTTON_STATE_PRESSED
)
696 wxRect cli_rect
= wnd
->GetClientRect();
697 wxColor light_gray_bg
= wxAuiStepColour(m_highlight_colour
, 170);
699 if (m_flags
& wxAUI_TB_VERTICAL
)
701 dc
.SetPen(wxPen(m_highlight_colour
));
702 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
703 dc
.SetPen(wxPen(light_gray_bg
));
704 dc
.SetBrush(wxBrush(light_gray_bg
));
705 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
709 dc
.SetPen(wxPen(m_highlight_colour
));
710 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
711 dc
.SetPen(wxPen(light_gray_bg
));
712 dc
.SetBrush(wxBrush(light_gray_bg
));
713 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
717 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
718 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
719 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
722 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
726 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
727 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
728 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
733 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
737 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
; break;
738 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
; break;
739 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
; break;
743 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
744 const wxAuiToolBarItemArray
& items
)
748 size_t items_added
= 0;
750 size_t i
, count
= items
.GetCount();
751 for (i
= 0; i
< count
; ++i
)
753 wxAuiToolBarItem
& item
= items
.Item(i
);
755 if (item
.GetKind() == wxITEM_NORMAL
)
757 wxString text
= item
.GetShortHelp();
759 text
= item
.GetLabel();
764 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
766 m
->SetBitmap(item
.GetBitmap());
770 else if (item
.GetKind() == wxITEM_SEPARATOR
)
773 menuPopup
.AppendSeparator();
777 // find out where to put the popup menu of window items
778 wxPoint pt
= ::wxGetMousePosition();
779 pt
= wnd
->ScreenToClient(pt
);
781 // find out the screen coordinate at the bottom of the tab ctrl
782 wxRect cli_rect
= wnd
->GetClientRect();
783 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
785 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
786 wnd
->PushEventHandler(cc
);
787 wnd
->PopupMenu(&menuPopup
, pt
);
788 int command
= cc
->GetCommandId();
789 wnd
->PopEventHandler(true);
797 static wxOrientation
GetOrientation(long& style
)
799 switch (style
& wxAUI_ORIENTATION_MASK
)
801 case wxAUI_TB_HORIZONTAL
:
803 case wxAUI_TB_VERTICAL
:
806 wxFAIL_MSG("toolbar cannot be locked in both horizontal and vertical orientations (maybe no lock was intended?)");
813 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
814 EVT_SIZE(wxAuiToolBar::OnSize
)
815 EVT_IDLE(wxAuiToolBar::OnIdle
)
816 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
817 EVT_PAINT(wxAuiToolBar::OnPaint
)
818 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
819 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
820 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
821 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
822 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
823 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
824 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
825 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
826 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
827 EVT_MOTION(wxAuiToolBar::OnMotion
)
828 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
829 EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost
)
830 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
834 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
836 const wxPoint
& position
,
843 style
| wxBORDER_NONE
)
845 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
847 m_button_height
= -1;
848 m_sizer_element_count
= 0;
849 m_action_pos
= wxPoint(-1,-1);
850 m_action_item
= NULL
;
852 m_art
= new wxAuiDefaultToolBarArt
;
854 m_tool_border_padding
= 3;
855 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
856 m_gripper_sizer_item
= NULL
;
857 m_overflow_sizer_item
= NULL
;
859 m_orientation
= GetOrientation(style
);
860 if (m_orientation
== wxBOTH
)
862 m_orientation
= wxHORIZONTAL
;
864 m_style
= style
| wxBORDER_NONE
;
865 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
866 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
867 m_overflow_state
= 0;
868 SetMargins(5, 5, 2, 2);
869 SetFont(*wxNORMAL_FONT
);
871 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
872 if (style
& wxAUI_TB_HORZ_LAYOUT
)
873 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
874 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
878 wxAuiToolBar::~wxAuiToolBar()
884 void wxAuiToolBar::SetWindowStyleFlag(long style
)
886 GetOrientation(style
); // assert if style is invalid
887 wxCHECK_RET(IsPaneValid(style
),
888 "window settings and pane settings are incompatible");
890 wxControl::SetWindowStyleFlag(style
);
899 if (m_style
& wxAUI_TB_GRIPPER
)
900 m_gripper_visible
= true;
902 m_gripper_visible
= false;
905 if (m_style
& wxAUI_TB_OVERFLOW
)
906 m_overflow_visible
= true;
908 m_overflow_visible
= false;
910 if (style
& wxAUI_TB_HORZ_LAYOUT
)
911 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
913 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
916 long wxAuiToolBar::GetWindowStyleFlag() const
921 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
930 m_art
->SetTextOrientation(m_tool_text_orientation
);
934 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
942 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
943 const wxString
& label
,
944 const wxBitmap
& bitmap
,
945 const wxString
& short_help_string
,
948 return AddTool(tool_id
,
959 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
960 const wxString
& label
,
961 const wxBitmap
& bitmap
,
962 const wxBitmap
& disabled_bitmap
,
964 const wxString
& short_help_string
,
965 const wxString
& long_help_string
,
966 wxObject
* WXUNUSED(client_data
))
968 wxAuiToolBarItem item
;
971 item
.bitmap
= bitmap
;
972 item
.disabled_bitmap
= disabled_bitmap
;
973 item
.short_help
= short_help_string
;
974 item
.long_help
= long_help_string
;
976 item
.dropdown
= false;
977 item
.spacer_pixels
= 0;
982 item
.sizer_item
= NULL
;
983 item
.min_size
= wxDefaultSize
;
987 if (item
.id
== wxID_ANY
)
990 if (!item
.disabled_bitmap
.IsOk())
992 // no disabled bitmap specified, we need to make one
993 if (item
.bitmap
.IsOk())
995 //wxImage img = item.bitmap.ConvertToImage();
996 //wxImage grey_version = img.ConvertToGreyscale();
997 //item.disabled_bitmap = wxBitmap(grey_version);
998 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
1002 return &m_items
.Last();
1005 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
1006 const wxString
& label
)
1008 wxAuiToolBarItem item
;
1009 item
.window
= (wxWindow
*)control
;
1011 item
.bitmap
= wxNullBitmap
;
1012 item
.disabled_bitmap
= wxNullBitmap
;
1014 item
.dropdown
= false;
1015 item
.spacer_pixels
= 0;
1016 item
.id
= control
->GetId();
1018 item
.proportion
= 0;
1019 item
.kind
= wxITEM_CONTROL
;
1020 item
.sizer_item
= NULL
;
1021 item
.min_size
= control
->GetEffectiveMinSize();
1023 item
.sticky
= false;
1026 return &m_items
.Last();
1029 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1030 const wxString
& label
,
1033 wxSize min_size
= wxDefaultSize
;
1037 wxAuiToolBarItem item
;
1040 item
.bitmap
= wxNullBitmap
;
1041 item
.disabled_bitmap
= wxNullBitmap
;
1043 item
.dropdown
= false;
1044 item
.spacer_pixels
= 0;
1047 item
.proportion
= 0;
1048 item
.kind
= wxITEM_LABEL
;
1049 item
.sizer_item
= NULL
;
1050 item
.min_size
= min_size
;
1052 item
.sticky
= false;
1054 if (item
.id
== wxID_ANY
)
1055 item
.id
= wxNewId();
1058 return &m_items
.Last();
1061 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1063 wxAuiToolBarItem item
;
1065 item
.label
= wxEmptyString
;
1066 item
.bitmap
= wxNullBitmap
;
1067 item
.disabled_bitmap
= wxNullBitmap
;
1069 item
.dropdown
= false;
1072 item
.proportion
= 0;
1073 item
.kind
= wxITEM_SEPARATOR
;
1074 item
.sizer_item
= NULL
;
1075 item
.min_size
= wxDefaultSize
;
1077 item
.sticky
= false;
1080 return &m_items
.Last();
1083 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1085 wxAuiToolBarItem item
;
1087 item
.label
= wxEmptyString
;
1088 item
.bitmap
= wxNullBitmap
;
1089 item
.disabled_bitmap
= wxNullBitmap
;
1091 item
.dropdown
= false;
1092 item
.spacer_pixels
= pixels
;
1095 item
.proportion
= 0;
1096 item
.kind
= wxITEM_SPACER
;
1097 item
.sizer_item
= NULL
;
1098 item
.min_size
= wxDefaultSize
;
1100 item
.sticky
= false;
1103 return &m_items
.Last();
1106 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1108 wxAuiToolBarItem item
;
1110 item
.label
= wxEmptyString
;
1111 item
.bitmap
= wxNullBitmap
;
1112 item
.disabled_bitmap
= wxNullBitmap
;
1114 item
.dropdown
= false;
1115 item
.spacer_pixels
= 0;
1118 item
.proportion
= proportion
;
1119 item
.kind
= wxITEM_SPACER
;
1120 item
.sizer_item
= NULL
;
1121 item
.min_size
= wxDefaultSize
;
1123 item
.sticky
= false;
1126 return &m_items
.Last();
1129 void wxAuiToolBar::Clear()
1132 m_sizer_element_count
= 0;
1135 bool wxAuiToolBar::DeleteTool(int tool_id
)
1137 int idx
= GetToolIndex(tool_id
);
1138 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1140 m_items
.RemoveAt(idx
);
1148 bool wxAuiToolBar::DeleteByIndex(int idx
)
1150 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1152 m_items
.RemoveAt(idx
);
1161 wxControl
* wxAuiToolBar::FindControl(int id
)
1163 wxWindow
* wnd
= FindWindow(id
);
1164 return (wxControl
*)wnd
;
1167 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1170 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1172 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1173 if (item
.id
== tool_id
)
1180 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1183 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1185 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1187 if (!item
.sizer_item
)
1190 wxRect rect
= item
.sizer_item
->GetRect();
1191 if (rect
.Contains(x
,y
))
1193 // if the item doesn't fit on the toolbar, return NULL
1194 if (!GetToolFitsByIndex(i
))
1204 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1207 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1209 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1211 if (!item
.sizer_item
)
1214 wxRect rect
= item
.sizer_item
->GetRect();
1216 // apply tool packing
1218 rect
.width
+= m_tool_packing
;
1220 if (rect
.Contains(x
,y
))
1222 // if the item doesn't fit on the toolbar, return NULL
1223 if (!GetToolFitsByIndex(i
))
1233 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1238 if (idx
>= (int)m_items
.size())
1241 return &(m_items
[idx
]);
1244 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1246 // TODO: wxToolBar compatibility
1249 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1251 // TODO: wxToolBar compatibility
1252 return wxSize(16,15);
1255 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1257 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1261 item
->proportion
= proportion
;
1264 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1266 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1270 return item
->proportion
;
1273 void wxAuiToolBar::SetToolSeparation(int separation
)
1276 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1279 int wxAuiToolBar::GetToolSeparation() const
1282 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1288 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1290 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1294 item
->dropdown
= dropdown
;
1297 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1299 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1303 return item
->dropdown
;
1306 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1308 // ignore separators
1312 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1316 if (item
->sticky
== sticky
)
1319 item
->sticky
= sticky
;
1325 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1327 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1331 return item
->sticky
;
1337 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1339 m_tool_border_padding
= padding
;
1342 int wxAuiToolBar::GetToolBorderPadding() const
1344 return m_tool_border_padding
;
1347 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1349 m_tool_text_orientation
= orientation
;
1353 m_art
->SetTextOrientation(orientation
);
1357 int wxAuiToolBar::GetToolTextOrientation() const
1359 return m_tool_text_orientation
;
1362 void wxAuiToolBar::SetToolPacking(int packing
)
1364 m_tool_packing
= packing
;
1367 int wxAuiToolBar::GetToolPacking() const
1369 return m_tool_packing
;
1373 void wxAuiToolBar::SetOrientation(int orientation
)
1375 wxCHECK_RET(orientation
== wxHORIZONTAL
||
1376 orientation
== wxVERTICAL
,
1377 "invalid orientation value");
1378 if (orientation
!= m_orientation
)
1380 m_orientation
= wxOrientation(orientation
);
1385 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1388 m_left_padding
= left
;
1390 m_right_padding
= right
;
1392 m_top_padding
= top
;
1394 m_bottom_padding
= bottom
;
1397 bool wxAuiToolBar::GetGripperVisible() const
1399 return m_gripper_visible
;
1402 void wxAuiToolBar::SetGripperVisible(bool visible
)
1404 m_gripper_visible
= visible
;
1406 m_style
|= wxAUI_TB_GRIPPER
;
1408 m_style
&= ~wxAUI_TB_GRIPPER
;
1414 bool wxAuiToolBar::GetOverflowVisible() const
1416 return m_overflow_visible
;
1419 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1421 m_overflow_visible
= visible
;
1423 m_style
|= wxAUI_TB_OVERFLOW
;
1425 m_style
&= ~wxAUI_TB_OVERFLOW
;
1429 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1431 bool res
= wxWindow::SetFont(font
);
1435 m_art
->SetFont(font
);
1442 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1444 wxAuiToolBarItem
* former_hover
= NULL
;
1447 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1449 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1450 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1451 former_hover
= &item
;
1452 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1457 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1460 if (former_hover
!= pitem
)
1467 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1469 wxAuiToolBarItem
* former_item
= NULL
;
1472 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1474 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1475 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1476 former_item
= &item
;
1477 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1482 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1483 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1486 if (former_item
!= pitem
)
1493 void wxAuiToolBar::RefreshOverflowState()
1495 if (!m_overflow_sizer_item
)
1497 m_overflow_state
= 0;
1501 int overflow_state
= 0;
1503 wxRect overflow_rect
= GetOverflowRect();
1506 // find out the mouse's current position
1507 wxPoint pt
= ::wxGetMousePosition();
1508 pt
= this->ScreenToClient(pt
);
1510 // find out if the mouse cursor is inside the dropdown rectangle
1511 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1513 if (::wxGetMouseState().LeftIsDown())
1514 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1516 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1519 if (overflow_state
!= m_overflow_state
)
1521 m_overflow_state
= overflow_state
;
1526 m_overflow_state
= overflow_state
;
1529 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1531 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1533 if (tool
&& (tool
->kind
== wxITEM_CHECK
|| tool
->kind
== wxITEM_RADIO
))
1535 if (tool
->kind
== wxITEM_RADIO
)
1538 idx
= GetToolIndex(tool_id
);
1539 count
= (int)m_items
.GetCount();
1541 if (idx
>= 0 && idx
< count
)
1543 for (i
= idx
; i
< count
; ++i
)
1545 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1547 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1549 for (i
= idx
; i
> 0; i
--)
1551 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1553 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1557 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1559 else if (tool
->kind
== wxITEM_CHECK
)
1562 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1564 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1569 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1571 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1575 if ( (tool
->kind
!= wxITEM_CHECK
) && (tool
->kind
!= wxITEM_RADIO
) )
1578 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1584 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1586 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1591 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1593 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1597 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1599 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1602 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1607 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1609 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1610 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1612 return wxEmptyString
;
1617 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1619 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1622 tool
->label
= label
;
1626 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1628 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1629 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1631 return wxNullBitmap
;
1633 return tool
->bitmap
;
1636 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1638 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1641 tool
->bitmap
= bitmap
;
1645 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1647 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1648 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1650 return wxEmptyString
;
1652 return tool
->short_help
;
1655 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1657 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1660 tool
->short_help
= help_string
;
1664 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1666 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1667 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1669 return wxEmptyString
;
1671 return tool
->long_help
;
1674 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1676 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1679 tool
->long_help
= help_string
;
1683 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1684 const wxAuiToolBarItemArray
& append
)
1686 m_custom_overflow_prepend
= prepend
;
1687 m_custom_overflow_append
= append
;
1690 // get size of hint rectangle for a particular dock location
1691 wxSize
wxAuiToolBar::GetHintSize(int dock_direction
) const
1693 switch (dock_direction
)
1695 case wxAUI_DOCK_TOP
:
1696 case wxAUI_DOCK_BOTTOM
:
1697 return m_horzHintSize
;
1698 case wxAUI_DOCK_RIGHT
:
1699 case wxAUI_DOCK_LEFT
:
1700 return m_vertHintSize
;
1702 wxCHECK_MSG(false, wxDefaultSize
, "invalid dock location value");
1706 bool wxAuiToolBar::IsPaneValid(const wxAuiPaneInfo
& pane
) const
1708 return IsPaneValid(m_style
, pane
);
1711 bool wxAuiToolBar::IsPaneValid(long style
, const wxAuiPaneInfo
& pane
)
1713 if (style
& wxAUI_TB_HORIZONTAL
)
1715 if (pane
.IsLeftDockable() || pane
.IsRightDockable())
1720 else if (style
& wxAUI_TB_VERTICAL
)
1722 if (pane
.IsTopDockable() || pane
.IsBottomDockable())
1730 bool wxAuiToolBar::IsPaneValid(long style
) const
1732 wxAuiManager
* manager
= wxAuiManager::GetManager(const_cast<wxAuiToolBar
*>(this));
1735 return IsPaneValid(style
, manager
->GetPane(const_cast<wxAuiToolBar
*>(this)));
1740 void wxAuiToolBar::SetArtFlags() const
1742 unsigned int artflags
= m_style
& ~wxAUI_ORIENTATION_MASK
;
1743 if (m_orientation
== wxVERTICAL
)
1745 artflags
|= wxAUI_TB_VERTICAL
;
1747 m_art
->SetFlags(artflags
);
1750 size_t wxAuiToolBar::GetToolCount() const
1752 return m_items
.size();
1755 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1757 // this will prevent us from returning the index of the
1758 // first separator in the toolbar since its id is equal to -1
1762 size_t i
, count
= m_items
.GetCount();
1763 for (i
= 0; i
< count
; ++i
)
1765 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1766 if (item
.id
== tool_id
)
1773 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1775 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1778 if (!m_items
[tool_idx
].sizer_item
)
1782 GetClientSize(&cli_w
, &cli_h
);
1784 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1786 if (m_orientation
== wxVERTICAL
)
1788 // take the dropdown size into account
1789 if (m_overflow_visible
)
1790 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1792 if (rect
.y
+rect
.height
< cli_h
)
1797 // take the dropdown size into account
1798 if (m_overflow_visible
)
1799 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1801 if (rect
.x
+rect
.width
< cli_w
)
1809 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1811 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1814 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1816 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1817 if (tool
&& tool
->sizer_item
)
1819 return tool
->sizer_item
->GetRect();
1825 bool wxAuiToolBar::GetToolBarFits() const
1827 if (m_items
.GetCount() == 0)
1829 // empty toolbar always 'fits'
1833 // entire toolbar content fits if the last tool fits
1834 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1837 bool wxAuiToolBar::Realize()
1839 wxClientDC
dc(this);
1843 // calculate hint sizes for both horizontal and vertical
1844 // in the order that leaves toolbar in correct final state
1845 bool retval
= false;
1846 if (m_orientation
== wxHORIZONTAL
)
1848 if (RealizeHelper(dc
, false))
1850 m_vertHintSize
= GetSize();
1851 if (RealizeHelper(dc
, true))
1853 m_horzHintSize
= GetSize();
1860 if (RealizeHelper(dc
, true))
1862 m_horzHintSize
= GetSize();
1863 if (RealizeHelper(dc
, false))
1865 m_vertHintSize
= GetSize();
1875 bool wxAuiToolBar::RealizeHelper(wxClientDC
& dc
, bool horizontal
)
1877 // create the new sizer to add toolbar elements to
1878 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1881 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1882 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1883 if (gripper_size
> 0 && m_gripper_visible
)
1886 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1888 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1892 m_gripper_sizer_item
= NULL
;
1895 // add "left" padding
1896 if (m_left_padding
> 0)
1899 sizer
->Add(m_left_padding
, 1);
1901 sizer
->Add(1, m_left_padding
);
1905 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1907 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1908 wxSizerItem
* sizer_item
= NULL
;
1914 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1915 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1916 size
.y
+ (m_tool_border_padding
*2),
1921 sizer
->AddSpacer(m_tool_packing
);
1931 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1932 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1933 size
.y
+ (m_tool_border_padding
*2),
1939 sizer
->AddSpacer(m_tool_packing
);
1945 case wxITEM_SEPARATOR
:
1948 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1950 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1955 sizer
->AddSpacer(m_tool_packing
);
1962 if (item
.proportion
> 0)
1963 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1965 sizer_item
= sizer
->Add(item
.spacer_pixels
, 1);
1968 case wxITEM_CONTROL
:
1970 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1971 wxSizerItem
* ctrl_sizer_item
;
1973 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1974 vert_sizer
->AddStretchSpacer(1);
1975 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1976 vert_sizer
->AddStretchSpacer(1);
1977 if ( (m_style
& wxAUI_TB_TEXT
) &&
1978 m_tool_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1979 !item
.GetLabel().empty() )
1981 wxSize s
= GetLabelSize(item
.GetLabel());
1982 vert_sizer
->Add(1, s
.y
);
1986 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1988 wxSize min_size
= item
.min_size
;
1991 // proportional items will disappear from the toolbar if
1992 // their min width is not set to something really small
1993 if (item
.proportion
!= 0)
1998 if (min_size
.IsFullySpecified())
2000 sizer_item
->SetMinSize(min_size
);
2001 ctrl_sizer_item
->SetMinSize(min_size
);
2007 sizer
->AddSpacer(m_tool_packing
);
2012 item
.sizer_item
= sizer_item
;
2015 // add "right" padding
2016 if (m_right_padding
> 0)
2019 sizer
->Add(m_right_padding
, 1);
2021 sizer
->Add(1, m_right_padding
);
2024 // add drop down area
2025 m_overflow_sizer_item
= NULL
;
2027 if (m_style
& wxAUI_TB_OVERFLOW
)
2029 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2030 if (overflow_size
> 0 && m_overflow_visible
)
2033 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
2035 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
2039 m_overflow_sizer_item
= NULL
;
2044 // the outside sizer helps us apply the "top" and "bottom" padding
2045 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
2047 // add "top" padding
2048 if (m_top_padding
> 0)
2051 outside_sizer
->Add(1, m_top_padding
);
2053 outside_sizer
->Add(m_top_padding
, 1);
2056 // add the sizer that contains all of the toolbar elements
2057 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
2059 // add "bottom" padding
2060 if (m_bottom_padding
> 0)
2063 outside_sizer
->Add(1, m_bottom_padding
);
2065 outside_sizer
->Add(m_bottom_padding
, 1);
2068 delete m_sizer
; // remove old sizer
2069 m_sizer
= outside_sizer
;
2071 // calculate the rock-bottom minimum size
2072 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2074 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2075 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2076 item
.sizer_item
->SetMinSize(0,0);
2079 m_absolute_min_size
= m_sizer
->GetMinSize();
2081 // reset the min sizes to what they were
2082 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2084 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2085 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
2086 item
.sizer_item
->SetMinSize(item
.min_size
);
2090 wxSize size
= m_sizer
->GetMinSize();
2091 m_minWidth
= size
.x
;
2092 m_minHeight
= size
.y
;
2094 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
2096 wxSize cur_size
= GetClientSize();
2097 wxSize new_size
= GetMinSize();
2098 if (new_size
!= cur_size
)
2100 SetClientSize(new_size
);
2104 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2109 wxSize cur_size
= GetClientSize();
2110 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
2116 int wxAuiToolBar::GetOverflowState() const
2118 return m_overflow_state
;
2121 wxRect
wxAuiToolBar::GetOverflowRect() const
2123 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2124 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
2125 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2127 if (m_orientation
== wxVERTICAL
)
2129 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2130 overflow_rect
.x
= 0;
2131 overflow_rect
.width
= cli_rect
.width
;
2132 overflow_rect
.height
= overflow_size
;
2136 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2137 overflow_rect
.y
= 0;
2138 overflow_rect
.width
= overflow_size
;
2139 overflow_rect
.height
= cli_rect
.height
;
2142 return overflow_rect
;
2145 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2147 wxClientDC
dc(this);
2150 int text_width
= 0, text_height
= 0;
2154 // get the text height
2155 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
2157 // get the text width
2158 dc
.GetTextExtent(label
, &text_width
, &ty
);
2160 return wxSize(text_width
, text_height
);
2164 void wxAuiToolBar::DoIdleUpdate()
2166 wxEvtHandler
* handler
= GetEventHandler();
2168 bool need_refresh
= false;
2171 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2173 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2178 wxUpdateUIEvent
evt(item
.id
);
2179 evt
.SetEventObject(this);
2181 if (handler
->ProcessEvent(evt
))
2183 if (evt
.GetSetEnabled())
2187 is_enabled
= item
.window
->IsEnabled();
2189 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2191 bool new_enabled
= evt
.GetEnabled();
2192 if (new_enabled
!= is_enabled
)
2196 item
.window
->Enable(new_enabled
);
2201 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2203 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2205 need_refresh
= true;
2209 if (evt
.GetSetChecked())
2211 // make sure we aren't checking an item that can't be
2212 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2215 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2216 bool new_checked
= evt
.GetChecked();
2218 if (new_checked
!= is_checked
)
2221 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2223 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2225 need_refresh
= true;
2240 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2243 GetClientSize(&x
, &y
);
2245 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2246 ((y
> x
) && m_absolute_min_size
.y
> y
))
2248 // hide all flexible items
2250 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2252 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2253 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2255 item
.sizer_item
->Show(false);
2256 item
.sizer_item
->SetProportion(0);
2262 // show all flexible items
2264 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2266 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2267 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2269 item
.sizer_item
->Show(true);
2270 item
.sizer_item
->SetProportion(item
.proportion
);
2275 m_sizer
->SetDimension(0, 0, x
, y
);
2280 // idle events aren't sent while user is resizing frame (why?),
2281 // but resizing toolbar here causes havoc,
2282 // so force idle handler to run after size handling complete
2283 QueueEvent(new wxIdleEvent
);
2288 void wxAuiToolBar::DoSetSize(int x
,
2294 wxSize parent_size
= GetParent()->GetClientSize();
2295 if (x
+ width
> parent_size
.x
)
2296 width
= wxMax(0, parent_size
.x
- x
);
2297 if (y
+ height
> parent_size
.y
)
2298 height
= wxMax(0, parent_size
.y
- y
);
2300 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2304 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2306 // if orientation doesn't match dock, fix it
2307 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2310 wxAuiPaneInfo
& pane
= manager
->GetPane(this);
2311 // pane state member is public, so it might have been changed
2312 // without going through wxPaneInfo::SetFlag() check
2313 bool ok
= pane
.IsOk();
2314 wxCHECK2_MSG(!ok
|| IsPaneValid(m_style
, pane
), ok
= false,
2315 "window settings and pane settings are incompatible");
2318 wxOrientation newOrientation
= m_orientation
;
2319 if (pane
.IsDocked())
2321 switch (pane
.dock_direction
)
2323 case wxAUI_DOCK_TOP
:
2324 case wxAUI_DOCK_BOTTOM
:
2325 newOrientation
= wxHORIZONTAL
;
2327 case wxAUI_DOCK_LEFT
:
2328 case wxAUI_DOCK_RIGHT
:
2329 newOrientation
= wxVERTICAL
;
2332 wxFAIL_MSG("invalid dock location value");
2335 else if (pane
.IsResizable() &&
2336 GetOrientation(m_style
) == wxBOTH
)
2338 // changing orientation in OnSize causes havoc
2340 GetClientSize(&x
, &y
);
2344 newOrientation
= wxHORIZONTAL
;
2348 newOrientation
= wxVERTICAL
;
2351 if (newOrientation
!= m_orientation
)
2353 SetOrientation(newOrientation
);
2355 if (newOrientation
== wxHORIZONTAL
)
2357 pane
.best_size
= GetHintSize(wxAUI_DOCK_TOP
);
2361 pane
.best_size
= GetHintSize(wxAUI_DOCK_LEFT
);
2363 if (pane
.IsDocked())
2365 pane
.floating_size
= wxDefaultSize
;
2369 SetSize(GetParent()->GetClientSize());
2380 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2382 wxAutoBufferedPaintDC
dc(this);
2383 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2386 bool horizontal
= m_orientation
== wxHORIZONTAL
;
2389 m_art
->DrawBackground(dc
, this, cli_rect
);
2391 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2392 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2394 // paint the gripper
2395 if (gripper_size
> 0 && m_gripper_sizer_item
)
2397 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2399 gripper_rect
.width
= gripper_size
;
2401 gripper_rect
.height
= gripper_size
;
2402 m_art
->DrawGripper(dc
, this, gripper_rect
);
2405 // calculated how far we can draw items
2408 last_extent
= cli_rect
.width
;
2410 last_extent
= cli_rect
.height
;
2411 if (m_overflow_visible
)
2412 last_extent
-= dropdown_size
;
2414 // paint each individual tool
2415 size_t i
, count
= m_items
.GetCount();
2416 for (i
= 0; i
< count
; ++i
)
2418 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2420 if (!item
.sizer_item
)
2423 wxRect item_rect
= item
.sizer_item
->GetRect();
2426 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2427 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2432 if (item
.kind
== wxITEM_SEPARATOR
)
2435 m_art
->DrawSeparator(dc
, this, item_rect
);
2437 else if (item
.kind
== wxITEM_LABEL
)
2439 // draw a text label only
2440 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2442 else if (item
.kind
== wxITEM_NORMAL
)
2444 // draw a regular button or dropdown button
2446 m_art
->DrawButton(dc
, this, item
, item_rect
);
2448 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2450 else if (item
.kind
== wxITEM_CHECK
)
2452 // draw a toggle button
2453 m_art
->DrawButton(dc
, this, item
, item_rect
);
2455 else if (item
.kind
== wxITEM_RADIO
)
2457 // draw a toggle button
2458 m_art
->DrawButton(dc
, this, item
, item_rect
);
2460 else if (item
.kind
== wxITEM_CONTROL
)
2462 // draw the control's label
2463 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2466 // fire a signal to see if the item wants to be custom-rendered
2467 OnCustomRender(dc
, item
, item_rect
);
2470 // paint the overflow button
2471 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2473 wxRect dropdown_rect
= GetOverflowRect();
2474 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2478 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2483 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2485 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2487 if (m_gripper_sizer_item
)
2489 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2490 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2493 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2497 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2498 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2500 // gripper was clicked
2501 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2506 if (m_overflow_sizer_item
)
2508 wxRect overflow_rect
= GetOverflowRect();
2511 m_overflow_visible
&&
2512 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2514 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2515 e
.SetEventObject(this);
2517 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2518 bool processed
= GetEventHandler()->ProcessEvent(e
);
2527 wxAuiToolBarItemArray overflow_items
;
2530 // add custom overflow prepend items, if any
2531 count
= m_custom_overflow_prepend
.GetCount();
2532 for (i
= 0; i
< count
; ++i
)
2533 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2535 // only show items that don't fit in the dropdown
2536 count
= m_items
.GetCount();
2537 for (i
= 0; i
< count
; ++i
)
2539 if (!GetToolFitsByIndex(i
))
2540 overflow_items
.Add(m_items
[i
]);
2543 // add custom overflow append items, if any
2544 count
= m_custom_overflow_append
.GetCount();
2545 for (i
= 0; i
< count
; ++i
)
2546 overflow_items
.Add(m_custom_overflow_append
[i
]);
2548 int res
= m_art
->ShowDropDown(this, overflow_items
);
2549 m_overflow_state
= 0;
2553 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2554 e
.SetEventObject(this);
2555 GetParent()->GetEventHandler()->ProcessEvent(e
);
2564 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2565 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2569 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2571 m_action_pos
= wxPoint(-1,-1);
2572 m_action_item
= NULL
;
2578 // fire the tool dropdown event
2579 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2580 e
.SetEventObject(this);
2581 e
.SetToolId(m_action_item
->id
);
2583 int mouse_x
= evt
.GetX();
2584 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2585 const bool dropDownHit
= m_action_item
->dropdown
&&
2586 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2587 mouse_x
< (rect
.x
+rect
.width
);
2588 e
.SetDropDownClicked(dropDownHit
);
2590 e
.SetClickPoint(evt
.GetPosition());
2591 e
.SetItemRect(rect
);
2593 // we only set the 'pressed button' state if we hit the actual button
2594 // and not just the drop-down
2595 SetPressedItem(dropDownHit
? 0 : m_action_item
);
2599 m_action_pos
= wxPoint(-1,-1);
2600 m_action_item
= NULL
;
2603 if(!GetEventHandler()->ProcessEvent(e
) || e
.GetSkipped())
2610 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2615 SetPressedItem(NULL
);
2617 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2618 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2620 SetHoverItem(hit_item
);
2625 // TODO: it would make sense to send out an 'END_DRAG' event here,
2626 // otherwise a client would never know what to do with the 'BEGIN_DRAG'
2629 // OnCaptureLost() will be called now and this will reset all our state
2630 // tracking variables
2635 wxAuiToolBarItem
* hit_item
;
2636 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2638 if (m_action_item
&& hit_item
== m_action_item
)
2642 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2643 e
.SetEventObject(this);
2645 if (hit_item
->kind
== wxITEM_CHECK
|| hit_item
->kind
== wxITEM_RADIO
)
2647 const bool toggle
= !(m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
);
2649 ToggleTool(m_action_item
->id
, toggle
);
2651 // repaint immediately
2658 // we have to release the mouse *before* sending the event, because
2659 // we don't know what a handler might do. It could open up a popup
2660 // menu for example and that would make us lose our capture anyway.
2664 GetEventHandler()->ProcessEvent(e
);
2672 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2674 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2676 if (m_gripper_sizer_item
)
2678 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2679 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2683 if (m_overflow_sizer_item
)
2685 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2686 if (dropdown_size
> 0 &&
2687 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2689 evt
.m_y
< cli_rect
.height
&&
2696 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2697 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2699 if (m_action_item
&& m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2701 m_action_pos
= wxPoint(-1,-1);
2702 m_action_item
= NULL
;
2709 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2711 wxAuiToolBarItem
* hit_item
;
2712 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2714 if (m_action_item
&& hit_item
== m_action_item
)
2716 if (hit_item
->kind
== wxITEM_NORMAL
)
2718 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2719 e
.SetEventObject(this);
2720 e
.SetToolId(m_action_item
->id
);
2721 e
.SetClickPoint(m_action_pos
);
2722 GetEventHandler()->ProcessEvent(e
);
2728 // right-clicked on the invalid area of the toolbar
2729 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2730 e
.SetEventObject(this);
2732 e
.SetClickPoint(m_action_pos
);
2733 GetEventHandler()->ProcessEvent(e
);
2737 // reset member variables
2738 m_action_pos
= wxPoint(-1,-1);
2739 m_action_item
= NULL
;
2742 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2744 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2746 if (m_gripper_sizer_item
)
2748 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2749 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2753 if (m_overflow_sizer_item
)
2755 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2756 if (dropdown_size
> 0 &&
2757 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2759 evt
.m_y
< cli_rect
.height
&&
2766 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2767 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2771 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2773 m_action_pos
= wxPoint(-1,-1);
2774 m_action_item
= NULL
;
2782 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2784 wxAuiToolBarItem
* hit_item
;
2785 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2787 if (m_action_item
&& hit_item
== m_action_item
)
2789 if (hit_item
->kind
== wxITEM_NORMAL
)
2791 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2792 e
.SetEventObject(this);
2793 e
.SetToolId(m_action_item
->id
);
2794 e
.SetClickPoint(m_action_pos
);
2795 GetEventHandler()->ProcessEvent(e
);
2800 // reset member variables
2801 m_action_pos
= wxPoint(-1,-1);
2802 m_action_item
= NULL
;
2805 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2807 const bool button_pressed
= HasCapture();
2809 // start a drag event
2810 if (!m_dragging
&& button_pressed
&&
2811 abs(evt
.GetX() - m_action_pos
.x
) + abs(evt
.GetY() - m_action_pos
.y
) > 5)
2813 // TODO: sending this event only makes sense if there is an 'END_DRAG'
2814 // event sent sometime in the future (see OnLeftUp())
2815 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2816 e
.SetEventObject(this);
2817 e
.SetToolId(m_action_item
->id
);
2818 m_dragging
= GetEventHandler()->ProcessEvent(e
) && !e
.GetSkipped();
2826 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2829 // if we have a button pressed we want it to be shown in 'depressed'
2830 // state unless we move the mouse outside the button, then we want it
2831 // to show as just 'highlighted'
2832 if (hit_item
== m_action_item
)
2833 SetPressedItem(m_action_item
);
2836 SetPressedItem(NULL
);
2837 SetHoverItem(m_action_item
);
2842 if (hit_item
&& (hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2845 SetHoverItem(hit_item
);
2847 // tooltips handling
2848 wxAuiToolBarItem
* packing_hit_item
;
2849 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2850 if (packing_hit_item
)
2852 if (packing_hit_item
!= m_tip_item
)
2854 m_tip_item
= packing_hit_item
;
2856 if ( !packing_hit_item
->short_help
.empty() )
2857 SetToolTip(packing_hit_item
->short_help
);
2868 // figure out the dropdown button state (are we hovering or pressing it?)
2869 RefreshOverflowState();
2873 void wxAuiToolBar::DoResetMouseState()
2875 RefreshOverflowState();
2877 SetPressedItem(NULL
);
2881 // we have to reset those here, because the mouse-up handlers which do
2882 // it usually won't be called if we let go of a mouse button while we
2883 // are outside of the window
2884 m_action_pos
= wxPoint(-1,-1);
2885 m_action_item
= NULL
;
2888 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& evt
)
2896 DoResetMouseState();
2899 void wxAuiToolBar::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(evt
))
2903 DoResetMouseState();
2906 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2908 wxCursor cursor
= wxNullCursor
;
2910 if (m_gripper_sizer_item
)
2912 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2913 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2915 cursor
= wxCursor(wxCURSOR_SIZING
);
2919 evt
.SetCursor(cursor
);