X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1481968400c94128642815b6871724f118141cbc..6c1465efb76c8da3e295152bc13223e1305fa555:/src/gtk/notebook.cpp diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index c82ea26a99..427e65677c 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -89,7 +89,7 @@ WX_DEFINE_LIST(wxGtkNotebookPagesList) extern "C" { static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), - GtkNotebookPage *WXUNUSED(page), + GtkNotebookPage *WXUNUSED(gpage), guint page, wxNotebook *notebook ) { @@ -104,28 +104,34 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), 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 */ - g_signal_stop_emission_by_name (notebook->m_widget, - "switch_page"); - } - else // change allowed + if (notebook->m_skipNextPageChangeEvent) { + // this event was programatically generated by ChangeSelection() and thus must + // be skipped + notebook->m_skipNextPageChangeEvent = false; + // 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; + } + else + { + if ( !notebook->SendPageChangingEvent(page) ) + { + // program doesn't allow the page change + g_signal_stop_emission_by_name(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->SendPageChangedEvent(old); + } } notebook->m_inSwitchPage = false; @@ -220,7 +226,6 @@ gtk_notebook_key_press_callback( GtkWidget *widget, // m_selection = page; gtk_notebook_set_current_page( GTK_NOTEBOOK(widget), page ); - g_signal_stop_emission_by_name (widget, "key_press_event"); return TRUE; } @@ -248,7 +253,6 @@ gtk_notebook_key_press_callback( GtkWidget *widget, client->SetFocus(); } - g_signal_stop_emission_by_name (widget, "key_press_event"); return TRUE; } @@ -291,6 +295,7 @@ void wxNotebook::Init() { m_padding = 0; m_inSwitchPage = false; + m_skipNextPageChangeEvent = false; m_imageList = (wxImageList *) NULL; m_selection = -1; @@ -416,7 +421,7 @@ wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const return m_pagesData.Item(page)->GetData(); } -int wxNotebook::SetSelection( size_t page ) +int wxNotebook::DoSetSelection( size_t page, int flags ) { wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") ); @@ -424,10 +429,23 @@ int wxNotebook::SetSelection( size_t page ) int selOld = GetSelection(); + if ( !(flags & SetSelection_SendEvent) ) + m_skipNextPageChangeEvent = true; + // cache the selection m_selection = page; gtk_notebook_set_current_page( GTK_NOTEBOOK(m_widget), page ); +#ifdef __WXDEBUG__ + if ( !(flags & SetSelection_SendEvent) ) + { + // gtk_notebook_set_current_page will emit the switch-page signal which will be + // caught by our gtk_notebook_page_change_callback which should have reset the + // flag to false: + wxASSERT(!m_skipNextPageChangeEvent); + } +#endif // __WXDEBUG__ + wxNotebookPage *client = GetPage(page); if ( client ) client->SetFocus(); @@ -694,7 +712,7 @@ bool wxNotebook::InsertPage( size_t position, /* set the label text */ - nb_page->m_text = text; + nb_page->m_text = wxStripMenuCodes(text); if (nb_page->m_text.empty()) nb_page->m_text = wxEmptyString; nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) ); @@ -806,7 +824,7 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const wxPoint pos = GetPosition(); rect.x -= pos.x; rect.y -= pos.y; - if ( rect.Inside( pt ) ) + if ( rect.Contains( pt ) ) *flags |= wxBK_HITTEST_ONPAGE; } }