]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/notebook.cpp
Applied colour patch for better 8-bit support,
[wxWidgets.git] / src / gtk1 / notebook.cpp
CommitLineData
53b28675
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: notebook.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
ff829f3f 7// Licence: wxWindows licence
53b28675
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "notebook.h"
12#endif
13
14#include "wx/notebook.h"
dcf924a3
RR
15
16#if wxUSE_NOTEBOOK
17
53b28675
RR
18#include "wx/panel.h"
19#include "wx/utils.h"
20#include "wx/imaglist.h"
30dea054 21#include "wx/intl.h"
4bf58c62 22#include "wx/log.h"
83624f79 23
5e7e9e1b
RR
24#include <gdk/gdk.h>
25#include <gtk/gtk.h>
83624f79 26#include "wx/gtk/win_gtk.h"
5e7e9e1b 27#include <gdk/gdkkeysyms.h>
b292e2f5 28
acfd422a
RR
29//-----------------------------------------------------------------------------
30// idle system
31//-----------------------------------------------------------------------------
32
33extern void wxapp_install_idle_handler();
34extern bool g_isIdle;
35
b292e2f5
RR
36//-----------------------------------------------------------------------------
37// data
38//-----------------------------------------------------------------------------
39
40extern bool g_blockEventsOnDrag;
53b28675 41
2e563988
RR
42//-----------------------------------------------------------------------------
43// debug
44//-----------------------------------------------------------------------------
45
46#ifdef __WXDEBUG__
47
48extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window );
49
50#endif
51
219f895a 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 216 m_imageList = (wxImageList *) NULL;
b656febd 217 m_ownsImageList = FALSE;
b292e2f5 218 m_pages.DeleteContents( TRUE );
29f538ce 219 m_lastSelection = -1;
a2d93e73 220 m_themeEnabled = TRUE;
ff829f3f
VZ
221}
222
223wxNotebook::wxNotebook()
224{
b292e2f5 225 Init();
ff7b1510 226}
53b28675 227
debe6624 228wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
53b28675 229 const wxPoint& pos, const wxSize& size,
debe6624 230 long style, const wxString& name )
53b28675 231{
b292e2f5
RR
232 Init();
233 Create( parent, id, pos, size, style, name );
ff7b1510 234}
53b28675 235
ff829f3f 236wxNotebook::~wxNotebook()
53b28675 237{
587ce561 238 /* don't generate change page events any more */
a6aa9b1e 239 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
587ce561 240 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
ff829f3f 241
b292e2f5 242 DeleteAllPages();
b656febd 243 if (m_ownsImageList) delete m_imageList;
ff7b1510 244}
53b28675 245
debe6624 246bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
53b28675 247 const wxPoint& pos, const wxSize& size,
debe6624 248 long style, const wxString& name )
53b28675 249{
b292e2f5
RR
250 m_needParent = TRUE;
251 m_acceptsFocus = TRUE;
252 m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
253
4dcaf11a
RR
254 if (!PreCreation( parent, pos, size ) ||
255 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
256 {
223d09f6 257 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
8712c6e7 258 return FALSE;
4dcaf11a
RR
259 }
260
ff829f3f 261
b292e2f5 262 m_widget = gtk_notebook_new();
53b28675 263
2e563988 264#ifdef __WXDEBUG__
223d09f6 265 debug_focus_in( m_widget, wxT("wxNotebook::m_widget"), name );
2e563988
RR
266#endif
267
b292e2f5 268 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
caac5181 269
587ce561
RR
270 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
271 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
ff829f3f 272
f03fc89f 273 m_parent->DoAddChild( this );
ef44a621 274
8712c6e7
VZ
275 if (m_windowStyle & wxNB_RIGHT)
276 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
277 if (m_windowStyle & wxNB_LEFT)
278 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
279 if (m_windowStyle & wxNB_BOTTOM)
280 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
a3a7f879 281
8253c7fd
RR
282 gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event",
283 GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this );
284
b292e2f5 285 PostCreation();
ff829f3f 286
db434467
RR
287 SetFont( parent->GetFont() );
288
6d693bb4
RR
289 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
290 GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this );
a6aa9b1e 291
b292e2f5
RR
292 Show( TRUE );
293
294 return TRUE;
ff7b1510 295}
53b28675 296
ff829f3f 297int wxNotebook::GetSelection() const
53b28675 298{
223d09f6 299 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
53b28675 300
587ce561 301 GList *pages = GTK_NOTEBOOK(m_widget)->children;
ef44a621 302
587ce561 303 if (g_list_length(pages) == 0) return -1;
53b28675 304
587ce561 305 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
a6aa9b1e 306
29f538ce 307 if (notebook->cur_page == NULL) return m_lastSelection;
a6aa9b1e 308
29f538ce 309 return g_list_index( pages, (gpointer)(notebook->cur_page) );
ff7b1510 310}
53b28675 311
ff829f3f 312int wxNotebook::GetPageCount() const
53b28675 313{
587ce561 314 return (int) g_list_length( GTK_NOTEBOOK(m_widget)->children );
ff7b1510 315}
53b28675 316
ff829f3f 317int wxNotebook::GetRowCount() const
53b28675 318{
b292e2f5 319 return 1;
ff7b1510 320}
53b28675 321
ff829f3f 322wxString wxNotebook::GetPageText( int page ) const
53b28675 323{
223d09f6 324 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") );
ef44a621 325
80a58c99 326 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
b292e2f5
RR
327 if (nb_page)
328 return nb_page->m_text;
329 else
223d09f6 330 return wxT("");
ff7b1510 331}
53b28675 332
ff829f3f 333int wxNotebook::GetPageImage( int page ) const
53b28675 334{
223d09f6 335 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 336
80a58c99 337 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
b292e2f5
RR
338 if (nb_page)
339 return nb_page->m_image;
340 else
587ce561 341 return -1;
ff7b1510 342}
53b28675 343
80a58c99 344wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
53b28675 345{
80a58c99 346 wxCHECK_MSG( m_widget != NULL, (wxGtkNotebookPage*) NULL, wxT("invalid notebook") );
ff829f3f 347
80a58c99 348 wxCHECK_MSG( page < (int)m_pages.GetCount(), (wxGtkNotebookPage*) NULL, wxT("invalid notebook index") );
a6aa9b1e 349
587ce561 350 wxNode *node = m_pages.Nth( page );
a6aa9b1e 351
80a58c99 352 return (wxGtkNotebookPage *) node->Data();
ff7b1510 353}
53b28675 354
ff829f3f 355int wxNotebook::SetSelection( int page )
53b28675 356{
223d09f6 357 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
a81258be 358
223d09f6 359 wxCHECK_MSG( page < (int)m_pages.GetCount(), -1, wxT("invalid notebook index") );
ff829f3f 360
587ce561 361 int selOld = GetSelection();
a6aa9b1e 362
587ce561 363 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page );
33d0e17c
RR
364
365 wxGtkNotebookPage* g_page = GetNotebookPage( page );
366 if (g_page->m_client)
367 g_page->m_client->SetFocus();
ff829f3f 368
3eb78d7e 369 return selOld;
ff7b1510 370}
53b28675 371
587ce561 372void wxNotebook::AdvanceSelection( bool forward )
ff829f3f 373{
223d09f6 374 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
a81258be 375
3eb78d7e 376 int max = GetPageCount();
8712c6e7
VZ
377 if ( !max )
378 {
379 // nothing to do with empty notebook
380 return;
381 }
382
383 int sel = GetSelection();
ff829f3f 384
587ce561 385 if (forward)
8712c6e7 386 SetSelection( sel == max - 1 ? 0 : sel + 1 );
3eb78d7e 387 else
8712c6e7 388 SetSelection( sel == 0 ? max - 1 : sel - 1 );
ff829f3f
VZ
389}
390
53b28675
RR
391void wxNotebook::SetImageList( wxImageList* imageList )
392{
b656febd 393 if (m_ownsImageList) delete m_imageList;
3eb78d7e 394 m_imageList = imageList;
b656febd
VS
395 m_ownsImageList = FALSE;
396}
397
398void wxNotebook::AssignImageList( wxImageList* imageList )
399{
400 SetImageList(imageList);
401 m_ownsImageList = TRUE;
ff7b1510 402}
53b28675 403
ff829f3f 404bool wxNotebook::SetPageText( int page, const wxString &text )
53b28675 405{
223d09f6 406 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 407
80a58c99 408 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 409
223d09f6 410 wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") );
ff829f3f 411
3eb78d7e 412 nb_page->m_text = text;
ff829f3f 413
587ce561 414 gtk_label_set( nb_page->m_label, nb_page->m_text.mbc_str() );
a6aa9b1e 415
3eb78d7e 416 return TRUE;
ff7b1510 417}
53b28675 418
debe6624 419bool wxNotebook::SetPageImage( int page, int image )
53b28675 420{
3eb78d7e 421 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
f861258f 422
80a58c99 423 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
ef44a621 424
3eb78d7e 425 if (!nb_page) return FALSE;
f861258f 426
3eb78d7e
RR
427 /* Optimization posibility: return immediately if image unchanged.
428 * Not enabled because it may break existing (stupid) code that
429 * manipulates the imagelist to cycle images */
f861258f 430
3eb78d7e 431 /* if (image == nb_page->m_image) return TRUE; */
f861258f
VZ
432
433 /* For different cases:
3eb78d7e
RR
434 1) no image -> no image
435 2) image -> no image
436 3) no image -> image
437 4) image -> image */
f861258f 438
3eb78d7e
RR
439 if (image == -1 && nb_page->m_image == -1)
440 return TRUE; /* Case 1): Nothing to do. */
f861258f 441
bbe0af5b 442 GtkWidget *pixmapwid = (GtkWidget*) NULL;
f861258f
VZ
443
444 if (nb_page->m_image != -1)
3eb78d7e
RR
445 {
446 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
f861258f 447
3eb78d7e
RR
448 GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
449 while (child)
8712c6e7 450 {
f861258f 451 if (GTK_IS_PIXMAP(child->data))
8712c6e7
VZ
452 {
453 pixmapwid = GTK_WIDGET(child->data);
454 break;
3eb78d7e 455 }
8712c6e7
VZ
456 child = child->next;
457 }
f861258f 458
3eb78d7e 459 /* We should have the pixmap widget now */
f861258f
VZ
460 wxASSERT(pixmapwid != NULL);
461
462 if (image == -1)
8712c6e7 463 {
3eb78d7e
RR
464 /* If there's no new widget, just remove the old from the box */
465 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
466 nb_page->m_image = -1;
53b28675 467
3eb78d7e
RR
468 return TRUE; /* Case 2) */
469 }
470 }
f861258f 471
3eb78d7e
RR
472 /* Only cases 3) and 4) left */
473 wxASSERT( m_imageList != NULL ); /* Just in case */
f861258f 474
3eb78d7e
RR
475 /* Construct the new pixmap */
476 const wxBitmap *bmp = m_imageList->GetBitmap(image);
477 GdkPixmap *pixmap = bmp->GetPixmap();
478 GdkBitmap *mask = (GdkBitmap*) NULL;
f861258f 479 if ( bmp->GetMask() )
3eb78d7e
RR
480 {
481 mask = bmp->GetMask()->GetBitmap();
482 }
f861258f
VZ
483
484 if (pixmapwid == NULL)
3eb78d7e
RR
485 {
486 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
487 pixmapwid = gtk_pixmap_new (pixmap, mask );
f861258f 488
3eb78d7e
RR
489 /* CHECKME: Are these pack flags okay? */
490 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, 3);
491 gtk_widget_show(pixmapwid);
492 }
f861258f 493 else
3eb78d7e
RR
494 {
495 /* Case 4) Simply replace the pixmap */
496 gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
497 }
f861258f 498
3eb78d7e 499 nb_page->m_image = image;
53b28675 500
3eb78d7e 501 return TRUE;
ff7b1510 502}
53b28675
RR
503
504void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
505{
223d09f6 506 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
ff7b1510 507}
53b28675
RR
508
509void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) )
510{
223d09f6 511 wxFAIL_MSG( wxT("wxNotebook::SetPadding not implemented") );
ff7b1510 512}
53b28675 513
74e3313b 514void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
ca8b28f2 515{
223d09f6 516 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
ca8b28f2
JS
517}
518
ff829f3f 519bool wxNotebook::DeleteAllPages()
53b28675 520{
223d09f6 521 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 522
587ce561
RR
523 while (m_pages.GetCount() > 0)
524 DeletePage( m_pages.GetCount()-1 );
ff829f3f 525
3eb78d7e 526 return TRUE;
ff7b1510 527}
53b28675 528
ff829f3f 529bool wxNotebook::DeletePage( int page )
53b28675 530{
80a58c99 531 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
3eb78d7e 532 if (!nb_page) return FALSE;
53b28675 533
29f538ce 534 /* GTK sets GtkNotebook.cur_page to NULL before sending
f6bcfd97 535 the switch page event */
29f538ce 536 m_lastSelection = GetSelection();
a6aa9b1e 537
587ce561 538 nb_page->m_client->Destroy();
3eb78d7e 539 m_pages.DeleteObject( nb_page );
a6aa9b1e 540
29f538ce 541 m_lastSelection = -1;
fed46e72 542
3eb78d7e 543 return TRUE;
fed46e72
RR
544}
545
546bool wxNotebook::RemovePage( int page )
547{
80a58c99 548 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
a6aa9b1e 549
f6bcfd97 550 wxCHECK_MSG( nb_page, FALSE, _T("wxNotebook::RemovePage: invalid page") );
fed46e72 551
f6bcfd97
BP
552 gtk_widget_ref( nb_page->m_client->m_widget );
553 gtk_widget_unrealize( nb_page->m_client->m_widget );
554 gtk_widget_unparent( nb_page->m_client->m_widget );
555
587ce561 556 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 557
3eb78d7e 558 m_pages.DeleteObject( nb_page );
ff829f3f 559
3eb78d7e 560 return TRUE;
ff7b1510 561}
53b28675 562
80a58c99 563bool wxNotebook::InsertPage( int position, wxNotebookPage* win, const wxString& text,
587ce561 564 bool select, int imageId )
53b28675 565{
223d09f6 566 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
a81258be 567
587ce561 568 wxCHECK_MSG( win->GetParent() == this, FALSE,
223d09f6 569 wxT("Can't add a page whose parent is not the notebook!") );
8aadf227 570
a6aa9b1e
RD
571 /* don't receive switch page during addition */
572 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
587ce561 573 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
a6aa9b1e 574
a2d93e73
JS
575 if (m_themeEnabled)
576 win->SetThemeEnabled(TRUE);
577
587ce561 578 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
53b28675 579
80a58c99 580 wxGtkNotebookPage *page = new wxGtkNotebookPage();
a6aa9b1e 581
587ce561
RR
582 if (position < 0)
583 m_pages.Append( page );
584 else
585 m_pages.Insert( m_pages.Nth( position ), page );
a6aa9b1e 586
587ce561 587 page->m_client = win;
8aadf227 588
587ce561
RR
589 page->m_box = gtk_hbox_new( FALSE, 0 );
590 gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 );
591
d1af991f
RR
592 gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
593 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
594
587ce561
RR
595 if (position < 0)
596 gtk_notebook_append_page( notebook, win->m_widget, page->m_box );
a6aa9b1e 597 else
587ce561
RR
598 gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position );
599
c693edf3 600 page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;
ef44a621 601
587ce561
RR
602 /* set the label image */
603 page->m_image = imageId;
a6aa9b1e 604
3eb78d7e 605 if (imageId != -1)
e4a81a2e 606 {
3eb78d7e
RR
607 wxASSERT( m_imageList != NULL );
608
609 const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
610 GdkPixmap *pixmap = bmp->GetPixmap();
611 GdkBitmap *mask = (GdkBitmap*) NULL;
612 if ( bmp->GetMask() )
613 {
614 mask = bmp->GetMask()->GetBitmap();
615 }
e4a81a2e 616
3eb78d7e 617 GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
24d20a8f 618
3eb78d7e 619 gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3);
24d20a8f 620
3eb78d7e
RR
621 gtk_widget_show(pixmapwid);
622 }
24d20a8f 623
587ce561 624 /* set the label text */
3eb78d7e 625 page->m_text = text;
223d09f6 626 if (page->m_text.IsEmpty()) page->m_text = wxT("");
a6aa9b1e 627
587ce561
RR
628 page->m_label = GTK_LABEL( gtk_label_new(page->m_text.mbc_str()) );
629 gtk_box_pack_end( GTK_BOX(page->m_box), GTK_WIDGET(page->m_label), FALSE, FALSE, 3 );
741fd203 630
587ce561
RR
631 /* show the label */
632 gtk_widget_show( GTK_WIDGET(page->m_label) );
741fd203 633
587ce561
RR
634 if (select && (m_pages.GetCount() > 1))
635 {
636 if (position < 0)
637 SetSelection( GetPageCount()-1 );
8712c6e7 638 else
587ce561
RR
639 SetSelection( position );
640 }
741fd203 641
587ce561
RR
642 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
643 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
ff829f3f 644
3eb78d7e 645 return TRUE;
ff7b1510 646}
53b28675 647
80a58c99 648bool wxNotebook::AddPage(wxNotebookPage* win, const wxString& text,
587ce561
RR
649 bool select, int imageId)
650{
651 return InsertPage( -1, win, text, select, imageId );
652}
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
80a58c99 662wxNotebookPage *wxNotebook::GetPage( int page ) const
53b28675 663{
223d09f6 664 wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, wxT("invalid notebook") );
a81258be 665
80a58c99 666 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
b292e2f5 667 if (!nb_page)
80a58c99 668 return (wxNotebookPage *) NULL;
b292e2f5
RR
669 else
670 return nb_page->m_client;
ff7b1510 671}
53b28675 672
93d38175
VS
673#if wxUSE_CONSTRAINTS
674
5a8c929e 675// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 676void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 677{
b292e2f5
RR
678 // don't set the sizes of the pages - their correct size is not yet known
679 wxControl::SetConstraintSizes(FALSE);
5a8c929e
VZ
680}
681
e3e65dac 682bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 683{
b292e2f5 684 return TRUE;
5a8c929e
VZ
685}
686
93d38175
VS
687#endif
688
58614078 689void wxNotebook::ApplyWidgetStyle()
a81258be 690{
db434467 691 // TODO, font for labels etc
8712c6e7 692
b292e2f5
RR
693 SetWidgetStyle();
694 gtk_widget_set_style( m_widget, m_widgetStyle );
a81258be
RR
695}
696
58d1c1ae
RR
697bool wxNotebook::IsOwnGtkWindow( GdkWindow *window )
698{
699 return ((m_widget->window == window) ||
700 (GTK_NOTEBOOK(m_widget)->panel == window));
701}
702
53b28675 703//-----------------------------------------------------------------------------
ff829f3f 704// wxNotebookEvent
53b28675
RR
705//-----------------------------------------------------------------------------
706
92976ab6 707IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
5b011451 708
a3a7f879 709#endif