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
.empty() )
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
.empty() )
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
.empty() )
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
.empty() )
567 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
568 width
= wxMax(width
, tx
+6);
571 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
572 !item
.label
.empty() )
574 width
+= 3; // space between left border and bitmap
575 width
+= 3; // space between bitmap and text
577 if ( !item
.label
.empty() )
579 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
581 height
= wxMax(height
, ty
);
586 // if the tool has a dropdown button, add it to the width
587 if (item
.dropdown
== true)
588 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
590 return wxSize(width
, height
);
593 void wxAuiDefaultToolBarArt::DrawSeparator(
595 wxWindow
* WXUNUSED(wnd
),
598 bool horizontal
= true;
599 if (m_flags
& wxAUI_TB_VERTICAL
)
606 rect
.x
+= (rect
.width
/2);
608 int new_height
= (rect
.height
*3)/4;
609 rect
.y
+= (rect
.height
/2) - (new_height
/2);
610 rect
.height
= new_height
;
614 rect
.y
+= (rect
.height
/2);
616 int new_width
= (rect
.width
*3)/4;
617 rect
.x
+= (rect
.width
/2) - (new_width
/2);
618 rect
.width
= new_width
;
621 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 80);
622 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 80);
623 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
626 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
627 wxWindow
* WXUNUSED(wnd
),
635 if (m_flags
& wxAUI_TB_VERTICAL
)
637 x
= rect
.x
+ (i
*4) + 5;
639 if (x
> rect
.GetWidth()-5)
645 y
= rect
.y
+ (i
*4) + 5;
646 if (y
> rect
.GetHeight()-5)
650 dc
.SetPen(m_gripper_pen1
);
652 dc
.SetPen(m_gripper_pen2
);
653 dc
.DrawPoint(x
, y
+1);
654 dc
.DrawPoint(x
+1, y
);
655 dc
.SetPen(m_gripper_pen3
);
656 dc
.DrawPoint(x
+2, y
+1);
657 dc
.DrawPoint(x
+2, y
+2);
658 dc
.DrawPoint(x
+1, y
+2);
665 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
670 if (state
& wxAUI_BUTTON_STATE_HOVER
||
671 state
& wxAUI_BUTTON_STATE_PRESSED
)
673 wxRect cli_rect
= wnd
->GetClientRect();
674 wxColor light_gray_bg
= wxAuiStepColour(m_highlight_colour
, 170);
676 if (m_flags
& wxAUI_TB_VERTICAL
)
678 dc
.SetPen(wxPen(m_highlight_colour
));
679 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
680 dc
.SetPen(wxPen(light_gray_bg
));
681 dc
.SetBrush(wxBrush(light_gray_bg
));
682 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
686 dc
.SetPen(wxPen(m_highlight_colour
));
687 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
688 dc
.SetPen(wxPen(light_gray_bg
));
689 dc
.SetBrush(wxBrush(light_gray_bg
));
690 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
694 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
695 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
696 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
699 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
703 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
704 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
705 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
710 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
714 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
;
715 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
;
716 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
;
720 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
721 const wxAuiToolBarItemArray
& items
)
725 size_t items_added
= 0;
727 size_t i
, count
= items
.GetCount();
728 for (i
= 0; i
< count
; ++i
)
730 wxAuiToolBarItem
& item
= items
.Item(i
);
732 if (item
.kind
== wxITEM_NORMAL
)
734 wxString text
= item
.short_help
;
741 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
);
743 m
->SetBitmap(item
.bitmap
);
747 else if (item
.kind
== wxITEM_SEPARATOR
)
750 menuPopup
.AppendSeparator();
754 // find out where to put the popup menu of window items
755 wxPoint pt
= ::wxGetMousePosition();
756 pt
= wnd
->ScreenToClient(pt
);
758 // find out the screen coordinate at the bottom of the tab ctrl
759 wxRect cli_rect
= wnd
->GetClientRect();
760 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
762 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
763 wnd
->PushEventHandler(cc
);
764 wnd
->PopupMenu(&menuPopup
, pt
);
765 int command
= cc
->GetCommandId();
766 wnd
->PopEventHandler(true);
774 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
775 EVT_SIZE(wxAuiToolBar::OnSize
)
776 EVT_IDLE(wxAuiToolBar::OnIdle
)
777 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
778 EVT_PAINT(wxAuiToolBar::OnPaint
)
779 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
780 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
781 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
782 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
783 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
784 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
785 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
786 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
787 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
788 EVT_MOTION(wxAuiToolBar::OnMotion
)
789 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
790 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
794 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
796 const wxPoint
& position
,
803 style
| wxBORDER_NONE
)
805 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
807 m_button_height
= -1;
808 m_sizer_element_count
= 0;
809 m_action_pos
= wxPoint(-1,-1);
810 m_action_item
= NULL
;
812 m_art
= new wxAuiDefaultToolBarArt
;
814 m_tool_border_padding
= 3;
815 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
816 m_gripper_sizer_item
= NULL
;
817 m_overflow_sizer_item
= NULL
;
820 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
821 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
822 m_overflow_state
= 0;
823 SetMargins(5, 5, 2, 2);
824 SetFont(*wxNORMAL_FONT
);
825 m_art
->SetFlags((unsigned int)m_style
);
826 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
827 if (style
& wxAUI_TB_HORZ_TEXT
)
828 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
832 wxAuiToolBar::~wxAuiToolBar()
838 void wxAuiToolBar::SetWindowStyleFlag(long style
)
840 wxControl::SetWindowStyleFlag(style
);
846 m_art
->SetFlags((unsigned int)m_style
);
849 if (m_style
& wxAUI_TB_GRIPPER
)
850 m_gripper_visible
= true;
852 m_gripper_visible
= false;
855 if (m_style
& wxAUI_TB_OVERFLOW
)
856 m_overflow_visible
= true;
858 m_overflow_visible
= false;
860 if (style
& wxAUI_TB_HORZ_TEXT
)
861 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
863 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
867 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
875 m_art
->SetFlags((unsigned int)m_style
);
876 m_art
->SetTextOrientation(m_tool_text_orientation
);
880 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
888 void wxAuiToolBar::AddTool(int tool_id
,
889 const wxString
& label
,
890 const wxBitmap
& bitmap
,
891 const wxString
& short_help_string
,
905 void wxAuiToolBar::AddTool(int tool_id
,
906 const wxString
& label
,
907 const wxBitmap
& bitmap
,
908 const wxBitmap
& disabled_bitmap
,
910 const wxString
& WXUNUSED(short_help_string
),
911 const wxString
& WXUNUSED(long_help_string
),
912 wxObject
* WXUNUSED(client_data
))
914 wxAuiToolBarItem item
;
917 item
.bitmap
= bitmap
;
918 item
.disabled_bitmap
= disabled_bitmap
;
920 item
.dropdown
= false;
921 item
.space_pixels
= 0;
926 item
.sizer_item
= NULL
;
927 item
.min_size
= wxDefaultSize
;
931 if (!item
.disabled_bitmap
.IsOk())
933 // no disabled bitmap specified, we need to make one
934 if (item
.bitmap
.IsOk())
936 //wxImage img = item.bitmap.ConvertToImage();
937 //wxImage grey_version = img.ConvertToGreyscale();
938 //item.disabled_bitmap = wxBitmap(grey_version);
939 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
946 void wxAuiToolBar::AddControl(wxControl
* control
,
947 const wxString
& label
)
949 wxAuiToolBarItem item
;
950 item
.window
= (wxWindow
*)control
;
952 item
.bitmap
= wxNullBitmap
;
953 item
.disabled_bitmap
= wxNullBitmap
;
955 item
.dropdown
= false;
956 item
.space_pixels
= 0;
957 item
.id
= control
->GetId();
960 item
.kind
= wxITEM_CONTROL
;
961 item
.sizer_item
= NULL
;
962 item
.min_size
= control
->GetEffectiveMinSize();
969 void wxAuiToolBar::AddLabel(int tool_id
,
970 const wxString
& label
,
973 wxSize min_size
= wxDefaultSize
;
977 wxAuiToolBarItem item
;
980 item
.bitmap
= wxNullBitmap
;
981 item
.disabled_bitmap
= wxNullBitmap
;
983 item
.dropdown
= false;
984 item
.space_pixels
= 0;
988 item
.kind
= wxITEM_LABEL
;
989 item
.sizer_item
= NULL
;
990 item
.min_size
= min_size
;
997 void wxAuiToolBar::AddSeparator()
999 wxAuiToolBarItem item
;
1001 item
.label
= wxEmptyString
;
1002 item
.bitmap
= wxNullBitmap
;
1003 item
.disabled_bitmap
= wxNullBitmap
;
1005 item
.dropdown
= false;
1008 item
.proportion
= 0;
1009 item
.kind
= wxITEM_SEPARATOR
;
1010 item
.sizer_item
= NULL
;
1011 item
.min_size
= wxDefaultSize
;
1013 item
.sticky
= false;
1018 void wxAuiToolBar::AddSpacer(int pixels
)
1020 wxAuiToolBarItem item
;
1022 item
.label
= wxEmptyString
;
1023 item
.bitmap
= wxNullBitmap
;
1024 item
.disabled_bitmap
= wxNullBitmap
;
1026 item
.dropdown
= false;
1027 item
.space_pixels
= pixels
;
1030 item
.proportion
= 0;
1031 item
.kind
= wxITEM_SPACER
;
1032 item
.sizer_item
= NULL
;
1033 item
.min_size
= wxDefaultSize
;
1035 item
.sticky
= false;
1040 void wxAuiToolBar::AddStretchSpacer(int proportion
)
1042 wxAuiToolBarItem item
;
1044 item
.label
= wxEmptyString
;
1045 item
.bitmap
= wxNullBitmap
;
1046 item
.disabled_bitmap
= wxNullBitmap
;
1048 item
.dropdown
= false;
1049 item
.space_pixels
= 0;
1052 item
.proportion
= proportion
;
1053 item
.kind
= wxITEM_SPACER
;
1054 item
.sizer_item
= NULL
;
1055 item
.min_size
= wxDefaultSize
;
1057 item
.sticky
= false;
1062 void wxAuiToolBar::Clear()
1065 m_sizer_element_count
= 0;
1068 bool wxAuiToolBar::DeleteTool(int tool_id
)
1070 int idx
= GetToolIndex(tool_id
);
1071 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1073 m_items
.RemoveAt(idx
);
1081 bool wxAuiToolBar::DeleteByIndex(int idx
)
1083 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1085 m_items
.RemoveAt(idx
);
1094 wxControl
* wxAuiToolBar::FindControl(int id
)
1096 wxWindow
* wnd
= FindWindow(id
);
1097 return (wxControl
*)wnd
;
1100 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1103 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1105 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1106 if (item
.id
== tool_id
)
1113 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1116 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1118 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1120 if (!item
.sizer_item
)
1123 wxRect rect
= item
.sizer_item
->GetRect();
1124 if (rect
.Contains(x
,y
))
1126 // if the item doesn't fit on the toolbar, return NULL
1127 if (!GetToolFitsByIndex(i
))
1137 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1140 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1142 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1144 if (!item
.sizer_item
)
1147 wxRect rect
= item
.sizer_item
->GetRect();
1149 // apply tool packing
1151 rect
.width
+= m_tool_packing
;
1153 if (rect
.Contains(x
,y
))
1155 // if the item doesn't fit on the toolbar, return NULL
1156 if (!GetToolFitsByIndex(i
))
1166 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1171 if (idx
>= (int)m_items
.size())
1174 return &(m_items
[idx
]);
1177 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1179 // TODO: wxToolBar compatibility
1182 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1184 // TODO: wxToolBar compatibility
1185 return wxSize(16,15);
1188 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1190 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1194 item
->proportion
= proportion
;
1197 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1199 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1203 return item
->proportion
;
1206 void wxAuiToolBar::SetToolSeparation(int separation
)
1209 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1212 int wxAuiToolBar::GetToolSeparation() const
1215 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1221 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1223 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1227 item
->dropdown
= dropdown
;
1230 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1232 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1236 return item
->dropdown
;
1239 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1241 // ignore separators
1245 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1249 if (item
->sticky
== sticky
)
1252 item
->sticky
= sticky
;
1258 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1260 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1264 return item
->sticky
;
1270 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1272 m_tool_border_padding
= padding
;
1275 int wxAuiToolBar::GetToolBorderPadding() const
1277 return m_tool_border_padding
;
1280 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1282 m_tool_text_orientation
= orientation
;
1286 m_art
->SetTextOrientation(orientation
);
1290 int wxAuiToolBar::GetToolTextOrientation() const
1292 return m_tool_text_orientation
;
1295 void wxAuiToolBar::SetToolPacking(int packing
)
1297 m_tool_packing
= packing
;
1300 int wxAuiToolBar::GetToolPacking() const
1302 return m_tool_packing
;
1306 void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation
))
1310 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1313 m_left_padding
= left
;
1315 m_right_padding
= right
;
1317 m_top_padding
= top
;
1319 m_bottom_padding
= bottom
;
1322 bool wxAuiToolBar::GetGripperVisible() const
1324 return m_gripper_visible
;
1327 void wxAuiToolBar::SetGripperVisible(bool visible
)
1329 m_gripper_visible
= visible
;
1331 m_style
|= wxAUI_TB_GRIPPER
;
1337 bool wxAuiToolBar::GetOverflowVisible() const
1339 return m_overflow_visible
;
1342 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1344 m_overflow_visible
= visible
;
1346 m_style
|= wxAUI_TB_OVERFLOW
;
1350 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1352 bool res
= wxWindow::SetFont(font
);
1356 m_art
->SetFont(font
);
1363 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1365 wxAuiToolBarItem
* former_hover
= NULL
;
1368 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1370 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1371 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1372 former_hover
= &item
;
1373 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1378 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1381 if (former_hover
!= pitem
)
1388 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1390 wxAuiToolBarItem
* former_item
= NULL
;
1393 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1395 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1396 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1397 former_item
= &item
;
1398 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1403 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1404 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1407 if (former_item
!= pitem
)
1414 void wxAuiToolBar::RefreshOverflowState()
1416 if (!m_overflow_sizer_item
)
1418 m_overflow_state
= 0;
1422 int overflow_state
= 0;
1424 wxRect overflow_rect
= GetOverflowRect();
1427 // find out the mouse's current position
1428 wxPoint pt
= ::wxGetMousePosition();
1429 pt
= this->ScreenToClient(pt
);
1431 // find out if the mouse cursor is inside the dropdown rectangle
1432 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1434 if (::wxGetMouseState().LeftDown())
1435 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1437 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1440 if (overflow_state
!= m_overflow_state
)
1442 m_overflow_state
= overflow_state
;
1447 m_overflow_state
= overflow_state
;
1450 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1452 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1456 if (tool
->kind
!= wxITEM_CHECK
)
1460 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1462 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1466 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1468 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1472 if (tool
->kind
!= wxITEM_CHECK
)
1475 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1481 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1483 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1488 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1490 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1494 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1496 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1499 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1504 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1506 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1507 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1509 return wxEmptyString
;
1514 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1516 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1519 tool
->label
= label
;
1523 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1525 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1526 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1528 return wxNullBitmap
;
1530 return tool
->bitmap
;
1533 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1535 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1538 tool
->bitmap
= bitmap
;
1542 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1544 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1545 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1547 return wxEmptyString
;
1549 return tool
->short_help
;
1552 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1554 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1557 tool
->short_help
= help_string
;
1561 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1563 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1564 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1566 return wxEmptyString
;
1568 return tool
->long_help
;
1571 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1573 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1576 tool
->long_help
= help_string
;
1580 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1581 const wxAuiToolBarItemArray
& append
)
1583 m_custom_overflow_prepend
= prepend
;
1584 m_custom_overflow_append
= append
;
1588 size_t wxAuiToolBar::GetToolCount() const
1590 return m_items
.size();
1593 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1595 // this will prevent us from returning the index of the
1596 // first separator in the toolbar since its id is equal to -1
1600 size_t i
, count
= m_items
.GetCount();
1601 for (i
= 0; i
< count
; ++i
)
1603 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1604 if (item
.id
== tool_id
)
1611 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1613 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1616 if (!m_items
[tool_idx
].sizer_item
)
1620 GetClientSize(&cli_w
, &cli_h
);
1622 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1624 if (m_style
& wxAUI_TB_VERTICAL
)
1626 // take the dropdown size into account
1627 if (m_overflow_visible
)
1628 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1630 if (rect
.y
+rect
.height
< cli_h
)
1635 // take the dropdown size into account
1636 if (m_overflow_visible
)
1637 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1639 if (rect
.x
+rect
.width
< cli_w
)
1647 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1649 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1652 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1654 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1655 if (tool
&& tool
->sizer_item
)
1657 return tool
->sizer_item
->GetRect();
1663 bool wxAuiToolBar::GetToolBarFits() const
1665 if (m_items
.GetCount() == 0)
1667 // empty toolbar always 'fits'
1671 // entire toolbar content fits if the last tool fits
1672 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1675 bool wxAuiToolBar::Realize()
1677 wxClientDC
dc(this);
1681 bool horizontal
= true;
1682 if (m_style
& wxAUI_TB_VERTICAL
)
1686 // create the new sizer to add toolbar elements to
1687 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1690 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1691 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1692 if (gripper_size
> 0 && m_gripper_visible
)
1695 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1697 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1701 m_gripper_sizer_item
= NULL
;
1704 // add "left" padding
1705 if (m_left_padding
> 0)
1708 sizer
->Add(m_left_padding
, 1);
1710 sizer
->Add(1, m_left_padding
);
1714 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1716 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1717 wxSizerItem
* sizer_item
= NULL
;
1723 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1724 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1725 size
.y
+ (m_tool_border_padding
*2),
1730 sizer
->AddSpacer(m_tool_packing
);
1739 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1740 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1741 size
.y
+ (m_tool_border_padding
*2),
1747 sizer
->AddSpacer(m_tool_packing
);
1753 case wxITEM_SEPARATOR
:
1756 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1758 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1763 sizer
->AddSpacer(m_tool_packing
);
1770 if (item
.proportion
> 0)
1771 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1773 sizer_item
= sizer
->Add(item
.space_pixels
, 1);
1776 case wxITEM_CONTROL
:
1778 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1779 wxSizerItem
* ctrl_sizer_item
;
1781 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1782 vert_sizer
->AddStretchSpacer(1);
1783 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1784 vert_sizer
->AddStretchSpacer(1);
1785 if ( (m_style
& wxAUI_TB_TEXT
) && !item
.label
.empty() )
1787 wxSize s
= GetLabelSize(item
.label
);
1788 vert_sizer
->Add(1, s
.y
);
1792 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1794 wxSize min_size
= item
.min_size
;
1797 // proportional items will disappear from the toolbar if
1798 // their min width is not set to something really small
1799 if (item
.proportion
!= 0)
1804 if (min_size
.IsFullySpecified())
1806 sizer_item
->SetMinSize(min_size
);
1807 ctrl_sizer_item
->SetMinSize(min_size
);
1813 sizer
->AddSpacer(m_tool_packing
);
1818 item
.sizer_item
= sizer_item
;
1821 // add "right" padding
1822 if (m_right_padding
> 0)
1825 sizer
->Add(m_right_padding
, 1);
1827 sizer
->Add(1, m_right_padding
);
1830 // add drop down area
1831 m_overflow_sizer_item
= NULL
;
1833 if (m_style
& wxAUI_TB_OVERFLOW
)
1835 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1836 if (overflow_size
> 0 && m_overflow_visible
)
1839 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
1841 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
1845 m_overflow_sizer_item
= NULL
;
1850 // the outside sizer helps us apply the "top" and "bottom" padding
1851 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
1853 // add "top" padding
1854 if (m_top_padding
> 0)
1857 outside_sizer
->Add(1, m_top_padding
);
1859 outside_sizer
->Add(m_top_padding
, 1);
1862 // add the sizer that contains all of the toolbar elements
1863 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
1865 // add "bottom" padding
1866 if (m_bottom_padding
> 0)
1869 outside_sizer
->Add(1, m_bottom_padding
);
1871 outside_sizer
->Add(m_bottom_padding
, 1);
1874 delete m_sizer
; // remove old sizer
1875 m_sizer
= outside_sizer
;
1877 // calculate the rock-bottom minimum size
1878 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1880 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1881 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1882 item
.sizer_item
->SetMinSize(0,0);
1885 m_absolute_min_size
= m_sizer
->GetMinSize();
1887 // reset the min sizes to what they were
1888 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1890 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1891 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1892 item
.sizer_item
->SetMinSize(item
.min_size
);
1896 wxSize size
= m_sizer
->GetMinSize();
1897 m_minWidth
= size
.x
;
1898 m_minHeight
= size
.y
;
1900 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
1902 wxSize cur_size
= GetClientSize();
1903 wxSize new_size
= GetMinSize();
1904 if (new_size
!= cur_size
)
1906 SetClientSize(new_size
);
1910 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1915 wxSize cur_size
= GetClientSize();
1916 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1923 int wxAuiToolBar::GetOverflowState() const
1925 return m_overflow_state
;
1928 wxRect
wxAuiToolBar::GetOverflowRect() const
1930 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
1931 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
1932 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1934 if (m_style
& wxAUI_TB_VERTICAL
)
1936 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
1937 overflow_rect
.x
= 0;
1938 overflow_rect
.width
= cli_rect
.width
;
1939 overflow_rect
.height
= overflow_size
;
1943 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
1944 overflow_rect
.y
= 0;
1945 overflow_rect
.width
= overflow_size
;
1946 overflow_rect
.height
= cli_rect
.height
;
1949 return overflow_rect
;
1952 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
1954 wxClientDC
dc(this);
1957 int text_width
= 0, text_height
= 0;
1961 // get the text height
1962 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
1964 // get the text width
1965 dc
.GetTextExtent(label
, &text_width
, &ty
);
1967 return wxSize(text_width
, text_height
);
1971 void wxAuiToolBar::DoIdleUpdate()
1973 wxEvtHandler
* handler
= GetEventHandler();
1975 bool need_refresh
= false;
1978 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1980 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1985 wxUpdateUIEvent
evt(item
.id
);
1986 evt
.SetEventObject(this);
1988 if (handler
->ProcessEvent(evt
))
1990 if (evt
.GetSetEnabled())
1994 is_enabled
= item
.window
->IsEnabled();
1996 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1998 bool new_enabled
= evt
.GetEnabled();
1999 if (new_enabled
!= is_enabled
)
2003 item
.window
->Enable(new_enabled
);
2008 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2010 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2012 need_refresh
= true;
2016 if (evt
.GetSetChecked())
2018 // make sure we aren't checking an item that can't be
2019 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2022 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2023 bool new_checked
= evt
.GetChecked();
2025 if (new_checked
!= is_checked
)
2028 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2030 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2032 need_refresh
= true;
2047 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2050 GetClientSize(&x
, &y
);
2053 SetOrientation(wxHORIZONTAL
);
2055 SetOrientation(wxVERTICAL
);
2057 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2058 ((y
> x
) && m_absolute_min_size
.y
> y
))
2060 // hide all flexible items
2062 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2064 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2065 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2067 item
.sizer_item
->Show(false);
2068 item
.sizer_item
->SetProportion(0);
2074 // show all flexible items
2076 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2078 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2079 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2081 item
.sizer_item
->Show(true);
2082 item
.sizer_item
->SetProportion(item
.proportion
);
2087 m_sizer
->SetDimension(0, 0, x
, y
);
2095 void wxAuiToolBar::DoSetSize(int x
,
2101 wxSize parent_size
= GetParent()->GetClientSize();
2102 if (x
+ width
> parent_size
.x
)
2103 width
= wxMax(0, parent_size
.x
- x
);
2104 if (y
+ height
> parent_size
.y
)
2105 height
= wxMax(0, parent_size
.y
- y
);
2107 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2111 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2117 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2119 wxBufferedPaintDC
dc(this);
2120 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2123 bool horizontal
= true;
2124 if (m_style
& wxAUI_TB_VERTICAL
)
2128 m_art
->DrawBackground(dc
, this, cli_rect
);
2130 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2131 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2133 // paint the gripper
2134 if (gripper_size
> 0 && m_gripper_sizer_item
)
2136 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2138 gripper_rect
.width
= gripper_size
;
2140 gripper_rect
.height
= gripper_size
;
2141 m_art
->DrawGripper(dc
, this, gripper_rect
);
2144 // calculated how far we can draw items
2147 last_extent
= cli_rect
.width
;
2149 last_extent
= cli_rect
.height
;
2150 if (m_overflow_visible
)
2151 last_extent
-= dropdown_size
;
2153 // paint each individual tool
2154 size_t i
, count
= m_items
.GetCount();
2155 for (i
= 0; i
< count
; ++i
)
2157 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2159 if (!item
.sizer_item
)
2162 wxRect item_rect
= item
.sizer_item
->GetRect();
2165 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2166 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2171 if (item
.kind
== wxITEM_SEPARATOR
)
2174 m_art
->DrawSeparator(dc
, this, item_rect
);
2176 else if (item
.kind
== wxITEM_LABEL
)
2178 // draw a text label only
2179 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2181 else if (item
.kind
== wxITEM_NORMAL
)
2183 // draw a regular button or dropdown button
2185 m_art
->DrawButton(dc
, this, item
, item_rect
);
2187 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2189 else if (item
.kind
== wxITEM_CHECK
)
2191 // draw a toggle button
2192 m_art
->DrawButton(dc
, this, item
, item_rect
);
2194 else if (item
.kind
== wxITEM_CONTROL
)
2196 // draw the control's label
2197 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2200 // fire a signal to see if the item wants to be custom-rendered
2201 OnCustomRender(dc
, item
, item_rect
);
2204 // paint the overflow button
2205 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2207 wxRect dropdown_rect
= GetOverflowRect();
2208 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2212 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2217 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2219 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2221 if (m_gripper_sizer_item
)
2223 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2224 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2227 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2231 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2232 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2234 // gripper was clicked
2235 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2240 if (m_overflow_sizer_item
)
2242 wxRect overflow_rect
= GetOverflowRect();
2245 m_overflow_visible
&&
2246 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2248 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2249 e
.SetEventObject(this);
2251 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2252 bool processed
= ProcessEvent(e
);
2261 wxAuiToolBarItemArray overflow_items
;
2264 // add custom overflow prepend items, if any
2265 count
= m_custom_overflow_prepend
.GetCount();
2266 for (i
= 0; i
< count
; ++i
)
2267 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2269 // only show items that don't fit in the dropdown
2270 count
= m_items
.GetCount();
2271 for (i
= 0; i
< count
; ++i
)
2273 if (!GetToolFitsByIndex(i
))
2274 overflow_items
.Add(m_items
[i
]);
2277 // add custom overflow append items, if any
2278 count
= m_custom_overflow_append
.GetCount();
2279 for (i
= 0; i
< count
; ++i
)
2280 overflow_items
.Add(m_custom_overflow_append
[i
]);
2282 int res
= m_art
->ShowDropDown(this, overflow_items
);
2283 m_overflow_state
= 0;
2287 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2288 e
.SetEventObject(this);
2289 GetParent()->ProcessEvent(e
);
2298 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2299 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2303 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2305 m_action_pos
= wxPoint(-1,-1);
2306 m_action_item
= NULL
;
2310 SetPressedItem(m_action_item
);
2312 // fire the tool dropdown event
2313 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2314 e
.SetEventObject(this);
2315 e
.SetToolId(m_action_item
->id
);
2316 e
.SetDropDownClicked(false);
2318 int mouse_x
= evt
.GetX();
2319 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2321 if (m_action_item
->dropdown
&&
2322 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2323 mouse_x
< (rect
.x
+rect
.width
))
2325 e
.SetDropDownClicked(true);
2328 e
.SetClickPoint(evt
.GetPosition());
2329 e
.SetItemRect(rect
);
2335 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2337 SetPressedItem(NULL
);
2339 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2340 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2342 SetHoverItem(hit_item
);
2348 // reset drag and drop member variables
2350 m_action_pos
= wxPoint(-1,-1);
2351 m_action_item
= NULL
;
2356 wxAuiToolBarItem
* hit_item
;
2357 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2359 if (m_action_item
&& hit_item
== m_action_item
)
2363 if (hit_item
->kind
== wxITEM_CHECK
)
2365 bool toggle
= false;
2367 if (m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
)
2372 ToggleTool(m_action_item
->id
, toggle
);
2374 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2375 e
.SetEventObject(this);
2381 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2382 e
.SetEventObject(this);
2389 // reset drag and drop member variables
2391 m_action_pos
= wxPoint(-1,-1);
2392 m_action_item
= NULL
;
2395 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2397 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2399 if (m_gripper_sizer_item
)
2401 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2402 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2406 if (m_overflow_sizer_item
)
2408 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2409 if (dropdown_size
> 0 &&
2410 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2412 evt
.m_y
< cli_rect
.height
&&
2419 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2420 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2424 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2426 m_action_pos
= wxPoint(-1,-1);
2427 m_action_item
= NULL
;
2433 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2435 wxAuiToolBarItem
* hit_item
;
2436 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2438 if (m_action_item
&& hit_item
== m_action_item
)
2440 if (hit_item
->kind
== wxITEM_NORMAL
)
2442 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2443 e
.SetEventObject(this);
2444 e
.SetToolId(m_action_item
->id
);
2445 e
.SetClickPoint(m_action_pos
);
2452 // right-clicked on the invalid area of the toolbar
2453 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2454 e
.SetEventObject(this);
2456 e
.SetClickPoint(m_action_pos
);
2461 // reset member variables
2462 m_action_pos
= wxPoint(-1,-1);
2463 m_action_item
= NULL
;
2466 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2468 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2470 if (m_gripper_sizer_item
)
2472 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2473 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2477 if (m_overflow_sizer_item
)
2479 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2480 if (dropdown_size
> 0 &&
2481 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2483 evt
.m_y
< cli_rect
.height
&&
2490 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2491 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2495 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2497 m_action_pos
= wxPoint(-1,-1);
2498 m_action_item
= NULL
;
2504 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2506 wxAuiToolBarItem
* hit_item
;
2507 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2509 if (m_action_item
&& hit_item
== m_action_item
)
2511 if (hit_item
->kind
== wxITEM_NORMAL
)
2513 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2514 e
.SetEventObject(this);
2515 e
.SetToolId(m_action_item
->id
);
2516 e
.SetClickPoint(m_action_pos
);
2522 // reset member variables
2523 m_action_pos
= wxPoint(-1,-1);
2524 m_action_item
= NULL
;
2527 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2529 // start a drag event
2531 m_action_item
!= NULL
&&
2532 m_action_pos
!= wxPoint(-1,-1) &&
2533 abs(evt
.m_x
- m_action_pos
.x
) + abs(evt
.m_y
- m_action_pos
.y
) > 5)
2539 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2540 e
.SetEventObject(this);
2541 e
.SetToolId(m_action_item
->id
);
2547 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2550 if (!(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2551 SetHoverItem(hit_item
);
2557 // no hit item, remove any hit item
2558 SetHoverItem(hit_item
);
2561 // figure out tooltips
2562 wxAuiToolBarItem
* packing_hit_item
;
2563 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2564 if (packing_hit_item
)
2566 if (packing_hit_item
!= m_tip_item
)
2568 m_tip_item
= packing_hit_item
;
2570 if ( !packing_hit_item
->short_help
.empty() )
2571 SetToolTip(packing_hit_item
->short_help
);
2582 // if we've pressed down an item and we're hovering
2583 // over it, make sure it's state is set to pressed
2586 if (m_action_item
== hit_item
)
2587 SetPressedItem(m_action_item
);
2589 SetPressedItem(NULL
);
2592 // figure out the dropdown button state (are we hovering or pressing it?)
2593 RefreshOverflowState();
2596 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& WXUNUSED(evt
))
2598 RefreshOverflowState();
2600 SetPressedItem(NULL
);
2606 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2608 wxCursor cursor
= wxNullCursor
;
2610 if (m_gripper_sizer_item
)
2612 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2613 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2615 cursor
= wxCursor(wxCURSOR_SIZING
);
2619 evt
.SetCursor(cursor
);