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_TEXT
= ((1 << 6) | wxAUI_TB_TEXT
),
30 wxAUI_TB_DEFAULT_STYLE
= 0
33 enum wxAuiToolBarArtSetting
35 wxAUI_TBART_SEPARATOR_SIZE
= 0,
36 wxAUI_TBART_GRIPPER_SIZE
= 1,
37 wxAUI_TBART_OVERFLOW_SIZE
= 2
40 enum wxAuiToolBarToolTextOrientation
42 wxAUI_TBTOOL_TEXT_LEFT
= 0, // unused/unimplemented
43 wxAUI_TBTOOL_TEXT_RIGHT
= 1,
44 wxAUI_TBTOOL_TEXT_TOP
= 2, // unused/unimplemented
45 wxAUI_TBTOOL_TEXT_BOTTOM
= 3
49 // aui toolbar event class
51 class WXDLLIMPEXP_AUI wxAuiToolBarEvent
: public wxNotifyEvent
54 wxAuiToolBarEvent(wxEventType command_type
= wxEVT_NULL
,
56 : wxNotifyEvent(command_type
, win_id
)
58 is_dropdown_clicked
= false;
59 click_pt
= wxPoint(-1, -1);
60 rect
= wxRect(-1,-1, 0, 0);
64 wxAuiToolBarEvent(const wxAuiToolBarEvent
& c
) : wxNotifyEvent(c
)
66 is_dropdown_clicked
= c
.is_dropdown_clicked
;
67 click_pt
= c
.click_pt
;
72 wxEvent
*Clone() const { return new wxAuiToolBarEvent(*this); }
74 bool IsDropDownClicked() const { return is_dropdown_clicked
; }
75 void SetDropDownClicked(bool c
) { is_dropdown_clicked
= c
; }
77 wxPoint
GetClickPoint() const { return click_pt
; }
78 void SetClickPoint(const wxPoint
& p
) { click_pt
= p
; }
80 wxRect
GetItemRect() const { return rect
; }
81 void SetItemRect(const wxRect
& r
) { rect
= r
; }
83 int GetToolId() const { return tool_id
; }
84 void SetToolId(int id
) { tool_id
= id
; }
88 bool is_dropdown_clicked
;
95 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiToolBarEvent
)
100 class WXDLLIMPEXP_AUI wxAuiToolBarItem
102 friend class wxAuiToolBar
;
112 kind
= wxITEM_NORMAL
;
113 state
= 0; // normal, enabled
121 wxAuiToolBarItem(const wxAuiToolBarItem
& c
)
126 wxAuiToolBarItem
& operator=(const wxAuiToolBarItem
& c
)
132 void Assign(const wxAuiToolBarItem
& c
)
137 disabled_bitmap
= c
.disabled_bitmap
;
138 hover_bitmap
= c
.hover_bitmap
;
139 short_help
= c
.short_help
;
140 long_help
= c
.long_help
;
141 sizer_item
= c
.sizer_item
;
142 min_size
= c
.min_size
;
143 spacer_pixels
= c
.spacer_pixels
;
147 proportion
= c
.proportion
;
149 dropdown
= c
.dropdown
;
151 user_data
= c
.user_data
;
155 wxWindow
* GetWindow() { return window
; }
156 int GetId() const { return id
; }
157 int GetKind() const { return kind
; }
158 int GetState() const { return state
; }
159 wxSizerItem
* GetSizerItem() const { return sizer_item
; }
161 void SetLabel(const wxString
& s
) { label
= s
; }
162 const wxString
& GetLabel() const { return label
; }
164 void SetBitmap(const wxBitmap
& bmp
) { bitmap
= bmp
; }
165 const wxBitmap
& GetBitmap() const { return bitmap
; }
167 void SetDisabledBitmap(const wxBitmap
& bmp
) { disabled_bitmap
= bmp
; }
168 const wxBitmap
& GetDisabledBitmap() const { return disabled_bitmap
; }
170 void SetHoverBitmap(const wxBitmap
& bmp
) { hover_bitmap
= bmp
; }
171 const wxBitmap
& GetHoverBitmap() const { return hover_bitmap
; }
173 void SetShortHelp(const wxString
& s
) { short_help
= s
; }
174 const wxString
& GetShortHelp() const { return short_help
; }
176 void SetLongHelp(const wxString
& s
) { long_help
= s
; }
177 const wxString
& GetLongHelp() const { return long_help
; }
179 void SetMinSize(const wxSize
& s
) { min_size
= s
; }
180 const wxSize
& GetMinSize() const { return min_size
; }
182 void SetSpacerPixels(int s
) { spacer_pixels
= s
; }
183 int GetSpacerPixels() const { return spacer_pixels
; }
185 void SetProportion(int p
) { proportion
= p
; }
186 int GetProportion() const { return proportion
; }
188 void SetActive(bool b
) { active
= b
; }
189 bool IsActive() const { return active
; }
191 void SetHasDropDown(bool b
) { dropdown
= b
; }
192 bool HasDropDown() const { return dropdown
; }
194 void SetSticky(bool b
) { sticky
= b
; }
195 bool IsSticky() const { return sticky
; }
197 void SetUserData(long l
) { user_data
= l
; }
198 long GetUserData() const { return user_data
; }
202 wxWindow
* window
; // item's associated window
203 wxString label
; // label displayed on the item
204 wxBitmap bitmap
; // item's bitmap
205 wxBitmap disabled_bitmap
; // item's disabled bitmap
206 wxBitmap hover_bitmap
; // item's hover bitmap
207 wxString short_help
; // short help (for tooltip)
208 wxString long_help
; // long help (for status bar)
209 wxSizerItem
* sizer_item
; // sizer item
210 wxSize min_size
; // item's minimum size
211 int spacer_pixels
; // size of a spacer
213 int kind
; // item's kind
215 int proportion
; // proportion
216 bool active
; // true if the item is currently active
217 bool dropdown
; // true if the item has a dropdown button
218 bool sticky
; // overrides button states if true (always active)
219 long user_data
; // user-specified data
223 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
231 class WXDLLIMPEXP_AUI wxAuiToolBarArt
235 wxAuiToolBarArt() { }
236 virtual ~wxAuiToolBarArt() { }
238 virtual wxAuiToolBarArt
* Clone() = 0;
239 virtual void SetFlags(unsigned int flags
) = 0;
240 virtual void SetFont(const wxFont
& font
) = 0;
241 virtual void SetTextOrientation(int orientation
) = 0;
243 virtual void DrawBackground(
246 const wxRect
& rect
) = 0;
248 virtual void DrawLabel(
251 const wxAuiToolBarItem
& item
,
252 const wxRect
& rect
) = 0;
254 virtual void DrawButton(
257 const wxAuiToolBarItem
& item
,
258 const wxRect
& rect
) = 0;
260 virtual void DrawDropDownButton(
263 const wxAuiToolBarItem
& item
,
264 const wxRect
& rect
) = 0;
266 virtual void DrawControlLabel(
269 const wxAuiToolBarItem
& item
,
270 const wxRect
& rect
) = 0;
272 virtual void DrawSeparator(
275 const wxRect
& rect
) = 0;
277 virtual void DrawGripper(
280 const wxRect
& rect
) = 0;
282 virtual void DrawOverflowButton(
288 virtual wxSize
GetLabelSize(
291 const wxAuiToolBarItem
& item
) = 0;
293 virtual wxSize
GetToolSize(
296 const wxAuiToolBarItem
& item
) = 0;
298 virtual int GetElementSize(int element_id
) = 0;
299 virtual void SetElementSize(int element_id
, int size
) = 0;
301 virtual int ShowDropDown(
303 const wxAuiToolBarItemArray
& items
) = 0;
308 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
313 wxAuiDefaultToolBarArt();
314 virtual ~wxAuiDefaultToolBarArt();
316 virtual wxAuiToolBarArt
* Clone();
317 virtual void SetFlags(unsigned int flags
);
318 virtual void SetFont(const wxFont
& font
);
319 virtual void SetTextOrientation(int orientation
);
321 virtual void DrawBackground(
326 virtual void DrawLabel(
329 const wxAuiToolBarItem
& item
,
332 virtual void DrawButton(
335 const wxAuiToolBarItem
& item
,
338 virtual void DrawDropDownButton(
341 const wxAuiToolBarItem
& item
,
344 virtual void DrawControlLabel(
347 const wxAuiToolBarItem
& item
,
350 virtual void DrawSeparator(
355 virtual void DrawGripper(
360 virtual void DrawOverflowButton(
366 virtual wxSize
GetLabelSize(
369 const wxAuiToolBarItem
& item
);
371 virtual wxSize
GetToolSize(
374 const wxAuiToolBarItem
& item
);
376 virtual int GetElementSize(int element
);
377 virtual void SetElementSize(int element_id
, int size
);
379 virtual int ShowDropDown(wxWindow
* wnd
,
380 const wxAuiToolBarItemArray
& items
);
384 wxBitmap m_button_dropdown_bmp
;
385 wxBitmap m_disabled_button_dropdown_bmp
;
386 wxBitmap m_overflow_bmp
;
387 wxBitmap m_disabled_overflow_bmp
;
388 wxColour m_base_colour
;
389 wxColour m_highlight_colour
;
391 unsigned int m_flags
;
392 int m_text_orientation
;
394 wxPen m_gripper_pen1
;
395 wxPen m_gripper_pen2
;
396 wxPen m_gripper_pen3
;
398 int m_separator_size
;
406 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
410 wxAuiToolBar(wxWindow
* parent
,
412 const wxPoint
& position
= wxDefaultPosition
,
413 const wxSize
& size
= wxDefaultSize
,
414 long style
= wxAUI_TB_DEFAULT_STYLE
);
417 void SetWindowStyleFlag(long style
);
419 void SetArtProvider(wxAuiToolBarArt
* art
);
420 wxAuiToolBarArt
* GetArtProvider() const;
422 bool SetFont(const wxFont
& font
);
425 void AddTool(int tool_id
,
426 const wxString
& label
,
427 const wxBitmap
& bitmap
,
428 const wxString
& short_help_string
= wxEmptyString
,
429 wxItemKind kind
= wxITEM_NORMAL
);
431 void AddTool(int tool_id
,
432 const wxString
& label
,
433 const wxBitmap
& bitmap
,
434 const wxBitmap
& disabled_bitmap
,
436 const wxString
& short_help_string
,
437 const wxString
& long_help_string
,
438 wxObject
* client_data
);
440 void AddTool(int tool_id
,
441 const wxBitmap
& bitmap
,
442 const wxBitmap
& disabled_bitmap
,
444 wxObject
* client_data
= NULL
,
445 const wxString
& short_help_string
= wxEmptyString
,
446 const wxString
& long_help_string
= wxEmptyString
)
452 toggle
? wxITEM_CHECK
: wxITEM_NORMAL
,
458 void AddLabel(int tool_id
,
459 const wxString
& label
= wxEmptyString
,
460 const int width
= -1);
461 void AddControl(wxControl
* control
,
462 const wxString
& label
= wxEmptyString
);
464 void AddSpacer(int pixels
);
465 void AddStretchSpacer(int proportion
= 1);
469 wxControl
* FindControl(int window_id
);
470 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
471 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
472 wxAuiToolBarItem
* FindTool(int tool_id
) const;
474 void ClearTools() { Clear() ; }
476 bool DeleteTool(int tool_id
);
477 bool DeleteByIndex(int tool_id
);
479 size_t GetToolCount() const;
480 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
481 int GetToolIndex(int tool_id
) const;
482 bool GetToolFits(int tool_id
) const;
483 wxRect
GetToolRect(int tool_id
) const;
484 bool GetToolFitsByIndex(int tool_id
) const;
485 bool GetToolBarFits() const;
487 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
488 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
489 void SetMargins(int left
, int right
, int top
, int bottom
);
491 void SetToolBitmapSize(const wxSize
& size
);
492 wxSize
GetToolBitmapSize() const;
494 bool GetOverflowVisible() const;
495 void SetOverflowVisible(bool visible
);
497 bool GetGripperVisible() const;
498 void SetGripperVisible(bool visible
);
500 void ToggleTool(int tool_id
, bool state
);
501 bool GetToolToggled(int tool_id
) const;
503 void EnableTool(int tool_id
, bool state
);
504 bool GetToolEnabled(int tool_id
) const;
506 void SetToolDropDown(int tool_id
, bool dropdown
);
507 bool GetToolDropDown(int tool_id
) const;
509 void SetToolBorderPadding(int padding
);
510 int GetToolBorderPadding() const;
512 void SetToolTextOrientation(int orientation
);
513 int GetToolTextOrientation() const;
515 void SetToolPacking(int packing
);
516 int GetToolPacking() const;
518 void SetToolProportion(int tool_id
, int proportion
);
519 int GetToolProportion(int tool_id
) const;
521 void SetToolSeparation(int separation
);
522 int GetToolSeparation() const;
524 void SetToolSticky(int tool_id
, bool sticky
);
525 bool GetToolSticky(int tool_id
) const;
527 wxString
GetToolLabel(int tool_id
) const;
528 void SetToolLabel(int tool_id
, const wxString
& label
);
530 wxBitmap
GetToolBitmap(int tool_id
) const;
531 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
533 wxString
GetToolShortHelp(int tool_id
) const;
534 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
536 wxString
GetToolLongHelp(int tool_id
) const;
537 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
539 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
540 const wxAuiToolBarItemArray
& append
);
544 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
545 const wxAuiToolBarItem
& WXUNUSED(item
),
546 const wxRect
& WXUNUSED(rect
)) { }
551 void SetOrientation(int orientation
);
552 void SetHoverItem(wxAuiToolBarItem
* item
);
553 void SetPressedItem(wxAuiToolBarItem
* item
);
554 void RefreshOverflowState();
556 int GetOverflowState() const;
557 wxRect
GetOverflowRect() const;
558 wxSize
GetLabelSize(const wxString
& label
);
559 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
561 void DoSetSize(int x
,
565 int sizeFlags
= wxSIZE_AUTO
);
567 protected: // handlers
569 void OnSize(wxSizeEvent
& evt
);
570 void OnIdle(wxIdleEvent
& evt
);
571 void OnPaint(wxPaintEvent
& evt
);
572 void OnEraseBackground(wxEraseEvent
& evt
);
573 void OnLeftDown(wxMouseEvent
& evt
);
574 void OnLeftUp(wxMouseEvent
& evt
);
575 void OnRightDown(wxMouseEvent
& evt
);
576 void OnRightUp(wxMouseEvent
& evt
);
577 void OnMiddleDown(wxMouseEvent
& evt
);
578 void OnMiddleUp(wxMouseEvent
& evt
);
579 void OnMotion(wxMouseEvent
& evt
);
580 void OnLeaveWindow(wxMouseEvent
& evt
);
581 void OnSetCursor(wxSetCursorEvent
& evt
);
585 wxAuiToolBarItemArray m_items
; // array of toolbar items
586 wxAuiToolBarArt
* m_art
; // art provider
587 wxBoxSizer
* m_sizer
; // main sizer for toolbar
588 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
589 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
590 wxBitmap m_bitmap
; // double-buffer bitmap
591 wxSizerItem
* m_gripper_sizer_item
;
592 wxSizerItem
* m_overflow_sizer_item
;
593 wxSize m_absolute_min_size
;
594 wxPoint m_action_pos
; // position of left-mouse down
595 wxAuiToolBarItemArray m_custom_overflow_prepend
;
596 wxAuiToolBarItemArray m_custom_overflow_append
;
600 int m_sizer_element_count
;
604 int m_bottom_padding
;
606 int m_tool_border_padding
;
607 int m_tool_text_orientation
;
608 int m_overflow_state
;
610 bool m_gripper_visible
;
611 bool m_overflow_visible
;
614 DECLARE_EVENT_TABLE()
615 DECLARE_CLASS(wxAuiToolBar
)
621 // wx event machinery
625 BEGIN_DECLARE_EVENT_TYPES()
626 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 0)
627 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 0)
628 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 0)
629 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 0)
630 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 0)
631 END_DECLARE_EVENT_TYPES()
633 typedef void (wxEvtHandler::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
635 #define wxAuiToolBarEventHandler(func) \
636 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiToolBarEventFunction, &func)
638 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
639 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
640 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
641 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
642 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
643 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
644 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
645 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
646 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
647 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
651 // wxpython/swig event work
652 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
653 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
654 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
655 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
656 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
659 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
660 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
661 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
662 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
663 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
668 #endif // _WX_AUIBAR_H_