1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: ribbon/buttonbar.h
3 // Purpose: interface of wxRibbonButtonBar
4 // Author: Peter Cawley
5 // Licence: wxWindows licence
6 ///////////////////////////////////////////////////////////////////////////////
9 Flags for button bar button size and state.
11 Buttons on a ribbon button bar can each come in three sizes: small, medium,
12 and large. In some places this is called the size class, and the term size
13 used for the pixel width and height associated with a particular size
16 A button can also be in zero or more hovered or active states, or in the
19 enum wxRibbonButtonBarButtonState
22 Button is small (the interpretation of small is dependent upon the art
23 provider, but it will be smaller than medium).
25 wxRIBBON_BUTTONBAR_BUTTON_SMALL
= 0 << 0,
28 Button is medium sized (the interpretation of medium is dependent upon
29 the art provider, but it will be between small and large).
31 wxRIBBON_BUTTONBAR_BUTTON_MEDIUM
= 1 << 0,
34 Button is large (the interpretation of large is dependent upon the art
35 provider, but it will be larger than medium).
37 wxRIBBON_BUTTONBAR_BUTTON_LARGE
= 2 << 0,
40 A mask to extract button size from a combination of flags.
42 wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK
= 3 << 0,
45 The normal (non-dropdown) region of the button is being hovered over by
46 the mouse cursor. Only applicable to normal and hybrid buttons.
48 wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
= 1 << 3,
51 The dropdown region of the button is being hovered over by the mouse
52 cursor. Only applicable to dropdown and hybrid buttons.
54 wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_HOVERED
= 1 << 4,
57 A mask to extract button hover state from a combination of flags.
59 wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
= wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
| wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_HOVERED
,
62 The normal (non-dropdown) region of the button is being pressed.
63 Only applicable to normal and hybrid buttons.
65 wxRIBBON_BUTTONBAR_BUTTON_NORMAL_ACTIVE
= 1 << 5,
68 The dropdown region of the button is being pressed.
69 Only applicable to dropdown and hybrid buttons.
71 wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE
= 1 << 6,
74 The button is disabled. Hover flags may still be set when a button
75 is disabled, but should be ignored during drawing if the button is
78 wxRIBBON_BUTTONBAR_BUTTON_DISABLED
= 1 << 7,
81 The button is a toggle button which is currently in the toggled state.
83 wxRIBBON_BUTTONBAR_BUTTON_TOGGLED
= 1 << 8,
86 A mask to extract button state from a combination of flags.
88 wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK
= 0x1F8,
92 @class wxRibbonButtonBar
94 A ribbon button bar is similar to a traditional toolbar. It contains one or
95 more buttons (button bar buttons, not wxButtons), each of which has a label
96 and an icon. It differs from a wxRibbonToolBar in several ways:
97 @li Individual buttons can grow and contract.
98 @li Buttons have labels as well as bitmaps.
99 @li Bitmaps are typically larger (at least 32x32 pixels) on a button bar
100 compared to a tool bar (which typically has 16x15).
101 @li There is no grouping of buttons on a button bar
102 @li A button bar typically has a border around each individual button,
103 whereas a tool bar typically has a border around each group of buttons.
105 @beginEventEmissionTable{wxRibbonButtonBarEvent}
106 @event{EVT_RIBBONBUTTONBAR_CLICKED(id, func)}
107 Triggered when the normal (non-dropdown) region of a button on the
108 button bar is clicked.
109 @event{EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(id, func)}
110 Triggered when the dropdown region of a button on the button bar is
111 clicked. wxRibbonButtonBarEvent::PopupMenu() should be called by the
112 event handler if it wants to display a popup menu (which is what most
113 dropdown buttons should be doing).
119 class wxRibbonButtonBar
: public wxRibbonControl
124 With this constructor, Create() should be called in order to create
130 Construct a ribbon button bar with the given parameters.
133 Parent window for the button bar (typically a wxRibbonPanel).
135 An identifier for the button bar. @c wxID_ANY is taken to mean a default.
137 Initial position of the button bar.
139 Initial size of the button bar.
141 Button bar style, currently unused.
143 wxRibbonButtonBar(wxWindow
* parent
,
144 wxWindowID id
= wxID_ANY
,
145 const wxPoint
& pos
= wxDefaultPosition
,
146 const wxSize
& size
= wxDefaultSize
,
152 virtual ~wxRibbonButtonBar();
155 Create a button bar in two-step button bar construction.
156 Should only be called when the default constructor is used, and
157 arguments have the same meaning as in the full constructor.
159 bool Create(wxWindow
* parent
,
160 wxWindowID id
= wxID_ANY
,
161 const wxPoint
& pos
= wxDefaultPosition
,
162 const wxSize
& size
= wxDefaultSize
,
166 Add a button to the button bar (simple version).
168 virtual wxRibbonButtonBarButtonBase
* AddButton(
170 const wxString
& label
,
171 const wxBitmap
& bitmap
,
172 const wxString
& help_string
,
173 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
176 Add a dropdown button to the button bar (simple version).
180 virtual wxRibbonButtonBarButtonBase
* AddDropdownButton(
182 const wxString
& label
,
183 const wxBitmap
& bitmap
,
184 const wxString
& help_string
= wxEmptyString
);
187 Add a hybrid button to the button bar (simple version).
191 virtual wxRibbonButtonBarButtonBase
* AddHybridButton(
193 const wxString
& label
,
194 const wxBitmap
& bitmap
,
195 const wxString
& help_string
= wxEmptyString
);
198 Add a toggle button to the button bar (simple version).
202 virtual wxRibbonButtonBarButtonBase
* AddToggleButton(
204 const wxString
& label
,
205 const wxBitmap
& bitmap
,
206 const wxString
& help_string
= wxEmptyString
);
209 Add a button to the button bar.
212 ID of the new button (used for event callbacks).
214 Label of the new button.
216 Large bitmap of the new button. Must be the same size as all other
217 large bitmaps used on the button bar.
219 Small bitmap of the new button. If left as null, then a small
220 bitmap will be automatically generated. Must be the same size as
221 all other small bitmaps used on the button bar.
222 @param bitmap_disabled
223 Large bitmap of the new button when it is disabled. If left as
224 null, then a bitmap will be automatically generated from @a bitmap.
225 @param bitmap_small_disabled
226 Small bitmap of the new button when it is disabled. If left as
227 null, then a bitmap will be automatically generated from @a
230 The kind of button to add.
232 The UI help string to associate with the new button.
234 @return An opaque pointer which can be used only with other button bar
237 @see AddDropdownButton()
238 @see AddHybridButton()
239 @see AddToggleButton()
241 virtual wxRibbonButtonBarButtonBase
* AddButton(
243 const wxString
& label
,
244 const wxBitmap
& bitmap
,
245 const wxBitmap
& bitmap_small
= wxNullBitmap
,
246 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
247 const wxBitmap
& bitmap_small_disabled
= wxNullBitmap
,
248 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
249 const wxString
& help_string
= wxEmptyString
);
252 Inserts a button to the button bar (simple version) at the given position.
258 virtual wxRibbonButtonBarButtonBase
* InsertButton(
261 const wxString
& label
,
262 const wxBitmap
& bitmap
,
263 const wxString
& help_string
,
264 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
267 Inserts a dropdown button to the button bar (simple version) at the
271 @see AddDropdownButton()
276 virtual wxRibbonButtonBarButtonBase
* InsertDropdownButton(
279 const wxString
& label
,
280 const wxBitmap
& bitmap
,
281 const wxString
& help_string
= wxEmptyString
);
284 Inserts a hybrid button to the button bar (simple version) at the given
288 @see AddHybridButton()
293 virtual wxRibbonButtonBarButtonBase
* InsertHybridButton(
296 const wxString
& label
,
297 const wxBitmap
& bitmap
,
298 const wxString
& help_string
= wxEmptyString
);
301 Inserts a toggle button to the button bar (simple version) at the given
305 @see AddToggleButton()
310 virtual wxRibbonButtonBarButtonBase
* InsertToggleButton(
313 const wxString
& label
,
314 const wxBitmap
& bitmap
,
315 const wxString
& help_string
= wxEmptyString
);
318 Insert a button to the button bar at the given position.
321 Position of the new button in the button bar.
323 ID of the new button (used for event callbacks).
325 Label of the new button.
327 Large bitmap of the new button. Must be the same size as all other
328 large bitmaps used on the button bar.
330 Small bitmap of the new button. If left as null, then a small
331 bitmap will be automatically generated. Must be the same size as
332 all other small bitmaps used on the button bar.
333 @param bitmap_disabled
334 Large bitmap of the new button when it is disabled. If left as
335 null, then a bitmap will be automatically generated from @a bitmap.
336 @param bitmap_small_disabled
337 Small bitmap of the new button when it is disabled. If left as
338 null, then a bitmap will be automatically generated from @a
341 The kind of button to add.
343 The UI help string to associate with the new button.
345 @return An opaque pointer which can be used only with other button bar
348 @see InsertDropdownButton()
349 @see InsertHybridButton()
350 @see InsertToggleButton()
355 virtual wxRibbonButtonBarButtonBase
* InsertButton(
358 const wxString
& label
,
359 const wxBitmap
& bitmap
,
360 const wxBitmap
& bitmap_small
= wxNullBitmap
,
361 const wxBitmap
& bitmap_disabled
= wxNullBitmap
,
362 const wxBitmap
& bitmap_small_disabled
= wxNullBitmap
,
363 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
,
364 const wxString
& help_string
= wxEmptyString
);
367 Returns the number of buttons in this button bar.
371 virtual size_t GetButtonCount() const;
374 Set the client object associated with a button. The button bar
375 owns the given object and takes care of its deletion.
376 Please, note that you cannot use both client object and client data.
380 void SetItemClientObject(wxRibbonButtonBarButtonBase
* item
, wxClientData
* data
);
383 Get the client object associated with a button.
387 wxClientData
* GetItemClientObject(const wxRibbonButtonBarButtonBase
* item
) const;
390 Set the client data associated with a button.
391 Please, note that you cannot use both client object and client data.
395 void SetItemClientData(wxRibbonButtonBarButtonBase
* item
, void* data
);
398 Get the client data associated with a button.
402 void* GetItemClientData(const wxRibbonButtonBarButtonBase
* item
) const;
405 Returns the N-th button of the bar.
407 @see GetButtonCount()
411 virtual wxRibbonButtonBarButtonBase
*GetItem(size_t n
) const;
414 Returns the first button having a given id or NULL if none matches.
418 virtual wxRibbonButtonBarButtonBase
*GetItemById(int id
) const;
421 Returns the id of a button.
425 virtual int GetItemId(wxRibbonButtonBarButtonBase
*) const;
428 Calculate button layouts and positions.
430 Must be called after buttons are added to the button bar, as otherwise
431 the newly added buttons will not be displayed. In normal situations, it
432 will be called automatically when wxRibbonBar::Realize() is called.
434 virtual bool Realize();
437 Delete all buttons from the button bar.
441 virtual void ClearButtons();
444 Delete a single button from the button bar.
448 virtual bool DeleteButton(int button_id
);
451 Enable or disable a single button on the bar.
454 ID of the button to enable or disable.
456 @true to enable the button, @false to disable it.
458 virtual void EnableButton(int button_id
, bool enable
= true);
461 Set a toggle button to the checked or unchecked state.
464 ID of the toggle button to manipulate.
466 @true to set the button to the toggled/pressed/checked state,
467 @false to set it to the untoggled/unpressed/unchecked state.
469 virtual void ToggleButton(int button_id
, bool checked
);
472 Returns the active item of the button bar or NULL if there is none.
473 The active button is the one being clicked.
477 virtual wxRibbonButtonBarButtonBase
*GetActiveItem() const;
480 Returns the hovered item of the button bar or NULL if there is none.
481 The hovered button is the one the mouse is over.
485 virtual wxRibbonButtonBarButtonBase
*GetHoveredItem() const;
488 Indicates whether tooltips are shown for disabled buttons.
490 By default they are not shown.
494 void SetShowToolTipsForDisabled(bool show
);
497 Sets whether tooltips should be shown for disabled buttons or not.
499 You may wish to show it to explain why a button is disabled or
500 what it normally does when enabled.
504 bool GetShowToolTipsForDisabled() const;
509 @class wxRibbonButtonBarEvent
511 Event used to indicate various actions relating to a button on a
512 wxRibbonButtonBar. For toggle buttons, IsChecked() can be used to test
513 the state of the button.
515 See wxRibbonButtonBar for available event types.
518 @category{events,ribbon}
522 class wxRibbonButtonBarEvent
: public wxCommandEvent
528 wxRibbonButtonBarEvent(wxEventType command_type
= wxEVT_NULL
,
530 wxRibbonButtonBar
* bar
= NULL
,
531 wxRibbonButtonBarButtonBase
* button
= NULL
);
534 Returns the bar which contains the button which the event relates to.
536 wxRibbonButtonBar
* GetBar();
539 Sets the button bar relating to this event.
541 void SetBar(wxRibbonButtonBar
* bar
);
544 Returns the button which the event relates to.
548 wxRibbonButtonBarButtonBase
* GetButton();
551 Sets the button relating to this event.
555 void SetButton(wxRibbonButtonBarButtonBase
* bar
);
558 Display a popup menu as a result of this (dropdown clicked) event.
560 bool PopupMenu(wxMenu
* menu
);