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