From 48200154f43831be952cf2503a926af333efb2b5 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Fri, 29 Aug 2008 15:46:48 +0000 Subject: [PATCH] replace m_insertCallback with a virtual function, contrary to the old comments a virtual works just fine git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55354 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/collpane.h | 1 + include/wx/gtk/dataview.h | 1 + include/wx/gtk/filedlg.h | 1 + include/wx/gtk/mdi.h | 2 ++ include/wx/gtk/notebook.h | 9 +++++---- include/wx/gtk/popupwin.h | 2 ++ include/wx/gtk/tbargtk.h | 1 + include/wx/gtk/window.h | 11 ++--------- src/gtk/collpane.cpp | 11 +++-------- src/gtk/dataview.cpp | 11 ++--------- src/gtk/filedlg.cpp | 5 ++--- src/gtk/mdi.cpp | 12 +++--------- src/gtk/notebook.cpp | 8 +++----- src/gtk/popupwin.cpp | 19 ++++--------------- src/gtk/tbargtk.cpp | 13 +++---------- src/gtk/window.cpp | 32 +++++--------------------------- 16 files changed, 40 insertions(+), 99 deletions(-) diff --git a/include/wx/gtk/collpane.h b/include/wx/gtk/collpane.h index ecc8f9b..813daea 100644 --- a/include/wx/gtk/collpane.h +++ b/include/wx/gtk/collpane.h @@ -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() diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 402720c..2816739 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -431,6 +431,7 @@ private: wxDataViewCtrlInternal *m_internal; wxDataViewColumnList m_cols; + virtual void AddChildGTK(wxWindowGTK* child); void GtkEnableSelectionEvents(); void GtkDisableSelectionEvents(); diff --git a/include/wx/gtk/filedlg.h b/include/wx/gtk/filedlg.h index 6505422..e588526 100644 --- a/include/wx/gtk/filedlg.h +++ b/include/wx/gtk/filedlg.h @@ -62,6 +62,7 @@ protected: private: void OnFakeOk( wxCommandEvent &event ); void OnSize(wxSizeEvent&); + virtual void AddChildGTK(wxWindowGTK* child); wxGtkFileChooser m_fc; diff --git a/include/wx/gtk/mdi.h b/include/wx/gtk/mdi.h index 53a3cde..6f420f8 100644 --- a/include/wx/gtk/mdi.h +++ b/include/wx/gtk/mdi.h @@ -183,6 +183,8 @@ public: virtual bool CreateClient( wxMDIParentFrame *parent, long style = wxVSCROLL | wxHSCROLL ); private: + virtual void AddChildGTK(wxWindowGTK* child); + DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) }; diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index befac80..45cb903 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -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_ diff --git a/include/wx/gtk/popupwin.h b/include/wx/gtk/popupwin.h index cb0f7f1..bd1a638 100644 --- a/include/wx/gtk/popupwin.h +++ b/include/wx/gtk/popupwin.h @@ -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 diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index e1529d9..07bff71 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -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; diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index f2af094..33a1908 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -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) diff --git a/src/gtk/collpane.cpp b/src/gtk/collpane.cpp index 6c27ad3..dd68dda 100644 --- a/src/gtk/collpane.cpp +++ b/src/gtk/collpane.cpp @@ -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); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 58b3538..c3bb0cc 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -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); diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index a472332..d7a2d8a 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -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, diff --git a/src/gtk/mdi.cpp b/src/gtk/mdi.cpp index 2503d66..f3f027e 100644 --- a/src/gtk/mdi.cpp +++ b/src/gtk/mdi.cpp @@ -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") )) { diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 60fe23a..13bc0da 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -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); diff --git a/src/gtk/popupwin.cpp b/src/gtk/popupwin.cpp index 5bcc578..0885668 100644 --- a/src/gtk/popupwin.cpp +++ b/src/gtk/popupwin.cpp @@ -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); diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index a179de7..7deab1f 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -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(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)) { diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index fb849b4..d795867 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -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) -- 2.7.4