]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/notebook.cpp
implemented GetLabel() (part of patch 1679337)
[wxWidgets.git] / src / gtk1 / notebook.cpp
index 8acf3f1fd9f1ced142cc9100debbb1c2c7496f80..ddc1c86ddf963116cd652c81aa2577c615113b55 100644 (file)
     #include "wx/utils.h"
     #include "wx/panel.h"
     #include "wx/msgdlg.h"
+    #include "wx/bitmap.h"
 #endif
 
 #include "wx/imaglist.h"
-#include "wx/bitmap.h"
 #include "wx/fontutil.h"
 
 #include "wx/gtk1/private.h"
@@ -105,28 +105,33 @@ 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 */
-        gtk_signal_emit_stop_by_name( GTK_OBJECT(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
+            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->SendPageChangedEvent(old);
+        }
     }
 
     notebook->m_inSwitchPage = FALSE;
@@ -417,7 +422,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") );
 
@@ -425,10 +430,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_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();
@@ -780,15 +798,15 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 
                 if ( pixmap && IsPointInsideWidget(pt, pixmap, x, y) )
                 {
-                    *flags = wxNB_HITTEST_ONICON;
+                    *flags = wxBK_HITTEST_ONICON;
                 }
                 else if ( IsPointInsideWidget(pt, GTK_WIDGET(nb_page->m_label), x, y) )
                 {
-                    *flags = wxNB_HITTEST_ONLABEL;
+                    *flags = wxBK_HITTEST_ONLABEL;
                 }
                 else
                 {
-                    *flags = wxNB_HITTEST_ONITEM;
+                    *flags = wxBK_HITTEST_ONITEM;
                 }
             }
 
@@ -797,7 +815,7 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
     }
 
     if ( flags )
-        *flags = wxNB_HITTEST_NOWHERE;
+        *flags = wxBK_HITTEST_NOWHERE;
 
     return wxNOT_FOUND;
 }