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