]> git.saurik.com Git - wxWidgets.git/commitdiff
Hold a reference on m_widget for the life of the associated wxWindow object.
authorPaul Cornett <paulcor@bullseye.com>
Tue, 26 Aug 2008 16:19:23 +0000 (16:19 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Tue, 26 Aug 2008 16:19:23 +0000 (16:19 +0000)
This allows removing some ugly hacks, and leaking of GtkWidgets by wxNotebook.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55288 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

43 files changed:
include/wx/gtk/filedlg.h
src/gtk/animate.cpp
src/gtk/bmpbuttn.cpp
src/gtk/bmpcbox.cpp
src/gtk/button.cpp
src/gtk/calctrl.cpp
src/gtk/checkbox.cpp
src/gtk/choice.cpp
src/gtk/clrpicker.cpp
src/gtk/collpane.cpp
src/gtk/colordlg.cpp
src/gtk/combobox.cpp
src/gtk/dataview.cpp
src/gtk/dirdlg.cpp
src/gtk/filectrl.cpp
src/gtk/filedlg.cpp
src/gtk/filepicker.cpp
src/gtk/fontdlg.cpp
src/gtk/fontpicker.cpp
src/gtk/gauge.cpp
src/gtk/hyperlink.cpp
src/gtk/listbox.cpp
src/gtk/mdi.cpp
src/gtk/menu.cpp
src/gtk/msgdlg.cpp
src/gtk/notebook.cpp
src/gtk/popupwin.cpp
src/gtk/radiobox.cpp
src/gtk/radiobut.cpp
src/gtk/scrolbar.cpp
src/gtk/slider.cpp
src/gtk/spinbutt.cpp
src/gtk/spinctrl.cpp
src/gtk/statbmp.cpp
src/gtk/statbox.cpp
src/gtk/statline.cpp
src/gtk/stattext.cpp
src/gtk/taskbar.cpp
src/gtk/tbargtk.cpp
src/gtk/textctrl.cpp
src/gtk/tglbtn.cpp
src/gtk/toplevel.cpp
src/gtk/window.cpp

index f81d91ca69106ee34bc1637a52177c42f42dbaf1..65054227e64f09157e8cce68e20ff2afa49b9c14 100644 (file)
@@ -30,7 +30,7 @@ public:
                  const wxPoint& pos = wxDefaultPosition,
                  const wxSize& sz = wxDefaultSize,
                  const wxString& name = wxFileDialogNameStr);
-    virtual ~wxFileDialog() { delete m_extraControl; }
+    virtual ~wxFileDialog();
 
     virtual wxString GetPath() const;
     virtual void GetPaths(wxArrayString& paths) const;
index 22cd588406e3a9a55a4ca21bad35e2a7c311fe38..67dd5aac993de435dcdaba63c891cbca5eae6fd1 100644 (file)
@@ -211,6 +211,7 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id,
     SetWindowStyle(style);
 
     m_widget = gtk_image_new();
+    g_object_ref(m_widget);
     gtk_widget_show(m_widget);
 
     m_parent->DoAddChild( this );
index 916cbf0f16c595cffed0dc906c754818fc587e59..7920f09130c27f6e1849f192ddf536bbc0ef18bd 100644 (file)
@@ -137,6 +137,7 @@ bool wxBitmapButton::Create( wxWindow *parent,
     m_bmpNormal = bitmap;
 
     m_widget = gtk_button_new();
+    g_object_ref(m_widget);
 
     if (style & wxNO_BORDER)
        gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
index 88e4dcb9a6a5751a629081a760da7f76d8174e7a..0378a0a0df449b7c27652ba42a52b70cd291df05 100644 (file)
 
 #include "wx/gtk/private.h"
 
-#ifdef __WXGTK24__
-    #include "wx/gtk/win_gtk.h"
-
-    #include <gobject/gvaluecollector.h>
-    #include <gtk/gtktreemodel.h>
-#endif
-
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -133,6 +125,7 @@ void wxBitmapComboBox::GTKCreateComboBoxWidget()
         m_entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
         gtk_entry_set_editable( m_entry, TRUE );
     }
+    g_object_ref(m_widget);
 
     // This must be called as gtk_combo_box_entry_new_with_model adds
     // automatically adds one text column.
index bee9497fbccaea9ff0c39cacd5048c17b65e2a54..331298c3833a507b2aa83f0b87dfbf814d54f778 100644 (file)
@@ -100,6 +100,7 @@ bool wxButton::Create(wxWindow *parent,
     }
 
     m_widget = gtk_button_new_with_mnemonic("");
+    g_object_ref(m_widget);
 
     float x_alignment = 0.5;
     if (HasFlag(wxBU_LEFT))
index 313a3e3dc6091498fc390fdfca6070d4e74990cb..2da9293d0bb3f35f1272bcf9e0f50dac88e79557 100644 (file)
@@ -88,6 +88,7 @@ bool wxGtkCalendarCtrl::Create(wxWindow *parent,
     }
 
     m_widget = gtk_calendar_new();
+    g_object_ref(m_widget);
     SetDate(date.IsValid() ? date : wxDateTime::Today());
 
     if (style & wxCAL_NO_MONTH_CHANGE)
index 1e4bcf5922f92337e223ac71156492162e34fab5..3e925d11603a735bfbda9f6f5d8fd1583ed96936 100644 (file)
@@ -144,6 +144,7 @@ bool wxCheckBox::Create(wxWindow *parent,
         m_widgetLabel = GTK_BIN(m_widgetCheckbox)->child;
         m_widget = m_widgetCheckbox;
     }
+    g_object_ref(m_widget);
     SetLabel( label );
 
     g_signal_connect (m_widgetCheckbox, "toggled",
index 97129ba2f1e5652eb08ac46d8c492375ee806d77..8ccb592059d5ad881d2281b45bc70836956db57b 100644 (file)
@@ -79,6 +79,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
     }
 
     m_widget = gtk_combo_box_new_text();
+    g_object_ref(m_widget);
 
     Append(n, choices);
 
index de19aa7c4d8f6a673f79d0e76e6fa687db66f39a..014285911154883f6d1931c9b0e0c94cd1d753ae 100644 (file)
@@ -68,6 +68,7 @@ bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
 
     m_colour = col;
     m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
+    g_object_ref(m_widget);
     gtk_widget_show(m_widget);
 
     // GtkColourButton signals
index d312306ca30703bf8e38be7e2874e404569d31fd..6c27ad35ef384c0044afd4109230c914fe537b35 100644 (file)
@@ -189,6 +189,7 @@ bool wxCollapsiblePane::Create(wxWindow *parent,
 
     m_widget =
         gtk_expander_new_with_mnemonic(wxGTK_CONV(GTKConvertMnemonics(label)));
+    g_object_ref(m_widget);
 
     // see the gtk_collapsiblepane_expanded_callback comments to understand why
     // we connect to the "notify::expanded" signal instead of the more common
index 07623444a34f1fef6e45c1dd5c03516f4be83ebf..8300d82f83d1813fdc2096f8828b4a83110fca41 100644 (file)
@@ -53,6 +53,8 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
     m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title));
 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
 
+    g_object_ref(m_widget);
+
     if ( parentGTK )
     {
         gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK);
index 30a9824ea49893c9403ce72fb59aff8b10e47135..b94d1f983b341429a83def8e8e4f1bc54ca5e408 100644 (file)
@@ -156,6 +156,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
 void wxComboBox::GTKCreateComboBoxWidget()
 {
     m_widget = gtk_combo_box_entry_new_text();
+    g_object_ref(m_widget);
 
     m_entry = GTK_ENTRY(GTK_BIN(m_widget)->child);
 }
index 697d1cf9cc962e13636c5ae6394a53e7375b295a..58b3538b6a843a4ed7b03b3a525c67c7832e3962 100644 (file)
@@ -3610,6 +3610,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     m_insertCallback = wxInsertChildInDataViewCtrl;
 
     m_widget = gtk_scrolled_window_new (NULL, NULL);
+    g_object_ref(m_widget);
 
     GtkScrolledWindowSetBorder(m_widget, style);
 
index 7874ff5773f8dc06960c9c81d687509d06d24f13..08e4a0af44558238d0f61238993209588ff81103 100644 (file)
@@ -120,6 +120,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent,
                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                    GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                    NULL);
+    g_object_ref(m_widget);
 
     gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
 
index b2729ab9e29df020f85df0f39f8d177b50be6e7a..dace1751e773a88f90abb84daad02da6e18936b6 100644 (file)
@@ -287,6 +287,7 @@ bool wxGtkFileCtrl::Create( wxWindow *parent,
         gtkAction = GTK_FILE_CHOOSER_ACTION_SAVE;
 
     m_widget =  gtk_alignment_new ( 0, 0, 1, 1 );
+    g_object_ref(m_widget);
     m_fcWidget = GTK_FILE_CHOOSER( gtk_file_chooser_widget_new(gtkAction) );
     gtk_widget_show ( GTK_WIDGET( m_fcWidget ) );
     gtk_container_add ( GTK_CONTAINER ( m_widget ), GTK_WIDGET( m_fcWidget ) );
index 6260b33b8e265bb0eeb5a9b8565d42ea38a17abd..e8906dfd4feab3be5e413f36ad8c770df496c39f 100644 (file)
@@ -214,6 +214,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                    ok_btn_stock, GTK_RESPONSE_ACCEPT,
                    NULL);
+    g_object_ref(m_widget);
     GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget);
 
     m_fc.SetWidget(file_chooser);
@@ -297,6 +298,17 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
     }
 }
 
+wxFileDialog::~wxFileDialog()
+{
+    if (m_extraControl)
+    {
+        // get chooser to drop its reference right now, allowing wxWindow dtor
+        // to verify that ref count drops to zero
+        gtk_file_chooser_set_extra_widget(
+            GTK_FILE_CHOOSER(m_widget), NULL);
+    }
+}
+
 void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
 {
     EndDialog(wxID_OK);
index 9e099cc444d6889a241b663e9608d906736ec96f..73aab00df15cb7d54d3b5d6afbe245021d718edb 100644 (file)
@@ -81,6 +81,7 @@ bool wxFileButton::Create( wxWindow *parent, wxWindowID id,
         // NOTE: we deliberately ignore the given label as GtkFileChooserButton
         //       use as label the currently selected file
         m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget );
+        g_object_ref(m_widget);
         gtk_widget_show(m_widget);
 
         // we need to know when the dialog has been dismissed clicking OK...
@@ -103,12 +104,6 @@ bool wxFileButton::Create( wxWindow *parent, wxWindowID id,
 
 wxFileButton::~wxFileButton()
 {
-    // GtkFileChooserButton will automatically destroy the
-    // GtkFileChooserDialog associated with m_dialog.
-    // Thus we have to set its m_widget to NULL to avoid
-    // double destruction on same widget
-    if (m_dialog)
-        m_dialog->m_widget = NULL;
 }
 
 void wxFileButton::OnDialogOK(wxCommandEvent& ev)
@@ -229,6 +224,7 @@ bool wxDirButton::Create( wxWindow *parent, wxWindowID id,
         // NOTE: we deliberately ignore the given label as GtkFileChooserButton
         //       use as label the currently selected file
         m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget );
+        g_object_ref(m_widget);
 
         gtk_widget_show(m_widget);
 
@@ -249,12 +245,6 @@ bool wxDirButton::Create( wxWindow *parent, wxWindowID id,
 
 wxDirButton::~wxDirButton()
 {
-    // GtkFileChooserButton will automatically destroy the
-    // GtkFileChooserDialog associated with m_dialog.
-    // Thus we have to set its m_widget to NULL to avoid
-    // double destruction on same widget
-    if (m_dialog)
-        m_dialog->m_widget = NULL;
 }
 
 void wxDirButton::SetPath(const wxString& str)
index 50f971d7567d468367a417729e4c92c9091adeea..8cb4f89917ef712f03525c54952e4ddeb157dcaf 100644 (file)
@@ -98,6 +98,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
 
     wxString m_message( _("Choose font") );
     m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
+    g_object_ref(m_widget);
 
     if (parent)
         gtk_window_set_transient_for(GTK_WINDOW(m_widget),
index 00b1181bc971559bdfc0fc4ff6db567f3c11afdb..b2cdb532e3bc8d11e4a69b46815c4b027f1f43d8 100644 (file)
@@ -66,6 +66,7 @@ bool wxFontButton::Create( wxWindow *parent, wxWindowID id,
     }
 
     m_widget = gtk_font_button_new();
+    g_object_ref(m_widget);
 
     // set initial font
     m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT;
index aaa124506cabbb677509cb9c73f52c164a3d83df..2d299229385a1fa3052e46cac5bdc21487bb60a2 100644 (file)
@@ -41,6 +41,7 @@ bool wxGauge::Create( wxWindow *parent,
     m_rangeMax = range;
 
     m_widget = gtk_progress_bar_new();
+    g_object_ref(m_widget);
     if ( style & wxGA_VERTICAL )
     {
         gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
index d9d9ea1420f82963ca2e76d9ca2a6f117136b540..44645ce0fab075e2486aef667c436e289b849207 100644 (file)
@@ -84,6 +84,7 @@ bool wxHyperlinkCtrl::Create(wxWindow *parent, wxWindowID id,
         }
 
         m_widget = gtk_link_button_new("asdfsaf asdfdsaf asdfdsa");
+        g_object_ref(m_widget);
         gtk_widget_show(m_widget);
 
         // alignment
index 79f85977bbd71fd96afcd937124e809a453ac1e2..d453bf384a9d4f50135ef732bd733de1f0da6d12 100644 (file)
@@ -169,7 +169,7 @@ gtk_listitem_changed_callback(GtkTreeSelection * WXUNUSED(selection),
 //-----------------------------------------------------------------------------
 
 extern "C" {
-static gint
+static gboolean
 gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget),
                                 GdkEventKey *gdk_event,
                                 wxListBox *listbox )
@@ -362,6 +362,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
     }
 
     m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
+    g_object_ref(m_widget);
     if (style & wxLB_ALWAYS_SB)
     {
       gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
index 4a7ddf7c9fe868e798ea233a039ed6e43f5356af..2503d660831d60d5c1340bc43c7a25d81a38224b 100644 (file)
@@ -457,6 +457,7 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
     }
 
     m_widget = gtk_notebook_new();
+    g_object_ref(m_widget);
 
     g_signal_connect (m_widget, "switch_page",
                       G_CALLBACK (gtk_mdi_page_change_callback), parent);
index 5511b9bae6336f8b43dc49fca5d0c56730e0c9c8..bbbd626e99e3d7987206b5f2ea1723fa2f2f51d7 100644 (file)
@@ -94,6 +94,8 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st
     ApplyWidgetStyle();
 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
 
+    g_object_ref(m_widget);
+
     for (size_t i = 0; i < n; ++i )
         Append(menus[i], titles[i]);
 }
index 49b2a38b1cf256e483d63e8193b12123a143cc05..b71806be72ae6e72617b2250ed2321e13f246b7d 100644 (file)
@@ -140,6 +140,8 @@ void wxMessageDialog::GTKCreateMsgDialog()
 #endif // GTK+ 2.6+
 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
 
+    g_object_ref(m_widget);
+
     if (m_caption != wxMessageBoxCaptionStr)
         gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
 
@@ -204,6 +206,7 @@ int wxMessageDialog::ShowModal()
 
     gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
     gtk_widget_destroy(m_widget);
+    g_object_unref(m_widget);
     m_widget = NULL;
 
     switch (result)
index 0b95ed355e690dd68168626678a1742815bb20aa..60fe23a01fb76af158681a3910072fe2e37acdce 100644 (file)
@@ -174,6 +174,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
 
 
     m_widget = gtk_notebook_new();
+    g_object_ref(m_widget);
 
     gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
 
@@ -345,7 +346,6 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
     if ( !client )
         return NULL;
 
-    gtk_widget_ref( client->m_widget );
     gtk_widget_unrealize( client->m_widget );
 
     // we don't need to unparent the client->m_widget; GTK+ will do
@@ -378,11 +378,8 @@ bool wxNotebook::InsertPage( size_t position,
                  _T("invalid page index in wxNotebookPage::InsertPage()") );
 
     // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
-    // why this has to be done.  NOTE: using gtk_widget_unparent here does not
-    // work as it seems to undo too much and will cause errors in the
-    // gtk_notebook_insert_page below, so instead just clear the parent by
-    // hand here.
-    win->m_widget->parent = NULL;
+    // why this has to be done.
+    gtk_widget_unparent(win->m_widget);
 
     if (m_themeEnabled)
         win->SetThemeEnabled(true);
index a16315563ba736ce45c364fb4f077a213a0f583d..5bcc578fa71be643abbb594a41358d276851b951 100644 (file)
@@ -154,6 +154,7 @@ bool wxPopupWindow::Create( wxWindow *parent, int style )
     m_insertCallback = wxInsertChildInPopupWin;
 
     m_widget = gtk_window_new( GTK_WINDOW_POPUP );
+    g_object_ref(m_widget);
 
     if ((m_parent) && (GTK_IS_WINDOW(m_parent->m_widget)))
         gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
index 15dd404b7dc91f85217d634627f758bd843774e6..33f01ccb61e1bd8be181309cdfd2663913109467 100644 (file)
@@ -224,6 +224,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
     }
 
     m_widget = GTKCreateFrame(title);
+    g_object_ref(m_widget);
     wxControl::SetLabel(title);
     if ( HasFlag(wxNO_BORDER) )
     {
index 649a520830c38758c5cbe62e89db960369cb2aff..fc095b65387bd132d8410927d678f7bc3eb47c71 100644 (file)
@@ -83,6 +83,7 @@ bool wxRadioButton::Create( wxWindow *parent,
     }
 
     m_widget = gtk_radio_button_new_with_label( radioButtonGroup, wxGTK_CONV( label ) );
+    g_object_ref(m_widget);
 
     SetLabel(label);
 
index 413e8fbe3c5f5bf2bb9708d8c215fd80e66a06a2..0a76b68267b89ad6f71f5b9c79fe803b14276b4c 100644 (file)
@@ -144,6 +144,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
         m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
     else
         m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
+    g_object_ref(m_widget);
 
     m_scrollBar[0] = (GtkRange*)m_widget;
 
index f14ae6394ae551c4ed25c47bdd6eb9b95f7b64bc..b2a24b3640b0de11ef788da6345d9ba2e37fb2bd 100644 (file)
@@ -307,6 +307,7 @@ bool wxSlider::Create(wxWindow *parent,
         m_widget = gtk_vscale_new( (GtkAdjustment *) NULL );
     else
         m_widget = gtk_hscale_new( (GtkAdjustment *) NULL );
+    g_object_ref(m_widget);
 
     gtk_scale_set_draw_value(GTK_SCALE (m_widget), (style & wxSL_LABELS) != 0);
     // Keep full precision in position value
index b886fbc324cf549b2cfa5855ccfc857db96769b8..45138d8ae483481fc4baffeeb43d91499e0eecf1 100644 (file)
@@ -107,6 +107,7 @@ bool wxSpinButton::Create(wxWindow *parent,
     m_pos = 0;
 
     m_widget = gtk_spin_button_new_with_range(0, 100, 1);
+    g_object_ref(m_widget);
 
     gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget),
                               (int)(m_windowStyle & wxSP_WRAP) );
index 77a9cb485b7a47adfab488f01dd57516498ab9e2..952d00378436cc7b079f554e9b6203c1471909a9 100644 (file)
@@ -113,6 +113,7 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id,
     }
 
     m_widget = gtk_spin_button_new_with_range(min, max, inc);
+    g_object_ref(m_widget);
 
     gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), initial);
     m_value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget));
index aeb95223ec0407ac674d4d0a271a9b85dd27a83d..b12acdde77a64e2cec979b3370ea185b5b4ddfb4 100644 (file)
@@ -47,6 +47,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
     m_bitmap = bitmap;
 
     m_widget = gtk_image_new();
+    g_object_ref(m_widget);
 
     if (bitmap.Ok())
         SetBitmap(bitmap);
index 7115010262a363e8e39c3f0f24e9c8b25148c90f..20326248c207cf18595b95d2aba90f9f20bece73 100644 (file)
@@ -78,6 +78,7 @@ bool wxStaticBox::Create( wxWindow *parent,
     }
 
     m_widget = GTKCreateFrame(label);
+    g_object_ref(m_widget);
     // only base SetLabel needs to be called after GTKCreateFrame
     wxControl::SetLabel(label);
 
index 97bfa70cfa4a3833a159ec0a323a808a541b2490..9cb487fb6ad4d5a6ae4951cbdd84a38885b8b611 100644 (file)
@@ -65,6 +65,7 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id,
             SetSize( new_size );
         }
     }
+    g_object_ref(m_widget);
 
     m_parent->DoAddChild( this );
 
index e0d277d91be0632e3d248bcdab5f3017b0dec30d..e9366a1e380a65095122356967bfcac5c7c14dde 100644 (file)
@@ -52,6 +52,7 @@ bool wxStaticText::Create(wxWindow *parent,
     }
 
     m_widget = gtk_label_new(NULL);
+    g_object_ref(m_widget);
 
     GtkJustification justify;
     if ( style & wxALIGN_CENTER_HORIZONTAL )
index 8035e5b3424ab6d59be2f2da24a9da3bbe2e7951..80bfd6b119dcebb03b89a2ef53f6bf55867374a8 100644 (file)
@@ -32,6 +32,7 @@ wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
     if (IsProtocolSupported())
     {
         m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon"));
+        g_object_ref(m_widget);
         gtk_window_set_resizable(GTK_WINDOW(m_widget), false);
 
         wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
index 63d7dae9755ad03093cae2860e104ce13c75f01a..a179de76e9a25113f591d3d216f6308a7bdf4291 100644 (file)
@@ -51,12 +51,6 @@ public:
         : wxToolBarToolBase(tbar, control, label)
     {
         m_item = NULL;
-        // Hold a reference to keep control alive until DoInsertTool() is
-        // called, or if RemoveTool() is called (see DoDeleteTool)
-        g_object_ref(control->m_widget);
-        // release reference when gtk_widget_destroy() is called on control
-        g_signal_connect(
-            control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
     }
 
     void SetImage();
@@ -411,6 +405,7 @@ bool wxToolBar::Create( wxWindow *parent,
         m_widget = gtk_event_box_new();
         ConnectWidget( m_widget );
     }
+    g_object_ref(m_widget);
     gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar));
     gtk_widget_show(GTK_WIDGET(m_toolbar));
 
index 325dcbd5c6d210cd30f428e08025a09c65f7310c..71ba5a70209efeb4a6f2d0ecd5d452e5139dae7b 100644 (file)
@@ -687,6 +687,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
             g_object_set (m_text, "has-frame", FALSE, NULL);
 
     }
+    g_object_ref(m_widget);
 
     m_parent->DoAddChild( this );
 
index b98f15130567a668edf3e0a268e7d0f0986b2d03..162d9b396ff4f1fabf46636ca3ccc9b9e95ed4ec 100644 (file)
@@ -66,6 +66,7 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
 
     // Create the gtk widget.
     m_widget = gtk_toggle_button_new();
+    g_object_ref(m_widget);
 
     if (style & wxNO_BORDER)
         gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
@@ -204,6 +205,7 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
 
     // Create the gtk widget.
     m_widget = gtk_toggle_button_new_with_mnemonic("");
+    g_object_ref(m_widget);
 
     SetLabel(label);
 
index 7ddd774e3ba9a06c08ef5f097e8a7421ff971bae..e7a51956d436cd247385a468aebb6b0d5b620314 100644 (file)
@@ -511,6 +511,8 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
             }
         }
 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
+
+        g_object_ref(m_widget);
     }
 
     wxWindow *topParent = wxGetTopLevelParent(m_parent);
index f62c235b8b7170b780c1c25004a586d2983f5741..fb849b4953d5e12d8634f28f85f241948c777d4c 100644 (file)
@@ -2131,6 +2131,7 @@ bool wxWindowGTK::Create( wxWindow *parent,
 
         gtk_widget_show( m_wxwindow );
     }
+    g_object_ref(m_widget);
 
     if (m_parent)
         m_parent->DoAddChild( this );
@@ -2180,17 +2181,17 @@ wxWindowGTK::~wxWindowGTK()
     // delete before the widgets to avoid a crash on solaris
     delete m_imData;
 
-    if (m_wxwindow && (m_wxwindow != m_widget))
-    {
-        gtk_widget_destroy( m_wxwindow );
-        m_wxwindow = (GtkWidget*) NULL;
-    }
-
     if (m_widget)
     {
-        gtk_widget_destroy( m_widget );
-        m_widget = (GtkWidget*) NULL;
+        // Note that gtk_widget_destroy() does not destroy the widget, it just
+        // emits the "destroy" signal. The widget is not actually destroyed
+        // until its reference count drops to zero.
+        gtk_widget_destroy(m_widget);
+        // Release our reference, should be the last one
+        g_object_unref(m_widget);
+        m_widget = NULL;
     }
+    m_wxwindow = NULL;
 }
 
 bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos,  const wxSize &size )