bookctrl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: bookctrl.h
  3. // Purpose: interface of wxBookCtrlBase
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Bit flags returned by wxBookCtrl::HitTest().
  9. Notice that wxOSX currently only returns wxBK_HITTEST_ONLABEL or
  10. wxBK_HITTEST_NOWHERE and never the other values, so you should only test
  11. for these two in the code that should be portable under OS X.
  12. */
  13. enum
  14. {
  15. /// No tab at the specified point.
  16. wxBK_HITTEST_NOWHERE = 1,
  17. /// The point is over an icon.
  18. wxBK_HITTEST_ONICON = 2,
  19. /// The point is over a tab label.
  20. wxBK_HITTEST_ONLABEL = 4,
  21. /// The point if over a tab item but not over its icon or label.
  22. wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL,
  23. /// The point is over the page area.
  24. wxBK_HITTEST_ONPAGE = 8
  25. };
  26. /**
  27. wxBookCtrl flags (common for wxNotebook, wxListbook, wxChoicebook, wxTreebook)
  28. */
  29. #define wxBK_DEFAULT 0x0000
  30. #define wxBK_TOP 0x0010
  31. #define wxBK_BOTTOM 0x0020
  32. #define wxBK_LEFT 0x0040
  33. #define wxBK_RIGHT 0x0080
  34. #define wxBK_ALIGN_MASK (wxBK_TOP | wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT)
  35. /**
  36. @class wxBookCtrlBase
  37. A book control is a convenient way of displaying multiple pages of information,
  38. displayed one page at a time. wxWidgets has five variants of this control:
  39. @li wxChoicebook: controlled by a wxChoice
  40. @li wxListbook: controlled by a wxListCtrl
  41. @li wxNotebook: uses a row of tabs
  42. @li wxTreebook: controlled by a wxTreeCtrl
  43. @li wxToolbook: controlled by a wxToolBar
  44. This abstract class is the parent of all these book controls, and provides
  45. their basic interface.
  46. This is a pure virtual class so you cannot allocate it directly.
  47. @library{wxcore}
  48. @category{bookctrl}
  49. @see @ref overview_bookctrl
  50. */
  51. class wxBookCtrlBase : public wxControl, public wxWithImages
  52. {
  53. public:
  54. enum
  55. {
  56. /// Symbolic constant indicating that no image should be used.
  57. NO_IMAGE = -1
  58. };
  59. /**
  60. Default ctor.
  61. */
  62. wxBookCtrlBase();
  63. /**
  64. Constructs the book control with the given parameters.
  65. See Create() for two-step construction.
  66. */
  67. wxBookCtrlBase(wxWindow *parent,
  68. wxWindowID winid,
  69. const wxPoint& pos = wxDefaultPosition,
  70. const wxSize& size = wxDefaultSize,
  71. long style = 0,
  72. const wxString& name = wxEmptyString);
  73. /**
  74. Constructs the book control with the given parameters.
  75. */
  76. bool Create(wxWindow *parent,
  77. wxWindowID winid,
  78. const wxPoint& pos = wxDefaultPosition,
  79. const wxSize& size = wxDefaultSize,
  80. long style = 0,
  81. const wxString& name = wxEmptyString);
  82. /**
  83. @name Image list functions
  84. Each page may have an attached image.
  85. The functions of this group manipulate that image.
  86. */
  87. //@{
  88. /**
  89. Returns the image index for the given page.
  90. */
  91. virtual int GetPageImage(size_t nPage) const = 0;
  92. /**
  93. Sets the image index for the given page. @a image is an index into
  94. the image list which was set with SetImageList().
  95. */
  96. virtual bool SetPageImage(size_t page, int image) = 0;
  97. //@}
  98. /**
  99. @name Page text functions
  100. Each page has a text string attached.
  101. The functions of this group manipulate that text.
  102. */
  103. //@{
  104. /**
  105. Returns the string for the given page.
  106. */
  107. virtual wxString GetPageText(size_t nPage) const = 0;
  108. /**
  109. Sets the text for the given page.
  110. */
  111. virtual bool SetPageText(size_t page, const wxString& text) = 0;
  112. //@}
  113. /**
  114. @name Selection functions
  115. The functions of this group manipulate the selection.
  116. */
  117. //@{
  118. /**
  119. Returns the currently selected page, or @c wxNOT_FOUND if none was selected.
  120. Note that this method may return either the previously or newly
  121. selected page when called from the @c EVT_BOOKCTRL_PAGE_CHANGED handler
  122. depending on the platform and so wxBookCtrlEvent::GetSelection should be
  123. used instead in this case.
  124. */
  125. virtual int GetSelection() const = 0;
  126. /**
  127. Returns the currently selected page or @NULL.
  128. */
  129. wxWindow* GetCurrentPage() const;
  130. /**
  131. Sets the selection to the given page, returning the previous selection.
  132. Notice that the call to this function generates the page changing
  133. events, use the ChangeSelection() function if you don't want these
  134. events to be generated.
  135. @see GetSelection()
  136. */
  137. virtual int SetSelection(size_t page) = 0;
  138. /**
  139. Cycles through the tabs.
  140. The call to this function generates the page changing events.
  141. */
  142. void AdvanceSelection(bool forward = true);
  143. /**
  144. Changes the selection to the given page, returning the previous selection.
  145. This function behaves as SetSelection() but does @em not generate the
  146. page changing events.
  147. See @ref overview_events_prog for more information.
  148. */
  149. virtual int ChangeSelection(size_t page) = 0;
  150. /**
  151. Returns the index of the specified tab window or @c wxNOT_FOUND
  152. if not found.
  153. @param page One of the control pages.
  154. @return The zero-based tab index or @c wxNOT_FOUND if not found.
  155. @since 2.9.5
  156. */
  157. int FindPage(const wxWindow* page) const;
  158. //@}
  159. /**
  160. Sets the width and height of the pages.
  161. @note This method is currently not implemented for wxGTK.
  162. */
  163. virtual void SetPageSize(const wxSize& size);
  164. /**
  165. Returns the index of the tab at the specified position or @c wxNOT_FOUND
  166. if none. If @a flags parameter is non-@NULL, the position of the point
  167. inside the tab is returned as well.
  168. @param pt
  169. Specifies the point for the hit test.
  170. @param flags
  171. Return more details about the point, see returned value is a
  172. combination of ::wxBK_HITTEST_NOWHERE, ::wxBK_HITTEST_ONICON,
  173. ::wxBK_HITTEST_ONLABEL, ::wxBK_HITTEST_ONITEM,
  174. ::wxBK_HITTEST_ONPAGE.
  175. @return Returns the zero-based tab index or @c wxNOT_FOUND if there is no
  176. tab at the specified position.
  177. */
  178. virtual int HitTest(const wxPoint& pt, long* flags = NULL) const;
  179. /**
  180. @name Page management functions
  181. Functions for adding/removing pages from this control.
  182. */
  183. //@{
  184. /**
  185. Adds a new page.
  186. The page must have the book control itself as the parent and must not
  187. have been added to this control previously.
  188. The call to this function may generate the page changing events.
  189. @param page
  190. Specifies the new page.
  191. @param text
  192. Specifies the text for the new page.
  193. @param select
  194. Specifies whether the page should be selected.
  195. @param imageId
  196. Specifies the optional image index for the new page.
  197. @return @true if successful, @false otherwise.
  198. @remarks Do not delete the page, it will be deleted by the book control.
  199. @see InsertPage()
  200. */
  201. virtual bool AddPage(wxWindow* page, const wxString& text,
  202. bool select = false, int imageId = NO_IMAGE);
  203. /**
  204. Deletes all pages.
  205. */
  206. virtual bool DeleteAllPages();
  207. /**
  208. Deletes the specified page, and the associated window.
  209. The call to this function generates the page changing events.
  210. */
  211. virtual bool DeletePage(size_t page);
  212. /**
  213. Inserts a new page at the specified position.
  214. @param index
  215. Specifies the position for the new page.
  216. @param page
  217. Specifies the new page.
  218. @param text
  219. Specifies the text for the new page.
  220. @param select
  221. Specifies whether the page should be selected.
  222. @param imageId
  223. Specifies the optional image index for the new page.
  224. @return @true if successful, @false otherwise.
  225. @remarks Do not delete the page, it will be deleted by the book control.
  226. @see AddPage()
  227. */
  228. virtual bool InsertPage(size_t index,
  229. wxWindow* page,
  230. const wxString& text,
  231. bool select = false,
  232. int imageId = NO_IMAGE) = 0;
  233. /**
  234. Deletes the specified page, without deleting the associated window.
  235. */
  236. virtual bool RemovePage(size_t page);
  237. /**
  238. Returns the number of pages in the control.
  239. */
  240. virtual size_t GetPageCount() const;
  241. /**
  242. Returns the window at the given page position.
  243. */
  244. wxWindow* GetPage(size_t page) const;
  245. //@}
  246. /*
  247. other functions which may be worth documenting:
  248. // geometry
  249. // --------
  250. // calculate the size of the control from the size of its page
  251. virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
  252. // get/set size of area between book control area and page area
  253. unsigned int GetInternalBorder() const { return m_internalBorder; }
  254. void SetInternalBorder(unsigned int border) { m_internalBorder = border; }
  255. // Sets/gets the margin around the controller
  256. void SetControlMargin(int margin) { m_controlMargin = margin; }
  257. int GetControlMargin() const { return m_controlMargin; }
  258. // returns true if we have wxBK_TOP or wxBK_BOTTOM style
  259. bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
  260. // set/get option to shrink to fit current page
  261. void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
  262. bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
  263. // returns the sizer containing the control, if any
  264. wxSizer* GetControlSizer() const { return m_controlSizer; }
  265. // we do have multiple pages
  266. virtual bool HasMultiplePages() const { return true; }
  267. // we don't want focus for ourselves
  268. virtual bool AcceptsFocus() const { return false; }
  269. // returns true if the platform should explicitly apply a theme border
  270. virtual bool CanApplyThemeBorder() const { return false; }
  271. */
  272. };
  273. /**
  274. wxBookCtrl is defined to one of the 'real' book controls.
  275. See @ref overview_bookctrl for more info.
  276. */
  277. #define wxBookCtrl TheBestBookCtrlForTheCurrentPlatform
  278. /**
  279. @class wxBookCtrlEvent
  280. This class represents the events generated by book controls (wxNotebook,
  281. wxListbook, wxChoicebook, wxTreebook, wxAuiNotebook).
  282. The PAGE_CHANGING events are sent before the current page is changed.
  283. It allows the program to examine the current page (which can be retrieved
  284. with wxBookCtrlEvent::GetOldSelection) and to veto the page change by calling
  285. wxNotifyEvent::Veto if, for example, the current values in the controls
  286. of the old page are invalid.
  287. The PAGE_CHANGED events are sent after the page has been changed and the
  288. program cannot veto it any more, it just informs it about the page change.
  289. To summarize, if the program is interested in validating the page values
  290. before allowing the user to change it, it should process the PAGE_CHANGING
  291. event, otherwise PAGE_CHANGED is probably enough. In any case, it is
  292. probably unnecessary to process both events at once.
  293. @library{wxcore}
  294. @category{events,bookctrl}
  295. @see wxNotebook, wxListbook, wxChoicebook, wxTreebook, wxToolbook, wxAuiNotebook
  296. */
  297. class wxBookCtrlEvent : public wxNotifyEvent
  298. {
  299. public:
  300. /**
  301. Constructor (used internally by wxWidgets only).
  302. */
  303. wxBookCtrlEvent(wxEventType eventType = wxEVT_NULL, int id = 0,
  304. int sel = wxNOT_FOUND, int oldSel = wxNOT_FOUND);
  305. /**
  306. Returns the page that was selected before the change, @c wxNOT_FOUND if
  307. none was selected.
  308. */
  309. int GetOldSelection() const;
  310. /**
  311. Returns the currently selected page, or @c wxNOT_FOUND if none was
  312. selected.
  313. @note under Windows, GetSelection() will return the same value as
  314. GetOldSelection() when called from the @c EVT_BOOKCTRL_PAGE_CHANGING
  315. handler and not the page which is going to be selected.
  316. */
  317. int GetSelection() const;
  318. /**
  319. Sets the id of the page selected before the change.
  320. */
  321. void SetOldSelection(int page);
  322. /**
  323. Sets the selection member variable.
  324. */
  325. void SetSelection(int page);
  326. };