[glom/spread-table] Details: Use of GtkSpreadTable: Align widgets again.



commit ff81d9af7eeeff20d879981121efa9d839d0fdc3
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Oct 11 15:33:31 2010 +0200

    Details: Use of GtkSpreadTable: Align widgets again.
    
    * glom/mode_data/flowtablewithfields.cc: apply_size_groups_to_labels():
      Re-enable the code to align adjacent widgets.
    * glom/utility_widgets/flowtable.[h|cc]: get_column_for_first_widget():
      Bring this code back, this time using the new
      gtk_spread_table_get_child_line() function.

 ChangeLog                             |   10 +++++++
 glom/mode_data/flowtablewithfields.cc |    8 ++----
 glom/utility_widgets/flowtable.cc     |   43 ++++++++++++++++++++++++++-------
 glom/utility_widgets/flowtable.h      |   19 +++++---------
 4 files changed, 54 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fa4aa78..0f285c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-10-11  Murray Cumming  <murrayc murrayc com>
+
+	Details: Use of GtkSpreadTable: Align widgets again.
+
+	* glom/mode_data/flowtablewithfields.cc: apply_size_groups_to_labels():
+  Re-enable the code to align adjacent widgets.
+	* glom/utility_widgets/flowtable.[h|cc]: get_column_for_first_widget():
+  Bring this code back, this time using the new
+  gtk_spread_table_get_child_line() function.
+
 2010-10-08  Murray Cumming  <murrayc murrayc com>
 
 	Details: FlowTable: Initial use of GtkSpreadTable instead of custom code.
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 3e2619c..b830850 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -56,7 +56,6 @@ FlowTableWithFields::FlowTableWithFields(const Glib::ustring& table_name)
   m_placeholder(0),
   m_table_name(table_name)
 {
-
 }
 
 FlowTableWithFields::~FlowTableWithFields()
@@ -1325,10 +1324,10 @@ void FlowTableWithFields::apply_size_groups_to_labels(const type_vec_sizegroups&
     //Only align labels in the first column, because items in separate columns
     //couldn't be aligned vertically anyway, and this would cause extra space.
     //TODO: Use a different SizeGroup for items in 2nd columns?
-    /* TODO:
     guint column = 0;
-    const bool column_allocated = get_column_for_first_widget(*label_parent, column);
-    if(!column_allocated)
+    const bool ready = get_column_for_first_widget(*label_parent, column);
+    if(!ready)
+      continue;
 
     if(column >= m_vec_size_groups.size())
       continue;
@@ -1339,7 +1338,6 @@ void FlowTableWithFields::apply_size_groups_to_labels(const type_vec_sizegroups&
       size_group->add_widget(*label);
       info.m_first_in_sizegroup = size_group; //Remember it so we can remove it later.
     }
-    */
   }
 }
 
diff --git a/glom/utility_widgets/flowtable.cc b/glom/utility_widgets/flowtable.cc
index d5ab5b2..3001e88 100644
--- a/glom/utility_widgets/flowtable.cc
+++ b/glom/utility_widgets/flowtable.cc
@@ -28,7 +28,8 @@ namespace Glom
 {
 
 FlowTable::FlowTableItem::FlowTableItem(Gtk::Widget* first, FlowTable* /* flowtable */)
-: m_first(first),
+: m_hbox(0),
+  m_first(first),
   m_second(0),
   m_expand_first_full(false),
   m_expand_second(false)
@@ -37,7 +38,8 @@ FlowTable::FlowTableItem::FlowTableItem(Gtk::Widget* first, FlowTable* /* flowta
 }
 
 FlowTable::FlowTableItem::FlowTableItem(Gtk::Widget* first, Gtk::Widget* second, FlowTable* /* flowtable */)
-: m_first(first),
+: m_hbox(0),
+  m_first(first),
   m_second(second),
   m_expand_first_full(false),
   m_expand_second(false)
@@ -68,6 +70,7 @@ void FlowTable::add(Gtk::Widget& first, Gtk::Widget& second, bool expand_second)
   FlowTableItem item(&first, &second, this);
 
   Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox(false, get_horizontal_spacing()));
+  item.m_hbox = hbox;
 
   item.m_expand_second = expand_second; //Expand to fill the width for all of the second item.
   m_children.push_back(item);
@@ -175,8 +178,6 @@ void FlowTable::remove(Gtk::Widget& first)
   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 == 0))
@@ -191,7 +192,6 @@ void FlowTable::remove(Gtk::Widget& first)
 
 void FlowTable::remove_all()
 {
-
   for(type_vecChildren::iterator iter = m_children.begin(); iter != m_children.end(); ++iter)
   {
     if(iter->m_first)
@@ -200,8 +200,6 @@ void FlowTable::remove_all()
 
       if(widget->is_managed_())
         widget->reference();
-
-      gtk_widget_unparent(GTK_WIDGET(iter->m_first->gobj()));
     }
 
     if(iter->m_second)
@@ -210,8 +208,6 @@ void FlowTable::remove_all()
 
       if(widget->is_managed_())
         widget->reference();
-
-      gtk_widget_unparent(GTK_WIDGET(iter->m_second->gobj()));
     }
 
   }
@@ -219,5 +215,34 @@ void FlowTable::remove_all()
   m_children.clear();
 }
 
+bool FlowTable::get_column_for_first_widget(const Gtk::Widget& first, guint& column) const
+{
+  //Initialize output parameter:
+  column = 0;
+
+  if(get_lines() == 0)
+    return false;
+
+  for(type_vecChildren::const_iterator iter = m_children.begin(); iter != m_children.end(); ++iter)
+  {
+    const FlowTableItem& item = *iter;
+
+    if((&first == item.m_first))
+    {
+      Gtk::Widget* child = item.m_hbox;
+      if(!child)
+        return false;
+
+      int width_min = 0;
+      int width_natural = 0;
+      child->get_preferred_width(width_min, width_natural);
+      column = get_child_line(*child, width_natural);
+
+      return true;
+    }
+  }
+
+  return false;
+}
 
 } //namespace Glom
diff --git a/glom/utility_widgets/flowtable.h b/glom/utility_widgets/flowtable.h
index 550c618..aa56b49 100644
--- a/glom/utility_widgets/flowtable.h
+++ b/glom/utility_widgets/flowtable.h
@@ -48,35 +48,30 @@ public:
 
   void remove_all();
 
-private:
-
-  //Overrides:
-
 protected:
 
+  /** Get the column in which the specified "first" widget is placed.
+   * result false if the widget is not one of the "first" widgets, or
+   * if has not yet been placed in a column, because the size has not yet been requested.
+   */
+  bool get_column_for_first_widget(const Gtk::Widget& first, guint& column) const;
+
   class FlowTableItem
   {
   public:
     FlowTableItem(Gtk::Widget* first, FlowTable* flowtable);
     FlowTableItem(Gtk::Widget* first, Gtk::Widget* second, FlowTable* flowtable);
 
+    Gtk::HBox* m_hbox;
     Gtk::Widget* m_first;
     Gtk::Widget* m_second;
     bool m_expand_first_full;
     bool m_expand_second;
 
-    //The column that the widgets are currently in, due to the size/allocation.
-    bool m_has_allocated_column;
-    guint m_allocated_column;
-
     bool operator==(Gtk::Widget* child) const
     {
       return (child == m_first || child == m_second);
     }
-
-    //Cache the positions, so we can use them in on_expose_event:
-    Gtk::Allocation m_first_allocation;
-    Gtk::Allocation m_second_allocation;
   };
 
 private:



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