[glom] Choices drop-downs: More improvement of the column alignment.



commit 20515f5d183f0042781937e8776c80715cd45e8c
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Sep 9 22:32:20 2010 +0200

    Choices drop-downs: More improvement of the column alignment.
    
    * glom/mode_data/datawidget/comboentry.cc: create_model():
    * glom/utility_widgets/db_adddel/cellrenderer_dblist.[h|cc]:
    on_editing_started(): Remove (with clear) the automatically-added
    CellRenderer and re-pack it, so we can specify expand=false.

 ChangeLog                                          |    9 ++++
 glom/mode_data/datawidget/combo.cc                 |    2 +
 glom/mode_data/datawidget/comboentry.cc            |   24 ++++-----
 .../db_adddel/cellrenderer_dblist.cc               |   49 +++++++++++--------
 .../db_adddel/cellrenderer_dblist.h                |    2 +
 5 files changed, 52 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index eb8b38d..8aaae75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-09-09  Murray Cumming  <murrayc murrayc com>
+
+	Choices drop-downs: More improvement of the column alignment.
+
+	* glom/mode_data/datawidget/comboentry.cc: create_model():
+	* glom/utility_widgets/db_adddel/cellrenderer_dblist.[h|cc]: 
+	on_editing_started(): Remove (with clear) the automatically-added 
+	CellRenderer and re-pack it, so we can specify expand=false.
+
 2010-09-09  David King  <davidk openismus com>
 
 	Initial dialog: Really try to load examples from each path.
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 9682afb..3097534 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -76,6 +76,8 @@ void ComboGlom::create_model(guint columns_count)
 
   //Show the model in the view:
   set_model(m_refModel);
+  
+  clear();
 
   for(guint i = 0; i < columns_count; ++i)
   {
diff --git a/glom/mode_data/datawidget/comboentry.cc b/glom/mode_data/datawidget/comboentry.cc
index 016e48f..e9b942c 100644
--- a/glom/mode_data/datawidget/comboentry.cc
+++ b/glom/mode_data/datawidget/comboentry.cc
@@ -124,27 +124,25 @@ void ComboEntry::create_model(guint columns_count)
     {
       //Get the default column, created by set_text_column():
       cell = dynamic_cast<Gtk::CellRendererText*>(get_first_cell());
+      
+      //Unpack and repack it with expand=false instead of expand=true:
+      //We don't expand the first column, so we can align the other columns.
+      cell->reference();
+      clear();
+      pack_start(*cell, false);
+      cell->unreference();
     }
-
-    if(!cell)
+    else
     {
       //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);
+      pack_start(*cell, true);
     }
 
-    cell->property_xalign() = 0.0f;
-
     //Make the renderer render the column:
     add_attribute(*cell, "text", i);
+    
+    cell->property_xalign() = 0.0f;
   }
 }
 
diff --git a/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
index 232bad0..4057e57 100644
--- a/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
+++ b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
@@ -27,6 +27,7 @@ namespace Glom
 {
 
 CellRendererDbList::CellRendererDbList()
+: m_repacked_first_cell(false)
 {
 }
 
@@ -61,35 +62,41 @@ void CellRendererDbList::on_editing_started(Gtk::CellEditable* cell_editable, co
   if(!combobox)
     return;
 
+  if(!m_repacked_first_cell)
+  {
+    //Get the default column, created by set_text_column():
+    Gtk::CellRendererText* cell = dynamic_cast<Gtk::CellRendererText*>(combobox->get_first_cell());
+        
+    //Unpack and repack it with expand=false instead of expand=true:
+    //We don't expand the first column, so we can align the other columns.
+    cell->reference();
+    combobox->clear();
+    combobox->pack_start(*cell, false);
+    cell->unreference();
+  
+    //Make the renderer render the column:
+    combobox->add_attribute(*cell, "text", 0);
+      
+    cell->property_xalign() = 0.0f;  
+    
+    m_repacked_first_cell = true; //Avoid doing this again.
+  }
+   
+  //Add extra cells:     
   Glib::ListHandle<Gtk::CellRenderer*> cells = combobox->get_cells();
   if(cells.size() < m_vec_model_columns.size())
   {
     for(guint col = cells.size(); col != m_vec_model_columns.size(); ++col)
     {
-      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);
-      }
+      Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
 
+      //Use the renderer:
+      combobox->pack_start(*cell, true);
+      
       //Make the renderer render the column:
       combobox->add_attribute(*cell, "text", col);
+      
+      cell->property_xalign() = 0.0f;
     }
   }
 
diff --git a/glom/utility_widgets/db_adddel/cellrenderer_dblist.h b/glom/utility_widgets/db_adddel/cellrenderer_dblist.h
index f596da5..6828f19 100644
--- a/glom/utility_widgets/db_adddel/cellrenderer_dblist.h
+++ b/glom/utility_widgets/db_adddel/cellrenderer_dblist.h
@@ -55,6 +55,8 @@ private:
 
   void set_text(const Glib::ustring& text);
   Glib::ustring get_text() const;
+  
+  bool m_repacked_first_cell;
 };
 
 } //namespace Glom



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