bar.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: ribbon/bar.h
  3. // Purpose: interface of wxRibbonBar
  4. // Author: Peter Cawley
  5. // Licence: wxWindows licence
  6. ///////////////////////////////////////////////////////////////////////////////
  7. /**
  8. The possible display modes of the panel area of a wxRibbonBar widget.
  9. @see wxRibbonBar::ShowPanels()
  10. @see wxRibbonBar::GetDisplayMode()
  11. @since 2.9.5
  12. */
  13. enum wxRibbonDisplayMode
  14. {
  15. /**
  16. The panel area is visible and pinned: it remains visible when the
  17. ribbon bar loses the focus.
  18. */
  19. wxRIBBON_BAR_PINNED,
  20. /**
  21. The panel area is hidden: only the pages tabs remain visible.
  22. */
  23. wxRIBBON_BAR_MINIMIZED,
  24. /**
  25. The panel area is visible, but not pinned: it minimizes as soon as the
  26. focus is lost.
  27. */
  28. wxRIBBON_BAR_EXPANDED
  29. };
  30. /**
  31. @class wxRibbonBarEvent
  32. Event used to indicate various actions relating to a wxRibbonBar.
  33. See wxRibbonBar for available event types.
  34. @library{wxribbon}
  35. @category{events,ribbon}
  36. @see wxRibbonBar
  37. */
  38. class wxRibbonBarEvent : public wxNotifyEvent
  39. {
  40. public:
  41. /**
  42. Constructor.
  43. */
  44. wxRibbonBarEvent(wxEventType command_type = wxEVT_NULL,
  45. int win_id = 0,
  46. wxRibbonPage* page = NULL);
  47. /**
  48. Returns the page being changed to, or being clicked on.
  49. */
  50. wxRibbonPage* GetPage();
  51. /**
  52. Sets the page relating to this event.
  53. */
  54. void SetPage(wxRibbonPage* page);
  55. };
  56. /**
  57. @class wxRibbonBar
  58. Top-level control in a ribbon user interface. Serves as a tabbed container
  59. for wxRibbonPage - a ribbon user interface typically has a ribbon bar,
  60. which contains one or more wxRibbonPages, which in turn each contain one
  61. or more wxRibbonPanels, which in turn contain controls.
  62. While a wxRibbonBar has tabs similar to a wxNotebook, it does not follow
  63. the same API for adding pages. Containers like wxNotebook can contain any
  64. type of window as a page, hence the normal procedure is to create the
  65. sub-window and then call wxBookCtrlBase::AddPage(). As wxRibbonBar can only
  66. have wxRibbonPage as children (and a wxRibbonPage can only have a
  67. wxRibbonBar as parent), when a page is created, it is automatically added
  68. to the bar - there is no AddPage equivalent to call.
  69. After all pages have been created, and all controls and panels placed on
  70. those pages, Realize() must be called.
  71. @sa wxRibbonPage
  72. @sa wxRibbonPanel
  73. @beginStyleTable
  74. @style{wxRIBBON_BAR_DEFAULT_STYLE}
  75. Defined as wxRIBBON_BAR_FLOW_HORIZONTAL |
  76. wxRIBBON_BAR_SHOW_PAGE_LABELS | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS |
  77. wxRIBBON_BAR_SHOW_TOGGLE_BUTTON | wxRIBBON_BAR_SHOW_HELP_BUTTON.
  78. @style{wxRIBBON_BAR_FOLDBAR_STYLE}
  79. Defined as wxRIBBON_BAR_FLOW_VERTICAL | wxRIBBON_BAR_SHOW_PAGE_ICONS
  80. | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS |
  81. wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS
  82. @style{wxRIBBON_BAR_SHOW_PAGE_LABELS}
  83. Causes labels to be shown on the tabs in the ribbon bar.
  84. @style{wxRIBBON_BAR_SHOW_PAGE_ICONS}
  85. Causes icons to be shown on the tabs in the ribbon bar.
  86. @style{wxRIBBON_BAR_FLOW_HORIZONTAL}
  87. Causes panels within pages to stack horizontally.
  88. @style{wxRIBBON_BAR_FLOW_VERTICAL}
  89. Causes panels within pages to stack vertically.
  90. @style{wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS}
  91. Causes extension buttons to be shown on panels (where the panel has
  92. such a button).
  93. @style{wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS}
  94. Causes minimise buttons to be shown on panels (where the panel has
  95. such a button).
  96. @style{wxRIBBON_BAR_SHOW_TOGGLE_BUTTON}
  97. Causes a toggle button to appear on the ribbon bar at top-right corner.
  98. This style is new since wxWidgets 2.9.5.
  99. @style{wxRIBBON_BAR_SHOW_HELP_BUTTON}
  100. Causes a help button to appear on the ribbon bar at the top-right corner.
  101. This style is new since wxWidgets 2.9.5.
  102. @endStyleTable
  103. @beginEventEmissionTable{wxRibbonBarEvent}
  104. @event{EVT_RIBBONBAR_PAGE_CHANGED(id, func)}
  105. Triggered after the transition from one page being active to a different
  106. page being active.
  107. @event{EVT_RIBBONBAR_PAGE_CHANGING(id, func)}
  108. Triggered prior to the transition from one page being active to a
  109. different page being active, and can veto the change.
  110. @event{EVT_RIBBONBAR_TAB_MIDDLE_DOWN(id, func)}
  111. Triggered when the middle mouse button is pressed on a tab.
  112. @event{EVT_RIBBONBAR_TAB_MIDDLE_UP(id, func)}
  113. Triggered when the middle mouse button is released on a tab.
  114. @event{EVT_RIBBONBAR_TAB_RIGHT_DOWN(id, func)}
  115. Triggered when the right mouse button is pressed on a tab.
  116. @event{EVT_RIBBONBAR_TAB_RIGHT_UP(id, func)}
  117. Triggered when the right mouse button is released on a tab.
  118. @event{EVT_RIBBONBAR_TAB_LEFT_DCLICK(id, func)}
  119. Triggered when the left mouse button is double clicked on a tab.
  120. @event{EVT_RIBBONBAR_TOGGLED(id, func)}
  121. Triggered when the button triggering the ribbon bar is clicked. This
  122. event is new since wxWidgets 2.9.5.
  123. @event{EVT_RIBBONBAR_HELP_CLICK(id, func)}
  124. Triggered when the help button is clicked. This even is new since
  125. wxWidgets 2.9.5.
  126. @endEventTable
  127. @library{wxribbon}
  128. @category{ribbon}
  129. */
  130. class wxRibbonBar : public wxRibbonControl
  131. {
  132. public:
  133. /**
  134. Default constructor.
  135. With this constructor, Create() should be called in order to create
  136. the ribbon bar.
  137. */
  138. wxRibbonBar();
  139. /**
  140. Construct a ribbon bar with the given parameters.
  141. */
  142. wxRibbonBar(wxWindow* parent,
  143. wxWindowID id = wxID_ANY,
  144. const wxPoint& pos = wxDefaultPosition,
  145. const wxSize& size = wxDefaultSize,
  146. long style = wxRIBBON_BAR_DEFAULT_STYLE);
  147. /**
  148. Create a ribbon bar in two-step ribbon bar construction.
  149. Should only be called when the default constructor is used, and
  150. arguments have the same meaning as in the full constructor.
  151. */
  152. bool Create(wxWindow* parent,
  153. wxWindowID id = wxID_ANY,
  154. const wxPoint& pos = wxDefaultPosition,
  155. const wxSize& size = wxDefaultSize,
  156. long style = wxRIBBON_BAR_DEFAULT_STYLE);
  157. /**
  158. Destructor.
  159. */
  160. virtual ~wxRibbonBar();
  161. /**
  162. Set the margin widths (in pixels) on the left and right sides of the
  163. tab bar region of the ribbon bar. These margins will be painted with
  164. the tab background, but tabs and scroll buttons will never be painted
  165. in the margins.
  166. The left margin could be used for rendering something equivalent to the
  167. "Office Button", though this is not currently implemented. The right
  168. margin could be used for rendering a help button, and/or MDI buttons,
  169. but again, this is not currently implemented.
  170. */
  171. void SetTabCtrlMargins(int left, int right);
  172. /**
  173. Set the art provider to be used be the ribbon bar. Also sets the art
  174. provider on all current wxRibbonPage children, and any wxRibbonPage
  175. children added in the future.
  176. Note that unlike most other ribbon controls, the ribbon bar creates a
  177. default art provider when initialised, so an explicit call to
  178. SetArtProvider() is not required if the default art provider is
  179. sufficient. Also, unlike other ribbon controls, the ribbon bar takes
  180. ownership of the given pointer, and will delete it when the art
  181. provider is changed or the bar is destroyed. If this behaviour is not
  182. desired, then clone the art provider before setting it.
  183. */
  184. void SetArtProvider(wxRibbonArtProvider* art);
  185. /**
  186. Set the active page by index, without triggering any events.
  187. @param page
  188. The zero-based index of the page to activate.
  189. @return @true if the specified page is now active, @false if it could
  190. not be activated (for example because the page index is invalid).
  191. */
  192. bool SetActivePage(size_t page);
  193. /**
  194. Set the active page, without triggering any events.
  195. @param page
  196. The page to activate.
  197. @return @true if the specified page is now active, @false if it could
  198. not be activated (for example because the given page is not a child
  199. of the ribbon bar).
  200. */
  201. bool SetActivePage(wxRibbonPage* page);
  202. /**
  203. Get the index of the active page.
  204. In the rare case of no page being active, -1 is returned.
  205. */
  206. int GetActivePage() const;
  207. /**
  208. Get a page by index.
  209. NULL will be returned if the given index is out of range.
  210. */
  211. wxRibbonPage* GetPage(int n);
  212. /**
  213. Get the number of pages in this bar.
  214. @since 2.9.4
  215. */
  216. size_t GetPageCount() const;
  217. /**
  218. Dismiss the expanded panel of the currently active page.
  219. Calls and returns the value from wxRibbonPage::DismissExpandedPanel()
  220. for the currently active page, or @false if there is no active page.
  221. */
  222. bool DismissExpandedPanel();
  223. /**
  224. Returns the number for a given ribbon bar page.
  225. The number can be used in other ribbon bar calls.
  226. @since 2.9.5
  227. */
  228. int GetPageNumber(wxRibbonPage* page) const;
  229. /**
  230. Delete a single page from this ribbon bar.
  231. The user must call wxRibbonBar::Realize() after one (or more) calls to
  232. this function.
  233. @since 2.9.4
  234. */
  235. void DeletePage(size_t n);
  236. /**
  237. Delete all pages from the ribbon bar.
  238. @since 2.9.4
  239. */
  240. void ClearPages();
  241. /**
  242. Indicates whether the tab for the given page is shown to the user or
  243. not.
  244. By default all page tabs are shown.
  245. @since 2.9.5
  246. */
  247. bool IsPageShown(size_t page) const;
  248. /**
  249. Show or hide the tab for a given page.
  250. After showing or hiding a tab, you need to call wxRibbonBar::Realize().
  251. If you hide the tab for the currently active page (GetActivePage) then
  252. you should call SetActivePage to activate a different page.
  253. @since 2.9.5
  254. */
  255. void ShowPage(size_t page, bool show_tab=true);
  256. /**
  257. Hides the tab for a given page.
  258. Equivalent to @c ShowPage(page, false).
  259. @since 2.9.5
  260. */
  261. void HidePage(size_t page);
  262. /**
  263. Indicates whether a tab is currently highlighted.
  264. @see AddPageHighlight()
  265. @since 2.9.5
  266. */
  267. bool IsPageHighlighted(size_t page) const;
  268. /**
  269. Highlight the specified tab.
  270. Highlighted tabs have a colour between that of the active tab
  271. and a tab over which the mouse is hovering. This can be used
  272. to make a tab (usually temporarily) more noticeable to the user.
  273. @since 2.9.5
  274. */
  275. void AddPageHighlight(size_t page, bool highlight = true);
  276. /**
  277. Changes a tab to not be highlighted.
  278. @see AddPageHighlight()
  279. @since 2.9.5
  280. */
  281. void RemovePageHighlight(size_t page);
  282. /**
  283. Shows or hides the panel area of the ribbon bar.
  284. If the panel area is hidden, then only the tab of the ribbon bar will
  285. be shown. This is useful for giving the user more screen space to work
  286. with when he/she doesn't need to see the ribbon's options.
  287. @since 2.9.2
  288. */
  289. void ShowPanels(bool show = true);
  290. /**
  291. Hides the panel area of the ribbon bar.
  292. This method simply calls ShowPanels() with @false argument.
  293. @since 2.9.2
  294. */
  295. void HidePanels();
  296. /**
  297. Indicates whether the panel area of the ribbon bar is shown.
  298. @see ShowPanels()
  299. @since 2.9.2
  300. */
  301. bool ArePanelsShown() const;
  302. /**
  303. Perform initial layout and size calculations of the bar and its
  304. children. This must be called after all of the bar's children have been
  305. created (and their children created, etc.) - if it is not, then windows
  306. may not be laid out or sized correctly.
  307. Also calls wxRibbonPage::Realize() on each child page.
  308. */
  309. virtual bool Realize();
  310. };