[glom/feature_choices_show_all] DbAddDel: Avoid some copy/pasting of code to append items to choices cells.



commit a170086a34bf51329f928f5a5bb556a448d6366c
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Aug 6 11:54:34 2010 +0200

    DbAddDel: Avoid some copy/pasting of code to append items to choices cells.
    
    * glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Added set_cell_choices(),
      using it in refresh_cell_choices_data_from_database_with_foreign_key() and
      construct_specified_columns_cellrenderer().

 ChangeLog                                   |   22 ++-
 glom/utility_widgets/db_adddel/db_adddel.cc |  241 +++++++++++++--------------
 glom/utility_widgets/db_adddel/db_adddel.h  |   71 ++++----
 3 files changed, 171 insertions(+), 163 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5063778..ba29e03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,14 +1,22 @@
 2010-08-06  Murray Cumming  <murrayc murrayc com>
 
+	DbAddDel: Avoid some copy/pasting of code to append items to choices cells.
+
+	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Added set_cell_choices(),
+  using it in refresh_cell_choices_data_from_database_with_foreign_key() and
+  construct_specified_columns_cellrenderer().
+
+2010-08-06  Murray Cumming  <murrayc murrayc com>
+
 	List: Choices with !show_all: Update the list when the from_field changes.
 
-	* glom/libglom/utils.[h|cc]: Added a get_choice_values() overload that 
+	* glom/libglom/utils.[h|cc]: Added a get_choice_values() overload that
 	takes the foreign_key.
-	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Added get_choice_index() 
+	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Added get_choice_index()
 	to get the affected choice lists when a field value changes.
-	Added refresh_cell_choices_data_from_database_with_foreign_key() to update 
+	Added refresh_cell_choices_data_from_database_with_foreign_key() to update
 	these lists.
-	set_value(): Use these methods to update choice lists when appropriate, 
+	set_value(): Use these methods to update choice lists when appropriate,
 	as already happens in the Details view.
 
 2010-08-05  Murray Cumming  <murrayc murrayc com>
@@ -16,10 +24,10 @@
 	List view: When a value is edited, update other instances of the same field.
 
 	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]:
-	get_data_model_column_index(): Add a including_specified_field_layout bool 
-	parameter, used in a new set_value() method overload that has a 
+	get_data_model_column_index(): Add a including_specified_field_layout bool
+	parameter, used in a new set_value() method overload that has a
 	set_specified_field_layout bool parameter.
-	user_changed(): Call set_value() to show the new value in any other 
+	user_changed(): Call set_value() to show the new value in any other
 	instances of the same field.
 	The details view already does this.
 
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index d2fe609..d7818e0 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -97,13 +97,13 @@ DbAddDel::DbAddDel()
   //Start with a useful default TreeModel:
   //set_columns_count(1);
   //construct_specified_columns();
-  
+
   // Give the TreeView an accessible name, to access it in LDTP
   // TODO: Maybe this should be a constructor parameter, so that multiple
   // DbAddDels in a single Window can be addressed separately.
 #ifdef GTKMM_ATKMM_ENABLED
   m_TreeView.get_accessible()->set_name(_("Table Content"));
-#endif  
+#endif
 
   #ifndef GLOM_ENABLE_MAEMO
   m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
@@ -116,11 +116,11 @@ DbAddDel::DbAddDel()
   //Do not let the treeview emit activated as soon as a row is pressed.
   //TODO: Allow this default maemo behaviour?
   g_object_set(m_TreeView.gobj(), "hildon-ui-mode", HILDON_UI_MODE_NORMAL, (void*)0);
-  
+
   //Allow get_selected() and get_active() to work:
   m_TreeView.set_column_selection_mode(Hildon::TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
   pack_start(m_TreeView);
-  
+
   m_TreeView.signal_changed().connect(sigc::mem_fun(*this, &DbAddDel::on_maemo_touchselector_changed));
   #endif //GLOM_ENABLE_MAEMO
 
@@ -154,7 +154,7 @@ DbAddDel::DbAddDel()
   // Adjust sizing when style changed
   // TODO_Maemo: This calls construct_specified_columns(), which runs the SQL query again.
   //       Try to change the row and column sizes without doing that.
-  
+
   signal_style_changed().connect(sigc::mem_fun(*this, &DbAddDel::on_self_style_changed));
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 }
@@ -166,7 +166,7 @@ DbAddDel::~DbAddDel()
   if(pApp)
   {
     pApp->remove_developer_action(m_refContextLayout);
-  } 
+  }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 }
 
@@ -281,7 +281,7 @@ void DbAddDel::setup_menu()
   if(pApp)
   {
     pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
-    pApp->update_userlevel_ui(); //Update our action's sensitivity. 
+    pApp->update_userlevel_ui(); //Update our action's sensitivity.
   }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
@@ -293,7 +293,7 @@ void DbAddDel::setup_menu()
 
   try
   {
-    Glib::ustring ui_info = 
+    Glib::ustring ui_info =
         "<ui>"
         "  <popup name='ContextMenu'>"
         "    <menuitem action='ContextEdit'/>"
@@ -313,7 +313,7 @@ void DbAddDel::setup_menu()
   }
 
   //Get the menu:
-  m_pMenuPopup = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/ContextMenu") ); 
+  m_pMenuPopup = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/ContextMenu") );
   if(!m_pMenuPopup)
     g_warning("menu not found");
 
@@ -328,7 +328,7 @@ void DbAddDel::setup_menu()
     m_refContextEdit->set_sensitive(false);
     m_refContextDelete->set_sensitive(false);
   }
- 
+
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   if(pApp)
     m_refContextLayout->set_sensitive(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER);
@@ -344,7 +344,7 @@ bool DbAddDel::on_button_press_event_Popup(GdkEventButton *event)
   if(pApp)
   {
     pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
-    pApp->update_userlevel_ui(); //Update our action's sensitivity. 
+    pApp->update_userlevel_ui(); //Update our action's sensitivity.
   }
 #endif
 
@@ -448,7 +448,7 @@ Gtk::TreeModel::iterator DbAddDel::get_item_selected() const
   #ifdef GLOM_ENABLE_MAEMO
   Hildon::TouchSelector& unconst = const_cast<Hildon::TouchSelector&>(m_TreeView);
   return unconst.get_selected(0);
-  
+
   //TODO: What would this mean?
   //See https://bugs.maemo.org/show_bug.cgi?id=4641
   // return m_TreeView.get_active();
@@ -530,7 +530,7 @@ bool DbAddDel::select_item(const Gtk::TreeModel::iterator& iter, const sharedptr
     Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = m_TreeView.get_selection();
     g_assert(refTreeSelection);
     refTreeSelection->select(iter);
-    
+
     Gtk::TreeModel::Path path = m_refListStore->get_path(iter);
 
     guint view_column_index = 0;
@@ -642,9 +642,9 @@ int DbAddDel::get_fixed_cell_height()
   {
     // Discover a suitable height, and cache it,
     // by looking at the heights of all columns:
-    // Note that this is usually calculated during construct_specified_columns(), 
+    // Note that this is usually calculated during construct_specified_columns(),
     // when all columns are known.
-    
+
     //Get a default:
     Glib::RefPtr<Pango::Layout> refLayout = create_pango_layout("example");
     int width = 0;
@@ -781,13 +781,13 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
   {
     apply_formatting(pCellRenderer, item_withformatting);
   }
-  
+
   //Set extra cellrenderer attributes, depending on the type used:
   Gtk::CellRendererText* pCellRendererText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
   if(pCellRendererText)
   {
-    //Use an ellipze to indicate excessive text, 
-    //so that similar values do not look equal, 
+    //Use an ellipze to indicate excessive text,
+    //so that similar values do not look equal,
     //and to avoid multi-line comments. TODO: Is there a better way to restrict the height? This doesn't actually truncate multilines anyway.
     g_object_set(pCellRendererText->gobj(), "ellipsize", PANGO_ELLIPSIZE_END, (gpointer)0);
 
@@ -860,16 +860,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
           if(choice_show_all) //Otherwise it must change whenever the relationships's ID value changes.
           {
             Utils::type_list_values_with_second list_values = Utils::get_choice_values(item_field);
-            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(item_field->get_glom_type(), iter->first, item_field->get_formatting_used().m_numeric_format);
-
-              Glib::ustring second;
-              if(use_second)
-                second = Conversions::get_text_for_gda_value(layout_field_second->get_glom_type(), iter->second, layout_field_second->get_formatting_used().m_numeric_format);
-
-                pCellRendererCombo->append_list_item(first, second);
-            }
+            set_cell_choices(pCellRendererCombo, item_field /* TODO: We shoulds really use a layout_field_first instead */, layout_field_second, list_values);
           }
         }
       }
@@ -922,12 +913,12 @@ void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<con
 
   const Glib::ustring font_desc = formatting.get_text_format_font();
   if(!font_desc.empty())
-  text_renderer->property_font() = font_desc;       
+  text_renderer->property_font() = font_desc;
 
   const Glib::ustring fg = formatting.get_text_format_color_foreground();
   if(!fg.empty())
     text_renderer->property_foreground() = fg;
-    
+
   const Glib::ustring bg = formatting.get_text_format_color_background();
   if(!bg.empty())
     text_renderer->property_background() = bg;
@@ -968,7 +959,7 @@ void DbAddDel::construct_specified_columns()
   //Create the Gtk ColumnRecord:
 
   Gtk::TreeModel::ColumnRecord record;
-    
+
   //Database columns:
   type_model_store::type_vec_fields fields;
   {
@@ -994,7 +985,7 @@ void DbAddDel::construct_specified_columns()
       }
     }
   }
-  
+
   m_FieldsShown = fields; //Needed by Base_DB_Table_Data::record_new().
 
   {
@@ -1035,7 +1026,7 @@ void DbAddDel::construct_specified_columns()
       m_refListStore = Glib::RefPtr<type_model_store>();
     }
   }
- 
+
   #ifdef GLOM_ENABLE_MAEMO
   //Remove all View columns:
   while(m_TreeView.get_num_columns())
@@ -1090,11 +1081,11 @@ void DbAddDel::construct_specified_columns()
 
   bool no_columns_used = true;
   int data_model_column_index = 0; //-1 means undefined index.
-  
+
   guint column_to_expand = 0;
   const bool has_expandable_column = get_column_to_expand(column_to_expand);
   //std::cout << "DEBUG: column_to_expand=" << column_to_expand  << ", has=" << has_expandable_column << std::endl;
-  
+
   for(type_vecModelColumns::iterator iter = vecModelColumns.begin(); iter != vecModelColumns.end(); ++iter)
   {
     const DbAddDelColumnInfo& column_info = m_ColumnTypes[model_column_index];
@@ -1105,7 +1096,7 @@ void DbAddDel::construct_specified_columns()
       const Glib::ustring column_name = column_info.m_item->get_title_or_name();
       const Glib::ustring column_id = column_info.m_item->get_name();
 
-      // Whenever we are dealing with real database fields, 
+      // Whenever we are dealing with real database fields,
       // we need to know the index of the field in the query:
       int item_data_model_column_index = -1;
       sharedptr<const LayoutItem> layout_item = m_ColumnTypes[model_column_index].m_item;
@@ -1123,14 +1114,14 @@ void DbAddDel::construct_specified_columns()
         //Get the index of the field in the query, if it is a field:
         //std::cout << "debug: model_column_index=" << model_column_index << ", item_data_model_column_index=" << item_data_model_column_index << std::endl;
         const bool expand = has_expandable_column && ((int)column_to_expand == model_column_index);
-        treeview_append_column(column_name, 
-          *pCellRenderer, 
-          model_column_index, item_data_model_column_index, 
+        treeview_append_column(column_name,
+          *pCellRenderer,
+          model_column_index, item_data_model_column_index,
           expand);
 
         if(column_info.m_editable)
         {
-       
+
         }
 
         ++view_column_index;
@@ -1149,7 +1140,7 @@ void DbAddDel::construct_specified_columns()
        delete pModelColumn;
   }
 
-  
+
   if(no_columns_used)
   {
     show_hint_model();
@@ -1162,7 +1153,7 @@ void DbAddDel::construct_specified_columns()
     #endif //GLOM_ENABLE_MAEMO
   }
 
-  
+
 
   #ifndef GLOM_ENABLE_MAEMO
   m_TreeView.columns_autosize();
@@ -1235,7 +1226,7 @@ void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<c
       treerow.set_value(treemodel_col, value);
     }
   }
-    
+
   /// Get indexes of any columns with choices with !show_all relationships that have @a from_key as the from_key.
   type_list_indexes list_choice_cells = get_choice_index(layout_item /* from_key field name */);
   std::cout << "debug: list_choice_cells.size() == " << list_choice_cells.size() << std::endl;
@@ -1244,10 +1235,10 @@ void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<c
     const guint model_index = *iter;
     refresh_cell_choices_data_from_database_with_foreign_key(model_index, value /* foreign key value */);
   }
- 
+
   //Add extra blank if necessary:
   //add_blank();
- 
+
   //g_warning("DbAddDel::set_value end");
 }
 
@@ -1256,6 +1247,31 @@ 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 LayoutItem_Field>& layout_choice_second, 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);
+
+    Glib::ustring second;
+    if(layout_choice_second)
+    {
+      second = Conversions::get_text_for_gda_value(
+        layout_choice_second->get_glom_type(), iter->second, 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)
@@ -1263,7 +1279,7 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
     std::cerr << G_STRFUNC << ": model_index is out of range: model_index=" << model_index << ", size=" << m_ColumnTypes.size() << std::endl;
     return;
   }
-      
+
   sharedptr<const LayoutItem> item = m_ColumnTypes[model_index].m_item;
   sharedptr<const LayoutItem_Field> layout_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
   if(!layout_field)
@@ -1271,7 +1287,7 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
     std::cerr << G_STRFUNC << ": The layout item was not a LayoutItem_Field." << std::endl;
     return;
   }
-  
+
   guint view_column_index = 0;
   const bool test = get_view_column_index(model_index, view_column_index);
   if(!test)
@@ -1279,39 +1295,23 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
     std::cerr << G_STRFUNC << ": view column not found for model_column=" << model_index << std::endl;
     return;
   }
-  
-  CellRendererList* cell = 
+
+  CellRendererList* cell =
     dynamic_cast<CellRendererList*>( 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;
     return;
   }
- 
-  //Set the choices:
-  cell->remove_all_list_items();
-  
+
+
   sharedptr<LayoutItem_Field> layout_choice_first;
-  sharedptr<LayoutItem_Field> layout_choice_second; 
-  Utils::type_list_values_with_second list_values = 
+  sharedptr<LayoutItem_Field> layout_choice_second;
+  Utils::type_list_values_with_second list_values =
     Utils::get_choice_values(get_document(), layout_field, foreign_key_value,
       layout_choice_first, layout_choice_second);
 
-  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);
-
-    Glib::ustring second;
-    if(layout_choice_second)
-    {
-      second = Conversions::get_text_for_gda_value(
-        layout_choice_second->get_glom_type(), iter->second, layout_choice_second->get_formatting_used().m_numeric_format);
-    }
-
-    cell->append_list_item(first, second);
-  }
+  set_cell_choices(cell, layout_choice_first, layout_choice_second, list_values);
 }
 
 void DbAddDel::remove_all_columns()
@@ -1334,7 +1334,7 @@ guint DbAddDel::add_column(const sharedptr<LayoutItem>& layout_item)
     return 0; //TODO: Do something more sensible.
 
   InnerIgnore innerIgnore(this); //Stop on_treeview_columns_changed() from doing anything when it is called just because we add a new column.
-  
+
   DbAddDelColumnInfo column_info;
   column_info.m_item = layout_item;
   //column_info.m_editable = editable;
@@ -1395,7 +1395,7 @@ DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const sharedpt
     sharedptr<const LayoutItem_Field> field = sharedptr<const LayoutItem_Field>::cast_dynamic(iter->m_item); //TODO_Performance: This would be unnecessary if !layout_item_field
     if(field)
     {
-      if(field->is_same_field(layout_item_field) 
+      if(field->is_same_field(layout_item_field)
         && (including_specified_field_layout || field != layout_item_field))
       {
         list_indexes.push_back(data_model_column_index);
@@ -1438,10 +1438,10 @@ DbAddDel::type_list_indexes DbAddDel::get_column_index(const sharedptr<const Lay
 DbAddDel::type_list_indexes DbAddDel::get_choice_index(const sharedptr<const LayoutItem_Field>& from_key)
 {
   type_list_indexes result;
-  
+
   if(!from_key)
     return result;
-    
+
   const Glib::ustring from_key_name = from_key->get_name();
 
   guint index = 0;
@@ -1462,7 +1462,7 @@ DbAddDel::type_list_indexes DbAddDel::get_choice_index(const sharedptr<const Lay
       if(choice_relationship->get_from_field() == from_key_name)
         result.push_back(index);
     }
-    
+
     index++;
   }
 
@@ -1492,6 +1492,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)
 {
   InnerIgnore innerIgnore(this); //Stop on_treeview_columns_changed() from doing anything when it is called just because we add new columns.
@@ -1501,7 +1502,7 @@ void DbAddDel::set_column_choices(guint col, const type_vec_strings& vecStrings)
   guint view_column_index = 0;
   const bool test = get_view_column_index(col, view_column_index);
   if(test)
-  { 
+  {
     #ifdef GLOM_ENABLE_MAEMO
     Glib::RefPtr<Hildon::TouchSelectorColumn> column = touch_selector_get_column();
     g_assert(column);
@@ -1509,7 +1510,7 @@ void DbAddDel::set_column_choices(guint col, const type_vec_strings& vecStrings)
     g_assert(!list_renderers.empty());
     CellRendererList* pCellRenderer = dynamic_cast<CellRendererList*>(list_renderers[0]);
     #else
-    CellRendererList* pCellRenderer = 
+    CellRendererList* pCellRenderer =
       dynamic_cast<CellRendererList*>( m_TreeView.get_column_cell_renderer(view_column_index) );
     #endif //GLOM_ENABLE_MAEMO
     if(pCellRenderer)
@@ -1566,7 +1567,7 @@ void DbAddDel::set_find_mode(bool val)
     construct_specified_columns();
   }
 }
-  
+
 void DbAddDel::set_allow_only_one_related_record(bool val)
 {
   m_allow_only_one_related_record = val;
@@ -1777,7 +1778,7 @@ void DbAddDel::on_treeview_cell_edited_bool(const Glib::ustring& path_string, in
     {
       //Change it back, so that we ignore it:
       row.set_value(tree_model_column_index, value_old);
-         
+
       //Signal that a new key was added:
       //We will ignore editing of bool values in the blank row. It seems like a bad way to start a new record.
       //user_added(row);
@@ -1895,7 +1896,7 @@ void DbAddDel::on_treeview_cell_edited(const Glib::ustring& path_string, const G
                     m_TreeView.get_background_area(path, *pColumn, background_area);
 
                     Gdk::Rectangle cell_area;
-                    m_TreeView.get_cell_area(path, *pColumn, background_area); 
+                    m_TreeView.get_cell_area(path, *pColumn, background_area);
                     */
                   }
                 }
@@ -1951,8 +1952,8 @@ bool DbAddDel::on_treeview_columnheader_button_press_event(GdkEventButton* event
   //If this is a right-click with the mouse:
   if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
   {
-    
-    
+
+
   }
 
   return false;
@@ -1967,13 +1968,13 @@ void DbAddDel::on_treeview_column_resized(int model_column_index, DbTreeViewColu
 {
   if(!view_column)
     return;
-  
+
   //Ignore this property change signal handler if we are setting the size in code:
   if(m_bIgnoreTreeViewSignals)
     return;
 
-  //We do not save the column width if this is the last column, 
-  //because that must always be automatic, 
+  //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();
@@ -1987,7 +1988,7 @@ void DbAddDel::on_treeview_column_resized(int model_column_index, DbTreeViewColu
 
   if(width == -1) //Means automatic.
     return;
-    
+
   if(column_info.m_item)
       column_info.m_item->set_display_width(width);
 }
@@ -2056,16 +2057,16 @@ bool DbAddDel::get_column_to_expand(guint& column_to_expand) const
   //Initialize output parameter:
   column_to_expand = 0;
   bool result = false;
-  
-  //Discover the right-most text column: 
+
+  //Discover the right-most text column:
   guint i = 0;
   for(type_ColumnTypes::const_iterator iter = m_ColumnTypes.begin(); iter != m_ColumnTypes.end(); ++iter)
   {
     sharedptr<LayoutItem> layout_item = iter->m_item;
-           
+
     sharedptr<LayoutItem_Field> layout_item_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
     if(layout_item_field)
-    {  
+    {
       //Only text columns should expand.
       //Number fields are right-aligned, so expansion is annoying.
       //Time and date fields don't vary their width much.
@@ -2078,13 +2079,13 @@ bool DbAddDel::get_column_to_expand(guint& column_to_expand) const
           column_to_expand = i;
           result = true;
         }
-        
+
       }
     }
-    
+
     ++i;
   }
-  
+
   return result;
 }
 
@@ -2092,7 +2093,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
 {
   InnerIgnore innerIgnore(this); //see comments for InnerIgnore class
 
-  #ifndef GLOM_ENABLE_MAEMO 
+  #ifndef GLOM_ENABLE_MAEMO
   DbTreeViewColumnGlom* pViewColumn = Gtk::manage( new DbTreeViewColumnGlom(Utils::string_escape_underscores(title), cellrenderer) );
 
   //This is needed by fixed-height mode. We get critical warnings otherwise.
@@ -2101,7 +2102,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
 
   guint cols_count = m_TreeView.append_column(*pViewColumn);
   #else
-  //Mathias Hasselmann says that this is required for the Maemo 5 style, 
+  //Mathias Hasselmann says that this is required for the Maemo 5 style,
   //though we don't know yet where that is documented. murrayc.
   cellrenderer.set_property("xpad", HILDON_MARGIN_DEFAULT);
 
@@ -2117,7 +2118,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
   //Tell the Treeview.how to render the Gnome::Gda::Values:
   if(layout_item_field)
   {
-    pViewColumn->set_cell_data_func(cellrenderer, 
+    pViewColumn->set_cell_data_func(cellrenderer,
       sigc::bind( sigc::mem_fun(*this, &DbAddDel::treeviewcolumn_on_cell_data), model_column_index, data_model_column_index) );
   }
 
@@ -2128,9 +2129,9 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
   //Allow the column to be resized:
   pViewColumn->set_resizable();
   #endif //GLOM_ENABLE_MAEMO
-  
+
   #ifndef GLOM_ENABLE_MAEMO
-  //GtkTreeView's fixed-height-mode does not allow us to have anything but 
+  //GtkTreeView's fixed-height-mode does not allow us to have anything but
   //the last column as expandable.
   //TODO: Can we get the total size and calculate a starting size instead?
   expand = false;
@@ -2159,7 +2160,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
   #else
   if(column_width > 0) //Otherwise there's an assertion fails.
     pViewColumn->set_fixed_width(column_width); //This is the only way to set the width, so we need to set it as resizable again immediately afterwards.
-    
+
   pViewColumn->set_resizable();
   //This property is read only: pViewColumn->property_width() = column_width;
 
@@ -2341,8 +2342,8 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
   std::vector<Gtk::CellRenderer*> cells = column->get_cells();
   Gtk::CellRenderer* renderer = cells[model_column_index];
 #endif
-  
-  //std::cout << "debug: DbAddDel::treeviewcolumn_on_cell_data()" << std::endl; 
+
+  //std::cout << "debug: DbAddDel::treeviewcolumn_on_cell_data()" << std::endl;
 
   if(iter)
   {
@@ -2360,7 +2361,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
       GType debug_type = value.get_value_type();
       std::cout << "debug: " << G_STRFUNC << ": GType=" << debug_type << std::endl;
       if(debug_type)
-         std::cout << "    GType name=\"" << g_type_name(debug_type) << "\"" << std::endl; 
+         std::cout << "    GType name=\"" << g_type_name(debug_type) << "\"" << std::endl;
       */
 
       const Field::glom_field_type type = field->get_glom_type();
@@ -2370,7 +2371,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
         {
           Gtk::CellRendererToggle* pDerived = dynamic_cast<Gtk::CellRendererToggle*>(renderer);
           if(pDerived)
-            pDerived->set_active( (value.get_value_type() == G_TYPE_BOOLEAN) && value.get_boolean() ); 
+            pDerived->set_active( (value.get_value_type() == G_TYPE_BOOLEAN) && value.get_boolean() );
 
           break;
         }
@@ -2380,7 +2381,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
           if(pDerived)
           {
             Glib::RefPtr<Gdk::Pixbuf> pixbuf = Utils::get_pixbuf_for_gda_value(value);
-         
+
             //Scale it down to a sensible size.
             if(pixbuf)
               pixbuf = Utils::image_scale_keeping_ratio(pixbuf,  get_fixed_cell_height(), pixbuf->get_width());
@@ -2407,7 +2408,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
           //Show a different color if the value is numeric, if that's specified:
           if(type == Field::TYPE_NUMERIC)
           {
-             const Glib::ustring fg_color = 
+             const Glib::ustring fg_color =
                field->get_formatting_used().get_text_format_color_foreground_to_use(value);
              if(!fg_color.empty())
                  g_object_set(pDerived->gobj(), "foreground", fg_color.c_str(), (gpointer)0);
@@ -2416,7 +2417,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
           }
 
           break;
-        } 
+        }
       }
     }
   }
@@ -2452,7 +2453,7 @@ bool DbAddDel::get_allow_view_details() const
   return m_allow_view_details;
 }
 
-#ifdef GLOM_ENABLE_CLIENT_ONLY 
+#ifdef GLOM_ENABLE_CLIENT_ONLY
 void DbAddDel::on_self_style_changed(const Glib::RefPtr<Gtk::Style>& /* style */)
 {
   // Reset fixed cell height because the font might have changed due to the new style:
@@ -2500,7 +2501,7 @@ bool DbAddDel::start_new_record()
   Gtk::TreeModel::iterator iter = get_item_placeholder();
   if(!iter)
     return false;
-  
+
   sharedptr<LayoutItem_Field> fieldToEdit;
 
   //Start editing in the primary key or the first cell if the primary key is auto-incremented (because there is no point in editing an auto-generated value)
@@ -2508,7 +2509,7 @@ bool DbAddDel::start_new_record()
   const bool bPresent = true; //get_field_primary_key_index(index_primary_key); //If there is no primary key then the default of 0 is OK.
   if(!bPresent)
     return false;
-   
+
   sharedptr<Field> fieldPrimaryKey = get_key_field();
   if(fieldPrimaryKey && fieldPrimaryKey->get_auto_increment())
   {
@@ -2544,7 +2545,7 @@ bool DbAddDel::start_new_record()
     select_item(iter); //without start_editing.
     //g_warning("start_new_record(): index_field_to_edit does not exist: %d", index_field_to_edit);
   }
-  
+
   return true;
 }
 
@@ -2552,7 +2553,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
 {
   const Gnome::Gda::Value parent_primary_key_value = get_value_key(row);
   //std::cout << "debug: " << G_STRFUNC << ": parent_primary_key_value=" << parent_primary_key_value.to_string() << std::endl;
- 
+
   sharedptr<const LayoutItem_Field> layout_field = get_column_field(col);
 
   if(!Conversions::value_is_empty(parent_primary_key_value)) //If the record's primary key is filled in:
@@ -2646,7 +2647,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
       {
         //Display the same value in other instances of the same field:
         set_value(row, layout_field, field_value, false /* don't set the actually-edited cell */);
-        
+
         signal_record_changed().emit();
       }
     }
@@ -2680,7 +2681,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
     //This record probably doesn't exist yet.
     //Add new record, which will generate the primary key:
     user_added(row);
-    
+
     const Gnome::Gda::Value primaryKeyValue = get_value_key(row); //TODO_Value
     if(!(Conversions::value_is_empty(primaryKeyValue))) //If the Add succeeeded:
     {
@@ -2711,10 +2712,10 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
     dialog.set_secondary_text(_("You attempted to add a new related record, but there can only be one related record, because the relationship uses a unique key.")),
     dialog.set_transient_for(*Application::get_application());
     dialog.run();
-    
+
     return;
   }
-  
+
   //std::cout << "DbAddDel::on_adddel_user_added" << std::endl;
 
   Gnome::Gda::Value primary_key_value;
@@ -2735,14 +2736,14 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
     //This only works when the primary key is already stored: primary_key_value = get_value_key(row);
     //sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
     //layout_item->set_full_field_details(field);
-    
+
     primary_key_value = get_value_key_selected();
   }
 
   //If no primary key value is available yet, then don't add the record yet:
   if(Conversions::value_is_empty(primary_key_value))
     return;
-    
+
   sharedptr<SharedConnection> sharedconnection = connect_to_server(get_application()); //Keep it alive while we need the data_model.
   if(!sharedconnection)
   {
@@ -2751,7 +2752,7 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
     fill_from_database();
     return;
   }
-  
+
 
   sharedptr<LayoutItem_Field> layout_field = sharedptr<LayoutItem_Field>::create();
   layout_field->set_full_field_details(primary_key_field);
@@ -2772,7 +2773,7 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
     handle_error();
     return;
   }
-  
+
   //Save the primary key value for later use:
   set_value_key(row, primary_key_value);
 
@@ -2852,5 +2853,3 @@ Gtk::TreeModel::iterator DbAddDel::get_row_selected()
 }
 
 } //namespace Glom
-
-
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 388a2fc..d453c83 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -80,26 +80,26 @@ public:
 
   virtual void set_allow_add(bool val = true);
   virtual void set_allow_delete(bool val = true);
-    
+
   /** Prevent any attempts by this class to change actual records,
    * if the widget is just being used to enter find critera.
-   * 
+   *
    * @param val True if find mode should be used.
    */
   void set_find_mode(bool val = true);
-    
+
   /** Prevent more than one record from being added,
-   * Use this if the portal is showing related records, 
+   * Use this if the portal is showing related records,
    * and if the relationship's to-field is unique or a primary key.
-   * In this case, adding a new record would require a duplicate value in that 
+   * In this case, adding a new record would require a duplicate value in that
    * unique field.
-   * When the user tries to do this, he will see an explanatory dialog from this 
+   * When the user tries to do this, he will see an explanatory dialog from this
    * widget.
-   * 
+   *
    * @param val True if multiple records  should be presented.
    */
   void set_allow_only_one_related_record(bool val = true);
-    
+
 
   //Gtk::TreeModel::iterator add_item(const Gnome::Gda::Value& valKey); //Return index of new row.
 
@@ -124,8 +124,8 @@ public:
   Gtk::TreeModel::iterator get_item_selected();
   Gtk::TreeModel::iterator get_item_selected() const; //There is no TreeModel::const_iterator
 
-  /** 
-   * @param iter The row to be selected. 
+  /**
+   * @param iter The row to be selected.
    * @param column A value returned from add_column().
    * @param start_editing Whether editing should start in the cell.
    * @result Whether the row was successfully selected.
@@ -135,14 +135,14 @@ public:
 
   guint get_count() const;
 
-  /** 
-   * @param iter The row to be changed. 
+  /**
+   * @param iter The row to be changed.
    * @param layout_item Describes the column(s) whose values should be changed.
    * @param value The new value.
    */
   virtual void set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value);
 
-  /** 
+  /**
    * @param col A value returned from add_column().
    * @param value The new value.
    */
@@ -206,7 +206,7 @@ public:
   void finish_editing(); //Closes active edit controls and commits the data to the cell.
   //virtual void reactivate(); //Sheet doesn't seem to update unless a cell is active.
   void set_prevent_user_signals(bool bVal = true);
-    
+
   //TODO_refactor: make private.
 
   void user_added(const Gtk::TreeModel::iterator& row);
@@ -244,42 +244,42 @@ public:
    */
   typedef sigc::signal<void, const Gtk::TreeModel::iterator&, const Gnome::Gda::Value&> type_signal_record_added;
   type_signal_record_added signal_record_added();
-    
 
-  /** Emitted when the user changed the sort order, 
+
+  /** Emitted when the user changed the sort order,
    * for instance by clicking on a column header.
    */
   typedef sigc::signal<void> type_signal_sort_clause_changed;
   type_signal_sort_clause_changed signal_sort_clause_changed();
 
- 
+
   virtual Gtk::TreeModel::iterator get_last_row();
   virtual Gtk::TreeModel::iterator get_last_row() const;
 
   virtual void set_open_button_title(const Glib::ustring& title);
-  
-  
+
+
   /** Add a new row to the list, for the user to enter record details,
    * adding the generated primary key if necessary.
    */
   bool start_new_record();
 
 private:
-  
+
   void set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value, bool set_specified_field_layout);
-  
+
   //Overrides of Base_DB/Base_DB_Table methods:
   virtual void set_entered_field_data(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
   virtual void set_entered_field_data(const Gtk::TreeModel::iterator& row, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
   virtual Gnome::Gda::Value get_entered_field_data(const sharedptr<const LayoutItem_Field>& field) const;
   virtual Gtk::TreeModel::iterator get_row_selected();
- 
+
   //Implementations of pure virtual methods from Base_DB_Table_Data:
   virtual sharedptr<Field> get_field_primary_key() const;
   virtual Gnome::Gda::Value get_primary_key_value_selected() const;
   virtual void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value);
   virtual Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const;
-      
+
   Gtk::CellRenderer* construct_specified_columns_cellrenderer(const sharedptr<LayoutItem>& layout_item, int model_column_index, int data_model_column_index);
 
   bool get_model_column_index(guint view_column_index, guint& model_column_index);
@@ -288,7 +288,7 @@ private:
   typedef std::list<guint> type_list_indexes;
   ///Return the column indexes of any columns that display this field.
   type_list_indexes get_column_index(const sharedptr<const LayoutItem>& layout_item) const;
-  
+
   /// Get indexes of any columns with choices with !show_all relationships that have @a from_key as the from_key.
   type_list_indexes get_choice_index(const sharedptr<const LayoutItem_Field>& from_key);
 
@@ -359,13 +359,13 @@ private:
   Glib::RefPtr<const Hildon::TouchSelectorColumn> touch_selector_get_column() const;
   #endif
 
-#ifdef GLOM_ENABLE_CLIENT_ONLY 
+#ifdef GLOM_ENABLE_CLIENT_ONLY
   // Don't name it on_style_changed, otherwise we would override a virtual
   // function from Gtk::Widget. We could indeed do that, but we do it with
   // a normal signal handler, because we have to do it this way anyway in
   // case default signal handlers have been disabled in glibmm.
   void on_self_style_changed(const Glib::RefPtr<Gtk::Style>& style);
-#endif //GLOM_ENABLE_CLIENT_ONLY 
+#endif //GLOM_ENABLE_CLIENT_ONLY
 
   bool get_prevent_user_signals() const;
 
@@ -389,7 +389,8 @@ 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 LayoutItem_Field>& layout_choice_second, 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);
@@ -417,7 +418,7 @@ private:
   FoundSet m_found_set; //table, where_clause, sort_clause.
 
   bool m_column_is_sorted; //If empty, then m_column_sorted and m_column_sorted_direction should not be used.
-  bool m_column_sorted_direction; //true means ascending. 
+  bool m_column_sorted_direction; //true means ascending.
   guint m_column_sorted; //Previously-clicked (on the treeview header) column. Remember it so we can reverse the sort order on a second click.
 
 protected:
@@ -442,13 +443,13 @@ private:
   bool m_bIgnoreTreeViewSignals;
 
   type_vec_strings m_vecColumnIDs; //We give each ViewColumn a special ID, so we know where they are after a reorder.
-  
+
 protected:
   bool m_allow_add;
   bool m_allow_delete;
 
 private:
-    
+
   bool m_find_mode;
   bool m_allow_only_one_related_record;
 
@@ -472,7 +473,7 @@ private:
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   type_signal_user_requested_layout m_signal_user_requested_layout;
 #endif // !GLOM_ENABLE_CLIENT_ONLY
-    
+
   //TODO: Do this properly:
   //type_signal_user_added m_signal_record_count_changed;
 
@@ -511,17 +512,17 @@ private:
 
     Gtk::TreeModelColumn<Glib::ustring> m_col_hint;
   };
- 
+
   ModelColumnsEmptyHint m_columns_hint;
   Glib::RefPtr<Gtk::ListStore> m_model_hint;
 
   int m_fixed_cell_height;
-  
+
 private:
-  
+
   /// Discover the right-most text column, so we can make it expand.
   bool get_column_to_expand(guint& column_to_expand) const;
-  
+
   //TODO_refactor: Give these better names, and document them:
   void user_changed(const Gtk::TreeModel::iterator& row, guint col);
   void user_requested_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator&  /* rowEnd TODO */);



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