Hold a reference on m_widget for the life of the associated wxWindow object.

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
This commit is contained in:
Paul Cornett
2008-08-26 16:19:23 +00:00
parent 4a693a9b8c
commit 9ff9d30c0a
43 changed files with 72 additions and 42 deletions

View File

@@ -30,7 +30,7 @@ public:
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize, const wxSize& sz = wxDefaultSize,
const wxString& name = wxFileDialogNameStr); const wxString& name = wxFileDialogNameStr);
virtual ~wxFileDialog() { delete m_extraControl; } virtual ~wxFileDialog();
virtual wxString GetPath() const; virtual wxString GetPath() const;
virtual void GetPaths(wxArrayString& paths) const; virtual void GetPaths(wxArrayString& paths) const;

View File

@@ -211,6 +211,7 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id,
SetWindowStyle(style); SetWindowStyle(style);
m_widget = gtk_image_new(); m_widget = gtk_image_new();
g_object_ref(m_widget);
gtk_widget_show(m_widget); gtk_widget_show(m_widget);
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );

View File

@@ -137,6 +137,7 @@ bool wxBitmapButton::Create( wxWindow *parent,
m_bmpNormal = bitmap; m_bmpNormal = bitmap;
m_widget = gtk_button_new(); m_widget = gtk_button_new();
g_object_ref(m_widget);
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );

View File

@@ -32,14 +32,6 @@
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
#ifdef __WXGTK24__
#include "wx/gtk/win_gtk.h"
#include <gobject/gvaluecollector.h>
#include <gtk/gtktreemodel.h>
#endif
// ============================================================================ // ============================================================================
// implementation // implementation
// ============================================================================ // ============================================================================
@@ -133,6 +125,7 @@ void wxBitmapComboBox::GTKCreateComboBoxWidget()
m_entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); m_entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
gtk_entry_set_editable( m_entry, TRUE ); 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 // This must be called as gtk_combo_box_entry_new_with_model adds
// automatically adds one text column. // automatically adds one text column.

View File

@@ -100,6 +100,7 @@ bool wxButton::Create(wxWindow *parent,
} }
m_widget = gtk_button_new_with_mnemonic(""); m_widget = gtk_button_new_with_mnemonic("");
g_object_ref(m_widget);
float x_alignment = 0.5; float x_alignment = 0.5;
if (HasFlag(wxBU_LEFT)) if (HasFlag(wxBU_LEFT))

View File

@@ -88,6 +88,7 @@ bool wxGtkCalendarCtrl::Create(wxWindow *parent,
} }
m_widget = gtk_calendar_new(); m_widget = gtk_calendar_new();
g_object_ref(m_widget);
SetDate(date.IsValid() ? date : wxDateTime::Today()); SetDate(date.IsValid() ? date : wxDateTime::Today());
if (style & wxCAL_NO_MONTH_CHANGE) if (style & wxCAL_NO_MONTH_CHANGE)

View File

@@ -144,6 +144,7 @@ bool wxCheckBox::Create(wxWindow *parent,
m_widgetLabel = GTK_BIN(m_widgetCheckbox)->child; m_widgetLabel = GTK_BIN(m_widgetCheckbox)->child;
m_widget = m_widgetCheckbox; m_widget = m_widgetCheckbox;
} }
g_object_ref(m_widget);
SetLabel( label ); SetLabel( label );
g_signal_connect (m_widgetCheckbox, "toggled", g_signal_connect (m_widgetCheckbox, "toggled",

View File

@@ -79,6 +79,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
} }
m_widget = gtk_combo_box_new_text(); m_widget = gtk_combo_box_new_text();
g_object_ref(m_widget);
Append(n, choices); Append(n, choices);

View File

@@ -68,6 +68,7 @@ bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
m_colour = col; m_colour = col;
m_widget = gtk_color_button_new_with_color( m_colour.GetColor() ); m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
g_object_ref(m_widget);
gtk_widget_show(m_widget); gtk_widget_show(m_widget);
// GtkColourButton signals // GtkColourButton signals

View File

@@ -189,6 +189,7 @@ bool wxCollapsiblePane::Create(wxWindow *parent,
m_widget = m_widget =
gtk_expander_new_with_mnemonic(wxGTK_CONV(GTKConvertMnemonics(label))); gtk_expander_new_with_mnemonic(wxGTK_CONV(GTKConvertMnemonics(label)));
g_object_ref(m_widget);
// see the gtk_collapsiblepane_expanded_callback comments to understand why // see the gtk_collapsiblepane_expanded_callback comments to understand why
// we connect to the "notify::expanded" signal instead of the more common // we connect to the "notify::expanded" signal instead of the more common

View File

@@ -53,6 +53,8 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title)); m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title));
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
g_object_ref(m_widget);
if ( parentGTK ) if ( parentGTK )
{ {
gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK); gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK);

View File

@@ -156,6 +156,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
void wxComboBox::GTKCreateComboBoxWidget() void wxComboBox::GTKCreateComboBoxWidget()
{ {
m_widget = gtk_combo_box_entry_new_text(); m_widget = gtk_combo_box_entry_new_text();
g_object_ref(m_widget);
m_entry = GTK_ENTRY(GTK_BIN(m_widget)->child); m_entry = GTK_ENTRY(GTK_BIN(m_widget)->child);
} }

View File

@@ -3610,6 +3610,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
m_insertCallback = wxInsertChildInDataViewCtrl; m_insertCallback = wxInsertChildInDataViewCtrl;
m_widget = gtk_scrolled_window_new (NULL, NULL); m_widget = gtk_scrolled_window_new (NULL, NULL);
g_object_ref(m_widget);
GtkScrolledWindowSetBorder(m_widget, style); GtkScrolledWindowSetBorder(m_widget, style);

View File

@@ -120,6 +120,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL); NULL);
g_object_ref(m_widget);
gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);

View File

@@ -287,6 +287,7 @@ bool wxGtkFileCtrl::Create( wxWindow *parent,
gtkAction = GTK_FILE_CHOOSER_ACTION_SAVE; gtkAction = GTK_FILE_CHOOSER_ACTION_SAVE;
m_widget = gtk_alignment_new ( 0, 0, 1, 1 ); 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) ); m_fcWidget = GTK_FILE_CHOOSER( gtk_file_chooser_widget_new(gtkAction) );
gtk_widget_show ( GTK_WIDGET( m_fcWidget ) ); gtk_widget_show ( GTK_WIDGET( m_fcWidget ) );
gtk_container_add ( GTK_CONTAINER ( m_widget ), GTK_WIDGET( m_fcWidget ) ); gtk_container_add ( GTK_CONTAINER ( m_widget ), GTK_WIDGET( m_fcWidget ) );

View File

@@ -214,6 +214,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
ok_btn_stock, GTK_RESPONSE_ACCEPT, ok_btn_stock, GTK_RESPONSE_ACCEPT,
NULL); NULL);
g_object_ref(m_widget);
GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget); GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget);
m_fc.SetWidget(file_chooser); 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)) void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
{ {
EndDialog(wxID_OK); EndDialog(wxID_OK);

View File

@@ -81,6 +81,7 @@ bool wxFileButton::Create( wxWindow *parent, wxWindowID id,
// NOTE: we deliberately ignore the given label as GtkFileChooserButton // NOTE: we deliberately ignore the given label as GtkFileChooserButton
// use as label the currently selected file // use as label the currently selected file
m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget ); m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget );
g_object_ref(m_widget);
gtk_widget_show(m_widget); gtk_widget_show(m_widget);
// we need to know when the dialog has been dismissed clicking OK... // 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() 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) 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 // NOTE: we deliberately ignore the given label as GtkFileChooserButton
// use as label the currently selected file // use as label the currently selected file
m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget ); m_widget = gtk_file_chooser_button_new_with_dialog( m_dialog->m_widget );
g_object_ref(m_widget);
gtk_widget_show(m_widget); gtk_widget_show(m_widget);
@@ -249,12 +245,6 @@ bool wxDirButton::Create( wxWindow *parent, wxWindowID id,
wxDirButton::~wxDirButton() 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) void wxDirButton::SetPath(const wxString& str)

View File

@@ -98,6 +98,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
wxString m_message( _("Choose font") ); wxString m_message( _("Choose font") );
m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
g_object_ref(m_widget);
if (parent) if (parent)
gtk_window_set_transient_for(GTK_WINDOW(m_widget), gtk_window_set_transient_for(GTK_WINDOW(m_widget),

View File

@@ -66,6 +66,7 @@ bool wxFontButton::Create( wxWindow *parent, wxWindowID id,
} }
m_widget = gtk_font_button_new(); m_widget = gtk_font_button_new();
g_object_ref(m_widget);
// set initial font // set initial font
m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT; m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT;

View File

@@ -41,6 +41,7 @@ bool wxGauge::Create( wxWindow *parent,
m_rangeMax = range; m_rangeMax = range;
m_widget = gtk_progress_bar_new(); m_widget = gtk_progress_bar_new();
g_object_ref(m_widget);
if ( style & wxGA_VERTICAL ) if ( style & wxGA_VERTICAL )
{ {
gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget), gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),

View File

@@ -84,6 +84,7 @@ bool wxHyperlinkCtrl::Create(wxWindow *parent, wxWindowID id,
} }
m_widget = gtk_link_button_new("asdfsaf asdfdsaf asdfdsa"); m_widget = gtk_link_button_new("asdfsaf asdfdsaf asdfdsa");
g_object_ref(m_widget);
gtk_widget_show(m_widget); gtk_widget_show(m_widget);
// alignment // alignment

View File

@@ -169,7 +169,7 @@ gtk_listitem_changed_callback(GtkTreeSelection * WXUNUSED(selection),
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" { extern "C" {
static gint static gboolean
gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget), gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget),
GdkEventKey *gdk_event, GdkEventKey *gdk_event,
wxListBox *listbox ) wxListBox *listbox )
@@ -362,6 +362,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
} }
m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL ); m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
g_object_ref(m_widget);
if (style & wxLB_ALWAYS_SB) if (style & wxLB_ALWAYS_SB)
{ {
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget), gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),

View File

@@ -457,6 +457,7 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
} }
m_widget = gtk_notebook_new(); m_widget = gtk_notebook_new();
g_object_ref(m_widget);
g_signal_connect (m_widget, "switch_page", g_signal_connect (m_widget, "switch_page",
G_CALLBACK (gtk_mdi_page_change_callback), parent); G_CALLBACK (gtk_mdi_page_change_callback), parent);

View File

@@ -94,6 +94,8 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st
ApplyWidgetStyle(); ApplyWidgetStyle();
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
g_object_ref(m_widget);
for (size_t i = 0; i < n; ++i ) for (size_t i = 0; i < n; ++i )
Append(menus[i], titles[i]); Append(menus[i], titles[i]);
} }

View File

@@ -140,6 +140,8 @@ void wxMessageDialog::GTKCreateMsgDialog()
#endif // GTK+ 2.6+ #endif // GTK+ 2.6+
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
g_object_ref(m_widget);
if (m_caption != wxMessageBoxCaptionStr) if (m_caption != wxMessageBoxCaptionStr)
gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); 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)); gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
gtk_widget_destroy(m_widget); gtk_widget_destroy(m_widget);
g_object_unref(m_widget);
m_widget = NULL; m_widget = NULL;
switch (result) switch (result)

View File

@@ -174,6 +174,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
m_widget = gtk_notebook_new(); m_widget = gtk_notebook_new();
g_object_ref(m_widget);
gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
@@ -345,7 +346,6 @@ wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
if ( !client ) if ( !client )
return NULL; return NULL;
gtk_widget_ref( client->m_widget );
gtk_widget_unrealize( client->m_widget ); gtk_widget_unrealize( client->m_widget );
// we don't need to unparent the client->m_widget; GTK+ will do // 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()") ); _T("invalid page index in wxNotebookPage::InsertPage()") );
// Hack Alert! (Part II): See above in wxInsertChildInNotebook callback // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
// why this has to be done. NOTE: using gtk_widget_unparent here does not // why this has to be done.
// work as it seems to undo too much and will cause errors in the gtk_widget_unparent(win->m_widget);
// gtk_notebook_insert_page below, so instead just clear the parent by
// hand here.
win->m_widget->parent = NULL;
if (m_themeEnabled) if (m_themeEnabled)
win->SetThemeEnabled(true); win->SetThemeEnabled(true);

View File

@@ -154,6 +154,7 @@ bool wxPopupWindow::Create( wxWindow *parent, int style )
m_insertCallback = wxInsertChildInPopupWin; m_insertCallback = wxInsertChildInPopupWin;
m_widget = gtk_window_new( GTK_WINDOW_POPUP ); m_widget = gtk_window_new( GTK_WINDOW_POPUP );
g_object_ref(m_widget);
if ((m_parent) && (GTK_IS_WINDOW(m_parent->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) ); gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );

View File

@@ -224,6 +224,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
} }
m_widget = GTKCreateFrame(title); m_widget = GTKCreateFrame(title);
g_object_ref(m_widget);
wxControl::SetLabel(title); wxControl::SetLabel(title);
if ( HasFlag(wxNO_BORDER) ) if ( HasFlag(wxNO_BORDER) )
{ {

View File

@@ -83,6 +83,7 @@ bool wxRadioButton::Create( wxWindow *parent,
} }
m_widget = gtk_radio_button_new_with_label( radioButtonGroup, wxGTK_CONV( label ) ); m_widget = gtk_radio_button_new_with_label( radioButtonGroup, wxGTK_CONV( label ) );
g_object_ref(m_widget);
SetLabel(label); SetLabel(label);

View File

@@ -144,6 +144,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL ); m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
else else
m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL ); m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
g_object_ref(m_widget);
m_scrollBar[0] = (GtkRange*)m_widget; m_scrollBar[0] = (GtkRange*)m_widget;

View File

@@ -307,6 +307,7 @@ bool wxSlider::Create(wxWindow *parent,
m_widget = gtk_vscale_new( (GtkAdjustment *) NULL ); m_widget = gtk_vscale_new( (GtkAdjustment *) NULL );
else else
m_widget = gtk_hscale_new( (GtkAdjustment *) NULL ); 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); gtk_scale_set_draw_value(GTK_SCALE (m_widget), (style & wxSL_LABELS) != 0);
// Keep full precision in position value // Keep full precision in position value

View File

@@ -107,6 +107,7 @@ bool wxSpinButton::Create(wxWindow *parent,
m_pos = 0; m_pos = 0;
m_widget = gtk_spin_button_new_with_range(0, 100, 1); 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), gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget),
(int)(m_windowStyle & wxSP_WRAP) ); (int)(m_windowStyle & wxSP_WRAP) );

View File

@@ -113,6 +113,7 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id,
} }
m_widget = gtk_spin_button_new_with_range(min, max, inc); 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); gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), initial);
m_value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget)); m_value = gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget));

View File

@@ -47,6 +47,7 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
m_bitmap = bitmap; m_bitmap = bitmap;
m_widget = gtk_image_new(); m_widget = gtk_image_new();
g_object_ref(m_widget);
if (bitmap.Ok()) if (bitmap.Ok())
SetBitmap(bitmap); SetBitmap(bitmap);

View File

@@ -78,6 +78,7 @@ bool wxStaticBox::Create( wxWindow *parent,
} }
m_widget = GTKCreateFrame(label); m_widget = GTKCreateFrame(label);
g_object_ref(m_widget);
// only base SetLabel needs to be called after GTKCreateFrame // only base SetLabel needs to be called after GTKCreateFrame
wxControl::SetLabel(label); wxControl::SetLabel(label);

View File

@@ -65,6 +65,7 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id,
SetSize( new_size ); SetSize( new_size );
} }
} }
g_object_ref(m_widget);
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );

View File

@@ -52,6 +52,7 @@ bool wxStaticText::Create(wxWindow *parent,
} }
m_widget = gtk_label_new(NULL); m_widget = gtk_label_new(NULL);
g_object_ref(m_widget);
GtkJustification justify; GtkJustification justify;
if ( style & wxALIGN_CENTER_HORIZONTAL ) if ( style & wxALIGN_CENTER_HORIZONTAL )

View File

@@ -32,6 +32,7 @@ wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
if (IsProtocolSupported()) if (IsProtocolSupported())
{ {
m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon")); m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon"));
g_object_ref(m_widget);
gtk_window_set_resizable(GTK_WINDOW(m_widget), false); gtk_window_set_resizable(GTK_WINDOW(m_widget), false);
wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec")); wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));

View File

@@ -51,12 +51,6 @@ public:
: wxToolBarToolBase(tbar, control, label) : wxToolBarToolBase(tbar, control, label)
{ {
m_item = NULL; 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(); void SetImage();
@@ -411,6 +405,7 @@ bool wxToolBar::Create( wxWindow *parent,
m_widget = gtk_event_box_new(); m_widget = gtk_event_box_new();
ConnectWidget( m_widget ); ConnectWidget( m_widget );
} }
g_object_ref(m_widget);
gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar)); gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar));
gtk_widget_show(GTK_WIDGET(m_toolbar)); gtk_widget_show(GTK_WIDGET(m_toolbar));

View File

@@ -687,6 +687,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
g_object_set (m_text, "has-frame", FALSE, NULL); g_object_set (m_text, "has-frame", FALSE, NULL);
} }
g_object_ref(m_widget);
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );

View File

@@ -66,6 +66,7 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
// Create the gtk widget. // Create the gtk widget.
m_widget = gtk_toggle_button_new(); m_widget = gtk_toggle_button_new();
g_object_ref(m_widget);
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); 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. // Create the gtk widget.
m_widget = gtk_toggle_button_new_with_mnemonic(""); m_widget = gtk_toggle_button_new_with_mnemonic("");
g_object_ref(m_widget);
SetLabel(label); SetLabel(label);

View File

@@ -511,6 +511,8 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
} }
} }
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
g_object_ref(m_widget);
} }
wxWindow *topParent = wxGetTopLevelParent(m_parent); wxWindow *topParent = wxGetTopLevelParent(m_parent);

View File

@@ -2131,6 +2131,7 @@ bool wxWindowGTK::Create( wxWindow *parent,
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
} }
g_object_ref(m_widget);
if (m_parent) if (m_parent)
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );
@@ -2180,17 +2181,17 @@ wxWindowGTK::~wxWindowGTK()
// delete before the widgets to avoid a crash on solaris // delete before the widgets to avoid a crash on solaris
delete m_imData; delete m_imData;
if (m_wxwindow && (m_wxwindow != m_widget))
{
gtk_widget_destroy( m_wxwindow );
m_wxwindow = (GtkWidget*) NULL;
}
if (m_widget) if (m_widget)
{ {
gtk_widget_destroy( m_widget ); // Note that gtk_widget_destroy() does not destroy the widget, it just
m_widget = (GtkWidget*) NULL; // 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 ) bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size )