]>
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) |
1e6feb95 VZ |
9 | // Licence: wxWindows licence |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_UNIV_NOTEBOOK_H_ | |
13 | #define _WX_UNIV_NOTEBOOK_H_ | |
14 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a3870b2f | 16 | #pragma interface "univnotebook.h" |
1e6feb95 VZ |
17 | #endif |
18 | ||
b5435dcc MB |
19 | #include "wx/arrstr.h" |
20 | ||
1e6feb95 VZ |
21 | class WXDLLEXPORT wxSpinButton; |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // the actions supported by this control | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | // change the page: to the next/previous/given one | |
28 | #define wxACTION_NOTEBOOK_NEXT _T("nexttab") | |
29 | #define wxACTION_NOTEBOOK_PREV _T("prevtab") | |
30 | #define wxACTION_NOTEBOOK_GOTO _T("gototab") | |
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // wxNotebook | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | class WXDLLEXPORT wxNotebook : public wxNotebookBase | |
37 | { | |
38 | public: | |
39 | // ctors and such | |
40 | // -------------- | |
41 | ||
42 | wxNotebook() { Init(); } | |
43 | ||
44 | wxNotebook(wxWindow *parent, | |
45 | wxWindowID id, | |
46 | const wxPoint& pos = wxDefaultPosition, | |
47 | const wxSize& size = wxDefaultSize, | |
48 | long style = 0, | |
49 | const wxString& name = wxNOTEBOOK_NAME) | |
50 | { | |
51 | Init(); | |
52 | ||
53 | (void)Create(parent, id, pos, size, style, name); | |
54 | } | |
55 | ||
56 | // quasi ctor | |
57 | bool Create(wxWindow *parent, | |
58 | wxWindowID id, | |
59 | const wxPoint& pos = wxDefaultPosition, | |
60 | const wxSize& size = wxDefaultSize, | |
61 | long style = 0, | |
62 | const wxString& name = wxNOTEBOOK_NAME); | |
63 | ||
64 | // dtor | |
65 | virtual ~wxNotebook(); | |
66 | ||
67 | // implement wxNotebookBase pure virtuals | |
68 | // -------------------------------------- | |
69 | ||
15aad3b9 | 70 | virtual int SetSelection(size_t nPage); |
1e6feb95 VZ |
71 | virtual int GetSelection() const { return m_sel; } |
72 | ||
15aad3b9 VZ |
73 | virtual bool SetPageText(size_t nPage, const wxString& strText); |
74 | virtual wxString GetPageText(size_t nPage) const; | |
1e6feb95 | 75 | |
15aad3b9 VZ |
76 | virtual int GetPageImage(size_t nPage) const; |
77 | virtual bool SetPageImage(size_t nPage, int nImage); | |
1e6feb95 VZ |
78 | |
79 | virtual void SetPageSize(const wxSize& size); | |
80 | virtual void SetPadding(const wxSize& padding); | |
81 | virtual void SetTabSize(const wxSize& sz); | |
82 | ||
2ce7af35 | 83 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; |
1e6feb95 VZ |
84 | |
85 | virtual bool DeleteAllPages(); | |
86 | ||
15aad3b9 | 87 | virtual bool InsertPage(size_t nPage, |
1e6feb95 VZ |
88 | wxNotebookPage *pPage, |
89 | const wxString& strText, | |
90 | bool bSelect = FALSE, | |
91 | int imageId = -1); | |
92 | ||
93 | // style tests | |
94 | // ----------- | |
95 | ||
96 | // return TRUE if all tabs have the same width | |
97 | bool FixedSizeTabs() const | |
98 | { return GetWindowStyle() & wxNB_FIXEDWIDTH != 0; } | |
99 | ||
100 | // return wxTOP/wxBOTTOM/wxRIGHT/wxLEFT | |
101 | wxDirection GetTabOrientation() const; | |
102 | ||
103 | // return TRUE if the notebook has tabs at the sidesand not at the top (or | |
104 | // bottom) as usual | |
105 | bool IsVertical() const; | |
106 | ||
107 | // hit testing | |
108 | // ----------- | |
109 | ||
e450aa69 | 110 | virtual int HitTest(const wxPoint& pt, long *flags = NULL) const; |
1e6feb95 VZ |
111 | |
112 | // input handling | |
113 | // -------------- | |
114 | ||
115 | virtual bool PerformAction(const wxControlAction& action, | |
116 | long numArg = 0l, | |
117 | const wxString& strArg = wxEmptyString); | |
118 | ||
119 | // refresh the currently selected tab | |
120 | void RefreshCurrent(); | |
121 | ||
122 | protected: | |
15aad3b9 | 123 | virtual wxNotebookPage *DoRemovePage(size_t nPage); |
1e6feb95 VZ |
124 | |
125 | // drawing | |
126 | virtual void DoDraw(wxControlRenderer *renderer); | |
127 | void DoDrawTab(wxDC& dc, const wxRect& rect, size_t n); | |
128 | ||
129 | // resizing | |
130 | virtual wxSize DoGetBestClientSize() const; | |
131 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
132 | virtual void DoSetSize(int x, int y, | |
133 | int width, int height, | |
134 | int sizeFlags = wxSIZE_AUTO); | |
135 | ||
136 | // common part of all ctors | |
137 | void Init(); | |
138 | ||
139 | // resize the tab to fit its title (and icon if any) | |
140 | void ResizeTab(int page); | |
141 | ||
142 | // recalculate the geometry of the notebook completely | |
143 | void Relayout(); | |
144 | ||
145 | // is the spin button currently shown? | |
146 | bool HasSpinBtn() const; | |
147 | ||
148 | // calculate last (fully) visible tab: updates m_lastVisible | |
149 | void CalcLastVisibleTab(); | |
150 | ||
151 | // show or hide the spin control for tabs scrolling depending on whether it | |
152 | // is needed or not | |
153 | void UpdateSpinBtn(); | |
154 | ||
155 | // position the spin button | |
156 | void PositionSpinBtn(); | |
157 | ||
158 | // refresh the given tab only | |
1d8c3e58 | 159 | void RefreshTab(int page, bool forceSelected = FALSE); |
1e6feb95 VZ |
160 | |
161 | // refresh all tabs | |
162 | void RefreshAllTabs(); | |
163 | ||
164 | // get the tab rect (inefficient, don't use this in a loop) | |
165 | wxRect GetTabRect(int page) const; | |
166 | ||
167 | // get the rectangle containing all tabs | |
168 | wxRect GetAllTabsRect() const; | |
169 | ||
170 | // get the part occupied by the tabs - slightly smaller than | |
171 | // GetAllTabsRect() because the tabs may be indented from it | |
172 | wxRect GetTabsPart() const; | |
173 | ||
174 | // calculate the tab size (without padding) | |
175 | wxSize CalcTabSize(int page) const; | |
176 | ||
177 | // get the (cached) size of a tab | |
178 | void GetTabSize(int page, wxCoord *w, wxCoord *h) const; | |
179 | ||
180 | // get the (cached) width of the tab | |
181 | wxCoord GetTabWidth(int page) const | |
182 | { return FixedSizeTabs() ? m_widthMax : m_widths[page]; } | |
183 | ||
184 | // return TRUE if the tab has an associated image | |
185 | bool HasImage(int page) const | |
186 | { return m_imageList && m_images[page] != -1; } | |
187 | ||
188 | // get the part of the notebook reserved for the pages (slightly larger | |
189 | // than GetPageRect() as we draw a border and leave marginin between) | |
190 | wxRect GetPagePart() const; | |
191 | ||
192 | // get the page rect in our client coords | |
193 | wxRect GetPageRect() const; | |
194 | ||
195 | // get our client size from the page size | |
196 | wxSize GetSizeForPage(const wxSize& size) const; | |
197 | ||
1e6feb95 VZ |
198 | // scroll the tabs so that the first page shown becomes the given one |
199 | void ScrollTo(int page); | |
200 | ||
201 | // scroll the tabs so that the first page shown becomes the given one | |
202 | void ScrollLastTo(int page); | |
203 | ||
204 | // the pages titles | |
205 | wxArrayString m_titles; | |
206 | ||
207 | // the current selection | |
208 | size_t m_sel; | |
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 | DECLARE_DYNAMIC_CLASS(wxNotebook) | |
248 | }; | |
249 | ||
250 | // ---------------------------------------------------------------------------- | |
251 | // wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse | |
252 | // click into button press/release actions | |
253 | // ---------------------------------------------------------------------------- | |
254 | ||
255 | class WXDLLEXPORT wxStdNotebookInputHandler : public wxStdInputHandler | |
256 | { | |
257 | public: | |
258 | wxStdNotebookInputHandler(wxInputHandler *inphand); | |
259 | ||
23645bfa | 260 | virtual bool HandleKey(wxInputConsumer *consumer, |
1e6feb95 VZ |
261 | const wxKeyEvent& event, |
262 | bool pressed); | |
23645bfa | 263 | virtual bool HandleMouse(wxInputConsumer *consumer, |
1e6feb95 | 264 | const wxMouseEvent& event); |
23645bfa VS |
265 | virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event); |
266 | virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event); | |
267 | virtual bool HandleActivation(wxInputConsumer *consumer, bool activated); | |
1e6feb95 VZ |
268 | |
269 | protected: | |
23645bfa | 270 | void HandleFocusChange(wxInputConsumer *consumer); |
1e6feb95 VZ |
271 | }; |
272 | ||
273 | #endif // _WX_UNIV_NOTEBOOK_H_ | |
274 |