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 wxWindow
* GetWindow() { return window
; }
157 int GetId() const { return id
; }
158 int GetKind() const { return kind
; }
159 int GetState() const { return state
; }
160 wxSizerItem
* GetSizerItem() const { return sizer_item
; }
162 void SetLabel(const wxString
& s
) { label
= s
; }
163 const wxString
& GetLabel() const { return label
; }
165 void SetBitmap(const wxBitmap
& bmp
) { bitmap
= bmp
; }
166 const wxBitmap
& GetBitmap() const { return bitmap
; }
168 void SetDisabledBitmap(const wxBitmap
& bmp
) { disabled_bitmap
= bmp
; }
169 const wxBitmap
& GetDisabledBitmap() const { return disabled_bitmap
; }
171 void SetHoverBitmap(const wxBitmap
& bmp
) { hover_bitmap
= bmp
; }
172 const wxBitmap
& GetHoverBitmap() const { return hover_bitmap
; }
174 void SetShortHelp(const wxString
& s
) { short_help
= s
; }
175 const wxString
& GetShortHelp() const { return short_help
; }
177 void SetLongHelp(const wxString
& s
) { long_help
= s
; }
178 const wxString
& GetLongHelp() const { return long_help
; }
180 void SetMinSize(const wxSize
& s
) { min_size
= s
; }
181 const wxSize
& GetMinSize() const { return min_size
; }
183 void SetSpacerPixels(int s
) { spacer_pixels
= s
; }
184 int GetSpacerPixels() const { return spacer_pixels
; }
186 void SetProportion(int p
) { proportion
= p
; }
187 int GetProportion() const { return proportion
; }
189 void SetActive(bool b
) { active
= b
; }
190 bool IsActive() const { return active
; }
192 void SetHasDropDown(bool b
) { dropdown
= b
; }
193 bool HasDropDown() const { return dropdown
; }
195 void SetSticky(bool b
) { sticky
= b
; }
196 bool IsSticky() const { return sticky
; }
198 void SetUserData(long l
) { user_data
= l
; }
199 long GetUserData() const { return user_data
; }
203 wxWindow
* window
; // item's associated window
204 wxString label
; // label displayed on the item
205 wxBitmap bitmap
; // item's bitmap
206 wxBitmap disabled_bitmap
; // item's disabled bitmap
207 wxBitmap hover_bitmap
; // item's hover bitmap
208 wxString short_help
; // short help (for tooltip)
209 wxString long_help
; // long help (for status bar)
210 wxSizerItem
* sizer_item
; // sizer item
211 wxSize min_size
; // item's minimum size
212 int spacer_pixels
; // size of a spacer
214 int kind
; // item's kind
216 int proportion
; // proportion
217 bool active
; // true if the item is currently active
218 bool dropdown
; // true if the item has a dropdown button
219 bool sticky
; // overrides button states if true (always active)
220 long user_data
; // user-specified data
224 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
232 class WXDLLIMPEXP_AUI wxAuiToolBarArt
236 wxAuiToolBarArt() { }
237 virtual ~wxAuiToolBarArt() { }
239 virtual wxAuiToolBarArt
* Clone() = 0;
240 virtual void SetFlags(unsigned int flags
) = 0;
241 virtual void SetFont(const wxFont
& font
) = 0;
242 virtual void SetTextOrientation(int orientation
) = 0;
244 virtual void DrawBackground(
247 const wxRect
& rect
) = 0;
249 virtual void DrawLabel(
252 const wxAuiToolBarItem
& item
,
253 const wxRect
& rect
) = 0;
255 virtual void DrawButton(
258 const wxAuiToolBarItem
& item
,
259 const wxRect
& rect
) = 0;
261 virtual void DrawDropDownButton(
264 const wxAuiToolBarItem
& item
,
265 const wxRect
& rect
) = 0;
267 virtual void DrawControlLabel(
270 const wxAuiToolBarItem
& item
,
271 const wxRect
& rect
) = 0;
273 virtual void DrawSeparator(
276 const wxRect
& rect
) = 0;
278 virtual void DrawGripper(
281 const wxRect
& rect
) = 0;
283 virtual void DrawOverflowButton(
289 virtual wxSize
GetLabelSize(
292 const wxAuiToolBarItem
& item
) = 0;
294 virtual wxSize
GetToolSize(
297 const wxAuiToolBarItem
& item
) = 0;
299 virtual int GetElementSize(int element_id
) = 0;
300 virtual void SetElementSize(int element_id
, int size
) = 0;
302 virtual int ShowDropDown(
304 const wxAuiToolBarItemArray
& items
) = 0;
309 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
314 wxAuiDefaultToolBarArt();
315 virtual ~wxAuiDefaultToolBarArt();
317 virtual wxAuiToolBarArt
* Clone();
318 virtual void SetFlags(unsigned int flags
);
319 virtual void SetFont(const wxFont
& font
);
320 virtual void SetTextOrientation(int orientation
);
322 virtual void DrawBackground(
327 virtual void DrawLabel(
330 const wxAuiToolBarItem
& item
,
333 virtual void DrawButton(
336 const wxAuiToolBarItem
& item
,
339 virtual void DrawDropDownButton(
342 const wxAuiToolBarItem
& item
,
345 virtual void DrawControlLabel(
348 const wxAuiToolBarItem
& item
,
351 virtual void DrawSeparator(
356 virtual void DrawGripper(
361 virtual void DrawOverflowButton(
367 virtual wxSize
GetLabelSize(
370 const wxAuiToolBarItem
& item
);
372 virtual wxSize
GetToolSize(
375 const wxAuiToolBarItem
& item
);
377 virtual int GetElementSize(int element
);
378 virtual void SetElementSize(int element_id
, int size
);
380 virtual int ShowDropDown(wxWindow
* wnd
,
381 const wxAuiToolBarItemArray
& items
);
385 wxBitmap m_button_dropdown_bmp
;
386 wxBitmap m_disabled_button_dropdown_bmp
;
387 wxBitmap m_overflow_bmp
;
388 wxBitmap m_disabled_overflow_bmp
;
389 wxColour m_base_colour
;
390 wxColour m_highlight_colour
;
392 unsigned int m_flags
;
393 int m_text_orientation
;
395 wxPen m_gripper_pen1
;
396 wxPen m_gripper_pen2
;
397 wxPen m_gripper_pen3
;
399 int m_separator_size
;
407 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
411 wxAuiToolBar(wxWindow
* parent
,
413 const wxPoint
& position
= wxDefaultPosition
,
414 const wxSize
& size
= wxDefaultSize
,
415 long style
= wxAUI_TB_DEFAULT_STYLE
);
418 void SetWindowStyleFlag(long style
);
420 void SetArtProvider(wxAuiToolBarArt
* art
);
421 wxAuiToolBarArt
* GetArtProvider() const;
423 bool SetFont(const wxFont
& font
);
426 void AddTool(int tool_id
,
427 const wxString
& label
,
428 const wxBitmap
& bitmap
,
429 const wxString
& short_help_string
= wxEmptyString
,
430 wxItemKind kind
= wxITEM_NORMAL
);
432 void AddTool(int tool_id
,
433 const wxString
& label
,
434 const wxBitmap
& bitmap
,
435 const wxBitmap
& disabled_bitmap
,
437 const wxString
& short_help_string
,
438 const wxString
& long_help_string
,
439 wxObject
* client_data
);
441 void AddTool(int tool_id
,
442 const wxBitmap
& bitmap
,
443 const wxBitmap
& disabled_bitmap
,
445 wxObject
* client_data
= NULL
,
446 const wxString
& short_help_string
= wxEmptyString
,
447 const wxString
& long_help_string
= wxEmptyString
)
453 toggle
? wxITEM_CHECK
: wxITEM_NORMAL
,
459 void AddLabel(int tool_id
,
460 const wxString
& label
= wxEmptyString
,
461 const int width
= -1);
462 void AddControl(wxControl
* control
,
463 const wxString
& label
= wxEmptyString
);
465 void AddSpacer(int pixels
);
466 void AddStretchSpacer(int proportion
= 1);
470 wxControl
* FindControl(int window_id
);
471 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
472 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
473 wxAuiToolBarItem
* FindTool(int tool_id
) const;
475 void ClearTools() { Clear() ; }
477 bool DeleteTool(int tool_id
);
478 bool DeleteByIndex(int tool_id
);
480 size_t GetToolCount() const;
481 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
482 int GetToolIndex(int tool_id
) const;
483 bool GetToolFits(int tool_id
) const;
484 wxRect
GetToolRect(int tool_id
) const;
485 bool GetToolFitsByIndex(int tool_id
) const;
486 bool GetToolBarFits() const;
488 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
489 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
490 void SetMargins(int left
, int right
, int top
, int bottom
);
492 void SetToolBitmapSize(const wxSize
& size
);
493 wxSize
GetToolBitmapSize() const;
495 bool GetOverflowVisible() const;
496 void SetOverflowVisible(bool visible
);
498 bool GetGripperVisible() const;
499 void SetGripperVisible(bool visible
);
501 void ToggleTool(int tool_id
, bool state
);
502 bool GetToolToggled(int tool_id
) const;
504 void EnableTool(int tool_id
, bool state
);
505 bool GetToolEnabled(int tool_id
) const;
507 void SetToolDropDown(int tool_id
, bool dropdown
);
508 bool GetToolDropDown(int tool_id
) const;
510 void SetToolBorderPadding(int padding
);
511 int GetToolBorderPadding() const;
513 void SetToolTextOrientation(int orientation
);
514 int GetToolTextOrientation() const;
516 void SetToolPacking(int packing
);
517 int GetToolPacking() const;
519 void SetToolProportion(int tool_id
, int proportion
);
520 int GetToolProportion(int tool_id
) const;
522 void SetToolSeparation(int separation
);
523 int GetToolSeparation() const;
525 void SetToolSticky(int tool_id
, bool sticky
);
526 bool GetToolSticky(int tool_id
) const;
528 wxString
GetToolLabel(int tool_id
) const;
529 void SetToolLabel(int tool_id
, const wxString
& label
);
531 wxBitmap
GetToolBitmap(int tool_id
) const;
532 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
534 wxString
GetToolShortHelp(int tool_id
) const;
535 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
537 wxString
GetToolLongHelp(int tool_id
) const;
538 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
540 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
541 const wxAuiToolBarItemArray
& append
);
545 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
546 const wxAuiToolBarItem
& WXUNUSED(item
),
547 const wxRect
& WXUNUSED(rect
)) { }
552 void SetOrientation(int orientation
);
553 void SetHoverItem(wxAuiToolBarItem
* item
);
554 void SetPressedItem(wxAuiToolBarItem
* item
);
555 void RefreshOverflowState();
557 int GetOverflowState() const;
558 wxRect
GetOverflowRect() const;
559 wxSize
GetLabelSize(const wxString
& label
);
560 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
562 void DoSetSize(int x
,
566 int sizeFlags
= wxSIZE_AUTO
);
568 protected: // handlers
570 void OnSize(wxSizeEvent
& evt
);
571 void OnIdle(wxIdleEvent
& evt
);
572 void OnPaint(wxPaintEvent
& evt
);
573 void OnEraseBackground(wxEraseEvent
& evt
);
574 void OnLeftDown(wxMouseEvent
& evt
);
575 void OnLeftUp(wxMouseEvent
& evt
);
576 void OnRightDown(wxMouseEvent
& evt
);
577 void OnRightUp(wxMouseEvent
& evt
);
578 void OnMiddleDown(wxMouseEvent
& evt
);
579 void OnMiddleUp(wxMouseEvent
& evt
);
580 void OnMotion(wxMouseEvent
& evt
);
581 void OnLeaveWindow(wxMouseEvent
& evt
);
582 void OnSetCursor(wxSetCursorEvent
& evt
);
586 wxAuiToolBarItemArray m_items
; // array of toolbar items
587 wxAuiToolBarArt
* m_art
; // art provider
588 wxBoxSizer
* m_sizer
; // main sizer for toolbar
589 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
590 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
591 wxBitmap m_bitmap
; // double-buffer bitmap
592 wxSizerItem
* m_gripper_sizer_item
;
593 wxSizerItem
* m_overflow_sizer_item
;
594 wxSize m_absolute_min_size
;
595 wxPoint m_action_pos
; // position of left-mouse down
596 wxAuiToolBarItemArray m_custom_overflow_prepend
;
597 wxAuiToolBarItemArray m_custom_overflow_append
;
601 int m_sizer_element_count
;
605 int m_bottom_padding
;
607 int m_tool_border_padding
;
608 int m_tool_text_orientation
;
609 int m_overflow_state
;
611 bool m_gripper_visible
;
612 bool m_overflow_visible
;
615 DECLARE_EVENT_TABLE()
616 DECLARE_CLASS(wxAuiToolBar
)
622 // wx event machinery
626 BEGIN_DECLARE_EVENT_TYPES()
627 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 0)
628 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 0)
629 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 0)
630 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 0)
631 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 0)
632 END_DECLARE_EVENT_TYPES()
634 typedef void (wxEvtHandler::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
636 #define wxAuiToolBarEventHandler(func) \
637 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiToolBarEventFunction, &func)
639 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
640 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
641 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
642 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
643 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
644 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
645 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
646 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
647 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
648 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
652 // wxpython/swig event work
653 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
654 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
655 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
656 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
657 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
660 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
661 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
662 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
663 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
664 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
669 #endif // _WX_AUIBAR_H_