1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/aui/toolbar.h
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
7 // RCS-ID: $Id: framemanager.h 53135 2008-04-12 02:31:04Z VZ $
8 // Copyright: (C) Copyright 2005, Kirix Corporation, All Rights Reserved.
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/control.h"
21 enum wxAuiToolBarStyle
23 wxAUI_TB_TEXT
= 1 << 0,
24 wxAUI_TB_NO_TOOLTIPS
= 1 << 1,
25 wxAUI_TB_NO_AUTORESIZE
= 1 << 2,
26 wxAUI_TB_GRIPPER
= 1 << 3,
27 wxAUI_TB_OVERFLOW
= 1 << 4,
28 wxAUI_TB_VERTICAL
= 1 << 5,
29 wxAUI_TB_HORZ_LAYOUT
= 1 << 6,
30 wxAUI_TB_HORZ_TEXT
= (wxAUI_TB_HORZ_LAYOUT
| wxAUI_TB_TEXT
),
31 wxAUI_TB_DEFAULT_STYLE
= 0
34 enum wxAuiToolBarArtSetting
36 wxAUI_TBART_SEPARATOR_SIZE
= 0,
37 wxAUI_TBART_GRIPPER_SIZE
= 1,
38 wxAUI_TBART_OVERFLOW_SIZE
= 2
41 enum wxAuiToolBarToolTextOrientation
43 wxAUI_TBTOOL_TEXT_LEFT
= 0, // unused/unimplemented
44 wxAUI_TBTOOL_TEXT_RIGHT
= 1,
45 wxAUI_TBTOOL_TEXT_TOP
= 2, // unused/unimplemented
46 wxAUI_TBTOOL_TEXT_BOTTOM
= 3
50 // aui toolbar event class
52 class WXDLLIMPEXP_AUI wxAuiToolBarEvent
: public wxNotifyEvent
55 wxAuiToolBarEvent(wxEventType command_type
= wxEVT_NULL
,
57 : wxNotifyEvent(command_type
, win_id
)
59 is_dropdown_clicked
= false;
60 click_pt
= wxPoint(-1, -1);
61 rect
= wxRect(-1,-1, 0, 0);
65 wxAuiToolBarEvent(const wxAuiToolBarEvent
& c
) : wxNotifyEvent(c
)
67 is_dropdown_clicked
= c
.is_dropdown_clicked
;
68 click_pt
= c
.click_pt
;
73 wxEvent
*Clone() const { return new wxAuiToolBarEvent(*this); }
75 bool IsDropDownClicked() const { return is_dropdown_clicked
; }
76 void SetDropDownClicked(bool c
) { is_dropdown_clicked
= c
; }
78 wxPoint
GetClickPoint() const { return click_pt
; }
79 void SetClickPoint(const wxPoint
& p
) { click_pt
= p
; }
81 wxRect
GetItemRect() const { return rect
; }
82 void SetItemRect(const wxRect
& r
) { rect
= r
; }
84 int GetToolId() const { return tool_id
; }
85 void SetToolId(int id
) { tool_id
= id
; }
89 bool is_dropdown_clicked
;
96 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiToolBarEvent
)
101 class WXDLLIMPEXP_AUI wxAuiToolBarItem
103 friend class wxAuiToolBar
;
113 kind
= wxITEM_NORMAL
;
114 state
= 0; // normal, enabled
122 wxAuiToolBarItem(const wxAuiToolBarItem
& c
)
127 wxAuiToolBarItem
& operator=(const wxAuiToolBarItem
& c
)
133 void Assign(const wxAuiToolBarItem
& c
)
138 disabled_bitmap
= c
.disabled_bitmap
;
139 hover_bitmap
= c
.hover_bitmap
;
140 short_help
= c
.short_help
;
141 long_help
= c
.long_help
;
142 sizer_item
= c
.sizer_item
;
143 min_size
= c
.min_size
;
144 spacer_pixels
= c
.spacer_pixels
;
148 proportion
= c
.proportion
;
150 dropdown
= c
.dropdown
;
152 user_data
= c
.user_data
;
156 void SetWindow(wxWindow
* w
) { window
= w
; }
157 wxWindow
* GetWindow() { return window
; }
159 void SetId(int new_id
) { id
= new_id
; }
160 int GetId() const { return id
; }
162 void SetKind(int new_kind
) { kind
= new_kind
; }
163 int GetKind() const { return kind
; }
165 void SetState(int new_state
) { state
= new_state
; }
166 int GetState() const { return state
; }
168 void SetSizerItem(wxSizerItem
* s
) { sizer_item
= s
; }
169 wxSizerItem
* GetSizerItem() const { return sizer_item
; }
171 void SetLabel(const wxString
& s
) { label
= s
; }
172 const wxString
& GetLabel() const { return label
; }
174 void SetBitmap(const wxBitmap
& bmp
) { bitmap
= bmp
; }
175 const wxBitmap
& GetBitmap() const { return bitmap
; }
177 void SetDisabledBitmap(const wxBitmap
& bmp
) { disabled_bitmap
= bmp
; }
178 const wxBitmap
& GetDisabledBitmap() const { return disabled_bitmap
; }
180 void SetHoverBitmap(const wxBitmap
& bmp
) { hover_bitmap
= bmp
; }
181 const wxBitmap
& GetHoverBitmap() const { return hover_bitmap
; }
183 void SetShortHelp(const wxString
& s
) { short_help
= s
; }
184 const wxString
& GetShortHelp() const { return short_help
; }
186 void SetLongHelp(const wxString
& s
) { long_help
= s
; }
187 const wxString
& GetLongHelp() const { return long_help
; }
189 void SetMinSize(const wxSize
& s
) { min_size
= s
; }
190 const wxSize
& GetMinSize() const { return min_size
; }
192 void SetSpacerPixels(int s
) { spacer_pixels
= s
; }
193 int GetSpacerPixels() const { return spacer_pixels
; }
195 void SetProportion(int p
) { proportion
= p
; }
196 int GetProportion() const { return proportion
; }
198 void SetActive(bool b
) { active
= b
; }
199 bool IsActive() const { return active
; }
201 void SetHasDropDown(bool b
) { dropdown
= b
; }
202 bool HasDropDown() const { return dropdown
; }
204 void SetSticky(bool b
) { sticky
= b
; }
205 bool IsSticky() const { return sticky
; }
207 void SetUserData(long l
) { user_data
= l
; }
208 long GetUserData() const { return user_data
; }
212 wxWindow
* window
; // item's associated window
213 wxString label
; // label displayed on the item
214 wxBitmap bitmap
; // item's bitmap
215 wxBitmap disabled_bitmap
; // item's disabled bitmap
216 wxBitmap hover_bitmap
; // item's hover bitmap
217 wxString short_help
; // short help (for tooltip)
218 wxString long_help
; // long help (for status bar)
219 wxSizerItem
* sizer_item
; // sizer item
220 wxSize min_size
; // item's minimum size
221 int spacer_pixels
; // size of a spacer
223 int kind
; // item's kind
225 int proportion
; // proportion
226 bool active
; // true if the item is currently active
227 bool dropdown
; // true if the item has a dropdown button
228 bool sticky
; // overrides button states if true (always active)
229 long user_data
; // user-specified data
233 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
241 class WXDLLIMPEXP_AUI wxAuiToolBarArt
245 wxAuiToolBarArt() { }
246 virtual ~wxAuiToolBarArt() { }
248 virtual wxAuiToolBarArt
* Clone() = 0;
249 virtual void SetFlags(unsigned int flags
) = 0;
250 virtual void SetFont(const wxFont
& font
) = 0;
251 virtual void SetTextOrientation(int orientation
) = 0;
253 virtual void DrawBackground(
256 const wxRect
& rect
) = 0;
258 virtual void DrawLabel(
261 const wxAuiToolBarItem
& item
,
262 const wxRect
& rect
) = 0;
264 virtual void DrawButton(
267 const wxAuiToolBarItem
& item
,
268 const wxRect
& rect
) = 0;
270 virtual void DrawDropDownButton(
273 const wxAuiToolBarItem
& item
,
274 const wxRect
& rect
) = 0;
276 virtual void DrawControlLabel(
279 const wxAuiToolBarItem
& item
,
280 const wxRect
& rect
) = 0;
282 virtual void DrawSeparator(
285 const wxRect
& rect
) = 0;
287 virtual void DrawGripper(
290 const wxRect
& rect
) = 0;
292 virtual void DrawOverflowButton(
298 virtual wxSize
GetLabelSize(
301 const wxAuiToolBarItem
& item
) = 0;
303 virtual wxSize
GetToolSize(
306 const wxAuiToolBarItem
& item
) = 0;
308 virtual int GetElementSize(int element_id
) = 0;
309 virtual void SetElementSize(int element_id
, int size
) = 0;
311 virtual int ShowDropDown(
313 const wxAuiToolBarItemArray
& items
) = 0;
318 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
323 wxAuiDefaultToolBarArt();
324 virtual ~wxAuiDefaultToolBarArt();
326 virtual wxAuiToolBarArt
* Clone();
327 virtual void SetFlags(unsigned int flags
);
328 virtual void SetFont(const wxFont
& font
);
329 virtual void SetTextOrientation(int orientation
);
331 virtual void DrawBackground(
336 virtual void DrawLabel(
339 const wxAuiToolBarItem
& item
,
342 virtual void DrawButton(
345 const wxAuiToolBarItem
& item
,
348 virtual void DrawDropDownButton(
351 const wxAuiToolBarItem
& item
,
354 virtual void DrawControlLabel(
357 const wxAuiToolBarItem
& item
,
360 virtual void DrawSeparator(
365 virtual void DrawGripper(
370 virtual void DrawOverflowButton(
376 virtual wxSize
GetLabelSize(
379 const wxAuiToolBarItem
& item
);
381 virtual wxSize
GetToolSize(
384 const wxAuiToolBarItem
& item
);
386 virtual int GetElementSize(int element
);
387 virtual void SetElementSize(int element_id
, int size
);
389 virtual int ShowDropDown(wxWindow
* wnd
,
390 const wxAuiToolBarItemArray
& items
);
394 wxBitmap m_button_dropdown_bmp
;
395 wxBitmap m_disabled_button_dropdown_bmp
;
396 wxBitmap m_overflow_bmp
;
397 wxBitmap m_disabled_overflow_bmp
;
398 wxColour m_base_colour
;
399 wxColour m_highlight_colour
;
401 unsigned int m_flags
;
402 int m_text_orientation
;
404 wxPen m_gripper_pen1
;
405 wxPen m_gripper_pen2
;
406 wxPen m_gripper_pen3
;
408 int m_separator_size
;
416 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
420 wxAuiToolBar(wxWindow
* parent
,
422 const wxPoint
& position
= wxDefaultPosition
,
423 const wxSize
& size
= wxDefaultSize
,
424 long style
= wxAUI_TB_DEFAULT_STYLE
);
427 void SetWindowStyleFlag(long style
);
429 void SetArtProvider(wxAuiToolBarArt
* art
);
430 wxAuiToolBarArt
* GetArtProvider() const;
432 bool SetFont(const wxFont
& font
);
435 void AddTool(int tool_id
,
436 const wxString
& label
,
437 const wxBitmap
& bitmap
,
438 const wxString
& short_help_string
= wxEmptyString
,
439 wxItemKind kind
= wxITEM_NORMAL
);
441 void AddTool(int tool_id
,
442 const wxString
& label
,
443 const wxBitmap
& bitmap
,
444 const wxBitmap
& disabled_bitmap
,
446 const wxString
& short_help_string
,
447 const wxString
& long_help_string
,
448 wxObject
* client_data
);
450 void AddTool(int tool_id
,
451 const wxBitmap
& bitmap
,
452 const wxBitmap
& disabled_bitmap
,
454 wxObject
* client_data
= NULL
,
455 const wxString
& short_help_string
= wxEmptyString
,
456 const wxString
& long_help_string
= wxEmptyString
)
462 toggle
? wxITEM_CHECK
: wxITEM_NORMAL
,
468 void AddLabel(int tool_id
,
469 const wxString
& label
= wxEmptyString
,
470 const int width
= -1);
471 void AddControl(wxControl
* control
,
472 const wxString
& label
= wxEmptyString
);
474 void AddSpacer(int pixels
);
475 void AddStretchSpacer(int proportion
= 1);
479 wxControl
* FindControl(int window_id
);
480 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
481 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
482 wxAuiToolBarItem
* FindTool(int tool_id
) const;
484 void ClearTools() { Clear() ; }
486 bool DeleteTool(int tool_id
);
487 bool DeleteByIndex(int tool_id
);
489 size_t GetToolCount() const;
490 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
491 int GetToolIndex(int tool_id
) const;
492 bool GetToolFits(int tool_id
) const;
493 wxRect
GetToolRect(int tool_id
) const;
494 bool GetToolFitsByIndex(int tool_id
) const;
495 bool GetToolBarFits() const;
497 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
498 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
499 void SetMargins(int left
, int right
, int top
, int bottom
);
501 void SetToolBitmapSize(const wxSize
& size
);
502 wxSize
GetToolBitmapSize() const;
504 bool GetOverflowVisible() const;
505 void SetOverflowVisible(bool visible
);
507 bool GetGripperVisible() const;
508 void SetGripperVisible(bool visible
);
510 void ToggleTool(int tool_id
, bool state
);
511 bool GetToolToggled(int tool_id
) const;
513 void EnableTool(int tool_id
, bool state
);
514 bool GetToolEnabled(int tool_id
) const;
516 void SetToolDropDown(int tool_id
, bool dropdown
);
517 bool GetToolDropDown(int tool_id
) const;
519 void SetToolBorderPadding(int padding
);
520 int GetToolBorderPadding() const;
522 void SetToolTextOrientation(int orientation
);
523 int GetToolTextOrientation() const;
525 void SetToolPacking(int packing
);
526 int GetToolPacking() const;
528 void SetToolProportion(int tool_id
, int proportion
);
529 int GetToolProportion(int tool_id
) const;
531 void SetToolSeparation(int separation
);
532 int GetToolSeparation() const;
534 void SetToolSticky(int tool_id
, bool sticky
);
535 bool GetToolSticky(int tool_id
) const;
537 wxString
GetToolLabel(int tool_id
) const;
538 void SetToolLabel(int tool_id
, const wxString
& label
);
540 wxBitmap
GetToolBitmap(int tool_id
) const;
541 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
543 wxString
GetToolShortHelp(int tool_id
) const;
544 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
546 wxString
GetToolLongHelp(int tool_id
) const;
547 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
549 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
550 const wxAuiToolBarItemArray
& append
);
554 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
555 const wxAuiToolBarItem
& WXUNUSED(item
),
556 const wxRect
& WXUNUSED(rect
)) { }
561 void SetOrientation(int orientation
);
562 void SetHoverItem(wxAuiToolBarItem
* item
);
563 void SetPressedItem(wxAuiToolBarItem
* item
);
564 void RefreshOverflowState();
566 int GetOverflowState() const;
567 wxRect
GetOverflowRect() const;
568 wxSize
GetLabelSize(const wxString
& label
);
569 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
571 void DoSetSize(int x
,
575 int sizeFlags
= wxSIZE_AUTO
);
577 protected: // handlers
579 void OnSize(wxSizeEvent
& evt
);
580 void OnIdle(wxIdleEvent
& evt
);
581 void OnPaint(wxPaintEvent
& evt
);
582 void OnEraseBackground(wxEraseEvent
& evt
);
583 void OnLeftDown(wxMouseEvent
& evt
);
584 void OnLeftUp(wxMouseEvent
& evt
);
585 void OnRightDown(wxMouseEvent
& evt
);
586 void OnRightUp(wxMouseEvent
& evt
);
587 void OnMiddleDown(wxMouseEvent
& evt
);
588 void OnMiddleUp(wxMouseEvent
& evt
);
589 void OnMotion(wxMouseEvent
& evt
);
590 void OnLeaveWindow(wxMouseEvent
& evt
);
591 void OnSetCursor(wxSetCursorEvent
& evt
);
595 wxAuiToolBarItemArray m_items
; // array of toolbar items
596 wxAuiToolBarArt
* m_art
; // art provider
597 wxBoxSizer
* m_sizer
; // main sizer for toolbar
598 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
599 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
600 wxBitmap m_bitmap
; // double-buffer bitmap
601 wxSizerItem
* m_gripper_sizer_item
;
602 wxSizerItem
* m_overflow_sizer_item
;
603 wxSize m_absolute_min_size
;
604 wxPoint m_action_pos
; // position of left-mouse down
605 wxAuiToolBarItemArray m_custom_overflow_prepend
;
606 wxAuiToolBarItemArray m_custom_overflow_append
;
610 int m_sizer_element_count
;
614 int m_bottom_padding
;
616 int m_tool_border_padding
;
617 int m_tool_text_orientation
;
618 int m_overflow_state
;
620 bool m_gripper_visible
;
621 bool m_overflow_visible
;
624 DECLARE_EVENT_TABLE()
625 DECLARE_CLASS(wxAuiToolBar
)
631 // wx event machinery
635 BEGIN_DECLARE_EVENT_TYPES()
636 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 0)
637 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 0)
638 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 0)
639 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 0)
640 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 0)
641 END_DECLARE_EVENT_TYPES()
643 typedef void (wxEvtHandler::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
645 #define wxAuiToolBarEventHandler(func) \
646 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiToolBarEventFunction, &func)
648 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
649 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
650 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
651 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
652 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
653 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
654 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
655 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
656 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
657 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
661 // wxpython/swig event work
662 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
663 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
664 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
665 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
666 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
669 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
670 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
671 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
672 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
673 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
678 #endif // _WX_AUIBAR_H_