glom r1673 - in trunk: . glom/mode_design/print_layouts



Author: murrayc
Date: Wed Aug 27 14:08:00 2008
New Revision: 1673
URL: http://svn.gnome.org/viewvc/glom?rev=1673&view=rev

Log:
2008-08-27  Murray Cumming  <murrayc murrayc com>

* glom/mode_design/print_layouts/print_layout_toolbar_button.cc:
* glom/mode_design/print_layouts/print_layout_toolbar_button.h: Added 
get_item_type_from_selection_data().
* glom/mode_design/print_layouts/window_print_layout_edit.cc: create_empty_item():
Mention unhandled items on std::cerr.
on_toolbar_item_drag_data_get(): Get the item type correctly. 
* glom/mode_design/print_layouts/canvas_layout_item.cc: set_layout_item(): Do 
not reference an empty layout item.

Modified:
   trunk/ChangeLog
   trunk/glom/mode_design/print_layouts/canvas_layout_item.cc
   trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
   trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.h
   trunk/glom/mode_design/print_layouts/window_print_layout_edit.cc

Modified: trunk/glom/mode_design/print_layouts/canvas_layout_item.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/canvas_layout_item.cc	(original)
+++ trunk/glom/mode_design/print_layouts/canvas_layout_item.cc	Wed Aug 27 14:08:00 2008
@@ -122,6 +122,9 @@
   //Add the new child:
   m_layout_item = item;
 
+  if(!m_layout_item)
+    std::cerr << "CanvasLayoutItem::set_layout_item(): item was NULL." << std::endl;
+
   sharedptr<LayoutItem_Line> line;
 
   Glib::RefPtr<CanvasItemMovable> child;

Modified: trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.cc	(original)
+++ trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.cc	Wed Aug 27 14:08:00 2008
@@ -19,6 +19,7 @@
  */
  
 #include "print_layout_toolbar_button.h"
+#include <glom/utility_widgets/egg/toolpalette/eggtoolpalette.h>
 #include <iostream>
 
 namespace
@@ -60,7 +61,26 @@
 
 PrintLayoutToolbarButton::~PrintLayoutToolbarButton()
 {
+}
+
+PrintLayoutToolbarButton::enumItems PrintLayoutToolbarButton::get_item_type_from_selection_data(const Glib::RefPtr<Gdk::DragContext>& drag_context, const Gtk::SelectionData& selection_data)
+{
+  PrintLayoutToolbarButton::enumItems result = ITEM_INVALID;
 
+  //Put this code in the toolbar class:
+  Gtk::Widget* palette = drag_get_source_widget(drag_context);
+  while(palette && !EGG_IS_TOOL_PALETTE (palette->gobj()))
+    palette = palette->get_parent();
+  
+  if(!palette)
+    return result;
+
+  GtkWidget* tool_item = egg_tool_palette_get_drag_item(EGG_TOOL_PALETTE (palette->gobj()), selection_data.gobj());
+  if(!tool_item)
+    return result;
+
+  result = static_cast<PrintLayoutToolbarButton::enumItems>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tool_item), "glom-type")));
+  return result;
 }
 
 void PrintLayoutToolbarButton::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, 

Modified: trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.h
==============================================================================
--- trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.h	(original)
+++ trunk/glom/mode_design/print_layouts/print_layout_toolbar_button.h	Wed Aug 27 14:08:00 2008
@@ -50,6 +50,8 @@
   PrintLayoutToolbarButton(const std::string& icon_name, enumItems type, const Glib::ustring& title, const Glib::ustring& tooltip);
   virtual ~PrintLayoutToolbarButton();
 
+  static enumItems get_item_type_from_selection_data(const Glib::RefPtr<Gdk::DragContext>& drag_context, const Gtk::SelectionData& selection_data);
+
 protected:
 
   //TODO: What is this for? murrayc.

Modified: trunk/glom/mode_design/print_layouts/window_print_layout_edit.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/window_print_layout_edit.cc	(original)
+++ trunk/glom/mode_design/print_layouts/window_print_layout_edit.cc	Wed Aug 27 14:08:00 2008
@@ -32,10 +32,6 @@
 namespace Glom
 {
 
-//TODO: I don't know what this really means. murrayc.
-const int DRAG_DATA_FORMAT = 8; // 8 bits format
-
-
 Window_PrintLayout_Edit::Window_PrintLayout_Edit(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
 : Gtk::Window(cobject),
   m_entry_name(0),
@@ -315,22 +311,13 @@
 }
 */
 
-void Window_PrintLayout_Edit::on_toolbar_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& drag_context, Gtk::SelectionData& selection_data, guint info, guint time)
-{
-  //Put this code in the toolbar class:
-  Gtk::Widget* palette = drag_get_source_widget(drag_context);
-  while(palette && !EGG_IS_TOOL_PALETTE (palette->gobj()))
-    palette = palette->get_parent();
-  
-  if(!palette)
-    return;
 
-  GtkWidget* tool_item = egg_tool_palette_get_drag_item(EGG_TOOL_PALETTE (palette->gobj()), selection_data.gobj());
-  if(!tool_item)
-    return;
+//TODO: I don't know what this really means. murrayc.
+const int DRAG_DATA_FORMAT = 8; // 8 bits format
 
-  PrintLayoutToolbarButton::enumItems type = 
-    static_cast<PrintLayoutToolbarButton::enumItems>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tool_item), "glom-type")));
+void Window_PrintLayout_Edit::on_toolbar_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& drag_context, Gtk::SelectionData& selection_data, guint info, guint time)
+{
+  PrintLayoutToolbarButton::enumItems type = PrintLayoutToolbarButton::get_item_type_from_selection_data(drag_context, selection_data);
 
   selection_data.set(selection_data.get_target(), DRAG_DATA_FORMAT,
           (const guchar*)&type,
@@ -352,19 +339,6 @@
   return true; //Allow the drop.
 }
 
-static PrintLayoutToolbarButton::enumItems get_item_type_from_selection_data(const Gtk::SelectionData& selection_data)
-{
-  PrintLayoutToolbarButton::enumItems item_type = PrintLayoutToolbarButton::ITEM_INVALID;
-  if((selection_data.get_length() >= 0) && (selection_data.get_format() == DRAG_DATA_FORMAT))
-  {
-    const guint8* data = selection_data.get_data();
-    if(data)
-      item_type = (PrintLayoutToolbarButton::enumItems)(data[0]);
-  }
-
-  return item_type;
-}
-
 bool Window_PrintLayout_Edit::on_canvas_drag_motion(const Glib::RefPtr<Gdk::DragContext>& drag_context, int x, int y, guint timestamp)
 {
   const Glib::ustring target = m_canvas.drag_dest_find_target(drag_context);
@@ -436,6 +410,10 @@
     layout_item = sharedptr<LayoutItem_Portal>::create();
     layout_item->set_print_layout_position(0, 0, 100, 50);
   }
+  else
+  {
+    std::cerr << "Window_PrintLayout_Edit::create_empty_item(): Unhandled item type: " << item_type << std::endl;
+  }
 
   return layout_item;
 }
@@ -446,7 +424,7 @@
   //or after our drag_motion handler has called drag_get_data()): 
   
   //Discover what toolbar item was dropped:
-  const PrintLayoutToolbarButton::enumItems item_type = get_item_type_from_selection_data(selection_data);
+  const PrintLayoutToolbarButton::enumItems item_type = PrintLayoutToolbarButton::get_item_type_from_selection_data(drag_context, selection_data);
   
   if(m_drag_preview_requested)
   {



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