notebook.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/notebook.h
  3. // Purpose: universal version of wxNotebook
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 01.02.01
  7. // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_NOTEBOOK_H_
  11. #define _WX_UNIV_NOTEBOOK_H_
  12. #include "wx/arrstr.h"
  13. class WXDLLIMPEXP_FWD_CORE wxSpinButton;
  14. // ----------------------------------------------------------------------------
  15. // the actions supported by this control
  16. // ----------------------------------------------------------------------------
  17. // change the page: to the next/previous/given one
  18. #define wxACTION_NOTEBOOK_NEXT wxT("nexttab")
  19. #define wxACTION_NOTEBOOK_PREV wxT("prevtab")
  20. #define wxACTION_NOTEBOOK_GOTO wxT("gototab")
  21. // ----------------------------------------------------------------------------
  22. // wxNotebook
  23. // ----------------------------------------------------------------------------
  24. class WXDLLIMPEXP_CORE wxNotebook : public wxNotebookBase
  25. {
  26. public:
  27. // ctors and such
  28. // --------------
  29. wxNotebook() { Init(); }
  30. wxNotebook(wxWindow *parent,
  31. wxWindowID id,
  32. const wxPoint& pos = wxDefaultPosition,
  33. const wxSize& size = wxDefaultSize,
  34. long style = 0,
  35. const wxString& name = wxNotebookNameStr)
  36. {
  37. Init();
  38. (void)Create(parent, id, pos, size, style, name);
  39. }
  40. // quasi ctor
  41. bool Create(wxWindow *parent,
  42. wxWindowID id,
  43. const wxPoint& pos = wxDefaultPosition,
  44. const wxSize& size = wxDefaultSize,
  45. long style = 0,
  46. const wxString& name = wxNotebookNameStr);
  47. // dtor
  48. virtual ~wxNotebook();
  49. // implement wxNotebookBase pure virtuals
  50. // --------------------------------------
  51. virtual int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); }
  52. // changes selected page without sending events
  53. int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); }
  54. virtual bool SetPageText(size_t nPage, const wxString& strText);
  55. virtual wxString GetPageText(size_t nPage) const;
  56. virtual int GetPageImage(size_t nPage) const;
  57. virtual bool SetPageImage(size_t nPage, int nImage);
  58. virtual void SetPageSize(const wxSize& size);
  59. virtual void SetPadding(const wxSize& padding);
  60. virtual void SetTabSize(const wxSize& sz);
  61. virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
  62. virtual bool DeleteAllPages();
  63. virtual bool InsertPage(size_t nPage,
  64. wxNotebookPage *pPage,
  65. const wxString& strText,
  66. bool bSelect = false,
  67. int imageId = NO_IMAGE);
  68. // style tests
  69. // -----------
  70. // return true if all tabs have the same width
  71. bool FixedSizeTabs() const { return HasFlag(wxNB_FIXEDWIDTH); }
  72. // return wxTOP/wxBOTTOM/wxRIGHT/wxLEFT
  73. wxDirection GetTabOrientation() const;
  74. // return true if the notebook has tabs at the sidesand not at the top (or
  75. // bottom) as usual
  76. bool IsVertical() const;
  77. // hit testing
  78. // -----------
  79. virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
  80. // input handling
  81. // --------------
  82. virtual bool PerformAction(const wxControlAction& action,
  83. long numArg = 0l,
  84. const wxString& strArg = wxEmptyString);
  85. static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
  86. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
  87. {
  88. return GetStdInputHandler(handlerDef);
  89. }
  90. // refresh the currently selected tab
  91. void RefreshCurrent();
  92. protected:
  93. virtual wxNotebookPage *DoRemovePage(size_t nPage);
  94. // drawing
  95. virtual void DoDraw(wxControlRenderer *renderer);
  96. void DoDrawTab(wxDC& dc, const wxRect& rect, size_t n);
  97. // resizing
  98. virtual void DoMoveWindow(int x, int y, int width, int height);
  99. virtual void DoSetSize(int x, int y,
  100. int width, int height,
  101. int sizeFlags = wxSIZE_AUTO);
  102. int DoSetSelection(size_t nPage, int flags = 0);
  103. // common part of all ctors
  104. void Init();
  105. // resize the tab to fit its title (and icon if any)
  106. void ResizeTab(int page);
  107. // recalculate the geometry of the notebook completely
  108. void Relayout();
  109. // is the spin button currently shown?
  110. bool HasSpinBtn() const;
  111. // calculate last (fully) visible tab: updates m_lastVisible
  112. void CalcLastVisibleTab();
  113. // show or hide the spin control for tabs scrolling depending on whether it
  114. // is needed or not
  115. void UpdateSpinBtn();
  116. // position the spin button
  117. void PositionSpinBtn();
  118. // refresh the given tab only
  119. void RefreshTab(int page, bool forceSelected = false);
  120. // refresh all tabs
  121. void RefreshAllTabs();
  122. // get the tab rect (inefficient, don't use this in a loop)
  123. wxRect GetTabRect(int page) const;
  124. // get the rectangle containing all tabs
  125. wxRect GetAllTabsRect() const;
  126. // get the part occupied by the tabs - slightly smaller than
  127. // GetAllTabsRect() because the tabs may be indented from it
  128. wxRect GetTabsPart() const;
  129. // calculate the tab size (without padding)
  130. wxSize CalcTabSize(int page) const;
  131. // get the (cached) size of a tab
  132. void GetTabSize(int page, wxCoord *w, wxCoord *h) const;
  133. // get the (cached) width of the tab
  134. wxCoord GetTabWidth(int page) const
  135. { return FixedSizeTabs() ? m_widthMax : m_widths[page]; }
  136. // return true if the tab has an associated image
  137. bool HasImage(int page) const
  138. { return HasImageList() && m_images[page] != -1; }
  139. // get the part of the notebook reserved for the pages (slightly larger
  140. // than GetPageRect() as we draw a border and leave marginin between)
  141. wxRect GetPagePart() const;
  142. // get the page rect in our client coords
  143. wxRect GetPageRect() const;
  144. // get our client size from the page size
  145. wxSize GetSizeForPage(const wxSize& size) const;
  146. // scroll the tabs so that the first page shown becomes the given one
  147. void ScrollTo(size_t page);
  148. // scroll the tabs so that the first page shown becomes the given one
  149. void ScrollLastTo(size_t page);
  150. // the pages titles
  151. wxArrayString m_titles;
  152. // the spin button to change the pages
  153. wxSpinButton *m_spinbtn;
  154. // the offset of the first page shown (may be changed with m_spinbtn)
  155. wxCoord m_offset;
  156. // the first and last currently visible tabs: the name is not completely
  157. // accurate as m_lastVisible is, in fact, the first tab which is *not*
  158. // visible: so the visible tabs are those with indexes such that
  159. // m_firstVisible <= n < m_lastVisible
  160. size_t m_firstVisible,
  161. m_lastVisible;
  162. // the last fully visible item, usually just m_lastVisible - 1 but may be
  163. // different from it
  164. size_t m_lastFullyVisible;
  165. // the height of tabs in a normal notebook or the width of tabs in a
  166. // notebook with tabs on a side
  167. wxCoord m_heightTab;
  168. // the biggest height (or width) of a notebook tab (used only if
  169. // FixedSizeTabs()) or -1 if not calculated yet
  170. wxCoord m_widthMax;
  171. // the cached widths (or heights) of tabs
  172. wxArrayInt m_widths;
  173. // the icon indices
  174. wxArrayInt m_images;
  175. // the accel indexes for labels
  176. wxArrayInt m_accels;
  177. // the padding
  178. wxSize m_sizePad;
  179. DECLARE_DYNAMIC_CLASS(wxNotebook)
  180. };
  181. #endif // _WX_UNIV_NOTEBOOK_H_