]> git.saurik.com Git - wxWidgets.git/blame - include/wx/notebook.h
Fix for wxTextCtrl::GetSelection for singel line controls in GTK2 mode
[wxWidgets.git] / include / wx / notebook.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/notebook.h
3// Purpose: wxNotebook interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 01.02.01
7// RCS-ID: $Id$
8// Copyright: (c) 1996-2000 wxWindows team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_NOTEBOOK_H_BASE_
13#define _WX_NOTEBOOK_H_BASE_
53b28675 14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
07b8d7ec
VZ
16 #pragma interface "notebookbase.h"
17#endif
18
4d0f3cd6
VZ
19// ----------------------------------------------------------------------------
20// headers
21// ----------------------------------------------------------------------------
22
1e6feb95
VZ
23#include "wx/defs.h"
24
25#if wxUSE_NOTEBOOK
26
27#include "wx/control.h"
28#include "wx/dynarray.h"
3cd94a0d 29#include "wx/imaglist.h"
1e6feb95 30
e450aa69
VZ
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
34
35// wxNotebook hit results
36enum
37{
38 wxNB_HITTEST_NOWHERE = 1, // not on tab
39 wxNB_HITTEST_ONICON = 2, // on icon
40 wxNB_HITTEST_ONLABEL = 4, // on label
41 wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL
42};
43
1e6feb95
VZ
44// ----------------------------------------------------------------------------
45// types
46// ----------------------------------------------------------------------------
47
48// array of notebook pages
49typedef wxWindow wxNotebookPage; // so far, any window can be a page
50
6108e3fd 51WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxNotebookPage *, wxArrayPages);
1e6feb95
VZ
52
53#define wxNOTEBOOK_NAME _T("notebook")
54
55// ----------------------------------------------------------------------------
56// wxNotebookBase: define wxNotebook interface
57// ----------------------------------------------------------------------------
58
59class WXDLLEXPORT wxNotebookBase : public wxControl
60{
61public:
62 // ctor
63 wxNotebookBase()
64 {
07b8d7ec 65 Init();
1e6feb95
VZ
66 }
67
68 // quasi ctor
69 bool Create(wxWindow *parent,
70 wxWindowID id,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxString& name = wxNOTEBOOK_NAME);
75
07b8d7ec
VZ
76 // dtor
77 virtual ~wxNotebookBase();
78
1e6feb95
VZ
79 // accessors
80 // ---------
81
82 // get number of pages in the dialog
083f7497 83 int GetPageCount() const { return (int) m_pages.GetCount(); }
1e6feb95
VZ
84
85 // get the panel which represents the given page
86 wxNotebookPage *GetPage(int nPage) { return m_pages[nPage]; }
87
88 // get the currently selected page
89 virtual int GetSelection() const = 0;
90
91 // set/get the title of a page
92 virtual bool SetPageText(int nPage, const wxString& strText) = 0;
93 virtual wxString GetPageText(int nPage) const = 0;
94
95 // image list stuff: each page may have an image associated with it (all
96 // images belong to the same image list)
07b8d7ec
VZ
97 virtual void SetImageList(wxImageList* imageList);
98
99 // as SetImageList() but we will delete the image list ourselves
100 void AssignImageList(wxImageList* imageList);
1e6feb95
VZ
101
102 // get pointer (may be NULL) to the associated image list
103 wxImageList* GetImageList() const { return m_imageList; }
104
105 // sets/returns item's image index in the current image list
106 virtual int GetPageImage(int nPage) const = 0;
107 virtual bool SetPageImage(int nPage, int nImage) = 0;
108
109 // get the number of rows for a control with wxNB_MULTILINE style (not all
110 // versions support it - they will always return 1 then)
111 virtual int GetRowCount() const { return 1; }
112
113 // set the size (the same for all pages)
114 virtual void SetPageSize(const wxSize& size) = 0;
115
116 // set the padding between tabs (in pixels)
117 virtual void SetPadding(const wxSize& padding) = 0;
118
119 // set the size of the tabs for wxNB_FIXEDWIDTH controls
120 virtual void SetTabSize(const wxSize& sz) = 0;
121
122 // calculate the size of the notebook from the size of its page
2ce7af35 123 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
1e6feb95
VZ
124
125 // operations
126 // ----------
127
128 // remove one page from the notebook and delete it
07b8d7ec 129 virtual bool DeletePage(int nPage);
1e6feb95
VZ
130
131 // remove one page from the notebook, without deleting it
132 virtual bool RemovePage(int nPage) { return DoRemovePage(nPage) != NULL; }
133
134 // remove all pages and delete them
135 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return TRUE; }
136
137 // adds a new page to the notebook (it will be deleted by the notebook,
138 // don't delete it yourself) and make it the current one if bSelect
139 virtual bool AddPage(wxNotebookPage *pPage,
140 const wxString& strText,
141 bool bSelect = FALSE,
142 int imageId = -1)
143 {
144 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
145 }
146
147 // the same as AddPage(), but adds the page at the specified position
148 virtual bool InsertPage(int nPage,
149 wxNotebookPage *pPage,
150 const wxString& strText,
151 bool bSelect = FALSE,
152 int imageId = -1) = 0;
153
154 // set the currently selected page, return the index of the previously
155 // selected one (or -1 on error)
156 //
157 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
158 virtual int SetSelection(int nPage) = 0;
159
e450aa69
VZ
160 // hit test, returns which tab is hit and, optionally, where (icon, label)
161 // (not implemented on all platforms)
fc7a2a60
VZ
162 virtual int HitTest(const wxPoint& WXUNUSED(pt),
163 long * WXUNUSED(flags) = NULL) const
e450aa69
VZ
164 {
165 return wxNOT_FOUND;
166 }
167
1e6feb95
VZ
168 // cycle thru the tabs
169 void AdvanceSelection(bool forward = TRUE)
170 {
171 int nPage = GetNextPage(forward);
172 if ( nPage != -1 )
173 SetSelection(nPage);
174 }
175
176protected:
177 // remove the page and return a pointer to it
10199e27 178 virtual wxNotebookPage *DoRemovePage(int page);
2ce7af35
JS
179 // return the minimum size large enough to display the largest page entirely
180 virtual wxSize DoGetBestSize() const;
1e6feb95 181
07b8d7ec
VZ
182 // common part of all ctors
183 void Init();
1e6feb95 184
07b8d7ec
VZ
185 // get the next page wrapping if we reached the end
186 int GetNextPage(bool forward) const;
1e6feb95 187
07b8d7ec
VZ
188 wxArrayPages m_pages; // array of pages
189 wxImageList *m_imageList; // we can have an associated image list
190 bool m_ownsImageList; // true if we must delete m_imageList
22f3361e
VZ
191
192 DECLARE_NO_COPY_CLASS(wxNotebookBase)
1e6feb95 193};
4d0f3cd6
VZ
194
195// ----------------------------------------------------------------------------
196// notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
197// ----------------------------------------------------------------------------
198
199class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
200{
201public:
202 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
203 int nSel = -1, int nOldSel = -1)
204 : wxNotifyEvent(commandType, id)
205 {
206 m_nSel = nSel;
207 m_nOldSel = nOldSel;
208 }
209
210 // accessors
211 // the currently selected page (-1 if none)
212 int GetSelection() const { return m_nSel; }
213 void SetSelection(int nSel) { m_nSel = nSel; }
214 // the page that was selected before the change (-1 if none)
215 int GetOldSelection() const { return m_nOldSel; }
216 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
217
218private:
219 int m_nSel, // currently selected page
220 m_nOldSel; // previously selected page
221
fc7a2a60 222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebookEvent)
4d0f3cd6
VZ
223};
224
225// ----------------------------------------------------------------------------
2e4df4bf 226// event types and macros for them
4d0f3cd6
VZ
227// ----------------------------------------------------------------------------
228
2e4df4bf
VZ
229BEGIN_DECLARE_EVENT_TYPES()
230 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 802)
231 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 803)
232END_DECLARE_EVENT_TYPES()
233
4d0f3cd6
VZ
234typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
235
236#define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
2e4df4bf 237 DECLARE_EVENT_TABLE_ENTRY( \
4d0f3cd6
VZ
238 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
239 id, \
240 -1, \
241 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
242 NULL \
82a5f02c 243 ),
4d0f3cd6
VZ
244
245#define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
2e4df4bf 246 DECLARE_EVENT_TABLE_ENTRY( \
4d0f3cd6
VZ
247 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
248 id, \
249 -1, \
250 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
251 NULL \
82a5f02c 252 ),
4d0f3cd6
VZ
253
254// ----------------------------------------------------------------------------
255// wxNotebook class itself
256// ----------------------------------------------------------------------------
257
1e6feb95
VZ
258#if defined(__WXUNIVERSAL__)
259 #include "wx/univ/notebook.h"
260#elif defined(__WXMSW__)
aaace873 261 #include "wx/msw/notebook.h"
2049ba38 262#elif defined(__WXMOTIF__)
1e6feb95 263 #include "wx/generic/notebook.h"
2049ba38 264#elif defined(__WXGTK__)
1e6feb95 265 #include "wx/gtk/notebook.h"
34138703 266#elif defined(__WXMAC__)
1e6feb95 267 #include "wx/mac/notebook.h"
0201182b
DE
268#elif defined(__WXCOCOA__)
269 #include "wx/generic/notebook.h"
1777b9bb 270#elif defined(__WXPM__)
1e6feb95 271 #include "wx/os2/notebook.h"
53b28675
RR
272#endif
273
1e6feb95
VZ
274#endif // wxUSE_NOTEBOOK
275
53b28675 276#endif
34138703 277 // _WX_NOTEBOOK_H_BASE_