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