]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/notebook.cpp
Back to previous call with -1 replacement.
[wxWidgets.git] / src / gtk1 / notebook.cpp
index 2d8998bbe16112f365242b0413b603ded5e860d0..ddc1c86ddf963116cd652c81aa2577c615113b55 100644 (file)
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/utils.h"
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/utils.h"
+    #include "wx/panel.h"
+    #include "wx/msgdlg.h"
+    #include "wx/bitmap.h"
 #endif
 
 #endif
 
-#include "wx/panel.h"
 #include "wx/imaglist.h"
 #include "wx/imaglist.h"
-#include "wx/bitmap.h"
 #include "wx/fontutil.h"
 
 #include "wx/gtk1/private.h"
 #include "wx/fontutil.h"
 
 #include "wx/gtk1/private.h"
@@ -30,8 +31,6 @@
 
 #include <gdk/gdkkeysyms.h>
 
 
 #include <gdk/gdkkeysyms.h>
 
-#include "wx/msgdlg.h"
-
 // ----------------------------------------------------------------------------
 // events
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // events
 // ----------------------------------------------------------------------------
@@ -106,28 +105,33 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
 
     int old = notebook->GetSelection();
 
 
     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;
         // 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;
     }
 
     notebook->m_inSwitchPage = FALSE;
@@ -325,6 +329,9 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
     m_acceptsFocus = true;
     m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
 
     m_acceptsFocus = true;
     m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
 
+    if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+        style |= wxBK_TOP;
+
     if (!PreCreation( parent, pos, size ) ||
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
     if (!PreCreation( parent, pos, size ) ||
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
@@ -415,7 +422,7 @@ wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
     return m_pagesData.Item(page)->GetData();
 }
 
     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") );
 
 {
     wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
 
@@ -423,10 +430,23 @@ int wxNotebook::SetSelection( size_t page )
 
     int selOld = GetSelection();
 
 
     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 );
 
     // 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();
     wxNotebookPage *client = GetPage(page);
     if ( client )
         client->SetFocus();
@@ -692,7 +712,7 @@ bool wxNotebook::InsertPage( size_t position,
     /* set the label text */
 
     nb_page->m_text = text;
     /* set the label text */
 
     nb_page->m_text = text;
-    if (nb_page->m_text.empty()) nb_page->m_text = wxT("");
+    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)) );
     gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );
 
     nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
     gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );
@@ -778,15 +798,15 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 
                 if ( pixmap && IsPointInsideWidget(pt, pixmap, x, y) )
                 {
 
                 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) )
                 {
                 }
                 else if ( IsPointInsideWidget(pt, GTK_WIDGET(nb_page->m_label), x, y) )
                 {
-                    *flags = wxNB_HITTEST_ONLABEL;
+                    *flags = wxBK_HITTEST_ONLABEL;
                 }
                 else
                 {
                 }
                 else
                 {
-                    *flags = wxNB_HITTEST_ONITEM;
+                    *flags = wxBK_HITTEST_ONITEM;
                 }
             }
 
                 }
             }
 
@@ -795,7 +815,7 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
     }
 
     if ( flags )
     }
 
     if ( flags )
-        *flags = wxNB_HITTEST_NOWHERE;
+        *flags = wxBK_HITTEST_NOWHERE;
 
     return wxNOT_FOUND;
 }
 
     return wxNOT_FOUND;
 }