[glom/gtktoolpallete] Simplified memory management. Added some checks. Still crashes.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom/gtktoolpallete] Simplified memory management. Added some checks. Still crashes.
- Date: Wed, 23 Dec 2009 12:27:41 +0000 (UTC)
commit 9db085b4a0efd4e1f7dfa9d428c64cb87dc21f8a
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Dec 23 13:27:26 2009 +0100
Simplified memory management. Added some checks. Still crashes.
Makefile_tests.am | 10 ---
glom/mode_data/flowtablewithfields.cc | 132 ++++++++++++++++++--------------
glom/mode_data/flowtablewithfields.h | 6 +-
glom/utility_widgets/flowtable.cc | 35 ++++++++-
glom/utility_widgets/flowtable.h | 4 +
glom/utility_widgets/flowtable_dnd.cc | 7 ++-
glom/utility_widgets/test_flowtable.cc | 17 ++++
po/POTFILES.in | 4 -
8 files changed, 137 insertions(+), 78 deletions(-)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index e5eafcf..9a77960 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -21,7 +21,6 @@ check_PROGRAMS = \
glom/libglom/test_sharedptr_layoutitem \
glom/utility_widgets/test_flowtable \
glom/utility_widgets/test_flowtable_dnd \
- glom/utility_widgets/egg/toolpalette/testtoolpalette \
glom/test_pyembed \
tests/test_parsing_time \
tests/test_signal_reemit \
@@ -86,10 +85,6 @@ glom_utility_widgets_test_flowtable_SOURCES = \
glom/utility_widgets/test_flowtable.cc
glom_utility_widgets_test_flowtable_LDADD = $(GLOM_LIBS)
-EGGTOOLPALETTE_LIBS = glom/utility_widgets/egg/toolpalette/libeggtoolpalette.a\
- glom/utility_widgets/egg/util/libeggutil.a \
- $(EGG_LIBS)
-
# You must remove PlaceholderGlom::get_application() to avoid having to specify
# a huge set of .cc files when building this test:
glom_utility_widgets_test_flowtable_dnd_SOURCES = \
@@ -105,11 +100,6 @@ glom_utility_widgets_test_flowtable_dnd_SOURCES = \
glom/utility_widgets/placeholder-glom.cc \
glom/utility_widgets/test_flowtable_dnd.cc
glom_utility_widgets_test_flowtable_dnd_LDADD = $(LIBGLOM_LA) $(GLOM_LIBS) $(EGGTOOLPALETTE_LIBS)
-
-glom_utility_widgets_egg_toolpalette_testtoolpalette_SOURCES = \
- glom/utility_widgets/egg/toolpalette/testtoolpalette.c
-glom_utility_widgets_egg_toolpalette_testtoolpalette_LDADD = \
- $(EGGTOOLPALETTE_LIBS)
glom_test_pyembed_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS)
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 58d1590..91ed7d6 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -26,7 +26,6 @@
#include <glom/utility_widgets/imageglom.h>
#include <glom/utility_widgets/labelglom.h>
#include <glom/utility_widgets/dialog_flowtable.h>
-#include <glom/utility_widgets/placeholder-glom.h>
#include <glom/application.h>
#include <gtkmm/checkbutton.h>
#include <libglom/data_structure/glomconversions.h>
@@ -58,10 +57,14 @@ FlowTableWithFields::FlowTableWithFields(const Glib::ustring& table_name)
// rather annoying, though I don't see another possibility at the moment. armin.
Glib::ObjectBase("Glom_FlowTable"),
#endif // !defined(GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED)
- m_placeholder(0),
m_table_name(table_name)
{
-
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ m_placeholder_alignment.set(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
+ m_placeholder_alignment.show();
+ m_placeholder_alignment.add(m_placeholder);
+ m_placeholder.show();
+#endif //GLOM_ENABLE_CLIENT_ONLY
}
FlowTableWithFields::~FlowTableWithFields()
@@ -449,9 +452,13 @@ void FlowTableWithFields::add_layout_notebook_at_position(const sharedptr<Layout
add_layoutwidgetbase(notebook_widget, add_before);
//add_view(button); //So it can get the document.
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
- insert_before (*notebook_widget, *widget, true /* expand */);
+ insert_before(*notebook_widget, *widget, true /* expand */);
else
add(*notebook_widget, true /* expand */);
}
@@ -559,8 +566,11 @@ void FlowTableWithFields::add_field_at_position(const sharedptr<LayoutItem_Field
eventbox->set_visible_window(false);
eventbox->set_events(Gdk::ALL_EVENTS_MASK);
eventbox->show_all();
-
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before(*eventbox, *(info.m_second), *widget, expand_second);
else
@@ -595,7 +605,10 @@ void FlowTableWithFields::add_button_at_position(const sharedptr<LayoutItem_Butt
add_layoutwidgetbase(button, add_before);
//add_view(button); //So it can get the document.
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before (*button, *widget, false /* expand */);
else
@@ -622,7 +635,10 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
const Glib::ustring title = layoutitem_text->get_title();
if(title.empty())
{
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before(*alignment_label, *widget, false /* expand */);
else
@@ -640,7 +656,10 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
alignment_title->add(*title_label);
add_layoutwidgetbase(title_label, add_before);
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before (*alignment_title, *alignment_label, *widget, false /* expand */);
else
@@ -650,29 +669,19 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
void FlowTableWithFields::add_placeholder_at_position(const sharedptr<LayoutItem_Placeholder>& /* layoutitem_placeholder */, const Glib::ustring& /* table_name */, const type_list_layoutwidgets::iterator& add_before)
{
- //Delete any existing placeholder (there can be only one):
- if(m_placeholder)
- {
- delete m_placeholder;
- m_placeholder = 0;
- }
-
- //Add the widget:
- m_placeholder = Gtk::manage(new Gtk::Alignment());
- m_placeholder->set(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
- m_placeholder->show();
+ //Remove the placeholder,
+ remove(m_placeholder_alignment);
- PlaceholderGlom* preview = Gtk::manage(new PlaceholderGlom);
- preview->show();
+ m_list_layoutwidgets.insert(add_before, &m_placeholder);
- m_placeholder->add(*preview);
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
- m_list_layoutwidgets.insert(add_before, preview);
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
if(widget)
- insert_before(*m_placeholder, *widget, false /* expand */);
+ insert_before(m_placeholder_alignment, *widget, false /* expand */);
else
- add(*m_placeholder, false);
+ add(m_placeholder_alignment, false);
}
void FlowTableWithFields::add_imageobject_at_position(const sharedptr<LayoutItem_Image>& layoutitem_image, const Glib::ustring& table_name , const type_list_layoutwidgets::iterator& add_before)
@@ -691,7 +700,10 @@ void FlowTableWithFields::add_imageobject_at_position(const sharedptr<LayoutItem
const Glib::ustring title = layoutitem_image->get_title();
if(title.empty())
{
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before(*image, *widget, true /* expand */);
else
@@ -706,7 +718,11 @@ void FlowTableWithFields::add_imageobject_at_position(const sharedptr<LayoutItem
Gtk::Label* title_label = Gtk::manage(new Gtk::Label(title));
title_label->show();
alignment_title->add(*title_label);
- Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
+ Gtk::Widget* widget = 0;
+ if(add_before != m_list_layoutwidgets.end())
+ widget = dynamic_cast<Gtk::Widget*>(*add_before);
+
if(widget)
insert_before(*alignment_title, *image, *widget, true /* expand */);
else
@@ -1365,20 +1381,18 @@ void FlowTableWithFields::on_dnd_add_layout_item(LayoutWidgetBase* above, const
void FlowTableWithFields::on_dnd_add_placeholder(Gtk::Widget* above_widget)
{
+ std::cout << "DEBUG: FlowTableWithFields::on_dnd_add_placeholder()" << std::endl;
+
LayoutWidgetBase* above = dynamic_cast<LayoutWidgetBase*>(above_widget);
if(!above)
return;
- if(m_placeholder)
- {
- if(dynamic_cast<Glom::PlaceholderGlom*>(above))
- return;
+ if(dynamic_cast<Glom::PlaceholderGlom*>(above))
+ return;
- on_dnd_remove_placeholder();
- }
- type_list_layoutwidgets::iterator cur_widget = std::find (m_list_layoutwidgets.begin(),
- m_list_layoutwidgets.end(),
- above);
+ on_dnd_remove_placeholder();
+ type_list_layoutwidgets::iterator cur_widget = std::find(m_list_layoutwidgets.begin(),
+ m_list_layoutwidgets.end(), above);
sharedptr<LayoutItem_Placeholder> placeholder_field(new LayoutItem_Placeholder);
sharedptr<LayoutItem> item = sharedptr<LayoutItem>::cast_dynamic(placeholder_field);
add_layout_item_at_position(placeholder_field, cur_widget);
@@ -1388,30 +1402,30 @@ void FlowTableWithFields::on_dnd_add_placeholder(Gtk::Widget* above_widget)
void FlowTableWithFields::on_dnd_remove_placeholder()
{
- if(m_placeholder)
- {
- //Get the layout group that the "above" widget's layout item is in
- sharedptr<LayoutGroup> layout_group = get_layout_group();
- if(layout_group)
- {
- LayoutGroup::type_list_items items = layout_group->get_items();
- for (LayoutGroup::type_list_items::iterator item = items.begin();
- item != items.end(); ++item)
- {
- sharedptr<LayoutItem_Placeholder> placeholder =
- sharedptr<LayoutItem_Placeholder>::cast_dynamic(*item);
+ std::cout << "DEBUG: FlowTableWithFields::on_dnd_remove_placeholder()" << std::endl;
- if(placeholder)
- {
- layout_group->remove_item(*item);
- }
- }
+ //Get the layout group that the "above" widget's layout item is in
+ sharedptr<LayoutGroup> layout_group = get_layout_group();
+ if(layout_group)
+ {
+ LayoutGroup::type_list_items items = layout_group->get_items();
+ for (LayoutGroup::type_list_items::iterator item = items.begin();
+ item != items.end(); ++item)
+ {
+ sharedptr<LayoutItem_Placeholder> placeholder =
+ sharedptr<LayoutItem_Placeholder>::cast_dynamic(*item);
+
+ if(placeholder)
+ {
+ layout_group->remove_item(*item);
+ }
}
- remove(*m_placeholder);
+std::cout << "DEBUG: FlowTableWithFields::on_dnd_remove_placeholder() 1" << std::endl;
+
+ remove(m_placeholder_alignment);
+std::cout << "DEBUG: FlowTableWithFields::on_dnd_remove_placeholder() 2" << std::endl;
}
-
- m_placeholder = 0;
}
void FlowTableWithFields::dnd_notify_failed_drop()
diff --git a/glom/mode_data/flowtablewithfields.h b/glom/mode_data/flowtablewithfields.h
index 1b71a1e..51842db 100644
--- a/glom/mode_data/flowtablewithfields.h
+++ b/glom/mode_data/flowtablewithfields.h
@@ -41,6 +41,7 @@
#include <glom/utility_widgets/layoutwidgetbase.h>
#include <glom/utility_widgets/layoutwidgetutils.h>
#include <glom/mode_data/box_data_list_related.h>
+#include <glom/utility_widgets/placeholder-glom.h>
#include "box_data_calendar_related.h"
#include <glom/mode_design/layout/treestore_layout.h> //Forthe enum.
#include <map>
@@ -241,7 +242,10 @@ private:
Box_Data_List_Related* create_related(const sharedptr<LayoutItem_Portal>& portal, bool show_title = true);
Box_Data_Calendar_Related* create_related_calendar(const sharedptr<LayoutItem_CalendarPortal>& portal, bool show_title = true);
- Gtk::Alignment* m_placeholder;
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ Gtk::Alignment m_placeholder_alignment;
+ PlaceholderGlom m_placeholder;
+#endif //GLOM_ENABLE_CLIENT_ONLY
Glib::ustring m_table_name;
diff --git a/glom/utility_widgets/flowtable.cc b/glom/utility_widgets/flowtable.cc
index 02faee4..b6f7ad8 100644
--- a/glom/utility_widgets/flowtable.cc
+++ b/glom/utility_widgets/flowtable.cc
@@ -936,15 +936,19 @@ guint FlowTable::get_row_padding() const
bool FlowTable::child_is_visible(const Gtk::Widget* widget) const
{
+ if(!widget)
+ return false;
+
#if GTKMM_MINOR_VERSION >= 18
- return widget && widget->get_visible();
+ return widget->get_visible();
#else
- return widget && widget->is_visible();
+ return widget->is_visible();
#endif
}
void FlowTable::remove(Gtk::Widget& first)
{
+ std::cout << "DEBUG: FlowTable::remove() 1" << std::endl;
//Gtk::Container::remove() does this too. We need to do it here too:
if(first.is_managed_())
first.reference();
@@ -955,12 +959,37 @@ void FlowTable::remove(Gtk::Widget& first)
{
if((iter->m_first == &first) && (iter->m_second == 0))
{
- //g_warning("FlowTable::remove(): removing %10X", (guint)&first);
+ g_warning("FlowTable::remove(): removing %10X", (guint)&first);
m_children.erase(iter);
break;
}
}
+
+ std::cout << "DEBUG: FlowTable::remove() 2" << std::endl;
+}
+
+void FlowTable::remove(Gtk::Widget& first, Gtk::Widget& second)
+{
+ std::cout << "DEBUG: FlowTable::remove(2) 1" << std::endl;
+ //Gtk::Container::remove() does this too. We need to do it here too:
+ if(first.is_managed_())
+ first.reference();
+
+ gtk_widget_unparent(first.gobj());
+
+ for(type_vecChildren::iterator iter = m_children.begin(); iter != m_children.end(); ++iter)
+ {
+ if((iter->m_first == &first) && (iter->m_second == &second))
+ {
+ g_warning("FlowTable::remove(2): removing %10X", (guint)&first);
+
+ m_children.erase(iter);
+ break;
+ }
+ }
+
+ std::cout << "DEBUG: FlowTable::remove(2) 2" << std::endl;
}
void FlowTable::remove_all()
diff --git a/glom/utility_widgets/flowtable.h b/glom/utility_widgets/flowtable.h
index 3f7aff7..c7914d8 100644
--- a/glom/utility_widgets/flowtable.h
+++ b/glom/utility_widgets/flowtable.h
@@ -40,8 +40,12 @@ public:
void insert_before(Gtk::Widget& first, Gtk::Widget& second, Gtk::Widget& before, bool expand_second);
void insert_before(Gtk::Widget& first, Gtk::Widget& before, bool expand);
+ /// Remove @a first if it was added without a second.
virtual void remove(Gtk::Widget& first); //override
+ /// Remove @a first and @a second if they were added together.
+ void remove(Gtk::Widget& first, Gtk::Widget& second);
+
void set_columns_count(guint value);
/** Sets the padding to put between the columns of widgets.
diff --git a/glom/utility_widgets/flowtable_dnd.cc b/glom/utility_widgets/flowtable_dnd.cc
index 75a7890..de1cc76 100644
--- a/glom/utility_widgets/flowtable_dnd.cc
+++ b/glom/utility_widgets/flowtable_dnd.cc
@@ -31,7 +31,7 @@
namespace Glom
{
-const std::string MOVE_TARGET = "FlowTableMoveTarget";
+const char* MOVE_TARGET = "FlowTableMoveTarget";
FlowTableDnd::FlowTableDnd() :
m_current_dnd_item(0),
@@ -383,6 +383,9 @@ FlowTable::FlowTableItem* FlowTableDnd::find_current_dnd_item(Gtk::Widget* child
bool FlowTableDnd::on_child_drag_motion(const Glib::RefPtr<Gdk::DragContext>& /* drag_context */, int x, int y, guint /* time */,
Gtk::Widget* child)
{
+ std::cout << "DEBUG: FlowTableDnd::on_child_drag_motion()" << std::endl;
+
+
m_current_dnd_item = find_current_dnd_item(child, x, y);
Gtk::Widget* above = dnd_datawidget_from_item(m_current_dnd_item);
@@ -507,6 +510,7 @@ void FlowTableDnd::set_design_mode(bool value)
void FlowTableDnd::dnd_remove_placeholder_idle()
{
+ std::cout << "DEBUG: FlowTableDnd::dnd_remove_placeholder_idle()" << std::endl;
static sigc::connection connection;
if(connection)
connection.disconnect();
@@ -516,6 +520,7 @@ void FlowTableDnd::dnd_remove_placeholder_idle()
bool FlowTableDnd::dnd_remove_placeholder_real()
{
+ std::cout << "DEBUG: FlowTableDnd::dnd_remove_placeholder_real()" << std::endl;
on_dnd_remove_placeholder();
queue_draw();
return false; // remove from idle source
diff --git a/glom/utility_widgets/test_flowtable.cc b/glom/utility_widgets/test_flowtable.cc
index 78f7dba..ea209e0 100644
--- a/glom/utility_widgets/test_flowtable.cc
+++ b/glom/utility_widgets/test_flowtable.cc
@@ -69,11 +69,28 @@ main(int argc, char* argv[])
Gtk::Entry button12; button11.set_text("eleven");
flowtable.add(button11, button12);
button11.show(); button12.show();
+
+
+ Gtk::Entry* button13 = Gtk::manage(new Gtk::Entry()); button13->set_text("13");
+ Gtk::Entry* button14 = Gtk::manage(new Gtk::Entry()); button14->set_text("14");
+ flowtable.add(*button13, *button14);
+ button13->show(); button14->show();
+
+ Gtk::Entry* button15 = new Gtk::Entry(); button15->set_text("15");
+ flowtable.add(*button15);
+ button15->show();
window.add(flowtable);
flowtable.set_design_mode();
flowtable.show();
+ flowtable.remove(*button13, *button14);
+ delete button13;
+ delete button14;
+
+ //flowtable.remove(*button15);
+ delete button15;
+
// Glom::DragWindow drag_window;
// drag_window.show();
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b96428f..73de47a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -119,10 +119,6 @@ glom/utility_widgets/datawidget.cc
glom/utility_widgets/db_adddel/db_adddel.cc
glom/utility_widgets/dialog_choose_id.cc
glom/utility_widgets/dialog_image_progress.cc
-glom/utility_widgets/egg/toolpalette/eggenumaction.c
-glom/utility_widgets/egg/toolpalette/eggtoolitemgroup.c
-glom/utility_widgets/egg/toolpalette/eggtoolpalette.c
-glom/utility_widgets/egg/toolpalette/testtoolpalette.c
glom/utility_widgets/entryglom.cc
glom/utility_widgets/filechooserdialog_saveextras.cc
glom/utility_widgets/imageglom.cc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]