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