]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/notebook.cpp
Added size hints to dialog,
[wxWidgets.git] / src / gtk1 / 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"
dcf924a3
RR
15
16#if wxUSE_NOTEBOOK
17
53b28675
RR
18#include "wx/panel.h"
19#include "wx/utils.h"
20#include "wx/imaglist.h"
30dea054 21#include "wx/intl.h"
4bf58c62 22#include "wx/log.h"
83624f79
RR
23
24#include "gdk/gdk.h"
25#include "gtk/gtk.h"
26#include "wx/gtk/win_gtk.h"
b292e2f5
RR
27#include "gdk/gdkkeysyms.h"
28
acfd422a
RR
29//-----------------------------------------------------------------------------
30// idle system
31//-----------------------------------------------------------------------------
32
33extern void wxapp_install_idle_handler();
34extern bool g_isIdle;
35
b292e2f5
RR
36//-----------------------------------------------------------------------------
37// data
38//-----------------------------------------------------------------------------
39
40extern bool g_blockEventsOnDrag;
53b28675 41
2e563988
RR
42//-----------------------------------------------------------------------------
43// debug
44//-----------------------------------------------------------------------------
45
46#ifdef __WXDEBUG__
47
48extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window );
49
50#endif
51
219f895a
RR
52//-----------------------------------------------------------------------------
53// wxNotebookPage
54//-----------------------------------------------------------------------------
55
56class wxNotebookPage: public wxObject
57{
58public:
59 wxNotebookPage()
60 {
219f895a
RR
61 m_text = "";
62 m_image = -1;
c67daf87
UR
63 m_page = (GtkNotebookPage *) NULL;
64 m_client = (wxWindow *) NULL;
24d20a8f 65 m_box = (GtkWidget *) NULL;
ff7b1510 66 }
219f895a 67
219f895a
RR
68 wxString m_text;
69 int m_image;
70 GtkNotebookPage *m_page;
71 GtkLabel *m_label;
72 wxWindow *m_client;
24d20a8f 73 GtkWidget *m_box; // in which the label and image are packed
219f895a
RR
74};
75
ff829f3f 76//-----------------------------------------------------------------------------
5b011451 77// "switch_page"
ff829f3f
VZ
78//-----------------------------------------------------------------------------
79
219f895a
RR
80static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
81 GtkNotebookPage *WXUNUSED(page),
587ce561
RR
82 gint page,
83 wxNotebook *notebook )
ff829f3f 84{
587ce561
RR
85 if (g_isIdle)
86 wxapp_install_idle_handler();
ff829f3f 87
b292e2f5 88 int old = notebook->GetSelection();
ff829f3f 89
587ce561
RR
90 wxNotebookEvent event1( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,
91 notebook->GetId(), page, old );
92 event1.SetEventObject( notebook );
93
94 if ((notebook->GetEventHandler()->ProcessEvent( event1 )) &&
95 !event1.IsAllowed() )
96 {
97 /* program doesn't allow the page change */
98 gtk_signal_emit_stop_by_name( GTK_OBJECT(notebook->m_widget), "switch_page" );
99 return;
100 }
ef44a621 101
587ce561
RR
102 wxNotebookEvent event2( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
103 notebook->GetId(), page, old );
104 event2.SetEventObject( notebook );
105 notebook->GetEventHandler()->ProcessEvent( event2 );
ff829f3f
VZ
106}
107
5b011451
RR
108//-----------------------------------------------------------------------------
109// "size_allocate"
110//-----------------------------------------------------------------------------
111
33d0b396 112static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
caac5181 113{
587ce561
RR
114 if (g_isIdle)
115 wxapp_install_idle_handler();
6d693bb4 116
a2053b27
RR
117 if ((win->m_x == alloc->x) &&
118 (win->m_y == alloc->y) &&
119 (win->m_width == alloc->width) &&
120 (win->m_height == alloc->height))
b292e2f5 121 {
58dea4b0 122 return;
b292e2f5 123 }
2b07d713 124
b292e2f5 125 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
f861258f 126
6d693bb4 127 if (win->GetAutoLayout())
6d693bb4 128 win->Layout();
6d693bb4
RR
129}
130
131//-----------------------------------------------------------------------------
132// "realize" from m_widget
133//-----------------------------------------------------------------------------
134
135/* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize
136 here in order to take repositioning before showing to take effect. */
137
138static gint
139gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
140{
141 if (g_isIdle)
142 wxapp_install_idle_handler();
143
144 gtk_widget_queue_resize( win->m_widget );
145
146 return FALSE;
b292e2f5
RR
147}
148
6ca41e57
RR
149//-----------------------------------------------------------------------------
150// InsertChild callback for wxNotebook
151//-----------------------------------------------------------------------------
152
587ce561 153static void wxInsertChildInNotebook( wxNotebook* WXUNUSED(parent), wxWindow* WXUNUSED(child) )
6ca41e57 154{
587ce561 155 /* we don't do anything here but pray */
6ca41e57
RR
156}
157
53b28675
RR
158//-----------------------------------------------------------------------------
159// wxNotebook
160//-----------------------------------------------------------------------------
161
53b28675
RR
162IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl)
163
b98d804b
RR
164BEGIN_EVENT_TABLE(wxNotebook, wxControl)
165 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
166END_EVENT_TABLE()
f861258f 167
ff829f3f 168void wxNotebook::Init()
53b28675 169{
b292e2f5
RR
170 m_imageList = (wxImageList *) NULL;
171 m_pages.DeleteContents( TRUE );
29f538ce 172 m_lastSelection = -1;
ff829f3f
VZ
173}
174
175wxNotebook::wxNotebook()
176{
b292e2f5 177 Init();
ff7b1510 178}
53b28675 179
debe6624 180wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
53b28675 181 const wxPoint& pos, const wxSize& size,
debe6624 182 long style, const wxString& name )
53b28675 183{
b292e2f5
RR
184 Init();
185 Create( parent, id, pos, size, style, name );
ff7b1510 186}
53b28675 187
ff829f3f 188wxNotebook::~wxNotebook()
53b28675 189{
587ce561
RR
190 /* don't generate change page events any more */
191 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
192 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
ff829f3f 193
b292e2f5 194 DeleteAllPages();
ff7b1510 195}
53b28675 196
debe6624 197bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
53b28675 198 const wxPoint& pos, const wxSize& size,
debe6624 199 long style, const wxString& name )
53b28675 200{
b292e2f5
RR
201 m_needParent = TRUE;
202 m_acceptsFocus = TRUE;
203 m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
204
4dcaf11a
RR
205 if (!PreCreation( parent, pos, size ) ||
206 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
207 {
223d09f6 208 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
4dcaf11a
RR
209 return FALSE;
210 }
211
ff829f3f 212
b292e2f5 213 m_widget = gtk_notebook_new();
53b28675 214
2e563988 215#ifdef __WXDEBUG__
223d09f6 216 debug_focus_in( m_widget, wxT("wxNotebook::m_widget"), name );
2e563988
RR
217#endif
218
b292e2f5 219 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
caac5181 220
587ce561
RR
221 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
222 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
ff829f3f 223
f03fc89f 224 m_parent->DoAddChild( this );
ef44a621 225
a3a7f879
RS
226 if(m_windowStyle & wxNB_RIGHT)
227 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
228 if(m_windowStyle & wxNB_LEFT)
229 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
230 if(m_windowStyle & wxNB_BOTTOM)
231 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
232
b292e2f5 233 PostCreation();
ff829f3f 234
6d693bb4
RR
235 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
236 GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this );
237
b292e2f5
RR
238 Show( TRUE );
239
240 return TRUE;
ff7b1510 241}
53b28675 242
ed58dbea
RR
243void wxNotebook::SetFocus()
244{
245 if (m_pages.GetCount() == 0) return;
246
247 wxNode *node = m_pages.Nth( GetSelection() );
248
249 if (!node) return;
250
251 wxNotebookPage *page = (wxNotebookPage*) node->Data();
252
253 page->m_client->SetFocus();
254}
255
ff829f3f 256int wxNotebook::GetSelection() const
53b28675 257{
223d09f6 258 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
53b28675 259
587ce561 260 GList *pages = GTK_NOTEBOOK(m_widget)->children;
ef44a621 261
587ce561 262 if (g_list_length(pages) == 0) return -1;
53b28675 263
587ce561
RR
264 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
265
29f538ce 266 if (notebook->cur_page == NULL) return m_lastSelection;
587ce561 267
29f538ce 268 return g_list_index( pages, (gpointer)(notebook->cur_page) );
ff7b1510 269}
53b28675 270
ff829f3f 271int wxNotebook::GetPageCount() const
53b28675 272{
587ce561 273 return (int) g_list_length( GTK_NOTEBOOK(m_widget)->children );
ff7b1510 274}
53b28675 275
ff829f3f 276int wxNotebook::GetRowCount() const
53b28675 277{
b292e2f5 278 return 1;
ff7b1510 279}
53b28675 280
ff829f3f 281wxString wxNotebook::GetPageText( int page ) const
53b28675 282{
223d09f6 283 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") );
ef44a621 284
b292e2f5
RR
285 wxNotebookPage* nb_page = GetNotebookPage(page);
286 if (nb_page)
287 return nb_page->m_text;
288 else
223d09f6 289 return wxT("");
ff7b1510 290}
53b28675 291
ff829f3f 292int wxNotebook::GetPageImage( int page ) const
53b28675 293{
223d09f6 294 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 295
b292e2f5
RR
296 wxNotebookPage* nb_page = GetNotebookPage(page);
297 if (nb_page)
298 return nb_page->m_image;
299 else
587ce561 300 return -1;
ff7b1510 301}
53b28675 302
587ce561 303wxNotebookPage* wxNotebook::GetNotebookPage( int page ) const
53b28675 304{
223d09f6 305 wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*) NULL, wxT("invalid notebook") );
ff829f3f 306
223d09f6 307 wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxNotebookPage*) NULL, wxT("invalid notebook index") );
587ce561
RR
308
309 wxNode *node = m_pages.Nth( page );
310
311 return (wxNotebookPage *) node->Data();
ff7b1510 312}
53b28675 313
ff829f3f 314int wxNotebook::SetSelection( int page )
53b28675 315{
223d09f6 316 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 317
223d09f6 318 wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, wxT("invalid notebook index") );
ff829f3f 319
587ce561
RR
320 int selOld = GetSelection();
321
322 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 323
3eb78d7e 324 return selOld;
ff7b1510 325}
53b28675 326
587ce561 327void wxNotebook::AdvanceSelection( bool forward )
ff829f3f 328{
223d09f6 329 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
a81258be 330
3eb78d7e
RR
331 int sel = GetSelection();
332 int max = GetPageCount();
ff829f3f 333
587ce561 334 if (forward)
3eb78d7e
RR
335 SetSelection( sel == max ? 0 : sel + 1 );
336 else
b98d804b 337 SetSelection( sel == 0 ? max-1 : sel - 1 );
ff829f3f
VZ
338}
339
53b28675
RR
340void wxNotebook::SetImageList( wxImageList* imageList )
341{
3eb78d7e 342 m_imageList = imageList;
ff7b1510 343}
53b28675 344
ff829f3f 345bool wxNotebook::SetPageText( int page, const wxString &text )
53b28675 346{
223d09f6 347 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 348
3eb78d7e 349 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 350
223d09f6 351 wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") );
ff829f3f 352
3eb78d7e 353 nb_page->m_text = text;
ff829f3f 354
587ce561 355 gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() );
3eb78d7e
RR
356
357 return TRUE;
ff7b1510 358}
53b28675 359
debe6624 360bool wxNotebook::SetPageImage( int page, int image )
53b28675 361{
3eb78d7e 362 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
f861258f 363
3eb78d7e 364 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 365
3eb78d7e 366 if (!nb_page) return FALSE;
f861258f 367
3eb78d7e
RR
368 /* Optimization posibility: return immediately if image unchanged.
369 * Not enabled because it may break existing (stupid) code that
370 * manipulates the imagelist to cycle images */
f861258f 371
3eb78d7e 372 /* if (image == nb_page->m_image) return TRUE; */
f861258f
VZ
373
374 /* For different cases:
3eb78d7e
RR
375 1) no image -> no image
376 2) image -> no image
377 3) no image -> image
378 4) image -> image */
f861258f 379
3eb78d7e
RR
380 if (image == -1 && nb_page->m_image == -1)
381 return TRUE; /* Case 1): Nothing to do. */
f861258f 382
bbe0af5b 383 GtkWidget *pixmapwid = (GtkWidget*) NULL;
f861258f
VZ
384
385 if (nb_page->m_image != -1)
3eb78d7e
RR
386 {
387 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
f861258f 388
3eb78d7e
RR
389 GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
390 while (child)
391 {
f861258f 392 if (GTK_IS_PIXMAP(child->data))
3eb78d7e
RR
393 {
394 pixmapwid = GTK_WIDGET(child->data);
395 break;
396 }
397 child = child->next;
398 }
f861258f 399
3eb78d7e 400 /* We should have the pixmap widget now */
f861258f
VZ
401 wxASSERT(pixmapwid != NULL);
402
403 if (image == -1)
3eb78d7e
RR
404 {
405 /* If there's no new widget, just remove the old from the box */
406 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
407 nb_page->m_image = -1;
53b28675 408
3eb78d7e
RR
409 return TRUE; /* Case 2) */
410 }
411 }
f861258f 412
3eb78d7e
RR
413 /* Only cases 3) and 4) left */
414 wxASSERT( m_imageList != NULL ); /* Just in case */
f861258f 415
3eb78d7e
RR
416 /* Construct the new pixmap */
417 const wxBitmap *bmp = m_imageList->GetBitmap(image);
418 GdkPixmap *pixmap = bmp->GetPixmap();
419 GdkBitmap *mask = (GdkBitmap*) NULL;
f861258f 420 if ( bmp->GetMask() )
3eb78d7e
RR
421 {
422 mask = bmp->GetMask()->GetBitmap();
423 }
f861258f
VZ
424
425 if (pixmapwid == NULL)
3eb78d7e
RR
426 {
427 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
428 pixmapwid = gtk_pixmap_new (pixmap, mask );
f861258f 429
3eb78d7e
RR
430 /* CHECKME: Are these pack flags okay? */
431 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3);
432 gtk_widget_show(pixmapwid);
433 }
f861258f 434 else
3eb78d7e
RR
435 {
436 /* Case 4) Simply replace the pixmap */
437 gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
438 }
f861258f 439
3eb78d7e 440 nb_page->m_image = image;
53b28675 441
3eb78d7e 442 return TRUE;
ff7b1510 443}
53b28675
RR
444
445void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
446{
223d09f6 447 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
ff7b1510 448}
53b28675
RR
449
450void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) )
451{
223d09f6 452 wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") );
ff7b1510 453}
53b28675 454
74e3313b 455void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
ca8b28f2 456{
223d09f6 457 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
ca8b28f2
JS
458}
459
ff829f3f 460bool wxNotebook::DeleteAllPages()
53b28675 461{
223d09f6 462 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 463
587ce561
RR
464 while (m_pages.GetCount() > 0)
465 DeletePage( m_pages.GetCount()-1 );
ff829f3f 466
3eb78d7e 467 return TRUE;
ff7b1510 468}
53b28675 469
ff829f3f 470bool wxNotebook::DeletePage( int page )
53b28675 471{
3eb78d7e
RR
472 wxNotebookPage* nb_page = GetNotebookPage(page);
473 if (!nb_page) return FALSE;
53b28675 474
29f538ce
RR
475 /* GTK sets GtkNotebook.cur_page to NULL before sending
476 the switvh page event */
477 m_lastSelection = GetSelection();
478
587ce561 479 nb_page->m_client->Destroy();
3eb78d7e 480 m_pages.DeleteObject( nb_page );
29f538ce
RR
481
482 m_lastSelection = -1;
fed46e72 483
3eb78d7e 484 return TRUE;
fed46e72
RR
485}
486
487bool wxNotebook::RemovePage( int page )
488{
3eb78d7e 489 wxNotebookPage* nb_page = GetNotebookPage(page);
587ce561 490
3eb78d7e 491 if (!nb_page) return FALSE;
fed46e72 492
587ce561 493 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 494
3eb78d7e 495 m_pages.DeleteObject( nb_page );
ff829f3f 496
3eb78d7e 497 return TRUE;
ff7b1510 498}
53b28675 499
587ce561
RR
500bool wxNotebook::InsertPage( int position, wxWindow* win, const wxString& text,
501 bool select, int imageId )
53b28675 502{
223d09f6 503 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 504
587ce561 505 wxCHECK_MSG( win->GetParent() == this, FALSE,
223d09f6 506 wxT("Can't add a page whose parent is not the notebook!") );
8aadf227 507
587ce561
RR
508 /* don't receive switch page during addition */
509 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
510 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
511
512 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
53b28675 513
587ce561
RR
514 wxNotebookPage *page = new wxNotebookPage();
515
516 if (position < 0)
517 m_pages.Append( page );
518 else
519 m_pages.Insert( m_pages.Nth( position ), page );
520
521 page->m_client = win;
8aadf227 522
587ce561
RR
523 page->m_box = gtk_hbox_new( FALSE, 0 );
524 gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 );
525
d1af991f
RR
526 gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
527 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
528
587ce561
RR
529 if (position < 0)
530 gtk_notebook_append_page( notebook, win->m_widget, page->m_box );
531 else
532 gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position );
533
c693edf3 534 page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;
ef44a621 535
587ce561
RR
536 /* set the label image */
537 page->m_image = imageId;
538
3eb78d7e 539 if (imageId != -1)
e4a81a2e 540 {
3eb78d7e
RR
541 wxASSERT( m_imageList != NULL );
542
543 const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
544 GdkPixmap *pixmap = bmp->GetPixmap();
545 GdkBitmap *mask = (GdkBitmap*) NULL;
546 if ( bmp->GetMask() )
547 {
548 mask = bmp->GetMask()->GetBitmap();
549 }
e4a81a2e 550
3eb78d7e 551 GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
24d20a8f 552
3eb78d7e 553 gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3);
24d20a8f 554
3eb78d7e
RR
555 gtk_widget_show(pixmapwid);
556 }
24d20a8f 557
587ce561 558 /* set the label text */
3eb78d7e 559 page->m_text = text;
223d09f6 560 if (page->m_text.IsEmpty()) page->m_text = wxT("");
587ce561
RR
561
562 page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) );
563 gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 );
741fd203 564
587ce561
RR
565 /* show the label */
566 gtk_widget_show( GTK_WIDGET(page->m_label) );
741fd203 567
587ce561
RR
568 if (select && (m_pages.GetCount() > 1))
569 {
570 if (position < 0)
571 SetSelection( GetPageCount()-1 );
572 else
573 SetSelection( position );
574 }
741fd203 575
587ce561
RR
576 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
577 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
ff829f3f 578
3eb78d7e 579 return TRUE;
ff7b1510 580}
53b28675 581
587ce561
RR
582bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
583 bool select, int imageId)
584{
585 return InsertPage( -1, win, text, select, imageId );
586}
587
b98d804b
RR
588void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
589{
f861258f 590 if (event.IsWindowChange())
b98d804b 591 AdvanceSelection( event.GetDirection() );
f861258f 592 else
b98d804b
RR
593 event.Skip();
594}
595
ff829f3f 596wxWindow *wxNotebook::GetPage( int page ) const
53b28675 597{
223d09f6 598 wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, wxT("invalid notebook") );
a81258be 599
b292e2f5
RR
600 wxNotebookPage* nb_page = GetNotebookPage(page);
601 if (!nb_page)
602 return (wxWindow *) NULL;
603 else
604 return nb_page->m_client;
ff7b1510 605}
53b28675 606
5a8c929e 607// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 608void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 609{
b292e2f5
RR
610 // don't set the sizes of the pages - their correct size is not yet known
611 wxControl::SetConstraintSizes(FALSE);
5a8c929e
VZ
612}
613
e3e65dac 614bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 615{
b292e2f5 616 return TRUE;
5a8c929e
VZ
617}
618
58614078 619void wxNotebook::ApplyWidgetStyle()
a81258be 620{
b292e2f5
RR
621 SetWidgetStyle();
622 gtk_widget_set_style( m_widget, m_widgetStyle );
a81258be
RR
623}
624
58d1c1ae
RR
625bool wxNotebook::IsOwnGtkWindow( GdkWindow *window )
626{
627 return ((m_widget->window == window) ||
628 (GTK_NOTEBOOK(m_widget)->panel == window));
629}
630
53b28675 631//-----------------------------------------------------------------------------
ff829f3f 632// wxNotebookEvent
53b28675
RR
633//-----------------------------------------------------------------------------
634
92976ab6 635IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
5b011451 636
a3a7f879 637#endif