]>
Commit | Line | Data |
---|---|---|
15aad3b9 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/bookctrl.h | |
3 | // Purpose: wxBookCtrl: common base class for wxList/Tree/Notebook | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 19.08.03 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
15aad3b9 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BOOKCTRL_H_ | |
13 | #define _WX_BOOKCTRL_H_ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "bookctrl.h" | |
17 | #endif | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // headers | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
25 | #if wxUSE_BOOKCTRL | |
26 | ||
27 | #include "wx/control.h" | |
28 | #include "wx/dynarray.h" | |
29 | ||
d5d29b8a | 30 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages); |
15aad3b9 VZ |
31 | |
32 | class WXDLLEXPORT wxImageList; | |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // wxBookCtrl | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxBookCtrl : public wxControl | |
39 | { | |
40 | public: | |
41 | // construction | |
42 | // ------------ | |
43 | ||
6463b9f5 JS |
44 | wxBookCtrl() |
45 | { | |
46 | Init(); | |
47 | } | |
15aad3b9 VZ |
48 | |
49 | wxBookCtrl(wxWindow *parent, | |
aa6f64c7 | 50 | wxWindowID winid, |
15aad3b9 VZ |
51 | const wxPoint& pos = wxDefaultPosition, |
52 | const wxSize& size = wxDefaultSize, | |
53 | long style = 0, | |
6463b9f5 JS |
54 | const wxString& name = wxEmptyString) |
55 | { | |
56 | Init(); | |
57 | ||
58 | (void)Create(parent, winid, pos, size, style, name); | |
59 | } | |
15aad3b9 VZ |
60 | |
61 | // quasi ctor | |
62 | bool Create(wxWindow *parent, | |
aa6f64c7 | 63 | wxWindowID winid, |
15aad3b9 VZ |
64 | const wxPoint& pos = wxDefaultPosition, |
65 | const wxSize& size = wxDefaultSize, | |
66 | long style = 0, | |
67 | const wxString& name = wxEmptyString); | |
68 | ||
69 | // dtor | |
70 | virtual ~wxBookCtrl(); | |
71 | ||
72 | ||
73 | // accessors | |
74 | // --------- | |
75 | ||
76 | // get number of pages in the dialog | |
77 | virtual size_t GetPageCount() const { return m_pages.size(); } | |
78 | ||
79 | // get the panel which represents the given page | |
80 | virtual wxWindow *GetPage(size_t n) { return m_pages[n]; } | |
81 | ||
82 | // get the currently selected page or wxNOT_FOUND if none | |
83 | virtual int GetSelection() const = 0; | |
84 | ||
85 | // set/get the title of a page | |
86 | virtual bool SetPageText(size_t n, const wxString& strText) = 0; | |
87 | virtual wxString GetPageText(size_t n) const = 0; | |
88 | ||
89 | ||
90 | // image list stuff: each page may have an image associated with it (all | |
91 | // images belong to the same image list) | |
92 | // --------------------------------------------------------------------- | |
93 | ||
94 | // sets the image list to use, it is *not* deleted by the control | |
95 | virtual void SetImageList(wxImageList *imageList); | |
96 | ||
97 | // as SetImageList() but we will delete the image list ourselves | |
98 | void AssignImageList(wxImageList *imageList); | |
99 | ||
100 | // get pointer (may be NULL) to the associated image list | |
101 | wxImageList* GetImageList() const { return m_imageList; } | |
102 | ||
103 | // sets/returns item's image index in the current image list | |
104 | virtual int GetPageImage(size_t n) const = 0; | |
105 | virtual bool SetPageImage(size_t n, int imageId) = 0; | |
106 | ||
107 | ||
108 | // geometry | |
109 | // -------- | |
110 | ||
111 | // resize the notebook so that all pages will have the specified size | |
112 | virtual void SetPageSize(const wxSize& size); | |
113 | ||
114 | // calculate the size of the control from the size of its page | |
115 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; | |
116 | ||
117 | ||
118 | // operations | |
119 | // ---------- | |
120 | ||
121 | // remove one page from the control and delete it | |
122 | virtual bool DeletePage(size_t n); | |
123 | ||
124 | // remove one page from the notebook, without deleting it | |
37144cf0 RD |
125 | virtual bool RemovePage(size_t n) |
126 | { | |
127 | InvalidateBestSize(); | |
128 | return DoRemovePage(n) != NULL; | |
129 | } | |
15aad3b9 VZ |
130 | |
131 | // remove all pages and delete them | |
37144cf0 RD |
132 | virtual bool DeleteAllPages() |
133 | { | |
134 | InvalidateBestSize(); | |
135 | WX_CLEAR_ARRAY(m_pages); | |
136 | return true; | |
137 | } | |
15aad3b9 VZ |
138 | |
139 | // adds a new page to the control | |
140 | virtual bool AddPage(wxWindow *page, | |
141 | const wxString& text, | |
142 | bool bSelect = false, | |
143 | int imageId = -1) | |
144 | { | |
37144cf0 | 145 | InvalidateBestSize(); |
15aad3b9 VZ |
146 | return InsertPage(GetPageCount(), page, text, bSelect, imageId); |
147 | } | |
148 | ||
149 | // the same as AddPage(), but adds the page at the specified position | |
150 | virtual bool InsertPage(size_t n, | |
151 | wxWindow *page, | |
152 | const wxString& text, | |
153 | bool bSelect = false, | |
154 | int imageId = -1) = 0; | |
155 | ||
156 | // set the currently selected page, return the index of the previously | |
157 | // selected one (or -1 on error) | |
158 | // | |
1f30c176 | 159 | // NB: this function will generate PAGE_CHANGING/ED events |
15aad3b9 VZ |
160 | virtual int SetSelection(size_t n) = 0; |
161 | ||
162 | ||
163 | // cycle thru the pages | |
164 | void AdvanceSelection(bool forward = true) | |
165 | { | |
166 | int nPage = GetNextPage(forward); | |
167 | if ( nPage != -1 ) | |
168 | { | |
169 | // cast is safe because of the check above | |
170 | SetSelection((size_t)nPage); | |
171 | } | |
172 | } | |
173 | ||
cc0bffac RD |
174 | virtual void ApplyParentThemeBackground(const wxColour& bg) |
175 | { SetBackgroundColour(bg); } | |
176 | ||
15aad3b9 VZ |
177 | protected: |
178 | // remove the page and return a pointer to it | |
179 | virtual wxWindow *DoRemovePage(size_t page) = 0; | |
180 | ||
181 | // our best size is the size which fits all our pages | |
182 | virtual wxSize DoGetBestSize() const; | |
183 | ||
184 | // helper: get the next page wrapping if we reached the end | |
185 | int GetNextPage(bool forward) const; | |
186 | ||
187 | // common part of all ctors | |
188 | void Init(); | |
189 | ||
6457949e RD |
190 | // Always rely on GetBestSize, which will look at all the pages |
191 | virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { } | |
15aad3b9 VZ |
192 | |
193 | // the array of all pages of this control | |
194 | wxArrayPages m_pages; | |
195 | ||
196 | // the associated image list or NULL | |
197 | wxImageList *m_imageList; | |
198 | ||
199 | // true if we must delete m_imageList | |
200 | bool m_ownsImageList; | |
201 | ||
202 | ||
203 | DECLARE_NO_COPY_CLASS(wxBookCtrl) | |
204 | }; | |
205 | ||
206 | // ---------------------------------------------------------------------------- | |
207 | // wxBookCtrlEvent: page changing events generated by derived classes | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
210 | class WXDLLEXPORT wxBookCtrlEvent : public wxNotifyEvent | |
211 | { | |
212 | public: | |
aa6f64c7 | 213 | wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
15aad3b9 | 214 | int nSel = -1, int nOldSel = -1) |
aa6f64c7 | 215 | : wxNotifyEvent(commandType, winid) |
15aad3b9 VZ |
216 | { |
217 | m_nSel = nSel; | |
218 | m_nOldSel = nOldSel; | |
219 | } | |
220 | ||
221 | // accessors | |
222 | // the currently selected page (-1 if none) | |
223 | int GetSelection() const { return m_nSel; } | |
224 | void SetSelection(int nSel) { m_nSel = nSel; } | |
225 | // the page that was selected before the change (-1 if none) | |
226 | int GetOldSelection() const { return m_nOldSel; } | |
227 | void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; } | |
228 | ||
229 | private: | |
230 | int m_nSel, // currently selected page | |
231 | m_nOldSel; // previously selected page | |
232 | }; | |
233 | ||
234 | #endif // wxUSE_BOOKCTRL | |
235 | ||
236 | #endif // _WX_BOOKCTRL_H_ |