[glom] List view: Support multiple extra fields in choices here too.



commit ea2b1861da0bb981c59f5e2c358f016c0c7009fa
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Sep 8 22:33:42 2010 +0200

    List view: Support multiple extra fields in choices here too.
    
      * glom/utility_widgets/cellrendererlist/cellrendererlist.[h|cc]:
      Split this into:
    	* glom/utility_widgets/cellrendererlist.[h|cc]: with no extra/second-column
      functionality. It is now just a convenience class for a string-based combo
      cell.
      And into this:
    	* glom/utility_widgets/db_adddel/cellrenderer_dblist.[h|cc]: deriving from
      ComboChoicesWithTreeModel, like the regular combo widgets. Remove non-DB
      API.
    	* glom/utility_widgets/db_adddel/db_adddel.cc: Adapted.

 ChangeLog                                          |   15 ++
 Makefile_glom.am                                   |    6 +-
 .../datawidget/combochoiceswithtreemodel.h         |    2 +-
 glom/utility_widgets/adddel/adddel.cc              |    2 +-
 glom/utility_widgets/cellrendererlist.cc           |   60 ++++++++
 .../{cellrendererlist => }/cellrendererlist.h      |   18 +--
 .../cellrendererlist/cellrendererlist.cc           |   91 ------------
 .../db_adddel/cellrenderer_dblist.cc               |  144 ++++++++++++++++++++
 .../cellrenderer_dblist.h}                         |   45 +++----
 glom/utility_widgets/db_adddel/db_adddel.cc        |   99 ++++----------
 glom/utility_widgets/db_adddel/db_adddel.h         |    5 +-
 11 files changed, 277 insertions(+), 210 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 14f07dc..819be1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-09-09  Murray Cumming  <murrayc murrayc com>>
+
+	List view: Support multiple extra fields in choices here too.
+
+  * glom/utility_widgets/cellrendererlist/cellrendererlist.[h|cc]:
+  Split this into:
+	* glom/utility_widgets/cellrendererlist.[h|cc]: with no extra/second-column
+  functionality. It is now just a convenience class for a string-based combo
+  cell.
+  And into this:
+	* glom/utility_widgets/db_adddel/cellrenderer_dblist.[h|cc]: deriving from
+  ComboChoicesWithTreeModel, like the regular combo widgets. Remove non-DB
+  API.
+	* glom/utility_widgets/db_adddel/db_adddel.cc: Adapted.
+
 2010-09-08  Murray Cumming  <murrayc murrayc com>
 
 	Combo widgets: Support multiple extra fields.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 3f12009..6c4fde3 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -187,8 +187,8 @@ glom_source_files = \
 	glom/utility_widgets/canvas/canvas_table_movable.h		\
 	glom/utility_widgets/canvas/canvas_text_movable.cc		\
 	glom/utility_widgets/canvas/canvas_text_movable.h		\
-	glom/utility_widgets/cellrendererlist/cellrendererlist.cc	\
-	glom/utility_widgets/cellrendererlist/cellrendererlist.h	\
+	glom/utility_widgets/cellrendererlist.cc	\
+	glom/utility_widgets/cellrendererlist.h	\
 	glom/utility_widgets/db_adddel/cellrenderer_buttonimage.cc	\
 	glom/utility_widgets/db_adddel/cellrenderer_buttonimage.h	\
 	glom/utility_widgets/db_adddel/cellrenderer_buttontext.cc	\
@@ -197,6 +197,8 @@ glom_source_files = \
 	glom/utility_widgets/db_adddel/db_adddel.h			\
 	glom/utility_widgets/db_adddel/db_adddel_withbuttons.cc		\
 	glom/utility_widgets/db_adddel/db_adddel_withbuttons.h		\
+	glom/utility_widgets/db_adddel/cellrenderer_dblist.cc	\
+	glom/utility_widgets/db_adddel/cellrenderer_dblist.h	\
 	glom/utility_widgets/db_adddel/db_treeviewcolumn_glom.cc	\
 	glom/utility_widgets/db_adddel/db_treeviewcolumn_glom.h		\
 	glom/utility_widgets/db_adddel/glom_db_treemodel.cc		\
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.h b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
index 6c0d16e..e98a682 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
@@ -47,11 +47,11 @@ protected:
 
   Glib::RefPtr<Gtk::ListStore> m_refModel;
 
-private:
   typedef Gtk::TreeModelColumn<Glib::ustring> type_model_column;
   typedef std::vector< type_model_column* > type_vec_model_columns;
   type_vec_model_columns m_vec_model_columns;
 
+private:
   void delete_model();
 };
 
diff --git a/glom/utility_widgets/adddel/adddel.cc b/glom/utility_widgets/adddel/adddel.cc
index 9152dfb..09e42b9 100644
--- a/glom/utility_widgets/adddel/adddel.cc
+++ b/glom/utility_widgets/adddel/adddel.cc
@@ -23,7 +23,7 @@
 #include <glom/utility_widgets/adddel/adddel.h>
 #include <algorithm> //For std::find.
 #include <glibmm/i18n.h>
-#include <glom/utility_widgets/cellrendererlist/cellrendererlist.h>
+#include <glom/utility_widgets/cellrendererlist.h>
 #include <glom/utility_widgets/adddel/treeviewcolumn_glom.h>
 #include <libglom/data_structure/glomconversions.h>
 #include <glom/dialog_invalid_data.h>
diff --git a/glom/utility_widgets/cellrendererlist.cc b/glom/utility_widgets/cellrendererlist.cc
new file mode 100644
index 0000000..0812b2e
--- /dev/null
+++ b/glom/utility_widgets/cellrendererlist.cc
@@ -0,0 +1,60 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+ 
+#include "cellrendererlist.h"
+#include <gtkmm.h>
+
+
+namespace Glom
+{
+
+CellRendererList::CellRendererList()
+:  Glib::ObjectBase(0) //Mark this class as gtkmmproc-generated, rather than a custom class, to allow vfunc optimisations.
+   //TODO: This should not be necessary - our gtkmm callbacks are somehow preventing the popup from appearing.
+{
+  m_refModel = Gtk::ListStore::create(m_model_columns);
+  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.
+}
+
+CellRendererList::~CellRendererList()
+{
+}
+
+void CellRendererList::remove_all_list_items()
+{
+  if(m_refModel)
+    m_refModel->clear();
+}
+
+void CellRendererList::append_list_item(const Glib::ustring& text)
+{
+  Gtk::TreeModel::Row row = *(m_refModel->append());
+  row[m_model_columns.m_col_choice] = text;
+}
+
+void CellRendererList::set_restrict_values_to_list(bool val)
+{
+  set_property("has-entry", static_cast<gboolean>(!val));
+}
+
+
+} //namespace Glom
diff --git a/glom/utility_widgets/cellrendererlist/cellrendererlist.h b/glom/utility_widgets/cellrendererlist.h
similarity index 74%
copy from glom/utility_widgets/cellrendererlist/cellrendererlist.h
copy to glom/utility_widgets/cellrendererlist.h
index 3a486e2..ac6414a 100644
--- a/glom/utility_widgets/cellrendererlist/cellrendererlist.h
+++ b/glom/utility_widgets/cellrendererlist.h
@@ -18,8 +18,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef ADDDEL_CELLRENDERERLIST_H
-#define ADDDEL_CELLRENDERERLIST_H
+#ifndef GLOM_UTILITY_WIDGETS_CELLRENDERERLIST_H
+#define GLOM_UTILITY_WIDGETS_CELLRENDERERLIST_H
 
 #include <gtkmm.h>
 //#include <gtkmm/cellrenderercombo.h>
@@ -29,6 +29,8 @@
 namespace Glom
 {
 
+/** A CellRendererCombo with a single (text) column.
+ */
 class CellRendererList : public Gtk::CellRendererCombo
 {
 public:
@@ -36,15 +38,11 @@ public:
   virtual ~CellRendererList();
 
   void remove_all_list_items();
-  void append_list_item(const Glib::ustring& text, const Glib::ustring& extra = Glib::ustring());
-
-  ///Whether the second column will be shown.
-  void set_use_second(bool use_second = true);
+  void append_list_item(const Glib::ustring& text);
 
   void set_restrict_values_to_list(bool val = true);
 
 private:
-  void on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
 
   //Tree model columns for the Combo CellRenderer in the TreeView column:
   class ModelColumns : public Gtk::TreeModel::ColumnRecord
@@ -52,18 +50,16 @@ private:
   public:
 
     ModelColumns()
-    { add(m_col_choice); add(m_col_extra); }
+    { add(m_col_choice); }
 
     Gtk::TreeModelColumn<Glib::ustring> m_col_choice;
-    Gtk::TreeModelColumn<Glib::ustring> m_col_extra;
   };
 
   ModelColumns m_model_columns;
 
   Glib::RefPtr<Gtk::ListStore> m_refModel;
-  bool m_use_second;
 };
 
 } //namespace Glom
 
-#endif //ADDDEL_CELLRENDERERLIST_H
+#endif //GLOM_UTILITY_WIDGETS_CELLRENDERERLIST_H
diff --git a/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
new file mode 100644
index 0000000..9ed47bd
--- /dev/null
+++ b/glom/utility_widgets/db_adddel/cellrenderer_dblist.cc
@@ -0,0 +1,144 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "cellrenderer_dblist.h"
+#include <gtkmm.h>
+#include <libglom/data_structure/glomconversions.h>
+
+
+namespace Glom
+{
+
+CellRendererDbList::CellRendererDbList()
+:  Glib::ObjectBase(0) //Mark this class as gtkmmproc-generated, rather than a custom class, to allow vfunc optimisations.
+   //TODO: This should not be necessary - our gtkmm callbacks are somehow preventing the popup from
+{
+}
+
+CellRendererDbList::~CellRendererDbList()
+{
+}
+
+
+void CellRendererDbList::create_model(guint columns_count)
+{
+  //Create the model itself:
+  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.
+
+  //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));
+}
+
+void CellRendererDbList::on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path)
+{
+  g_assert(cell_editable);
+
+  Gtk::CellLayout* combobox = dynamic_cast<Gtk::CellLayout*>(cell_editable);
+  if(!combobox)
+    return;
+
+  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 = Gtk::manage(new Gtk::CellRendererText);
+      cell->set_property("xalign", 0.0);
+
+      //Use the renderer:
+      combobox->pack_start(*cell);
+
+      //Make the renderer render the column:
+      combobox->add_attribute(*cell, "text", col);
+    }
+  }
+
+  Gtk::CellRenderer::on_editing_started(cell_editable, path);
+}
+
+void CellRendererDbList::set_value(const Gnome::Gda::Value& value)
+{
+  sharedptr<const LayoutItem_Field> layout_item = sharedptr<const LayoutItem_Field>::cast_dynamic(get_layout_item());
+  if(!layout_item)
+    return;
+
+  set_text(Conversions::get_text_for_gda_value(layout_item->get_glom_type(), value, layout_item->get_formatting_used().m_numeric_format));
+
+  //Show a different color if the value is numeric, if that's specified:
+  /* TODO:
+  if(layout_item->get_glom_type() == Field::TYPE_NUMERIC)
+  {
+    std::vector<Gtk::CellRenderer*> cells = get_cells();
+    if(cells.empty())
+      return;
+
+    Gtk::CellRendererText* cell = dynamic_cast<Gtk::CellRendererText*>(cells[0]);
+    if(!cell)
+      return;
+
+    const Glib::ustring fg_color =
+      layout_item->get_formatting_used().get_text_format_color_foreground_to_use(value);
+    if(fg_color.empty())
+    {
+      //GtkComboBox doesn't interpret "" as an unset. TODO: Fix that?
+      cell->property_foreground_set() = false;
+    }
+    else
+      cell->property_foreground() = fg_color;
+  }
+  */
+}
+
+Gnome::Gda::Value CellRendererDbList::get_value() const
+{
+  sharedptr<const LayoutItem_Field> layout_item = sharedptr<const LayoutItem_Field>::cast_dynamic(get_layout_item());
+  bool success = false;
+
+  const Glib::ustring text = get_text();
+  return Conversions::parse_value(layout_item->get_glom_type(), text, layout_item->get_formatting_used().m_numeric_format, success);
+}
+
+void CellRendererDbList::set_text(const Glib::ustring& text)
+{
+  property_text() = text;
+}
+
+Glib::ustring CellRendererDbList::get_text() const
+{
+  return property_text();
+}
+
+void CellRendererDbList::set_choices_with_second(const type_list_values_with_second& list_values)
+{
+  DataWidgetChildren::ComboChoicesWithTreeModel::set_choices_with_second(list_values);
+}
+
+
+
+} //namespace Glom
diff --git a/glom/utility_widgets/cellrendererlist/cellrendererlist.h b/glom/utility_widgets/db_adddel/cellrenderer_dblist.h
similarity index 51%
rename from glom/utility_widgets/cellrendererlist/cellrendererlist.h
rename to glom/utility_widgets/db_adddel/cellrenderer_dblist.h
index 3a486e2..f596da5 100644
--- a/glom/utility_widgets/cellrendererlist/cellrendererlist.h
+++ b/glom/utility_widgets/db_adddel/cellrenderer_dblist.h
@@ -18,9 +18,10 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef ADDDEL_CELLRENDERERLIST_H
-#define ADDDEL_CELLRENDERERLIST_H
+#ifndef GLOM_UTILITY_WIDGETS_DBADDDELL_CELLRENDERDBERLIST_H
+#define GLOM_UTILITY_WIDGETS_DBADDDELL_CELLRENDERDBERLIST_H
 
+#include <glom/mode_data/datawidget/combochoiceswithtreemodel.h>
 #include <gtkmm.h>
 //#include <gtkmm/cellrenderercombo.h>
 //#include <gtkmm/liststore.h>
@@ -29,41 +30,33 @@
 namespace Glom
 {
 
-class CellRendererList : public Gtk::CellRendererCombo
+/** A CellRendererCombo to show database records.
+ * For instance, to show related choices.
+ */
+class CellRendererDbList
+ : public Gtk::CellRendererCombo,
+   public DataWidgetChildren::ComboChoicesWithTreeModel
 {
 public:
-  CellRendererList();
-  virtual ~CellRendererList();
-
-  void remove_all_list_items();
-  void append_list_item(const Glib::ustring& text, const Glib::ustring& extra = Glib::ustring());
+  CellRendererDbList();
+  virtual ~CellRendererDbList();
 
-  ///Whether the second column will be shown.
-  void set_use_second(bool use_second = true);
+  void set_choices_with_second(const type_list_values_with_second& list_values);
 
   void set_restrict_values_to_list(bool val = true);
 
 private:
-  void on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
-
-  //Tree model columns for the Combo CellRenderer in the TreeView column:
-  class ModelColumns : public Gtk::TreeModel::ColumnRecord
-  {
-  public:
-
-    ModelColumns()
-    { add(m_col_choice); add(m_col_extra); }
 
-    Gtk::TreeModelColumn<Glib::ustring> m_col_choice;
-    Gtk::TreeModelColumn<Glib::ustring> m_col_extra;
-  };
+  virtual void create_model(guint columns_count);
+  virtual void on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
 
-  ModelColumns m_model_columns;
+  virtual void set_value(const Gnome::Gda::Value& value);
+  virtual Gnome::Gda::Value get_value() const;
 
-  Glib::RefPtr<Gtk::ListStore> m_refModel;
-  bool m_use_second;
+  void set_text(const Glib::ustring& text);
+  Glib::ustring get_text() const;
 };
 
 } //namespace Glom
 
-#endif //ADDDEL_CELLRENDERERLIST_H
+#endif //GLOM_UTILITY_WIDGETS_DBADDDELL_CELLRENDERDBERLIST_H
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index fd5315b..54323e3 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -21,7 +21,8 @@
 #include "db_adddel.h"
 #include <algorithm> //For std::find.
 #include <glibmm/i18n.h>
-#include "../cellrendererlist/cellrendererlist.h"
+#include <glom/utility_widgets/cellrendererlist.h>
+#include <glom/utility_widgets/db_adddel/cellrenderer_dblist.h>
 #include "db_treeviewcolumn_glom.h"
 #include <libglom/data_structure/glomconversions.h>
 #include <glom/dialog_invalid_data.h>
@@ -714,7 +715,8 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
       {
         if(item_field->get_formatting_used().get_has_choices())
         {
-          CellRendererList* rendererList = Gtk::manage( new CellRendererList() );
+          CellRendererDbList* rendererList = Gtk::manage( new CellRendererDbList() );
+          rendererList->set_layout_item(item_field, m_table_name);
           bool as_radio_buttons = false; //Can't really be done in a list, so we ignore it.
           rendererList->set_restrict_values_to_list(
             item_field->get_formatting_used().get_choices_restricted(as_radio_buttons));
@@ -812,24 +814,26 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
     #endif //GLOM_ENABLE_MAEMO
 
     //Choices:
-    CellRendererList* pCellRendererCombo = dynamic_cast<CellRendererList*>(pCellRenderer);
-    if(pCellRendererCombo)
+    CellRendererList* pCellRendererList = dynamic_cast<CellRendererList*>(pCellRenderer);
+    CellRendererDbList* pCellRendererDbList = dynamic_cast<CellRendererDbList*>(pCellRenderer);
+    if(pCellRendererList) //Used for custom choices:
     {
-      pCellRendererCombo->remove_all_list_items();
+      pCellRendererList->remove_all_list_items();
 
       if(item_field && item_field->get_formatting_used().get_has_custom_choices())
       {
-        pCellRendererCombo->set_use_second(false); //Custom choices have only one column.
-
         //set_choices() needs this, for the numeric layout:
         //pCellRendererCombo->set_layout_item(get_layout_item()->clone(), table_name); //TODO_Performance: We only need this for the numerical format.
         const FieldFormatting::type_list_values list_values = item_field->get_formatting_used().get_choices_custom();
         for(FieldFormatting::type_list_values::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
         {
-          pCellRendererCombo->append_list_item( Conversions::get_text_for_gda_value(item_field->get_glom_type(), *iter, item_field->get_formatting_used().m_numeric_format) );
+          pCellRendererList->append_list_item( Conversions::get_text_for_gda_value(item_field->get_glom_type(), *iter, item_field->get_formatting_used().m_numeric_format) );
         }
       }
-      else if(item_field && item_field->get_formatting_used().get_has_related_choices())
+    }
+    else if(pCellRendererDbList) //Used for related choices:
+    {
+      if(item_field && item_field->get_formatting_used().get_has_related_choices())
       {
         sharedptr<const Relationship> choice_relationship;
         sharedptr<const LayoutItem_Field> choice_field;
@@ -841,15 +845,13 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
         {
           const Glib::ustring to_table = choice_relationship->get_to_table();
 
-          const bool use_second = choice_extras;
-          pCellRendererCombo->set_use_second(use_second);
-
           //TODO: Update this when the relationship's field value changes:
           if(choice_show_all) //Otherwise it must change whenever the relationships's ID value changes.
           {
-            const Utils::type_list_values_with_second list_values = 
+            const Utils::type_list_values_with_second list_values =
               Utils::get_choice_values_all(get_document(), item_field);
-            set_cell_choices(pCellRendererCombo, choice_field, choice_extras, list_values);
+            std::cout << G_STRFUNC << ": debug: values size=" << list_values.size() << std::endl;
+            pCellRendererDbList->set_choices_with_second(list_values);
           }
         }
       }
@@ -1236,54 +1238,6 @@ void DbAddDel::set_value_selected(const sharedptr<const LayoutItem_Field>& layou
   set_value(get_item_selected(), layout_item, value);
 }
 
-void DbAddDel::set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first,  const sharedptr<const LayoutGroup>& layout_choice_extras, const Utils::type_list_values_with_second& list_values)
-{
-  if(!cell)
-    return;
-
-  //Set the choices:
-  cell->remove_all_list_items();
-
-  for(Utils::type_list_values_with_second::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
-  {
-    const Glib::ustring first =
-      Conversions::get_text_for_gda_value(
-        layout_choice_first->get_glom_type(), iter->first, layout_choice_first->get_formatting_used().m_numeric_format);
-
-    //TODO: Support multiple extra fields:
-    //For now, use only the first extra field:
-    sharedptr<const LayoutItem_Field> layout_choice_second;
-    if(layout_choice_extras)
-    {
-      const LayoutGroup::type_list_const_items extra_fields
-        = layout_choice_extras->get_items_recursive();
-
-      for(LayoutGroup::type_list_const_items::const_iterator iterExtra = extra_fields.begin();
-          iterExtra != extra_fields.end(); ++iterExtra)
-      {
-        const sharedptr<const LayoutItem> item = *iterExtra;
-        const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
-        if(item_field)
-        {
-          layout_choice_second = item_field;
-          break;
-        }
-      }
-    }
-        
-    Glib::ustring second;
-    const Utils::type_list_values extra_values = iter->second;
-    if(layout_choice_second && !extra_values.empty())
-    {
-      const Gnome::Gda::Value value = *(extra_values.begin()); //TODO: Use a vector instead?
-      second = Conversions::get_text_for_gda_value(
-        layout_choice_second->get_glom_type(), value, layout_choice_second->get_formatting_used().m_numeric_format);
-    }
-
-    cell->append_list_item(first, second);
-  }
-}
-
 void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint model_index, const Gnome::Gda::Value& foreign_key_value)
 {
   if(m_ColumnTypes.size() <= model_index)
@@ -1308,8 +1262,8 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
     return;
   }
 
-  CellRendererList* cell =
-    dynamic_cast<CellRendererList*>( m_TreeView.get_column_cell_renderer(view_column_index) );
+  CellRendererDbList* cell =
+    dynamic_cast<CellRendererDbList*>( m_TreeView.get_column_cell_renderer(view_column_index) );
   if(!cell)
   {
     std::cerr << G_STRFUNC << ": cell renderer not found for model_column=" << model_index << std::endl;
@@ -1318,14 +1272,7 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
 
   const Utils::type_list_values_with_second list_values =
     Utils::get_choice_values(get_document(), layout_field, foreign_key_value);
-
-  sharedptr<const Relationship> choice_relationship;
-  sharedptr<const LayoutItem_Field> layout_choice_first;
-  sharedptr<const LayoutGroup> layout_choice_extras;
-  bool choice_show_all = false;
-  layout_field->get_formatting_used().get_choices_related(choice_relationship, layout_choice_first, layout_choice_extras, choice_show_all); 
-    
-  set_cell_choices(cell, layout_choice_first, layout_choice_extras, list_values);
+  cell->set_choices_with_second(list_values);
 }
 
 void DbAddDel::remove_all_columns()
@@ -1505,6 +1452,7 @@ void DbAddDel::set_prevent_user_signals(bool bVal)
   m_bPreventUserSignals = bVal;
 }
 
+/*
 //This is generally used for non-database-data lists.
 void DbAddDel::set_column_choices(guint col, const type_vec_strings& vecStrings)
 {
@@ -1521,10 +1469,10 @@ void DbAddDel::set_column_choices(guint col, const type_vec_strings& vecStrings)
     g_assert(column);
     std::vector<Gtk::CellRenderer*> list_renderers = column->get_cells();
     g_assert(!list_renderers.empty());
-    CellRendererList* pCellRenderer = dynamic_cast<CellRendererList*>(list_renderers[0]);
+    CellRendererDbList* pCellRenderer = dynamic_cast<CellRendererDbList*>(list_renderers[0]);
     #else
-    CellRendererList* pCellRenderer =
-      dynamic_cast<CellRendererList*>( m_TreeView.get_column_cell_renderer(view_column_index) );
+    CellRendererDbList* pCellRenderer =
+      dynamic_cast<CellRendererDbList*>( m_TreeView.get_column_cell_renderer(view_column_index) );
     #endif //GLOM_ENABLE_MAEMO
     if(pCellRenderer)
     {
@@ -1543,6 +1491,7 @@ void DbAddDel::set_column_choices(guint col, const type_vec_strings& vecStrings)
     }
   }
 }
+*/
 
 void DbAddDel::set_allow_add(bool val)
 {
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 7ea85dd..4bbca73 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -61,7 +61,7 @@ public:
 };
 
 class DbTreeViewColumnGlom;
-class CellRendererList;
+class CellRendererDbList;
 
 /** For adding/deleting/selecting record rows.
  */
@@ -194,7 +194,7 @@ public:
   void remove_all_columns();
 
   /// For popup cells.
-  void set_column_choices(guint col, const type_vec_strings& vecStrings);
+  //void set_column_choices(guint col, const type_vec_strings& vecStrings);
 
   void construct_specified_columns(); //Delay actual use of set_column_*() stuff until this method is called.
 
@@ -390,7 +390,6 @@ private:
   //TODO: Remove this and use AppGlom::get_application() instead?
   Application* get_application();
 
-  void set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first,  const sharedptr<const LayoutGroup>& layout_choice_extras, const Utils::type_list_values_with_second& list_values);
   void refresh_cell_choices_data_from_database_with_foreign_key(guint model_index, const Gnome::Gda::Value& foreign_key_value);
 
   static void apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<const LayoutItem_WithFormatting>& layout_item);



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