]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/notebook.cpp
char handling fixed once again
[wxWidgets.git] / src / gtk / notebook.cpp
CommitLineData
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"
83624f79
RR
20
21#include "gdk/gdk.h"
22#include "gtk/gtk.h"
23#include "wx/gtk/win_gtk.h"
b292e2f5
RR
24#include "gdk/gdkkeysyms.h"
25
26//-----------------------------------------------------------------------------
27// data
28//-----------------------------------------------------------------------------
29
30extern bool g_blockEventsOnDrag;
53b28675 31
219f895a
RR
32//-----------------------------------------------------------------------------
33// wxNotebookPage
34//-----------------------------------------------------------------------------
35
36class wxNotebookPage: public wxObject
37{
38public:
39 wxNotebookPage()
40 {
41 m_id = -1;
42 m_text = "";
43 m_image = -1;
c67daf87
UR
44 m_page = (GtkNotebookPage *) NULL;
45 m_client = (wxWindow *) NULL;
46 m_parent = (GtkNotebook *) NULL;
24d20a8f 47 m_box = (GtkWidget *) NULL;
ef44a621 48 m_added = FALSE;
ff7b1510 49 }
219f895a 50
3eb78d7e
RR
51 /*
52 mark page as "added' to the notebook, return FALSE if the page was
53 already added
54 */
55
ef44a621
VZ
56 bool Add()
57 {
58 if ( WasAdded() )
59 return FALSE;
60
61 m_added = TRUE;
62 return TRUE;
63 }
64
65 bool WasAdded() const { return m_added; }
66
219f895a
RR
67 int m_id;
68 wxString m_text;
69 int m_image;
70 GtkNotebookPage *m_page;
71 GtkLabel *m_label;
72 wxWindow *m_client;
73 GtkNotebook *m_parent;
24d20a8f 74 GtkWidget *m_box; // in which the label and image are packed
ef44a621
VZ
75
76private:
77 bool m_added;
219f895a
RR
78};
79
ff829f3f 80//-----------------------------------------------------------------------------
5b011451 81// "switch_page"
ff829f3f
VZ
82//-----------------------------------------------------------------------------
83
219f895a
RR
84static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
85 GtkNotebookPage *WXUNUSED(page),
ff829f3f
VZ
86 gint nPage,
87 gpointer data)
88{
b292e2f5 89 wxNotebook *notebook = (wxNotebook *)data;
ff829f3f 90
b292e2f5 91 int old = notebook->GetSelection();
ff829f3f 92
b292e2f5 93 // TODO: emulate PAGE_CHANGING event
ef44a621 94
b292e2f5
RR
95 wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
96 notebook->GetId(), nPage, old );
97 event.SetEventObject( notebook );
98 notebook->GetEventHandler()->ProcessEvent( event );
ff829f3f
VZ
99}
100
5b011451
RR
101//-----------------------------------------------------------------------------
102// "size_allocate"
103//-----------------------------------------------------------------------------
104
33d0b396 105static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
caac5181 106{
b292e2f5
RR
107 if ((win->m_x == alloc->x) &&
108 (win->m_y == alloc->y) &&
109 (win->m_width == alloc->width) &&
110 (win->m_height == alloc->height))
111 {
112 return;
113 }
ef44a621 114
b292e2f5 115 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
435fe83e 116
b292e2f5
RR
117 if (win->GetAutoLayout()) win->Layout();
118}
119
120//-----------------------------------------------------------------------------
121// "key_press_event"
122//-----------------------------------------------------------------------------
123
124static gint
125gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook )
126{
127 if (g_blockEventsOnDrag) return FALSE;
128
129 if (!notebook->HasVMT()) return FALSE;
b98d804b
RR
130
131 /* this code makes jumping down from the handles of the notebooks
132 to the actual items in the visible notebook page possible with
133 the down-arrow key */
b292e2f5
RR
134
135 if (gdk_event->keyval != GDK_Down) return FALSE;
136
137 if (notebook != notebook->FindFocus()) return FALSE;
138
139 if (notebook->m_pages.GetCount() == 0) return FALSE;
140
141 wxNode *node = notebook->m_pages.Nth( notebook->GetSelection() );
142
143 if (!node) return FALSE;
144
145 wxNotebookPage *page = (wxNotebookPage*) node->Data();
146
147 // don't let others the key event
148 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
149
150 page->m_client->SetFocus();
151
152 return TRUE;
ff7b1510 153}
caac5181 154
6ca41e57
RR
155//-----------------------------------------------------------------------------
156// InsertChild callback for wxNotebook
157//-----------------------------------------------------------------------------
158
159static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
160{
b292e2f5 161 wxNotebookPage *page = new wxNotebookPage();
6ca41e57 162
b292e2f5 163 page->m_id = parent->GetPageCount();
6ca41e57 164
b292e2f5
RR
165 page->m_box = gtk_hbox_new (FALSE, 0);
166 gtk_container_border_width(GTK_CONTAINER(page->m_box), 2);
6ca41e57 167
b292e2f5 168 GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
ef44a621 169
b292e2f5
RR
170 page->m_client = child;
171 gtk_notebook_append_page( notebook, child->m_widget, page->m_box );
6ca41e57 172
b292e2f5 173 page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
6ca41e57 174
b292e2f5 175 page->m_parent = notebook;
6ca41e57 176
b292e2f5
RR
177 gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
178 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
6ca41e57 179
b292e2f5 180 wxASSERT_MSG( page->m_page, "Notebook page creation error" );
6ca41e57 181
b292e2f5 182 parent->m_pages.Append( page );
6ca41e57
RR
183}
184
53b28675
RR
185//-----------------------------------------------------------------------------
186// wxNotebook
187//-----------------------------------------------------------------------------
188
53b28675
RR
189IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl)
190
b98d804b
RR
191BEGIN_EVENT_TABLE(wxNotebook, wxControl)
192 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
193END_EVENT_TABLE()
194
ff829f3f 195void wxNotebook::Init()
53b28675 196{
b292e2f5
RR
197 m_imageList = (wxImageList *) NULL;
198 m_pages.DeleteContents( TRUE );
199 m_idHandler = 0;
ff829f3f
VZ
200}
201
202wxNotebook::wxNotebook()
203{
b292e2f5 204 Init();
ff7b1510 205}
53b28675 206
debe6624 207wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
53b28675 208 const wxPoint& pos, const wxSize& size,
debe6624 209 long style, const wxString& name )
53b28675 210{
b292e2f5
RR
211 Init();
212 Create( parent, id, pos, size, style, name );
ff7b1510 213}
53b28675 214
ff829f3f 215wxNotebook::~wxNotebook()
53b28675 216{
b292e2f5
RR
217 // don't generate change page events any more
218 if (m_idHandler != 0)
219 gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler);
ff829f3f 220
b292e2f5 221 DeleteAllPages();
ff7b1510 222}
53b28675 223
debe6624 224bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
53b28675 225 const wxPoint& pos, const wxSize& size,
debe6624 226 long style, const wxString& name )
53b28675 227{
b292e2f5
RR
228 m_needParent = TRUE;
229 m_acceptsFocus = TRUE;
230 m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
231
232 PreCreation( parent, id, pos, size, style, name );
ff829f3f 233
b292e2f5 234 m_widget = gtk_notebook_new();
53b28675 235
b292e2f5
RR
236#ifdef __WXDEBUG__
237 debug_focus_in( m_widget, "wxNotebook::m_widget", name );
238#endif
caac5181 239
b292e2f5 240 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
caac5181 241
b292e2f5 242 m_idHandler = gtk_signal_connect (
ff829f3f
VZ
243 GTK_OBJECT(m_widget), "switch_page",
244 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback),
ba4e3652 245 (gpointer)this );
ff829f3f 246
b292e2f5 247 m_parent->AddChild( this );
6ca41e57 248
b292e2f5 249 (m_parent->m_insertCallback)( m_parent, this );
ef44a621 250
b292e2f5
RR
251 gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event",
252 GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this );
ff829f3f 253
b292e2f5 254 PostCreation();
ff829f3f 255
b292e2f5
RR
256 Show( TRUE );
257
258 return TRUE;
ff7b1510 259}
53b28675 260
ff829f3f 261int wxNotebook::GetSelection() const
53b28675 262{
b292e2f5 263 wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
53b28675 264
b292e2f5 265 if (m_pages.Number() == 0) return -1;
ff829f3f 266
b292e2f5
RR
267 GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
268 if (!g_page) return -1;
53b28675 269
b292e2f5 270 wxNotebookPage *page = (wxNotebookPage *) NULL;
ef44a621 271
b292e2f5
RR
272 wxNode *node = m_pages.First();
273 while (node)
ba4e3652 274 {
b292e2f5
RR
275 page = (wxNotebookPage*)node->Data();
276
277 if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL))
278 {
279 // page->m_page is NULL directly after gtk_notebook_append. gtk emits
280 // "switch_page" then and we ask for GetSelection() in the handler for
281 // "switch_page". otherwise m_page should never be NULL. all this
282 // might also be wrong.
283 break;
284 }
285 node = node->Next();
ba4e3652 286 }
53b28675 287
b292e2f5 288 wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" );
ff829f3f 289
b292e2f5 290 return page->m_id;
ff7b1510 291}
53b28675 292
ff829f3f 293int wxNotebook::GetPageCount() const
53b28675 294{
b292e2f5
RR
295 // count only the pages which were already added to the notebook for MSW
296 // compatibility (and, in fact, this behaviour makes more sense anyhow
297 // because only the added pages are shown)
298
299 int n = 0;
300 for ( wxNode *node = m_pages.First(); node; node = node->Next() )
301 {
302 wxNotebookPage *page = (wxNotebookPage*)node->Data();
303
304 if (page->WasAdded()) n++;
305 }
ef44a621 306
b292e2f5 307 return n;
ff7b1510 308}
53b28675 309
ff829f3f 310int wxNotebook::GetRowCount() const
53b28675 311{
b292e2f5 312 return 1;
ff7b1510 313}
53b28675 314
ff829f3f 315wxString wxNotebook::GetPageText( int page ) const
53b28675 316{
b292e2f5 317 wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
ef44a621 318
b292e2f5
RR
319 wxNotebookPage* nb_page = GetNotebookPage(page);
320 if (nb_page)
321 return nb_page->m_text;
322 else
323 return "";
ff7b1510 324}
53b28675 325
ff829f3f 326int wxNotebook::GetPageImage( int page ) const
53b28675 327{
b292e2f5 328 wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
a81258be 329
b292e2f5
RR
330 wxNotebookPage* nb_page = GetNotebookPage(page);
331 if (nb_page)
332 return nb_page->m_image;
333 else
334 return 0;
ff7b1510 335}
53b28675 336
8aadf227 337wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
53b28675 338{
b292e2f5 339 wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
a81258be 340
b292e2f5 341 wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
53b28675 342
b292e2f5
RR
343 wxNode *node = m_pages.First();
344 while (node)
345 {
346 nb_page = (wxNotebookPage*)node->Data();
347 if (nb_page->m_id == page)
348 return nb_page;
349 node = node->Next();
350 }
ff829f3f 351
b292e2f5 352 wxFAIL_MSG( "Notebook page not found!" );
ff829f3f 353
b292e2f5 354 return (wxNotebookPage *) NULL;
ff7b1510 355}
53b28675 356
ff829f3f 357int wxNotebook::SetSelection( int page )
53b28675 358{
3eb78d7e 359 wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
a81258be 360
3eb78d7e
RR
361 int selOld = GetSelection();
362 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 363
3eb78d7e 364 if (!nb_page) return -1;
ff829f3f 365
3eb78d7e
RR
366 int page_num = 0;
367 GList *child = GTK_NOTEBOOK(m_widget)->children;
368 while (child)
369 {
370 if (nb_page->m_page == (GtkNotebookPage*)child->data) break;
371 page_num++;
372 child = child->next;
373 }
ff829f3f 374
3eb78d7e 375 if (!child) return -1;
ff829f3f 376
3eb78d7e 377 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page_num );
ff829f3f 378
3eb78d7e 379 return selOld;
ff7b1510 380}
53b28675 381
5b011451 382void wxNotebook::AdvanceSelection( bool bForward )
ff829f3f 383{
3eb78d7e 384 wxCHECK_RET( m_widget != NULL, "invalid notebook" );
a81258be 385
3eb78d7e
RR
386 int sel = GetSelection();
387 int max = GetPageCount();
ff829f3f 388
3eb78d7e
RR
389 if (bForward)
390 SetSelection( sel == max ? 0 : sel + 1 );
391 else
b98d804b 392 SetSelection( sel == 0 ? max-1 : sel - 1 );
ff829f3f
VZ
393}
394
53b28675
RR
395void wxNotebook::SetImageList( wxImageList* imageList )
396{
3eb78d7e 397 m_imageList = imageList;
ff7b1510 398}
53b28675 399
ff829f3f 400bool wxNotebook::SetPageText( int page, const wxString &text )
53b28675 401{
3eb78d7e 402 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
a81258be 403
3eb78d7e 404 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 405
3eb78d7e 406 if (!nb_page) return FALSE;
ff829f3f 407
3eb78d7e 408 nb_page->m_text = text;
ff829f3f 409
3eb78d7e
RR
410 if (nb_page->m_text.IsEmpty()) nb_page->m_text = "";
411
412 gtk_label_set(nb_page->m_label, nb_page->m_text);
413
414 return TRUE;
ff7b1510 415}
53b28675 416
debe6624 417bool wxNotebook::SetPageImage( int page, int image )
53b28675 418{
3eb78d7e
RR
419 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
420
421 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 422
3eb78d7e
RR
423 if (!nb_page) return FALSE;
424
425 /* Optimization posibility: return immediately if image unchanged.
426 * Not enabled because it may break existing (stupid) code that
427 * manipulates the imagelist to cycle images */
428
429 /* if (image == nb_page->m_image) return TRUE; */
430
431 /* For different cases:
432 1) no image -> no image
433 2) image -> no image
434 3) no image -> image
435 4) image -> image */
436
437 if (image == -1 && nb_page->m_image == -1)
438 return TRUE; /* Case 1): Nothing to do. */
439
bbe0af5b 440 GtkWidget *pixmapwid = (GtkWidget*) NULL;
3eb78d7e
RR
441
442 if (nb_page->m_image != -1)
443 {
444 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
445
446 GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
447 while (child)
448 {
449 if (GTK_IS_PIXMAP(child->data))
450 {
451 pixmapwid = GTK_WIDGET(child->data);
452 break;
453 }
454 child = child->next;
455 }
456
457 /* We should have the pixmap widget now */
458 wxASSERT(pixmapwid != NULL);
459
460 if (image == -1)
461 {
462 /* If there's no new widget, just remove the old from the box */
463 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
464 nb_page->m_image = -1;
53b28675 465
3eb78d7e
RR
466 return TRUE; /* Case 2) */
467 }
468 }
469
470 /* Only cases 3) and 4) left */
471 wxASSERT( m_imageList != NULL ); /* Just in case */
472
473 /* Construct the new pixmap */
474 const wxBitmap *bmp = m_imageList->GetBitmap(image);
475 GdkPixmap *pixmap = bmp->GetPixmap();
476 GdkBitmap *mask = (GdkBitmap*) NULL;
477 if ( bmp->GetMask() )
478 {
479 mask = bmp->GetMask()->GetBitmap();
480 }
481
482 if (pixmapwid == NULL)
483 {
484 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
485 pixmapwid = gtk_pixmap_new (pixmap, mask );
486
487 /* CHECKME: Are these pack flags okay? */
488 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3);
489 gtk_widget_show(pixmapwid);
490 }
491 else
492 {
493 /* Case 4) Simply replace the pixmap */
494 gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
495 }
496
497 nb_page->m_image = image;
53b28675 498
3eb78d7e 499 return TRUE;
ff7b1510 500}
53b28675
RR
501
502void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
503{
3eb78d7e 504 wxFAIL_MSG( "wxNotebook::SetPageSize not implemented" );
ff7b1510 505}
53b28675
RR
506
507void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) )
508{
3eb78d7e 509 wxFAIL_MSG( "wxNotebook::SetPadding not implemented" );
ff7b1510 510}
53b28675 511
ff829f3f 512bool wxNotebook::DeleteAllPages()
53b28675 513{
3eb78d7e 514 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
a81258be 515
3eb78d7e
RR
516 wxNode *page_node = m_pages.First();
517 while (page_node)
518 {
519 wxNotebookPage *page = (wxNotebookPage*)page_node->Data();
ff829f3f 520
3eb78d7e 521 DeletePage( page->m_id );
ff829f3f 522
3eb78d7e
RR
523 page_node = m_pages.First();
524 }
ff829f3f 525
3eb78d7e 526 return TRUE;
ff7b1510 527}
53b28675 528
ff829f3f 529bool wxNotebook::DeletePage( int page )
53b28675 530{
3eb78d7e
RR
531 wxNotebookPage* nb_page = GetNotebookPage(page);
532 if (!nb_page) return FALSE;
53b28675 533
3eb78d7e
RR
534 int page_num = 0;
535 GList *child = GTK_NOTEBOOK(m_widget)->children;
536 while (child)
537 {
538 if (nb_page->m_page == (GtkNotebookPage*)child->data) break;
539 page_num++;
540 child = child->next;
541 }
53010e52 542
3eb78d7e 543 wxCHECK_MSG( child != NULL, FALSE, "illegal notebook index" );
ff829f3f 544
3eb78d7e 545 delete nb_page->m_client;
ff829f3f 546
3eb78d7e 547 m_pages.DeleteObject( nb_page );
fed46e72 548
3eb78d7e 549 return TRUE;
fed46e72
RR
550}
551
552bool wxNotebook::RemovePage( int page )
553{
3eb78d7e
RR
554 wxNotebookPage* nb_page = GetNotebookPage(page);
555 if (!nb_page) return FALSE;
fed46e72 556
3eb78d7e
RR
557 int page_num = 0;
558 GList *child = GTK_NOTEBOOK(m_widget)->children;
559 while (child)
560 {
561 if (nb_page->m_page == (GtkNotebookPage*)child->data) break;
562 page_num++;
563 child = child->next;
564 }
fed46e72 565
3eb78d7e 566 wxCHECK_MSG( child != NULL, FALSE, "illegal notebook index" );
fed46e72 567
3eb78d7e 568 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
ff829f3f 569
3eb78d7e 570 m_pages.DeleteObject( nb_page );
ff829f3f 571
3eb78d7e 572 return TRUE;
ff7b1510 573}
53b28675 574
ff829f3f 575bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
b292e2f5 576 bool select, int imageId)
53b28675 577{
3eb78d7e 578 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
a81258be 579
3eb78d7e
RR
580 /* we've created the notebook page in AddChild(). Now we just have to set
581 the caption for the page and set the others parameters. */
8aadf227 582
3eb78d7e 583 wxNotebookPage *page = (wxNotebookPage *) NULL;
53b28675 584
3eb78d7e
RR
585 wxNode *node = m_pages.First();
586 while (node)
587 {
588 page = (wxNotebookPage*)node->Data();
589 if ( page->m_client == win ) break;
590 node = node->Next();
591 }
8aadf227 592
3eb78d7e 593 wxCHECK_MSG( page != NULL, FALSE,
ef44a621
VZ
594 "Can't add a page whose parent is not the notebook!" );
595
3eb78d7e 596 wxCHECK_MSG( page->Add(), FALSE,
ef44a621 597 "Can't add the same page twice to a notebook." );
ff829f3f 598
3eb78d7e 599 if (imageId != -1)
e4a81a2e 600 {
3eb78d7e
RR
601 wxASSERT( m_imageList != NULL );
602
603 const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
604 GdkPixmap *pixmap = bmp->GetPixmap();
605 GdkBitmap *mask = (GdkBitmap*) NULL;
606 if ( bmp->GetMask() )
607 {
608 mask = bmp->GetMask()->GetBitmap();
609 }
e4a81a2e 610
3eb78d7e 611 GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
24d20a8f 612
3eb78d7e 613 gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3);
24d20a8f 614
3eb78d7e
RR
615 gtk_widget_show(pixmapwid);
616 }
24d20a8f 617
3eb78d7e
RR
618 /* then set the attributes */
619 page->m_text = text;
620 if (page->m_text.IsEmpty()) page->m_text = "";
621 page->m_image = imageId;
622 page->m_label = (GtkLabel *)gtk_label_new(page->m_text);
623 gtk_box_pack_end( GTK_BOX(page->m_box), (GtkWidget *)page->m_label, FALSE, FALSE, 3);
741fd203 624
3eb78d7e
RR
625 /* @@@: what does this do? do we still need it?
626 gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); */
741fd203 627
3eb78d7e 628 gtk_widget_show((GtkWidget *)page->m_label);
741fd203 629
3eb78d7e 630 if (select) SetSelection( GetPageCount()-1 );
ff829f3f 631
3eb78d7e 632 return TRUE;
ff7b1510 633}
53b28675 634
b98d804b
RR
635void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
636{
637 if (event.IsWindowChange())
638 AdvanceSelection( event.GetDirection() );
639 else
640 event.Skip();
641}
642
ff829f3f 643wxWindow *wxNotebook::GetPage( int page ) const
53b28675 644{
b292e2f5 645 wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
a81258be 646
b292e2f5
RR
647 wxNotebookPage* nb_page = GetNotebookPage(page);
648 if (!nb_page)
649 return (wxWindow *) NULL;
650 else
651 return nb_page->m_client;
ff7b1510 652}
53b28675 653
5a8c929e 654// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 655void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 656{
b292e2f5
RR
657 // don't set the sizes of the pages - their correct size is not yet known
658 wxControl::SetConstraintSizes(FALSE);
5a8c929e
VZ
659}
660
e3e65dac 661bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 662{
b292e2f5 663 return TRUE;
5a8c929e
VZ
664}
665
58614078 666void wxNotebook::ApplyWidgetStyle()
a81258be 667{
b292e2f5
RR
668 SetWidgetStyle();
669 gtk_widget_set_style( m_widget, m_widgetStyle );
a81258be
RR
670}
671
53b28675 672//-----------------------------------------------------------------------------
ff829f3f 673// wxNotebookEvent
53b28675
RR
674//-----------------------------------------------------------------------------
675
92976ab6 676IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
5b011451 677