]> git.saurik.com Git - wxWidgets.git/commitdiff
replace m_insertCallback with a virtual function, contrary to the old comments a...
authorPaul Cornett <paulcor@bullseye.com>
Fri, 29 Aug 2008 15:46:48 +0000 (15:46 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Fri, 29 Aug 2008 15:46:48 +0000 (15:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55354 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
include/wx/gtk/collpane.h
include/wx/gtk/dataview.h
include/wx/gtk/filedlg.h
include/wx/gtk/mdi.h
include/wx/gtk/notebook.h
include/wx/gtk/popupwin.h
include/wx/gtk/tbargtk.h
include/wx/gtk/window.h
src/gtk/collpane.cpp
src/gtk/dataview.cpp
src/gtk/filedlg.cpp
src/gtk/mdi.cpp
src/gtk/notebook.cpp
src/gtk/popupwin.cpp
src/gtk/tbargtk.cpp
src/gtk/window.cpp

index ecc8f9bd3acfe301cf9d538e7a620e4c96b788c1..813daea8f45260a0b460ddc04d84ee39ce701b68 100644 (file)
@@ -70,6 +70,7 @@ public:     // used by GTK callbacks
 
 private:
     void OnSize(wxSizeEvent&);
+    virtual void AddChildGTK(wxWindowGTK* child);
 
     DECLARE_DYNAMIC_CLASS(wxCollapsiblePane)
     DECLARE_EVENT_TABLE()
index 402720cce95a9133c29b727f0fd097649f7966fa..28167393b793276638ad9a1427295384fb05b444 100644 (file)
@@ -431,6 +431,7 @@ private:
     wxDataViewCtrlInternal  *m_internal;
     wxDataViewColumnList     m_cols;
 
+    virtual void AddChildGTK(wxWindowGTK* child);
     void GtkEnableSelectionEvents();
     void GtkDisableSelectionEvents();
     
index 65054227e64f09157e8cce68e20ff2afa49b9c14..e588526f0070894b7295ae275b3021eac29d26bb 100644 (file)
@@ -62,6 +62,7 @@ protected:
 private:
     void OnFakeOk( wxCommandEvent &event );
     void OnSize(wxSizeEvent&);
+    virtual void AddChildGTK(wxWindowGTK* child);
 
     wxGtkFileChooser    m_fc;
 
index 53a3cdecebb9a69067e6b8164d8cad90338749ba..6f420f8a4f6e86cd2d8b7f665509d12a3e7b1274 100644 (file)
@@ -183,6 +183,8 @@ public:
     virtual bool CreateClient( wxMDIParentFrame *parent, long style = wxVSCROLL | wxHSCROLL );
 
 private:
+    virtual void AddChildGTK(wxWindowGTK* child);
+
     DECLARE_DYNAMIC_CLASS(wxMDIClientWindow)
 };
 
index befac801d8bdd800b79b6ffd93ff6d3e6ffff319..45cb903ea5dbb9b5a8eabc3c662efd4109b98234 100644 (file)
@@ -8,8 +8,8 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifndef __GTKNOTEBOOKH__
-#define __GTKNOTEBOOKH__
+#ifndef _WX_GTKNOTEBOOK_H_
+#define _WX_GTKNOTEBOOK_H_
 
 //-----------------------------------------------------------------------------
 // internal class
@@ -135,9 +135,10 @@ private:
     // the padding set by SetPadding()
     int m_padding;
 
+    virtual void AddChildGTK(wxWindowGTK* child);
+
     DECLARE_DYNAMIC_CLASS(wxNotebook)
     DECLARE_EVENT_TABLE()
 };
 
-#endif
-    // __GTKNOTEBOOKH__
+#endif // _WX_GTKNOTEBOOK_H_
index cb0f7f18dd208c09f79724bddcbf2bc019ec8fd6..bd1a638b7f7c044416cfd59b32d0d2a81d079c10 100644 (file)
@@ -41,6 +41,8 @@ protected:
     virtual void DoMoveWindow(int x, int y, int width, int height);
 
 private:
+    virtual void AddChildGTK(wxWindowGTK* child);
+
 #ifdef __WXUNIVERSAL__
     DECLARE_EVENT_TABLE()
 #endif
index e1529d9861a445beed783995f0c0712ce09de9e9..07bff7128a392a882b595d133a685ddff5460d85 100644 (file)
@@ -86,6 +86,7 @@ private:
     void Init();
     void GtkSetStyle();
     GSList* GetRadioGroup(size_t pos);
+    virtual void AddChildGTK(wxWindowGTK* child);
 
     GtkToolbar* m_toolbar;
     GtkTooltips* m_tooltips;
index f2af094363a48456ea787459c3c71bbc001f0e53..33a190824b2eb81df64727e47e5b65b3edf60134 100644 (file)
@@ -139,9 +139,7 @@ public:
     bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size );
     void PostCreation();
 
-    // Internal addition of child windows. differs from class
-    // to class not by using virtual functions but by using
-    // the m_insertCallback.
+    // Internal addition of child windows
     void DoAddChild(wxWindowGTK *child);
 
     // This methods sends wxPaintEvents to the window. It reads the
@@ -303,12 +301,6 @@ public:
     bool                 m_showOnIdle:1;        // postpone showing the window until idle
 
 protected:
-    // C++ has no virtual methods in the constrcutor of any class but we need
-    // different methods of inserting a child window into a wxFrame,
-    // wxMDIFrame, wxNotebook etc. this is the callback that will get used.
-    typedef void (*InsertChildFunction)(wxWindowGTK*, wxWindowGTK*);
-    InsertChildFunction m_insertCallback;
-
     // implement the base class pure virtuals
     virtual void DoClientToScreen( int *x, int *y ) const;
     virtual void DoScreenToClient( int *x, int *y ) const;
@@ -384,6 +376,7 @@ private:
     // return true if we scrolled, false otherwise (on error or simply if we
     // are already at the end)
     bool DoScrollByUnits(ScrollDir dir, ScrollUnit unit, int units);
+    virtual void AddChildGTK(wxWindowGTK* child);
 
 
     DECLARE_DYNAMIC_CLASS(wxWindowGTK)
index 6c27ad35ef384c0044afd4109230c914fe537b35..dd68dda50558ae6ff9eaad6af8352ee243fb68ab 100644 (file)
@@ -148,15 +148,14 @@ gtk_collapsiblepane_expanded_callback(GObject * WXUNUSED(object),
 }
 }
 
-static void
-gtk_collapsiblepane_insert_callback(wxWindowGTK* parent, wxWindowGTK* child)
+void wxCollapsiblePane::AddChildGTK(wxWindowGTK* child)
 {
-    // this callback should be used only once to insert the "pane" into the
+    // should be used only once to insert the "pane" into the
     // GtkExpander widget. wxGenericCollapsiblePane::DoAddChild() will check if
     // it has been called only once (and in any case we would get a warning
     // from the following call as GtkExpander is a GtkBin and can contain only
     // a single child!).
-    gtk_container_add (GTK_CONTAINER (parent->m_widget), child->m_widget);
+    gtk_container_add(GTK_CONTAINER(m_widget), child->m_widget);
 }
 
 //-----------------------------------------------------------------------------
@@ -197,10 +196,6 @@ bool wxCollapsiblePane::Create(wxWindow *parent,
     g_signal_connect(m_widget, "notify::expanded",
                      G_CALLBACK(gtk_collapsiblepane_expanded_callback), this);
 
-    // before creating m_pPane, we need to makesure our own insert callback
-    // will be used
-    m_insertCallback = gtk_collapsiblepane_insert_callback;
-
     // this the real "pane"
     m_pPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                            wxTAB_TRAVERSAL|wxNO_BORDER);
index 58b3538b6a843a4ed7b03b3a525c67c7832e3962..c3bb0ccd49428b921d6980123b3bfb58cb48ebb1 100644 (file)
@@ -3439,14 +3439,9 @@ wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter*
     // wxDataViewCtrl
 //-----------------------------------------------------------------------------
 
-//-----------------------------------------------------------------------------
-// InsertChild for wxDataViewCtrl
-//-----------------------------------------------------------------------------
-
-static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child )
+void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child)
 {
-    wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent;
-    GtkWidget *treeview = dvc->GtkGetTreeView();
+    GtkWidget* treeview = GtkGetTreeView();
 
     // Insert widget in GtkTreeView
     if (GTK_WIDGET_REALIZED(treeview))
@@ -3607,8 +3602,6 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
         return false;
     }
 
-    m_insertCallback = wxInsertChildInDataViewCtrl;
-
     m_widget = gtk_scrolled_window_new (NULL, NULL);
     g_object_ref(m_widget);
 
index a472332a8b17273e73571a3b99bff299f0f12a39..d7a2d8a57e663aeaf1d48044df60b2f4de0e56f9 100644 (file)
@@ -145,12 +145,12 @@ static void extra_widget_size_request(GtkWidget*, GtkRequisition* req, wxWindow*
 }
 }
 
-static void wxInsertChildInFileDialog(wxWindow* parent, wxWindow* child)
+void wxFileDialog::AddChildGTK(wxWindowGTK* child)
 {
     g_signal_connect_after(child->m_widget, "size_request",
         G_CALLBACK(extra_widget_size_request), child);
     gtk_file_chooser_set_extra_widget(
-        GTK_FILE_CHOOSER(parent->m_widget), child->m_widget);
+        GTK_FILE_CHOOSER(m_widget), child->m_widget);
 }
 
 //-----------------------------------------------------------------------------
@@ -173,7 +173,6 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
                            const wxString& name)
     : wxFileDialogBase()
 {
-    m_insertCallback = wxInsertChildInFileDialog;
     parent = GetParentForModalDialog(parent);
 
     if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName,
index 2503d660831d60d5c1340bc43c7a25d81a38224b..f3f027e03e990ecc9b01b8749275e3d124eeed12 100644 (file)
@@ -402,11 +402,7 @@ void wxMDIChildFrame::SetTitle( const wxString &title )
     gtk_notebook_set_tab_label_text(notebook, m_widget, wxGTK_CONV( title ) );
 }
 
-//-----------------------------------------------------------------------------
-// InsertChild callback for wxMDIClientWindow
-//-----------------------------------------------------------------------------
-
-static void wxInsertChildInMDI(wxWindow* parent, wxWindow* child)
+void wxMDIClientWindow::AddChildGTK(wxWindowGTK* child)
 {
     wxMDIChildFrame* child_frame = wx_static_cast(wxMDIChildFrame*, child);
     wxString s = child_frame->GetTitle();
@@ -415,13 +411,13 @@ static void wxInsertChildInMDI(wxWindow* parent, wxWindow* child)
     GtkWidget *label_widget = gtk_label_new( s.mbc_str() );
     gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
 
-    GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
+    GtkNotebook* notebook = GTK_NOTEBOOK(m_widget);
 
     gtk_notebook_append_page( notebook, child->m_widget, label_widget );
 
     child_frame->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
 
-    wxMDIParentFrame *parent_frame = wx_static_cast(wxMDIParentFrame*, parent->GetParent());
+    wxMDIParentFrame* parent_frame = wx_static_cast(wxMDIParentFrame*, GetParent());
     parent_frame->m_justInserted = true;
 }
 
@@ -447,8 +443,6 @@ wxMDIClientWindow::~wxMDIClientWindow()
 
 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
 {
-    m_insertCallback = wxInsertChildInMDI;
-
     if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
         !CreateBase( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("wxMDIClientWindow") ))
     {
index 60fe23a01fb76af158681a3910072fe2e37acdce..13bc0dae9dedf3d882042f50004faba93a25c5c6 100644 (file)
@@ -104,7 +104,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 +114,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
@@ -160,8 +160,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;
 
@@ -377,7 +375,7 @@ bool wxNotebook::InsertPage( size_t position,
     wxCHECK_MSG( position <= GetPageCount(), false,
                  _T("invalid page index in wxNotebookPage::InsertPage()") );
 
-    // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
+    // Hack Alert! (Part II): See above in wxNotebook::AddChildGTK
     // why this has to be done.
     gtk_widget_unparent(win->m_widget);
 
index 5bcc578fa71be643abbb594a41358d276851b951..0885668e42f8952817b7a4a9530b26dd11e25ba2 100644 (file)
@@ -98,27 +98,18 @@ gtk_dialog_realized_callback( GtkWidget * WXUNUSED(widget), wxPopupWindow *win )
 }
 }
 
-//-----------------------------------------------------------------------------
-// InsertChild for wxPopupWindow
-//-----------------------------------------------------------------------------
-
-/* Callback for wxFrame. This very strange beast has to be used because
- * C++ has no virtual methods in a constructor. We have to emulate a
- * virtual function here as wxWidgets requires different ways to insert
- * a child in container classes. */
-
-static void wxInsertChildInPopupWin(wxWindowGTK* parent, wxWindowGTK* child)
+void wxPopupWindow::AddChildGTK(wxWindowGTK* child)
 {
     gtk_widget_set_size_request(
         child->m_widget, child->m_width, child->m_height);
     gtk_fixed_put(
-        GTK_FIXED(parent->m_wxwindow), child->m_widget, child->m_x, child->m_y);
+        GTK_FIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y);
 
-    if (parent->HasFlag(wxTAB_TRAVERSAL))
+    if (HasFlag(wxTAB_TRAVERSAL))
     {
         /* we now allow a window to get the focus as long as it
            doesn't have any children. */
-        GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
+        GTK_WIDGET_UNSET_FLAGS(m_wxwindow, GTK_CAN_FOCUS);
     }
 }
 
@@ -151,8 +142,6 @@ bool wxPopupWindow::Create( wxWindow *parent, int style )
     // All dialogs should really have this style
     m_windowStyle |= wxTAB_TRAVERSAL;
 
-    m_insertCallback = wxInsertChildInPopupWin;
-
     m_widget = gtk_window_new( GTK_WINDOW_POPUP );
     g_object_ref(m_widget);
 
index a179de76e9a25113f591d3d216f6308a7bdf4291..7deab1ffa54a348cc79ab1faf4a150184c0b8cf3 100644 (file)
@@ -242,20 +242,15 @@ arrow_button_press_event(GtkToggleButton* button, GdkEventButton* event, wxToolB
 }
 }
 
-//-----------------------------------------------------------------------------
-// InsertChild callback for wxToolBar
-//-----------------------------------------------------------------------------
-
-static void wxInsertChildInToolBar(wxWindow* parent, wxWindow* child)
+void wxToolBar::AddChildGTK(wxWindowGTK* child)
 {
     GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
     gtk_widget_show(align);
     gtk_container_add(GTK_CONTAINER(align), child->m_widget);
     GtkToolItem* item = gtk_tool_item_new();
     gtk_container_add(GTK_CONTAINER(item), align);
-    wxToolBar* tbar = static_cast<wxToolBar*>(parent);
     // position will be corrected in DoInsertTool if necessary
-    gtk_toolbar_insert(GTK_TOOLBAR(GTK_BIN(tbar->m_widget)->child), item, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(GTK_BIN(m_widget)->child), item, -1);
 }
 
 // ----------------------------------------------------------------------------
@@ -370,8 +365,6 @@ bool wxToolBar::Create( wxWindow *parent,
                         long style,
                         const wxString& name )
 {
-    m_insertCallback = wxInsertChildInToolBar;
-
     if ( !PreCreation( parent, pos, size ) ||
          !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
@@ -532,7 +525,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
         case wxTOOL_STYLE_CONTROL:
             wxWindow* control = tool->GetControl();
             if (control->m_widget->parent == NULL)
-                wxInsertChildInToolBar(this, control);
+                AddChildGTK(control);
             tool->m_item = GTK_TOOL_ITEM(control->m_widget->parent->parent);
             if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos))
             {
index fb849b4953d5e12d8634f28f85f241948c777d4c..d79586731544a345bdb111e24cb83099bb376f9c 100644 (file)
@@ -1905,29 +1905,18 @@ wxWindow *wxWindowBase::DoFindFocus()
     return wx_static_cast(wxWindow*, focus);
 }
 
-//-----------------------------------------------------------------------------
-// InsertChild for wxWindowGTK.
-//-----------------------------------------------------------------------------
-
-/* Callback for wxWindowGTK. This very strange beast has to be used because
- * C++ has no virtual methods in a constructor. We have to emulate a
- * virtual function here as wxNotebook requires a different way to insert
- * a child in it. I had opted for creating a wxNotebookPage window class
- * which would have made this superfluous (such in the MDI window system),
- * but no-one was listening to me... */
-
-static void wxInsertChildInWindow( wxWindowGTK* parent, wxWindowGTK* child )
+void wxWindowGTK::AddChildGTK(wxWindowGTK* child)
 {
     /* the window might have been scrolled already, do we
        have to adapt the position */
-    wxPizza* pizza = WX_PIZZA(parent->m_wxwindow);
+    wxPizza* pizza = WX_PIZZA(m_wxwindow);
     child->m_x += pizza->m_scroll_x;
     child->m_y += pizza->m_scroll_y;
 
     gtk_widget_set_size_request(
         child->m_widget, child->m_width, child->m_height);
     gtk_fixed_put(
-        GTK_FIXED(parent->m_wxwindow), child->m_widget, child->m_x, child->m_y);
+        GTK_FIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y);
 }
 
 //-----------------------------------------------------------------------------
@@ -2012,8 +2001,6 @@ void wxWindowGTK::Init()
     m_oldClientWidth =
     m_oldClientHeight = 0;
 
-    m_insertCallback = wxInsertChildInWindow;
-
     m_clipPaintRegion = false;
 
     m_needsStyleChange = false;
@@ -3100,13 +3087,8 @@ bool wxWindowGTK::Reparent( wxWindowBase *newParentBase )
 
     wxASSERT( GTK_IS_WIDGET(m_widget) );
 
-    /* prevent GTK from deleting the widget arbitrarily */
-    gtk_widget_ref( m_widget );
-
     if (oldParent)
-    {
         gtk_container_remove( GTK_CONTAINER(m_widget->parent), m_widget );
-    }
 
     wxASSERT( GTK_IS_WIDGET(m_widget) );
 
@@ -3117,14 +3099,10 @@ bool wxWindowGTK::Reparent( wxWindowBase *newParentBase )
             m_showOnIdle = true;
             gtk_widget_hide( m_widget );
         }
-
         /* insert GTK representation */
-        (*(newParent->m_insertCallback))(newParent, this);
+        newParent->AddChildGTK(this);
     }
 
-    /* reverse: prevent GTK from deleting the widget arbitrarily */
-    gtk_widget_unref( m_widget );
-
     SetLayoutDirection(wxLayout_Default);
 
     return true;
@@ -3139,7 +3117,7 @@ void wxWindowGTK::DoAddChild(wxWindowGTK *child)
     AddChild( child );
 
     /* insert GTK representation */
-    (*m_insertCallback)(this, child);
+    AddChildGTK(child);
 }
 
 void wxWindowGTK::AddChild(wxWindowBase *child)