glom r1680 - in trunk: . glom/layout_item_dialogs glom/libglom/data_structure/layout glom/libglom/document glom/mode_data glom/mode_design/print_layouts glom/utility_widgets/db_adddel



Author: murrayc
Date: Sat Sep  6 09:08:04 2008
New Revision: 1680
URL: http://svn.gnome.org/viewvc/glom?rev=1680&view=rev

Log:
2008-09-06  Murray Cumming  <murrayc murrayc com>

* glom/mode_data/dialog_layout_details.cc:
* glom/mode_data/dialog_layout_details.h:
* glom/mode_data/dialog_layout_list.cc: Add a column for the column width, 
but only show it for the list. Also hide the columns count column for 
the list.
* glom/libglom/document/document_glom.cc: load_after_layout_group(),
        Glom.save_before_layout_group(): Save the column widths for items 
in the document.

* glom/mode_data/dialog_layout_list_related.cc:
* glom/mode_data/dialog_layout_list_related.h: Remove one set_document() 
method overload, adding the parent_table to the existing one, to simplify 
code and to allow us to preserve LayoutItem_Portal details such as print 
layout positions, even when no relationship is chosen yet.
* glom/mode_data/box_data_list_related.cc: Adapted.
* glom/mode_design/print_layouts/canvas_print_layout.cc: Adapted.

* glom/mode_design/print_layouts/canvas_layout_item.cc: create_item():
For the portal, create a rect cell for each field in the layout. Still 
not very useful, but gradually becoming more sensible.

* glom/utility_widgets/db_adddel/db_adddel.cc: on_treeview_column_resized(): 
Do not save the column width if it is the last column because that autosizes 
to take all remaining space.
* glom/mode_data/box_data_list.cc:
* glom/mode_data/box_data_list.h: Remove the reset_column_widths 
stuff, because ignoring the last column is a better fix.

Modified:
   trunk/ChangeLog
   trunk/glom/layout_item_dialogs/dialog_field_layout.cc
   trunk/glom/libglom/data_structure/layout/layoutitem.cc
   trunk/glom/libglom/data_structure/layout/layoutitem.h
   trunk/glom/libglom/document/document_glom.cc
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/mode_data/box_data_list.cc
   trunk/glom/mode_data/box_data_list.h
   trunk/glom/mode_data/box_data_list_related.cc
   trunk/glom/mode_data/dialog_layout_details.cc
   trunk/glom/mode_data/dialog_layout_details.h
   trunk/glom/mode_data/dialog_layout_list.cc
   trunk/glom/mode_data/dialog_layout_list_related.cc
   trunk/glom/mode_data/dialog_layout_list_related.h
   trunk/glom/mode_design/print_layouts/canvas_layout_item.cc
   trunk/glom/mode_design/print_layouts/canvas_print_layout.cc
   trunk/glom/mode_design/print_layouts/window_print_layout_edit.cc
   trunk/glom/utility_widgets/db_adddel/db_adddel.cc

Modified: trunk/glom/layout_item_dialogs/dialog_field_layout.cc
==============================================================================
--- trunk/glom/layout_item_dialogs/dialog_field_layout.cc	(original)
+++ trunk/glom/layout_item_dialogs/dialog_field_layout.cc	Sat Sep  6 09:08:04 2008
@@ -79,12 +79,6 @@
 {
   m_layout_item = glom_sharedptr_clone(field);
 
-    double x = 0;
-    double y = 0;
-    double width, height;
-    m_layout_item->get_print_layout_position(x, y, width, height);
-    std::cout << "DEBUGDialog_FieldLayout::set_field(): m_layout_item: x=" << x << std::endl;
-
   m_table_name = table_name;
 
   m_label_field_name->set_text( field->get_layout_display_name() );

Modified: trunk/glom/libglom/data_structure/layout/layoutitem.cc
==============================================================================
--- trunk/glom/libglom/data_structure/layout/layoutitem.cc	(original)
+++ trunk/glom/libglom/data_structure/layout/layoutitem.cc	Sat Sep  6 09:08:04 2008
@@ -101,11 +101,12 @@
   return *this;
 }
 
+//Is this used?
 bool LayoutItem::operator==(const LayoutItem& src) const
 {
   bool equal = (TranslatableItem::operator==(src)) &&
           (m_editable == src.m_editable) &&
-          (m_display_width == src.m_display_width); //careful of this - it's not saved in the document.
+          (m_display_width == src.m_display_width);
 
   if(m_positions && src.m_positions)
   {

Modified: trunk/glom/libglom/data_structure/layout/layoutitem.h
==============================================================================
--- trunk/glom/libglom/data_structure/layout/layoutitem.h	(original)
+++ trunk/glom/libglom/data_structure/layout/layoutitem.h	Sat Sep  6 09:08:04 2008
@@ -75,8 +75,7 @@
   Glib::ustring m_name;
   bool m_editable;
 
-  //Not saved in document:
-  guint m_display_width; //In pixels.
+  guint m_display_width; //In pixels for the list layout, in mm for the print layout.
 
   void instantiate_positions() const;
 

Modified: trunk/glom/libglom/document/document_glom.cc
==============================================================================
--- trunk/glom/libglom/document/document_glom.cc	(original)
+++ trunk/glom/libglom/document/document_glom.cc	Sat Sep  6 09:08:04 2008
@@ -69,10 +69,12 @@
 #define GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP "portal_navigation_relationship"
 #define GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN "navigation_main"
 #define GLOM_NODE_DATA_LAYOUT_CALENDAR_PORTAL "data_layout_calendar_portal"
+#define GLOM_ATTRIBUTE_PORTAL_PRINT_LAYOUT_ROW_HEIGHT "row_height"
 #define GLOM_ATTRIBUTE_PORTAL_CALENDAR_DATE_FIELD "date_field"
 #define GLOM_NODE_DATA_LAYOUT_ITEM "data_layout_item" //A field.
 #define GLOM_NODE_LAYOUT_ITEM_CUSTOM_TITLE "title_custom"
 #define GLOM_ATTRIBUTE_LAYOUT_ITEM_CUSTOM_TITLE_USE "use_custom"
+#define GLOM_ATTRIBUTE_LAYOUT_ITEM_COLUMN_WIDTH "column_width"
 #define GLOM_NODE_DATA_LAYOUT_BUTTON "data_layout_button"
 #define GLOM_NODE_DATA_LAYOUT_TEXTOBJECT "data_layout_text"
 #define GLOM_NODE_DATA_LAYOUT_TEXTOBJECT_TEXT "text"
@@ -2067,8 +2069,6 @@
         xmlpp::Element* elementNavigationRelationshipSpecific = get_node_child_named(element, GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP);
         if(elementNavigationRelationshipSpecific)
         {
-           //std::cout << "debug: loading GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP" << std::endl;
-
            relationship_navigation_specific = sharedptr<UsesRelationship>::create();
            load_after_layout_item_usesrelationship(elementNavigationRelationshipSpecific, portal->get_table_used(table_name), relationship_navigation_specific);
            relationship_navigation_specific_main = get_node_attribute_value_as_bool(elementNavigationRelationshipSpecific, GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN);
@@ -2091,6 +2091,9 @@
           sharedptr<Field> date_field = get_field(calendar_portal->get_table_used(table_name), date_field_name);
           calendar_portal->set_date_field(date_field);
         }
+
+        //Print Layout specific stuff:
+        portal->set_print_layout_row_height( get_node_attribute_value_as_decimal(element, GLOM_ATTRIBUTE_PORTAL_PRINT_LAYOUT_ROW_HEIGHT) );
         
         item_added = portal; 
       }
@@ -2159,6 +2162,9 @@
     {
       group->add_item(item_added);
 
+      //Attributes that all items could have:
+      item_added->set_display_width( get_node_attribute_value_as_decimal(element, GLOM_ATTRIBUTE_LAYOUT_ITEM_COLUMN_WIDTH) );
+
       if(with_print_layout_positions)
         load_after_print_layout_position(element, item_added);
     }
@@ -2881,11 +2887,14 @@
                 save_before_layout_item_usesrelationship(child_navigation_relationship_specific, relationship_navigation_specific);
                 set_node_attribute_value_as_bool(child_navigation_relationship_specific, GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN, navigation_specific_main);
               }
+
+              //Print Layout specific stuff:
+              set_node_attribute_value_as_decimal(child, GLOM_ATTRIBUTE_PORTAL_PRINT_LAYOUT_ROW_HEIGHT, portal->get_print_layout_row_height());
             }
             else
             {
               sharedptr<const LayoutItem_Notebook> notebook = sharedptr<const LayoutItem_Notebook>::cast_dynamic(group);
-              if(notebook) //If it is a related records portal
+              if(notebook) //If it is a notebook.
               {
                 child = node->add_child(GLOM_NODE_DATA_LAYOUT_NOTEBOOK);
               }
@@ -3008,6 +3017,11 @@
 
       if(nodeItem)
       {
+        //Attributes that any layout item could have:
+        guint column_width = 0;
+        item->get_display_width(column_width);
+        set_node_attribute_value_as_decimal(nodeItem, GLOM_ATTRIBUTE_LAYOUT_ITEM_COLUMN_WIDTH, column_width);
+
         if(with_print_layout_positions)
           save_before_print_layout_position(nodeItem, item);
       }

Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc	(original)
+++ trunk/glom/mode_data/box_data_details.cc	Sat Sep  6 09:08:04 2008
@@ -152,7 +152,7 @@
 
 void Box_Data_Details::set_found_set_from_primary_key_value()
 {
-  if (!m_primary_key_value.is_null())
+  if(!m_primary_key_value.is_null())
   {
     m_found_set.m_where_clause = "\"" + m_table_name + "\".\"" + m_field_primary_key->get_name() + 
       "\" = " + m_field_primary_key->sql(m_primary_key_value);

Modified: trunk/glom/mode_data/box_data_list.cc
==============================================================================
--- trunk/glom/mode_data/box_data_list.cc	(original)
+++ trunk/glom/mode_data/box_data_list.cc	Sat Sep  6 09:08:04 2008
@@ -34,8 +34,7 @@
 
 Box_Data_List::Box_Data_List()
 : m_has_one_or_more_records(false),
-  m_read_only(false),
-  m_reset_column_widths(false)
+  m_read_only(false)
 {
   m_layout_name = "list";
 
@@ -435,10 +434,6 @@
         }
       }
 
-      //Sometimes we reset the column width so that new fields are easily visible:
-      if(m_reset_column_widths)
-        child_item->set_display_width(0);
-
       m_AddDel.add_column(child_item);
     }
   }
@@ -587,10 +582,7 @@
 //overridden, so we can change the column widths, so they are all visible:
 void Box_Data_List::on_dialog_layout_hide()
 {
-  //Tell create_layout() to reset the display_width for each layout item:
-  m_reset_column_widths = true;
   Box_Data::on_dialog_layout_hide();
-  m_reset_column_widths = false;
 }
 
 Dialog_Layout* Box_Data_List::create_layout_dialog() const

Modified: trunk/glom/mode_data/box_data_list.h
==============================================================================
--- trunk/glom/mode_data/box_data_list.h	(original)
+++ trunk/glom/mode_data/box_data_list.h	Sat Sep  6 09:08:04 2008
@@ -112,8 +112,6 @@
 
   bool m_has_one_or_more_records;
   bool m_read_only;
-
-  bool m_reset_column_widths; //create_layout() sets these to 0 when this is set.
 };
 
 } //namespace Glom

Modified: trunk/glom/mode_data/box_data_list_related.cc
==============================================================================
--- trunk/glom/mode_data/box_data_list_related.cc	(original)
+++ trunk/glom/mode_data/box_data_list_related.cc	Sat Sep  6 09:08:04 2008
@@ -344,10 +344,7 @@
   Dialog_Layout_List_Related* related_dialog = dynamic_cast<Dialog_Layout_List_Related*>(dialog);
   g_assert(related_dialog != NULL);
 
-  if(m_portal && m_portal->get_has_relationship_name())
-    related_dialog->set_document(m_layout_name, get_document(), m_portal);
-  else
-    related_dialog->set_document(m_layout_name, get_document(), m_parent_table);
+  related_dialog->set_document(m_layout_name, get_document(), m_portal, m_parent_table);
 }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
@@ -472,10 +469,6 @@
         }
       }
 
-      //Sometimes we reset the column width so that new fields are easily visible:
-      //if(m_reset_column_widths)
-      //  child_item->set_display_width(0);
-
       m_AddDel.add_column(child_item);
     }
   }

Modified: trunk/glom/mode_data/dialog_layout_details.cc
==============================================================================
--- trunk/glom/mode_data/dialog_layout_details.cc	(original)
+++ trunk/glom/mode_data/dialog_layout_details.cc	Sat Sep  6 09:08:04 2008
@@ -36,6 +36,8 @@
 : Dialog_Layout(cobject, refGlade),
   m_treeview_fields(0),
   m_treeview_column_title(0),
+  m_treeview_column_group_columns(0),
+  m_treeview_column_column_width(0),
   m_box_table_widgets(0),
   m_box_related_table_widgets(0),
   m_box_related_navigation(0),
@@ -108,15 +110,33 @@
 
 
     //Columns-count column:
-    Gtk::TreeView::Column* column_count = Gtk::manage( new Gtk::TreeView::Column(_("Columns Count")) );
-    m_treeview_fields->append_column(*column_count);
+    m_treeview_column_group_columns = Gtk::manage( new Gtk::TreeView::Column(_("Group Columns")) );
+    m_treeview_fields->append_column(*m_treeview_column_group_columns);
 
     Gtk::CellRendererText* renderer_count = Gtk::manage(new Gtk::CellRendererText);
-    column_count->pack_start(*renderer_count);
-    column_count->set_cell_data_func(*renderer_count, sigc::mem_fun(*this, &Dialog_Layout_Details::on_cell_data_columns_count));
+    m_treeview_column_group_columns->pack_start(*renderer_count);
+    m_treeview_column_group_columns->set_cell_data_func(*renderer_count, sigc::mem_fun(*this, &Dialog_Layout_Details::on_cell_data_group_columns));
 
     //Connect to its signal:
-    renderer_count->signal_edited().connect( sigc::mem_fun(*this, &Dialog_Layout_Details::on_treeview_cell_edited_columns_count) );
+    renderer_count->signal_edited().connect( sigc::mem_fun(*this, &Dialog_Layout_Details::on_treeview_cell_edited_group_columns) );
+
+
+    //Column-Width column: (only for list views)
+    //Note to translators: This is a name (the width of a UI element in the display), not an action.
+    m_treeview_column_column_width = Gtk::manage( new Gtk::TreeView::Column(_("Display Width")) );
+    m_treeview_fields->append_column(*m_treeview_column_column_width);
+
+    Gtk::CellRendererText* renderer_column_width = Gtk::manage(new Gtk::CellRendererText);
+    m_treeview_column_column_width->pack_start(*renderer_column_width);
+    m_treeview_column_column_width->set_cell_data_func(*renderer_column_width, sigc::mem_fun(*this, &Dialog_Layout_Details::on_cell_data_column_width));
+
+    //Connect to its signal:
+    renderer_column_width->signal_edited().connect( sigc::mem_fun(*this, &Dialog_Layout_Details::on_treeview_cell_edited_column_width) );
+
+    //Hide this column because we don't need it for the details layout.
+    //It is made visible by the (derived) list layout class.
+    m_treeview_column_column_width->set_visible(false);
+
 
     //Respond to changes of selection:
     Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_treeview_fields->get_selection();
@@ -974,8 +994,8 @@
           sharedptr<LayoutGroup> layout_group = sharedptr<LayoutGroup>::cast_dynamic(layout_item);
           if(layout_group)
           {
-              Gtk::TreeModel::Path path = m_model_items->get_path(iter);
-              m_treeview_fields->set_cursor(path, *m_treeview_column_title, true /* start_editing */);
+            Gtk::TreeModel::Path path = m_model_items->get_path(iter);
+            m_treeview_fields->set_cursor(path, *m_treeview_column_title, true /* start_editing */);
           }
           else
           {
@@ -1212,7 +1232,35 @@
   }
 }
 
-void Dialog_Layout_Details::on_cell_data_columns_count(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter)
+void Dialog_Layout_Details::on_cell_data_column_width(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter)
+{
+  //Set the view's cell properties depending on the model's data:
+  Gtk::CellRendererText* renderer_text = dynamic_cast<Gtk::CellRendererText*>(renderer);
+  if(renderer_text)
+  {
+    if(iter)
+    {
+      Gtk::TreeModel::Row row = *iter;
+      sharedptr<LayoutItem> layout_item = row[m_model_items->m_columns.m_col_layout_item];
+     
+      sharedptr<LayoutItem_Button> layout_button = sharedptr<LayoutItem_Button>::cast_dynamic(layout_item);
+      sharedptr<LayoutItem_Text> layout_text = sharedptr<LayoutItem_Text>::cast_dynamic(layout_item);
+      sharedptr<LayoutItem_Field> layout_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
+      const bool editable = (layout_field || layout_button || layout_text); //Only these have column widths that can be edited.
+      renderer_text->property_editable() = editable;
+
+      guint column_width = 0;
+      layout_item->get_display_width(column_width);
+      Glib::ustring text; 
+      if(column_width) //Show nothing if no width has been specified, meaning that it's automatic.
+        text = Utils::string_from_decimal(column_width);
+
+      renderer_text->property_text() = text;
+    }
+  }
+}
+
+void Dialog_Layout_Details::on_cell_data_group_columns(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter)
 {
   //Set the view's cell properties depending on the model's data:
   Gtk::CellRendererText* renderer_text = dynamic_cast<Gtk::CellRendererText*>(renderer);
@@ -1232,11 +1280,7 @@
       Glib::ustring text;
       if(is_group)
       {
-        std::stringstream the_stream;
-        //the_stream.imbue(std::locale::classic());
-        const guint number = layout_group->m_columns_count;
-        the_stream << number;
-        text = the_stream.str();
+        text = Utils::string_from_decimal(layout_group->m_columns_count);
       }
       else
       {
@@ -1273,6 +1317,7 @@
   }
 }
 
+
 void Dialog_Layout_Details::on_treeview_cell_edited_name(const Glib::ustring& path_string, const Glib::ustring& new_text)
 {
   if(!path_string.empty())
@@ -1297,7 +1342,35 @@
   }
 }
 
-void Dialog_Layout_Details::on_treeview_cell_edited_columns_count(const Glib::ustring& path_string, const Glib::ustring& new_text)
+void Dialog_Layout_Details::on_treeview_cell_edited_column_width(const Glib::ustring& path_string, const Glib::ustring& new_text)
+{
+  if(!path_string.empty())
+  {
+    Gtk::TreePath path(path_string);
+
+    //Get the row from the path:
+    Gtk::TreeModel::iterator iter = m_model_items->get_iter(path);
+    if(iter)
+    {
+      Gtk::TreeModel::Row row = *iter;
+      sharedptr<LayoutItem> layout_item = row[m_model_items->m_columns.m_col_layout_item];
+      if(layout_item)
+      {
+        //Convert the text to a number, using the same logic used by GtkCellRendererText when it stores numbers.
+        char* pchEnd = 0;
+        const guint new_value = static_cast<guint>( strtod(new_text.c_str(), &pchEnd) );
+
+        //Store the user's new value in the model:
+        Gtk::TreeRow row = *iter;
+        layout_item->set_display_width(new_value);
+
+        m_modified = true;
+      }
+    }
+  }
+}
+
+void Dialog_Layout_Details::on_treeview_cell_edited_group_columns(const Glib::ustring& path_string, const Glib::ustring& new_text)
 {
   //This is used on numerical model columns:
   if(path_string.empty())

Modified: trunk/glom/mode_data/dialog_layout_details.h
==============================================================================
--- trunk/glom/mode_data/dialog_layout_details.h	(original)
+++ trunk/glom/mode_data/dialog_layout_details.h	Sat Sep  6 09:08:04 2008
@@ -75,16 +75,20 @@
 
   void on_cell_data_name(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
   void on_cell_data_title(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
-  void on_cell_data_columns_count(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
+  void on_cell_data_group_columns(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
+  void on_cell_data_column_width(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
 
   void on_treeview_cell_edited_name(const Glib::ustring& path_string, const Glib::ustring& new_text);
   void on_treeview_cell_edited_title(const Glib::ustring& path_string, const Glib::ustring& new_text);
-  void on_treeview_cell_edited_columns_count(const Glib::ustring& path_string, const Glib::ustring& new_text);
+  void on_treeview_cell_edited_group_columns(const Glib::ustring& path_string, const Glib::ustring& new_text);
+  void on_treeview_cell_edited_column_width(const Glib::ustring& path_string, const Glib::ustring& new_text);
 
   Gtk::TreeModel::iterator append_appropriate_row();
 
   Gtk::TreeView* m_treeview_fields;
   Gtk::TreeView::Column* m_treeview_column_title;
+  Gtk::TreeView::Column* m_treeview_column_group_columns;
+  Gtk::TreeView::Column* m_treeview_column_column_width;
 
   // Only one of these boxes should be shown:
   Gtk::Box* m_box_table_widgets;

Modified: trunk/glom/mode_data/dialog_layout_list.cc
==============================================================================
--- trunk/glom/mode_data/dialog_layout_list.cc	(original)
+++ trunk/glom/mode_data/dialog_layout_list.cc	Sat Sep  6 09:08:04 2008
@@ -43,6 +43,14 @@
   Gtk::Frame* box_calendar = 0;
   refGlade->get_widget("frame_calendar", box_calendar); 
   box_calendar->hide();
+
+  //We don't use this column:
+  if(m_treeview_column_group_columns)
+    m_treeview_column_group_columns->set_visible(false);
+
+  //We do use this column:
+  if(m_treeview_column_column_width)
+    m_treeview_column_column_width->set_visible();
 }
 
 Dialog_Layout_List::~Dialog_Layout_List()

Modified: trunk/glom/mode_data/dialog_layout_list_related.cc
==============================================================================
--- trunk/glom/mode_data/dialog_layout_list_related.cc	(original)
+++ trunk/glom/mode_data/dialog_layout_list_related.cc	Sat Sep  6 09:08:04 2008
@@ -79,31 +79,33 @@
 {
 }
 
-void Dialog_Layout_List_Related::set_document(const Glib::ustring& layout, Document_Glom* document, const Glib::ustring& from_table)
+
+void Dialog_Layout_List_Related::set_document(const Glib::ustring& layout, Document_Glom* document, const sharedptr<const LayoutItem_Portal>& portal, const Glib::ustring& from_table)
 {
-  if(!m_portal)
+  //Ignore the provided from_table if the portal has one:
+  Glib::ustring actual_from_table;
+  if(portal)
   {
-    m_portal = sharedptr<LayoutItem_Portal>::create(); //The rest of the class assumes that this is not null.
+    const Glib::ustring portal_from_table = portal->get_from_table();
+    if(portal_from_table.empty())
+      actual_from_table = portal_from_table;
   }
+  
+  if(actual_from_table.empty())
+    actual_from_table = from_table;
 
+  if(portal)
+    m_portal = glom_sharedptr_clone(portal);
+  else
+    m_portal = sharedptr<LayoutItem_Portal>::create(); //The rest of the class assumes that this is not null.
+  
   type_vecLayoutFields empty_fields; //Just to satisfy the base class.
-  Dialog_Layout::set_document(layout, document, from_table, empty_fields);
+  Dialog_Layout::set_document(layout, document, actual_from_table, empty_fields);
   //m_table_name is now actually the parent_table_name.
 
   update_ui();
 }
 
-void Dialog_Layout_List_Related::set_document(const Glib::ustring& layout, Document_Glom* document, const sharedptr<const LayoutItem_Portal>& portal)
-{
-  m_portal = glom_sharedptr_clone(portal);
-
-  Glib::ustring from_table;
-  if(portal)
-    from_table = portal->get_from_table();
-
-  set_document(layout, document, from_table);
-}
-
 void Dialog_Layout_List_Related::update_ui(bool including_relationship_list)
 {
   if(!m_portal)

Modified: trunk/glom/mode_data/dialog_layout_list_related.h
==============================================================================
--- trunk/glom/mode_data/dialog_layout_list_related.h	(original)
+++ trunk/glom/mode_data/dialog_layout_list_related.h	Sat Sep  6 09:08:04 2008
@@ -39,15 +39,7 @@
    * @param document The document, so that the dialog can load the previous layout, and save changes.
    * @param portal The layout item, which knows its from_table, for instance.
    */
-  virtual void set_document(const Glib::ustring& layout, Document_Glom* document, const sharedptr<const LayoutItem_Portal>& portal);
-
-  /** Use this if there is no portal yet that can specify its from_table.
-   *
-   * @param layout "list" or "details"
-   * @param document The document, so that the dialog can load the previous layout, and save changes.
-   * @param from_table The parent table name.
-   */
-  virtual void set_document(const Glib::ustring& layout, Document_Glom* document, const Glib::ustring& from_table);
+  virtual void set_document(const Glib::ustring& layout, Document_Glom* document, const sharedptr<const LayoutItem_Portal>& portal, const Glib::ustring& from_table);
 
   virtual void update_ui(bool including_relationships_list = true);
 

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	Sat Sep  6 09:08:04 2008
@@ -206,15 +206,14 @@
           sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::cast_dynamic(m_layout_item);
           if(portal)
           {
-            std::cout << "DEBUG: found portal: items=" << portal->get_items_count() << std::endl;
-
             Glib::RefPtr<CanvasTableMovable> canvas_item = CanvasTableMovable::create();
             canvas_item->property_vert_grid_line_width() = 1;
             canvas_item->property_horz_grid_line_width() = 1;
             canvas_item->property_stroke_color() = "black";
 
             //Show as many rows as can fit in the height.
-            const double row_height = portal->get_print_layout_row_height();
+            //TODO: use std::max():
+            const double row_height = MAX(portal->get_print_layout_row_height(), 1); //Avoid 0, because that makes the whole thing zero sized.
             double ignore_x = 0;
             double ignore_y = 0;
             double total_width = 0;
@@ -224,16 +223,31 @@
             const double max_rows_fraction = total_height / row_height;
             double max_rows = 0;
             modf(max_rows_fraction, &max_rows);
-            for(int i = 0; i < (int)max_rows; ++i)
-            {
-              Glib::RefPtr<CanvasRectMovable> rect_row = CanvasRectMovable::create();
-              rect_row->property_fill_color() = "white"; //This makes the whole area clickable, not just the outline stroke.
-              rect_row->property_line_width() = 1;
-              rect_row->property_stroke_color() = "black";
-              rect_row->set_width_height(total_width, row_height);
 
-              //TODO: Add/Remove rows when resizing, instead of resizing the rows:
-              canvas_item->attach(rect_row, 0 /* left_attach */, 1 /* right_attach */, i /* top_attach */, i + 1 /* right_attach */, (Gtk::AttachOptions)Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)Gtk::FILL | Gtk::EXPAND, 0.0, 0.0, 0.0, 0.0);
+            const LayoutGroup::type_list_items child_items = portal->get_items();
+
+            for(guint row = 0; row < (guint)max_rows; ++row)
+            {
+              guint col = 0;
+              for(LayoutGroup::type_list_items::const_iterator iter = child_items.begin(); iter != child_items.end(); ++iter)
+              {
+                sharedptr<LayoutItem> layout_item = *iter;
+
+                Glib::RefPtr<CanvasRectMovable> rect = CanvasRectMovable::create();
+                rect->property_fill_color() = "white"; //This makes the whole area clickable, not just the outline stroke.
+                rect->property_line_width() = 1;
+                rect->property_stroke_color() = "black";
+
+                //TODO: Use std::max():
+                guint width = 0;
+                layout_item->get_display_width(width);
+                width = MAX(width, 10);
+                rect->set_width_height(width, row_height);
+
+                //TODO: Add/Remove rows when resizing, instead of resizing the rows:
+                canvas_item->attach(rect, col /* left_attach */, col+1 /* right_attach */, row /* top_attach */, row + 1 /* right_attach */, Gtk::SHRINK, (Gtk::AttachOptions)Gtk::FILL | Gtk::EXPAND, 0.0, 0.0, 0.0, 0.0);
+                ++col;
+              }
             }
 
             child = canvas_item;

Modified: trunk/glom/mode_design/print_layouts/canvas_print_layout.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/canvas_print_layout.cc	(original)
+++ trunk/glom/mode_design/print_layouts/canvas_print_layout.cc	Sat Sep  6 09:08:04 2008
@@ -303,21 +303,33 @@
 
   add_view(dialog); //Give it access to the document.
 
-  if(!portal || (portal->get_from_table().empty()))
-    dialog->set_document("TODO_layout_name", get_document(), m_table_name);
-  else
-    dialog->set_document("TODO_layout_name", get_document(), portal);
+  dialog->set_document("TODO_layout_name", get_document(), portal, m_table_name);
 
   if(parent)
     dialog->set_transient_for(*parent);
 
   Utils::show_window_until_hide(dialog);
 
+  if(portal)
+  {
+    double x = 0;
+    double y = 0;
+    double width =0;
+    double height = 0;
+    portal->get_print_layout_position(x, y, width, height);
+    std::cout << "DEBUG before: x=" << x << ", y=" << y << ", width=" << width << ", height=" << height << std::endl;
+  }
+
   result = dialog->get_portal_layout();
-  if(!result)
-    std::cout << "DEBUG: result is empty." << std::endl;
-  else
-    std::cout << "result->get_items_count():" << result->get_items_count() << std::endl;
+  if(result)
+  {
+    double x = 0;
+    double y = 0;
+    double width =0;
+    double height = 0;
+    result->get_print_layout_position(x, y, width, height);
+    std::cout << "DEBUG after: x=" << x << ", y=" << y << ", width=" << width << ", height=" << height << std::endl;
+  }
 
   delete dialog;
   dialog = 0;

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	Sat Sep  6 09:08:04 2008
@@ -411,7 +411,9 @@
   }
   else if(item_type == PrintLayoutToolbarButton::ITEM_PORTAL)
   {
-    layout_item = sharedptr<LayoutItem_Portal>::create();
+    sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::create();
+    portal->set_print_layout_row_height(10); //Otherwise it will be 0, which is useless.
+    layout_item = portal;
     layout_item->set_print_layout_position(0, 0, 100, 50);
   }
   else

Modified: trunk/glom/utility_widgets/db_adddel/db_adddel.cc
==============================================================================
--- trunk/glom/utility_widgets/db_adddel/db_adddel.cc	(original)
+++ trunk/glom/utility_widgets/db_adddel/db_adddel.cc	Sat Sep  6 09:08:04 2008
@@ -1691,7 +1691,7 @@
   pViewColumn->set_resizable();
   
   guint column_width = 0;
-  if(!layout_item->get_display_width(column_width)) //Not saved in document, but remembered when the column is resized.
+  if(!layout_item->get_display_width(column_width))
      column_width = 100; //Fairly sensible default. TODO: Choose a width based on the first 100 values.
 
   pViewColumn->set_fixed_width((int)column_width); //This is the only way to set the width, so we need to set it as resizable again immediately afterwards.
@@ -1720,9 +1720,17 @@
   if(!view_column)
     return;
 
+  //We do not save the column width if this is the last column, 
+  //because that must always be automatic, 
+  //because it must resize when the whole column resizes.
+  std::list<const Gtk::TreeView::Column*> columns = m_TreeView.get_columns();
+  const int n_view_columns = columns.size();
+  if(n_view_columns && (view_column == m_TreeView.get_column(n_view_columns -1)))
+    return;
+
   DbAddDelColumnInfo& column_info = m_ColumnTypes[model_column_index];
 
-  guint width = (guint)view_column->get_width();
+  const guint width = (guint)view_column->get_width();
   //std::cout << "  DbAddDel::on_treeview_column_resized(): width=" << width << std::endl;
 
   if(column_info.m_item)



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