1 ///////////////////////////////////////////////////////////////////////////////
3 // Name: src/aui/dockart.cpp
4 // Purpose: wxaui: wx advanced user interface - docking window manager
5 // Author: Benjamin I. Williams
9 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
10 // Licence: wxWindows Library Licence, Version 3.1
11 ///////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/wxprec.h"
29 #include "wx/statline.h"
30 #include "wx/dcbuffer.h"
33 #include "wx/settings.h"
36 #include "wx/aui/auibar.h"
37 #include "wx/aui/framemanager.h"
40 #include "wx/osx/private.h"
43 #include "wx/arrimpl.cpp"
44 WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray
)
47 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
48 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
49 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
50 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
51 wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent
);
54 IMPLEMENT_CLASS(wxAuiToolBar
, wxControl
)
55 IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent
, wxEvent
)
58 // missing wxITEM_* items
61 wxITEM_CONTROL
= wxITEM_MAX
,
66 const int BUTTON_DROPDOWN_WIDTH
= 10;
69 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
70 const wxColour
& color
);
72 unsigned char wxAuiBlendColour(unsigned char fg
, unsigned char bg
, double alpha
);
73 wxColor
wxAuiStepColour(const wxColor
& c
, int percent
);
75 static wxBitmap
MakeDisabledBitmap(wxBitmap
& bmp
)
77 wxImage image
= bmp
.ConvertToImage();
80 mr
= image
.GetMaskRed();
81 mg
= image
.GetMaskGreen();
82 mb
= image
.GetMaskBlue();
84 unsigned char* data
= image
.GetData();
85 int width
= image
.GetWidth();
86 int height
= image
.GetHeight();
87 bool has_mask
= image
.HasMask();
89 for (int y
= height
-1; y
>= 0; --y
)
91 for (int x
= width
-1; x
>= 0; --x
)
93 data
= image
.GetData() + (y
*(width
*3))+(x
*3);
94 unsigned char* r
= data
;
95 unsigned char* g
= data
+1;
96 unsigned char* b
= data
+2;
98 if (has_mask
&& *r
== mr
&& *g
== mg
&& *b
== mb
)
101 *r
= wxAuiBlendColour(*r
, 255, 0.4);
102 *g
= wxAuiBlendColour(*g
, 255, 0.4);
103 *b
= wxAuiBlendColour(*b
, 255, 0.4);
107 return wxBitmap(image
);
110 static wxColor
GetBaseColor()
113 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
114 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
116 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
119 // the base_colour is too pale to use as our base colour,
120 // so darken it a bit --
121 if ((255-base_colour
.Red()) +
122 (255-base_colour
.Green()) +
123 (255-base_colour
.Blue()) < 60)
125 base_colour
= wxAuiStepColour(base_colour
, 92);
133 class ToolbarCommandCapture
: public wxEvtHandler
137 ToolbarCommandCapture() { m_last_id
= 0; }
138 int GetCommandId() const { return m_last_id
; }
140 bool ProcessEvent(wxEvent
& evt
)
142 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
144 m_last_id
= evt
.GetId();
148 if (GetNextHandler())
149 return GetNextHandler()->ProcessEvent(evt
);
160 static const unsigned char
161 DISABLED_TEXT_GREY_HUE
= wxAuiBlendColour(0, 255, 0.4);
162 const wxColour
DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE
,
163 DISABLED_TEXT_GREY_HUE
,
164 DISABLED_TEXT_GREY_HUE
);
166 wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
168 m_base_colour
= GetBaseColor();
171 m_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
172 m_highlight_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
174 m_separator_size
= 7;
176 m_overflow_size
= 16;
178 wxColor darker1_colour
= wxAuiStepColour(m_base_colour
, 85);
179 wxColor darker2_colour
= wxAuiStepColour(m_base_colour
, 75);
180 wxColor darker3_colour
= wxAuiStepColour(m_base_colour
, 60);
181 wxColor darker4_colour
= wxAuiStepColour(m_base_colour
, 50);
182 wxColor darker5_colour
= wxAuiStepColour(m_base_colour
, 40);
184 m_gripper_pen1
= wxPen(darker5_colour
);
185 m_gripper_pen2
= wxPen(darker3_colour
);
186 m_gripper_pen3
= *wxWHITE_PEN
;
188 static 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 unsigned int wxAuiDefaultToolBarArt::GetFlags()
233 wxFont
wxAuiDefaultToolBarArt::GetFont()
238 int wxAuiDefaultToolBarArt::GetTextOrientation()
240 return m_text_orientation
;
243 void wxAuiDefaultToolBarArt::DrawBackground(
245 wxWindow
* WXUNUSED(wnd
),
250 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 150);
251 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 90);
252 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, wxSOUTH
);
255 void wxAuiDefaultToolBarArt::DrawLabel(
257 wxWindow
* WXUNUSED(wnd
),
258 const wxAuiToolBarItem
& item
,
262 dc
.SetTextForeground(*wxBLACK
);
264 // we only care about the text height here since the text
265 // will get cropped based on the width of the item
266 int text_width
= 0, text_height
= 0;
267 dc
.GetTextExtent(wxT("ABCDHgj"), &text_width
, &text_height
);
269 // set the clipping region
270 wxRect clip_rect
= rect
;
271 clip_rect
.width
-= 1;
272 dc
.SetClippingRegion(clip_rect
);
276 text_y
= rect
.y
+ (rect
.height
-text_height
)/2;
277 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
278 dc
.DestroyClippingRegion();
282 void wxAuiDefaultToolBarArt::DrawButton(
284 wxWindow
* WXUNUSED(wnd
),
285 const wxAuiToolBarItem
& item
,
288 int text_width
= 0, text_height
= 0;
290 if (m_flags
& wxAUI_TB_TEXT
)
296 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
298 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
301 int bmp_x
= 0, bmp_y
= 0;
302 int text_x
= 0, text_y
= 0;
304 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
308 (item
.GetBitmap().GetWidth()/2);
311 ((rect
.height
-text_height
)/2) -
312 (item
.GetBitmap().GetHeight()/2);
314 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
315 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
317 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
323 (item
.GetBitmap().GetHeight()/2);
325 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
332 if (!(item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
))
334 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
336 dc
.SetPen(wxPen(m_highlight_colour
));
337 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 150)));
338 dc
.DrawRectangle(rect
);
340 else if ((item
.GetState() & wxAUI_BUTTON_STATE_HOVER
) || item
.IsSticky())
342 dc
.SetPen(wxPen(m_highlight_colour
));
343 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
345 // draw an even lighter background for checked item hovers (since
346 // the hover background is the same color as the check background)
347 if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
348 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 180)));
350 dc
.DrawRectangle(rect
);
352 else if (item
.GetState() & wxAUI_BUTTON_STATE_CHECKED
)
354 // it's important to put this code in an else statment after the
355 // hover, otherwise hovers won't draw properly for checked items
356 dc
.SetPen(wxPen(m_highlight_colour
));
357 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
358 dc
.DrawRectangle(rect
);
363 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
364 bmp
= item
.GetDisabledBitmap();
366 bmp
= item
.GetBitmap();
371 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
373 // set the item's text color based on if it is disabled
374 dc
.SetTextForeground(*wxBLACK
);
375 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
376 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
378 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
380 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
385 void wxAuiDefaultToolBarArt::DrawDropDownButton(
387 wxWindow
* WXUNUSED(wnd
),
388 const wxAuiToolBarItem
& item
,
391 int text_width
= 0, text_height
= 0, text_x
= 0, text_y
= 0;
392 int bmp_x
= 0, bmp_y
= 0, dropbmp_x
= 0, dropbmp_y
= 0;
394 wxRect button_rect
= wxRect(rect
.x
,
396 rect
.width
-BUTTON_DROPDOWN_WIDTH
,
398 wxRect dropdown_rect
= wxRect(rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1,
400 BUTTON_DROPDOWN_WIDTH
+1,
403 if (m_flags
& wxAUI_TB_TEXT
)
408 if (m_flags
& wxAUI_TB_TEXT
)
410 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
414 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
419 dropbmp_x
= dropdown_rect
.x
+
420 (dropdown_rect
.width
/2) -
421 (m_button_dropdown_bmp
.GetWidth()/2);
422 dropbmp_y
= dropdown_rect
.y
+
423 (dropdown_rect
.height
/2) -
424 (m_button_dropdown_bmp
.GetHeight()/2);
427 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
429 bmp_x
= button_rect
.x
+
430 (button_rect
.width
/2) -
431 (item
.GetBitmap().GetWidth()/2);
432 bmp_y
= button_rect
.y
+
433 ((button_rect
.height
-text_height
)/2) -
434 (item
.GetBitmap().GetHeight()/2);
436 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
437 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
439 else if (m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
)
445 (item
.GetBitmap().GetHeight()/2);
447 text_x
= bmp_x
+ 3 + item
.GetBitmap().GetWidth();
454 if (item
.GetState() & wxAUI_BUTTON_STATE_PRESSED
)
456 dc
.SetPen(wxPen(m_highlight_colour
));
457 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 140)));
458 dc
.DrawRectangle(button_rect
);
459 dc
.DrawRectangle(dropdown_rect
);
461 else if (item
.GetState() & wxAUI_BUTTON_STATE_HOVER
||
464 dc
.SetPen(wxPen(m_highlight_colour
));
465 dc
.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour
, 170)));
466 dc
.DrawRectangle(button_rect
);
467 dc
.DrawRectangle(dropdown_rect
);
472 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
474 bmp
= item
.GetDisabledBitmap();
475 dropbmp
= m_disabled_button_dropdown_bmp
;
479 bmp
= item
.GetBitmap();
480 dropbmp
= m_button_dropdown_bmp
;
486 dc
.DrawBitmap(bmp
, bmp_x
, bmp_y
, true);
487 dc
.DrawBitmap(dropbmp
, dropbmp_x
, dropbmp_y
, true);
489 // set the item's text color based on if it is disabled
490 dc
.SetTextForeground(*wxBLACK
);
491 if (item
.GetState() & wxAUI_BUTTON_STATE_DISABLED
)
492 dc
.SetTextForeground(DISABLED_TEXT_COLOR
);
494 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
496 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
500 void wxAuiDefaultToolBarArt::DrawControlLabel(
502 wxWindow
* WXUNUSED(wnd
),
503 const wxAuiToolBarItem
& item
,
506 if (!(m_flags
& wxAUI_TB_TEXT
))
509 if (m_text_orientation
!= wxAUI_TBTOOL_TEXT_BOTTOM
)
512 int text_x
= 0, text_y
= 0;
513 int text_width
= 0, text_height
= 0;
518 if (m_flags
& wxAUI_TB_TEXT
)
520 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
524 dc
.GetTextExtent(item
.GetLabel(), &text_width
, &ty
);
526 // don't draw the label if it is wider than the item width
527 if (text_width
> rect
.width
)
530 // set the label's text color
531 dc
.SetTextForeground(*wxBLACK
);
533 text_x
= rect
.x
+ (rect
.width
/2) - (text_width
/2) + 1;
534 text_y
= rect
.y
+ rect
.height
- text_height
- 1;
536 if ( (m_flags
& wxAUI_TB_TEXT
) && !item
.GetLabel().empty() )
538 dc
.DrawText(item
.GetLabel(), text_x
, text_y
);
542 wxSize
wxAuiDefaultToolBarArt::GetLabelSize(
544 wxWindow
* WXUNUSED(wnd
),
545 const wxAuiToolBarItem
& item
)
549 // get label's height
550 int width
= 0, height
= 0;
551 dc
.GetTextExtent(wxT("ABCDHgj"), &width
, &height
);
554 width
= item
.GetMinSize().GetWidth();
558 // no width specified, measure the text ourselves
559 width
= dc
.GetTextExtent(item
.GetLabel()).GetX();
562 return wxSize(width
, height
);
565 wxSize
wxAuiDefaultToolBarArt::GetToolSize(
567 wxWindow
* WXUNUSED(wnd
),
568 const wxAuiToolBarItem
& item
)
570 if (!item
.GetBitmap().IsOk() && !(m_flags
& wxAUI_TB_TEXT
))
571 return wxSize(16,16);
573 int width
= item
.GetBitmap().GetWidth();
574 int height
= item
.GetBitmap().GetHeight();
576 if (m_flags
& wxAUI_TB_TEXT
)
581 if (m_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
)
583 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &ty
);
586 if ( !item
.GetLabel().empty() )
588 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
589 width
= wxMax(width
, tx
+6);
592 else if ( m_text_orientation
== wxAUI_TBTOOL_TEXT_RIGHT
&&
593 !item
.GetLabel().empty() )
595 width
+= 3; // space between left border and bitmap
596 width
+= 3; // space between bitmap and text
598 if ( !item
.GetLabel().empty() )
600 dc
.GetTextExtent(item
.GetLabel(), &tx
, &ty
);
602 height
= wxMax(height
, ty
);
607 // if the tool has a dropdown button, add it to the width
608 if (item
.HasDropDown())
609 width
+= (BUTTON_DROPDOWN_WIDTH
+4);
611 return wxSize(width
, height
);
614 void wxAuiDefaultToolBarArt::DrawSeparator(
616 wxWindow
* WXUNUSED(wnd
),
619 bool horizontal
= true;
620 if (m_flags
& wxAUI_TB_VERTICAL
)
627 rect
.x
+= (rect
.width
/2);
629 int new_height
= (rect
.height
*3)/4;
630 rect
.y
+= (rect
.height
/2) - (new_height
/2);
631 rect
.height
= new_height
;
635 rect
.y
+= (rect
.height
/2);
637 int new_width
= (rect
.width
*3)/4;
638 rect
.x
+= (rect
.width
/2) - (new_width
/2);
639 rect
.width
= new_width
;
642 wxColour start_colour
= wxAuiStepColour(m_base_colour
, 80);
643 wxColour end_colour
= wxAuiStepColour(m_base_colour
, 80);
644 dc
.GradientFillLinear(rect
, start_colour
, end_colour
, horizontal
? wxSOUTH
: wxEAST
);
647 void wxAuiDefaultToolBarArt::DrawGripper(wxDC
& dc
,
648 wxWindow
* WXUNUSED(wnd
),
656 if (m_flags
& wxAUI_TB_VERTICAL
)
658 x
= rect
.x
+ (i
*4) + 5;
660 if (x
> rect
.GetWidth()-5)
666 y
= rect
.y
+ (i
*4) + 5;
667 if (y
> rect
.GetHeight()-5)
671 dc
.SetPen(m_gripper_pen1
);
673 dc
.SetPen(m_gripper_pen2
);
674 dc
.DrawPoint(x
, y
+1);
675 dc
.DrawPoint(x
+1, y
);
676 dc
.SetPen(m_gripper_pen3
);
677 dc
.DrawPoint(x
+2, y
+1);
678 dc
.DrawPoint(x
+2, y
+2);
679 dc
.DrawPoint(x
+1, y
+2);
686 void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC
& dc
,
691 if (state
& wxAUI_BUTTON_STATE_HOVER
||
692 state
& wxAUI_BUTTON_STATE_PRESSED
)
694 wxRect cli_rect
= wnd
->GetClientRect();
695 wxColor light_gray_bg
= wxAuiStepColour(m_highlight_colour
, 170);
697 if (m_flags
& wxAUI_TB_VERTICAL
)
699 dc
.SetPen(wxPen(m_highlight_colour
));
700 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
);
701 dc
.SetPen(wxPen(light_gray_bg
));
702 dc
.SetBrush(wxBrush(light_gray_bg
));
703 dc
.DrawRectangle(rect
.x
, rect
.y
+1, rect
.width
, rect
.height
);
707 dc
.SetPen(wxPen(m_highlight_colour
));
708 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
709 dc
.SetPen(wxPen(light_gray_bg
));
710 dc
.SetBrush(wxBrush(light_gray_bg
));
711 dc
.DrawRectangle(rect
.x
+1, rect
.y
, rect
.width
, rect
.height
);
715 int x
= rect
.x
+1+(rect
.width
-m_overflow_bmp
.GetWidth())/2;
716 int y
= rect
.y
+1+(rect
.height
-m_overflow_bmp
.GetHeight())/2;
717 dc
.DrawBitmap(m_overflow_bmp
, x
, y
, true);
720 int wxAuiDefaultToolBarArt::GetElementSize(int element_id
)
724 case wxAUI_TBART_SEPARATOR_SIZE
: return m_separator_size
;
725 case wxAUI_TBART_GRIPPER_SIZE
: return m_gripper_size
;
726 case wxAUI_TBART_OVERFLOW_SIZE
: return m_overflow_size
;
731 void wxAuiDefaultToolBarArt::SetElementSize(int element_id
, int size
)
735 case wxAUI_TBART_SEPARATOR_SIZE
: m_separator_size
= size
; break;
736 case wxAUI_TBART_GRIPPER_SIZE
: m_gripper_size
= size
; break;
737 case wxAUI_TBART_OVERFLOW_SIZE
: m_overflow_size
= size
; break;
741 int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow
* wnd
,
742 const wxAuiToolBarItemArray
& items
)
746 size_t items_added
= 0;
748 size_t i
, count
= items
.GetCount();
749 for (i
= 0; i
< count
; ++i
)
751 wxAuiToolBarItem
& item
= items
.Item(i
);
753 if (item
.GetKind() == wxITEM_NORMAL
)
755 wxString text
= item
.GetShortHelp();
757 text
= item
.GetLabel();
762 wxMenuItem
* m
= new wxMenuItem(&menuPopup
, item
.GetId(), text
, item
.GetShortHelp());
764 m
->SetBitmap(item
.GetBitmap());
768 else if (item
.GetKind() == wxITEM_SEPARATOR
)
771 menuPopup
.AppendSeparator();
775 // find out where to put the popup menu of window items
776 wxPoint pt
= ::wxGetMousePosition();
777 pt
= wnd
->ScreenToClient(pt
);
779 // find out the screen coordinate at the bottom of the tab ctrl
780 wxRect cli_rect
= wnd
->GetClientRect();
781 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
783 ToolbarCommandCapture
* cc
= new ToolbarCommandCapture
;
784 wnd
->PushEventHandler(cc
);
785 wnd
->PopupMenu(&menuPopup
, pt
);
786 int command
= cc
->GetCommandId();
787 wnd
->PopEventHandler(true);
795 BEGIN_EVENT_TABLE(wxAuiToolBar
, wxControl
)
796 EVT_SIZE(wxAuiToolBar::OnSize
)
797 EVT_IDLE(wxAuiToolBar::OnIdle
)
798 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground
)
799 EVT_PAINT(wxAuiToolBar::OnPaint
)
800 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown
)
801 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown
)
802 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp
)
803 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown
)
804 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown
)
805 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp
)
806 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown
)
807 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown
)
808 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp
)
809 EVT_MOTION(wxAuiToolBar::OnMotion
)
810 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow
)
811 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor
)
815 wxAuiToolBar::wxAuiToolBar(wxWindow
* parent
,
817 const wxPoint
& position
,
824 style
| wxBORDER_NONE
)
826 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
828 m_button_height
= -1;
829 m_sizer_element_count
= 0;
830 m_action_pos
= wxPoint(-1,-1);
831 m_action_item
= NULL
;
833 m_art
= new wxAuiDefaultToolBarArt
;
835 m_tool_border_padding
= 3;
836 m_tool_text_orientation
= wxAUI_TBTOOL_TEXT_BOTTOM
;
837 m_gripper_sizer_item
= NULL
;
838 m_overflow_sizer_item
= NULL
;
840 m_style
= style
| wxBORDER_NONE
;
841 m_gripper_visible
= (m_style
& wxAUI_TB_GRIPPER
) ? true : false;
842 m_overflow_visible
= (m_style
& wxAUI_TB_OVERFLOW
) ? true : false;
843 m_overflow_state
= 0;
844 SetMargins(5, 5, 2, 2);
845 SetFont(*wxNORMAL_FONT
);
846 m_art
->SetFlags((unsigned int)m_style
);
847 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
848 if (style
& wxAUI_TB_HORZ_LAYOUT
)
849 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
850 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
854 wxAuiToolBar::~wxAuiToolBar()
860 void wxAuiToolBar::SetWindowStyleFlag(long style
)
862 wxControl::SetWindowStyleFlag(style
);
868 m_art
->SetFlags((unsigned int)m_style
);
871 if (m_style
& wxAUI_TB_GRIPPER
)
872 m_gripper_visible
= true;
874 m_gripper_visible
= false;
877 if (m_style
& wxAUI_TB_OVERFLOW
)
878 m_overflow_visible
= true;
880 m_overflow_visible
= false;
882 if (style
& wxAUI_TB_HORZ_LAYOUT
)
883 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT
);
885 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM
);
888 long wxAuiToolBar::GetWindowStyleFlag() const
893 void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt
* art
)
901 m_art
->SetFlags((unsigned int)m_style
);
902 m_art
->SetTextOrientation(m_tool_text_orientation
);
906 wxAuiToolBarArt
* wxAuiToolBar::GetArtProvider() const
914 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
915 const wxString
& label
,
916 const wxBitmap
& bitmap
,
917 const wxString
& short_help_string
,
920 return AddTool(tool_id
,
931 wxAuiToolBarItem
* wxAuiToolBar::AddTool(int tool_id
,
932 const wxString
& label
,
933 const wxBitmap
& bitmap
,
934 const wxBitmap
& disabled_bitmap
,
936 const wxString
& short_help_string
,
937 const wxString
& long_help_string
,
938 wxObject
* WXUNUSED(client_data
))
940 wxAuiToolBarItem item
;
943 item
.bitmap
= bitmap
;
944 item
.disabled_bitmap
= disabled_bitmap
;
945 item
.short_help
= short_help_string
;
946 item
.long_help
= long_help_string
;
948 item
.dropdown
= false;
949 item
.spacer_pixels
= 0;
954 item
.sizer_item
= NULL
;
955 item
.min_size
= wxDefaultSize
;
959 if (item
.id
== wxID_ANY
)
962 if (!item
.disabled_bitmap
.IsOk())
964 // no disabled bitmap specified, we need to make one
965 if (item
.bitmap
.IsOk())
967 //wxImage img = item.bitmap.ConvertToImage();
968 //wxImage grey_version = img.ConvertToGreyscale();
969 //item.disabled_bitmap = wxBitmap(grey_version);
970 item
.disabled_bitmap
= MakeDisabledBitmap(item
.bitmap
);
974 return &m_items
.Last();
977 wxAuiToolBarItem
* wxAuiToolBar::AddControl(wxControl
* control
,
978 const wxString
& label
)
980 wxAuiToolBarItem item
;
981 item
.window
= (wxWindow
*)control
;
983 item
.bitmap
= wxNullBitmap
;
984 item
.disabled_bitmap
= wxNullBitmap
;
986 item
.dropdown
= false;
987 item
.spacer_pixels
= 0;
988 item
.id
= control
->GetId();
991 item
.kind
= wxITEM_CONTROL
;
992 item
.sizer_item
= NULL
;
993 item
.min_size
= control
->GetEffectiveMinSize();
998 return &m_items
.Last();
1001 wxAuiToolBarItem
* wxAuiToolBar::AddLabel(int tool_id
,
1002 const wxString
& label
,
1005 wxSize min_size
= wxDefaultSize
;
1009 wxAuiToolBarItem item
;
1012 item
.bitmap
= wxNullBitmap
;
1013 item
.disabled_bitmap
= wxNullBitmap
;
1015 item
.dropdown
= false;
1016 item
.spacer_pixels
= 0;
1019 item
.proportion
= 0;
1020 item
.kind
= wxITEM_LABEL
;
1021 item
.sizer_item
= NULL
;
1022 item
.min_size
= min_size
;
1024 item
.sticky
= false;
1026 if (item
.id
== wxID_ANY
)
1027 item
.id
= wxNewId();
1030 return &m_items
.Last();
1033 wxAuiToolBarItem
* wxAuiToolBar::AddSeparator()
1035 wxAuiToolBarItem item
;
1037 item
.label
= wxEmptyString
;
1038 item
.bitmap
= wxNullBitmap
;
1039 item
.disabled_bitmap
= wxNullBitmap
;
1041 item
.dropdown
= false;
1044 item
.proportion
= 0;
1045 item
.kind
= wxITEM_SEPARATOR
;
1046 item
.sizer_item
= NULL
;
1047 item
.min_size
= wxDefaultSize
;
1049 item
.sticky
= false;
1052 return &m_items
.Last();
1055 wxAuiToolBarItem
* wxAuiToolBar::AddSpacer(int pixels
)
1057 wxAuiToolBarItem item
;
1059 item
.label
= wxEmptyString
;
1060 item
.bitmap
= wxNullBitmap
;
1061 item
.disabled_bitmap
= wxNullBitmap
;
1063 item
.dropdown
= false;
1064 item
.spacer_pixels
= pixels
;
1067 item
.proportion
= 0;
1068 item
.kind
= wxITEM_SPACER
;
1069 item
.sizer_item
= NULL
;
1070 item
.min_size
= wxDefaultSize
;
1072 item
.sticky
= false;
1075 return &m_items
.Last();
1078 wxAuiToolBarItem
* wxAuiToolBar::AddStretchSpacer(int proportion
)
1080 wxAuiToolBarItem item
;
1082 item
.label
= wxEmptyString
;
1083 item
.bitmap
= wxNullBitmap
;
1084 item
.disabled_bitmap
= wxNullBitmap
;
1086 item
.dropdown
= false;
1087 item
.spacer_pixels
= 0;
1090 item
.proportion
= proportion
;
1091 item
.kind
= wxITEM_SPACER
;
1092 item
.sizer_item
= NULL
;
1093 item
.min_size
= wxDefaultSize
;
1095 item
.sticky
= false;
1098 return &m_items
.Last();
1101 void wxAuiToolBar::Clear()
1104 m_sizer_element_count
= 0;
1107 bool wxAuiToolBar::DeleteTool(int tool_id
)
1109 int idx
= GetToolIndex(tool_id
);
1110 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1112 m_items
.RemoveAt(idx
);
1120 bool wxAuiToolBar::DeleteByIndex(int idx
)
1122 if (idx
>= 0 && idx
< (int)m_items
.GetCount())
1124 m_items
.RemoveAt(idx
);
1133 wxControl
* wxAuiToolBar::FindControl(int id
)
1135 wxWindow
* wnd
= FindWindow(id
);
1136 return (wxControl
*)wnd
;
1139 wxAuiToolBarItem
* wxAuiToolBar::FindTool(int tool_id
) const
1142 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1144 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1145 if (item
.id
== tool_id
)
1152 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPosition(wxCoord x
, wxCoord y
) const
1155 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1157 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1159 if (!item
.sizer_item
)
1162 wxRect rect
= item
.sizer_item
->GetRect();
1163 if (rect
.Contains(x
,y
))
1165 // if the item doesn't fit on the toolbar, return NULL
1166 if (!GetToolFitsByIndex(i
))
1176 wxAuiToolBarItem
* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const
1179 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1181 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1183 if (!item
.sizer_item
)
1186 wxRect rect
= item
.sizer_item
->GetRect();
1188 // apply tool packing
1190 rect
.width
+= m_tool_packing
;
1192 if (rect
.Contains(x
,y
))
1194 // if the item doesn't fit on the toolbar, return NULL
1195 if (!GetToolFitsByIndex(i
))
1205 wxAuiToolBarItem
* wxAuiToolBar::FindToolByIndex(int idx
) const
1210 if (idx
>= (int)m_items
.size())
1213 return &(m_items
[idx
]);
1216 void wxAuiToolBar::SetToolBitmapSize(const wxSize
& WXUNUSED(size
))
1218 // TODO: wxToolBar compatibility
1221 wxSize
wxAuiToolBar::GetToolBitmapSize() const
1223 // TODO: wxToolBar compatibility
1224 return wxSize(16,15);
1227 void wxAuiToolBar::SetToolProportion(int tool_id
, int proportion
)
1229 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1233 item
->proportion
= proportion
;
1236 int wxAuiToolBar::GetToolProportion(int tool_id
) const
1238 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1242 return item
->proportion
;
1245 void wxAuiToolBar::SetToolSeparation(int separation
)
1248 m_art
->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE
, separation
);
1251 int wxAuiToolBar::GetToolSeparation() const
1254 return m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1260 void wxAuiToolBar::SetToolDropDown(int tool_id
, bool dropdown
)
1262 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1266 item
->dropdown
= dropdown
;
1269 bool wxAuiToolBar::GetToolDropDown(int tool_id
) const
1271 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1275 return item
->dropdown
;
1278 void wxAuiToolBar::SetToolSticky(int tool_id
, bool sticky
)
1280 // ignore separators
1284 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1288 if (item
->sticky
== sticky
)
1291 item
->sticky
= sticky
;
1297 bool wxAuiToolBar::GetToolSticky(int tool_id
) const
1299 wxAuiToolBarItem
* item
= FindTool(tool_id
);
1303 return item
->sticky
;
1309 void wxAuiToolBar::SetToolBorderPadding(int padding
)
1311 m_tool_border_padding
= padding
;
1314 int wxAuiToolBar::GetToolBorderPadding() const
1316 return m_tool_border_padding
;
1319 void wxAuiToolBar::SetToolTextOrientation(int orientation
)
1321 m_tool_text_orientation
= orientation
;
1325 m_art
->SetTextOrientation(orientation
);
1329 int wxAuiToolBar::GetToolTextOrientation() const
1331 return m_tool_text_orientation
;
1334 void wxAuiToolBar::SetToolPacking(int packing
)
1336 m_tool_packing
= packing
;
1339 int wxAuiToolBar::GetToolPacking() const
1341 return m_tool_packing
;
1345 void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation
))
1349 void wxAuiToolBar::SetMargins(int left
, int right
, int top
, int bottom
)
1352 m_left_padding
= left
;
1354 m_right_padding
= right
;
1356 m_top_padding
= top
;
1358 m_bottom_padding
= bottom
;
1361 bool wxAuiToolBar::GetGripperVisible() const
1363 return m_gripper_visible
;
1366 void wxAuiToolBar::SetGripperVisible(bool visible
)
1368 m_gripper_visible
= visible
;
1370 m_style
|= wxAUI_TB_GRIPPER
;
1372 m_style
&= ~wxAUI_TB_GRIPPER
;
1378 bool wxAuiToolBar::GetOverflowVisible() const
1380 return m_overflow_visible
;
1383 void wxAuiToolBar::SetOverflowVisible(bool visible
)
1385 m_overflow_visible
= visible
;
1387 m_style
|= wxAUI_TB_OVERFLOW
;
1389 m_style
&= ~wxAUI_TB_OVERFLOW
;
1393 bool wxAuiToolBar::SetFont(const wxFont
& font
)
1395 bool res
= wxWindow::SetFont(font
);
1399 m_art
->SetFont(font
);
1406 void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem
* pitem
)
1408 wxAuiToolBarItem
* former_hover
= NULL
;
1411 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1413 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1414 if (item
.state
& wxAUI_BUTTON_STATE_HOVER
)
1415 former_hover
= &item
;
1416 item
.state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1421 pitem
->state
|= wxAUI_BUTTON_STATE_HOVER
;
1424 if (former_hover
!= pitem
)
1431 void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem
* pitem
)
1433 wxAuiToolBarItem
* former_item
= NULL
;
1436 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1438 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1439 if (item
.state
& wxAUI_BUTTON_STATE_PRESSED
)
1440 former_item
= &item
;
1441 item
.state
&= ~wxAUI_BUTTON_STATE_PRESSED
;
1446 pitem
->state
&= ~wxAUI_BUTTON_STATE_HOVER
;
1447 pitem
->state
|= wxAUI_BUTTON_STATE_PRESSED
;
1450 if (former_item
!= pitem
)
1457 void wxAuiToolBar::RefreshOverflowState()
1459 if (!m_overflow_sizer_item
)
1461 m_overflow_state
= 0;
1465 int overflow_state
= 0;
1467 wxRect overflow_rect
= GetOverflowRect();
1470 // find out the mouse's current position
1471 wxPoint pt
= ::wxGetMousePosition();
1472 pt
= this->ScreenToClient(pt
);
1474 // find out if the mouse cursor is inside the dropdown rectangle
1475 if (overflow_rect
.Contains(pt
.x
, pt
.y
))
1477 if (::wxGetMouseState().LeftIsDown())
1478 overflow_state
= wxAUI_BUTTON_STATE_PRESSED
;
1480 overflow_state
= wxAUI_BUTTON_STATE_HOVER
;
1483 if (overflow_state
!= m_overflow_state
)
1485 m_overflow_state
= overflow_state
;
1490 m_overflow_state
= overflow_state
;
1493 void wxAuiToolBar::ToggleTool(int tool_id
, bool state
)
1495 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1497 if (tool
&& (tool
->kind
== wxITEM_CHECK
|| tool
->kind
== wxITEM_RADIO
))
1499 if (tool
->kind
== wxITEM_RADIO
)
1502 idx
= GetToolIndex(tool_id
);
1503 count
= (int)m_items
.GetCount();
1505 if (idx
>= 0 && idx
< count
)
1507 for (i
= idx
; i
< count
; ++i
)
1509 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1511 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1513 for (i
= idx
; i
> 0; i
--)
1515 if (m_items
[i
].kind
!= wxITEM_RADIO
)
1517 m_items
[i
].state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1521 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1523 else if (tool
->kind
== wxITEM_CHECK
)
1526 tool
->state
|= wxAUI_BUTTON_STATE_CHECKED
;
1528 tool
->state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
1533 bool wxAuiToolBar::GetToolToggled(int tool_id
) const
1535 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1539 if ( (tool
->kind
!= wxITEM_CHECK
) && (tool
->kind
!= wxITEM_RADIO
) )
1542 return (tool
->state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
1548 void wxAuiToolBar::EnableTool(int tool_id
, bool state
)
1550 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1555 tool
->state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1557 tool
->state
|= wxAUI_BUTTON_STATE_DISABLED
;
1561 bool wxAuiToolBar::GetToolEnabled(int tool_id
) const
1563 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1566 return (tool
->state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
1571 wxString
wxAuiToolBar::GetToolLabel(int tool_id
) const
1573 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1574 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1576 return wxEmptyString
;
1581 void wxAuiToolBar::SetToolLabel(int tool_id
, const wxString
& label
)
1583 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1586 tool
->label
= label
;
1590 wxBitmap
wxAuiToolBar::GetToolBitmap(int tool_id
) const
1592 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1593 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1595 return wxNullBitmap
;
1597 return tool
->bitmap
;
1600 void wxAuiToolBar::SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
)
1602 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1605 tool
->bitmap
= bitmap
;
1609 wxString
wxAuiToolBar::GetToolShortHelp(int tool_id
) const
1611 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1612 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1614 return wxEmptyString
;
1616 return tool
->short_help
;
1619 void wxAuiToolBar::SetToolShortHelp(int tool_id
, const wxString
& help_string
)
1621 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1624 tool
->short_help
= help_string
;
1628 wxString
wxAuiToolBar::GetToolLongHelp(int tool_id
) const
1630 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1631 wxASSERT_MSG(tool
, wxT("can't find tool in toolbar item array"));
1633 return wxEmptyString
;
1635 return tool
->long_help
;
1638 void wxAuiToolBar::SetToolLongHelp(int tool_id
, const wxString
& help_string
)
1640 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1643 tool
->long_help
= help_string
;
1647 void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
1648 const wxAuiToolBarItemArray
& append
)
1650 m_custom_overflow_prepend
= prepend
;
1651 m_custom_overflow_append
= append
;
1655 size_t wxAuiToolBar::GetToolCount() const
1657 return m_items
.size();
1660 int wxAuiToolBar::GetToolIndex(int tool_id
) const
1662 // this will prevent us from returning the index of the
1663 // first separator in the toolbar since its id is equal to -1
1667 size_t i
, count
= m_items
.GetCount();
1668 for (i
= 0; i
< count
; ++i
)
1670 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1671 if (item
.id
== tool_id
)
1678 bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx
) const
1680 if (tool_idx
< 0 || tool_idx
>= (int)m_items
.GetCount())
1683 if (!m_items
[tool_idx
].sizer_item
)
1687 GetClientSize(&cli_w
, &cli_h
);
1689 wxRect rect
= m_items
[tool_idx
].sizer_item
->GetRect();
1691 if (m_style
& wxAUI_TB_VERTICAL
)
1693 // take the dropdown size into account
1694 if (m_overflow_visible
)
1695 cli_h
-= m_overflow_sizer_item
->GetSize().y
;
1697 if (rect
.y
+rect
.height
< cli_h
)
1702 // take the dropdown size into account
1703 if (m_overflow_visible
)
1704 cli_w
-= m_overflow_sizer_item
->GetSize().x
;
1706 if (rect
.x
+rect
.width
< cli_w
)
1714 bool wxAuiToolBar::GetToolFits(int tool_id
) const
1716 return GetToolFitsByIndex(GetToolIndex(tool_id
));
1719 wxRect
wxAuiToolBar::GetToolRect(int tool_id
) const
1721 wxAuiToolBarItem
* tool
= FindTool(tool_id
);
1722 if (tool
&& tool
->sizer_item
)
1724 return tool
->sizer_item
->GetRect();
1730 bool wxAuiToolBar::GetToolBarFits() const
1732 if (m_items
.GetCount() == 0)
1734 // empty toolbar always 'fits'
1738 // entire toolbar content fits if the last tool fits
1739 return GetToolFitsByIndex(m_items
.GetCount() - 1);
1742 bool wxAuiToolBar::Realize()
1744 wxClientDC
dc(this);
1748 bool horizontal
= true;
1749 if (m_style
& wxAUI_TB_VERTICAL
)
1753 // create the new sizer to add toolbar elements to
1754 wxBoxSizer
* sizer
= new wxBoxSizer(horizontal
? wxHORIZONTAL
: wxVERTICAL
);
1757 int separator_size
= m_art
->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE
);
1758 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
1759 if (gripper_size
> 0 && m_gripper_visible
)
1762 m_gripper_sizer_item
= sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1764 m_gripper_sizer_item
= sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1768 m_gripper_sizer_item
= NULL
;
1771 // add "left" padding
1772 if (m_left_padding
> 0)
1775 sizer
->Add(m_left_padding
, 1);
1777 sizer
->Add(1, m_left_padding
);
1781 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1783 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1784 wxSizerItem
* sizer_item
= NULL
;
1790 wxSize size
= m_art
->GetLabelSize(dc
, this, item
);
1791 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1792 size
.y
+ (m_tool_border_padding
*2),
1797 sizer
->AddSpacer(m_tool_packing
);
1807 wxSize size
= m_art
->GetToolSize(dc
, this, item
);
1808 sizer_item
= sizer
->Add(size
.x
+ (m_tool_border_padding
*2),
1809 size
.y
+ (m_tool_border_padding
*2),
1815 sizer
->AddSpacer(m_tool_packing
);
1821 case wxITEM_SEPARATOR
:
1824 sizer_item
= sizer
->Add(separator_size
, 1, 0, wxEXPAND
);
1826 sizer_item
= sizer
->Add(1, separator_size
, 0, wxEXPAND
);
1831 sizer
->AddSpacer(m_tool_packing
);
1838 if (item
.proportion
> 0)
1839 sizer_item
= sizer
->AddStretchSpacer(item
.proportion
);
1841 sizer_item
= sizer
->Add(item
.spacer_pixels
, 1);
1844 case wxITEM_CONTROL
:
1846 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1847 wxSizerItem
* ctrl_sizer_item
;
1849 wxBoxSizer
* vert_sizer
= new wxBoxSizer(wxVERTICAL
);
1850 vert_sizer
->AddStretchSpacer(1);
1851 ctrl_sizer_item
= vert_sizer
->Add(item
.window
, 0, wxEXPAND
);
1852 vert_sizer
->AddStretchSpacer(1);
1853 if ( (m_style
& wxAUI_TB_TEXT
) &&
1854 m_tool_text_orientation
== wxAUI_TBTOOL_TEXT_BOTTOM
&&
1855 !item
.GetLabel().empty() )
1857 wxSize s
= GetLabelSize(item
.GetLabel());
1858 vert_sizer
->Add(1, s
.y
);
1862 sizer_item
= sizer
->Add(vert_sizer
, item
.proportion
, wxEXPAND
);
1864 wxSize min_size
= item
.min_size
;
1867 // proportional items will disappear from the toolbar if
1868 // their min width is not set to something really small
1869 if (item
.proportion
!= 0)
1874 if (min_size
.IsFullySpecified())
1876 sizer_item
->SetMinSize(min_size
);
1877 ctrl_sizer_item
->SetMinSize(min_size
);
1883 sizer
->AddSpacer(m_tool_packing
);
1888 item
.sizer_item
= sizer_item
;
1891 // add "right" padding
1892 if (m_right_padding
> 0)
1895 sizer
->Add(m_right_padding
, 1);
1897 sizer
->Add(1, m_right_padding
);
1900 // add drop down area
1901 m_overflow_sizer_item
= NULL
;
1903 if (m_style
& wxAUI_TB_OVERFLOW
)
1905 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
1906 if (overflow_size
> 0 && m_overflow_visible
)
1909 m_overflow_sizer_item
= sizer
->Add(overflow_size
, 1, 0, wxEXPAND
);
1911 m_overflow_sizer_item
= sizer
->Add(1, overflow_size
, 0, wxEXPAND
);
1915 m_overflow_sizer_item
= NULL
;
1920 // the outside sizer helps us apply the "top" and "bottom" padding
1921 wxBoxSizer
* outside_sizer
= new wxBoxSizer(horizontal
? wxVERTICAL
: wxHORIZONTAL
);
1923 // add "top" padding
1924 if (m_top_padding
> 0)
1927 outside_sizer
->Add(1, m_top_padding
);
1929 outside_sizer
->Add(m_top_padding
, 1);
1932 // add the sizer that contains all of the toolbar elements
1933 outside_sizer
->Add(sizer
, 1, wxEXPAND
);
1935 // add "bottom" padding
1936 if (m_bottom_padding
> 0)
1939 outside_sizer
->Add(1, m_bottom_padding
);
1941 outside_sizer
->Add(m_bottom_padding
, 1);
1944 delete m_sizer
; // remove old sizer
1945 m_sizer
= outside_sizer
;
1947 // calculate the rock-bottom minimum size
1948 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1950 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1951 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1952 item
.sizer_item
->SetMinSize(0,0);
1955 m_absolute_min_size
= m_sizer
->GetMinSize();
1957 // reset the min sizes to what they were
1958 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
1960 wxAuiToolBarItem
& item
= m_items
.Item(i
);
1961 if (item
.sizer_item
&& item
.proportion
> 0 && item
.min_size
.IsFullySpecified())
1962 item
.sizer_item
->SetMinSize(item
.min_size
);
1966 wxSize size
= m_sizer
->GetMinSize();
1967 m_minWidth
= size
.x
;
1968 m_minHeight
= size
.y
;
1970 if ((m_style
& wxAUI_TB_NO_AUTORESIZE
) == 0)
1972 wxSize cur_size
= GetClientSize();
1973 wxSize new_size
= GetMinSize();
1974 if (new_size
!= cur_size
)
1976 SetClientSize(new_size
);
1980 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1985 wxSize cur_size
= GetClientSize();
1986 m_sizer
->SetDimension(0, 0, cur_size
.x
, cur_size
.y
);
1993 int wxAuiToolBar::GetOverflowState() const
1995 return m_overflow_state
;
1998 wxRect
wxAuiToolBar::GetOverflowRect() const
2000 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2001 wxRect overflow_rect
= m_overflow_sizer_item
->GetRect();
2002 int overflow_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2004 if (m_style
& wxAUI_TB_VERTICAL
)
2006 overflow_rect
.y
= cli_rect
.height
- overflow_size
;
2007 overflow_rect
.x
= 0;
2008 overflow_rect
.width
= cli_rect
.width
;
2009 overflow_rect
.height
= overflow_size
;
2013 overflow_rect
.x
= cli_rect
.width
- overflow_size
;
2014 overflow_rect
.y
= 0;
2015 overflow_rect
.width
= overflow_size
;
2016 overflow_rect
.height
= cli_rect
.height
;
2019 return overflow_rect
;
2022 wxSize
wxAuiToolBar::GetLabelSize(const wxString
& label
)
2024 wxClientDC
dc(this);
2027 int text_width
= 0, text_height
= 0;
2031 // get the text height
2032 dc
.GetTextExtent(wxT("ABCDHgj"), &tx
, &text_height
);
2034 // get the text width
2035 dc
.GetTextExtent(label
, &text_width
, &ty
);
2037 return wxSize(text_width
, text_height
);
2041 void wxAuiToolBar::DoIdleUpdate()
2043 wxEvtHandler
* handler
= GetEventHandler();
2045 bool need_refresh
= false;
2048 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2050 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2055 wxUpdateUIEvent
evt(item
.id
);
2056 evt
.SetEventObject(this);
2058 if (handler
->ProcessEvent(evt
))
2060 if (evt
.GetSetEnabled())
2064 is_enabled
= item
.window
->IsEnabled();
2066 is_enabled
= (item
.state
& wxAUI_BUTTON_STATE_DISABLED
) ? false : true;
2068 bool new_enabled
= evt
.GetEnabled();
2069 if (new_enabled
!= is_enabled
)
2073 item
.window
->Enable(new_enabled
);
2078 item
.state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
2080 item
.state
|= wxAUI_BUTTON_STATE_DISABLED
;
2082 need_refresh
= true;
2086 if (evt
.GetSetChecked())
2088 // make sure we aren't checking an item that can't be
2089 if (item
.kind
!= wxITEM_CHECK
&& item
.kind
!= wxITEM_RADIO
)
2092 bool is_checked
= (item
.state
& wxAUI_BUTTON_STATE_CHECKED
) ? true : false;
2093 bool new_checked
= evt
.GetChecked();
2095 if (new_checked
!= is_checked
)
2098 item
.state
|= wxAUI_BUTTON_STATE_CHECKED
;
2100 item
.state
&= ~wxAUI_BUTTON_STATE_CHECKED
;
2102 need_refresh
= true;
2117 void wxAuiToolBar::OnSize(wxSizeEvent
& WXUNUSED(evt
))
2120 GetClientSize(&x
, &y
);
2123 SetOrientation(wxHORIZONTAL
);
2125 SetOrientation(wxVERTICAL
);
2127 if (((x
>= y
) && m_absolute_min_size
.x
> x
) ||
2128 ((y
> x
) && m_absolute_min_size
.y
> y
))
2130 // hide all flexible items
2132 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2134 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2135 if (item
.sizer_item
&& item
.proportion
> 0 && item
.sizer_item
->IsShown())
2137 item
.sizer_item
->Show(false);
2138 item
.sizer_item
->SetProportion(0);
2144 // show all flexible items
2146 for (i
= 0, count
= m_items
.GetCount(); i
< count
; ++i
)
2148 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2149 if (item
.sizer_item
&& item
.proportion
> 0 && !item
.sizer_item
->IsShown())
2151 item
.sizer_item
->Show(true);
2152 item
.sizer_item
->SetProportion(item
.proportion
);
2157 m_sizer
->SetDimension(0, 0, x
, y
);
2165 void wxAuiToolBar::DoSetSize(int x
,
2171 wxSize parent_size
= GetParent()->GetClientSize();
2172 if (x
+ width
> parent_size
.x
)
2173 width
= wxMax(0, parent_size
.x
- x
);
2174 if (y
+ height
> parent_size
.y
)
2175 height
= wxMax(0, parent_size
.y
- y
);
2177 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
2181 void wxAuiToolBar::OnIdle(wxIdleEvent
& evt
)
2187 void wxAuiToolBar::OnPaint(wxPaintEvent
& WXUNUSED(evt
))
2189 wxAutoBufferedPaintDC
dc(this);
2190 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2193 bool horizontal
= true;
2194 if (m_style
& wxAUI_TB_VERTICAL
)
2198 m_art
->DrawBackground(dc
, this, cli_rect
);
2200 int gripper_size
= m_art
->GetElementSize(wxAUI_TBART_GRIPPER_SIZE
);
2201 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2203 // paint the gripper
2204 if (gripper_size
> 0 && m_gripper_sizer_item
)
2206 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2208 gripper_rect
.width
= gripper_size
;
2210 gripper_rect
.height
= gripper_size
;
2211 m_art
->DrawGripper(dc
, this, gripper_rect
);
2214 // calculated how far we can draw items
2217 last_extent
= cli_rect
.width
;
2219 last_extent
= cli_rect
.height
;
2220 if (m_overflow_visible
)
2221 last_extent
-= dropdown_size
;
2223 // paint each individual tool
2224 size_t i
, count
= m_items
.GetCount();
2225 for (i
= 0; i
< count
; ++i
)
2227 wxAuiToolBarItem
& item
= m_items
.Item(i
);
2229 if (!item
.sizer_item
)
2232 wxRect item_rect
= item
.sizer_item
->GetRect();
2235 if ((horizontal
&& item_rect
.x
+ item_rect
.width
>= last_extent
) ||
2236 (!horizontal
&& item_rect
.y
+ item_rect
.height
>= last_extent
))
2241 if (item
.kind
== wxITEM_SEPARATOR
)
2244 m_art
->DrawSeparator(dc
, this, item_rect
);
2246 else if (item
.kind
== wxITEM_LABEL
)
2248 // draw a text label only
2249 m_art
->DrawLabel(dc
, this, item
, item_rect
);
2251 else if (item
.kind
== wxITEM_NORMAL
)
2253 // draw a regular button or dropdown button
2255 m_art
->DrawButton(dc
, this, item
, item_rect
);
2257 m_art
->DrawDropDownButton(dc
, this, item
, item_rect
);
2259 else if (item
.kind
== wxITEM_CHECK
)
2261 // draw a toggle button
2262 m_art
->DrawButton(dc
, this, item
, item_rect
);
2264 else if (item
.kind
== wxITEM_RADIO
)
2266 // draw a toggle button
2267 m_art
->DrawButton(dc
, this, item
, item_rect
);
2269 else if (item
.kind
== wxITEM_CONTROL
)
2271 // draw the control's label
2272 m_art
->DrawControlLabel(dc
, this, item
, item_rect
);
2275 // fire a signal to see if the item wants to be custom-rendered
2276 OnCustomRender(dc
, item
, item_rect
);
2279 // paint the overflow button
2280 if (dropdown_size
> 0 && m_overflow_sizer_item
)
2282 wxRect dropdown_rect
= GetOverflowRect();
2283 m_art
->DrawOverflowButton(dc
, this, dropdown_rect
, m_overflow_state
);
2287 void wxAuiToolBar::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2292 void wxAuiToolBar::OnLeftDown(wxMouseEvent
& evt
)
2294 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2296 if (m_gripper_sizer_item
)
2298 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2299 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2302 wxAuiManager
* manager
= wxAuiManager::GetManager(this);
2306 int x_drag_offset
= evt
.GetX() - gripper_rect
.GetX();
2307 int y_drag_offset
= evt
.GetY() - gripper_rect
.GetY();
2309 // gripper was clicked
2310 manager
->StartPaneDrag(this, wxPoint(x_drag_offset
, y_drag_offset
));
2315 if (m_overflow_sizer_item
)
2317 wxRect overflow_rect
= GetOverflowRect();
2320 m_overflow_visible
&&
2321 overflow_rect
.Contains(evt
.m_x
, evt
.m_y
))
2323 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, -1);
2324 e
.SetEventObject(this);
2326 e
.SetClickPoint(wxPoint(evt
.GetX(), evt
.GetY()));
2327 bool processed
= GetEventHandler()->ProcessEvent(e
);
2336 wxAuiToolBarItemArray overflow_items
;
2339 // add custom overflow prepend items, if any
2340 count
= m_custom_overflow_prepend
.GetCount();
2341 for (i
= 0; i
< count
; ++i
)
2342 overflow_items
.Add(m_custom_overflow_prepend
[i
]);
2344 // only show items that don't fit in the dropdown
2345 count
= m_items
.GetCount();
2346 for (i
= 0; i
< count
; ++i
)
2348 if (!GetToolFitsByIndex(i
))
2349 overflow_items
.Add(m_items
[i
]);
2352 // add custom overflow append items, if any
2353 count
= m_custom_overflow_append
.GetCount();
2354 for (i
= 0; i
< count
; ++i
)
2355 overflow_items
.Add(m_custom_overflow_append
[i
]);
2357 int res
= m_art
->ShowDropDown(this, overflow_items
);
2358 m_overflow_state
= 0;
2362 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, res
);
2363 e
.SetEventObject(this);
2364 GetParent()->GetEventHandler()->ProcessEvent(e
);
2373 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2374 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2378 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2380 m_action_pos
= wxPoint(-1,-1);
2381 m_action_item
= NULL
;
2385 SetPressedItem(m_action_item
);
2387 // fire the tool dropdown event
2388 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, m_action_item
->id
);
2389 e
.SetEventObject(this);
2390 e
.SetToolId(m_action_item
->id
);
2391 e
.SetDropDownClicked(false);
2393 int mouse_x
= evt
.GetX();
2394 wxRect rect
= m_action_item
->sizer_item
->GetRect();
2396 if (m_action_item
->dropdown
&&
2397 mouse_x
>= (rect
.x
+rect
.width
-BUTTON_DROPDOWN_WIDTH
-1) &&
2398 mouse_x
< (rect
.x
+rect
.width
))
2400 e
.SetDropDownClicked(true);
2403 e
.SetClickPoint(evt
.GetPosition());
2404 e
.SetItemRect(rect
);
2405 GetEventHandler()->ProcessEvent(e
);
2410 void wxAuiToolBar::OnLeftUp(wxMouseEvent
& evt
)
2412 SetPressedItem(NULL
);
2414 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2415 if (hit_item
&& !(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2417 SetHoverItem(hit_item
);
2423 // reset drag and drop member variables
2425 m_action_pos
= wxPoint(-1,-1);
2426 m_action_item
= NULL
;
2431 wxAuiToolBarItem
* hit_item
;
2432 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2434 if (m_action_item
&& hit_item
== m_action_item
)
2438 if (hit_item
->kind
== wxITEM_CHECK
|| hit_item
->kind
== wxITEM_RADIO
)
2440 bool toggle
= false;
2442 if (m_action_item
->state
& wxAUI_BUTTON_STATE_CHECKED
)
2447 ToggleTool(m_action_item
->id
, toggle
);
2449 // repaint immediately
2453 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2454 e
.SetEventObject(this);
2456 GetEventHandler()->ProcessEvent(e
);
2461 wxCommandEvent
e(wxEVT_COMMAND_MENU_SELECTED
, m_action_item
->id
);
2462 e
.SetEventObject(this);
2463 GetEventHandler()->ProcessEvent(e
);
2469 // reset drag and drop member variables
2471 m_action_pos
= wxPoint(-1,-1);
2472 m_action_item
= NULL
;
2475 void wxAuiToolBar::OnRightDown(wxMouseEvent
& evt
)
2477 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2479 if (m_gripper_sizer_item
)
2481 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2482 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2486 if (m_overflow_sizer_item
)
2488 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2489 if (dropdown_size
> 0 &&
2490 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2492 evt
.m_y
< cli_rect
.height
&&
2499 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2500 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2504 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2506 m_action_pos
= wxPoint(-1,-1);
2507 m_action_item
= NULL
;
2513 void wxAuiToolBar::OnRightUp(wxMouseEvent
& evt
)
2515 wxAuiToolBarItem
* hit_item
;
2516 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2518 if (m_action_item
&& hit_item
== m_action_item
)
2520 if (hit_item
->kind
== wxITEM_NORMAL
)
2522 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, m_action_item
->id
);
2523 e
.SetEventObject(this);
2524 e
.SetToolId(m_action_item
->id
);
2525 e
.SetClickPoint(m_action_pos
);
2526 GetEventHandler()->ProcessEvent(e
);
2532 // right-clicked on the invalid area of the toolbar
2533 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, -1);
2534 e
.SetEventObject(this);
2536 e
.SetClickPoint(m_action_pos
);
2537 GetEventHandler()->ProcessEvent(e
);
2541 // reset member variables
2542 m_action_pos
= wxPoint(-1,-1);
2543 m_action_item
= NULL
;
2546 void wxAuiToolBar::OnMiddleDown(wxMouseEvent
& evt
)
2548 wxRect
cli_rect(wxPoint(0,0), GetClientSize());
2550 if (m_gripper_sizer_item
)
2552 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2553 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2557 if (m_overflow_sizer_item
)
2559 int dropdown_size
= m_art
->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE
);
2560 if (dropdown_size
> 0 &&
2561 evt
.m_x
> cli_rect
.width
- dropdown_size
&&
2563 evt
.m_y
< cli_rect
.height
&&
2570 m_action_pos
= wxPoint(evt
.GetX(), evt
.GetY());
2571 m_action_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2575 if (m_action_item
->state
& wxAUI_BUTTON_STATE_DISABLED
)
2577 m_action_pos
= wxPoint(-1,-1);
2578 m_action_item
= NULL
;
2584 void wxAuiToolBar::OnMiddleUp(wxMouseEvent
& evt
)
2586 wxAuiToolBarItem
* hit_item
;
2587 hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2589 if (m_action_item
&& hit_item
== m_action_item
)
2591 if (hit_item
->kind
== wxITEM_NORMAL
)
2593 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, m_action_item
->id
);
2594 e
.SetEventObject(this);
2595 e
.SetToolId(m_action_item
->id
);
2596 e
.SetClickPoint(m_action_pos
);
2597 GetEventHandler()->ProcessEvent(e
);
2602 // reset member variables
2603 m_action_pos
= wxPoint(-1,-1);
2604 m_action_item
= NULL
;
2607 void wxAuiToolBar::OnMotion(wxMouseEvent
& evt
)
2609 // start a drag event
2611 m_action_item
!= NULL
&&
2612 m_action_pos
!= wxPoint(-1,-1) &&
2613 abs(evt
.m_x
- m_action_pos
.x
) + abs(evt
.m_y
- m_action_pos
.y
) > 5)
2619 wxAuiToolBarEvent
e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, GetId());
2620 e
.SetEventObject(this);
2621 e
.SetToolId(m_action_item
->id
);
2622 GetEventHandler()->ProcessEvent(e
);
2627 wxAuiToolBarItem
* hit_item
= FindToolByPosition(evt
.GetX(), evt
.GetY());
2630 if (!(hit_item
->state
& wxAUI_BUTTON_STATE_DISABLED
))
2631 SetHoverItem(hit_item
);
2637 // no hit item, remove any hit item
2638 SetHoverItem(hit_item
);
2641 // figure out tooltips
2642 wxAuiToolBarItem
* packing_hit_item
;
2643 packing_hit_item
= FindToolByPositionWithPacking(evt
.GetX(), evt
.GetY());
2644 if (packing_hit_item
)
2646 if (packing_hit_item
!= m_tip_item
)
2648 m_tip_item
= packing_hit_item
;
2650 if ( !packing_hit_item
->short_help
.empty() )
2651 SetToolTip(packing_hit_item
->short_help
);
2662 // if we've pressed down an item and we're hovering
2663 // over it, make sure it's state is set to pressed
2666 if (m_action_item
== hit_item
)
2667 SetPressedItem(m_action_item
);
2669 SetPressedItem(NULL
);
2672 // figure out the dropdown button state (are we hovering or pressing it?)
2673 RefreshOverflowState();
2676 void wxAuiToolBar::OnLeaveWindow(wxMouseEvent
& WXUNUSED(evt
))
2678 RefreshOverflowState();
2680 SetPressedItem(NULL
);
2686 void wxAuiToolBar::OnSetCursor(wxSetCursorEvent
& evt
)
2688 wxCursor cursor
= wxNullCursor
;
2690 if (m_gripper_sizer_item
)
2692 wxRect gripper_rect
= m_gripper_sizer_item
->GetRect();
2693 if (gripper_rect
.Contains(evt
.GetX(), evt
.GetY()))
2695 cursor
= wxCursor(wxCURSOR_SIZING
);
2699 evt
.SetCursor(cursor
);