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_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "univnotebook.h"
19 #include "wx/arrstr.h"
21 class WXDLLEXPORT wxSpinButton
;
23 // ----------------------------------------------------------------------------
24 // the actions supported by this control
25 // ----------------------------------------------------------------------------
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")
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxNotebook
: public wxNotebookBase
44 wxNotebook(wxWindow
*parent
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
49 const wxString
& name
= wxNOTEBOOK_NAME
);
52 bool Create(wxWindow
*parent
,
54 const wxPoint
& pos
= wxDefaultPosition
,
55 const wxSize
& size
= wxDefaultSize
,
57 const wxString
& name
= wxNOTEBOOK_NAME
);
60 virtual ~wxNotebook();
62 // implement wxNotebookBase pure virtuals
63 // --------------------------------------
65 virtual int SetSelection(size_t nPage
);
66 virtual int GetSelection() const { return m_sel
; }
68 virtual bool SetPageText(size_t nPage
, const wxString
& strText
);
69 virtual wxString
GetPageText(size_t nPage
) const;
71 virtual int GetPageImage(size_t nPage
) const;
72 virtual bool SetPageImage(size_t nPage
, int nImage
);
74 virtual void SetPageSize(const wxSize
& size
);
75 virtual void SetPadding(const wxSize
& padding
);
76 virtual void SetTabSize(const wxSize
& sz
);
78 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
) const;
80 virtual bool DeleteAllPages();
82 virtual bool InsertPage(size_t nPage
,
83 wxNotebookPage
*pPage
,
84 const wxString
& strText
,
91 // return TRUE if all tabs have the same width
92 bool FixedSizeTabs() const { return HasFlag(wxNB_FIXEDWIDTH
); }
94 // return wxTOP/wxBOTTOM/wxRIGHT/wxLEFT
95 wxDirection
GetTabOrientation() const;
97 // return TRUE if the notebook has tabs at the sidesand not at the top (or
99 bool IsVertical() const;
104 virtual int HitTest(const wxPoint
& pt
, long *flags
= NULL
) const;
109 virtual bool PerformAction(const wxControlAction
& action
,
111 const wxString
& strArg
= wxEmptyString
);
113 // refresh the currently selected tab
114 void RefreshCurrent();
117 virtual wxNotebookPage
*DoRemovePage(size_t nPage
);
120 virtual void DoDraw(wxControlRenderer
*renderer
);
121 void DoDrawTab(wxDC
& dc
, const wxRect
& rect
, size_t n
);
124 virtual wxSize
DoGetBestClientSize() const;
125 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
126 virtual void DoSetSize(int x
, int y
,
127 int width
, int height
,
128 int sizeFlags
= wxSIZE_AUTO
);
130 // common part of all ctors
133 // resize the tab to fit its title (and icon if any)
134 void ResizeTab(int page
);
136 // recalculate the geometry of the notebook completely
139 // is the spin button currently shown?
140 bool HasSpinBtn() const;
142 // calculate last (fully) visible tab: updates m_lastVisible
143 void CalcLastVisibleTab();
145 // show or hide the spin control for tabs scrolling depending on whether it
147 void UpdateSpinBtn();
149 // position the spin button
150 void PositionSpinBtn();
152 // refresh the given tab only
153 void RefreshTab(int page
, bool forceSelected
= FALSE
);
156 void RefreshAllTabs();
158 // get the tab rect (inefficient, don't use this in a loop)
159 wxRect
GetTabRect(int page
) const;
161 // get the rectangle containing all tabs
162 wxRect
GetAllTabsRect() const;
164 // get the part occupied by the tabs - slightly smaller than
165 // GetAllTabsRect() because the tabs may be indented from it
166 wxRect
GetTabsPart() const;
168 // calculate the tab size (without padding)
169 wxSize
CalcTabSize(int page
) const;
171 // get the (cached) size of a tab
172 void GetTabSize(int page
, wxCoord
*w
, wxCoord
*h
) const;
174 // get the (cached) width of the tab
175 wxCoord
GetTabWidth(int page
) const
176 { return FixedSizeTabs() ? m_widthMax
: m_widths
[page
]; }
178 // return TRUE if the tab has an associated image
179 bool HasImage(int page
) const
180 { return m_imageList
&& m_images
[page
] != -1; }
182 // get the part of the notebook reserved for the pages (slightly larger
183 // than GetPageRect() as we draw a border and leave marginin between)
184 wxRect
GetPagePart() const;
186 // get the page rect in our client coords
187 wxRect
GetPageRect() const;
189 // get our client size from the page size
190 wxSize
GetSizeForPage(const wxSize
& size
) const;
192 // scroll the tabs so that the first page shown becomes the given one
193 void ScrollTo(int page
);
195 // scroll the tabs so that the first page shown becomes the given one
196 void ScrollLastTo(int page
);
199 wxArrayString m_titles
;
201 // the current selection
204 // the spin button to change the pages
205 wxSpinButton
*m_spinbtn
;
207 // the offset of the first page shown (may be changed with m_spinbtn)
210 // the first and last currently visible tabs: the name is not completely
211 // accurate as m_lastVisible is, in fact, the first tab which is *not*
212 // visible: so the visible tabs are those with indexes such that
213 // m_firstVisible <= n < m_lastVisible
214 size_t m_firstVisible
,
217 // the last fully visible item, usually just m_lastVisible - 1 but may be
219 size_t m_lastFullyVisible
;
221 // the height of tabs in a normal notebook or the width of tabs in a
222 // notebook with tabs on a side
225 // the biggest height (or width) of a notebook tab (used only if
226 // FixedSizeTabs()) or -1 if not calculated yet
229 // the cached widths (or heights) of tabs
235 // the accel indexes for labels
241 DECLARE_DYNAMIC_CLASS(wxNotebook
)
244 // ----------------------------------------------------------------------------
245 // wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse
246 // click into button press/release actions
247 // ----------------------------------------------------------------------------
249 class WXDLLEXPORT wxStdNotebookInputHandler
: public wxStdInputHandler
252 wxStdNotebookInputHandler(wxInputHandler
*inphand
);
254 virtual bool HandleKey(wxInputConsumer
*consumer
,
255 const wxKeyEvent
& event
,
257 virtual bool HandleMouse(wxInputConsumer
*consumer
,
258 const wxMouseEvent
& event
);
259 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
260 virtual bool HandleFocus(wxInputConsumer
*consumer
, const wxFocusEvent
& event
);
261 virtual bool HandleActivation(wxInputConsumer
*consumer
, bool activated
);
264 void HandleFocusChange(wxInputConsumer
*consumer
);
267 #endif // _WX_UNIV_NOTEBOOK_H_