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
122 alignment
= wxALIGN_CENTER
;
125 wxAuiToolBarItem(const wxAuiToolBarItem
& c
)
130 wxAuiToolBarItem
& operator=(const wxAuiToolBarItem
& c
)
136 void Assign(const wxAuiToolBarItem
& c
)
141 disabled_bitmap
= c
.disabled_bitmap
;
142 hover_bitmap
= c
.hover_bitmap
;
143 short_help
= c
.short_help
;
144 long_help
= c
.long_help
;
145 sizer_item
= c
.sizer_item
;
146 min_size
= c
.min_size
;
147 spacer_pixels
= c
.spacer_pixels
;
151 proportion
= c
.proportion
;
153 dropdown
= c
.dropdown
;
155 user_data
= c
.user_data
;
156 alignment
= c
.alignment
;
160 void SetWindow(wxWindow
* w
) { window
= w
; }
161 wxWindow
* GetWindow() { return window
; }
163 void SetId(int new_id
) { id
= new_id
; }
164 int GetId() const { return id
; }
166 void SetKind(int new_kind
) { kind
= new_kind
; }
167 int GetKind() const { return kind
; }
169 void SetState(int new_state
) { state
= new_state
; }
170 int GetState() const { return state
; }
172 void SetSizerItem(wxSizerItem
* s
) { sizer_item
= s
; }
173 wxSizerItem
* GetSizerItem() const { return sizer_item
; }
175 void SetLabel(const wxString
& s
) { label
= s
; }
176 const wxString
& GetLabel() const { return label
; }
178 void SetBitmap(const wxBitmap
& bmp
) { bitmap
= bmp
; }
179 const wxBitmap
& GetBitmap() const { return bitmap
; }
181 void SetDisabledBitmap(const wxBitmap
& bmp
) { disabled_bitmap
= bmp
; }
182 const wxBitmap
& GetDisabledBitmap() const { return disabled_bitmap
; }
184 void SetHoverBitmap(const wxBitmap
& bmp
) { hover_bitmap
= bmp
; }
185 const wxBitmap
& GetHoverBitmap() const { return hover_bitmap
; }
187 void SetShortHelp(const wxString
& s
) { short_help
= s
; }
188 const wxString
& GetShortHelp() const { return short_help
; }
190 void SetLongHelp(const wxString
& s
) { long_help
= s
; }
191 const wxString
& GetLongHelp() const { return long_help
; }
193 void SetMinSize(const wxSize
& s
) { min_size
= s
; }
194 const wxSize
& GetMinSize() const { return min_size
; }
196 void SetSpacerPixels(int s
) { spacer_pixels
= s
; }
197 int GetSpacerPixels() const { return spacer_pixels
; }
199 void SetProportion(int p
) { proportion
= p
; }
200 int GetProportion() const { return proportion
; }
202 void SetActive(bool b
) { active
= b
; }
203 bool IsActive() const { return active
; }
205 void SetHasDropDown(bool b
) { dropdown
= b
; }
206 bool HasDropDown() const { return dropdown
; }
208 void SetSticky(bool b
) { sticky
= b
; }
209 bool IsSticky() const { return sticky
; }
211 void SetUserData(long l
) { user_data
= l
; }
212 long GetUserData() const { return user_data
; }
214 void SetAlignment(int l
) { alignment
= l
; }
215 int GetAlignment() const { return alignment
; }
219 wxWindow
* window
; // item's associated window
220 wxString label
; // label displayed on the item
221 wxBitmap bitmap
; // item's bitmap
222 wxBitmap disabled_bitmap
; // item's disabled bitmap
223 wxBitmap hover_bitmap
; // item's hover bitmap
224 wxString short_help
; // short help (for tooltip)
225 wxString long_help
; // long help (for status bar)
226 wxSizerItem
* sizer_item
; // sizer item
227 wxSize min_size
; // item's minimum size
228 int spacer_pixels
; // size of a spacer
230 int kind
; // item's kind
232 int proportion
; // proportion
233 bool active
; // true if the item is currently active
234 bool dropdown
; // true if the item has a dropdown button
235 bool sticky
; // overrides button states if true (always active)
236 long user_data
; // user-specified data
237 int alignment
; // sizer alignment flag, defaults to wxCENTER, may be wxEXPAND or any other
241 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
249 class WXDLLIMPEXP_AUI wxAuiToolBarArt
253 wxAuiToolBarArt() { }
254 virtual ~wxAuiToolBarArt() { }
256 virtual wxAuiToolBarArt
* Clone() = 0;
257 virtual void SetFlags(unsigned int flags
) = 0;
258 virtual unsigned int GetFlags() = 0;
259 virtual void SetFont(const wxFont
& font
) = 0;
260 virtual wxFont
GetFont() = 0;
261 virtual void SetTextOrientation(int orientation
) = 0;
262 virtual int GetTextOrientation() = 0;
264 virtual void DrawBackground(
267 const wxRect
& rect
) = 0;
269 virtual void DrawLabel(
272 const wxAuiToolBarItem
& item
,
273 const wxRect
& rect
) = 0;
275 virtual void DrawButton(
278 const wxAuiToolBarItem
& item
,
279 const wxRect
& rect
) = 0;
281 virtual void DrawDropDownButton(
284 const wxAuiToolBarItem
& item
,
285 const wxRect
& rect
) = 0;
287 virtual void DrawControlLabel(
290 const wxAuiToolBarItem
& item
,
291 const wxRect
& rect
) = 0;
293 virtual void DrawSeparator(
296 const wxRect
& rect
) = 0;
298 virtual void DrawGripper(
301 const wxRect
& rect
) = 0;
303 virtual void DrawOverflowButton(
309 virtual wxSize
GetLabelSize(
312 const wxAuiToolBarItem
& item
) = 0;
314 virtual wxSize
GetToolSize(
317 const wxAuiToolBarItem
& item
) = 0;
319 virtual int GetElementSize(int element_id
) = 0;
320 virtual void SetElementSize(int element_id
, int size
) = 0;
322 virtual int ShowDropDown(
324 const wxAuiToolBarItemArray
& items
) = 0;
329 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
334 wxAuiDefaultToolBarArt();
335 virtual ~wxAuiDefaultToolBarArt();
337 virtual wxAuiToolBarArt
* Clone();
338 virtual void SetFlags(unsigned int flags
);
339 virtual unsigned int GetFlags();
340 virtual void SetFont(const wxFont
& font
);
341 virtual wxFont
GetFont();
342 virtual void SetTextOrientation(int orientation
);
343 virtual int GetTextOrientation();
345 virtual void DrawBackground(
350 virtual void DrawLabel(
353 const wxAuiToolBarItem
& item
,
356 virtual void DrawButton(
359 const wxAuiToolBarItem
& item
,
362 virtual void DrawDropDownButton(
365 const wxAuiToolBarItem
& item
,
368 virtual void DrawControlLabel(
371 const wxAuiToolBarItem
& item
,
374 virtual void DrawSeparator(
379 virtual void DrawGripper(
384 virtual void DrawOverflowButton(
390 virtual wxSize
GetLabelSize(
393 const wxAuiToolBarItem
& item
);
395 virtual wxSize
GetToolSize(
398 const wxAuiToolBarItem
& item
);
400 virtual int GetElementSize(int element
);
401 virtual void SetElementSize(int element_id
, int size
);
403 virtual int ShowDropDown(wxWindow
* wnd
,
404 const wxAuiToolBarItemArray
& items
);
408 wxBitmap m_button_dropdown_bmp
;
409 wxBitmap m_disabled_button_dropdown_bmp
;
410 wxBitmap m_overflow_bmp
;
411 wxBitmap m_disabled_overflow_bmp
;
412 wxColour m_base_colour
;
413 wxColour m_highlight_colour
;
415 unsigned int m_flags
;
416 int m_text_orientation
;
418 wxPen m_gripper_pen1
;
419 wxPen m_gripper_pen2
;
420 wxPen m_gripper_pen3
;
422 int m_separator_size
;
430 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
434 wxAuiToolBar(wxWindow
* parent
,
436 const wxPoint
& position
= wxDefaultPosition
,
437 const wxSize
& size
= wxDefaultSize
,
438 long style
= wxAUI_TB_DEFAULT_STYLE
);
439 virtual ~wxAuiToolBar();
441 void SetWindowStyleFlag(long style
);
442 long GetWindowStyleFlag() const;
444 void SetArtProvider(wxAuiToolBarArt
* art
);
445 wxAuiToolBarArt
* GetArtProvider() const;
447 bool SetFont(const wxFont
& font
);
450 wxAuiToolBarItem
* AddTool(int tool_id
,
451 const wxString
& label
,
452 const wxBitmap
& bitmap
,
453 const wxString
& short_help_string
= wxEmptyString
,
454 wxItemKind kind
= wxITEM_NORMAL
);
456 wxAuiToolBarItem
* AddTool(int tool_id
,
457 const wxString
& label
,
458 const wxBitmap
& bitmap
,
459 const wxBitmap
& disabled_bitmap
,
461 const wxString
& short_help_string
,
462 const wxString
& long_help_string
,
463 wxObject
* client_data
);
465 wxAuiToolBarItem
* AddTool(int tool_id
,
466 const wxBitmap
& bitmap
,
467 const wxBitmap
& disabled_bitmap
,
469 wxObject
* client_data
= NULL
,
470 const wxString
& short_help_string
= wxEmptyString
,
471 const wxString
& long_help_string
= wxEmptyString
)
473 return AddTool(tool_id
,
477 toggle
? wxITEM_CHECK
: wxITEM_NORMAL
,
483 wxAuiToolBarItem
* AddLabel(int tool_id
,
484 const wxString
& label
= wxEmptyString
,
485 const int width
= -1);
486 wxAuiToolBarItem
* AddControl(wxControl
* control
,
487 const wxString
& label
= wxEmptyString
);
488 wxAuiToolBarItem
* AddSeparator();
489 wxAuiToolBarItem
* AddSpacer(int pixels
);
490 wxAuiToolBarItem
* AddStretchSpacer(int proportion
= 1);
494 wxControl
* FindControl(int window_id
);
495 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
496 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
497 wxAuiToolBarItem
* FindTool(int tool_id
) const;
499 void ClearTools() { Clear() ; }
501 bool DeleteTool(int tool_id
);
502 bool DeleteByIndex(int tool_id
);
504 size_t GetToolCount() const;
505 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
506 int GetToolIndex(int tool_id
) const;
507 bool GetToolFits(int tool_id
) const;
508 wxRect
GetToolRect(int tool_id
) const;
509 bool GetToolFitsByIndex(int tool_id
) const;
510 bool GetToolBarFits() const;
512 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
513 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
514 void SetMargins(int left
, int right
, int top
, int bottom
);
516 void SetToolBitmapSize(const wxSize
& size
);
517 wxSize
GetToolBitmapSize() const;
519 bool GetOverflowVisible() const;
520 void SetOverflowVisible(bool visible
);
522 bool GetGripperVisible() const;
523 void SetGripperVisible(bool visible
);
525 void ToggleTool(int tool_id
, bool state
);
526 bool GetToolToggled(int tool_id
) const;
528 void EnableTool(int tool_id
, bool state
);
529 bool GetToolEnabled(int tool_id
) const;
531 void SetToolDropDown(int tool_id
, bool dropdown
);
532 bool GetToolDropDown(int tool_id
) const;
534 void SetToolBorderPadding(int padding
);
535 int GetToolBorderPadding() const;
537 void SetToolTextOrientation(int orientation
);
538 int GetToolTextOrientation() const;
540 void SetToolPacking(int packing
);
541 int GetToolPacking() const;
543 void SetToolProportion(int tool_id
, int proportion
);
544 int GetToolProportion(int tool_id
) const;
546 void SetToolSeparation(int separation
);
547 int GetToolSeparation() const;
549 void SetToolSticky(int tool_id
, bool sticky
);
550 bool GetToolSticky(int tool_id
) const;
552 wxString
GetToolLabel(int tool_id
) const;
553 void SetToolLabel(int tool_id
, const wxString
& label
);
555 wxBitmap
GetToolBitmap(int tool_id
) const;
556 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
558 wxString
GetToolShortHelp(int tool_id
) const;
559 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
561 wxString
GetToolLongHelp(int tool_id
) const;
562 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
564 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
565 const wxAuiToolBarItemArray
& append
);
569 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
570 const wxAuiToolBarItem
& WXUNUSED(item
),
571 const wxRect
& WXUNUSED(rect
)) { }
576 void SetOrientation(int orientation
);
577 void SetHoverItem(wxAuiToolBarItem
* item
);
578 void SetPressedItem(wxAuiToolBarItem
* item
);
579 void RefreshOverflowState();
581 int GetOverflowState() const;
582 wxRect
GetOverflowRect() const;
583 wxSize
GetLabelSize(const wxString
& label
);
584 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
586 void DoSetSize(int x
,
590 int sizeFlags
= wxSIZE_AUTO
);
592 protected: // handlers
594 void OnSize(wxSizeEvent
& evt
);
595 void OnIdle(wxIdleEvent
& evt
);
596 void OnPaint(wxPaintEvent
& evt
);
597 void OnEraseBackground(wxEraseEvent
& evt
);
598 void OnLeftDown(wxMouseEvent
& evt
);
599 void OnLeftUp(wxMouseEvent
& evt
);
600 void OnRightDown(wxMouseEvent
& evt
);
601 void OnRightUp(wxMouseEvent
& evt
);
602 void OnMiddleDown(wxMouseEvent
& evt
);
603 void OnMiddleUp(wxMouseEvent
& evt
);
604 void OnMotion(wxMouseEvent
& evt
);
605 void OnLeaveWindow(wxMouseEvent
& evt
);
606 void OnSetCursor(wxSetCursorEvent
& evt
);
610 wxAuiToolBarItemArray m_items
; // array of toolbar items
611 wxAuiToolBarArt
* m_art
; // art provider
612 wxBoxSizer
* m_sizer
; // main sizer for toolbar
613 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
614 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
615 wxBitmap m_bitmap
; // double-buffer bitmap
616 wxSizerItem
* m_gripper_sizer_item
;
617 wxSizerItem
* m_overflow_sizer_item
;
618 wxSize m_absolute_min_size
;
619 wxPoint m_action_pos
; // position of left-mouse down
620 wxAuiToolBarItemArray m_custom_overflow_prepend
;
621 wxAuiToolBarItemArray m_custom_overflow_append
;
625 int m_sizer_element_count
;
629 int m_bottom_padding
;
631 int m_tool_border_padding
;
632 int m_tool_text_orientation
;
633 int m_overflow_state
;
635 bool m_gripper_visible
;
636 bool m_overflow_visible
;
639 DECLARE_EVENT_TABLE()
640 DECLARE_CLASS(wxAuiToolBar
)
646 // wx event machinery
650 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, wxAuiToolBarEvent
);
651 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, wxAuiToolBarEvent
);
652 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, wxAuiToolBarEvent
);
653 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, wxAuiToolBarEvent
);
654 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, wxAuiToolBarEvent
);
656 typedef void (wxEvtHandler::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
658 #define wxAuiToolBarEventHandler(func) \
659 wxEVENT_HANDLER_CAST(wxAuiToolBarEventFunction, func)
661 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
662 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
663 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
664 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
665 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
666 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
667 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
668 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
669 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
670 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
674 // wxpython/swig event work
675 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
676 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
677 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
678 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
679 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
682 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
683 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
684 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
685 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
686 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
691 #endif // _WX_AUIBAR_H_