buttonbar.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: ribbon/buttonbar.h
  3. // Purpose: interface of wxRibbonButtonBar
  4. // Author: Peter Cawley
  5. // Licence: wxWindows licence
  6. ///////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Flags for button bar button size and state.
  9. Buttons on a ribbon button bar can each come in three sizes: small, medium,
  10. and large. In some places this is called the size class, and the term size
  11. used for the pixel width and height associated with a particular size
  12. class.
  13. A button can also be in zero or more hovered or active states, or in the
  14. disabled state.
  15. */
  16. enum wxRibbonButtonBarButtonState
  17. {
  18. /**
  19. Button is small (the interpretation of small is dependent upon the art
  20. provider, but it will be smaller than medium).
  21. */
  22. wxRIBBON_BUTTONBAR_BUTTON_SMALL = 0 << 0,
  23. /**
  24. Button is medium sized (the interpretation of medium is dependent upon
  25. the art provider, but it will be between small and large).
  26. */
  27. wxRIBBON_BUTTONBAR_BUTTON_MEDIUM = 1 << 0,
  28. /**
  29. Button is large (the interpretation of large is dependent upon the art
  30. provider, but it will be larger than medium).
  31. */
  32. wxRIBBON_BUTTONBAR_BUTTON_LARGE = 2 << 0,
  33. /**
  34. A mask to extract button size from a combination of flags.
  35. */
  36. wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK = 3 << 0,
  37. /**
  38. The normal (non-dropdown) region of the button is being hovered over by
  39. the mouse cursor. Only applicable to normal and hybrid buttons.
  40. */
  41. wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED = 1 << 3,
  42. /**
  43. The dropdown region of the button is being hovered over by the mouse
  44. cursor. Only applicable to dropdown and hybrid buttons.
  45. */
  46. wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_HOVERED = 1 << 4,
  47. /**
  48. A mask to extract button hover state from a combination of flags.
  49. */
  50. wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK = wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED | wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_HOVERED,
  51. /**
  52. The normal (non-dropdown) region of the button is being pressed.
  53. Only applicable to normal and hybrid buttons.
  54. */
  55. wxRIBBON_BUTTONBAR_BUTTON_NORMAL_ACTIVE = 1 << 5,
  56. /**
  57. The dropdown region of the button is being pressed.
  58. Only applicable to dropdown and hybrid buttons.
  59. */
  60. wxRIBBON_BUTTONBAR_BUTTON_DROPDOWN_ACTIVE = 1 << 6,
  61. /**
  62. The button is disabled. Hover flags may still be set when a button
  63. is disabled, but should be ignored during drawing if the button is
  64. disabled.
  65. */
  66. wxRIBBON_BUTTONBAR_BUTTON_DISABLED = 1 << 7,
  67. /**
  68. The button is a toggle button which is currently in the toggled state.
  69. */
  70. wxRIBBON_BUTTONBAR_BUTTON_TOGGLED = 1 << 8,
  71. /**
  72. A mask to extract button state from a combination of flags.
  73. */
  74. wxRIBBON_BUTTONBAR_BUTTON_STATE_MASK = 0x1F8,
  75. };
  76. /**
  77. @class wxRibbonButtonBar
  78. A ribbon button bar is similar to a traditional toolbar. It contains one or
  79. more buttons (button bar buttons, not wxButtons), each of which has a label
  80. and an icon. It differs from a wxRibbonToolBar in several ways:
  81. @li Individual buttons can grow and contract.
  82. @li Buttons have labels as well as bitmaps.
  83. @li Bitmaps are typically larger (at least 32x32 pixels) on a button bar
  84. compared to a tool bar (which typically has 16x15).
  85. @li There is no grouping of buttons on a button bar
  86. @li A button bar typically has a border around each individual button,
  87. whereas a tool bar typically has a border around each group of buttons.
  88. @beginEventEmissionTable{wxRibbonButtonBarEvent}
  89. @event{EVT_RIBBONBUTTONBAR_CLICKED(id, func)}
  90. Triggered when the normal (non-dropdown) region of a button on the
  91. button bar is clicked.
  92. @event{EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(id, func)}
  93. Triggered when the dropdown region of a button on the button bar is
  94. clicked. wxRibbonButtonBarEvent::PopupMenu() should be called by the
  95. event handler if it wants to display a popup menu (which is what most
  96. dropdown buttons should be doing).
  97. @endEventTable
  98. @library{wxribbon}
  99. @category{ribbon}
  100. */
  101. class wxRibbonButtonBar : public wxRibbonControl
  102. {
  103. public:
  104. /**
  105. Default constructor.
  106. With this constructor, Create() should be called in order to create
  107. the button bar.
  108. */
  109. wxRibbonButtonBar();
  110. /**
  111. Construct a ribbon button bar with the given parameters.
  112. @param parent
  113. Parent window for the button bar (typically a wxRibbonPanel).
  114. @param id
  115. An identifier for the button bar. @c wxID_ANY is taken to mean a default.
  116. @param pos
  117. Initial position of the button bar.
  118. @param size
  119. Initial size of the button bar.
  120. @param style
  121. Button bar style, currently unused.
  122. */
  123. wxRibbonButtonBar(wxWindow* parent,
  124. wxWindowID id = wxID_ANY,
  125. const wxPoint& pos = wxDefaultPosition,
  126. const wxSize& size = wxDefaultSize,
  127. long style = 0);
  128. /**
  129. Destructor.
  130. */
  131. virtual ~wxRibbonButtonBar();
  132. /**
  133. Create a button bar in two-step button bar construction.
  134. Should only be called when the default constructor is used, and
  135. arguments have the same meaning as in the full constructor.
  136. */
  137. bool Create(wxWindow* parent,
  138. wxWindowID id = wxID_ANY,
  139. const wxPoint& pos = wxDefaultPosition,
  140. const wxSize& size = wxDefaultSize,
  141. long style = 0);
  142. /**
  143. Add a button to the button bar (simple version).
  144. */
  145. virtual wxRibbonButtonBarButtonBase* AddButton(
  146. int button_id,
  147. const wxString& label,
  148. const wxBitmap& bitmap,
  149. const wxString& help_string,
  150. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  151. /**
  152. Add a dropdown button to the button bar (simple version).
  153. @see AddButton()
  154. */
  155. virtual wxRibbonButtonBarButtonBase* AddDropdownButton(
  156. int button_id,
  157. const wxString& label,
  158. const wxBitmap& bitmap,
  159. const wxString& help_string = wxEmptyString);
  160. /**
  161. Add a hybrid button to the button bar (simple version).
  162. @see AddButton()
  163. */
  164. virtual wxRibbonButtonBarButtonBase* AddHybridButton(
  165. int button_id,
  166. const wxString& label,
  167. const wxBitmap& bitmap,
  168. const wxString& help_string = wxEmptyString);
  169. /**
  170. Add a toggle button to the button bar (simple version).
  171. @see AddButton()
  172. */
  173. virtual wxRibbonButtonBarButtonBase* AddToggleButton(
  174. int button_id,
  175. const wxString& label,
  176. const wxBitmap& bitmap,
  177. const wxString& help_string = wxEmptyString);
  178. /**
  179. Add a button to the button bar.
  180. @param button_id
  181. ID of the new button (used for event callbacks).
  182. @param label
  183. Label of the new button.
  184. @param bitmap
  185. Large bitmap of the new button. Must be the same size as all other
  186. large bitmaps used on the button bar.
  187. @param bitmap_small
  188. Small bitmap of the new button. If left as null, then a small
  189. bitmap will be automatically generated. Must be the same size as
  190. all other small bitmaps used on the button bar.
  191. @param bitmap_disabled
  192. Large bitmap of the new button when it is disabled. If left as
  193. null, then a bitmap will be automatically generated from @a bitmap.
  194. @param bitmap_small_disabled
  195. Small bitmap of the new button when it is disabled. If left as
  196. null, then a bitmap will be automatically generated from @a
  197. bitmap_small.
  198. @param kind
  199. The kind of button to add.
  200. @param help_string
  201. The UI help string to associate with the new button.
  202. @return An opaque pointer which can be used only with other button bar
  203. methods.
  204. @see AddDropdownButton()
  205. @see AddHybridButton()
  206. @see AddToggleButton()
  207. */
  208. virtual wxRibbonButtonBarButtonBase* AddButton(
  209. int button_id,
  210. const wxString& label,
  211. const wxBitmap& bitmap,
  212. const wxBitmap& bitmap_small = wxNullBitmap,
  213. const wxBitmap& bitmap_disabled = wxNullBitmap,
  214. const wxBitmap& bitmap_small_disabled = wxNullBitmap,
  215. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  216. const wxString& help_string = wxEmptyString);
  217. /**
  218. Inserts a button to the button bar (simple version) at the given position.
  219. @see AddButton()
  220. @since 2.9.4
  221. */
  222. virtual wxRibbonButtonBarButtonBase* InsertButton(
  223. size_t pos,
  224. int button_id,
  225. const wxString& label,
  226. const wxBitmap& bitmap,
  227. const wxString& help_string,
  228. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  229. /**
  230. Inserts a dropdown button to the button bar (simple version) at the
  231. given position.
  232. @see InsertButton()
  233. @see AddDropdownButton()
  234. @see AddButton()
  235. @since 2.9.4
  236. */
  237. virtual wxRibbonButtonBarButtonBase* InsertDropdownButton(
  238. size_t pos,
  239. int button_id,
  240. const wxString& label,
  241. const wxBitmap& bitmap,
  242. const wxString& help_string = wxEmptyString);
  243. /**
  244. Inserts a hybrid button to the button bar (simple version) at the given
  245. position.
  246. @see InsertButton()
  247. @see AddHybridButton()
  248. @see AddButton()
  249. @since 2.9.4
  250. */
  251. virtual wxRibbonButtonBarButtonBase* InsertHybridButton(
  252. size_t pos,
  253. int button_id,
  254. const wxString& label,
  255. const wxBitmap& bitmap,
  256. const wxString& help_string = wxEmptyString);
  257. /**
  258. Inserts a toggle button to the button bar (simple version) at the given
  259. position.
  260. @see InsertButton()
  261. @see AddToggleButton()
  262. @see AddButton()
  263. @since 2.9.4
  264. */
  265. virtual wxRibbonButtonBarButtonBase* InsertToggleButton(
  266. size_t pos,
  267. int button_id,
  268. const wxString& label,
  269. const wxBitmap& bitmap,
  270. const wxString& help_string = wxEmptyString);
  271. /**
  272. Insert a button to the button bar at the given position.
  273. @param pos
  274. Position of the new button in the button bar.
  275. @param button_id
  276. ID of the new button (used for event callbacks).
  277. @param label
  278. Label of the new button.
  279. @param bitmap
  280. Large bitmap of the new button. Must be the same size as all other
  281. large bitmaps used on the button bar.
  282. @param bitmap_small
  283. Small bitmap of the new button. If left as null, then a small
  284. bitmap will be automatically generated. Must be the same size as
  285. all other small bitmaps used on the button bar.
  286. @param bitmap_disabled
  287. Large bitmap of the new button when it is disabled. If left as
  288. null, then a bitmap will be automatically generated from @a bitmap.
  289. @param bitmap_small_disabled
  290. Small bitmap of the new button when it is disabled. If left as
  291. null, then a bitmap will be automatically generated from @a
  292. bitmap_small.
  293. @param kind
  294. The kind of button to add.
  295. @param help_string
  296. The UI help string to associate with the new button.
  297. @return An opaque pointer which can be used only with other button bar
  298. methods.
  299. @see InsertDropdownButton()
  300. @see InsertHybridButton()
  301. @see InsertToggleButton()
  302. @see AddButton()
  303. @since 2.9.4
  304. */
  305. virtual wxRibbonButtonBarButtonBase* InsertButton(
  306. size_t pos,
  307. int button_id,
  308. const wxString& label,
  309. const wxBitmap& bitmap,
  310. const wxBitmap& bitmap_small = wxNullBitmap,
  311. const wxBitmap& bitmap_disabled = wxNullBitmap,
  312. const wxBitmap& bitmap_small_disabled = wxNullBitmap,
  313. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  314. const wxString& help_string = wxEmptyString);
  315. /**
  316. Returns the number of buttons in this button bar.
  317. @since 2.9.4
  318. */
  319. virtual size_t GetButtonCount() const;
  320. /**
  321. Set the client object associated with a button. The button bar
  322. owns the given object and takes care of its deletion.
  323. Please, note that you cannot use both client object and client data.
  324. @since 2.9.5
  325. */
  326. void SetItemClientObject(wxRibbonButtonBarButtonBase* item, wxClientData* data);
  327. /**
  328. Get the client object associated with a button.
  329. @since 2.9.5
  330. */
  331. wxClientData* GetItemClientObject(const wxRibbonButtonBarButtonBase* item) const;
  332. /**
  333. Set the client data associated with a button.
  334. Please, note that you cannot use both client object and client data.
  335. @since 2.9.5
  336. */
  337. void SetItemClientData(wxRibbonButtonBarButtonBase* item, void* data);
  338. /**
  339. Get the client data associated with a button.
  340. @since 2.9.5
  341. */
  342. void* GetItemClientData(const wxRibbonButtonBarButtonBase* item) const;
  343. /**
  344. Returns the N-th button of the bar.
  345. @see GetButtonCount()
  346. @since 2.9.5
  347. */
  348. virtual wxRibbonButtonBarButtonBase *GetItem(size_t n) const;
  349. /**
  350. Returns the first button having a given id or NULL if none matches.
  351. @since 2.9.5
  352. */
  353. virtual wxRibbonButtonBarButtonBase *GetItemById(int id) const;
  354. /**
  355. Returns the id of a button.
  356. @since 2.9.5
  357. */
  358. virtual int GetItemId(wxRibbonButtonBarButtonBase *) const;
  359. /**
  360. Calculate button layouts and positions.
  361. Must be called after buttons are added to the button bar, as otherwise
  362. the newly added buttons will not be displayed. In normal situations, it
  363. will be called automatically when wxRibbonBar::Realize() is called.
  364. */
  365. virtual bool Realize();
  366. /**
  367. Delete all buttons from the button bar.
  368. @see DeleteButton()
  369. */
  370. virtual void ClearButtons();
  371. /**
  372. Delete a single button from the button bar.
  373. @see ClearButtons()
  374. */
  375. virtual bool DeleteButton(int button_id);
  376. /**
  377. Enable or disable a single button on the bar.
  378. @param button_id
  379. ID of the button to enable or disable.
  380. @param enable
  381. @true to enable the button, @false to disable it.
  382. */
  383. virtual void EnableButton(int button_id, bool enable = true);
  384. /**
  385. Set a toggle button to the checked or unchecked state.
  386. @param button_id
  387. ID of the toggle button to manipulate.
  388. @param checked
  389. @true to set the button to the toggled/pressed/checked state,
  390. @false to set it to the untoggled/unpressed/unchecked state.
  391. */
  392. virtual void ToggleButton(int button_id, bool checked);
  393. /**
  394. Returns the active item of the button bar or NULL if there is none.
  395. The active button is the one being clicked.
  396. @since 2.9.5
  397. */
  398. virtual wxRibbonButtonBarButtonBase *GetActiveItem() const;
  399. /**
  400. Returns the hovered item of the button bar or NULL if there is none.
  401. The hovered button is the one the mouse is over.
  402. @since 2.9.5
  403. */
  404. virtual wxRibbonButtonBarButtonBase *GetHoveredItem() const;
  405. /**
  406. Indicates whether tooltips are shown for disabled buttons.
  407. By default they are not shown.
  408. @since 2.9.5
  409. */
  410. void SetShowToolTipsForDisabled(bool show);
  411. /**
  412. Sets whether tooltips should be shown for disabled buttons or not.
  413. You may wish to show it to explain why a button is disabled or
  414. what it normally does when enabled.
  415. @since 2.9.5
  416. */
  417. bool GetShowToolTipsForDisabled() const;
  418. };
  419. /**
  420. @class wxRibbonButtonBarEvent
  421. Event used to indicate various actions relating to a button on a
  422. wxRibbonButtonBar. For toggle buttons, IsChecked() can be used to test
  423. the state of the button.
  424. See wxRibbonButtonBar for available event types.
  425. @library{wxribbon}
  426. @category{events,ribbon}
  427. @see wxRibbonBar
  428. */
  429. class wxRibbonButtonBarEvent : public wxCommandEvent
  430. {
  431. public:
  432. /**
  433. Constructor.
  434. */
  435. wxRibbonButtonBarEvent(wxEventType command_type = wxEVT_NULL,
  436. int win_id = 0,
  437. wxRibbonButtonBar* bar = NULL,
  438. wxRibbonButtonBarButtonBase* button = NULL);
  439. /**
  440. Returns the bar which contains the button which the event relates to.
  441. */
  442. wxRibbonButtonBar* GetBar();
  443. /**
  444. Sets the button bar relating to this event.
  445. */
  446. void SetBar(wxRibbonButtonBar* bar);
  447. /**
  448. Returns the button which the event relates to.
  449. @since 2.9.5
  450. */
  451. wxRibbonButtonBarButtonBase* GetButton();
  452. /**
  453. Sets the button relating to this event.
  454. @since 2.9.5
  455. */
  456. void SetButton(wxRibbonButtonBarButtonBase* bar);
  457. /**
  458. Display a popup menu as a result of this (dropdown clicked) event.
  459. */
  460. bool PopupMenu(wxMenu* menu);
  461. };