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 double wxAuiBlendColour(double fg
, double 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
= (unsigned char)wxAuiBlendColour((double)*r
, 255.0, 0.4);
102 *g
= (unsigned char)wxAuiBlendColour((double)*g
, 255.0, 0.4);
103 *b
= (unsigned char)wxAuiBlendColour((double)*b
, 255.0, 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 const wxColour DISABLED_TEXT_COLOR
= wxColour(wxAuiBlendColour(0,255,0.4),
161 wxAuiBlendColour(0,255,0.4),
162 wxAuiBlendColour(0,255,0.4));
165 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
167 m_base_colour
= GetBaseColor();
170 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
171 m_highlight_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
173 m_separator_size
= 7;
175 m_overflow_size
= 16;
177 wxColor darker1_colour
= wxAuiStepColour(m_base_colour
, 85);
178 wxColor darker2_colour
= wxAuiStepColour(m_base_colour
, 75);
179 wxColor darker3_colour
= wxAuiStepColour(m_base_colour
, 60);
180 wxColor darker4_colour
= wxAuiStepColour(m_base_colour
, 50);
181 wxColor darker5_colour
= wxAuiStepColour(m_base_colour
, 40);
183 m_gripper_pen1
= wxPen(darker5_colour
);
184 m_gripper_pen2
= wxPen(darker3_colour
);
185 m_gripper_pen3
= *wxWHITE_PEN
;
187 static unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
188 static unsigned char overflow_bits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
190 m_button_dropdown_bmp
= wxAuiBitmapFromBits(button_dropdown_bits
, 5, 3,
192 m_disabled_button_dropdown_bmp
= wxAuiBitmapFromBits(
193 button_dropdown_bits
, 5, 3,
194 wxColor(128,128,128));
195 m_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, *wxBLACK
);
196 m_disabled_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, wxColor(128,128,128));
198 m_font
= *wxNORMAL_FONT
;
201 wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
203 m_font
= *wxNORMAL_FONT
;
207 wxAuiToolBarArt
* wxAuiDefaultToolBarArt::Clone()
209 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
212 void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags
)
217 void wxAuiDefaultToolBarArt::SetFont(const wxFont
& font
)
222 void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation
)
224 m_text_orientation
= orientation
;
227 void wxAuiDefaultToolBarArt::DrawBackground(
229 wxWindow
* WXUNUSED(wnd
),
234 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 150);
235 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 90);
236 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
239 void wxAuiDefaultToolBarArt::DrawLabel(
241 wxWindow
* WXUNUSED(wnd
),
242 const wxAuiToolBarItem
& item
,
246 dc
.SetTextForeground(*wxBLACK
);
248 // we only care about the text height here since the text
249 // will get cropped based on the width of the item
250 int text_width
= 0, text_height
= 0;
251 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
253 // set the clipping region
254 wxRect clip_rect
= rect
;
255 clip_rect
.width
-= 1;
256 dc
.SetClippingRegion(clip_rect
);
260 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
261 dc
.DrawText(item
.label
, text_x
, text_y
);
262 dc
.DestroyClippingRegion();
266 void wxAuiDefaultToolBarArt::DrawButton(
268 wxWindow
* WXUNUSED(wnd
),
269 const wxAuiToolBarItem
& item
,
272 int text_width
= 0, text_height
= 0;
274 if (m_flags
& wxAUI_TB_TEXT
)
280 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
282 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
285 int bmp_x
= 0, bmp_y
= 0;
286 int text_x
= 0, text_y
= 0;
288 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
292 (item
.bitmap
.GetWidth()/2);
295 ((rect
.height
-text_height
)/2) -
296 (item
.bitmap
.GetHeight()/2);
298 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
299 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
301 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
307 (item
.bitmap
.GetHeight()/2);
309 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
316 if (!(item
.state
& wxAUI_BUTTON_STATE_DISABLED
))
318 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
320 dc
.SetPen(wxPen(m_highlight_colour
));
321 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 150)));
322 dc
.DrawRectangle(rect
);
324 else if ((item
.state
& wxAUI_BUTTON_STATE_HOVER
) || item
.sticky
== true)
326 dc
.SetPen(wxPen(m_highlight_colour
));
327 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
329 // draw an even lighter background for checked item hovers (since
330 // the hover background is the same color as the check background)
331 if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
332 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 180)));
334 dc
.DrawRectangle(rect
);
336 else if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
338 // it's important to put this code in an else statment after the
339 // hover, otherwise hovers won't draw properly for checked items
340 dc
.SetPen(wxPen(m_highlight_colour
));
341 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
342 dc
.DrawRectangle(rect
);
347 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
348 bmp
= item
.disabled_bitmap
;
355 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
357 // set the item's text color based on if it is disabled
358 dc
.SetTextForeground(*wxBLACK
);
359 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
360 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
362 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
364 dc
.DrawText(item
.label
, text_x
, text_y
);
369 void wxAuiDefaultToolBarArt::DrawDropDownButton(
371 wxWindow
* WXUNUSED(wnd
),
372 const wxAuiToolBarItem
& item
,
375 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
376 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
378 wxRect button_rect
= wxRect(rect
.x
,
380 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
382 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
384 BUTTON_DROPDOWN_WIDTH
+1,
387 if (m_flags
& wxAUI_TB_TEXT
)
392 if (m_flags
& wxAUI_TB_TEXT
)
394 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
398 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
403 dropbmp_x
= dropdown_rect
.x
+
404 (dropdown_rect
.width
/2) -
405 (m_button_dropdown_bmp
.GetWidth()/2);
406 dropbmp_y
= dropdown_rect
.y
+
407 (dropdown_rect
.height
/2) -
408 (m_button_dropdown_bmp
.GetHeight()/2);
411 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
413 bmp_x
= button_rect
.x
+
414 (button_rect
.width
/2) -
415 (item
.bitmap
.GetWidth()/2);
416 bmp_y
= button_rect
.y
+
417 ((button_rect
.height
-text_height
)/2) -
418 (item
.bitmap
.GetHeight()/2);
420 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
421 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
423 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
429 (item
.bitmap
.GetHeight()/2);
431 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
438 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
440 dc
.SetPen(wxPen(m_highlight_colour
));
441 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 140)));
442 dc
.DrawRectangle(button_rect
);
443 dc
.DrawRectangle(dropdown_rect
);
445 else if (item
.state
& wxAUI_BUTTON_STATE_HOVER
||
448 dc
.SetPen(wxPen(m_highlight_colour
));
449 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
450 dc
.DrawRectangle(button_rect
);
451 dc
.DrawRectangle(dropdown_rect
);
456 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
458 bmp
= item
.disabled_bitmap
;
459 dropbmp
= m_disabled_button_dropdown_bmp
;
464 dropbmp
= m_button_dropdown_bmp
;
470 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
471 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
473 // set the item's text color based on if it is disabled
474 dc
.SetTextForeground(*wxBLACK
);
475 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
476 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
478 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
480 dc
.DrawText(item
.label
, text_x
, text_y
);
484 void wxAuiDefaultToolBarArt::DrawControlLabel(
486 wxWindow
* WXUNUSED(wnd
),
487 const wxAuiToolBarItem
& item
,
490 if (!(m_flags
& wxAUI_TB_TEXT
))
493 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
496 int text_x
= 0, text_y
= 0;
497 int text_width
= 0, text_height
= 0;
502 if (m_flags
& wxAUI_TB_TEXT
)
504 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
508 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
510 // don't draw the label if it is wider than the item width
511 if (text_width
> rect
.width
)
514 // set the label's text color
515 dc
.SetTextForeground(*wxBLACK
);
517 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
518 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
520 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
522 dc
.DrawText(item
.label
, text_x
, text_y
);
526 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
528 wxWindow
* WXUNUSED(wnd
),
529 const wxAuiToolBarItem
& item
)
533 // get label's height
534 int width
= 0, height
= 0;
535 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
538 width
= item
.min_size
.GetWidth();
540 return wxSize(width
, height
);
543 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
545 wxWindow
* WXUNUSED(wnd
),
546 const wxAuiToolBarItem
& item
)
548 if (!item
.bitmap
.IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
549 return wxSize(16,16);
551 int width
= item
.bitmap
.GetWidth();
552 int height
= item
.bitmap
.GetHeight();
554 if (m_flags
& wxAUI_TB_TEXT
)
559 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
561 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
564 if (item
.label
.Length() > 0)
566 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
567 width
= wxMax(width
, tx
+6);
570 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&& item
.label
.Length() > 0)
572 width
+= 3; // space between left border and bitmap
573 width
+= 3; // space between bitmap and text
575 if (item
.label
.Length() > 0)
577 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
579 height
= wxMax(height
, ty
);
584 // if the tool has a dropdown button, add it to the width
585 if (item
.dropdown
== true)
586 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
588 return wxSize(width
, height
);
591 void wxAuiDefaultToolBarArt::DrawSeparator(
593 wxWindow
* WXUNUSED(wnd
),
596 bool horizontal
= true;
597 if (m_flags
& wxAUI_TB_VERTICAL
)
604 rect
.x
+= (rect
.width
/2);
606 int new_height
= (rect
.height
*3)/4;
607 rect
.y
+= (rect
.height
/2) - (new_height
/2);
608 rect
.height
= new_height
;
612 rect
.y
+= (rect
.height
/2);
614 int new_width
= (rect
.width
*3)/4;
615 rect
.x
+= (rect
.width
/2) - (new_width
/2);
616 rect
.width
= new_width
;
619 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 80);
620 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 80);
621 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
624 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
625 wxWindow
* WXUNUSED(wnd
),
633 if (m_flags
& wxAUI_TB_VERTICAL
)
635 x
= rect
.x
+ (i
*4) + 5;
637 if (x
> rect
.GetWidth()-5)
643 y
= rect
.y
+ (i
*4) + 5;
644 if (y
> rect
.GetHeight()-5)
648 dc
.SetPen(m_gripper_pen1
);
650 dc
.SetPen(m_gripper_pen2
);
651 dc
.DrawPoint(x
, y
+1);
652 dc
.DrawPoint(x
+1, y
);
653 dc
.SetPen(m_gripper_pen3
);
654 dc
.DrawPoint(x
+2, y
+1);
655 dc
.DrawPoint(x
+2, y
+2);
656 dc
.DrawPoint(x
+1, y
+2);
663 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
668 if (state
& wxAUI_BUTTON_STATE_HOVER
||
669 state
& wxAUI_BUTTON_STATE_PRESSED
)
671 wxRect cli_rect
= wnd
->GetClientRect();
672 wxColor light_gray_bg
= wxAuiStepColour(m_highlight_colour
, 170);
674 if (m_flags
& wxAUI_TB_VERTICAL
)
676 dc
.SetPen(wxPen(m_highlight_colour
));
677 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
678 dc
.SetPen(wxPen(light_gray_bg
));
679 dc
.SetBrush(wxBrush(light_gray_bg
));
680 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
684 dc
.SetPen(wxPen(m_highlight_colour
));
685 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
686 dc
.SetPen(wxPen(light_gray_bg
));
687 dc
.SetBrush(wxBrush(light_gray_bg
));
688 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
692 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
693 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
694 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
697 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
701 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
702 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
703 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
708 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
712 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
;
713 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
;
714 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
;
718 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
719 const wxAuiToolBarItemArray
& items
)
723 size_t items_added
= 0;
725 size_t i
, count
= items
.GetCount();
726 for (i
= 0; i
< count
; ++i
)
728 wxAuiToolBarItem
& item
= items
.Item(i
);
730 if (item
.kind
== wxITEM_NORMAL
)
732 wxString text
= item
.short_help
;
740 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
);
742 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
, false);
745 m
->SetBitmap(item
.bitmap
);
749 else if (item
.kind
== wxITEM_SEPARATOR
)
752 menuPopup
.AppendSeparator();
756 // find out where to put the popup menu of window items
757 wxPoint pt
= ::wxGetMousePosition();
758 pt
= wnd
->ScreenToClient(pt
);
760 // find out the screen coordinate at the bottom of the tab ctrl
761 wxRect cli_rect
= wnd
->GetClientRect();
762 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
764 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
765 wnd
->PushEventHandler(cc
);
766 wnd
->PopupMenu(&menuPopup
, pt
);
767 int command
= cc
->GetCommandId();
768 wnd
->PopEventHandler(true);
776 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
777 EVT_SIZE(wxAuiToolBar::OnSize
)
778 EVT_IDLE(wxAuiToolBar::OnIdle
)
779 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
780 EVT_PAINT(wxAuiToolBar::OnPaint
)
781 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
782 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
783 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
784 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
785 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
786 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
787 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
788 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
789 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
790 EVT_MOTION(wxAuiToolBar::OnMotion
)
791 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
792 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
796 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
798 const wxPoint
& position
,
805 style
| wxBORDER_NONE
)
807 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
809 m_button_height
= -1;
810 m_sizer_element_count
= 0;
811 m_action_pos
= wxPoint(-1,-1);
812 m_action_item
= NULL
;
814 m_art
= new wxAuiDefaultToolBarArt
;
816 m_tool_border_padding
= 3;
817 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
818 m_gripper_sizer_item
= NULL
;
819 m_overflow_sizer_item
= NULL
;
822 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
823 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
824 m_overflow_state
= 0;
825 SetMargins(5, 5, 2, 2);
826 SetFont(*wxNORMAL_FONT
);
827 m_art
->SetFlags((unsigned int)m_style
);
828 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
829 if (style
& wxAUI_TB_HORZ_TEXT
)
830 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
834 wxAuiToolBar::~wxAuiToolBar()
840 void wxAuiToolBar::SetWindowStyleFlag(long style
)
842 wxControl::SetWindowStyleFlag(style
);
848 m_art
->SetFlags((unsigned int)m_style
);
851 if (m_style
& wxAUI_TB_GRIPPER
)
852 m_gripper_visible
= true;
854 m_gripper_visible
= false;
857 if (m_style
& wxAUI_TB_OVERFLOW
)
858 m_overflow_visible
= true;
860 m_overflow_visible
= false;
862 if (style
& wxAUI_TB_HORZ_TEXT
)
863 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
865 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
869 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
877 m_art
->SetFlags((unsigned int)m_style
);
878 m_art
->SetTextOrientation(m_tool_text_orientation
);
882 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
890 void wxAuiToolBar::AddTool(int tool_id
,
891 const wxString
& label
,
892 const wxBitmap
& bitmap
,
893 const wxString
& short_help_string
,
907 void wxAuiToolBar::AddTool(int tool_id
,
908 const wxString
& label
,
909 const wxBitmap
& bitmap
,
910 const wxBitmap
& disabled_bitmap
,
912 const wxString
& WXUNUSED(short_help_string
),
913 const wxString
& WXUNUSED(long_help_string
),
914 wxObject
* WXUNUSED(client_data
))
916 wxAuiToolBarItem item
;
919 item
.bitmap
= bitmap
;
920 item
.disabled_bitmap
= disabled_bitmap
;
922 item
.dropdown
= false;
923 item
.space_pixels
= 0;
928 item
.sizer_item
= NULL
;
929 item
.min_size
= wxDefaultSize
;
933 if (!item
.disabled_bitmap
.IsOk())
935 // no disabled bitmap specified, we need to make one
936 if (item
.bitmap
.IsOk())
938 //wxImage img = item.bitmap.ConvertToImage();
939 //wxImage grey_version = img.ConvertToGreyscale();
940 //item.disabled_bitmap = wxBitmap(grey_version);
941 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
948 void wxAuiToolBar::AddControl(wxControl
* control
,
949 const wxString
& label
)
951 wxAuiToolBarItem item
;
952 item
.window
= (wxWindow
*)control
;
954 item
.bitmap
= wxNullBitmap
;
955 item
.disabled_bitmap
= wxNullBitmap
;
957 item
.dropdown
= false;
958 item
.space_pixels
= 0;
959 item
.id
= control
->GetId();
962 item
.kind
= wxITEM_CONTROL
;
963 item
.sizer_item
= NULL
;
964 item
.min_size
= control
->GetEffectiveMinSize();
971 void wxAuiToolBar::AddLabel(int tool_id
,
972 const wxString
& label
,
975 wxSize min_size
= wxDefaultSize
;
979 wxAuiToolBarItem item
;
982 item
.bitmap
= wxNullBitmap
;
983 item
.disabled_bitmap
= wxNullBitmap
;
985 item
.dropdown
= false;
986 item
.space_pixels
= 0;
990 item
.kind
= wxITEM_LABEL
;
991 item
.sizer_item
= NULL
;
992 item
.min_size
= min_size
;
999 void wxAuiToolBar::AddSeparator()
1001 wxAuiToolBarItem item
;
1003 item
.label
= wxEmptyString
;
1004 item
.bitmap
= wxNullBitmap
;
1005 item
.disabled_bitmap
= wxNullBitmap
;
1007 item
.dropdown
= false;
1010 item
.proportion
= 0;
1011 item
.kind
= wxITEM_SEPARATOR
;
1012 item
.sizer_item
= NULL
;
1013 item
.min_size
= wxDefaultSize
;
1015 item
.sticky
= false;
1020 void wxAuiToolBar::AddSpacer(int pixels
)
1022 wxAuiToolBarItem item
;
1024 item
.label
= wxEmptyString
;
1025 item
.bitmap
= wxNullBitmap
;
1026 item
.disabled_bitmap
= wxNullBitmap
;
1028 item
.dropdown
= false;
1029 item
.space_pixels
= pixels
;
1032 item
.proportion
= 0;
1033 item
.kind
= wxITEM_SPACER
;
1034 item
.sizer_item
= NULL
;
1035 item
.min_size
= wxDefaultSize
;
1037 item
.sticky
= false;
1042 void wxAuiToolBar::AddStretchSpacer(int proportion
)
1044 wxAuiToolBarItem item
;
1046 item
.label
= wxEmptyString
;
1047 item
.bitmap
= wxNullBitmap
;
1048 item
.disabled_bitmap
= wxNullBitmap
;
1050 item
.dropdown
= false;
1051 item
.space_pixels
= 0;
1054 item
.proportion
= proportion
;
1055 item
.kind
= wxITEM_SPACER
;
1056 item
.sizer_item
= NULL
;
1057 item
.min_size
= wxDefaultSize
;
1059 item
.sticky
= false;
1064 void wxAuiToolBar::Clear()
1067 m_sizer_element_count
= 0;
1070 bool wxAuiToolBar::DeleteTool(int tool_id
)
1072 int idx
= GetToolIndex(tool_id
);
1073 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1075 m_items
.RemoveAt(idx
);
1083 bool wxAuiToolBar::DeleteByIndex(int idx
)
1085 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1087 m_items
.RemoveAt(idx
);
1096 wxControl
* wxAuiToolBar::FindControl(int id
)
1098 wxWindow
* wnd
= FindWindow(id
);
1099 return (wxControl
*)wnd
;
1102 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1105 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1107 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1108 if (item
.id
== tool_id
)
1115 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1118 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1120 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1122 if (!item
.sizer_item
)
1125 wxRect rect
= item
.sizer_item
->GetRect();
1126 if (rect
.Contains(x
,y
))
1128 // if the item doesn't fit on the toolbar, return NULL
1129 if (!GetToolFitsByIndex(i
))
1139 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1142 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1144 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1146 if (!item
.sizer_item
)
1149 wxRect rect
= item
.sizer_item
->GetRect();
1151 // apply tool packing
1153 rect
.width
+= m_tool_packing
;
1155 if (rect
.Contains(x
,y
))
1157 // if the item doesn't fit on the toolbar, return NULL
1158 if (!GetToolFitsByIndex(i
))
1168 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1173 if (idx
>= (int)m_items
.size())
1176 return &(m_items
[idx
]);
1179 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1181 // TODO: wxToolBar compatibility
1184 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1186 // TODO: wxToolBar compatibility
1187 return wxSize(16,15);
1190 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1192 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1196 item
->proportion
= proportion
;
1199 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1201 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1205 return item
->proportion
;
1208 void wxAuiToolBar::SetToolSeparation(int separation
)
1211 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1214 int wxAuiToolBar::GetToolSeparation() const
1217 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1223 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1225 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1229 item
->dropdown
= dropdown
;
1232 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1234 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1238 return item
->dropdown
;
1241 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1243 // ignore separators
1247 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1251 if (item
->sticky
== sticky
)
1254 item
->sticky
= sticky
;
1260 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1262 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1266 return item
->sticky
;
1272 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1274 m_tool_border_padding
= padding
;
1277 int wxAuiToolBar::GetToolBorderPadding() const
1279 return m_tool_border_padding
;
1282 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1284 m_tool_text_orientation
= orientation
;
1288 m_art
->SetTextOrientation(orientation
);
1292 int wxAuiToolBar::GetToolTextOrientation() const
1294 return m_tool_text_orientation
;
1297 void wxAuiToolBar::SetToolPacking(int packing
)
1299 m_tool_packing
= packing
;
1302 int wxAuiToolBar::GetToolPacking() const
1304 return m_tool_packing
;
1308 void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation
))
1312 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1315 m_left_padding
= left
;
1317 m_right_padding
= right
;
1319 m_top_padding
= top
;
1321 m_bottom_padding
= bottom
;
1324 bool wxAuiToolBar::GetGripperVisible() const
1326 return m_gripper_visible
;
1329 void wxAuiToolBar::SetGripperVisible(bool visible
)
1331 m_gripper_visible
= visible
;
1333 m_style
|= wxAUI_TB_GRIPPER
;
1339 bool wxAuiToolBar::GetOverflowVisible() const
1341 return m_overflow_visible
;
1344 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1346 m_overflow_visible
= visible
;
1348 m_style
|= wxAUI_TB_OVERFLOW
;
1352 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1354 bool res
= wxWindow::SetFont(font
);
1358 m_art
->SetFont(font
);
1365 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1367 wxAuiToolBarItem
* former_hover
= NULL
;
1370 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1372 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1373 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1374 former_hover
= &item
;
1375 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1380 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1383 if (former_hover
!= pitem
)
1390 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1392 wxAuiToolBarItem
* former_item
= NULL
;
1395 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1397 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1398 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1399 former_item
= &item
;
1400 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1405 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1406 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1409 if (former_item
!= pitem
)
1416 void wxAuiToolBar::RefreshOverflowState()
1418 if (!m_overflow_sizer_item
)
1420 m_overflow_state
= 0;
1424 int overflow_state
= 0;
1426 wxRect overflow_rect
= GetOverflowRect();
1429 // find out the mouse's current position
1430 wxPoint pt
= ::wxGetMousePosition();
1431 pt
= this->ScreenToClient(pt
);
1433 // find out if the mouse cursor is inside the dropdown rectangle
1434 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1436 if (::wxGetMouseState().LeftDown())
1437 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1439 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1442 if (overflow_state
!= m_overflow_state
)
1444 m_overflow_state
= overflow_state
;
1449 m_overflow_state
= overflow_state
;
1452 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1454 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1458 if (tool
->kind
!= wxITEM_CHECK
)
1462 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1464 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1468 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1470 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1474 if (tool
->kind
!= wxITEM_CHECK
)
1477 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1483 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1485 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1490 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1492 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1496 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1498 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1501 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1506 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1508 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1509 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1511 return wxEmptyString
;
1516 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1518 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1521 tool
->label
= label
;
1525 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1527 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1528 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1530 return wxNullBitmap
;
1532 return tool
->bitmap
;
1535 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1537 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1540 tool
->bitmap
= bitmap
;
1544 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1546 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1547 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1549 return wxEmptyString
;
1551 return tool
->short_help
;
1554 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1556 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1559 tool
->short_help
= help_string
;
1563 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1565 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1566 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1568 return wxEmptyString
;
1570 return tool
->long_help
;
1573 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1575 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1578 tool
->long_help
= help_string
;
1582 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1583 const wxAuiToolBarItemArray
& append
)
1585 m_custom_overflow_prepend
= prepend
;
1586 m_custom_overflow_append
= append
;
1590 size_t wxAuiToolBar::GetToolCount() const
1592 return m_items
.size();
1595 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1597 // this will prevent us from returning the index of the
1598 // first separator in the toolbar since its id is equal to -1
1602 size_t i
, count
= m_items
.GetCount();
1603 for (i
= 0; i
< count
; ++i
)
1605 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1606 if (item
.id
== tool_id
)
1613 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1615 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1618 if (!m_items
[tool_idx
].sizer_item
)
1622 GetClientSize(&cli_w
, &cli_h
);
1624 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1626 if (m_style
& wxAUI_TB_VERTICAL
)
1628 // take the dropdown size into account
1629 if (m_overflow_visible
)
1630 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1632 if (rect
.y
+rect
.height
< cli_h
)
1637 // take the dropdown size into account
1638 if (m_overflow_visible
)
1639 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1641 if (rect
.x
+rect
.width
< cli_w
)
1649 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1651 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1654 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1656 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1657 if (tool
&& tool
->sizer_item
)
1659 return tool
->sizer_item
->GetRect();
1665 bool wxAuiToolBar::GetToolBarFits() const
1667 if (m_items
.GetCount() == 0)
1669 // empty toolbar always 'fits'
1673 // entire toolbar content fits if the last tool fits
1674 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1677 bool wxAuiToolBar::Realize()
1679 wxClientDC
dc(this);
1683 bool horizontal
= true;
1684 if (m_style
& wxAUI_TB_VERTICAL
)
1688 // create the new sizer to add toolbar elements to
1689 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1692 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1693 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1694 if (gripper_size
> 0 && m_gripper_visible
)
1697 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1699 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1703 m_gripper_sizer_item
= NULL
;
1706 // add "left" padding
1707 if (m_left_padding
> 0)
1710 sizer
->Add(m_left_padding
, 1);
1712 sizer
->Add(1, m_left_padding
);
1716 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1718 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1719 wxSizerItem
* sizer_item
= NULL
;
1725 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1726 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1727 size
.y
+ (m_tool_border_padding
*2),
1732 sizer
->AddSpacer(m_tool_packing
);
1741 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1742 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1743 size
.y
+ (m_tool_border_padding
*2),
1749 sizer
->AddSpacer(m_tool_packing
);
1755 case wxITEM_SEPARATOR
:
1758 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1760 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1765 sizer
->AddSpacer(m_tool_packing
);
1772 if (item
.proportion
> 0)
1773 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1775 sizer_item
= sizer
->Add(item
.space_pixels
, 1);
1778 case wxITEM_CONTROL
:
1780 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1781 wxSizerItem
* ctrl_sizer_item
;
1783 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1784 vert_sizer
->AddStretchSpacer(1);
1785 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1786 vert_sizer
->AddStretchSpacer(1);
1787 if ((m_style
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
1789 wxSize s
= GetLabelSize(item
.label
);
1790 vert_sizer
->Add(1, s
.y
);
1794 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1796 wxSize min_size
= item
.min_size
;
1799 // proportional items will disappear from the toolbar if
1800 // their min width is not set to something really small
1801 if (item
.proportion
!= 0)
1806 if (min_size
.IsFullySpecified())
1808 sizer_item
->SetMinSize(min_size
);
1809 ctrl_sizer_item
->SetMinSize(min_size
);
1815 sizer
->AddSpacer(m_tool_packing
);
1820 item
.sizer_item
= sizer_item
;
1823 // add "right" padding
1824 if (m_right_padding
> 0)
1827 sizer
->Add(m_right_padding
, 1);
1829 sizer
->Add(1, m_right_padding
);
1832 // add drop down area
1833 m_overflow_sizer_item
= NULL
;
1835 if (m_style
& wxAUI_TB_OVERFLOW
)
1837 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1838 if (overflow_size
> 0 && m_overflow_visible
)
1841 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
1843 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
1847 m_overflow_sizer_item
= NULL
;
1852 // the outside sizer helps us apply the "top" and "bottom" padding
1853 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
1855 // add "top" padding
1856 if (m_top_padding
> 0)
1859 outside_sizer
->Add(1, m_top_padding
);
1861 outside_sizer
->Add(m_top_padding
, 1);
1864 // add the sizer that contains all of the toolbar elements
1865 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
1867 // add "bottom" padding
1868 if (m_bottom_padding
> 0)
1871 outside_sizer
->Add(1, m_bottom_padding
);
1873 outside_sizer
->Add(m_bottom_padding
, 1);
1876 delete m_sizer
; // remove old sizer
1877 m_sizer
= outside_sizer
;
1879 // calculate the rock-bottom minimum size
1880 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1882 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1883 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1884 item
.sizer_item
->SetMinSize(0,0);
1887 m_absolute_min_size
= m_sizer
->GetMinSize();
1889 // reset the min sizes to what they were
1890 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1892 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1893 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1894 item
.sizer_item
->SetMinSize(item
.min_size
);
1898 wxSize size
= m_sizer
->GetMinSize();
1899 m_minWidth
= size
.x
;
1900 m_minHeight
= size
.y
;
1902 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
1904 wxSize cur_size
= GetClientSize();
1905 wxSize new_size
= GetMinSize();
1906 if (new_size
!= cur_size
)
1908 SetClientSize(new_size
);
1912 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1917 wxSize cur_size
= GetClientSize();
1918 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1925 int wxAuiToolBar::GetOverflowState() const
1927 return m_overflow_state
;
1930 wxRect
wxAuiToolBar::GetOverflowRect() const
1932 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
1933 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
1934 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1936 if (m_style
& wxAUI_TB_VERTICAL
)
1938 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
1939 overflow_rect
.x
= 0;
1940 overflow_rect
.width
= cli_rect
.width
;
1941 overflow_rect
.height
= overflow_size
;
1945 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
1946 overflow_rect
.y
= 0;
1947 overflow_rect
.width
= overflow_size
;
1948 overflow_rect
.height
= cli_rect
.height
;
1951 return overflow_rect
;
1954 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
1956 wxClientDC
dc(this);
1959 int text_width
= 0, text_height
= 0;
1963 // get the text height
1964 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
1966 // get the text width
1967 dc
.GetTextExtent(label
, &text_width
, &ty
);
1969 return wxSize(text_width
, text_height
);
1973 void wxAuiToolBar::DoIdleUpdate()
1975 wxEvtHandler
* handler
= GetEventHandler();
1977 bool need_refresh
= false;
1980 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1982 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1987 wxUpdateUIEvent
evt(item
.id
);
1988 evt
.SetEventObject(this);
1990 if (handler
->ProcessEvent(evt
))
1992 if (evt
.GetSetEnabled())
1996 is_enabled
= item
.window
->IsEnabled();
1998 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2000 bool new_enabled
= evt
.GetEnabled();
2001 if (new_enabled
!= is_enabled
)
2005 item
.window
->Enable(new_enabled
);
2010 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2012 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2014 need_refresh
= true;
2018 if (evt
.GetSetChecked())
2020 // make sure we aren't checking an item that can't be
2021 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2024 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2025 bool new_checked
= evt
.GetChecked();
2027 if (new_checked
!= is_checked
)
2030 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2032 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2034 need_refresh
= true;
2049 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2052 GetClientSize(&x
, &y
);
2055 SetOrientation(wxHORIZONTAL
);
2057 SetOrientation(wxVERTICAL
);
2059 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2060 ((y
> x
) && m_absolute_min_size
.y
> y
))
2062 // hide all flexible items
2064 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2066 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2067 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2069 item
.sizer_item
->Show(false);
2070 item
.sizer_item
->SetProportion(0);
2076 // show all flexible items
2078 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2080 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2081 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2083 item
.sizer_item
->Show(true);
2084 item
.sizer_item
->SetProportion(item
.proportion
);
2089 m_sizer
->SetDimension(0, 0, x
, y
);
2097 void wxAuiToolBar::DoSetSize(int x
,
2103 wxSize parent_size
= GetParent()->GetClientSize();
2104 if (x
+ width
> parent_size
.x
)
2105 width
= wxMax(0, parent_size
.x
- x
);
2106 if (y
+ height
> parent_size
.y
)
2107 height
= wxMax(0, parent_size
.y
- y
);
2109 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2113 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2119 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2121 wxBufferedPaintDC
dc(this);
2122 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2125 bool horizontal
= true;
2126 if (m_style
& wxAUI_TB_VERTICAL
)
2130 m_art
->DrawBackground(dc
, this, cli_rect
);
2132 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2133 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2135 // paint the gripper
2136 if (gripper_size
> 0 && m_gripper_sizer_item
)
2138 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2140 gripper_rect
.width
= gripper_size
;
2142 gripper_rect
.height
= gripper_size
;
2143 m_art
->DrawGripper(dc
, this, gripper_rect
);
2146 // calculated how far we can draw items
2149 last_extent
= cli_rect
.width
;
2151 last_extent
= cli_rect
.height
;
2152 if (m_overflow_visible
)
2153 last_extent
-= dropdown_size
;
2155 // paint each individual tool
2156 size_t i
, count
= m_items
.GetCount();
2157 for (i
= 0; i
< count
; ++i
)
2159 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2161 if (!item
.sizer_item
)
2164 wxRect item_rect
= item
.sizer_item
->GetRect();
2167 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2168 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2173 if (item
.kind
== wxITEM_SEPARATOR
)
2176 m_art
->DrawSeparator(dc
, this, item_rect
);
2178 else if (item
.kind
== wxITEM_LABEL
)
2180 // draw a text label only
2181 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2183 else if (item
.kind
== wxITEM_NORMAL
)
2185 // draw a regular button or dropdown button
2187 m_art
->DrawButton(dc
, this, item
, item_rect
);
2189 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2191 else if (item
.kind
== wxITEM_CHECK
)
2193 // draw a toggle button
2194 m_art
->DrawButton(dc
, this, item
, item_rect
);
2196 else if (item
.kind
== wxITEM_CONTROL
)
2198 // draw the control's label
2199 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2202 // fire a signal to see if the item wants to be custom-rendered
2203 OnCustomRender(dc
, item
, item_rect
);
2206 // paint the overflow button
2207 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2209 wxRect dropdown_rect
= GetOverflowRect();
2210 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2214 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2219 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2221 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2223 if (m_gripper_sizer_item
)
2225 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2226 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2229 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2233 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2234 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2236 // gripper was clicked
2237 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2242 if (m_overflow_sizer_item
)
2244 wxRect overflow_rect
= GetOverflowRect();
2247 m_overflow_visible
&&
2248 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2250 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2251 e
.SetEventObject(this);
2253 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2254 bool processed
= ProcessEvent(e
);
2263 wxAuiToolBarItemArray overflow_items
;
2266 // add custom overflow prepend items, if any
2267 count
= m_custom_overflow_prepend
.GetCount();
2268 for (i
= 0; i
< count
; ++i
)
2269 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2271 // only show items that don't fit in the dropdown
2272 count
= m_items
.GetCount();
2273 for (i
= 0; i
< count
; ++i
)
2275 if (!GetToolFitsByIndex(i
))
2276 overflow_items
.Add(m_items
[i
]);
2279 // add custom overflow append items, if any
2280 count
= m_custom_overflow_append
.GetCount();
2281 for (i
= 0; i
< count
; ++i
)
2282 overflow_items
.Add(m_custom_overflow_append
[i
]);
2284 int res
= m_art
->ShowDropDown(this, overflow_items
);
2285 m_overflow_state
= 0;
2289 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2290 e
.SetEventObject(this);
2291 GetParent()->ProcessEvent(e
);
2300 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2301 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2305 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2307 m_action_pos
= wxPoint(-1,-1);
2308 m_action_item
= NULL
;
2312 SetPressedItem(m_action_item
);
2314 // fire the tool dropdown event
2315 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2316 e
.SetEventObject(this);
2317 e
.SetToolId(m_action_item
->id
);
2318 e
.SetDropDownClicked(false);
2320 int mouse_x
= evt
.GetX();
2321 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2323 if (m_action_item
->dropdown
&&
2324 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2325 mouse_x
< (rect
.x
+rect
.width
))
2327 e
.SetDropDownClicked(true);
2330 e
.SetClickPoint(evt
.GetPosition());
2331 e
.SetItemRect(rect
);
2337 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2339 SetPressedItem(NULL
);
2341 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2342 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2344 SetHoverItem(hit_item
);
2350 // reset drag and drop member variables
2352 m_action_pos
= wxPoint(-1,-1);
2353 m_action_item
= NULL
;
2358 wxAuiToolBarItem
* hit_item
;
2359 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2361 if (m_action_item
&& hit_item
== m_action_item
)
2365 if (hit_item
->kind
== wxITEM_CHECK
)
2367 bool toggle
= false;
2369 if (m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
)
2374 ToggleTool(m_action_item
->id
, toggle
);
2376 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2377 e
.SetEventObject(this);
2383 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2384 e
.SetEventObject(this);
2391 // reset drag and drop member variables
2393 m_action_pos
= wxPoint(-1,-1);
2394 m_action_item
= NULL
;
2397 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2399 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2401 if (m_gripper_sizer_item
)
2403 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2404 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2408 if (m_overflow_sizer_item
)
2410 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2411 if (dropdown_size
> 0 &&
2412 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2414 evt
.m_y
< cli_rect
.height
&&
2421 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2422 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2426 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2428 m_action_pos
= wxPoint(-1,-1);
2429 m_action_item
= NULL
;
2435 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2437 wxAuiToolBarItem
* hit_item
;
2438 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2440 if (m_action_item
&& hit_item
== m_action_item
)
2442 if (hit_item
->kind
== wxITEM_NORMAL
)
2444 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2445 e
.SetEventObject(this);
2446 e
.SetToolId(m_action_item
->id
);
2447 e
.SetClickPoint(m_action_pos
);
2454 // right-clicked on the invalid area of the toolbar
2455 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2456 e
.SetEventObject(this);
2458 e
.SetClickPoint(m_action_pos
);
2463 // reset member variables
2464 m_action_pos
= wxPoint(-1,-1);
2465 m_action_item
= NULL
;
2468 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2470 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2472 if (m_gripper_sizer_item
)
2474 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2475 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2479 if (m_overflow_sizer_item
)
2481 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2482 if (dropdown_size
> 0 &&
2483 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2485 evt
.m_y
< cli_rect
.height
&&
2492 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2493 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2497 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2499 m_action_pos
= wxPoint(-1,-1);
2500 m_action_item
= NULL
;
2506 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2508 wxAuiToolBarItem
* hit_item
;
2509 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2511 if (m_action_item
&& hit_item
== m_action_item
)
2513 if (hit_item
->kind
== wxITEM_NORMAL
)
2515 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2516 e
.SetEventObject(this);
2517 e
.SetToolId(m_action_item
->id
);
2518 e
.SetClickPoint(m_action_pos
);
2524 // reset member variables
2525 m_action_pos
= wxPoint(-1,-1);
2526 m_action_item
= NULL
;
2529 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2531 // start a drag event
2533 m_action_item
!= NULL
&&
2534 m_action_pos
!= wxPoint(-1,-1) &&
2535 abs(evt
.m_x
- m_action_pos
.x
) + abs(evt
.m_y
- m_action_pos
.y
) > 5)
2541 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2542 e
.SetEventObject(this);
2543 e
.SetToolId(m_action_item
->id
);
2549 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2552 if (!(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2553 SetHoverItem(hit_item
);
2559 // no hit item, remove any hit item
2560 SetHoverItem(hit_item
);
2563 // figure out tooltips
2564 wxAuiToolBarItem
* packing_hit_item
;
2565 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2566 if (packing_hit_item
)
2568 if (packing_hit_item
!= m_tip_item
)
2570 m_tip_item
= packing_hit_item
;
2572 if (packing_hit_item
->short_help
.Length() > 0)
2573 SetToolTip(packing_hit_item
->short_help
);
2584 // if we've pressed down an item and we're hovering
2585 // over it, make sure it's state is set to pressed
2588 if (m_action_item
== hit_item
)
2589 SetPressedItem(m_action_item
);
2591 SetPressedItem(NULL
);
2594 // figure out the dropdown button state (are we hovering or pressing it?)
2595 RefreshOverflowState();
2598 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& WXUNUSED(evt
))
2600 RefreshOverflowState();
2602 SetPressedItem(NULL
);
2608 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2610 wxCursor cursor
= wxNullCursor
;
2612 if (m_gripper_sizer_item
)
2614 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2615 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2617 cursor
= wxCursor(wxCURSOR_SIZING
);
2621 evt
.SetCursor(cursor
);