]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/notebook.cpp
Bug fix in GetLabelFromText
[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 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") );
db434467 216 return FALSE;
4dcaf11a
RR
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
db434467 233 if (m_windowStyle & wxNB_RIGHT)
a3a7f879 234 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
db434467 235 if (m_windowStyle & wxNB_LEFT)
a3a7f879 236 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
db434467 237 if (m_windowStyle & wxNB_BOTTOM)
a3a7f879
RS
238 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
239
b292e2f5 240 PostCreation();
ff829f3f 241
db434467
RR
242 SetFont( parent->GetFont() );
243
6d693bb4
RR
244 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
245 GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this );
a6aa9b1e 246
b292e2f5
RR
247 Show( TRUE );
248
249 return TRUE;
ff7b1510 250}
53b28675 251
ed58dbea
RR
252void wxNotebook::SetFocus()
253{
254 if (m_pages.GetCount() == 0) return;
255
256 wxNode *node = m_pages.Nth( GetSelection() );
257
258 if (!node) return;
259
260 wxNotebookPage *page = (wxNotebookPage*) node->Data();
261
262 page->m_client->SetFocus();
263}
264
ff829f3f 265int wxNotebook::GetSelection() const
53b28675 266{
223d09f6 267 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
53b28675 268
587ce561 269 GList *pages = GTK_NOTEBOOK(m_widget)->children;
ef44a621 270
587ce561 271 if (g_list_length(pages) == 0) return -1;
53b28675 272
587ce561 273 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
a6aa9b1e 274
29f538ce 275 if (notebook->cur_page == NULL) return m_lastSelection;
a6aa9b1e 276
29f538ce 277 return g_list_index( pages, (gpointer)(notebook->cur_page) );
ff7b1510 278}
53b28675 279
ff829f3f 280int wxNotebook::GetPageCount() const
53b28675 281{
587ce561 282 return (int) g_list_length( GTK_NOTEBOOK(m_widget)->children );
ff7b1510 283}
53b28675 284
ff829f3f 285int wxNotebook::GetRowCount() const
53b28675 286{
b292e2f5 287 return 1;
ff7b1510 288}
53b28675 289
ff829f3f 290wxString wxNotebook::GetPageText( int page ) const
53b28675 291{
223d09f6 292 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") );
ef44a621 293
b292e2f5
RR
294 wxNotebookPage* nb_page = GetNotebookPage(page);
295 if (nb_page)
296 return nb_page->m_text;
297 else
223d09f6 298 return wxT("");
ff7b1510 299}
53b28675 300
ff829f3f 301int wxNotebook::GetPageImage( int page ) const
53b28675 302{
223d09f6 303 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 304
b292e2f5
RR
305 wxNotebookPage* nb_page = GetNotebookPage(page);
306 if (nb_page)
307 return nb_page->m_image;
308 else
587ce561 309 return -1;
ff7b1510 310}
53b28675 311
587ce561 312wxNotebookPage* wxNotebook::GetNotebookPage( int page ) const
53b28675 313{
223d09f6 314 wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*) NULL, wxT("invalid notebook") );
ff829f3f 315
223d09f6 316 wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxNotebookPage*) NULL, wxT("invalid notebook index") );
a6aa9b1e 317
587ce561 318 wxNode *node = m_pages.Nth( page );
a6aa9b1e 319
587ce561 320 return (wxNotebookPage *) node->Data();
ff7b1510 321}
53b28675 322
ff829f3f 323int wxNotebook::SetSelection( int page )
53b28675 324{
223d09f6 325 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 326
223d09f6 327 wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, wxT("invalid notebook index") );
ff829f3f 328
587ce561 329 int selOld = GetSelection();
a6aa9b1e 330
587ce561 331 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 332
3eb78d7e 333 return selOld;
ff7b1510 334}
53b28675 335
587ce561 336void wxNotebook::AdvanceSelection( bool forward )
ff829f3f 337{
223d09f6 338 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
a81258be 339
3eb78d7e
RR
340 int sel = GetSelection();
341 int max = GetPageCount();
ff829f3f 342
587ce561 343 if (forward)
3eb78d7e
RR
344 SetSelection( sel == max ? 0 : sel + 1 );
345 else
b98d804b 346 SetSelection( sel == 0 ? max-1 : sel - 1 );
ff829f3f
VZ
347}
348
53b28675
RR
349void wxNotebook::SetImageList( wxImageList* imageList )
350{
3eb78d7e 351 m_imageList = imageList;
ff7b1510 352}
53b28675 353
ff829f3f 354bool wxNotebook::SetPageText( int page, const wxString &text )
53b28675 355{
223d09f6 356 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 357
3eb78d7e 358 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 359
223d09f6 360 wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") );
ff829f3f 361
3eb78d7e 362 nb_page->m_text = text;
ff829f3f 363
587ce561 364 gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() );
a6aa9b1e 365
3eb78d7e 366 return TRUE;
ff7b1510 367}
53b28675 368
debe6624 369bool wxNotebook::SetPageImage( int page, int image )
53b28675 370{
3eb78d7e 371 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
f861258f 372
3eb78d7e 373 wxNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 374
3eb78d7e 375 if (!nb_page) return FALSE;
f861258f 376
3eb78d7e
RR
377 /* Optimization posibility: return immediately if image unchanged.
378 * Not enabled because it may break existing (stupid) code that
379 * manipulates the imagelist to cycle images */
f861258f 380
3eb78d7e 381 /* if (image == nb_page->m_image) return TRUE; */
f861258f
VZ
382
383 /* For different cases:
3eb78d7e
RR
384 1) no image -> no image
385 2) image -> no image
386 3) no image -> image
387 4) image -> image */
f861258f 388
3eb78d7e
RR
389 if (image == -1 && nb_page->m_image == -1)
390 return TRUE; /* Case 1): Nothing to do. */
f861258f 391
bbe0af5b 392 GtkWidget *pixmapwid = (GtkWidget*) NULL;
f861258f
VZ
393
394 if (nb_page->m_image != -1)
3eb78d7e
RR
395 {
396 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
f861258f 397
3eb78d7e
RR
398 GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
399 while (child)
400 {
f861258f 401 if (GTK_IS_PIXMAP(child->data))
3eb78d7e
RR
402 {
403 pixmapwid = GTK_WIDGET(child->data);
404 break;
405 }
406 child = child->next;
407 }
f861258f 408
3eb78d7e 409 /* We should have the pixmap widget now */
f861258f
VZ
410 wxASSERT(pixmapwid != NULL);
411
412 if (image == -1)
3eb78d7e
RR
413 {
414 /* If there's no new widget, just remove the old from the box */
415 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
416 nb_page->m_image = -1;
53b28675 417
3eb78d7e
RR
418 return TRUE; /* Case 2) */
419 }
420 }
f861258f 421
3eb78d7e
RR
422 /* Only cases 3) and 4) left */
423 wxASSERT( m_imageList != NULL ); /* Just in case */
f861258f 424
3eb78d7e
RR
425 /* Construct the new pixmap */
426 const wxBitmap *bmp = m_imageList->GetBitmap(image);
427 GdkPixmap *pixmap = bmp->GetPixmap();
428 GdkBitmap *mask = (GdkBitmap*) NULL;
f861258f 429 if ( bmp->GetMask() )
3eb78d7e
RR
430 {
431 mask = bmp->GetMask()->GetBitmap();
432 }
f861258f
VZ
433
434 if (pixmapwid == NULL)
3eb78d7e
RR
435 {
436 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
437 pixmapwid = gtk_pixmap_new (pixmap, mask );
f861258f 438
3eb78d7e
RR
439 /* CHECKME: Are these pack flags okay? */
440 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3);
441 gtk_widget_show(pixmapwid);
442 }
f861258f 443 else
3eb78d7e
RR
444 {
445 /* Case 4) Simply replace the pixmap */
446 gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
447 }
f861258f 448
3eb78d7e 449 nb_page->m_image = image;
53b28675 450
3eb78d7e 451 return TRUE;
ff7b1510 452}
53b28675
RR
453
454void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
455{
223d09f6 456 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
ff7b1510 457}
53b28675
RR
458
459void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) )
460{
223d09f6 461 wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") );
ff7b1510 462}
53b28675 463
74e3313b 464void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
ca8b28f2 465{
223d09f6 466 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
ca8b28f2
JS
467}
468
ff829f3f 469bool wxNotebook::DeleteAllPages()
53b28675 470{
223d09f6 471 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 472
587ce561
RR
473 while (m_pages.GetCount() > 0)
474 DeletePage( m_pages.GetCount()-1 );
ff829f3f 475
3eb78d7e 476 return TRUE;
ff7b1510 477}
53b28675 478
ff829f3f 479bool wxNotebook::DeletePage( int page )
53b28675 480{
3eb78d7e
RR
481 wxNotebookPage* nb_page = GetNotebookPage(page);
482 if (!nb_page) return FALSE;
53b28675 483
29f538ce
RR
484 /* GTK sets GtkNotebook.cur_page to NULL before sending
485 the switvh page event */
486 m_lastSelection = GetSelection();
a6aa9b1e 487
587ce561 488 nb_page->m_client->Destroy();
3eb78d7e 489 m_pages.DeleteObject( nb_page );
a6aa9b1e 490
29f538ce 491 m_lastSelection = -1;
fed46e72 492
3eb78d7e 493 return TRUE;
fed46e72
RR
494}
495
496bool wxNotebook::RemovePage( int page )
497{
3eb78d7e 498 wxNotebookPage* nb_page = GetNotebookPage(page);
a6aa9b1e 499
3eb78d7e 500 if (!nb_page) return FALSE;
fed46e72 501
587ce561 502 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 503
3eb78d7e 504 m_pages.DeleteObject( nb_page );
ff829f3f 505
3eb78d7e 506 return TRUE;
ff7b1510 507}
53b28675 508
587ce561
RR
509bool wxNotebook::InsertPage( int position, wxWindow* win, const wxString& text,
510 bool select, int imageId )
53b28675 511{
223d09f6 512 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 513
587ce561 514 wxCHECK_MSG( win->GetParent() == this, FALSE,
223d09f6 515 wxT("Can't add a page whose parent is not the notebook!") );
8aadf227 516
a6aa9b1e
RD
517 /* don't receive switch page during addition */
518 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
587ce561 519 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
a6aa9b1e 520
587ce561 521 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
53b28675 522
587ce561 523 wxNotebookPage *page = new wxNotebookPage();
a6aa9b1e 524
587ce561
RR
525 if (position < 0)
526 m_pages.Append( page );
527 else
528 m_pages.Insert( m_pages.Nth( position ), page );
a6aa9b1e 529
587ce561 530 page->m_client = win;
8aadf227 531
587ce561
RR
532 page->m_box = gtk_hbox_new( FALSE, 0 );
533 gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 );
534
d1af991f
RR
535 gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
536 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
537
587ce561
RR
538 if (position < 0)
539 gtk_notebook_append_page( notebook, win->m_widget, page->m_box );
a6aa9b1e 540 else
587ce561
RR
541 gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position );
542
c693edf3 543 page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;
ef44a621 544
587ce561
RR
545 /* set the label image */
546 page->m_image = imageId;
a6aa9b1e 547
3eb78d7e 548 if (imageId != -1)
e4a81a2e 549 {
3eb78d7e
RR
550 wxASSERT( m_imageList != NULL );
551
552 const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
553 GdkPixmap *pixmap = bmp->GetPixmap();
554 GdkBitmap *mask = (GdkBitmap*) NULL;
555 if ( bmp->GetMask() )
556 {
557 mask = bmp->GetMask()->GetBitmap();
558 }
e4a81a2e 559
3eb78d7e 560 GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
24d20a8f 561
3eb78d7e 562 gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3);
24d20a8f 563
3eb78d7e
RR
564 gtk_widget_show(pixmapwid);
565 }
24d20a8f 566
587ce561 567 /* set the label text */
3eb78d7e 568 page->m_text = text;
223d09f6 569 if (page->m_text.IsEmpty()) page->m_text = wxT("");
a6aa9b1e 570
587ce561
RR
571 page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) );
572 gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 );
741fd203 573
587ce561
RR
574 /* show the label */
575 gtk_widget_show( GTK_WIDGET(page->m_label) );
741fd203 576
587ce561
RR
577 if (select && (m_pages.GetCount() > 1))
578 {
579 if (position < 0)
580 SetSelection( GetPageCount()-1 );
581 else
582 SetSelection( position );
583 }
741fd203 584
587ce561
RR
585 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
586 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
ff829f3f 587
3eb78d7e 588 return TRUE;
ff7b1510 589}
53b28675 590
587ce561
RR
591bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
592 bool select, int imageId)
593{
594 return InsertPage( -1, win, text, select, imageId );
595}
596
b98d804b
RR
597void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
598{
f861258f 599 if (event.IsWindowChange())
b98d804b 600 AdvanceSelection( event.GetDirection() );
f861258f 601 else
b98d804b
RR
602 event.Skip();
603}
604
ff829f3f 605wxWindow *wxNotebook::GetPage( int page ) const
53b28675 606{
223d09f6 607 wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, wxT("invalid notebook") );
a81258be 608
b292e2f5
RR
609 wxNotebookPage* nb_page = GetNotebookPage(page);
610 if (!nb_page)
611 return (wxWindow *) NULL;
612 else
613 return nb_page->m_client;
ff7b1510 614}
53b28675 615
5a8c929e 616// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 617void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 618{
b292e2f5
RR
619 // don't set the sizes of the pages - their correct size is not yet known
620 wxControl::SetConstraintSizes(FALSE);
5a8c929e
VZ
621}
622
e3e65dac 623bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 624{
b292e2f5 625 return TRUE;
5a8c929e
VZ
626}
627
58614078 628void wxNotebook::ApplyWidgetStyle()
a81258be 629{
db434467
RR
630 // TODO, font for labels etc
631
b292e2f5
RR
632 SetWidgetStyle();
633 gtk_widget_set_style( m_widget, m_widgetStyle );
a81258be
RR
634}
635
58d1c1ae
RR
636bool wxNotebook::IsOwnGtkWindow( GdkWindow *window )
637{
638 return ((m_widget->window == window) ||
639 (GTK_NOTEBOOK(m_widget)->panel == window));
640}
641
53b28675 642//-----------------------------------------------------------------------------
ff829f3f 643// wxNotebookEvent
53b28675
RR
644//-----------------------------------------------------------------------------
645
92976ab6 646IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
5b011451 647
a3a7f879 648#endif