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
; }
87 bool is_dropdown_clicked
;
94 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiToolBarEvent
)
99 class WXDLLIMPEXP_AUI wxAuiToolBarItem
109 kind
= wxITEM_NORMAL
;
110 state
= 0; // normal, enabled
118 wxAuiToolBarItem(const wxAuiToolBarItem
& c
)
123 wxAuiToolBarItem
& operator=(const wxAuiToolBarItem
& c
)
129 void Assign(const wxAuiToolBarItem
& c
)
134 disabled_bitmap
= c
.disabled_bitmap
;
135 hover_bitmap
= c
.hover_bitmap
;
136 short_help
= c
.short_help
;
137 long_help
= c
.long_help
;
138 sizer_item
= c
.sizer_item
;
139 min_size
= c
.min_size
;
140 space_pixels
= c
.space_pixels
;
144 proportion
= c
.proportion
;
146 dropdown
= c
.dropdown
;
148 user_data
= c
.user_data
;
153 wxWindow
* window
; // item's associated window
154 wxString label
; // label displayed on the item
155 wxBitmap bitmap
; // item's bitmap
156 wxBitmap disabled_bitmap
; // item's disabled bitmap
157 wxBitmap hover_bitmap
; // item's hover bitmap
158 wxString short_help
; // short help (for tooltip)
159 wxString long_help
; // long help (for status bar)
160 wxSizerItem
* sizer_item
; // sizer item
161 wxSize min_size
; // item's minimum size
162 int space_pixels
; // size of a spacer
164 int kind
; // item's kind
166 int proportion
; // proportion
167 bool active
; // true if the item is currently active
168 bool dropdown
; // true if the item has a dropdown button
169 bool sticky
; // overrides button states if true (always active)
170 long user_data
; // user-specified data
174 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem
, wxAuiToolBarItemArray
, WXDLLIMPEXP_AUI
);
182 class WXDLLIMPEXP_AUI wxAuiToolBarArt
186 wxAuiToolBarArt() { }
187 virtual ~wxAuiToolBarArt() { }
189 virtual wxAuiToolBarArt
* Clone() = 0;
190 virtual void SetFlags(unsigned int flags
) = 0;
191 virtual void SetFont(const wxFont
& font
) = 0;
192 virtual void SetTextOrientation(int orientation
) = 0;
194 virtual void DrawBackground(
197 const wxRect
& rect
) = 0;
199 virtual void DrawLabel(
202 const wxAuiToolBarItem
& item
,
203 const wxRect
& rect
) = 0;
205 virtual void DrawButton(
208 const wxAuiToolBarItem
& item
,
209 const wxRect
& rect
) = 0;
211 virtual void DrawDropDownButton(
214 const wxAuiToolBarItem
& item
,
215 const wxRect
& rect
) = 0;
217 virtual void DrawControlLabel(
220 const wxAuiToolBarItem
& item
,
221 const wxRect
& rect
) = 0;
223 virtual void DrawSeparator(
226 const wxRect
& rect
) = 0;
228 virtual void DrawGripper(
231 const wxRect
& rect
) = 0;
233 virtual void DrawOverflowButton(
239 virtual wxSize
GetLabelSize(
242 const wxAuiToolBarItem
& item
) = 0;
244 virtual wxSize
GetToolSize(
247 const wxAuiToolBarItem
& item
) = 0;
249 virtual int GetElementSize(int element_id
) = 0;
250 virtual void SetElementSize(int element_id
, int size
) = 0;
252 virtual int ShowDropDown(
254 const wxAuiToolBarItemArray
& items
) = 0;
259 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt
: public wxAuiToolBarArt
264 wxAuiDefaultToolBarArt();
265 virtual ~wxAuiDefaultToolBarArt();
267 virtual wxAuiToolBarArt
* Clone();
268 virtual void SetFlags(unsigned int flags
);
269 virtual void SetFont(const wxFont
& font
);
270 virtual void SetTextOrientation(int orientation
);
272 virtual void DrawBackground(
277 virtual void DrawLabel(
280 const wxAuiToolBarItem
& item
,
283 virtual void DrawButton(
286 const wxAuiToolBarItem
& item
,
289 virtual void DrawDropDownButton(
292 const wxAuiToolBarItem
& item
,
295 virtual void DrawControlLabel(
298 const wxAuiToolBarItem
& item
,
301 virtual void DrawSeparator(
306 virtual void DrawGripper(
311 virtual void DrawOverflowButton(
317 virtual wxSize
GetLabelSize(
320 const wxAuiToolBarItem
& item
);
322 virtual wxSize
GetToolSize(
325 const wxAuiToolBarItem
& item
);
327 virtual int GetElementSize(int element
);
328 virtual void SetElementSize(int element_id
, int size
);
330 virtual int ShowDropDown(wxWindow
* wnd
,
331 const wxAuiToolBarItemArray
& items
);
335 wxBitmap m_button_dropdown_bmp
;
336 wxBitmap m_disabled_button_dropdown_bmp
;
337 wxBitmap m_overflow_bmp
;
338 wxBitmap m_disabled_overflow_bmp
;
339 wxColour m_base_colour
;
340 wxColour m_highlight_colour
;
342 unsigned int m_flags
;
343 int m_text_orientation
;
345 wxPen m_gripper_pen1
;
346 wxPen m_gripper_pen2
;
347 wxPen m_gripper_pen3
;
349 int m_separator_size
;
357 class WXDLLIMPEXP_AUI wxAuiToolBar
: public wxControl
361 wxAuiToolBar(wxWindow
* parent
,
363 const wxPoint
& position
= wxDefaultPosition
,
364 const wxSize
& size
= wxDefaultSize
,
365 long style
= wxAUI_TB_DEFAULT_STYLE
);
368 void SetWindowStyleFlag(long style
);
370 void SetArtProvider(wxAuiToolBarArt
* art
);
371 wxAuiToolBarArt
* GetArtProvider() const;
373 bool SetFont(const wxFont
& font
);
376 void AddTool(int tool_id
,
377 const wxString
& label
,
378 const wxBitmap
& bitmap
,
379 const wxString
& short_help_string
= wxEmptyString
,
380 wxItemKind kind
= wxITEM_NORMAL
);
382 void AddTool(int tool_id
,
383 const wxString
& label
,
384 const wxBitmap
& bitmap
,
385 const wxBitmap
& disabled_bitmap
,
387 const wxString
& short_help_string
,
388 const wxString
& long_help_string
,
389 wxObject
* client_data
);
391 void AddTool(int tool_id
,
392 const wxBitmap
& bitmap
,
393 const wxBitmap
& disabled_bitmap
,
395 wxObject
* client_data
= NULL
,
396 const wxString
& short_help_string
= wxEmptyString
,
397 const wxString
& long_help_string
= wxEmptyString
)
403 toggle ? wxITEM_CHECK
: wxITEM_NORMAL
,
409 void AddLabel(int tool_id
,
410 const wxString
& label
= wxEmptyString
,
411 const int width
= -1);
412 void AddControl(wxControl
* control
,
413 const wxString
& label
= wxEmptyString
);
415 void AddSpacer(int pixels
);
416 void AddStretchSpacer(int proportion
= 1);
420 wxControl
* FindControl(int window_id
);
421 wxAuiToolBarItem
* FindToolByPosition(wxCoord x
, wxCoord y
) const;
422 wxAuiToolBarItem
* FindToolByIndex(int idx
) const;
423 wxAuiToolBarItem
* FindTool(int tool_id
) const;
425 void ClearTools() { Clear() ; }
427 bool DeleteTool(int tool_id
);
428 bool DeleteByIndex(int tool_id
);
430 size_t GetToolCount() const;
431 int GetToolPos(int tool_id
) const { return GetToolIndex(tool_id
); }
432 int GetToolIndex(int tool_id
) const;
433 bool GetToolFits(int tool_id
) const;
434 wxRect
GetToolRect(int tool_id
) const;
435 bool GetToolFitsByIndex(int tool_id
) const;
436 bool GetToolBarFits() const;
438 void SetMargins(const wxSize
& size
) { SetMargins(size
.x
, size
.x
, size
.y
, size
.y
); }
439 void SetMargins(int x
, int y
) { SetMargins(x
, x
, y
, y
); }
440 void SetMargins(int left
, int right
, int top
, int bottom
);
442 void SetToolBitmapSize(const wxSize
& size
);
443 wxSize
GetToolBitmapSize() const;
445 bool GetOverflowVisible() const;
446 void SetOverflowVisible(bool visible
);
448 bool GetGripperVisible() const;
449 void SetGripperVisible(bool visible
);
451 void ToggleTool(int tool_id
, bool state
);
452 bool GetToolToggled(int tool_id
) const;
454 void EnableTool(int tool_id
, bool state
);
455 bool GetToolEnabled(int tool_id
) const;
457 void SetToolDropDown(int tool_id
, bool dropdown
);
458 bool GetToolDropDown(int tool_id
) const;
460 void SetToolBorderPadding(int padding
);
461 int GetToolBorderPadding() const;
463 void SetToolTextOrientation(int orientation
);
464 int GetToolTextOrientation() const;
466 void SetToolPacking(int packing
);
467 int GetToolPacking() const;
469 void SetToolProportion(int tool_id
, int proportion
);
470 int GetToolProportion(int tool_id
) const;
472 void SetToolSeparation(int separation
);
473 int GetToolSeparation() const;
475 void SetToolSticky(int tool_id
, bool sticky
);
476 bool GetToolSticky(int tool_id
) const;
478 wxString
GetToolLabel(int tool_id
) const;
479 void SetToolLabel(int tool_id
, const wxString
& label
);
481 wxBitmap
GetToolBitmap(int tool_id
) const;
482 void SetToolBitmap(int tool_id
, const wxBitmap
& bitmap
);
484 wxString
GetToolShortHelp(int tool_id
) const;
485 void SetToolShortHelp(int tool_id
, const wxString
& help_string
);
487 wxString
GetToolLongHelp(int tool_id
) const;
488 void SetToolLongHelp(int tool_id
, const wxString
& help_string
);
490 void SetCustomOverflowItems(const wxAuiToolBarItemArray
& prepend
,
491 const wxAuiToolBarItemArray
& append
);
495 virtual void OnCustomRender(wxDC
& WXUNUSED(dc
),
496 const wxAuiToolBarItem
& WXUNUSED(item
),
497 const wxRect
& WXUNUSED(rect
)) { }
502 void SetOrientation(int orientation
);
503 void SetHoverItem(wxAuiToolBarItem
* item
);
504 void SetPressedItem(wxAuiToolBarItem
* item
);
505 void RefreshOverflowState();
507 int GetOverflowState() const;
508 wxRect
GetOverflowRect() const;
509 wxSize
GetLabelSize(const wxString
& label
);
510 wxAuiToolBarItem
* FindToolByPositionWithPacking(wxCoord x
, wxCoord y
) const;
512 void DoSetSize(int x
,
516 int sizeFlags
= wxSIZE_AUTO
);
518 protected: // handlers
520 void OnSize(wxSizeEvent
& evt
);
521 void OnIdle(wxIdleEvent
& evt
);
522 void OnPaint(wxPaintEvent
& evt
);
523 void OnEraseBackground(wxEraseEvent
& evt
);
524 void OnLeftDown(wxMouseEvent
& evt
);
525 void OnLeftUp(wxMouseEvent
& evt
);
526 void OnRightDown(wxMouseEvent
& evt
);
527 void OnRightUp(wxMouseEvent
& evt
);
528 void OnMiddleDown(wxMouseEvent
& evt
);
529 void OnMiddleUp(wxMouseEvent
& evt
);
530 void OnMotion(wxMouseEvent
& evt
);
531 void OnLeaveWindow(wxMouseEvent
& evt
);
532 void OnSetCursor(wxSetCursorEvent
& evt
);
536 wxAuiToolBarItemArray m_items
; // array of toolbar items
537 wxAuiToolBarArt
* m_art
; // art provider
538 wxBoxSizer
* m_sizer
; // main sizer for toolbar
539 wxAuiToolBarItem
* m_action_item
; // item that's being acted upon (pressed)
540 wxAuiToolBarItem
* m_tip_item
; // item that has its tooltip shown
541 wxBitmap m_bitmap
; // double-buffer bitmap
542 wxSizerItem
* m_gripper_sizer_item
;
543 wxSizerItem
* m_overflow_sizer_item
;
544 wxSize m_absolute_min_size
;
545 wxPoint m_action_pos
; // position of left-mouse down
546 wxAuiToolBarItemArray m_custom_overflow_prepend
;
547 wxAuiToolBarItemArray m_custom_overflow_append
;
551 int m_sizer_element_count
;
555 int m_bottom_padding
;
557 int m_tool_border_padding
;
558 int m_tool_text_orientation
;
559 int m_overflow_state
;
561 bool m_gripper_visible
;
562 bool m_overflow_visible
;
565 DECLARE_EVENT_TABLE()
566 DECLARE_CLASS(wxAuiToolBar
)
572 // wx event machinery
576 BEGIN_DECLARE_EVENT_TYPES()
577 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 0)
578 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 0)
579 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 0)
580 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 0)
581 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI
, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 0)
582 END_DECLARE_EVENT_TYPES()
584 typedef void (wxEvtHandler
::*wxAuiToolBarEventFunction
)(wxAuiToolBarEvent
&);
586 #define wxAuiToolBarEventHandler(func) \
587 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiToolBarEventFunction, &func)
589 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
590 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
591 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
592 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
593 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
594 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
595 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
596 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
597 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
598 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
602 // wxpython/swig event work
603 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
;
604 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
;
605 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
;
606 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
;
607 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
;
610 EVT_AUITOOLBAR_TOOL_DROPDOWN
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN
, 1 )
611 EVT_AUITOOLBAR_OVERFLOW_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK
, 1 )
612 EVT_AUITOOLBAR_RIGHT_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK
, 1 )
613 EVT_AUITOOLBAR_MIDDLE_CLICK
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK
, 1 )
614 EVT_AUITOOLBAR_BEGIN_DRAG
= wx
.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG
, 1 )
619 #endif // _WX_AUIBAR_H_