[glom] Choices drop-downs: Improve the column alignment.



commit 72f001190cbd99ee60f1b32b66b01652bcbbdc08
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Sep 9 11:58:06 2010 +0200

    Choices drop-downs: Improve the column alignment.
    
    	* glom/mode_data/datawidget/combo.cc: create_model():
    	* glom/mode_data/datawidget/comboentry.cc: create_model():
      * glom/utility_widgets/db_adddel.cc: on_start_editing():
      Use expand=false with pack_start() with the first column, plus xalign=0,
      so we can actually align the columns, though it only really works if the
      previous columns have values all of a similar width.
      And this doesn't work with ComboEntry or the cell renderer because
      GtkComboBoxEntry and GtkCellRendererCombo do the pack_start() of the first
      column automatically - see the comments.

 ChangeLog                                          |   14 ++++++++
 glom/mode_data/datawidget/combo.cc                 |   10 +++++-
 glom/mode_data/datawidget/comboentry.cc            |   30 ++++++++++++++---
 .../db_adddel/cellrenderer_dblist.cc               |   34 ++++++++++++++-----
 4 files changed, 71 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 819be1d..9fac323 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-09  Murray Cumming  <murrayc murrayc com>
+
+  Choices drop-downs: Improve the column alignment.
+
+	* glom/mode_data/datawidget/combo.cc: create_model():
+	* glom/mode_data/datawidget/comboentry.cc: create_model():
+  * glom/utility_widgets/db_adddel.cc: on_start_editing():
+  Use expand=false with pack_start() with the first column, plus xalign=0,
+  so we can actually align the columns, though it only really works if the
+  previous columns have values all of a similar width.
+  And this doesn't work with ComboEntry or the cell renderer because
+  GtkComboBoxEntry and GtkCellRendererCombo do the pack_start() of the first
+  column automatically - see the comments.
+
 2010-09-09  Murray Cumming  <murrayc murrayc com>>
 
 	List view: Support multiple extra fields in choices here too.
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index d693b18..9682afb 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -80,10 +80,16 @@ void ComboGlom::create_model(guint columns_count)
   for(guint i = 0; i < columns_count; ++i)
   {
     Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
-    cell->set_property("xalign", 0.0);
+    cell->property_xalign() = 0.0f;
 
     //Use the renderer:
-    pack_start(*cell);
+    //We don't expand the first column, so we can align the other columns.
+    //Otherwise the other columns appear center-aligned.
+    //This bug is relevant: https://bugzilla.gnome.org/show_bug.cgi?id=629133
+    if(i == 0)
+      pack_start(*cell, false);
+    else
+      pack_start(*cell, false);
 
     //Make the renderer render the column:
     add_attribute(*cell, "text", i);
diff --git a/glom/mode_data/datawidget/comboentry.cc b/glom/mode_data/datawidget/comboentry.cc
index b7afa88..016e48f 100644
--- a/glom/mode_data/datawidget/comboentry.cc
+++ b/glom/mode_data/datawidget/comboentry.cc
@@ -117,13 +117,31 @@ void ComboEntry::create_model(guint columns_count)
   set_model(m_refModel);
   set_text_column(0);
 
-  for(guint i = 1; i < columns_count; ++i)
+  for(guint i = 0; i < columns_count; ++i)
   {
-    Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
-    cell->set_property("xalign", 0.0);
+    Gtk::CellRendererText* cell = 0;
+    if(i == 0)
+    {
+      //Get the default column, created by set_text_column():
+      cell = dynamic_cast<Gtk::CellRendererText*>(get_first_cell());
+    }
+
+    if(!cell)
+    {
+      //Create the cell:
+      cell = Gtk::manage(new Gtk::CellRendererText);
+
+      //Use the renderer:
+      //We don't expand the first column, so we can align the other columns.
+      //Otherwise the other columns appear center-aligned.
+      //This bug is relevant: https://bugzilla.gnome.org/show_bug.cgi?id=629133
+      if(i == 0) //Impossible anyway, because we use set_text_column().
+        pack_start(*cell, false); //Unfortunately gtk_combo_box_entry_set_text_column() has already used true, making our xalign=0.0 useless.
+      else
+        pack_start(*cell, true);
+    }
 
-    //Use the renderer:
-    pack_start(*cell);
+    cell->property_xalign() = 0.0f;
 
     //Make the renderer render the column:
     add_attribute(*cell, "text", i);
diff --git a/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
index 9ed47bd..3bb1f0c 100644
--- a/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
+++ b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
@@ -43,16 +43,16 @@ void CellRendererDbList::create_model(guint columns_count)
   DataWidgetChildren::ComboChoicesWithTreeModel::create_model(columns_count);
 
   //Show model in the view:
-  set_property("model", m_refModel);
-  set_property("text-column", 0); //This must be a text column, in m_refModel.
-  set_property("editable", true); //It would be useless if we couldn't edit it.
+  property_model() = m_refModel;
+  property_text_column() = 0; //This must be a text column, in m_refModel.
+  property_editable() = true; //It would be useless if we couldn't edit it.
 
   //The other cells are added in on_editing_started().
 }
 
 void CellRendererDbList::set_restrict_values_to_list(bool val)
 {
-  set_property("has-entry", static_cast<gboolean>(!val));
+  property_has_entry() = !val;
 }
 
 void CellRendererDbList::on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path)
@@ -68,11 +68,27 @@ void CellRendererDbList::on_editing_started(Gtk::CellEditable* cell_editable, co
   {
     for(guint col = cells.size(); col != m_vec_model_columns.size(); ++col)
     {
-      Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
-      cell->set_property("xalign", 0.0);
-
-      //Use the renderer:
-      combobox->pack_start(*cell);
+      Gtk::CellRendererText* cell = 0;
+      if(col == 0)
+      {
+        //Get the default column, created by set_text_column()?
+        cell = dynamic_cast<Gtk::CellRendererText*>(combobox->get_first_cell());
+      }
+
+      if(!cell)
+      {
+        //Create the cell:
+        cell = Gtk::manage(new Gtk::CellRendererText);
+
+        //Use the renderer:
+        //We don't expand the first column, so we can align the other columns.
+        //Otherwise the other columns appear center-aligned.
+        //This bug is relevant: https://bugzilla.gnome.org/show_bug.cgi?id=629133
+        if(col == 0) //Impossible anyway, because we use the text-column property.
+          combobox->pack_start(*cell, false); //Unfortunately gtk_combo_box_entry_set_text_column() has already used true, making our xalign=0.0 useless.
+        else
+          combobox->pack_start(*cell, true);
+      }
 
       //Make the renderer render the column:
       combobox->add_attribute(*cell, "text", col);



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