Common default notebook name.
[wxWidgets.git] / include / wx / univ / notebook.h
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$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_NOTEBOOK_H_
13 #define _WX_UNIV_NOTEBOOK_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "univnotebook.h"
17 #endif
18
19 #include "wx/arrstr.h"
20
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 = wxNotebookNameStr)
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 = wxNotebookNameStr);
63
64 // dtor
65 virtual ~wxNotebook();
66
67 // implement wxNotebookBase pure virtuals
68 // --------------------------------------
69
70 virtual int SetSelection(size_t nPage);
71 virtual int GetSelection() const { return m_sel; }
72
73 virtual bool SetPageText(size_t nPage, const wxString& strText);
74 virtual wxString GetPageText(size_t nPage) const;
75
76 virtual int GetPageImage(size_t nPage) const;
77 virtual bool SetPageImage(size_t nPage, int nImage);
78
79 virtual void SetPageSize(const wxSize& size);
80 virtual void SetPadding(const wxSize& padding);
81 virtual void SetTabSize(const wxSize& sz);
82
83 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
84
85 virtual bool DeleteAllPages();
86
87 virtual bool InsertPage(size_t nPage,
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 { return HasFlag(wxNB_FIXEDWIDTH); }
98
99 // return wxTOP/wxBOTTOM/wxRIGHT/wxLEFT
100 wxDirection GetTabOrientation() const;
101
102 // return true if the notebook has tabs at the sidesand not at the top (or
103 // bottom) as usual
104 bool IsVertical() const;
105
106 // hit testing
107 // -----------
108
109 virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
110
111 // input handling
112 // --------------
113
114 virtual bool PerformAction(const wxControlAction& action,
115 long numArg = 0l,
116 const wxString& strArg = wxEmptyString);
117
118 // refresh the currently selected tab
119 void RefreshCurrent();
120
121 protected:
122 virtual wxNotebookPage *DoRemovePage(size_t nPage);
123
124 // drawing
125 virtual void DoDraw(wxControlRenderer *renderer);
126 void DoDrawTab(wxDC& dc, const wxRect& rect, size_t n);
127
128 // resizing
129 virtual wxSize DoGetBestClientSize() const;
130 virtual void DoMoveWindow(int x, int y, int width, int height);
131 virtual void DoSetSize(int x, int y,
132 int width, int height,
133 int sizeFlags = wxSIZE_AUTO);
134
135 // common part of all ctors
136 void Init();
137
138 // resize the tab to fit its title (and icon if any)
139 void ResizeTab(int page);
140
141 // recalculate the geometry of the notebook completely
142 void Relayout();
143
144 // is the spin button currently shown?
145 bool HasSpinBtn() const;
146
147 // calculate last (fully) visible tab: updates m_lastVisible
148 void CalcLastVisibleTab();
149
150 // show or hide the spin control for tabs scrolling depending on whether it
151 // is needed or not
152 void UpdateSpinBtn();
153
154 // position the spin button
155 void PositionSpinBtn();
156
157 // refresh the given tab only
158 void RefreshTab(int page, bool forceSelected = false);
159
160 // refresh all tabs
161 void RefreshAllTabs();
162
163 // get the tab rect (inefficient, don't use this in a loop)
164 wxRect GetTabRect(int page) const;
165
166 // get the rectangle containing all tabs
167 wxRect GetAllTabsRect() const;
168
169 // get the part occupied by the tabs - slightly smaller than
170 // GetAllTabsRect() because the tabs may be indented from it
171 wxRect GetTabsPart() const;
172
173 // calculate the tab size (without padding)
174 wxSize CalcTabSize(int page) const;
175
176 // get the (cached) size of a tab
177 void GetTabSize(int page, wxCoord *w, wxCoord *h) const;
178
179 // get the (cached) width of the tab
180 wxCoord GetTabWidth(int page) const
181 { return FixedSizeTabs() ? m_widthMax : m_widths[page]; }
182
183 // return true if the tab has an associated image
184 bool HasImage(int page) const
185 { return m_imageList && m_images[page] != -1; }
186
187 // get the part of the notebook reserved for the pages (slightly larger
188 // than GetPageRect() as we draw a border and leave marginin between)
189 wxRect GetPagePart() const;
190
191 // get the page rect in our client coords
192 wxRect GetPageRect() const;
193
194 // get our client size from the page size
195 wxSize GetSizeForPage(const wxSize& size) const;
196
197 // scroll the tabs so that the first page shown becomes the given one
198 void ScrollTo(int page);
199
200 // scroll the tabs so that the first page shown becomes the given one
201 void ScrollLastTo(int page);
202
203 // the pages titles
204 wxArrayString m_titles;
205
206 // the current selection
207 size_t m_sel;
208
209 // the spin button to change the pages
210 wxSpinButton *m_spinbtn;
211
212 // the offset of the first page shown (may be changed with m_spinbtn)
213 wxCoord m_offset;
214
215 // the first and last currently visible tabs: the name is not completely
216 // accurate as m_lastVisible is, in fact, the first tab which is *not*
217 // visible: so the visible tabs are those with indexes such that
218 // m_firstVisible <= n < m_lastVisible
219 size_t m_firstVisible,
220 m_lastVisible;
221
222 // the last fully visible item, usually just m_lastVisible - 1 but may be
223 // different from it
224 size_t m_lastFullyVisible;
225
226 // the height of tabs in a normal notebook or the width of tabs in a
227 // notebook with tabs on a side
228 wxCoord m_heightTab;
229
230 // the biggest height (or width) of a notebook tab (used only if
231 // FixedSizeTabs()) or -1 if not calculated yet
232 wxCoord m_widthMax;
233
234 // the cached widths (or heights) of tabs
235 wxArrayInt m_widths;
236
237 // the icon indices
238 wxArrayInt m_images;
239
240 // the accel indexes for labels
241 wxArrayInt m_accels;
242
243 // the padding
244 wxSize m_sizePad;
245
246 DECLARE_DYNAMIC_CLASS(wxNotebook)
247 };
248
249 // ----------------------------------------------------------------------------
250 // wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse
251 // click into button press/release actions
252 // ----------------------------------------------------------------------------
253
254 class WXDLLEXPORT wxStdNotebookInputHandler : public wxStdInputHandler
255 {
256 public:
257 wxStdNotebookInputHandler(wxInputHandler *inphand);
258
259 virtual bool HandleKey(wxInputConsumer *consumer,
260 const wxKeyEvent& event,
261 bool pressed);
262 virtual bool HandleMouse(wxInputConsumer *consumer,
263 const wxMouseEvent& event);
264 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
265 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
266 virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
267
268 protected:
269 void HandleFocusChange(wxInputConsumer *consumer);
270 };
271
272 #endif // _WX_UNIV_NOTEBOOK_H_
273