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