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