+
+bool wxGtkNotebookPage::SetFont(const wxFont& font)
+{
+ if (!m_label)
+ return false;
+
+ if (m_labelStyle)
+ {
+ GtkStyle *remake = gtk_style_copy( m_labelStyle );
+
+#ifndef __WXGTK20__
+ remake->klass = m_labelStyle->klass;
+#endif
+
+ gtk_style_unref( m_labelStyle );
+ m_labelStyle = remake;
+ }
+ else
+ {
+ GtkStyle *def = gtk_rc_get_style( GTK_WIDGET(m_label) );
+
+ if (!def)
+ def = gtk_widget_get_default_style();
+
+ m_labelStyle = gtk_style_copy( def );
+
+ // FIXME: no more klass in 2.0
+#ifndef __WXGTK20__
+ m_labelStyle->klass = def->klass;
+#endif
+ }
+
+#ifdef __WXGTK20__
+ pango_font_description_free( m_labelStyle->font_desc );
+ m_labelStyle->font_desc = pango_font_description_copy( font.GetNativeFontInfo()->description );
+#else
+ gdk_font_unref( m_labelStyle->font );
+ m_labelStyle->font = gdk_font_ref( font.GetInternalFont( 1.0 ) );
+#endif
+
+ gtk_widget_set_style( GTK_WIDGET(m_label), m_labelStyle );
+
+ return true;
+}
+
+
+#include "wx/listimpl.cpp"
+WX_DEFINE_LIST(wxGtkNotebookPagesList);
+
+
+//-----------------------------------------------------------------------------
+// "switch_page"
+//-----------------------------------------------------------------------------
+
+static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
+ GtkNotebookPage *WXUNUSED(page),
+ gint page,
+ wxNotebook *notebook )
+{
+ // are you trying to call SetSelection() from a notebook event handler?
+ // you shouldn't!
+ wxCHECK_RET( !notebook->m_inSwitchPage,
+ _T("gtk_notebook_page_change_callback reentered") );
+
+ notebook->m_inSwitchPage = TRUE;
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ int old = notebook->GetSelection();
+
+ wxNotebookEvent eventChanging( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,
+ notebook->GetId(), page, old );
+ eventChanging.SetEventObject( notebook );
+
+ if ( (notebook->GetEventHandler()->ProcessEvent(eventChanging)) &&
+ !eventChanging.IsAllowed() )
+ {
+ /* program doesn't allow the page change */
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(notebook->m_widget),
+ "switch_page" );
+ }
+ else // change allowed
+ {
+ // make wxNotebook::GetSelection() return the correct (i.e. consistent
+ // with wxNotebookEvent::GetSelection()) value even though the page is
+ // not really changed in GTK+
+ notebook->m_selection = page;
+
+ wxNotebookEvent eventChanged( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
+ notebook->GetId(), page, old );
+ eventChanged.SetEventObject( notebook );
+ notebook->GetEventHandler()->ProcessEvent( eventChanged );
+ }
+
+ notebook->m_inSwitchPage = FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "size_allocate"
+//-----------------------------------------------------------------------------
+
+static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ if ((win->m_x == alloc->x) &&
+ (win->m_y == alloc->y) &&
+ (win->m_width == alloc->width) &&
+ (win->m_height == alloc->height))
+ {
+ return;
+ }
+
+ win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
+
+ /* GTK 1.2 up to version 1.2.5 is broken so that we have to call allocate
+ here in order to make repositioning after resizing to take effect. */
+ if ((gtk_major_version == 1) &&
+ (gtk_minor_version == 2) &&
+ (gtk_micro_version < 6) &&
+ (win->m_wxwindow) &&
+ (GTK_WIDGET_REALIZED(win->m_wxwindow)))
+ {
+ gtk_widget_size_allocate( win->m_wxwindow, alloc );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// "realize" from m_widget
+//-----------------------------------------------------------------------------
+
+static gint
+gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize
+ here in order to make repositioning before showing to take effect. */
+ gtk_widget_queue_resize( win->m_widget );
+
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "key_press_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *win )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ if (!win->m_hasVMT) return FALSE;
+ if (g_blockEventsOnDrag) return FALSE;
+
+ /* win is a control: tab can be propagated up */
+ if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
+ {
+ int sel = win->GetSelection();
+ if (sel == -1)
+ return TRUE;
+ wxGtkNotebookPage *nb_page = win->GetNotebookPage(sel);
+ wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
+
+ wxNavigationKeyEvent event;
+ event.SetEventObject( win );
+ /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
+ event.SetDirection( (gdk_event->keyval == GDK_Tab) );
+ /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
+ event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
+ event.SetCurrentFocus( win );
+
+ wxNotebookPage *client = win->GetPage(sel);
+ if ( !client->GetEventHandler()->ProcessEvent( event ) )
+ {
+ client->SetFocus();
+ }
+
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// InsertChild callback for wxNotebook
+//-----------------------------------------------------------------------------
+
+static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
+{
+ // Hack alert! We manually set the child window
+ // parent field so that GTK can query the
+ // notebook's style and font. Without that, GetBestSize could return
+ // incorrect size, see bug #901694 for details
+ // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863)
+ child->m_widget->parent = parent->m_widget;
+}
+