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/mac/carbon/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()
114 wxBrush toolbarbrush
;
115 toolbarbrush
.MacSetTheme( kThemeBrushToolbarBackground
);
116 wxColor base_color
= toolbarbrush
.GetColour();
118 wxColor base_color
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
121 // the base_colour is too pale to use as our base colour,
122 // so darken it a bit --
123 if ((255-base_color
.Red()) +
124 (255-base_color
.Green()) +
125 (255-base_color
.Blue()) < 60)
127 base_color
= wxAuiStepColour(base_color
, 92);
135 class ToolbarCommandCapture
: public wxEvtHandler
139 ToolbarCommandCapture() { m_last_id
= 0; }
140 int GetCommandId() const { return m_last_id
; }
142 bool ProcessEvent(wxEvent
& evt
)
144 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
146 m_last_id
= evt
.GetId();
150 if (GetNextHandler())
151 return GetNextHandler()->ProcessEvent(evt
);
162 const wxColour DISABLED_TEXT_COLOR
= wxColour(wxAuiBlendColour(0,255,0.4),
163 wxAuiBlendColour(0,255,0.4),
164 wxAuiBlendColour(0,255,0.4));
167 wxAuiDefaultToolBarArt
::wxAuiDefaultToolBarArt()
169 m_base_colour
= GetBaseColor();
172 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
173 m_highlight_colour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
175 m_separator_size
= 7;
177 m_overflow_size
= 16;
179 wxColor darker1_colour
= wxAuiStepColour(m_base_colour
, 85);
180 wxColor darker2_colour
= wxAuiStepColour(m_base_colour
, 75);
181 wxColor darker3_colour
= wxAuiStepColour(m_base_colour
, 60);
182 wxColor darker4_colour
= wxAuiStepColour(m_base_colour
, 50);
183 wxColor darker5_colour
= wxAuiStepColour(m_base_colour
, 40);
185 m_gripper_pen1
= wxPen(darker5_colour
);
186 m_gripper_pen2
= wxPen(darker3_colour
);
187 m_gripper_pen3
= *wxWHITE_PEN
;
189 static unsigned char button_dropdown_bits
[] = { 0xe0, 0xf1, 0xfb };
190 static unsigned char overflow_bits
[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
192 m_button_dropdown_bmp
= wxAuiBitmapFromBits(button_dropdown_bits
, 5, 3,
194 m_disabled_button_dropdown_bmp
= wxAuiBitmapFromBits(
195 button_dropdown_bits
, 5, 3,
196 wxColor(128,128,128));
197 m_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, *wxBLACK
);
198 m_disabled_overflow_bmp
= wxAuiBitmapFromBits(overflow_bits
, 7, 6, wxColor(128,128,128));
200 m_font
= *wxNORMAL_FONT
;
203 wxAuiDefaultToolBarArt
::~wxAuiDefaultToolBarArt()
205 m_font
= *wxNORMAL_FONT
;
209 wxAuiToolBarArt
* wxAuiDefaultToolBarArt
::Clone()
211 return static_cast<wxAuiToolBarArt
*>(new wxAuiDefaultToolBarArt
);
214 void wxAuiDefaultToolBarArt
::SetFlags(unsigned int flags
)
219 void wxAuiDefaultToolBarArt
::SetFont(const wxFont
& font
)
224 void wxAuiDefaultToolBarArt
::SetTextOrientation(int orientation
)
226 m_text_orientation
= orientation
;
229 void wxAuiDefaultToolBarArt
::DrawBackground(
231 wxWindow
* WXUNUSED(wnd
),
236 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 150);
237 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 90);
238 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
241 void wxAuiDefaultToolBarArt
::DrawLabel(
243 wxWindow
* WXUNUSED(wnd
),
244 const wxAuiToolBarItem
& item
,
248 dc
.SetTextForeground(*wxBLACK
);
250 // we only care about the text height here since the text
251 // will get cropped based on the width of the item
252 int text_width
= 0, text_height
= 0;
253 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
255 // set the clipping region
256 wxRect clip_rect
= rect
;
257 clip_rect
.width
-= 1;
258 dc
.SetClippingRegion(clip_rect
);
262 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
263 dc
.DrawText(item
.label
, text_x
, text_y
);
264 dc
.DestroyClippingRegion();
268 void wxAuiDefaultToolBarArt
::DrawButton(
270 wxWindow
* WXUNUSED(wnd
),
271 const wxAuiToolBarItem
& item
,
274 int text_width
= 0, text_height
= 0;
276 if (m_flags
& wxAUI_TB_TEXT
)
282 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
284 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
287 int bmp_x
= 0, bmp_y
= 0;
288 int text_x
= 0, text_y
= 0;
290 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
294 (item
.bitmap
.GetWidth()/2);
297 ((rect
.height
-text_height
)/2) -
298 (item
.bitmap
.GetHeight()/2);
300 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
301 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
303 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
309 (item
.bitmap
.GetHeight()/2);
311 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
318 if (!(item
.state
& wxAUI_BUTTON_STATE_DISABLED
))
320 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
322 dc
.SetPen(wxPen(m_highlight_colour
));
323 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 150)));
324 dc
.DrawRectangle(rect
);
326 else if ((item
.state
& wxAUI_BUTTON_STATE_HOVER
) || item
.sticky
== true)
328 dc
.SetPen(wxPen(m_highlight_colour
));
329 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
331 // draw an even lighter background for checked item hovers (since
332 // the hover background is the same color as the check background)
333 if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
334 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 180)));
336 dc
.DrawRectangle(rect
);
338 else if (item
.state
& wxAUI_BUTTON_STATE_CHECKED
)
340 // it's important to put this code in an else statment after the
341 // hover, otherwise hovers won't draw properly for checked items
342 dc
.SetPen(wxPen(m_highlight_colour
));
343 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
344 dc
.DrawRectangle(rect
);
349 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
350 bmp
= item
.disabled_bitmap
;
357 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
359 // set the item's text color based on if it is disabled
360 dc
.SetTextForeground(*wxBLACK
);
361 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
362 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
364 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
366 dc
.DrawText(item
.label
, text_x
, text_y
);
371 void wxAuiDefaultToolBarArt
::DrawDropDownButton(
373 wxWindow
* WXUNUSED(wnd
),
374 const wxAuiToolBarItem
& item
,
377 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
378 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
380 wxRect button_rect
= wxRect(rect
.x
,
382 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
384 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
386 BUTTON_DROPDOWN_WIDTH
+1,
389 if (m_flags
& wxAUI_TB_TEXT
)
394 if (m_flags
& wxAUI_TB_TEXT
)
396 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
400 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
405 dropbmp_x
= dropdown_rect
.x
+
406 (dropdown_rect
.width
/2) -
407 (m_button_dropdown_bmp
.GetWidth()/2);
408 dropbmp_y
= dropdown_rect
.y
+
409 (dropdown_rect
.height
/2) -
410 (m_button_dropdown_bmp
.GetHeight()/2);
413 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
415 bmp_x
= button_rect
.x
+
416 (button_rect
.width
/2) -
417 (item
.bitmap
.GetWidth()/2);
418 bmp_y
= button_rect
.y
+
419 ((button_rect
.height
-text_height
)/2) -
420 (item
.bitmap
.GetHeight()/2);
422 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
423 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
425 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
431 (item
.bitmap
.GetHeight()/2);
433 text_x
= bmp_x
+ 3 + item
.bitmap
.GetWidth();
440 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
442 dc
.SetPen(wxPen(m_highlight_colour
));
443 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 140)));
444 dc
.DrawRectangle(button_rect
);
445 dc
.DrawRectangle(dropdown_rect
);
447 else if (item
.state
& wxAUI_BUTTON_STATE_HOVER
||
450 dc
.SetPen(wxPen(m_highlight_colour
));
451 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
452 dc
.DrawRectangle(button_rect
);
453 dc
.DrawRectangle(dropdown_rect
);
458 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
460 bmp
= item
.disabled_bitmap
;
461 dropbmp
= m_disabled_button_dropdown_bmp
;
466 dropbmp
= m_button_dropdown_bmp
;
472 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
473 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
475 // set the item's text color based on if it is disabled
476 dc
.SetTextForeground(*wxBLACK
);
477 if (item
.state
& wxAUI_BUTTON_STATE_DISABLED
)
478 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
480 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
482 dc
.DrawText(item
.label
, text_x
, text_y
);
486 void wxAuiDefaultToolBarArt
::DrawControlLabel(
488 wxWindow
* WXUNUSED(wnd
),
489 const wxAuiToolBarItem
& item
,
492 if (!(m_flags
& wxAUI_TB_TEXT
))
495 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
498 int text_x
= 0, text_y
= 0;
499 int text_width
= 0, text_height
= 0;
504 if (m_flags
& wxAUI_TB_TEXT
)
506 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
510 dc
.GetTextExtent(item
.label
, &text_width
, &ty
);
512 // don't draw the label if it is wider than the item width
513 if (text_width
> rect
.width
)
516 // set the label's text color
517 dc
.SetTextForeground(*wxBLACK
);
519 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
520 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
522 if ((m_flags
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
524 dc
.DrawText(item
.label
, text_x
, text_y
);
528 wxSize wxAuiDefaultToolBarArt
::GetLabelSize(
530 wxWindow
* WXUNUSED(wnd
),
531 const wxAuiToolBarItem
& item
)
535 // get label's height
536 int width
= 0, height
= 0;
537 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
540 width
= item
.min_size
.GetWidth();
542 return wxSize(width
, height
);
545 wxSize wxAuiDefaultToolBarArt
::GetToolSize(
547 wxWindow
* WXUNUSED(wnd
),
548 const wxAuiToolBarItem
& item
)
550 if (!item
.bitmap
.IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
551 return wxSize(16,16);
553 int width
= item
.bitmap
.GetWidth();
554 int height
= item
.bitmap
.GetHeight();
556 if (m_flags
& wxAUI_TB_TEXT
)
561 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
563 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
566 if (item
.label
.Length() > 0)
568 dc
.GetTextExtent(item
.label
, &tx
, &ty
);
569 width
= wxMax(width
, tx
+6);
572 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&& item
.label
.Length() > 0)
574 width
+= 3; // space between left border and bitmap
575 width
+= 3; // space between bitmap and text
577 if (item
.label
.Length() > 0)
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
;
742 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
);
744 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.id
, text
, item
.short_help
, false);
747 m
->SetBitmap(item
.bitmap
);
751 else if (item
.kind
== wxITEM_SEPARATOR
)
754 menuPopup
.AppendSeparator();
758 // find out where to put the popup menu of window items
759 wxPoint pt
= ::wxGetMousePosition();
760 pt
= wnd
->ScreenToClient(pt
);
762 // find out the screen coordinate at the bottom of the tab ctrl
763 wxRect cli_rect
= wnd
->GetClientRect();
764 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
766 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
767 wnd
->PushEventHandler(cc
);
768 wnd
->PopupMenu(&menuPopup
, pt
);
769 int command
= cc
->GetCommandId();
770 wnd
->PopEventHandler(true);
778 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
779 EVT_SIZE(wxAuiToolBar
::OnSize
)
780 EVT_IDLE(wxAuiToolBar
::OnIdle
)
781 EVT_ERASE_BACKGROUND(wxAuiToolBar
::OnEraseBackground
)
782 EVT_PAINT(wxAuiToolBar
::OnPaint
)
783 EVT_LEFT_DOWN(wxAuiToolBar
::OnLeftDown
)
784 EVT_LEFT_DCLICK(wxAuiToolBar
::OnLeftDown
)
785 EVT_LEFT_UP(wxAuiToolBar
::OnLeftUp
)
786 EVT_RIGHT_DOWN(wxAuiToolBar
::OnRightDown
)
787 EVT_RIGHT_DCLICK(wxAuiToolBar
::OnRightDown
)
788 EVT_RIGHT_UP(wxAuiToolBar
::OnRightUp
)
789 EVT_MIDDLE_DOWN(wxAuiToolBar
::OnMiddleDown
)
790 EVT_MIDDLE_DCLICK(wxAuiToolBar
::OnMiddleDown
)
791 EVT_MIDDLE_UP(wxAuiToolBar
::OnMiddleUp
)
792 EVT_MOTION(wxAuiToolBar
::OnMotion
)
793 EVT_LEAVE_WINDOW(wxAuiToolBar
::OnLeaveWindow
)
794 EVT_SET_CURSOR(wxAuiToolBar
::OnSetCursor
)
798 wxAuiToolBar
::wxAuiToolBar(wxWindow
* parent
,
800 const wxPoint
& position
,
807 style
| wxBORDER_NONE
)
809 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
811 m_button_height
= -1;
812 m_sizer_element_count
= 0;
813 m_action_pos
= wxPoint(-1,-1);
814 m_action_item
= NULL
;
816 m_art
= new wxAuiDefaultToolBarArt
;
818 m_tool_border_padding
= 3;
819 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
820 m_gripper_sizer_item
= NULL
;
821 m_overflow_sizer_item
= NULL
;
824 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ?
true : false;
825 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ?
true : false;
826 m_overflow_state
= 0;
827 SetMargins(5, 5, 2, 2);
828 SetFont(*wxNORMAL_FONT
);
829 m_art
->SetFlags((unsigned int)m_style
);
830 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
831 if (style
& wxAUI_TB_HORZ_TEXT
)
832 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
836 wxAuiToolBar
::~wxAuiToolBar()
842 void wxAuiToolBar
::SetWindowStyleFlag(long style
)
844 wxControl
::SetWindowStyleFlag(style
);
850 m_art
->SetFlags((unsigned int)m_style
);
853 if (m_style
& wxAUI_TB_GRIPPER
)
854 m_gripper_visible
= true;
856 m_gripper_visible
= false;
859 if (m_style
& wxAUI_TB_OVERFLOW
)
860 m_overflow_visible
= true;
862 m_overflow_visible
= false;
864 if (style
& wxAUI_TB_HORZ_TEXT
)
865 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
867 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
871 void wxAuiToolBar
::SetArtProvider(wxAuiToolBarArt
* art
)
879 m_art
->SetFlags((unsigned int)m_style
);
880 m_art
->SetTextOrientation(m_tool_text_orientation
);
884 wxAuiToolBarArt
* wxAuiToolBar
::GetArtProvider() const
892 void wxAuiToolBar
::AddTool(int tool_id
,
893 const wxString
& label
,
894 const wxBitmap
& bitmap
,
895 const wxString
& short_help_string
,
909 void wxAuiToolBar
::AddTool(int tool_id
,
910 const wxString
& label
,
911 const wxBitmap
& bitmap
,
912 const wxBitmap
& disabled_bitmap
,
914 const wxString
& WXUNUSED(short_help_string
),
915 const wxString
& WXUNUSED(long_help_string
),
916 wxObject
* WXUNUSED(client_data
))
918 wxAuiToolBarItem item
;
921 item
.bitmap
= bitmap
;
922 item
.disabled_bitmap
= disabled_bitmap
;
924 item
.dropdown
= false;
925 item
.space_pixels
= 0;
930 item
.sizer_item
= NULL
;
931 item
.min_size
= wxDefaultSize
;
935 if (!item
.disabled_bitmap
.IsOk())
937 // no disabled bitmap specified, we need to make one
938 if (item
.bitmap
.IsOk())
940 //wxImage img = item.bitmap.ConvertToImage();
941 //wxImage grey_version = img.ConvertToGreyscale();
942 //item.disabled_bitmap = wxBitmap(grey_version);
943 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
950 void wxAuiToolBar
::AddControl(wxControl
* control
,
951 const wxString
& label
)
953 wxAuiToolBarItem item
;
954 item
.window
= (wxWindow
*)control
;
956 item
.bitmap
= wxNullBitmap
;
957 item
.disabled_bitmap
= wxNullBitmap
;
959 item
.dropdown
= false;
960 item
.space_pixels
= 0;
961 item
.id
= control
->GetId();
964 item
.kind
= wxITEM_CONTROL
;
965 item
.sizer_item
= NULL
;
966 item
.min_size
= control
->GetEffectiveMinSize();
973 void wxAuiToolBar
::AddLabel(int tool_id
,
974 const wxString
& label
,
977 wxSize min_size
= wxDefaultSize
;
981 wxAuiToolBarItem item
;
984 item
.bitmap
= wxNullBitmap
;
985 item
.disabled_bitmap
= wxNullBitmap
;
987 item
.dropdown
= false;
988 item
.space_pixels
= 0;
992 item
.kind
= wxITEM_LABEL
;
993 item
.sizer_item
= NULL
;
994 item
.min_size
= min_size
;
1001 void wxAuiToolBar
::AddSeparator()
1003 wxAuiToolBarItem item
;
1005 item
.label
= wxEmptyString
;
1006 item
.bitmap
= wxNullBitmap
;
1007 item
.disabled_bitmap
= wxNullBitmap
;
1009 item
.dropdown
= false;
1012 item
.proportion
= 0;
1013 item
.kind
= wxITEM_SEPARATOR
;
1014 item
.sizer_item
= NULL
;
1015 item
.min_size
= wxDefaultSize
;
1017 item
.sticky
= false;
1022 void wxAuiToolBar
::AddSpacer(int pixels
)
1024 wxAuiToolBarItem item
;
1026 item
.label
= wxEmptyString
;
1027 item
.bitmap
= wxNullBitmap
;
1028 item
.disabled_bitmap
= wxNullBitmap
;
1030 item
.dropdown
= false;
1031 item
.space_pixels
= pixels
;
1034 item
.proportion
= 0;
1035 item
.kind
= wxITEM_SPACER
;
1036 item
.sizer_item
= NULL
;
1037 item
.min_size
= wxDefaultSize
;
1039 item
.sticky
= false;
1044 void wxAuiToolBar
::AddStretchSpacer(int proportion
)
1046 wxAuiToolBarItem item
;
1048 item
.label
= wxEmptyString
;
1049 item
.bitmap
= wxNullBitmap
;
1050 item
.disabled_bitmap
= wxNullBitmap
;
1052 item
.dropdown
= false;
1053 item
.space_pixels
= 0;
1056 item
.proportion
= proportion
;
1057 item
.kind
= wxITEM_SPACER
;
1058 item
.sizer_item
= NULL
;
1059 item
.min_size
= wxDefaultSize
;
1061 item
.sticky
= false;
1066 void wxAuiToolBar
::Clear()
1069 m_sizer_element_count
= 0;
1072 bool wxAuiToolBar
::DeleteTool(int tool_id
)
1074 int idx
= GetToolIndex(tool_id
);
1075 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1077 m_items
.RemoveAt(idx
);
1085 bool wxAuiToolBar
::DeleteByIndex(int idx
)
1087 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1089 m_items
.RemoveAt(idx
);
1098 wxControl
* wxAuiToolBar
::FindControl(int id
)
1100 wxWindow
* wnd
= FindWindow(id
);
1101 return (wxControl
*)wnd
;
1104 wxAuiToolBarItem
* wxAuiToolBar
::FindTool(int tool_id
) const
1107 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1109 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1110 if (item
.id
== tool_id
)
1117 wxAuiToolBarItem
* wxAuiToolBar
::FindToolByPosition(wxCoord x
, wxCoord y
) const
1120 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1122 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1124 if (!item
.sizer_item
)
1127 wxRect rect
= item
.sizer_item
->GetRect();
1128 if (rect
.Contains(x
,y
))
1130 // if the item doesn't fit on the toolbar, return NULL
1131 if (!GetToolFitsByIndex(i
))
1141 wxAuiToolBarItem
* wxAuiToolBar
::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1144 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1146 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1148 if (!item
.sizer_item
)
1151 wxRect rect
= item
.sizer_item
->GetRect();
1153 // apply tool packing
1155 rect
.width
+= m_tool_packing
;
1157 if (rect
.Contains(x
,y
))
1159 // if the item doesn't fit on the toolbar, return NULL
1160 if (!GetToolFitsByIndex(i
))
1170 wxAuiToolBarItem
* wxAuiToolBar
::FindToolByIndex(int idx
) const
1175 if (idx
>= (int)m_items
.size())
1178 return &(m_items
[idx
]);
1181 void wxAuiToolBar
::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1183 // TODO: wxToolBar compatibility
1186 wxSize wxAuiToolBar
::GetToolBitmapSize() const
1188 // TODO: wxToolBar compatibility
1189 return wxSize(16,15);
1192 void wxAuiToolBar
::SetToolProportion(int tool_id
, int proportion
)
1194 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1198 item
->proportion
= proportion
;
1201 int wxAuiToolBar
::GetToolProportion(int tool_id
) const
1203 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1207 return item
->proportion
;
1210 void wxAuiToolBar
::SetToolSeparation(int separation
)
1213 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1216 int wxAuiToolBar
::GetToolSeparation() const
1219 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1225 void wxAuiToolBar
::SetToolDropDown(int tool_id
, bool dropdown
)
1227 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1231 item
->dropdown
= dropdown
;
1234 bool wxAuiToolBar
::GetToolDropDown(int tool_id
) const
1236 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1240 return item
->dropdown
;
1243 void wxAuiToolBar
::SetToolSticky(int tool_id
, bool sticky
)
1245 // ignore separators
1249 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1253 if (item
->sticky
== sticky
)
1256 item
->sticky
= sticky
;
1262 bool wxAuiToolBar
::GetToolSticky(int tool_id
) const
1264 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1268 return item
->sticky
;
1274 void wxAuiToolBar
::SetToolBorderPadding(int padding
)
1276 m_tool_border_padding
= padding
;
1279 int wxAuiToolBar
::GetToolBorderPadding() const
1281 return m_tool_border_padding
;
1284 void wxAuiToolBar
::SetToolTextOrientation(int orientation
)
1286 m_tool_text_orientation
= orientation
;
1290 m_art
->SetTextOrientation(orientation
);
1294 int wxAuiToolBar
::GetToolTextOrientation() const
1296 return m_tool_text_orientation
;
1299 void wxAuiToolBar
::SetToolPacking(int packing
)
1301 m_tool_packing
= packing
;
1304 int wxAuiToolBar
::GetToolPacking() const
1306 return m_tool_packing
;
1310 void wxAuiToolBar
::SetOrientation(int WXUNUSED(orientation
))
1314 void wxAuiToolBar
::SetMargins(int left
, int right
, int top
, int bottom
)
1317 m_left_padding
= left
;
1319 m_right_padding
= right
;
1321 m_top_padding
= top
;
1323 m_bottom_padding
= bottom
;
1326 bool wxAuiToolBar
::GetGripperVisible() const
1328 return m_gripper_visible
;
1331 void wxAuiToolBar
::SetGripperVisible(bool visible
)
1333 m_gripper_visible
= visible
;
1335 m_style
|= wxAUI_TB_GRIPPER
;
1341 bool wxAuiToolBar
::GetOverflowVisible() const
1343 return m_overflow_visible
;
1346 void wxAuiToolBar
::SetOverflowVisible(bool visible
)
1348 m_overflow_visible
= visible
;
1350 m_style
|= wxAUI_TB_OVERFLOW
;
1354 bool wxAuiToolBar
::SetFont(const wxFont
& font
)
1356 bool res
= wxWindow
::SetFont(font
);
1360 m_art
->SetFont(font
);
1367 void wxAuiToolBar
::SetHoverItem(wxAuiToolBarItem
* pitem
)
1369 wxAuiToolBarItem
* former_hover
= NULL
;
1372 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1374 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1375 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1376 former_hover
= &item
;
1377 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1382 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1385 if (former_hover
!= pitem
)
1392 void wxAuiToolBar
::SetPressedItem(wxAuiToolBarItem
* pitem
)
1394 wxAuiToolBarItem
* former_item
= NULL
;
1397 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1399 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1400 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1401 former_item
= &item
;
1402 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1407 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1408 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1411 if (former_item
!= pitem
)
1418 void wxAuiToolBar
::RefreshOverflowState()
1420 if (!m_overflow_sizer_item
)
1422 m_overflow_state
= 0;
1426 int overflow_state
= 0;
1428 wxRect overflow_rect
= GetOverflowRect();
1431 // find out the mouse's current position
1432 wxPoint pt
= ::wxGetMousePosition();
1433 pt
= this->ScreenToClient(pt
);
1435 // find out if the mouse cursor is inside the dropdown rectangle
1436 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1438 if (::wxGetMouseState().LeftDown())
1439 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1441 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1444 if (overflow_state
!= m_overflow_state
)
1446 m_overflow_state
= overflow_state
;
1451 m_overflow_state
= overflow_state
;
1454 void wxAuiToolBar
::ToggleTool(int tool_id
, bool state
)
1456 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1460 if (tool
->kind
!= wxITEM_CHECK
)
1464 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1466 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1470 bool wxAuiToolBar
::GetToolToggled(int tool_id
) const
1472 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1476 if (tool
->kind
!= wxITEM_CHECK
)
1479 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ?
true : false;
1485 void wxAuiToolBar
::EnableTool(int tool_id
, bool state
)
1487 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1492 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1494 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1498 bool wxAuiToolBar
::GetToolEnabled(int tool_id
) const
1500 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1503 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ?
false : true;
1508 wxString wxAuiToolBar
::GetToolLabel(int tool_id
) const
1510 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1511 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1513 return wxEmptyString
;
1518 void wxAuiToolBar
::SetToolLabel(int tool_id
, const wxString
& label
)
1520 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1523 tool
->label
= label
;
1527 wxBitmap wxAuiToolBar
::GetToolBitmap(int tool_id
) const
1529 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1530 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1532 return wxNullBitmap
;
1534 return tool
->bitmap
;
1537 void wxAuiToolBar
::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1539 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1542 tool
->bitmap
= bitmap
;
1546 wxString wxAuiToolBar
::GetToolShortHelp(int tool_id
) const
1548 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1549 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1551 return wxEmptyString
;
1553 return tool
->short_help
;
1556 void wxAuiToolBar
::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1558 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1561 tool
->short_help
= help_string
;
1565 wxString wxAuiToolBar
::GetToolLongHelp(int tool_id
) const
1567 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1568 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1570 return wxEmptyString
;
1572 return tool
->long_help
;
1575 void wxAuiToolBar
::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1577 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1580 tool
->long_help
= help_string
;
1584 void wxAuiToolBar
::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1585 const wxAuiToolBarItemArray
& append
)
1587 m_custom_overflow_prepend
= prepend
;
1588 m_custom_overflow_append
= append
;
1592 size_t wxAuiToolBar
::GetToolCount() const
1594 return m_items
.size();
1597 int wxAuiToolBar
::GetToolIndex(int tool_id
) const
1599 // this will prevent us from returning the index of the
1600 // first separator in the toolbar since its id is equal to -1
1604 size_t i
, count
= m_items
.GetCount();
1605 for (i
= 0; i
< count
; ++i
)
1607 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1608 if (item
.id
== tool_id
)
1615 bool wxAuiToolBar
::GetToolFitsByIndex(int tool_idx
) const
1617 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1620 if (!m_items
[tool_idx
].sizer_item
)
1624 GetClientSize(&cli_w
, &cli_h
);
1626 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1628 if (m_style
& wxAUI_TB_VERTICAL
)
1630 // take the dropdown size into account
1631 if (m_overflow_visible
)
1632 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1634 if (rect
.y
+rect
.height
< cli_h
)
1639 // take the dropdown size into account
1640 if (m_overflow_visible
)
1641 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1643 if (rect
.x
+rect
.width
< cli_w
)
1651 bool wxAuiToolBar
::GetToolFits(int tool_id
) const
1653 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1656 wxRect wxAuiToolBar
::GetToolRect(int tool_id
) const
1658 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1659 if (tool
&& tool
->sizer_item
)
1661 return tool
->sizer_item
->GetRect();
1667 bool wxAuiToolBar
::GetToolBarFits() const
1669 if (m_items
.GetCount() == 0)
1671 // empty toolbar always 'fits'
1675 // entire toolbar content fits if the last tool fits
1676 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1679 bool wxAuiToolBar
::Realize()
1681 wxClientDC
dc(this);
1685 bool horizontal
= true;
1686 if (m_style
& wxAUI_TB_VERTICAL
)
1690 // create the new sizer to add toolbar elements to
1691 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal ? wxHORIZONTAL
: wxVERTICAL
);
1694 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1695 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1696 if (gripper_size
> 0 && m_gripper_visible
)
1699 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1701 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1705 m_gripper_sizer_item
= NULL
;
1708 // add "left" padding
1709 if (m_left_padding
> 0)
1712 sizer
->Add(m_left_padding
, 1);
1714 sizer
->Add(1, m_left_padding
);
1718 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1720 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1721 wxSizerItem
* sizer_item
= NULL
;
1727 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1728 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1729 size
.y
+ (m_tool_border_padding
*2),
1734 sizer
->AddSpacer(m_tool_packing
);
1743 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1744 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1745 size
.y
+ (m_tool_border_padding
*2),
1751 sizer
->AddSpacer(m_tool_packing
);
1757 case wxITEM_SEPARATOR
:
1760 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1762 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1767 sizer
->AddSpacer(m_tool_packing
);
1774 if (item
.proportion
> 0)
1775 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1777 sizer_item
= sizer
->Add(item
.space_pixels
, 1);
1780 case wxITEM_CONTROL
:
1782 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1783 wxSizerItem
* ctrl_sizer_item
;
1785 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1786 vert_sizer
->AddStretchSpacer(1);
1787 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1788 vert_sizer
->AddStretchSpacer(1);
1789 if ((m_style
& wxAUI_TB_TEXT
) && item
.label
.Length() > 0)
1791 wxSize s
= GetLabelSize(item
.label
);
1792 vert_sizer
->Add(1, s
.y
);
1796 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1798 wxSize min_size
= item
.min_size
;
1801 // proportional items will disappear from the toolbar if
1802 // their min width is not set to something really small
1803 if (item
.proportion
!= 0)
1808 if (min_size
.IsFullySpecified())
1810 sizer_item
->SetMinSize(min_size
);
1811 ctrl_sizer_item
->SetMinSize(min_size
);
1817 sizer
->AddSpacer(m_tool_packing
);
1822 item
.sizer_item
= sizer_item
;
1825 // add "right" padding
1826 if (m_right_padding
> 0)
1829 sizer
->Add(m_right_padding
, 1);
1831 sizer
->Add(1, m_right_padding
);
1834 // add drop down area
1835 m_overflow_sizer_item
= NULL
;
1837 if (m_style
& wxAUI_TB_OVERFLOW
)
1839 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1840 if (overflow_size
> 0 && m_overflow_visible
)
1843 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
1845 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
1849 m_overflow_sizer_item
= NULL
;
1854 // the outside sizer helps us apply the "top" and "bottom" padding
1855 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal ? wxVERTICAL
: wxHORIZONTAL
);
1857 // add "top" padding
1858 if (m_top_padding
> 0)
1861 outside_sizer
->Add(1, m_top_padding
);
1863 outside_sizer
->Add(m_top_padding
, 1);
1866 // add the sizer that contains all of the toolbar elements
1867 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
1869 // add "bottom" padding
1870 if (m_bottom_padding
> 0)
1873 outside_sizer
->Add(1, m_bottom_padding
);
1875 outside_sizer
->Add(m_bottom_padding
, 1);
1878 delete m_sizer
; // remove old sizer
1879 m_sizer
= outside_sizer
;
1881 // calculate the rock-bottom minimum size
1882 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1884 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1885 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1886 item
.sizer_item
->SetMinSize(0,0);
1889 m_absolute_min_size
= m_sizer
->GetMinSize();
1891 // reset the min sizes to what they were
1892 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1894 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1895 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1896 item
.sizer_item
->SetMinSize(item
.min_size
);
1900 wxSize size
= m_sizer
->GetMinSize();
1901 m_minWidth
= size
.x
;
1902 m_minHeight
= size
.y
;
1904 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
1906 wxSize cur_size
= GetClientSize();
1907 wxSize new_size
= GetMinSize();
1908 if (new_size
!= cur_size
)
1910 SetClientSize(new_size
);
1914 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1919 wxSize cur_size
= GetClientSize();
1920 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1927 int wxAuiToolBar
::GetOverflowState() const
1929 return m_overflow_state
;
1932 wxRect wxAuiToolBar
::GetOverflowRect() const
1934 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
1935 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
1936 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1938 if (m_style
& wxAUI_TB_VERTICAL
)
1940 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
1941 overflow_rect
.x
= 0;
1942 overflow_rect
.width
= cli_rect
.width
;
1943 overflow_rect
.height
= overflow_size
;
1947 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
1948 overflow_rect
.y
= 0;
1949 overflow_rect
.width
= overflow_size
;
1950 overflow_rect
.height
= cli_rect
.height
;
1953 return overflow_rect
;
1956 wxSize wxAuiToolBar
::GetLabelSize(const wxString
& label
)
1958 wxClientDC
dc(this);
1961 int text_width
= 0, text_height
= 0;
1965 // get the text height
1966 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
1968 // get the text width
1969 dc
.GetTextExtent(label
, &text_width
, &ty
);
1971 return wxSize(text_width
, text_height
);
1975 void wxAuiToolBar
::DoIdleUpdate()
1977 wxEvtHandler
* handler
= GetEventHandler();
1979 bool need_refresh
= false;
1982 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1984 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1989 wxUpdateUIEvent
evt(item
.id
);
1990 evt
.SetEventObject(this);
1992 if (handler
->ProcessEvent(evt
))
1994 if (evt
.GetSetEnabled())
1998 is_enabled
= item
.window
->IsEnabled();
2000 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ?
false : true;
2002 bool new_enabled
= evt
.GetEnabled();
2003 if (new_enabled
!= is_enabled
)
2007 item
.window
->Enable(new_enabled
);
2012 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2014 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2016 need_refresh
= true;
2020 if (evt
.GetSetChecked())
2022 // make sure we aren't checking an item that can't be
2023 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2026 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ?
true : false;
2027 bool new_checked
= evt
.GetChecked();
2029 if (new_checked
!= is_checked
)
2032 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2034 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2036 need_refresh
= true;
2051 void wxAuiToolBar
::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2054 GetClientSize(&x
, &y
);
2057 SetOrientation(wxHORIZONTAL
);
2059 SetOrientation(wxVERTICAL
);
2061 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2062 ((y
> x
) && m_absolute_min_size
.y
> y
))
2064 // hide all flexible items
2066 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2068 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2069 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2071 item
.sizer_item
->Show(false);
2072 item
.sizer_item
->SetProportion(0);
2078 // show all flexible items
2080 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2082 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2083 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2085 item
.sizer_item
->Show(true);
2086 item
.sizer_item
->SetProportion(item
.proportion
);
2091 m_sizer
->SetDimension(0, 0, x
, y
);
2099 void wxAuiToolBar
::DoSetSize(int x
,
2105 wxSize parent_size
= GetParent()->GetClientSize();
2106 if (x
+ width
> parent_size
.x
)
2107 width
= wxMax(0, parent_size
.x
- x
);
2108 if (y
+ height
> parent_size
.y
)
2109 height
= wxMax(0, parent_size
.y
- y
);
2111 wxWindow
::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2115 void wxAuiToolBar
::OnIdle(wxIdleEvent
& evt
)
2121 void wxAuiToolBar
::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2123 wxBufferedPaintDC
dc(this);
2124 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2127 bool horizontal
= true;
2128 if (m_style
& wxAUI_TB_VERTICAL
)
2132 m_art
->DrawBackground(dc
, this, cli_rect
);
2134 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2135 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2137 // paint the gripper
2138 if (gripper_size
> 0 && m_gripper_sizer_item
)
2140 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2142 gripper_rect
.width
= gripper_size
;
2144 gripper_rect
.height
= gripper_size
;
2145 m_art
->DrawGripper(dc
, this, gripper_rect
);
2148 // calculated how far we can draw items
2151 last_extent
= cli_rect
.width
;
2153 last_extent
= cli_rect
.height
;
2154 if (m_overflow_visible
)
2155 last_extent
-= dropdown_size
;
2157 // paint each individual tool
2158 size_t i
, count
= m_items
.GetCount();
2159 for (i
= 0; i
< count
; ++i
)
2161 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2163 if (!item
.sizer_item
)
2166 wxRect item_rect
= item
.sizer_item
->GetRect();
2169 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2170 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2175 if (item
.kind
== wxITEM_SEPARATOR
)
2178 m_art
->DrawSeparator(dc
, this, item_rect
);
2180 else if (item
.kind
== wxITEM_LABEL
)
2182 // draw a text label only
2183 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2185 else if (item
.kind
== wxITEM_NORMAL
)
2187 // draw a regular button or dropdown button
2189 m_art
->DrawButton(dc
, this, item
, item_rect
);
2191 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2193 else if (item
.kind
== wxITEM_CHECK
)
2195 // draw a toggle button
2196 m_art
->DrawButton(dc
, this, item
, item_rect
);
2198 else if (item
.kind
== wxITEM_CONTROL
)
2200 // draw the control's label
2201 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2204 // fire a signal to see if the item wants to be custom-rendered
2205 OnCustomRender(dc
, item
, item_rect
);
2208 // paint the overflow button
2209 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2211 wxRect dropdown_rect
= GetOverflowRect();
2212 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2216 void wxAuiToolBar
::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2221 void wxAuiToolBar
::OnLeftDown(wxMouseEvent
& evt
)
2223 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2225 if (m_gripper_sizer_item
)
2227 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2228 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2231 wxAuiManager
* manager
= wxAuiManager
::GetManager(this);
2235 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2236 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2238 // gripper was clicked
2239 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2244 if (m_overflow_sizer_item
)
2246 wxRect overflow_rect
= GetOverflowRect();
2249 m_overflow_visible
&&
2250 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2252 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2253 e
.SetEventObject(this);
2255 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2256 bool processed
= ProcessEvent(e
);
2265 wxAuiToolBarItemArray overflow_items
;
2268 // add custom overflow prepend items, if any
2269 count
= m_custom_overflow_prepend
.GetCount();
2270 for (i
= 0; i
< count
; ++i
)
2271 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2273 // only show items that don't fit in the dropdown
2274 count
= m_items
.GetCount();
2275 for (i
= 0; i
< count
; ++i
)
2277 if (!GetToolFitsByIndex(i
))
2278 overflow_items
.Add(m_items
[i
]);
2281 // add custom overflow append items, if any
2282 count
= m_custom_overflow_append
.GetCount();
2283 for (i
= 0; i
< count
; ++i
)
2284 overflow_items
.Add(m_custom_overflow_append
[i
]);
2286 int res
= m_art
->ShowDropDown(this, overflow_items
);
2287 m_overflow_state
= 0;
2291 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2292 e
.SetEventObject(this);
2293 GetParent()->ProcessEvent(e
);
2302 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2303 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2307 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2309 m_action_pos
= wxPoint(-1,-1);
2310 m_action_item
= NULL
;
2314 SetPressedItem(m_action_item
);
2316 // fire the tool dropdown event
2317 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2318 e
.SetEventObject(this);
2319 e
.SetToolId(m_action_item
->id
);
2320 e
.SetDropDownClicked(false);
2322 int mouse_x
= evt
.GetX();
2323 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2325 if (m_action_item
->dropdown
&&
2326 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2327 mouse_x
< (rect
.x
+rect
.width
))
2329 e
.SetDropDownClicked(true);
2332 e
.SetClickPoint(evt
.GetPosition());
2333 e
.SetItemRect(rect
);
2339 void wxAuiToolBar
::OnLeftUp(wxMouseEvent
& evt
)
2341 SetPressedItem(NULL
);
2343 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2344 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2346 SetHoverItem(hit_item
);
2352 // reset drag and drop member variables
2354 m_action_pos
= wxPoint(-1,-1);
2355 m_action_item
= NULL
;
2360 wxAuiToolBarItem
* hit_item
;
2361 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2363 if (m_action_item
&& hit_item
== m_action_item
)
2367 if (hit_item
->kind
== wxITEM_CHECK
)
2369 bool toggle
= false;
2371 if (m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
)
2376 ToggleTool(m_action_item
->id
, toggle
);
2378 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2379 e
.SetEventObject(this);
2385 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2386 e
.SetEventObject(this);
2393 // reset drag and drop member variables
2395 m_action_pos
= wxPoint(-1,-1);
2396 m_action_item
= NULL
;
2399 void wxAuiToolBar
::OnRightDown(wxMouseEvent
& evt
)
2401 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2403 if (m_gripper_sizer_item
)
2405 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2406 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2410 if (m_overflow_sizer_item
)
2412 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2413 if (dropdown_size
> 0 &&
2414 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2416 evt
.m_y
< cli_rect
.height
&&
2423 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2424 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2428 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2430 m_action_pos
= wxPoint(-1,-1);
2431 m_action_item
= NULL
;
2437 void wxAuiToolBar
::OnRightUp(wxMouseEvent
& evt
)
2439 wxAuiToolBarItem
* hit_item
;
2440 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2442 if (m_action_item
&& hit_item
== m_action_item
)
2444 if (hit_item
->kind
== wxITEM_NORMAL
)
2446 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2447 e
.SetEventObject(this);
2448 e
.SetToolId(m_action_item
->id
);
2449 e
.SetClickPoint(m_action_pos
);
2456 // right-clicked on the invalid area of the toolbar
2457 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2458 e
.SetEventObject(this);
2460 e
.SetClickPoint(m_action_pos
);
2465 // reset member variables
2466 m_action_pos
= wxPoint(-1,-1);
2467 m_action_item
= NULL
;
2470 void wxAuiToolBar
::OnMiddleDown(wxMouseEvent
& evt
)
2472 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2474 if (m_gripper_sizer_item
)
2476 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2477 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2481 if (m_overflow_sizer_item
)
2483 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2484 if (dropdown_size
> 0 &&
2485 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2487 evt
.m_y
< cli_rect
.height
&&
2494 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2495 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2499 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2501 m_action_pos
= wxPoint(-1,-1);
2502 m_action_item
= NULL
;
2508 void wxAuiToolBar
::OnMiddleUp(wxMouseEvent
& evt
)
2510 wxAuiToolBarItem
* hit_item
;
2511 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2513 if (m_action_item
&& hit_item
== m_action_item
)
2515 if (hit_item
->kind
== wxITEM_NORMAL
)
2517 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2518 e
.SetEventObject(this);
2519 e
.SetToolId(m_action_item
->id
);
2520 e
.SetClickPoint(m_action_pos
);
2526 // reset member variables
2527 m_action_pos
= wxPoint(-1,-1);
2528 m_action_item
= NULL
;
2531 void wxAuiToolBar
::OnMotion(wxMouseEvent
& evt
)
2533 // start a drag event
2535 m_action_item
!= NULL
&&
2536 m_action_pos
!= wxPoint(-1,-1) &&
2537 abs(evt
.m_x
- m_action_pos
.x
) + abs(evt
.m_y
- m_action_pos
.y
) > 5)
2543 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2544 e
.SetEventObject(this);
2545 e
.SetToolId(m_action_item
->id
);
2551 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2554 if (!(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2555 SetHoverItem(hit_item
);
2561 // no hit item, remove any hit item
2562 SetHoverItem(hit_item
);
2565 // figure out tooltips
2566 wxAuiToolBarItem
* packing_hit_item
;
2567 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2568 if (packing_hit_item
)
2570 if (packing_hit_item
!= m_tip_item
)
2572 m_tip_item
= packing_hit_item
;
2574 if (packing_hit_item
->short_help
.Length() > 0)
2575 SetToolTip(packing_hit_item
->short_help
);
2586 // if we've pressed down an item and we're hovering
2587 // over it, make sure it's state is set to pressed
2590 if (m_action_item
== hit_item
)
2591 SetPressedItem(m_action_item
);
2593 SetPressedItem(NULL
);
2596 // figure out the dropdown button state (are we hovering or pressing it?)
2597 RefreshOverflowState();
2600 void wxAuiToolBar
::OnLeaveWindow(wxMouseEvent
& WXUNUSED(evt
))
2602 RefreshOverflowState();
2604 SetPressedItem(NULL
);
2610 void wxAuiToolBar
::OnSetCursor(wxSetCursorEvent
& evt
)
2612 wxCursor cursor
= wxNullCursor
;
2614 if (m_gripper_sizer_item
)
2616 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2617 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2619 cursor
= wxCursor(wxCURSOR_SIZING
);
2623 evt
.SetCursor(cursor
);