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