[glom/gtktoolpallete] Dnd layout: Avoid a crash when dragging to empty space.



commit 299e15f79b7ada94b967fccb4508c8ce046f49d2
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Dec 30 21:56:53 2009 +0100

     Dnd layout: Avoid a crash when dragging to empty space.
    
    * glom/utility_widgets/flowtable_dnd.cc: on_drag_data_received():
    Avoid dereferencing a null group. Bug #599232

 ChangeLog                             |    7 ++++++
 glom/mode_data/flowtablewithfields.cc |    3 +-
 glom/utility_widgets/flowtable_dnd.cc |   38 +++++++++++---------------------
 3 files changed, 22 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 82c54ff..dbef467 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-12-30  Murray Cumming  <murrayc murrayc com>
 
+  Dnd layout: Avoid a crash when dragging to empty space.
+  
+	* glom/utility_widgets/flowtable_dnd.cc: on_drag_data_received():
+	Avoid dereferencing a null group.
+
+2009-12-30  Murray Cumming  <murrayc murrayc com>
+
 	FlowTable: Use foreach() instead of implementing forall().
 
 	* glom/utility_widgets/flowtable.[h|cc]:
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 94a2953..4c5d195 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -1478,7 +1478,8 @@ void FlowTableWithFields::on_dnd_remove_placeholder()
 
 void FlowTableWithFields::dnd_notify_failed_drop()
 {
-  // TODO: Avoid this error message
+  // TODO: Avoid this error message, maybe by adding a group.
+  // TODO: At least avoid losing the dragged item.
   Gtk::MessageDialog dialog(_("You cannot drop anything here. Try to add a group first"),
                       false, Gtk::MESSAGE_ERROR);
   dialog.run();
diff --git a/glom/utility_widgets/flowtable_dnd.cc b/glom/utility_widgets/flowtable_dnd.cc
index 63eebe3..09abd05 100644
--- a/glom/utility_widgets/flowtable_dnd.cc
+++ b/glom/utility_widgets/flowtable_dnd.cc
@@ -200,22 +200,15 @@ void FlowTableDnd::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& d
   else
   {
     //If the item was dragged from a FlowTable.
-    std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): !palette" << std::endl;
-    
     gpointer* pdata = (gpointer*)selection_data.get_data();
     if(!pdata)
       return;
-    std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): typeid: " << typeid(pdata).name() << std::endl;
 
     gpointer data = *pdata;
     if(!data)
       return;
-    std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): typeid: " << typeid(data).name() << std::endl;
 
     Gtk::Widget* widget = static_cast<Gtk::Widget*>(data);
-    std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): typeid: " << typeid(widget).name() << std::endl;
-std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): gobjecttype: " << G_OBJECT_TYPE_NAME(widget->gobj()) << std::endl;
-
 
     LayoutWidgetBase* base = dynamic_cast<LayoutWidgetBase*>(widget);
     if(!base)
@@ -223,28 +216,23 @@ std::cout << "DEBUG: FlowTableDnd::on_drag_data_received(): gobjecttype: " << G_
 
     sharedptr<LayoutItem> item = base->get_layout_item();
     if(!item)
-      return;
-
-    sharedptr<LayoutGroup> group = sharedptr<LayoutGroup>::cast_dynamic(get_layout_item());
-    LayoutGroup::type_list_items items = group->m_list_items;
-    if(std::find(items.begin(), items.end(), item) != items.end())
     {
-      m_internal_drag = true;
-      group->remove_item(item);
-    }
-    else
       m_internal_drag = false;
+      sharedptr<LayoutGroup> group = sharedptr<LayoutGroup>::cast_dynamic(get_layout_item());
+      if(group)
+      {
+        LayoutGroup::type_list_items items = group->m_list_items;
+        if(std::find(items.begin(), items.end(), item) != items.end())
+        {
+          m_internal_drag = true;
+          group->remove_item(item);
+        }
+      }
 
-    LayoutWidgetBase* above_layoutwidget = dynamic_cast<LayoutWidgetBase*>(above);
-    if(above_layoutwidget)
-    {
-      on_dnd_add_layout_item(above_layoutwidget, item);
+      LayoutWidgetBase* above_casted = dynamic_cast<LayoutWidgetBase*>(above);
+      on_dnd_add_layout_item(above_casted, item);
       base->set_dnd_in_progress(false);
     }
-    else
-    {
-      std::cerr << "FlowTableDnd::on_drag_data_received(): above was not a LayoutWidgetBase: above = " << above << std::endl;
-    }
   }
 
   queue_draw();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]