1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/toolbar.h
3 // Purpose: Ribbon-style tool bar
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RIBBON_TOOLBAR_H_
12 #define _WX_RIBBON_TOOLBAR_H_
18 #include "wx/ribbon/control.h"
19 #include "wx/ribbon/art.h"
21 class wxRibbonToolBarToolBase
;
22 class wxRibbonToolBarToolGroup
;
23 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonToolBarToolGroup
*, wxArrayRibbonToolBarToolGroup
, class WXDLLIMPEXP_RIBBON
);
25 enum wxRibbonToolBarToolState
27 wxRIBBON_TOOLBAR_TOOL_FIRST
= 1 << 0,
28 wxRIBBON_TOOLBAR_TOOL_LAST
= 1 << 1,
29 wxRIBBON_TOOLBAR_TOOL_POSITION_MASK
= wxRIBBON_TOOLBAR_TOOL_FIRST
| wxRIBBON_TOOLBAR_TOOL_LAST
,
31 wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED
= 1 << 3,
32 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED
= 1 << 4,
33 wxRIBBON_TOOLBAR_TOOL_HOVER_MASK
= wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED
| wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED
,
34 wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE
= 1 << 5,
35 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
= 1 << 6,
36 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
= wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE
| wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
,
37 wxRIBBON_TOOLBAR_TOOL_DISABLED
= 1 << 7,
38 wxRIBBON_TOOLBAR_TOOL_TOGGLED
= 1 << 8,
39 wxRIBBON_TOOLBAR_TOOL_STATE_MASK
= 0x1F8
43 class WXDLLIMPEXP_RIBBON wxRibbonToolBar
: public wxRibbonControl
48 wxRibbonToolBar(wxWindow
* parent
,
49 wxWindowID id
= wxID_ANY
,
50 const wxPoint
& pos
= wxDefaultPosition
,
51 const wxSize
& size
= wxDefaultSize
,
54 virtual ~wxRibbonToolBar();
56 bool Create(wxWindow
* parent
,
57 wxWindowID id
= wxID_ANY
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
62 virtual wxRibbonToolBarToolBase
* AddTool(
64 const wxBitmap
& bitmap
,
65 const wxString
& help_string
,
66 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
68 virtual wxRibbonToolBarToolBase
* AddDropdownTool(
70 const wxBitmap
& bitmap
,
71 const wxString
& help_string
= wxEmptyString
);
73 virtual wxRibbonToolBarToolBase
* AddHybridTool(
75 const wxBitmap
& bitmap
,
76 const wxString
& help_string
= wxEmptyString
);
78 virtual wxRibbonToolBarToolBase
* AddToggleTool(
80 const wxBitmap
& bitmap
,
81 const wxString
& help_string
= wxEmptyString
);
83 virtual wxRibbonToolBarToolBase
* AddTool(
85 const wxBitmap
& bitmap
,
86 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
87 const wxString
& help_string
= wxEmptyString
,
88 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
89 wxObject
* client_data
= NULL
);
91 virtual wxRibbonToolBarToolBase
* AddSeparator();
93 virtual wxRibbonToolBarToolBase
* InsertTool(
96 const wxBitmap
& bitmap
,
97 const wxString
& help_string
,
98 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
100 virtual wxRibbonToolBarToolBase
* InsertDropdownTool(
103 const wxBitmap
& bitmap
,
104 const wxString
& help_string
= wxEmptyString
);
106 virtual wxRibbonToolBarToolBase
* InsertHybridTool(
109 const wxBitmap
& bitmap
,
110 const wxString
& help_string
= wxEmptyString
);
112 virtual wxRibbonToolBarToolBase
* InsertToggleTool(
115 const wxBitmap
& bitmap
,
116 const wxString
& help_string
= wxEmptyString
);
118 virtual wxRibbonToolBarToolBase
* InsertTool(
121 const wxBitmap
& bitmap
,
122 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
123 const wxString
& help_string
= wxEmptyString
,
124 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
125 wxObject
* client_data
= NULL
);
127 virtual wxRibbonToolBarToolBase
* InsertSeparator(size_t pos
);
129 virtual void ClearTools();
130 virtual bool DeleteTool(int tool_id
);
131 virtual bool DeleteToolByPos(size_t pos
);
133 virtual wxRibbonToolBarToolBase
* FindById(int tool_id
)const;
134 virtual wxRibbonToolBarToolBase
* GetToolByPos(size_t pos
)const;
135 virtual size_t GetToolCount() const;
136 virtual int GetToolId(const wxRibbonToolBarToolBase
* tool
)const;
138 virtual wxObject
* GetToolClientData(int tool_id
)const;
139 virtual bool GetToolEnabled(int tool_id
)const;
140 virtual wxString
GetToolHelpString(int tool_id
)const;
141 virtual wxRibbonButtonKind
GetToolKind(int tool_id
)const;
142 virtual int GetToolPos(int tool_id
)const;
143 virtual bool GetToolState(int tool_id
)const;
145 virtual bool Realize();
146 virtual void SetRows(int nMin
, int nMax
= -1);
148 virtual void SetToolClientData(int tool_id
, wxObject
* clientData
);
149 virtual void SetToolDisabledBitmap(int tool_id
, const wxBitmap
&bitmap
);
150 virtual void SetToolHelpString(int tool_id
, const wxString
& helpString
);
151 virtual void SetToolNormalBitmap(int tool_id
, const wxBitmap
&bitmap
);
153 virtual bool IsSizingContinuous() const;
155 virtual void EnableTool(int tool_id
, bool enable
= true);
156 virtual void ToggleTool(int tool_id
, bool checked
);
158 // Finds the best width and height given the parent's width and height
159 virtual wxSize
GetBestSizeForParentSize(const wxSize
& parentSize
) const;
162 friend class wxRibbonToolBarEvent
;
163 virtual wxSize
DoGetBestSize() const;
164 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
166 void OnEraseBackground(wxEraseEvent
& evt
);
167 void OnMouseDown(wxMouseEvent
& evt
);
168 void OnMouseEnter(wxMouseEvent
& evt
);
169 void OnMouseLeave(wxMouseEvent
& evt
);
170 void OnMouseMove(wxMouseEvent
& evt
);
171 void OnMouseUp(wxMouseEvent
& evt
);
172 void OnPaint(wxPaintEvent
& evt
);
173 void OnSize(wxSizeEvent
& evt
);
175 virtual wxSize
DoGetNextSmallerSize(wxOrientation direction
,
176 wxSize relative_to
) const;
177 virtual wxSize
DoGetNextLargerSize(wxOrientation direction
,
178 wxSize relative_to
) const;
180 void CommonInit(long style
);
182 wxRibbonToolBarToolGroup
* InsertGroup(size_t pos
);
183 virtual void UpdateWindowUI(long flags
);
185 static wxBitmap
MakeDisabledBitmap(const wxBitmap
& original
);
187 wxArrayRibbonToolBarToolGroup m_groups
;
188 wxRibbonToolBarToolBase
* m_hover_tool
;
189 wxRibbonToolBarToolBase
* m_active_tool
;
195 DECLARE_CLASS(wxRibbonToolBar
)
196 DECLARE_EVENT_TABLE()
201 class WXDLLIMPEXP_RIBBON wxRibbonToolBarEvent
: public wxCommandEvent
204 wxRibbonToolBarEvent(wxEventType command_type
= wxEVT_NULL
,
206 wxRibbonToolBar
* bar
= NULL
)
207 : wxCommandEvent(command_type
, win_id
)
212 wxRibbonToolBarEvent(const wxRibbonToolBarEvent
& e
) : wxCommandEvent(e
)
217 wxEvent
*Clone() const { return new wxRibbonToolBarEvent(*this); }
219 wxRibbonToolBar
* GetBar() {return m_bar
;}
220 void SetBar(wxRibbonToolBar
* bar
) {m_bar
= bar
;}
221 bool PopupMenu(wxMenu
* menu
);
224 wxRibbonToolBar
* m_bar
;
228 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonToolBarEvent
)
234 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONTOOLBAR_CLICKED
, wxRibbonToolBarEvent
);
235 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
, wxRibbonToolBarEvent
);
237 typedef void (wxEvtHandler::*wxRibbonToolBarEventFunction
)(wxRibbonToolBarEvent
&);
239 #define wxRibbonToolBarEventHandler(func) \
240 wxEVENT_HANDLER_CAST(wxRibbonToolBarEventFunction, func)
242 #define EVT_RIBBONTOOLBAR_CLICKED(winid, fn) \
243 wx__DECLARE_EVT1(wxEVT_RIBBONTOOLBAR_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
244 #define EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(winid, fn) \
245 wx__DECLARE_EVT1(wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
248 // wxpython/swig event work
249 %constant wxEventType wxEVT_RIBBONTOOLBAR_CLICKED
;
250 %constant wxEventType wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
;
253 EVT_RIBBONTOOLBAR_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONTOOLBAR_CLICKED
, 1 )
254 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
, 1 )
258 // old wxEVT_COMMAND_* constants
259 #define wxEVT_COMMAND_RIBBONTOOL_CLICKED wxEVT_RIBBONTOOLBAR_CLICKED
260 #define wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED wxEVT_RIBBONTOOLBAR_DROPDOWN_CLICKED
262 #endif // wxUSE_RIBBON
264 #endif // _WX_RIBBON_TOOLBAR_H_