1 ///////////////////////////////////////////////////////////////////////////////
3 // Name: src/aui/dockart.cpp
4 // Purpose: wxaui: wx advanced user interface - docking window manager
5 // Author: Benjamin I. Williams
8 // RCS-ID: $Id: dockart.cpp 48848 2007-09-21 10:19:53Z SC $
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 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
)
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 unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
189 static 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 void wxAuiDefaultToolBarArt::DrawBackground(
230 wxWindow
* WXUNUSED(wnd
),
235 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 150);
236 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 90);
237 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
240 void wxAuiDefaultToolBarArt::DrawLabel(
242 wxWindow
* WXUNUSED(wnd
),
243 const wxAuiToolBarItem
& item
,
247 dc
.SetTextForeground(*wxBLACK
);
249 // we only care about the text height here since the text
250 // will get cropped based on the width of the item
251 int text_width
= 0, text_height
= 0;
252 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
254 // set the clipping region
255 wxRect clip_rect
= rect
;
256 clip_rect
.width
-= 1;
257 dc
.SetClippingRegion(clip_rect
);
261 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
262 dc
.DrawText(item
.label
, text_x
, text_y
);
263 dc
.DestroyClippingRegion();
267 void wxAuiDefaultToolBarArt::DrawButton(
269 wxWindow
* WXUNUSED(wnd
),
270 const wxAuiToolBarItem
& item
,
273 int text_width
= 0, text_height
= 0;
275 if (m_flags
& wxAUI_TB_TEXT
)
281 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
283 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
286 int bmp_x
= 0, bmp_y
= 0;
287 int text_x
= 0, text_y
= 0;
289 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
293 (item
.bitmap
.GetWidth()/2);
296 ((rect
.height
-text_height
)/2) -
297 (item
.bitmap
.GetHeight()/2);
299 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
300 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
302 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
308 (item
.bitmap
.GetHeight()/2);
310 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
317 if (!(item
.state
& wxAUI_BUTTON_STATE_DISABLED
))
319 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
321 dc
.SetPen(wxPen(m_highlight_colour
));
322 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 150)));
323 dc
.DrawRectangle(rect
);
325 else if ((item
.state
& wxAUI_BUTTON_STATE_HOVER
) || item
.sticky
== true)
327 dc
.SetPen(wxPen(m_highlight_colour
));
328 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
330 // draw an even lighter background for checked item hovers (since
331 // the hover background is the same color as the check background)
332 if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
333 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 180)));
335 dc
.DrawRectangle(rect
);
337 else if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
339 // it's important to put this code in an else statment after the
340 // hover, otherwise hovers won't draw properly for checked items
341 dc
.SetPen(wxPen(m_highlight_colour
));
342 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
343 dc
.DrawRectangle(rect
);
348 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
349 bmp
= item
.disabled_bitmap
;
356 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
358 // set the item's text color based on if it is disabled
359 dc
.SetTextForeground(*wxBLACK
);
360 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
361 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
363 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
365 dc
.DrawText(item
.label
, text_x
, text_y
);
370 void wxAuiDefaultToolBarArt::DrawDropDownButton(
372 wxWindow
* WXUNUSED(wnd
),
373 const wxAuiToolBarItem
& item
,
376 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
377 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
379 wxRect button_rect
= wxRect(rect
.x
,
381 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
383 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
385 BUTTON_DROPDOWN_WIDTH
+1,
388 if (m_flags
& wxAUI_TB_TEXT
)
393 if (m_flags
& wxAUI_TB_TEXT
)
395 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
399 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
404 dropbmp_x
= dropdown_rect
.x
+
405 (dropdown_rect
.width
/2) -
406 (m_button_dropdown_bmp
.GetWidth()/2);
407 dropbmp_y
= dropdown_rect
.y
+
408 (dropdown_rect
.height
/2) -
409 (m_button_dropdown_bmp
.GetHeight()/2);
412 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
414 bmp_x
= button_rect
.x
+
415 (button_rect
.width
/2) -
416 (item
.bitmap
.GetWidth()/2);
417 bmp_y
= button_rect
.y
+
418 ((button_rect
.height
-text_height
)/2) -
419 (item
.bitmap
.GetHeight()/2);
421 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
422 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
424 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
430 (item
.bitmap
.GetHeight()/2);
432 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
439 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
441 dc
.SetPen(wxPen(m_highlight_colour
));
442 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 140)));
443 dc
.DrawRectangle(button_rect
);
444 dc
.DrawRectangle(dropdown_rect
);
446 else if (item
.state
& wxAUI_BUTTON_STATE_HOVER
||
449 dc
.SetPen(wxPen(m_highlight_colour
));
450 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
451 dc
.DrawRectangle(button_rect
);
452 dc
.DrawRectangle(dropdown_rect
);
457 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
459 bmp
= item
.disabled_bitmap
;
460 dropbmp
= m_disabled_button_dropdown_bmp
;
465 dropbmp
= m_button_dropdown_bmp
;
471 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
472 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
474 // set the item's text color based on if it is disabled
475 dc
.SetTextForeground(*wxBLACK
);
476 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
477 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
479 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
481 dc
.DrawText(item
.label
, text_x
, text_y
);
485 void wxAuiDefaultToolBarArt::DrawControlLabel(
487 wxWindow
* WXUNUSED(wnd
),
488 const wxAuiToolBarItem
& item
,
491 if (!(m_flags
& wxAUI_TB_TEXT
))
494 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
497 int text_x
= 0, text_y
= 0;
498 int text_width
= 0, text_height
= 0;
503 if (m_flags
& wxAUI_TB_TEXT
)
505 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
509 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
511 // don't draw the label if it is wider than the item width
512 if (text_width
> rect
.width
)
515 // set the label's text color
516 dc
.SetTextForeground(*wxBLACK
);
518 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
519 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
521 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
523 dc
.DrawText(item
.label
, text_x
, text_y
);
527 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
529 wxWindow
* WXUNUSED(wnd
),
530 const wxAuiToolBarItem
& item
)
534 // get label's height
535 int width
= 0, height
= 0;
536 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
539 width
= item
.min_size
.GetWidth();
541 return wxSize(width
, height
);
544 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
546 wxWindow
* WXUNUSED(wnd
),
547 const wxAuiToolBarItem
& item
)
549 if (!item
.bitmap
.IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
550 return wxSize(16,16);
552 int width
= item
.bitmap
.GetWidth();
553 int height
= item
.bitmap
.GetHeight();
555 if (m_flags
& wxAUI_TB_TEXT
)
560 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
562 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
565 if (item
.label
.Length() > 0)
567 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
568 width
= wxMax(width
, tx
+6);
571 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&& item
.label
.Length() > 0)
573 width
+= 3; // space between left border and bitmap
574 width
+= 3; // space between bitmap and text
576 if (item
.label
.Length() > 0)
578 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
580 height
= wxMax(height
, ty
);
585 // if the tool has a dropdown button, add it to the width
586 if (item
.dropdown
== true)
587 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
589 return wxSize(width
, height
);
592 void wxAuiDefaultToolBarArt::DrawSeparator(
594 wxWindow
* WXUNUSED(wnd
),
597 bool horizontal
= true;
598 if (m_flags
& wxAUI_TB_VERTICAL
)
605 rect
.x
+= (rect
.width
/2);
607 int new_height
= (rect
.height
*3)/4;
608 rect
.y
+= (rect
.height
/2) - (new_height
/2);
609 rect
.height
= new_height
;
613 rect
.y
+= (rect
.height
/2);
615 int new_width
= (rect
.width
*3)/4;
616 rect
.x
+= (rect
.width
/2) - (new_width
/2);
617 rect
.width
= new_width
;
620 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 80);
621 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 80);
622 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
625 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
626 wxWindow
* WXUNUSED(wnd
),
634 if (m_flags
& wxAUI_TB_VERTICAL
)
636 x
= rect
.x
+ (i
*4) + 5;
638 if (x
> rect
.GetWidth()-5)
644 y
= rect
.y
+ (i
*4) + 5;
645 if (y
> rect
.GetHeight()-5)
649 dc
.SetPen(m_gripper_pen1
);
651 dc
.SetPen(m_gripper_pen2
);
652 dc
.DrawPoint(x
, y
+1);
653 dc
.DrawPoint(x
+1, y
);
654 dc
.SetPen(m_gripper_pen3
);
655 dc
.DrawPoint(x
+2, y
+1);
656 dc
.DrawPoint(x
+2, y
+2);
657 dc
.DrawPoint(x
+1, y
+2);
664 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
669 if (state
& wxAUI_BUTTON_STATE_HOVER
||
670 state
& wxAUI_BUTTON_STATE_PRESSED
)
672 wxRect cli_rect
= wnd
->GetClientRect();
673 wxColor light_gray_bg
= wxAuiStepColour(m_highlight_colour
, 170);
675 if (m_flags
& wxAUI_TB_VERTICAL
)
677 dc
.SetPen(wxPen(m_highlight_colour
));
678 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
679 dc
.SetPen(wxPen(light_gray_bg
));
680 dc
.SetBrush(wxBrush(light_gray_bg
));
681 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
685 dc
.SetPen(wxPen(m_highlight_colour
));
686 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
687 dc
.SetPen(wxPen(light_gray_bg
));
688 dc
.SetBrush(wxBrush(light_gray_bg
));
689 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
693 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
694 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
695 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
698 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
702 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
703 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
704 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
709 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
713 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
;
714 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
;
715 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
;
719 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
720 const wxAuiToolBarItemArray
& items
)
724 size_t items_added
= 0;
726 size_t i
, count
= items
.GetCount();
727 for (i
= 0; i
< count
; ++i
)
729 wxAuiToolBarItem
& item
= items
.Item(i
);
731 if (item
.kind
== wxITEM_NORMAL
)
733 wxString text
= item
.short_help
;
741 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
);
743 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
, false);
746 m
->SetBitmap(item
.bitmap
);
750 else if (item
.kind
== wxITEM_SEPARATOR
)
753 menuPopup
.AppendSeparator();
757 // find out where to put the popup menu of window items
758 wxPoint pt
= ::wxGetMousePosition();
759 pt
= wnd
->ScreenToClient(pt
);
761 // find out the screen coordinate at the bottom of the tab ctrl
762 wxRect cli_rect
= wnd
->GetClientRect();
763 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
765 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
766 wnd
->PushEventHandler(cc
);
767 wnd
->PopupMenu(&menuPopup
, pt
);
768 int command
= cc
->GetCommandId();
769 wnd
->PopEventHandler(true);
777 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
778 EVT_SIZE(wxAuiToolBar::OnSize
)
779 EVT_IDLE(wxAuiToolBar::OnIdle
)
780 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
781 EVT_PAINT(wxAuiToolBar::OnPaint
)
782 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
783 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
784 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
785 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
786 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
787 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
788 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
789 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
790 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
791 EVT_MOTION(wxAuiToolBar::OnMotion
)
792 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
793 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
797 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
799 const wxPoint
& position
,
806 style
| wxBORDER_NONE
)
808 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
810 m_button_height
= -1;
811 m_sizer_element_count
= 0;
812 m_action_pos
= wxPoint(-1,-1);
813 m_action_item
= NULL
;
815 m_art
= new wxAuiDefaultToolBarArt
;
817 m_tool_border_padding
= 3;
818 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
819 m_gripper_sizer_item
= NULL
;
820 m_overflow_sizer_item
= NULL
;
823 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
824 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
825 m_overflow_state
= 0;
826 SetMargins(5, 5, 2, 2);
827 SetFont(*wxNORMAL_FONT
);
828 m_art
->SetFlags((unsigned int)m_style
);
829 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
830 if (style
& wxAUI_TB_HORZ_TEXT
)
831 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
835 wxAuiToolBar::~wxAuiToolBar()
841 void wxAuiToolBar::SetWindowStyleFlag(long style
)
843 wxControl::SetWindowStyleFlag(style
);
849 m_art
->SetFlags((unsigned int)m_style
);
852 if (m_style
& wxAUI_TB_GRIPPER
)
853 m_gripper_visible
= true;
855 m_gripper_visible
= false;
858 if (m_style
& wxAUI_TB_OVERFLOW
)
859 m_overflow_visible
= true;
861 m_overflow_visible
= false;
863 if (style
& wxAUI_TB_HORZ_TEXT
)
864 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
866 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
870 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
878 m_art
->SetFlags((unsigned int)m_style
);
879 m_art
->SetTextOrientation(m_tool_text_orientation
);
883 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
891 void wxAuiToolBar::AddTool(int tool_id
,
892 const wxString
& label
,
893 const wxBitmap
& bitmap
,
894 const wxString
& short_help_string
,
908 void wxAuiToolBar::AddTool(int tool_id
,
909 const wxString
& label
,
910 const wxBitmap
& bitmap
,
911 const wxBitmap
& disabled_bitmap
,
913 const wxString
& WXUNUSED(short_help_string
),
914 const wxString
& WXUNUSED(long_help_string
),
915 wxObject
* WXUNUSED(client_data
))
917 wxAuiToolBarItem item
;
920 item
.bitmap
= bitmap
;
921 item
.disabled_bitmap
= disabled_bitmap
;
923 item
.dropdown
= false;
924 item
.space_pixels
= 0;
929 item
.sizer_item
= NULL
;
930 item
.min_size
= wxDefaultSize
;
934 if (!item
.disabled_bitmap
.IsOk())
936 // no disabled bitmap specified, we need to make one
937 if (item
.bitmap
.IsOk())
939 //wxImage img = item.bitmap.ConvertToImage();
940 //wxImage grey_version = img.ConvertToGreyscale();
941 //item.disabled_bitmap = wxBitmap(grey_version);
942 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
949 void wxAuiToolBar::AddControl(wxControl
* control
,
950 const wxString
& label
)
952 wxAuiToolBarItem item
;
953 item
.window
= (wxWindow
*)control
;
955 item
.bitmap
= wxNullBitmap
;
956 item
.disabled_bitmap
= wxNullBitmap
;
958 item
.dropdown
= false;
959 item
.space_pixels
= 0;
960 item
.id
= control
->GetId();
963 item
.kind
= wxITEM_CONTROL
;
964 item
.sizer_item
= NULL
;
965 item
.min_size
= control
->GetEffectiveMinSize();
972 void wxAuiToolBar::AddLabel(int tool_id
,
973 const wxString
& label
,
976 wxSize min_size
= wxDefaultSize
;
980 wxAuiToolBarItem item
;
983 item
.bitmap
= wxNullBitmap
;
984 item
.disabled_bitmap
= wxNullBitmap
;
986 item
.dropdown
= false;
987 item
.space_pixels
= 0;
991 item
.kind
= wxITEM_LABEL
;
992 item
.sizer_item
= NULL
;
993 item
.min_size
= min_size
;
1000 void wxAuiToolBar::AddSeparator()
1002 wxAuiToolBarItem item
;
1004 item
.label
= wxEmptyString
;
1005 item
.bitmap
= wxNullBitmap
;
1006 item
.disabled_bitmap
= wxNullBitmap
;
1008 item
.dropdown
= false;
1011 item
.proportion
= 0;
1012 item
.kind
= wxITEM_SEPARATOR
;
1013 item
.sizer_item
= NULL
;
1014 item
.min_size
= wxDefaultSize
;
1016 item
.sticky
= false;
1021 void wxAuiToolBar::AddSpacer(int pixels
)
1023 wxAuiToolBarItem item
;
1025 item
.label
= wxEmptyString
;
1026 item
.bitmap
= wxNullBitmap
;
1027 item
.disabled_bitmap
= wxNullBitmap
;
1029 item
.dropdown
= false;
1030 item
.space_pixels
= pixels
;
1033 item
.proportion
= 0;
1034 item
.kind
= wxITEM_SPACER
;
1035 item
.sizer_item
= NULL
;
1036 item
.min_size
= wxDefaultSize
;
1038 item
.sticky
= false;
1043 void wxAuiToolBar::AddStretchSpacer(int proportion
)
1045 wxAuiToolBarItem item
;
1047 item
.label
= wxEmptyString
;
1048 item
.bitmap
= wxNullBitmap
;
1049 item
.disabled_bitmap
= wxNullBitmap
;
1051 item
.dropdown
= false;
1052 item
.space_pixels
= 0;
1055 item
.proportion
= proportion
;
1056 item
.kind
= wxITEM_SPACER
;
1057 item
.sizer_item
= NULL
;
1058 item
.min_size
= wxDefaultSize
;
1060 item
.sticky
= false;
1065 void wxAuiToolBar::Clear()
1068 m_sizer_element_count
= 0;
1071 bool wxAuiToolBar::DeleteTool(int tool_id
)
1073 int idx
= GetToolIndex(tool_id
);
1074 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1076 m_items
.RemoveAt(idx
);
1084 bool wxAuiToolBar::DeleteByIndex(int idx
)
1086 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1088 m_items
.RemoveAt(idx
);
1097 wxControl
* wxAuiToolBar::FindControl(int id
)
1099 wxWindow
* wnd
= FindWindow(id
);
1100 return (wxControl
*)wnd
;
1103 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1106 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1108 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1109 if (item
.id
== tool_id
)
1116 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1119 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1121 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1123 if (!item
.sizer_item
)
1126 wxRect rect
= item
.sizer_item
->GetRect();
1127 if (rect
.Contains(x
,y
))
1129 // if the item doesn't fit on the toolbar, return NULL
1130 if (!GetToolFitsByIndex(i
))
1140 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1143 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1145 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1147 if (!item
.sizer_item
)
1150 wxRect rect
= item
.sizer_item
->GetRect();
1152 // apply tool packing
1154 rect
.width
+= m_tool_packing
;
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::FindToolByIndex(int idx
) const
1174 if (idx
>= (int)m_items
.size())
1177 return &(m_items
[idx
]);
1180 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1182 // TODO: wxToolBar compatibility
1185 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1187 // TODO: wxToolBar compatibility
1188 return wxSize(16,15);
1191 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1193 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1197 item
->proportion
= proportion
;
1200 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1202 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1206 return item
->proportion
;
1209 void wxAuiToolBar::SetToolSeparation(int separation
)
1212 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1215 int wxAuiToolBar::GetToolSeparation() const
1218 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1224 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1226 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1230 item
->dropdown
= dropdown
;
1233 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1235 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1239 return item
->dropdown
;
1242 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1244 // ignore separators
1248 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1252 if (item
->sticky
== sticky
)
1255 item
->sticky
= sticky
;
1261 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1263 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1267 return item
->sticky
;
1273 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1275 m_tool_border_padding
= padding
;
1278 int wxAuiToolBar::GetToolBorderPadding() const
1280 return m_tool_border_padding
;
1283 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1285 m_tool_text_orientation
= orientation
;
1289 m_art
->SetTextOrientation(orientation
);
1293 int wxAuiToolBar::GetToolTextOrientation() const
1295 return m_tool_text_orientation
;
1298 void wxAuiToolBar::SetToolPacking(int packing
)
1300 m_tool_packing
= packing
;
1303 int wxAuiToolBar::GetToolPacking() const
1305 return m_tool_packing
;
1309 void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation
))
1313 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1316 m_left_padding
= left
;
1318 m_right_padding
= right
;
1320 m_top_padding
= top
;
1322 m_bottom_padding
= bottom
;
1325 bool wxAuiToolBar::GetGripperVisible() const
1327 return m_gripper_visible
;
1330 void wxAuiToolBar::SetGripperVisible(bool visible
)
1332 m_gripper_visible
= visible
;
1334 m_style
|= wxAUI_TB_GRIPPER
;
1340 bool wxAuiToolBar::GetOverflowVisible() const
1342 return m_overflow_visible
;
1345 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1347 m_overflow_visible
= visible
;
1349 m_style
|= wxAUI_TB_OVERFLOW
;
1353 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1355 bool res
= wxWindow::SetFont(font
);
1359 m_art
->SetFont(font
);
1366 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1368 wxAuiToolBarItem
* former_hover
= NULL
;
1371 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1373 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1374 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1375 former_hover
= &item
;
1376 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1381 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1384 if (former_hover
!= pitem
)
1391 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1393 wxAuiToolBarItem
* former_item
= NULL
;
1396 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1398 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1399 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1400 former_item
= &item
;
1401 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1406 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1407 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1410 if (former_item
!= pitem
)
1417 void wxAuiToolBar::RefreshOverflowState()
1419 if (!m_overflow_sizer_item
)
1421 m_overflow_state
= 0;
1425 int overflow_state
= 0;
1427 wxRect overflow_rect
= GetOverflowRect();
1430 // find out the mouse's current position
1431 wxPoint pt
= ::wxGetMousePosition();
1432 pt
= this->ScreenToClient(pt
);
1434 // find out if the mouse cursor is inside the dropdown rectangle
1435 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1437 if (::wxGetMouseState().LeftDown())
1438 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1440 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1443 if (overflow_state
!= m_overflow_state
)
1445 m_overflow_state
= overflow_state
;
1450 m_overflow_state
= overflow_state
;
1453 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1455 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1459 if (tool
->kind
!= wxITEM_CHECK
)
1463 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1465 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1469 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1471 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1475 if (tool
->kind
!= wxITEM_CHECK
)
1478 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1484 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1486 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1491 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1493 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1497 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1499 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1502 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1507 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1509 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1510 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1512 return wxEmptyString
;
1517 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1519 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1522 tool
->label
= label
;
1526 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1528 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1529 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1531 return wxNullBitmap
;
1533 return tool
->bitmap
;
1536 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1538 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1541 tool
->bitmap
= bitmap
;
1545 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1547 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1548 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1550 return wxEmptyString
;
1552 return tool
->short_help
;
1555 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1557 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1560 tool
->short_help
= help_string
;
1564 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1566 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1567 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1569 return wxEmptyString
;
1571 return tool
->long_help
;
1574 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1576 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1579 tool
->long_help
= help_string
;
1583 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1584 const wxAuiToolBarItemArray
& append
)
1586 m_custom_overflow_prepend
= prepend
;
1587 m_custom_overflow_append
= append
;
1591 size_t wxAuiToolBar::GetToolCount() const
1593 return m_items
.size();
1596 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1598 // this will prevent us from returning the index of the
1599 // first separator in the toolbar since its id is equal to -1
1603 size_t i
, count
= m_items
.GetCount();
1604 for (i
= 0; i
< count
; ++i
)
1606 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1607 if (item
.id
== tool_id
)
1614 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1616 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1619 if (!m_items
[tool_idx
].sizer_item
)
1623 GetClientSize(&cli_w
, &cli_h
);
1625 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1627 if (m_style
& wxAUI_TB_VERTICAL
)
1629 // take the dropdown size into account
1630 if (m_overflow_visible
)
1631 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1633 if (rect
.y
+rect
.height
< cli_h
)
1638 // take the dropdown size into account
1639 if (m_overflow_visible
)
1640 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1642 if (rect
.x
+rect
.width
< cli_w
)
1650 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1652 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1655 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1657 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1658 if (tool
&& tool
->sizer_item
)
1660 return tool
->sizer_item
->GetRect();
1666 bool wxAuiToolBar::GetToolBarFits() const
1668 if (m_items
.GetCount() == 0)
1670 // empty toolbar always 'fits'
1674 // entire toolbar content fits if the last tool fits
1675 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1678 bool wxAuiToolBar::Realize()
1680 wxClientDC
dc(this);
1684 bool horizontal
= true;
1685 if (m_style
& wxAUI_TB_VERTICAL
)
1689 // create the new sizer to add toolbar elements to
1690 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1693 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1694 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1695 if (gripper_size
> 0 && m_gripper_visible
)
1698 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1700 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1704 m_gripper_sizer_item
= NULL
;
1707 // add "left" padding
1708 if (m_left_padding
> 0)
1711 sizer
->Add(m_left_padding
, 1);
1713 sizer
->Add(1, m_left_padding
);
1717 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1719 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1720 wxSizerItem
* sizer_item
= NULL
;
1726 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1727 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1728 size
.y
+ (m_tool_border_padding
*2),
1733 sizer
->AddSpacer(m_tool_packing
);
1742 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1743 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1744 size
.y
+ (m_tool_border_padding
*2),
1750 sizer
->AddSpacer(m_tool_packing
);
1756 case wxITEM_SEPARATOR
:
1759 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1761 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1766 sizer
->AddSpacer(m_tool_packing
);
1773 if (item
.proportion
> 0)
1774 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1776 sizer_item
= sizer
->Add(item
.space_pixels
, 1);
1779 case wxITEM_CONTROL
:
1781 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1782 wxSizerItem
* ctrl_sizer_item
;
1784 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1785 vert_sizer
->AddStretchSpacer(1);
1786 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1787 vert_sizer
->AddStretchSpacer(1);
1788 if ((m_style
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
1790 wxSize s
= GetLabelSize(item
.label
);
1791 vert_sizer
->Add(1, s
.y
);
1795 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1797 wxSize min_size
= item
.min_size
;
1800 // proportional items will disappear from the toolbar if
1801 // their min width is not set to something really small
1802 if (item
.proportion
!= 0)
1807 if (min_size
.IsFullySpecified())
1809 sizer_item
->SetMinSize(min_size
);
1810 ctrl_sizer_item
->SetMinSize(min_size
);
1816 sizer
->AddSpacer(m_tool_packing
);
1821 item
.sizer_item
= sizer_item
;
1824 // add "right" padding
1825 if (m_right_padding
> 0)
1828 sizer
->Add(m_right_padding
, 1);
1830 sizer
->Add(1, m_right_padding
);
1833 // add drop down area
1834 m_overflow_sizer_item
= NULL
;
1836 if (m_style
& wxAUI_TB_OVERFLOW
)
1838 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1839 if (overflow_size
> 0 && m_overflow_visible
)
1842 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
1844 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
1848 m_overflow_sizer_item
= NULL
;
1853 // the outside sizer helps us apply the "top" and "bottom" padding
1854 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
1856 // add "top" padding
1857 if (m_top_padding
> 0)
1860 outside_sizer
->Add(1, m_top_padding
);
1862 outside_sizer
->Add(m_top_padding
, 1);
1865 // add the sizer that contains all of the toolbar elements
1866 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
1868 // add "bottom" padding
1869 if (m_bottom_padding
> 0)
1872 outside_sizer
->Add(1, m_bottom_padding
);
1874 outside_sizer
->Add(m_bottom_padding
, 1);
1877 delete m_sizer
; // remove old sizer
1878 m_sizer
= outside_sizer
;
1880 // calculate the rock-bottom minimum size
1881 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1883 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1884 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1885 item
.sizer_item
->SetMinSize(0,0);
1888 m_absolute_min_size
= m_sizer
->GetMinSize();
1890 // reset the min sizes to what they were
1891 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1893 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1894 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1895 item
.sizer_item
->SetMinSize(item
.min_size
);
1899 wxSize size
= m_sizer
->GetMinSize();
1900 m_minWidth
= size
.x
;
1901 m_minHeight
= size
.y
;
1903 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
1905 wxSize cur_size
= GetClientSize();
1906 wxSize new_size
= GetMinSize();
1907 if (new_size
!= cur_size
)
1909 SetClientSize(new_size
);
1913 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1918 wxSize cur_size
= GetClientSize();
1919 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1926 int wxAuiToolBar::GetOverflowState() const
1928 return m_overflow_state
;
1931 wxRect
wxAuiToolBar::GetOverflowRect() const
1933 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
1934 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
1935 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1937 if (m_style
& wxAUI_TB_VERTICAL
)
1939 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
1940 overflow_rect
.x
= 0;
1941 overflow_rect
.width
= cli_rect
.width
;
1942 overflow_rect
.height
= overflow_size
;
1946 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
1947 overflow_rect
.y
= 0;
1948 overflow_rect
.width
= overflow_size
;
1949 overflow_rect
.height
= cli_rect
.height
;
1952 return overflow_rect
;
1955 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
1957 wxClientDC
dc(this);
1960 int text_width
= 0, text_height
= 0;
1964 // get the text height
1965 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
1967 // get the text width
1968 dc
.GetTextExtent(label
, &text_width
, &ty
);
1970 return wxSize(text_width
, text_height
);
1974 void wxAuiToolBar::DoIdleUpdate()
1976 wxEvtHandler
* handler
= GetEventHandler();
1978 bool need_refresh
= false;
1981 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1983 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1988 wxUpdateUIEvent
evt(item
.id
);
1989 evt
.SetEventObject(this);
1991 if (handler
->ProcessEvent(evt
))
1993 if (evt
.GetSetEnabled())
1997 is_enabled
= item
.window
->IsEnabled();
1999 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2001 bool new_enabled
= evt
.GetEnabled();
2002 if (new_enabled
!= is_enabled
)
2006 item
.window
->Enable(new_enabled
);
2011 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2013 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2015 need_refresh
= true;
2019 if (evt
.GetSetChecked())
2021 // make sure we aren't checking an item that can't be
2022 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2025 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2026 bool new_checked
= evt
.GetChecked();
2028 if (new_checked
!= is_checked
)
2031 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2033 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2035 need_refresh
= true;
2050 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2053 GetClientSize(&x
, &y
);
2056 SetOrientation(wxHORIZONTAL
);
2058 SetOrientation(wxVERTICAL
);
2060 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2061 ((y
> x
) && m_absolute_min_size
.y
> y
))
2063 // hide all flexible items
2065 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2067 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2068 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2070 item
.sizer_item
->Show(false);
2071 item
.sizer_item
->SetProportion(0);
2077 // show all flexible items
2079 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2081 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2082 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2084 item
.sizer_item
->Show(true);
2085 item
.sizer_item
->SetProportion(item
.proportion
);
2090 m_sizer
->SetDimension(0, 0, x
, y
);
2098 void wxAuiToolBar::DoSetSize(int x
,
2104 wxSize parent_size
= GetParent()->GetClientSize();
2105 if (x
+ width
> parent_size
.x
)
2106 width
= wxMax(0, parent_size
.x
- x
);
2107 if (y
+ height
> parent_size
.y
)
2108 height
= wxMax(0, parent_size
.y
- y
);
2110 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2114 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2120 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2122 wxBufferedPaintDC
dc(this);
2123 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2126 bool horizontal
= true;
2127 if (m_style
& wxAUI_TB_VERTICAL
)
2131 m_art
->DrawBackground(dc
, this, cli_rect
);
2133 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2134 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2136 // paint the gripper
2137 if (gripper_size
> 0 && m_gripper_sizer_item
)
2139 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2141 gripper_rect
.width
= gripper_size
;
2143 gripper_rect
.height
= gripper_size
;
2144 m_art
->DrawGripper(dc
, this, gripper_rect
);
2147 // calculated how far we can draw items
2150 last_extent
= cli_rect
.width
;
2152 last_extent
= cli_rect
.height
;
2153 if (m_overflow_visible
)
2154 last_extent
-= dropdown_size
;
2156 // paint each individual tool
2157 size_t i
, count
= m_items
.GetCount();
2158 for (i
= 0; i
< count
; ++i
)
2160 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2162 if (!item
.sizer_item
)
2165 wxRect item_rect
= item
.sizer_item
->GetRect();
2168 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2169 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2174 if (item
.kind
== wxITEM_SEPARATOR
)
2177 m_art
->DrawSeparator(dc
, this, item_rect
);
2179 else if (item
.kind
== wxITEM_LABEL
)
2181 // draw a text label only
2182 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2184 else if (item
.kind
== wxITEM_NORMAL
)
2186 // draw a regular button or dropdown button
2188 m_art
->DrawButton(dc
, this, item
, item_rect
);
2190 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2192 else if (item
.kind
== wxITEM_CHECK
)
2194 // draw a toggle button
2195 m_art
->DrawButton(dc
, this, item
, item_rect
);
2197 else if (item
.kind
== wxITEM_CONTROL
)
2199 // draw the control's label
2200 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2203 // fire a signal to see if the item wants to be custom-rendered
2204 OnCustomRender(dc
, item
, item_rect
);
2207 // paint the overflow button
2208 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2210 wxRect dropdown_rect
= GetOverflowRect();
2211 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2215 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2220 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2222 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2224 if (m_gripper_sizer_item
)
2226 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2227 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2230 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2234 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2235 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2237 // gripper was clicked
2238 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2243 if (m_overflow_sizer_item
)
2245 wxRect overflow_rect
= GetOverflowRect();
2248 m_overflow_visible
&&
2249 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2251 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2252 e
.SetEventObject(this);
2254 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2255 bool processed
= ProcessEvent(e
);
2264 wxAuiToolBarItemArray overflow_items
;
2267 // add custom overflow prepend items, if any
2268 count
= m_custom_overflow_prepend
.GetCount();
2269 for (i
= 0; i
< count
; ++i
)
2270 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2272 // only show items that don't fit in the dropdown
2273 count
= m_items
.GetCount();
2274 for (i
= 0; i
< count
; ++i
)
2276 if (!GetToolFitsByIndex(i
))
2277 overflow_items
.Add(m_items
[i
]);
2280 // add custom overflow append items, if any
2281 count
= m_custom_overflow_append
.GetCount();
2282 for (i
= 0; i
< count
; ++i
)
2283 overflow_items
.Add(m_custom_overflow_append
[i
]);
2285 int res
= m_art
->ShowDropDown(this, overflow_items
);
2286 m_overflow_state
= 0;
2290 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2291 e
.SetEventObject(this);
2292 GetParent()->ProcessEvent(e
);
2301 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2302 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2306 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2308 m_action_pos
= wxPoint(-1,-1);
2309 m_action_item
= NULL
;
2313 SetPressedItem(m_action_item
);
2315 // fire the tool dropdown event
2316 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2317 e
.SetEventObject(this);
2318 e
.SetToolId(m_action_item
->id
);
2319 e
.SetDropDownClicked(false);
2321 int mouse_x
= evt
.GetX();
2322 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2324 if (m_action_item
->dropdown
&&
2325 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2326 mouse_x
< (rect
.x
+rect
.width
))
2328 e
.SetDropDownClicked(true);
2331 e
.SetClickPoint(evt
.GetPosition());
2332 e
.SetItemRect(rect
);
2338 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2340 SetPressedItem(NULL
);
2342 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2343 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2345 SetHoverItem(hit_item
);
2351 // reset drag and drop member variables
2353 m_action_pos
= wxPoint(-1,-1);
2354 m_action_item
= NULL
;
2359 wxAuiToolBarItem
* hit_item
;
2360 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2362 if (m_action_item
&& hit_item
== m_action_item
)
2366 if (hit_item
->kind
== wxITEM_CHECK
)
2368 bool toggle
= false;
2370 if (m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
)
2375 ToggleTool(m_action_item
->id
, toggle
);
2377 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2378 e
.SetEventObject(this);
2384 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2385 e
.SetEventObject(this);
2392 // reset drag and drop member variables
2394 m_action_pos
= wxPoint(-1,-1);
2395 m_action_item
= NULL
;
2398 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2400 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2402 if (m_gripper_sizer_item
)
2404 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2405 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2409 if (m_overflow_sizer_item
)
2411 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2412 if (dropdown_size
> 0 &&
2413 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2415 evt
.m_y
< cli_rect
.height
&&
2422 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2423 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2427 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2429 m_action_pos
= wxPoint(-1,-1);
2430 m_action_item
= NULL
;
2436 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2438 wxAuiToolBarItem
* hit_item
;
2439 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2441 if (m_action_item
&& hit_item
== m_action_item
)
2443 if (hit_item
->kind
== wxITEM_NORMAL
)
2445 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2446 e
.SetEventObject(this);
2447 e
.SetToolId(m_action_item
->id
);
2448 e
.SetClickPoint(m_action_pos
);
2455 // right-clicked on the invalid area of the toolbar
2456 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2457 e
.SetEventObject(this);
2459 e
.SetClickPoint(m_action_pos
);
2464 // reset member variables
2465 m_action_pos
= wxPoint(-1,-1);
2466 m_action_item
= NULL
;
2469 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2471 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2473 if (m_gripper_sizer_item
)
2475 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2476 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2480 if (m_overflow_sizer_item
)
2482 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2483 if (dropdown_size
> 0 &&
2484 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2486 evt
.m_y
< cli_rect
.height
&&
2493 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2494 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2498 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2500 m_action_pos
= wxPoint(-1,-1);
2501 m_action_item
= NULL
;
2507 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2509 wxAuiToolBarItem
* hit_item
;
2510 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2512 if (m_action_item
&& hit_item
== m_action_item
)
2514 if (hit_item
->kind
== wxITEM_NORMAL
)
2516 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2517 e
.SetEventObject(this);
2518 e
.SetToolId(m_action_item
->id
);
2519 e
.SetClickPoint(m_action_pos
);
2525 // reset member variables
2526 m_action_pos
= wxPoint(-1,-1);
2527 m_action_item
= NULL
;
2530 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2532 // start a drag event
2534 m_action_item
!= NULL
&&
2535 m_action_pos
!= wxPoint(-1,-1) &&
2536 abs(evt
.m_x
- m_action_pos
.x
) + abs(evt
.m_y
- m_action_pos
.y
) > 5)
2542 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2543 e
.SetEventObject(this);
2544 e
.SetToolId(m_action_item
->id
);
2550 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2553 if (!(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2554 SetHoverItem(hit_item
);
2560 // no hit item, remove any hit item
2561 SetHoverItem(hit_item
);
2564 // figure out tooltips
2565 wxAuiToolBarItem
* packing_hit_item
;
2566 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2567 if (packing_hit_item
)
2569 if (packing_hit_item
!= m_tip_item
)
2571 m_tip_item
= packing_hit_item
;
2573 if (packing_hit_item
->short_help
.Length() > 0)
2574 SetToolTip(packing_hit_item
->short_help
);
2585 // if we've pressed down an item and we're hovering
2586 // over it, make sure it's state is set to pressed
2589 if (m_action_item
== hit_item
)
2590 SetPressedItem(m_action_item
);
2592 SetPressedItem(NULL
);
2595 // figure out the dropdown button state (are we hovering or pressing it?)
2596 RefreshOverflowState();
2599 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& WXUNUSED(evt
))
2601 RefreshOverflowState();
2603 SetPressedItem(NULL
);
2609 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2611 wxCursor cursor
= wxNullCursor
;
2613 if (m_gripper_sizer_item
)
2615 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2616 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2618 cursor
= wxCursor(wxCURSOR_SIZING
);
2622 evt
.SetCursor(cursor
);