1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/notebook.h
3 // Purpose: universal version of wxNotebook
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_NOTEBOOK_H_
13 #define _WX_UNIV_NOTEBOOK_H_
16 #pragma interface "notebook.h"
19 class WXDLLEXPORT wxSpinButton
;
21 // ----------------------------------------------------------------------------
22 // the actions supported by this control
23 // ----------------------------------------------------------------------------
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")
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class WXDLLEXPORT wxNotebook
: public wxNotebookBase
40 wxNotebook() { Init(); }
42 wxNotebook(wxWindow
*parent
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
47 const wxString
& name
= wxNOTEBOOK_NAME
)
51 (void)Create(parent
, id
, pos
, size
, style
, name
);
55 bool Create(wxWindow
*parent
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
60 const wxString
& name
= wxNOTEBOOK_NAME
);
63 virtual ~wxNotebook();
65 // implement wxNotebookBase pure virtuals
66 // --------------------------------------
68 virtual int SetSelection(int nPage
);
69 virtual int GetSelection() const { return m_sel
; }
71 virtual bool SetPageText(int nPage
, const wxString
& strText
);
72 virtual wxString
GetPageText(int nPage
) const;
74 virtual int GetPageImage(int nPage
) const;
75 virtual bool SetPageImage(int nPage
, int nImage
);
77 virtual void SetPageSize(const wxSize
& size
);
78 virtual void SetPadding(const wxSize
& padding
);
79 virtual void SetTabSize(const wxSize
& sz
);
81 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
);
83 virtual bool DeleteAllPages();
85 virtual bool InsertPage(int nPage
,
86 wxNotebookPage
*pPage
,
87 const wxString
& strText
,
94 // return TRUE if all tabs have the same width
95 bool FixedSizeTabs() const
96 { return GetWindowStyle() & wxNB_FIXEDWIDTH
!= 0; }
98 // return wxTOP/wxBOTTOM/wxRIGHT/wxLEFT
99 wxDirection
GetTabOrientation() const;
101 // return TRUE if the notebook has tabs at the sidesand not at the top (or
103 bool IsVertical() const;
108 // return the tab at this position or -1 if none
109 int HitTest(const wxPoint
& pt
) const;
114 virtual bool PerformAction(const wxControlAction
& action
,
116 const wxString
& strArg
= wxEmptyString
);
118 // refresh the currently selected tab
119 void RefreshCurrent();
122 virtual wxNotebookPage
*DoRemovePage(int nPage
);
125 virtual void DoDraw(wxControlRenderer
*renderer
);
126 void DoDrawTab(wxDC
& dc
, const wxRect
& rect
, size_t n
);
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
);
135 // common part of all ctors
138 // resize the tab to fit its title (and icon if any)
139 void ResizeTab(int page
);
141 // recalculate the geometry of the notebook completely
144 // is the spin button currently shown?
145 bool HasSpinBtn() const;
147 // calculate last (fully) visible tab: updates m_lastVisible
148 void CalcLastVisibleTab();
150 // show or hide the spin control for tabs scrolling depending on whether it
152 void UpdateSpinBtn();
154 // position the spin button
155 void PositionSpinBtn();
157 // refresh the given tab only
158 void RefreshTab(int page
);
161 void RefreshAllTabs();
163 // get the tab rect (inefficient, don't use this in a loop)
164 wxRect
GetTabRect(int page
) const;
166 // get the rectangle containing all tabs
167 wxRect
GetAllTabsRect() const;
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;
173 // calculate the tab size (without padding)
174 wxSize
CalcTabSize(int page
) const;
176 // get the (cached) size of a tab
177 void GetTabSize(int page
, wxCoord
*w
, wxCoord
*h
) const;
179 // get the (cached) width of the tab
180 wxCoord
GetTabWidth(int page
) const
181 { return FixedSizeTabs() ? m_widthMax
: m_widths
[page
]; }
183 // return TRUE if the tab has an associated image
184 bool HasImage(int page
) const
185 { return m_imageList
&& m_images
[page
] != -1; }
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;
191 // get the page rect in our client coords
192 wxRect
GetPageRect() const;
194 // get our client size from the page size
195 wxSize
GetSizeForPage(const wxSize
& size
) const;
197 // change thep age and send events about it (can be vetoed by user code)
198 void ChangePage(int nPage
);
200 // scroll the tabs so that the first page shown becomes the given one
201 void ScrollTo(int page
);
203 // scroll the tabs so that the first page shown becomes the given one
204 void ScrollLastTo(int page
);
207 wxArrayString m_titles
;
209 // the current selection
212 // the spin button to change the pages
213 wxSpinButton
*m_spinbtn
;
215 // the offset of the first page shown (may be changed with m_spinbtn)
218 // the first and last currently visible tabs: the name is not completely
219 // accurate as m_lastVisible is, in fact, the first tab which is *not*
220 // visible: so the visible tabs are those with indexes such that
221 // m_firstVisible <= n < m_lastVisible
222 size_t m_firstVisible
,
225 // the last fully visible item, usually just m_lastVisible - 1 but may be
227 size_t m_lastFullyVisible
;
229 // the height of tabs in a normal notebook or the width of tabs in a
230 // notebook with tabs on a side
233 // the biggest height (or width) of a notebook tab (used only if
234 // FixedSizeTabs()) or -1 if not calculated yet
237 // the cached widths (or heights) of tabs
243 // the accel indexes for labels
249 DECLARE_DYNAMIC_CLASS(wxNotebook
)
252 // ----------------------------------------------------------------------------
253 // wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse
254 // click into button press/release actions
255 // ----------------------------------------------------------------------------
257 class WXDLLEXPORT wxStdNotebookInputHandler
: public wxStdInputHandler
260 wxStdNotebookInputHandler(wxInputHandler
*inphand
);
262 virtual bool HandleKey(wxControl
*control
,
263 const wxKeyEvent
& event
,
265 virtual bool HandleMouse(wxControl
*control
,
266 const wxMouseEvent
& event
);
267 virtual bool HandleMouseMove(wxControl
*control
, const wxMouseEvent
& event
);
268 virtual bool HandleFocus(wxControl
*control
, const wxFocusEvent
& event
);
269 virtual bool HandleActivation(wxControl
*control
, bool activated
);
272 void HandleFocusChange(wxControl
*control
);
275 #endif // _WX_UNIV_NOTEBOOK_H_