1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/toolbar.h
3 // Purpose: Ribbon-style tool bar
4 // Author: Peter Cawley
7 // Copyright: (C) Peter Cawley
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_RIBBON_TOOLBAR_H_
11 #define _WX_RIBBON_TOOLBAR_H_
17 #include "wx/ribbon/control.h"
18 #include "wx/ribbon/art.h"
20 class wxRibbonToolBarToolBase
;
21 class wxRibbonToolBarToolGroup
;
22 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonToolBarToolGroup
*, wxArrayRibbonToolBarToolGroup
, class WXDLLIMPEXP_RIBBON
);
24 enum wxRibbonToolBarToolState
26 wxRIBBON_TOOLBAR_TOOL_FIRST
= 1 << 0,
27 wxRIBBON_TOOLBAR_TOOL_LAST
= 1 << 1,
28 wxRIBBON_TOOLBAR_TOOL_POSITION_MASK
= wxRIBBON_TOOLBAR_TOOL_FIRST
| wxRIBBON_TOOLBAR_TOOL_LAST
,
30 wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED
= 1 << 3,
31 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED
= 1 << 4,
32 wxRIBBON_TOOLBAR_TOOL_HOVER_MASK
= wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED
| wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED
,
33 wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE
= 1 << 5,
34 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
= 1 << 6,
35 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
= wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE
| wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
,
36 wxRIBBON_TOOLBAR_TOOL_DISABLED
= 1 << 7,
37 wxRIBBON_TOOLBAR_TOOL_TOGGLED
= 1 << 8,
38 wxRIBBON_TOOLBAR_TOOL_STATE_MASK
= 0x1F8
42 class WXDLLIMPEXP_RIBBON wxRibbonToolBar
: public wxRibbonControl
47 wxRibbonToolBar(wxWindow
* parent
,
48 wxWindowID id
= wxID_ANY
,
49 const wxPoint
& pos
= wxDefaultPosition
,
50 const wxSize
& size
= wxDefaultSize
,
53 virtual ~wxRibbonToolBar();
55 bool Create(wxWindow
* parent
,
56 wxWindowID id
= wxID_ANY
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
61 virtual wxRibbonToolBarToolBase
* AddTool(
63 const wxBitmap
& bitmap
,
64 const wxString
& help_string
,
65 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
67 virtual wxRibbonToolBarToolBase
* AddDropdownTool(
69 const wxBitmap
& bitmap
,
70 const wxString
& help_string
= wxEmptyString
);
72 virtual wxRibbonToolBarToolBase
* AddHybridTool(
74 const wxBitmap
& bitmap
,
75 const wxString
& help_string
= wxEmptyString
);
77 virtual wxRibbonToolBarToolBase
* AddToggleTool(
79 const wxBitmap
& bitmap
,
80 const wxString
& help_string
= wxEmptyString
);
82 virtual wxRibbonToolBarToolBase
* AddTool(
84 const wxBitmap
& bitmap
,
85 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
86 const wxString
& help_string
= wxEmptyString
,
87 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
88 wxObject
* client_data
= NULL
);
90 virtual wxRibbonToolBarToolBase
* AddSeparator();
92 virtual wxRibbonToolBarToolBase
* InsertTool(
95 const wxBitmap
& bitmap
,
96 const wxString
& help_string
,
97 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
99 virtual wxRibbonToolBarToolBase
* InsertDropdownTool(
102 const wxBitmap
& bitmap
,
103 const wxString
& help_string
= wxEmptyString
);
105 virtual wxRibbonToolBarToolBase
* InsertHybridTool(
108 const wxBitmap
& bitmap
,
109 const wxString
& help_string
= wxEmptyString
);
111 virtual wxRibbonToolBarToolBase
* InsertToggleTool(
114 const wxBitmap
& bitmap
,
115 const wxString
& help_string
= wxEmptyString
);
117 virtual wxRibbonToolBarToolBase
* InsertTool(
120 const wxBitmap
& bitmap
,
121 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
122 const wxString
& help_string
= wxEmptyString
,
123 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
124 wxObject
* client_data
= NULL
);
126 virtual wxRibbonToolBarToolBase
* InsertSeparator(size_t pos
);
128 virtual void ClearTools();
129 virtual bool DeleteTool(int tool_id
);
130 virtual bool DeleteToolByPos(size_t pos
);
132 virtual wxRibbonToolBarToolBase
* FindById(int tool_id
)const;
133 virtual wxRibbonToolBarToolBase
* GetToolByPos(size_t pos
)const;
134 virtual size_t GetToolCount() const;
135 virtual int GetToolId(const wxRibbonToolBarToolBase
* tool
)const;
137 virtual wxObject
* GetToolClientData(int tool_id
)const;
138 virtual bool GetToolEnabled(int tool_id
)const;
139 virtual wxString
GetToolHelpString(int tool_id
)const;
140 virtual wxRibbonButtonKind
GetToolKind(int tool_id
)const;
141 virtual int GetToolPos(int tool_id
)const;
142 virtual bool GetToolState(int tool_id
)const;
144 virtual bool Realize();
145 virtual void SetRows(int nMin
, int nMax
= -1);
147 virtual void SetToolClientData(int tool_id
, wxObject
* clientData
);
148 virtual void SetToolDisabledBitmap(int tool_id
, const wxBitmap
&bitmap
);
149 virtual void SetToolHelpString(int tool_id
, const wxString
& helpString
);
150 virtual void SetToolNormalBitmap(int tool_id
, const wxBitmap
&bitmap
);
152 virtual bool IsSizingContinuous() const;
154 virtual void EnableTool(int tool_id
, bool enable
= true);
155 virtual void ToggleTool(int tool_id
, bool checked
);
157 // Finds the best width and height given the parent's width and height
158 virtual wxSize
GetBestSizeForParentSize(const wxSize
& parentSize
) const;
161 friend class wxRibbonToolBarEvent
;
162 virtual wxSize
DoGetBestSize() const;
163 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
165 void OnEraseBackground(wxEraseEvent
& evt
);
166 void OnMouseDown(wxMouseEvent
& evt
);
167 void OnMouseEnter(wxMouseEvent
& evt
);
168 void OnMouseLeave(wxMouseEvent
& evt
);
169 void OnMouseMove(wxMouseEvent
& evt
);
170 void OnMouseUp(wxMouseEvent
& evt
);
171 void OnPaint(wxPaintEvent
& evt
);
172 void OnSize(wxSizeEvent
& evt
);
174 virtual wxSize
DoGetNextSmallerSize(wxOrientation direction
,
175 wxSize relative_to
) const;
176 virtual wxSize
DoGetNextLargerSize(wxOrientation direction
,
177 wxSize relative_to
) const;
179 void CommonInit(long style
);
181 wxRibbonToolBarToolGroup
* InsertGroup(size_t pos
);
182 virtual void UpdateWindowUI(long flags
);
184 static wxBitmap
MakeDisabledBitmap(const wxBitmap
& original
);
186 wxArrayRibbonToolBarToolGroup m_groups
;
187 wxRibbonToolBarToolBase
* m_hover_tool
;
188 wxRibbonToolBarToolBase
* m_active_tool
;
194 DECLARE_CLASS(wxRibbonToolBar
)
195 DECLARE_EVENT_TABLE()
200 class WXDLLIMPEXP_RIBBON wxRibbonToolBarEvent
: public wxCommandEvent
203 wxRibbonToolBarEvent(wxEventType command_type
= wxEVT_NULL
,
205 wxRibbonToolBar
* bar
= NULL
)
206 : wxCommandEvent(command_type
, win_id
)
211 wxRibbonToolBarEvent(const wxRibbonToolBarEvent
& e
) : wxCommandEvent(e
)
216 wxEvent
*Clone() const { return new wxRibbonToolBarEvent(*this); }
218 wxRibbonToolBar
* GetBar() {return m_bar
;}
219 void SetBar(wxRibbonToolBar
* bar
) {m_bar
= bar
;}
220 bool PopupMenu(wxMenu
* menu
);
223 wxRibbonToolBar
* m_bar
;
227 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonToolBarEvent
)
233 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONTOOLBAR_CLICKED
, wxRibbonToolBarEvent
);
234 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
, wxRibbonToolBarEvent
);
236 typedef void (wxEvtHandler::*wxRibbonToolBarEventFunction
)(wxRibbonToolBarEvent
&);
238 #define wxRibbonToolBarEventHandler(func) \
239 wxEVENT_HANDLER_CAST(wxRibbonToolBarEventFunction, func)
241 #define EVT_RIBBONTOOLBAR_CLICKED(winid, fn) \
242 wx__DECLARE_EVT1(wxEVT_RIBBONTOOLBAR_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
243 #define EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(winid, fn) \
244 wx__DECLARE_EVT1(wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
247 // wxpython/swig event work
248 %constant wxEventType wxEVT_RIBBONTOOLBAR_CLICKED
;
249 %constant wxEventType wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
;
252 EVT_RIBBONTOOLBAR_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONTOOLBAR_CLICKED
, 1 )
253 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
, 1 )
257 // old wxEVT_COMMAND_* constants
258 #define wxEVT_COMMAND_RIBBONTOOL_CLICKED wxEVT_RIBBONTOOLBAR_CLICKED
259 #define wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
261 #endif // wxUSE_RIBBON
263 #endif // _WX_RIBBON_TOOLBAR_H_