X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c58d22381aaeece1c27c1d9061061ed68f269ae3..74a8f67d96591cec101def2a7d47c64072aff7fd:/src/gtk/notebook.cpp diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 0b95ed355e..f418384a36 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -61,10 +61,11 @@ static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*); extern "C" { static void -switch_page_after(GtkWidget* widget, GtkNotebookPage*, guint, wxNotebook* win) +switch_page_after(GtkNotebook* widget, GtkNotebookPage*, guint, wxNotebook* win) { g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win); - win->SendPageChangedEvent(win->m_oldSelection); + + win->GTKOnPageChanged(); } } @@ -104,7 +105,7 @@ static void event_after(GtkNotebook* widget, GdkEvent*, wxNotebook* win) // InsertChild callback for wxNotebook //----------------------------------------------------------------------------- -static void wxInsertChildInNotebook(wxWindow* parent, wxWindow* child) +void wxNotebook::AddChildGTK(wxWindowGTK* child) { // Hack Alert! (Part I): This sets the notebook as the parent of the child // widget, and takes care of some details such as updating the state and @@ -114,7 +115,7 @@ static void wxInsertChildInNotebook(wxWindow* parent, wxWindow* child) // incorrect sizes since the widget's style context is not fully known. // See bug #901694 for details // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863) - gtk_widget_set_parent(child->m_widget, parent->m_widget); + gtk_widget_set_parent(child->m_widget, m_widget); // NOTE: This should be considered a temporary workaround until we can // work out the details and implement delaying the setting of the initial @@ -125,8 +126,6 @@ static void wxInsertChildInNotebook(wxWindow* parent, wxWindow* child) // wxNotebook //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxBookCtrlBase) - BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() @@ -160,8 +159,6 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { - m_insertCallback = wxInsertChildInNotebook; - if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) style |= wxBK_TOP; @@ -174,6 +171,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, m_widget = gtk_notebook_new(); + g_object_ref(m_widget); gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); @@ -203,7 +201,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, int wxNotebook::GetSelection() const { - wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); + wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid notebook") ); return gtk_notebook_get_current_page( GTK_NOTEBOOK(m_widget) ); } @@ -218,7 +216,7 @@ wxString wxNotebook::GetPageText( size_t page ) const int wxNotebook::GetPageImage( size_t page ) const { - wxCHECK_MSG(page < GetPageCount(), -1, "invalid notebook index"); + wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index"); return GetNotebookPage(page)->m_imageIndex; } @@ -230,7 +228,7 @@ wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const int wxNotebook::DoSetSelection( size_t page, int flags ) { - wxCHECK_MSG(page < GetPageCount(), -1, "invalid notebook index"); + wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index"); int selOld = GetSelection(); @@ -246,6 +244,8 @@ int wxNotebook::DoSetSelection( size_t page, int flags ) g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this); } + m_selection = page; + wxNotebookPage *client = GetPage(page); if ( client ) client->SetFocus(); @@ -253,6 +253,13 @@ int wxNotebook::DoSetSelection( size_t page, int flags ) return selOld; } +void wxNotebook::GTKOnPageChanged() +{ + m_selection = gtk_notebook_get_current_page(GTK_NOTEBOOK(m_widget)); + + SendPageChangedEvent(m_oldSelection); +} + bool wxNotebook::SetPageText( size_t page, const wxString &text ) { wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index"); @@ -345,7 +352,6 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page ) if ( !client ) return NULL; - gtk_widget_ref( client->m_widget ); gtk_widget_unrealize( client->m_widget ); // we don't need to unparent the client->m_widget; GTK+ will do @@ -359,7 +365,7 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page ) wxGtkNotebookPage* p = GetNotebookPage(page); m_pagesData.DeleteObject(p); delete p; - + return client; } @@ -375,14 +381,11 @@ bool wxNotebook::InsertPage( size_t position, wxT("Can't add a page whose parent is not the notebook!") ); wxCHECK_MSG( position <= GetPageCount(), false, - _T("invalid page index in wxNotebookPage::InsertPage()") ); + wxT("invalid page index in wxNotebookPage::InsertPage()") ); - // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback - // why this has to be done. NOTE: using gtk_widget_unparent here does not - // work as it seems to undo too much and will cause errors in the - // gtk_notebook_insert_page below, so instead just clear the parent by - // hand here. - win->m_widget->parent = NULL; + // Hack Alert! (Part II): See above in wxNotebook::AddChildGTK + // why this has to be done. + gtk_widget_unparent(win->m_widget); if (m_themeEnabled) win->SetThemeEnabled(true); @@ -415,7 +418,9 @@ bool wxNotebook::InsertPage( size_t position, pageData->m_image, false, false, m_padding); } else + { wxFAIL_MSG("invalid notebook imagelist"); + } } /* set the label text */ @@ -427,11 +432,11 @@ bool wxNotebook::InsertPage( size_t position, gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position); /* apply current style */ - GtkRcStyle *style = CreateWidgetStyle(); + GtkRcStyle *style = GTKCreateWidgetStyle(); if ( style ) { gtk_widget_modify_style(pageData->m_label, style); - gtk_rc_style_unref(style); + g_object_unref(style); } if (select && GetPageCount() > 1) @@ -450,24 +455,30 @@ static bool IsPointInsideWidget(const wxPoint& pt, GtkWidget *w, gint x, gint y, gint border = 0) { + GtkAllocation a; + gtk_widget_get_allocation(w, &a); return - (pt.x >= w->allocation.x - x - border) && - (pt.x <= w->allocation.x - x + border + w->allocation.width) && - (pt.y >= w->allocation.y - y - border) && - (pt.y <= w->allocation.y - y + border + w->allocation.height); + (pt.x >= a.x - x - border) && + (pt.x <= a.x - x + border + a.width) && + (pt.y >= a.y - y - border) && + (pt.y <= a.y - y + border + a.height); } int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { - const gint x = m_widget->allocation.x; - const gint y = m_widget->allocation.y; + GtkAllocation a; + gtk_widget_get_allocation(m_widget, &a); + const int x = a.x; + const int y = a.y; const size_t count = GetPageCount(); size_t i = 0; +#if !GTK_CHECK_VERSION(3,0,0) && !defined(GSEAL_ENABLE) GtkNotebook * notebook = GTK_NOTEBOOK(m_widget); if (gtk_notebook_get_scrollable(notebook)) i = g_list_position( notebook->children, notebook->first_tab ); +#endif for ( ; i < count; i++ ) { @@ -553,7 +564,7 @@ void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style) GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const { - windows.push_back(m_widget->window); + windows.push_back(gtk_widget_get_window(m_widget)); windows.push_back(GTK_NOTEBOOK(m_widget)->event_window); return NULL;