fix removing control tool (partial backport of r52840 and r53913), ticket #4102
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53915 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -95,6 +95,12 @@ public:
|
|||||||
: wxToolBarToolBase(tbar, control)
|
: wxToolBarToolBase(tbar, control)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a radio button?
|
// is this a radio button?
|
||||||
@@ -252,11 +258,9 @@ static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
|
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
|
||||||
wxWindow* child)
|
wxWindow* /* child */)
|
||||||
{
|
{
|
||||||
// Child widget will be inserted into GtkToolbar by DoInsertTool. Ref it
|
// Child widget will be inserted into GtkToolbar by DoInsertTool()
|
||||||
// here so reparenting into wxToolBar doesn't delete it.
|
|
||||||
g_object_ref(child->m_widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -493,8 +497,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
(const char *) NULL,
|
(const char *) NULL,
|
||||||
posGtk
|
posGtk
|
||||||
);
|
);
|
||||||
// release reference obtained by wxInsertChildInToolBar
|
tool->m_item = align;
|
||||||
g_object_unref(tool->GetControl()->m_widget);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,11 +518,17 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
|
|||||||
switch ( tool->GetStyle() )
|
switch ( tool->GetStyle() )
|
||||||
{
|
{
|
||||||
case wxTOOL_STYLE_CONTROL:
|
case wxTOOL_STYLE_CONTROL:
|
||||||
tool->GetControl()->Destroy();
|
// don't destroy the control here as we can be called from
|
||||||
break;
|
// RemoveTool() and then we need to keep the control alive;
|
||||||
|
// while if we're called from DeleteTool() the control will
|
||||||
|
// be destroyed when wxToolBarToolBase itself is deleted
|
||||||
|
gtk_container_remove(
|
||||||
|
GTK_CONTAINER(tool->m_item), tool->GetControl()->m_widget);
|
||||||
|
// fall through
|
||||||
|
|
||||||
case wxTOOL_STYLE_BUTTON:
|
case wxTOOL_STYLE_BUTTON:
|
||||||
gtk_widget_destroy( tool->m_item );
|
gtk_widget_destroy( tool->m_item );
|
||||||
|
tool->m_item = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
|
Reference in New Issue
Block a user