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