]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: notebook.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "notebook.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/notebook.h" | |
16 | #include "wx/panel.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/imaglist.h" | |
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | // wxNotebookPage | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | class wxNotebookPage: public wxObject | |
25 | { | |
26 | public: | |
27 | ||
28 | int m_id; | |
29 | wxString m_text; | |
30 | int m_image; | |
31 | void *m_clientData; | |
32 | GtkNotebookPage *m_page; | |
33 | wxPanel *m_clientPanel; | |
34 | ||
35 | wxNotebookPage(void) | |
36 | { | |
37 | m_id = -1; | |
38 | m_text = ""; | |
39 | m_image = -1; | |
40 | m_clientData = NULL; | |
41 | m_page = NULL; | |
42 | m_clientPanel = NULL; | |
43 | }; | |
44 | ||
45 | }; | |
46 | ||
47 | //----------------------------------------------------------------------------- | |
48 | // wxNotebook | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
51 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) | |
52 | END_EVENT_TABLE() | |
53 | ||
54 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) | |
55 | ||
56 | wxNotebook::wxNotebook(void) | |
57 | { | |
58 | m_imageList = NULL; | |
59 | m_frame = NULL; | |
60 | m_pages.DeleteContents( TRUE ); | |
61 | }; | |
62 | ||
63 | wxNotebook::wxNotebook( wxWindow *parent, const wxWindowID id, | |
64 | const wxPoint& pos, const wxSize& size, | |
65 | const long style, const wxString& name ) | |
66 | { | |
67 | m_imageList = NULL; | |
68 | m_frame = NULL; | |
69 | m_pages.DeleteContents( TRUE ); | |
70 | Create( parent, id, pos, size, style, name ); | |
71 | }; | |
72 | ||
73 | wxNotebook::~wxNotebook(void) | |
74 | { | |
75 | if (m_imageList) delete m_imageList; | |
76 | DeleteAllPages(); | |
77 | }; | |
78 | ||
79 | bool wxNotebook::Create(wxWindow *parent, const wxWindowID id, | |
80 | const wxPoint& pos, const wxSize& size, | |
81 | const long style, const wxString& name ) | |
82 | { | |
83 | m_needParent = TRUE; | |
84 | ||
85 | PreCreation( parent, id, pos, size, style, name ); | |
86 | ||
87 | m_widget = gtk_notebook_new(); | |
88 | ||
89 | PostCreation(); | |
90 | ||
91 | Show( TRUE ); | |
92 | ||
93 | return TRUE; | |
94 | }; | |
95 | ||
96 | int wxNotebook::GetSelection(void) const | |
97 | { | |
98 | if (m_pages.Number() == 0) return -1; | |
99 | ||
100 | GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page; | |
101 | ||
102 | wxNotebookPage *page = NULL; | |
103 | ||
104 | wxNode *node = m_pages.First(); | |
105 | while (node) | |
106 | { | |
107 | page = (wxNotebookPage*)node->Data(); | |
108 | if (page->m_page == g_page) break; | |
109 | node = node->Next(); | |
110 | }; | |
111 | ||
112 | if (!node) wxFatalError( "Notebook error." ); | |
113 | ||
114 | return page->m_id; | |
115 | }; | |
116 | ||
117 | wxImageList* wxNotebook::GetImageList(void) const | |
118 | { | |
119 | return m_imageList; | |
120 | }; | |
121 | ||
122 | int wxNotebook::GetPageCount(void) const | |
123 | { | |
124 | return m_pages.Number(); | |
125 | }; | |
126 | ||
127 | int wxNotebook::GetRowCount(void) const | |
128 | { | |
129 | return 1; | |
130 | }; | |
131 | ||
132 | wxString wxNotebook::GetPageText( const int page ) const | |
133 | { | |
134 | wxNotebookPage *nb_page = NULL; | |
135 | ||
136 | wxNode *node = m_pages.First(); | |
137 | while (node) | |
138 | { | |
139 | nb_page = (wxNotebookPage*)node->Data(); | |
140 | if (nb_page->m_id == page) break; | |
141 | node = node->Next(); | |
142 | }; | |
143 | if (!node) return ""; | |
144 | ||
145 | return nb_page->m_text; | |
146 | }; | |
147 | ||
148 | int wxNotebook::GetPageImage( const int page ) const | |
149 | { | |
150 | wxNotebookPage *nb_page = NULL; | |
151 | ||
152 | wxNode *node = m_pages.First(); | |
153 | while (node) | |
154 | { | |
155 | nb_page = (wxNotebookPage*)node->Data(); | |
156 | if (nb_page->m_id == page) break; | |
157 | node = node->Next(); | |
158 | }; | |
159 | if (!node) return -1; | |
160 | ||
161 | return nb_page->m_image; | |
162 | }; | |
163 | ||
164 | void* wxNotebook::GetPageData( const int page ) const | |
165 | { | |
166 | wxNotebookPage *nb_page = NULL; | |
167 | ||
168 | wxNode *node = m_pages.First(); | |
169 | while (node) | |
170 | { | |
171 | nb_page = (wxNotebookPage*)node->Data(); | |
172 | if (nb_page->m_id == page) break; | |
173 | node = node->Next(); | |
174 | }; | |
175 | if (!node) return NULL; | |
176 | ||
177 | return nb_page->m_clientData; | |
178 | }; | |
179 | ||
180 | int wxNotebook::SetSelection( const int page ) | |
181 | { | |
182 | wxNotebookPage *nb_page = NULL; | |
183 | ||
184 | wxNode *node = m_pages.First(); | |
185 | while (node) | |
186 | { | |
187 | nb_page = (wxNotebookPage*)node->Data(); | |
188 | if (nb_page->m_id == page) break; | |
189 | node = node->Next(); | |
190 | }; | |
191 | if (!node) return -1; | |
192 | ||
193 | int page_num = 0; | |
194 | GList *child = GTK_NOTEBOOK(m_widget)->children; | |
195 | while (child) | |
196 | { | |
197 | if (nb_page->m_page == (GtkNotebookPage*)child->data) break; | |
198 | page_num++; | |
199 | child = child->next; | |
200 | }; | |
201 | ||
202 | if (!child) return -1; | |
203 | ||
204 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page_num ); | |
205 | ||
206 | return page; | |
207 | }; | |
208 | ||
209 | void wxNotebook::SetImageList( wxImageList* imageList ) | |
210 | { | |
211 | m_imageList = imageList; | |
212 | }; | |
213 | ||
214 | bool wxNotebook::SetPageText( const int page, const wxString &text ) | |
215 | { | |
216 | wxNotebookPage *nb_page = NULL; | |
217 | ||
218 | wxNode *node = m_pages.First(); | |
219 | while (node) | |
220 | { | |
221 | nb_page = (wxNotebookPage*)node->Data(); | |
222 | if (nb_page->m_id == page) break; | |
223 | node = node->Next(); | |
224 | }; | |
225 | if (!node) return FALSE; | |
226 | ||
227 | nb_page->m_text = text; | |
228 | ||
229 | // recreate | |
230 | ||
231 | return TRUE; | |
232 | }; | |
233 | ||
234 | bool wxNotebook::SetPageImage( const int page, const int image ) | |
235 | { | |
236 | wxNotebookPage *nb_page = NULL; | |
237 | ||
238 | wxNode *node = m_pages.First(); | |
239 | while (node) | |
240 | { | |
241 | nb_page = (wxNotebookPage*)node->Data(); | |
242 | if (nb_page->m_id == page) break; | |
243 | node = node->Next(); | |
244 | }; | |
245 | if (!node) return FALSE; | |
246 | ||
247 | nb_page->m_image = image; | |
248 | ||
249 | // recreate | |
250 | ||
251 | return TRUE; | |
252 | }; | |
253 | ||
254 | bool wxNotebook::SetPageData( const int page, void* data ) | |
255 | { | |
256 | wxNotebookPage *nb_page = NULL; | |
257 | ||
258 | wxNode *node = m_pages.First(); | |
259 | while (node) | |
260 | { | |
261 | nb_page = (wxNotebookPage*)node->Data(); | |
262 | if (nb_page->m_id == page) break; | |
263 | node = node->Next(); | |
264 | }; | |
265 | if (!node) return FALSE; | |
266 | ||
267 | nb_page->m_clientData = data; | |
268 | ||
269 | return TRUE; | |
270 | }; | |
271 | ||
272 | void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) ) | |
273 | { | |
274 | }; | |
275 | ||
276 | void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) | |
277 | { | |
278 | // what's this ? | |
279 | }; | |
280 | ||
281 | bool wxNotebook::DeleteAllPages(void) | |
282 | { | |
283 | wxNode *page_node = m_pages.First(); | |
284 | while (page_node) | |
285 | { | |
286 | wxNotebookPage *page = (wxNotebookPage*)page_node->Data(); | |
287 | ||
288 | DeletePage( page->m_id ); | |
289 | ||
290 | page_node = m_pages.First(); | |
291 | }; | |
292 | ||
293 | return TRUE; | |
294 | }; | |
295 | ||
296 | bool wxNotebook::DeletePage( const int page ) | |
297 | { | |
298 | wxNotebookPage *nb_page = NULL; | |
299 | ||
300 | wxNode *node = m_pages.First(); | |
301 | while (node) | |
302 | { | |
303 | nb_page = (wxNotebookPage*)node->Data(); | |
304 | if (nb_page->m_id == page) break; | |
305 | node = node->Next(); | |
306 | }; | |
307 | if (!node) return FALSE; | |
308 | ||
309 | int page_num = 0; | |
310 | GList *child = GTK_NOTEBOOK(m_widget)->children; | |
311 | while (child) | |
312 | { | |
313 | if (nb_page->m_page == (GtkNotebookPage*)child->data) break; | |
314 | page_num++; | |
315 | child = child->next; | |
316 | }; | |
317 | ||
318 | wxASSERT( child ); | |
319 | ||
320 | delete nb_page->m_clientPanel; | |
321 | ||
322 | // Amazingly, this is not necessary | |
323 | // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); | |
324 | ||
325 | m_pages.DeleteObject( nb_page ); | |
326 | ||
327 | return TRUE; | |
328 | }; | |
329 | ||
330 | wxPanel *wxNotebook::CreatePage( const int item, const wxString &text, const int imageId, void* data ) | |
331 | { | |
332 | wxNotebookPage *page = new wxNotebookPage; | |
333 | ||
334 | page->m_text = text; | |
335 | if (page->m_text.IsNull()) page->m_text = ""; | |
336 | page->m_id = item; | |
337 | page->m_image = imageId; | |
338 | page->m_clientData = data; | |
339 | ||
340 | m_frame = gtk_label_new( page->m_text ); | |
341 | gtk_misc_set_alignment( GTK_MISC(m_frame), 0.0, 0.5 ); | |
342 | ||
343 | page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) ); | |
344 | ||
345 | m_frame = NULL; | |
346 | ||
347 | page->m_page = (GtkNotebookPage*)( g_list_last( GTK_NOTEBOOK(m_widget)->children )->data ); | |
348 | ||
349 | if (!page->m_page) wxFatalError( "Notebook page creation error" ); | |
350 | ||
351 | m_pages.Append( page ); | |
352 | ||
353 | return page->m_clientPanel; | |
354 | }; | |
355 | ||
356 | wxPanel *wxNotebook::GetPanel( const int page ) | |
357 | { | |
358 | wxNotebookPage *nb_page = NULL; | |
359 | ||
360 | wxNode *node = m_pages.First(); | |
361 | while (node) | |
362 | { | |
363 | nb_page = (wxNotebookPage*)node->Data(); | |
364 | if (nb_page->m_id == page) break; | |
365 | node = node->Next(); | |
366 | }; | |
367 | if (!node) return NULL; | |
368 | ||
369 | return nb_page->m_clientPanel; | |
370 | }; | |
371 | ||
372 | void wxNotebook::AddChild( wxWindow *win ) | |
373 | { | |
374 | if (!m_frame) wxFatalError( "Notebook::Addchild() must not be called directly." ); | |
375 | ||
376 | gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame ); | |
377 | }; | |
378 | ||
379 | //----------------------------------------------------------------------------- | |
380 | // wxTabEvent | |
381 | //----------------------------------------------------------------------------- | |
382 | ||
383 | IMPLEMENT_DYNAMIC_CLASS(wxTabEvent, wxCommandEvent) | |
384 | ||
385 | wxTabEvent::wxTabEvent( WXTYPE commandType, int id ) : | |
386 | wxCommandEvent(commandType, id) | |
387 | { | |
388 | }; | |
389 |