]>
Commit | Line | Data |
---|---|---|
53b28675 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: notebook.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin |
ff829f3f | 7 | // Licence: wxWindows licence |
53b28675 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "notebook.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/notebook.h" | |
15 | #include "wx/panel.h" | |
16 | #include "wx/utils.h" | |
17 | #include "wx/imaglist.h" | |
30dea054 | 18 | #include "wx/intl.h" |
4bf58c62 | 19 | #include "wx/log.h" |
b292e2f5 RR |
20 | #include "gdk/gdkkeysyms.h" |
21 | ||
22 | //----------------------------------------------------------------------------- | |
23 | // data | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | extern bool g_blockEventsOnDrag; | |
53b28675 | 27 | |
219f895a RR |
28 | //----------------------------------------------------------------------------- |
29 | // wxNotebookPage | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | class wxNotebookPage: public wxObject | |
33 | { | |
34 | public: | |
35 | wxNotebookPage() | |
36 | { | |
37 | m_id = -1; | |
38 | m_text = ""; | |
39 | m_image = -1; | |
c67daf87 UR |
40 | m_page = (GtkNotebookPage *) NULL; |
41 | m_client = (wxWindow *) NULL; | |
42 | m_parent = (GtkNotebook *) NULL; | |
24d20a8f | 43 | m_box = (GtkWidget *) NULL; |
ef44a621 | 44 | m_added = FALSE; |
ff7b1510 | 45 | } |
219f895a | 46 | |
ef44a621 VZ |
47 | // mark page as "added' to the notebook, return FALSE if the page was |
48 | // already added | |
49 | bool Add() | |
50 | { | |
51 | if ( WasAdded() ) | |
52 | return FALSE; | |
53 | ||
54 | m_added = TRUE; | |
55 | return TRUE; | |
56 | } | |
57 | ||
58 | bool WasAdded() const { return m_added; } | |
59 | ||
219f895a RR |
60 | int m_id; |
61 | wxString m_text; | |
62 | int m_image; | |
63 | GtkNotebookPage *m_page; | |
64 | GtkLabel *m_label; | |
65 | wxWindow *m_client; | |
66 | GtkNotebook *m_parent; | |
24d20a8f | 67 | GtkWidget *m_box; // in which the label and image are packed |
ef44a621 VZ |
68 | |
69 | private: | |
70 | bool m_added; | |
219f895a RR |
71 | }; |
72 | ||
ff829f3f | 73 | //----------------------------------------------------------------------------- |
5b011451 | 74 | // "switch_page" |
ff829f3f VZ |
75 | //----------------------------------------------------------------------------- |
76 | ||
219f895a RR |
77 | static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), |
78 | GtkNotebookPage *WXUNUSED(page), | |
ff829f3f VZ |
79 | gint nPage, |
80 | gpointer data) | |
81 | { | |
b292e2f5 | 82 | wxNotebook *notebook = (wxNotebook *)data; |
ff829f3f | 83 | |
b292e2f5 | 84 | int old = notebook->GetSelection(); |
ff829f3f | 85 | |
b292e2f5 | 86 | // TODO: emulate PAGE_CHANGING event |
ef44a621 | 87 | |
b292e2f5 RR |
88 | wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, |
89 | notebook->GetId(), nPage, old ); | |
90 | event.SetEventObject( notebook ); | |
91 | notebook->GetEventHandler()->ProcessEvent( event ); | |
ff829f3f VZ |
92 | } |
93 | ||
5b011451 RR |
94 | //----------------------------------------------------------------------------- |
95 | // "size_allocate" | |
96 | //----------------------------------------------------------------------------- | |
97 | ||
33d0b396 | 98 | static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) |
caac5181 | 99 | { |
b292e2f5 RR |
100 | if ((win->m_x == alloc->x) && |
101 | (win->m_y == alloc->y) && | |
102 | (win->m_width == alloc->width) && | |
103 | (win->m_height == alloc->height)) | |
104 | { | |
105 | return; | |
106 | } | |
ef44a621 | 107 | |
b292e2f5 | 108 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
435fe83e | 109 | |
b292e2f5 RR |
110 | if (win->GetAutoLayout()) win->Layout(); |
111 | } | |
112 | ||
113 | //----------------------------------------------------------------------------- | |
114 | // "key_press_event" | |
115 | //----------------------------------------------------------------------------- | |
116 | ||
117 | static gint | |
118 | gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook ) | |
119 | { | |
120 | if (g_blockEventsOnDrag) return FALSE; | |
121 | ||
122 | if (!notebook->HasVMT()) return FALSE; | |
123 | ||
124 | if (gdk_event->keyval != GDK_Down) return FALSE; | |
125 | ||
126 | if (notebook != notebook->FindFocus()) return FALSE; | |
127 | ||
128 | if (notebook->m_pages.GetCount() == 0) return FALSE; | |
129 | ||
130 | wxNode *node = notebook->m_pages.Nth( notebook->GetSelection() ); | |
131 | ||
132 | if (!node) return FALSE; | |
133 | ||
134 | wxNotebookPage *page = (wxNotebookPage*) node->Data(); | |
135 | ||
136 | // don't let others the key event | |
137 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); | |
138 | ||
139 | page->m_client->SetFocus(); | |
140 | ||
141 | return TRUE; | |
ff7b1510 | 142 | } |
caac5181 | 143 | |
6ca41e57 RR |
144 | //----------------------------------------------------------------------------- |
145 | // InsertChild callback for wxNotebook | |
146 | //----------------------------------------------------------------------------- | |
147 | ||
148 | static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) | |
149 | { | |
b292e2f5 | 150 | wxNotebookPage *page = new wxNotebookPage(); |
6ca41e57 | 151 | |
b292e2f5 | 152 | page->m_id = parent->GetPageCount(); |
6ca41e57 | 153 | |
b292e2f5 RR |
154 | page->m_box = gtk_hbox_new (FALSE, 0); |
155 | gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); | |
6ca41e57 | 156 | |
b292e2f5 | 157 | GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); |
ef44a621 | 158 | |
b292e2f5 RR |
159 | page->m_client = child; |
160 | gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); | |
6ca41e57 | 161 | |
b292e2f5 | 162 | page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); |
6ca41e57 | 163 | |
b292e2f5 | 164 | page->m_parent = notebook; |
6ca41e57 | 165 | |
b292e2f5 RR |
166 | gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", |
167 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); | |
6ca41e57 | 168 | |
b292e2f5 | 169 | wxASSERT_MSG( page->m_page, "Notebook page creation error" ); |
6ca41e57 | 170 | |
b292e2f5 | 171 | parent->m_pages.Append( page ); |
6ca41e57 RR |
172 | } |
173 | ||
53b28675 RR |
174 | //----------------------------------------------------------------------------- |
175 | // wxNotebook | |
176 | //----------------------------------------------------------------------------- | |
177 | ||
53b28675 RR |
178 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) |
179 | ||
ff829f3f | 180 | void wxNotebook::Init() |
53b28675 | 181 | { |
b292e2f5 RR |
182 | m_imageList = (wxImageList *) NULL; |
183 | m_pages.DeleteContents( TRUE ); | |
184 | m_idHandler = 0; | |
ff829f3f VZ |
185 | } |
186 | ||
187 | wxNotebook::wxNotebook() | |
188 | { | |
b292e2f5 | 189 | Init(); |
ff7b1510 | 190 | } |
53b28675 | 191 | |
debe6624 | 192 | wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, |
53b28675 | 193 | const wxPoint& pos, const wxSize& size, |
debe6624 | 194 | long style, const wxString& name ) |
53b28675 | 195 | { |
b292e2f5 RR |
196 | Init(); |
197 | Create( parent, id, pos, size, style, name ); | |
ff7b1510 | 198 | } |
53b28675 | 199 | |
ff829f3f | 200 | wxNotebook::~wxNotebook() |
53b28675 | 201 | { |
b292e2f5 RR |
202 | // don't generate change page events any more |
203 | if (m_idHandler != 0) | |
204 | gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler); | |
ff829f3f | 205 | |
b292e2f5 | 206 | DeleteAllPages(); |
ff7b1510 | 207 | } |
53b28675 | 208 | |
debe6624 | 209 | bool wxNotebook::Create(wxWindow *parent, wxWindowID id, |
53b28675 | 210 | const wxPoint& pos, const wxSize& size, |
debe6624 | 211 | long style, const wxString& name ) |
53b28675 | 212 | { |
b292e2f5 RR |
213 | m_needParent = TRUE; |
214 | m_acceptsFocus = TRUE; | |
215 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; | |
216 | ||
217 | PreCreation( parent, id, pos, size, style, name ); | |
ff829f3f | 218 | |
b292e2f5 | 219 | m_widget = gtk_notebook_new(); |
53b28675 | 220 | |
b292e2f5 RR |
221 | #ifdef __WXDEBUG__ |
222 | debug_focus_in( m_widget, "wxNotebook::m_widget", name ); | |
223 | #endif | |
caac5181 | 224 | |
b292e2f5 | 225 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); |
caac5181 | 226 | |
b292e2f5 | 227 | m_idHandler = gtk_signal_connect ( |
ff829f3f VZ |
228 | GTK_OBJECT(m_widget), "switch_page", |
229 | GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), | |
ba4e3652 | 230 | (gpointer)this ); |
ff829f3f | 231 | |
b292e2f5 | 232 | m_parent->AddChild( this ); |
6ca41e57 | 233 | |
b292e2f5 | 234 | (m_parent->m_insertCallback)( m_parent, this ); |
ef44a621 | 235 | |
b292e2f5 RR |
236 | gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event", |
237 | GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this ); | |
ff829f3f | 238 | |
b292e2f5 | 239 | PostCreation(); |
ff829f3f | 240 | |
b292e2f5 RR |
241 | Show( TRUE ); |
242 | ||
243 | return TRUE; | |
ff7b1510 | 244 | } |
53b28675 | 245 | |
ff829f3f | 246 | int wxNotebook::GetSelection() const |
53b28675 | 247 | { |
b292e2f5 | 248 | wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); |
53b28675 | 249 | |
b292e2f5 | 250 | if (m_pages.Number() == 0) return -1; |
ff829f3f | 251 | |
b292e2f5 RR |
252 | GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page; |
253 | if (!g_page) return -1; | |
53b28675 | 254 | |
b292e2f5 | 255 | wxNotebookPage *page = (wxNotebookPage *) NULL; |
ef44a621 | 256 | |
b292e2f5 RR |
257 | wxNode *node = m_pages.First(); |
258 | while (node) | |
ba4e3652 | 259 | { |
b292e2f5 RR |
260 | page = (wxNotebookPage*)node->Data(); |
261 | ||
262 | if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL)) | |
263 | { | |
264 | // page->m_page is NULL directly after gtk_notebook_append. gtk emits | |
265 | // "switch_page" then and we ask for GetSelection() in the handler for | |
266 | // "switch_page". otherwise m_page should never be NULL. all this | |
267 | // might also be wrong. | |
268 | break; | |
269 | } | |
270 | node = node->Next(); | |
ba4e3652 | 271 | } |
53b28675 | 272 | |
b292e2f5 | 273 | wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" ); |
ff829f3f | 274 | |
b292e2f5 | 275 | return page->m_id; |
ff7b1510 | 276 | } |
53b28675 | 277 | |
ff829f3f | 278 | int wxNotebook::GetPageCount() const |
53b28675 | 279 | { |
b292e2f5 RR |
280 | // count only the pages which were already added to the notebook for MSW |
281 | // compatibility (and, in fact, this behaviour makes more sense anyhow | |
282 | // because only the added pages are shown) | |
283 | ||
284 | int n = 0; | |
285 | for ( wxNode *node = m_pages.First(); node; node = node->Next() ) | |
286 | { | |
287 | wxNotebookPage *page = (wxNotebookPage*)node->Data(); | |
288 | ||
289 | if (page->WasAdded()) n++; | |
290 | } | |
ef44a621 | 291 | |
b292e2f5 | 292 | return n; |
ff7b1510 | 293 | } |
53b28675 | 294 | |
ff829f3f | 295 | int wxNotebook::GetRowCount() const |
53b28675 | 296 | { |
b292e2f5 | 297 | return 1; |
ff7b1510 | 298 | } |
53b28675 | 299 | |
ff829f3f | 300 | wxString wxNotebook::GetPageText( int page ) const |
53b28675 | 301 | { |
b292e2f5 | 302 | wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" ); |
ef44a621 | 303 | |
b292e2f5 RR |
304 | wxNotebookPage* nb_page = GetNotebookPage(page); |
305 | if (nb_page) | |
306 | return nb_page->m_text; | |
307 | else | |
308 | return ""; | |
ff7b1510 | 309 | } |
53b28675 | 310 | |
ff829f3f | 311 | int wxNotebook::GetPageImage( int page ) const |
53b28675 | 312 | { |
b292e2f5 | 313 | wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" ); |
a81258be | 314 | |
b292e2f5 RR |
315 | wxNotebookPage* nb_page = GetNotebookPage(page); |
316 | if (nb_page) | |
317 | return nb_page->m_image; | |
318 | else | |
319 | return 0; | |
ff7b1510 | 320 | } |
53b28675 | 321 | |
8aadf227 | 322 | wxNotebookPage* wxNotebook::GetNotebookPage(int page) const |
53b28675 | 323 | { |
b292e2f5 | 324 | wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" ); |
a81258be | 325 | |
b292e2f5 | 326 | wxNotebookPage *nb_page = (wxNotebookPage *) NULL; |
53b28675 | 327 | |
b292e2f5 RR |
328 | wxNode *node = m_pages.First(); |
329 | while (node) | |
330 | { | |
331 | nb_page = (wxNotebookPage*)node->Data(); | |
332 | if (nb_page->m_id == page) | |
333 | return nb_page; | |
334 | node = node->Next(); | |
335 | } | |
ff829f3f | 336 | |
b292e2f5 | 337 | wxFAIL_MSG( "Notebook page not found!" ); |
ff829f3f | 338 | |
b292e2f5 | 339 | return (wxNotebookPage *) NULL; |
ff7b1510 | 340 | } |
53b28675 | 341 | |
ff829f3f | 342 | int wxNotebook::SetSelection( int page ) |
53b28675 | 343 | { |
a81258be RR |
344 | wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); |
345 | ||
ff829f3f | 346 | int selOld = GetSelection(); |
8aadf227 | 347 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 348 | |
5b011451 | 349 | if (!nb_page) return -1; |
ff829f3f | 350 | |
53b28675 RR |
351 | int page_num = 0; |
352 | GList *child = GTK_NOTEBOOK(m_widget)->children; | |
353 | while (child) | |
354 | { | |
5b011451 | 355 | if (nb_page->m_page == (GtkNotebookPage*)child->data) break; |
53b28675 RR |
356 | page_num++; |
357 | child = child->next; | |
ff7b1510 | 358 | } |
ff829f3f | 359 | |
53b28675 | 360 | if (!child) return -1; |
ff829f3f | 361 | |
53b28675 | 362 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page_num ); |
ff829f3f VZ |
363 | |
364 | return selOld; | |
ff7b1510 | 365 | } |
53b28675 | 366 | |
5b011451 | 367 | void wxNotebook::AdvanceSelection( bool bForward ) |
ff829f3f | 368 | { |
a81258be RR |
369 | wxCHECK_RET( m_widget != NULL, "invalid notebook" ); |
370 | ||
5b011451 RR |
371 | int sel = GetSelection(); |
372 | int max = GetPageCount(); | |
ff829f3f | 373 | |
ef44a621 | 374 | if (bForward) |
5b011451 RR |
375 | SetSelection( sel == max ? 0 : sel + 1 ); |
376 | else | |
377 | SetSelection( sel == 0 ? max : sel - 1 ); | |
ff829f3f VZ |
378 | } |
379 | ||
53b28675 RR |
380 | void wxNotebook::SetImageList( wxImageList* imageList ) |
381 | { | |
382 | m_imageList = imageList; | |
ff7b1510 | 383 | } |
53b28675 | 384 | |
ff829f3f | 385 | bool wxNotebook::SetPageText( int page, const wxString &text ) |
53b28675 | 386 | { |
a81258be RR |
387 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); |
388 | ||
8aadf227 | 389 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 390 | |
5b011451 | 391 | if (!nb_page) return FALSE; |
ff829f3f | 392 | |
53b28675 | 393 | nb_page->m_text = text; |
ff829f3f | 394 | |
53b28675 | 395 | return TRUE; |
ff7b1510 | 396 | } |
53b28675 | 397 | |
debe6624 | 398 | bool wxNotebook::SetPageImage( int page, int image ) |
53b28675 | 399 | { |
8aadf227 | 400 | wxNotebookPage* nb_page = GetNotebookPage(page); |
ef44a621 | 401 | |
5b011451 | 402 | if (!nb_page) return FALSE; |
53b28675 | 403 | |
ff829f3f | 404 | nb_page->m_image = image; |
53b28675 | 405 | |
53b28675 | 406 | return TRUE; |
ff7b1510 | 407 | } |
53b28675 RR |
408 | |
409 | void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) ) | |
410 | { | |
5b011451 | 411 | wxFAIL_MSG( "wxNotebook::SetPageSize not implemented" ); |
ff7b1510 | 412 | } |
53b28675 RR |
413 | |
414 | void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) | |
415 | { | |
5b011451 | 416 | wxFAIL_MSG( "wxNotebook::SetPadding not implemented" ); |
ff7b1510 | 417 | } |
53b28675 | 418 | |
ff829f3f | 419 | bool wxNotebook::DeleteAllPages() |
53b28675 | 420 | { |
a81258be RR |
421 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); |
422 | ||
53b28675 RR |
423 | wxNode *page_node = m_pages.First(); |
424 | while (page_node) | |
425 | { | |
426 | wxNotebookPage *page = (wxNotebookPage*)page_node->Data(); | |
ff829f3f | 427 | |
53b28675 | 428 | DeletePage( page->m_id ); |
ff829f3f | 429 | |
53b28675 | 430 | page_node = m_pages.First(); |
ff7b1510 | 431 | } |
ff829f3f | 432 | |
53b28675 | 433 | return TRUE; |
ff7b1510 | 434 | } |
53b28675 | 435 | |
ff829f3f | 436 | bool wxNotebook::DeletePage( int page ) |
53b28675 | 437 | { |
8aadf227 JS |
438 | wxNotebookPage* nb_page = GetNotebookPage(page); |
439 | if (!nb_page) return FALSE; | |
53b28675 RR |
440 | |
441 | int page_num = 0; | |
442 | GList *child = GTK_NOTEBOOK(m_widget)->children; | |
443 | while (child) | |
444 | { | |
445 | if (nb_page->m_page == (GtkNotebookPage*)child->data) break; | |
446 | page_num++; | |
447 | child = child->next; | |
ff7b1510 | 448 | } |
53010e52 | 449 | |
fed46e72 | 450 | wxCHECK_MSG( child != NULL, FALSE, "illegal notebook index" ); |
ff829f3f | 451 | |
219f895a | 452 | delete nb_page->m_client; |
ff829f3f | 453 | |
fed46e72 RR |
454 | m_pages.DeleteObject( nb_page ); |
455 | ||
456 | return TRUE; | |
457 | } | |
458 | ||
459 | bool wxNotebook::RemovePage( int page ) | |
460 | { | |
461 | wxNotebookPage* nb_page = GetNotebookPage(page); | |
462 | if (!nb_page) return FALSE; | |
463 | ||
464 | int page_num = 0; | |
465 | GList *child = GTK_NOTEBOOK(m_widget)->children; | |
466 | while (child) | |
467 | { | |
468 | if (nb_page->m_page == (GtkNotebookPage*)child->data) break; | |
469 | page_num++; | |
470 | child = child->next; | |
471 | } | |
472 | ||
473 | wxCHECK_MSG( child != NULL, FALSE, "illegal notebook index" ); | |
474 | ||
475 | gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); | |
ff829f3f | 476 | |
53b28675 | 477 | m_pages.DeleteObject( nb_page ); |
ff829f3f | 478 | |
53b28675 | 479 | return TRUE; |
ff7b1510 | 480 | } |
53b28675 | 481 | |
ff829f3f | 482 | bool wxNotebook::AddPage(wxWindow* win, const wxString& text, |
b292e2f5 | 483 | bool select, int imageId) |
53b28675 | 484 | { |
a81258be RR |
485 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); |
486 | ||
4bf58c62 VZ |
487 | // we've created the notebook page in AddChild(). Now we just have to set |
488 | // the caption for the page and set the others parameters. | |
8aadf227 | 489 | |
c67daf87 | 490 | wxNotebookPage *page = (wxNotebookPage *) NULL; |
53b28675 | 491 | |
4bf58c62 VZ |
492 | wxNode *node = m_pages.First(); |
493 | while (node) | |
8aadf227 | 494 | { |
4bf58c62 | 495 | page = (wxNotebookPage*)node->Data(); |
5b011451 | 496 | if ( page->m_client == win ) break; |
4bf58c62 | 497 | node = node->Next(); |
ff7b1510 | 498 | } |
8aadf227 | 499 | |
ef44a621 VZ |
500 | wxCHECK_MSG( page != NULL, FALSE, |
501 | "Can't add a page whose parent is not the notebook!" ); | |
502 | ||
503 | wxCHECK_MSG( page->Add(), FALSE, | |
504 | "Can't add the same page twice to a notebook." ); | |
ff829f3f | 505 | |
ef44a621 | 506 | if (imageId != -1) |
5b011451 | 507 | { |
24d20a8f VZ |
508 | wxASSERT( m_imageList != NULL ); |
509 | ||
e4a81a2e | 510 | const wxBitmap *bmp = m_imageList->GetBitmap(imageId); |
24d20a8f | 511 | GdkPixmap *pixmap = bmp->GetPixmap(); |
5b011451 | 512 | GdkBitmap *mask = (GdkBitmap*) NULL; |
e4a81a2e VZ |
513 | if ( bmp->GetMask() ) |
514 | { | |
515 | mask = bmp->GetMask()->GetBitmap(); | |
516 | } | |
517 | ||
5b011451 | 518 | GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask ); |
24d20a8f VZ |
519 | |
520 | gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3); | |
521 | ||
522 | gtk_widget_show(pixmapwid); | |
523 | } | |
524 | ||
741fd203 VZ |
525 | // then set the attributes |
526 | page->m_text = text; | |
5b011451 | 527 | if (page->m_text.IsEmpty()) page->m_text = ""; |
741fd203 VZ |
528 | page->m_image = imageId; |
529 | page->m_label = (GtkLabel *)gtk_label_new(page->m_text); | |
5b011451 | 530 | gtk_box_pack_start( GTK_BOX(page->m_box), (GtkWidget *)page->m_label, FALSE, FALSE, 3); |
741fd203 VZ |
531 | |
532 | // @@@: what does this do? do we still need it? | |
533 | // gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); | |
534 | ||
535 | gtk_widget_show((GtkWidget *)page->m_label); | |
536 | ||
b292e2f5 | 537 | if (select) SetSelection( GetPageCount()-1 ); |
ff829f3f | 538 | |
8aadf227 | 539 | return TRUE; |
ff7b1510 | 540 | } |
53b28675 | 541 | |
ff829f3f | 542 | wxWindow *wxNotebook::GetPage( int page ) const |
53b28675 | 543 | { |
b292e2f5 | 544 | wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); |
a81258be | 545 | |
b292e2f5 RR |
546 | wxNotebookPage* nb_page = GetNotebookPage(page); |
547 | if (!nb_page) | |
548 | return (wxWindow *) NULL; | |
549 | else | |
550 | return nb_page->m_client; | |
ff7b1510 | 551 | } |
53b28675 | 552 | |
5a8c929e | 553 | // override these 2 functions to do nothing: everything is done in OnSize |
e3e65dac | 554 | void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) |
5a8c929e | 555 | { |
b292e2f5 RR |
556 | // don't set the sizes of the pages - their correct size is not yet known |
557 | wxControl::SetConstraintSizes(FALSE); | |
5a8c929e VZ |
558 | } |
559 | ||
e3e65dac | 560 | bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) |
5a8c929e | 561 | { |
b292e2f5 | 562 | return TRUE; |
5a8c929e VZ |
563 | } |
564 | ||
58614078 | 565 | void wxNotebook::ApplyWidgetStyle() |
a81258be | 566 | { |
b292e2f5 RR |
567 | SetWidgetStyle(); |
568 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
a81258be RR |
569 | } |
570 | ||
53b28675 | 571 | //----------------------------------------------------------------------------- |
ff829f3f | 572 | // wxNotebookEvent |
53b28675 RR |
573 | //----------------------------------------------------------------------------- |
574 | ||
92976ab6 | 575 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) |
5b011451 | 576 |