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