1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/aui/toolbar.h
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005, Kirix Corporation, All Rights Reserved.
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/control.h"
23 //class WXDLLIMPEXP_FWD_CORE wxSizerItem;
25 enum wxAuiToolBarStyle
27 wxAUI_TB_TEXT
= 1 << 0,
28 wxAUI_TB_NO_TOOLTIPS
= 1 << 1,
29 wxAUI_TB_NO_AUTORESIZE
= 1 << 2,
30 wxAUI_TB_GRIPPER
= 1 << 3,
31 wxAUI_TB_OVERFLOW
= 1 << 4,
32 wxAUI_TB_VERTICAL
= 1 << 5,
33 wxAUI_TB_HORZ_LAYOUT
= 1 << 6,
34 wxAUI_TB_HORZ_TEXT
= (wxAUI_TB_HORZ_LAYOUT
| wxAUI_TB_TEXT
),
35 wxAUI_TB_DEFAULT_STYLE
= 0
38 enum wxAuiToolBarArtSetting
40 wxAUI_TBART_SEPARATOR_SIZE
= 0,
41 wxAUI_TBART_GRIPPER_SIZE
= 1,
42 wxAUI_TBART_OVERFLOW_SIZE
= 2
45 enum wxAuiToolBarToolTextOrientation
47 wxAUI_TBTOOL_TEXT_LEFT
= 0, // unused/unimplemented
48 wxAUI_TBTOOL_TEXT_RIGHT
= 1,
49 wxAUI_TBTOOL_TEXT_TOP
= 2, // unused/unimplemented
50 wxAUI_TBTOOL_TEXT_BOTTOM
= 3
54 // aui toolbar event class
56 class WXDLLIMPEXP_AUI wxAuiToolBarEvent
: public wxNotifyEvent
59 wxAuiToolBarEvent(wxEventType command_type
= wxEVT_NULL
,
61 : wxNotifyEvent(command_type
, win_id
)
63 is_dropdown_clicked
= false;
64 click_pt
= wxPoint(-1, -1);
65 rect
= wxRect(-1,-1, 0, 0);
69 wxAuiToolBarEvent(const wxAuiToolBarEvent
& c
) : wxNotifyEvent(c
)
71 is_dropdown_clicked
= c
.is_dropdown_clicked
;
72 click_pt
= c
.click_pt
;
77 wxEvent
*Clone() const { return new wxAuiToolBarEvent(*this); }
79 bool IsDropDownClicked() const { return is_dropdown_clicked
; }
80 void SetDropDownClicked(bool c
) { is_dropdown_clicked
= c
; }
82 wxPoint
GetClickPoint() const { return click_pt
; }
83 void SetClickPoint(const wxPoint
& p
) { click_pt
= p
; }
85 wxRect
GetItemRect() const { return rect
; }
86 void SetItemRect(const wxRect
& r
) { rect
= r
; }
88 int GetToolId() const { return tool_id
; }
89 void SetToolId(int id
) { tool_id
= id
; }
93 bool is_dropdown_clicked
;
99 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiToolBarEvent
)
103 class WXDLLIMPEXP_AUI wxAuiToolBarItem
105 friend class wxAuiToolBar
;
115 kind
= wxITEM_NORMAL
;
116 state
= 0; // normal, enabled
124 wxAuiToolBarItem(const wxAuiToolBarItem
& c
)
129 wxAuiToolBarItem
& operator=(const wxAuiToolBarItem
& c
)
135 void Assign(const wxAuiToolBarItem
& c
)
140 disabled_bitmap
= c
.disabled_bitmap
;
141 hover_bitmap
= c
.hover_bitmap
;
142 short_help
= c
.short_help
;
143 long_help
= c
.long_help
;
144 sizer_item
= c
.sizer_item
;
145 min_size
= c
.min_size
;
146 spacer_pixels
= c
.spacer_pixels
;
150 proportion
= c
.proportion
;
152 dropdown
= c
.dropdown
;
154 user_data
= c
.user_data
;
158 void SetWindow(wxWindow
* w
) { window
= w
; }
159 wxWindow
* GetWindow() { return window
; }
161 void SetId(int new_id
) { id
= new_id
; }
162 int GetId() const { return id
; }
164 void SetKind(int new_kind
) { kind
= new_kind
; }
165 int GetKind() const { return kind
; }
167 void SetState(int new_state
) { state
= new_state
; }
168 int GetState() const { return state
; }
170 void SetSizerItem(wxSizerItem
* s
) { sizer_item
= s
; }
171 wxSizerItem
* GetSizerItem() const { return sizer_item
; }
173 void SetLabel(const wxString
& s
) { label
= s
; }
174 const wxString
& GetLabel() const { return label
; }
176 void SetBitmap(const wxBitmap
& bmp
) { bitmap
= bmp
; }
177 const wxBitmap
& GetBitmap() const { return bitmap
; }
179 void SetDisabledBitmap(const wxBitmap
& bmp
) { disabled_bitmap
= bmp
; }
180 const wxBitmap
& GetDisabledBitmap() const { return disabled_bitmap
; }
182 void SetHoverBitmap(const wxBitmap
& bmp
) { hover_bitmap
= bmp
; }
183 const wxBitmap
& GetHoverBitmap() const { return hover_bitmap
; }
185 void SetShortHelp(const wxString
& s
) { short_help
= s
; }
186 const wxString
& GetShortHelp() const { return short_help
; }
188 void SetLongHelp(const wxString
& s
) { long_help
= s
; }
189 const wxString
& GetLongHelp() const { return long_help
; }
191 void SetMinSize(const wxSize
& s
) { min_size
= s
; }
192 const wxSize
& GetMinSize() const { return min_size
; }
194 void SetSpacerPixels(int s
) { spacer_pixels
= s
; }
195 int GetSpacerPixels() const { return spacer_pixels
; }
197 void SetProportion(int p
) { proportion
= p
; }
198 int GetProportion() const { return proportion
; }
200 void SetActive(bool b
) { active
= b
; }
201 bool IsActive() const { return active
; }
203 void SetHasDropDown(bool b
) { dropdown
= b
; }
204 bool HasDropDown() const { return dropdown
; }
206 void SetSticky(bool b
) { sticky
= b
; }
207 bool IsSticky() const { return sticky
; }
209 void SetUserData(long l
) { user_data
= l
; }
210 long GetUserData() const { return user_data
; }
214 wxWindow
* window
; // item's associated window
215 wxString label
; // label displayed on the item
216 wxBitmap bitmap
; // item's bitmap
217 wxBitmap disabled_bitmap
; // item's disabled bitmap
218 wxBitmap hover_bitmap
; // item's hover bitmap
219 wxString short_help
; // short help (for tooltip)
220 wxString long_help
; // long help (for status bar)
221 wxSizerItem
* sizer_item
; // sizer item
222 wxSize min_size
; // item's minimum size
223 int spacer_pixels
; // size of a spacer
225 int kind
; // item's kind
227 int proportion
; // proportion
228 bool active
; // true if the item is currently active
229 bool dropdown
; // true if the item has a dropdown button
230 bool sticky
; // overrides button states if true (always active)
231 long user_data
; // user-specified data
235 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
243 class WXDLLIMPEXP_AUI wxAuiToolBarArt
247 wxAuiToolBarArt() { }
248 virtual ~wxAuiToolBarArt() { }
250 virtual wxAuiToolBarArt
* Clone() = 0;
251 virtual void SetFlags(unsigned int flags
) = 0;
252 virtual unsigned int GetFlags() = 0;
253 virtual void SetFont(const wxFont
& font
) = 0;
254 virtual wxFont
GetFont() = 0;
255 virtual void SetTextOrientation(int orientation
) = 0;
256 virtual int GetTextOrientation() = 0;
258 virtual void DrawBackground(
261 const wxRect
& rect
) = 0;
263 virtual void DrawLabel(
266 const wxAuiToolBarItem
& item
,
267 const wxRect
& rect
) = 0;
269 virtual void DrawButton(
272 const wxAuiToolBarItem
& item
,
273 const wxRect
& rect
) = 0;
275 virtual void DrawDropDownButton(
278 const wxAuiToolBarItem
& item
,
279 const wxRect
& rect
) = 0;
281 virtual void DrawControlLabel(
284 const wxAuiToolBarItem
& item
,
285 const wxRect
& rect
) = 0;
287 virtual void DrawSeparator(
290 const wxRect
& rect
) = 0;
292 virtual void DrawGripper(
295 const wxRect
& rect
) = 0;
297 virtual void DrawOverflowButton(
303 virtual wxSize
GetLabelSize(
306 const wxAuiToolBarItem
& item
) = 0;
308 virtual wxSize
GetToolSize(
311 const wxAuiToolBarItem
& item
) = 0;
313 virtual int GetElementSize(int element_id
) = 0;
314 virtual void SetElementSize(int element_id
, int size
) = 0;
316 virtual int ShowDropDown(
318 const wxAuiToolBarItemArray
& items
) = 0;
323 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
328 wxAuiDefaultToolBarArt();
329 virtual ~wxAuiDefaultToolBarArt();
331 virtual wxAuiToolBarArt
* Clone();
332 virtual void SetFlags(unsigned int flags
);
333 virtual unsigned int GetFlags();
334 virtual void SetFont(const wxFont
& font
);
335 virtual wxFont
GetFont();
336 virtual void SetTextOrientation(int orientation
);
337 virtual int GetTextOrientation();
339 virtual void DrawBackground(
344 virtual void DrawLabel(
347 const wxAuiToolBarItem
& item
,
350 virtual void DrawButton(
353 const wxAuiToolBarItem
& item
,
356 virtual void DrawDropDownButton(
359 const wxAuiToolBarItem
& item
,
362 virtual void DrawControlLabel(
365 const wxAuiToolBarItem
& item
,
368 virtual void DrawSeparator(
373 virtual void DrawGripper(
378 virtual void DrawOverflowButton(
384 virtual wxSize
GetLabelSize(
387 const wxAuiToolBarItem
& item
);
389 virtual wxSize
GetToolSize(
392 const wxAuiToolBarItem
& item
);
394 virtual int GetElementSize(int element
);
395 virtual void SetElementSize(int element_id
, int size
);
397 virtual int ShowDropDown(wxWindow
* wnd
,
398 const wxAuiToolBarItemArray
& items
);
402 wxBitmap m_button_dropdown_bmp
;
403 wxBitmap m_disabled_button_dropdown_bmp
;
404 wxBitmap m_overflow_bmp
;
405 wxBitmap m_disabled_overflow_bmp
;
406 wxColour m_base_colour
;
407 wxColour m_highlight_colour
;
409 unsigned int m_flags
;
410 int m_text_orientation
;
412 wxPen m_gripper_pen1
;
413 wxPen m_gripper_pen2
;
414 wxPen m_gripper_pen3
;
416 int m_separator_size
;
424 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
428 wxAuiToolBar(wxWindow
* parent
,
430 const wxPoint
& position
= wxDefaultPosition
,
431 const wxSize
& size
= wxDefaultSize
,
432 long style
= wxAUI_TB_DEFAULT_STYLE
);
433 virtual ~wxAuiToolBar();
435 void SetWindowStyleFlag(long style
);
436 long GetWindowStyleFlag() const;
438 void SetArtProvider(wxAuiToolBarArt
* art
);
439 wxAuiToolBarArt
* GetArtProvider() const;
441 bool SetFont(const wxFont
& font
);
444 wxAuiToolBarItem
* AddTool(int tool_id
,
445 const wxString
& label
,
446 const wxBitmap
& bitmap
,
447 const wxString
& short_help_string
= wxEmptyString
,
448 wxItemKind kind
= wxITEM_NORMAL
);
450 wxAuiToolBarItem
* AddTool(int tool_id
,
451 const wxString
& label
,
452 const wxBitmap
& bitmap
,
453 const wxBitmap
& disabled_bitmap
,
455 const wxString
& short_help_string
,
456 const wxString
& long_help_string
,
457 wxObject
* client_data
);
459 wxAuiToolBarItem
* AddTool(int tool_id
,
460 const wxBitmap
& bitmap
,
461 const wxBitmap
& disabled_bitmap
,
463 wxObject
* client_data
= NULL
,
464 const wxString
& short_help_string
= wxEmptyString
,
465 const wxString
& long_help_string
= wxEmptyString
)
467 return AddTool(tool_id
,
471 toggle ? wxITEM_CHECK
: wxITEM_NORMAL
,
477 wxAuiToolBarItem
* AddLabel(int tool_id
,
478 const wxString
& label
= wxEmptyString
,
479 const int width
= -1);
480 wxAuiToolBarItem
* AddControl(wxControl
* control
,
481 const wxString
& label
= wxEmptyString
);
482 wxAuiToolBarItem
* AddSeparator();
483 wxAuiToolBarItem
* AddSpacer(int pixels
);
484 wxAuiToolBarItem
* AddStretchSpacer(int proportion
= 1);
488 wxControl
* FindControl(int window_id
);
489 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
490 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
491 wxAuiToolBarItem
* FindTool(int tool_id
) const;
493 void ClearTools() { Clear() ; }
495 bool DeleteTool(int tool_id
);
496 bool DeleteByIndex(int tool_id
);
498 size_t GetToolCount() const;
499 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
500 int GetToolIndex(int tool_id
) const;
501 bool GetToolFits(int tool_id
) const;
502 wxRect
GetToolRect(int tool_id
) const;
503 bool GetToolFitsByIndex(int tool_id
) const;
504 bool GetToolBarFits() const;
506 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
507 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
508 void SetMargins(int left
, int right
, int top
, int bottom
);
510 void SetToolBitmapSize(const wxSize
& size
);
511 wxSize
GetToolBitmapSize() const;
513 bool GetOverflowVisible() const;
514 void SetOverflowVisible(bool visible
);
516 bool GetGripperVisible() const;
517 void SetGripperVisible(bool visible
);
519 void ToggleTool(int tool_id
, bool state
);
520 bool GetToolToggled(int tool_id
) const;
522 void EnableTool(int tool_id
, bool state
);
523 bool GetToolEnabled(int tool_id
) const;
525 void SetToolDropDown(int tool_id
, bool dropdown
);
526 bool GetToolDropDown(int tool_id
) const;
528 void SetToolBorderPadding(int padding
);
529 int GetToolBorderPadding() const;
531 void SetToolTextOrientation(int orientation
);
532 int GetToolTextOrientation() const;
534 void SetToolPacking(int packing
);
535 int GetToolPacking() const;
537 void SetToolProportion(int tool_id
, int proportion
);
538 int GetToolProportion(int tool_id
) const;
540 void SetToolSeparation(int separation
);
541 int GetToolSeparation() const;
543 void SetToolSticky(int tool_id
, bool sticky
);
544 bool GetToolSticky(int tool_id
) const;
546 wxString
GetToolLabel(int tool_id
) const;
547 void SetToolLabel(int tool_id
, const wxString
& label
);
549 wxBitmap
GetToolBitmap(int tool_id
) const;
550 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
552 wxString
GetToolShortHelp(int tool_id
) const;
553 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
555 wxString
GetToolLongHelp(int tool_id
) const;
556 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
558 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
559 const wxAuiToolBarItemArray
& append
);
563 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
564 const wxAuiToolBarItem
& WXUNUSED(item
),
565 const wxRect
& WXUNUSED(rect
)) { }
570 void SetOrientation(int orientation
);
571 void SetHoverItem(wxAuiToolBarItem
* item
);
572 void SetPressedItem(wxAuiToolBarItem
* item
);
573 void RefreshOverflowState();
575 int GetOverflowState() const;
576 wxRect
GetOverflowRect() const;
577 wxSize
GetLabelSize(const wxString
& label
);
578 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
580 void DoSetSize(int x
,
584 int sizeFlags
= wxSIZE_AUTO
);
586 protected: // handlers
588 void OnSize(wxSizeEvent
& evt
);
589 void OnIdle(wxIdleEvent
& evt
);
590 void OnPaint(wxPaintEvent
& evt
);
591 void OnEraseBackground(wxEraseEvent
& evt
);
592 void OnLeftDown(wxMouseEvent
& evt
);
593 void OnLeftUp(wxMouseEvent
& evt
);
594 void OnRightDown(wxMouseEvent
& evt
);
595 void OnRightUp(wxMouseEvent
& evt
);
596 void OnMiddleDown(wxMouseEvent
& evt
);
597 void OnMiddleUp(wxMouseEvent
& evt
);
598 void OnMotion(wxMouseEvent
& evt
);
599 void OnLeaveWindow(wxMouseEvent
& evt
);
600 void OnSetCursor(wxSetCursorEvent
& evt
);
604 wxAuiToolBarItemArray m_items
; // array of toolbar items
605 wxAuiToolBarArt
* m_art
; // art provider
606 wxBoxSizer
* m_sizer
; // main sizer for toolbar
607 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
608 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
609 wxBitmap m_bitmap
; // double-buffer bitmap
610 wxSizerItem
* m_gripper_sizer_item
;
611 wxSizerItem
* m_overflow_sizer_item
;
612 wxSize m_absolute_min_size
;
613 wxPoint m_action_pos
; // position of left-mouse down
614 wxAuiToolBarItemArray m_custom_overflow_prepend
;
615 wxAuiToolBarItemArray m_custom_overflow_append
;
619 int m_sizer_element_count
;
623 int m_bottom_padding
;
625 int m_tool_border_padding
;
626 int m_tool_text_orientation
;
627 int m_overflow_state
;
629 bool m_gripper_visible
;
630 bool m_overflow_visible
;
633 DECLARE_EVENT_TABLE()
634 DECLARE_CLASS(wxAuiToolBar
)
640 // wx event machinery
644 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
645 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
646 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
647 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
648 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent
);
650 typedef void (wxEvtHandler
::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
652 #define wxAuiToolBarEventHandler(func) \
653 wxEVENT_HANDLER_CAST(wxAuiToolBarEventFunction, func)
655 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
656 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
657 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
658 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
659 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
660 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
661 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
662 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
663 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
664 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
668 // wxpython/swig event work
669 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
670 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
671 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
672 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
673 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
676 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
677 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
678 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
679 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
680 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
685 #endif // _WX_AUIBAR_H_