[glom] Show the alternative colors for negatives in fields with choices too.



commit 2ac3b320cab9f2d70c49ef89118528d8accfe67e
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jan 22 10:14:39 2010 +0100

    Show the alternative colors for negatives in fields with choices too.
    
    * glom/utility_widgets/comboentryglom.cc: set_value():
    * glom/utility_widgets/comboglom.cc: set_value(): Use the alternative
    negative color feature here too.

 ChangeLog                              |    8 ++++++++
 glom/utility_widgets/comboentryglom.cc |   21 ++++++++++++++++++---
 glom/utility_widgets/comboglom.cc      |   28 ++++++++++++++++++++++++++--
 glom/utility_widgets/entryglom.cc      |   28 +++++++++++++---------------
 4 files changed, 65 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 358a1e4..e8995d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-01-22  Murray Cumming  <murrayc murrayc com>
+
+	Show the alternative colors for negatives in fields with choices too.
+
+	* glom/utility_widgets/comboentryglom.cc: set_value():
+	* glom/utility_widgets/comboglom.cc: set_value(): Use the alternative 
+	negative color feature here too.
+
 2010-01-21  Murray Cumming  <murrayc murrayc com>
 
 	Field Formatting: Text Formatting: Add horizontal alignment option.
diff --git a/glom/utility_widgets/comboentryglom.cc b/glom/utility_widgets/comboentryglom.cc
index 7ada3d0..de931f9 100644
--- a/glom/utility_widgets/comboentryglom.cc
+++ b/glom/utility_widgets/comboentryglom.cc
@@ -249,10 +249,25 @@ void ComboEntryGlom::on_entry_changed()
 
 void ComboEntryGlom::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)
+  sharedptr<const LayoutItem_Field> layout_item = sharedptr<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:
+  if(layout_item->get_glom_type() == Field::TYPE_NUMERIC)
   {
-    set_text(Conversions::get_text_for_gda_value(layout_item->get_glom_type(), value, layout_item->get_formatting_used().m_numeric_format));
+    Gtk::Entry* entry = get_entry();
+    if(!entry)
+      return;
+
+    const Glib::ustring fg_color = 
+    layout_item->get_formatting_used().get_text_format_color_foreground_to_use(value);
+    if(!fg_color.empty())
+      entry->modify_text(Gtk::STATE_NORMAL, Gdk::Color(fg_color));
+    else
+      entry->modify_text(Gtk::STATE_NORMAL, Gdk::Color());
   }
 }
 
diff --git a/glom/utility_widgets/comboglom.cc b/glom/utility_widgets/comboglom.cc
index 4270d50..8350759 100644
--- a/glom/utility_widgets/comboglom.cc
+++ b/glom/utility_widgets/comboglom.cc
@@ -149,8 +149,32 @@ void ComboGlom::check_for_change()
 void ComboGlom::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)
-    set_text(Conversions::get_text_for_gda_value(layout_item->get_glom_type(), value, layout_item->get_formatting_used().m_numeric_format));
+  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:
+  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;
+  }
 }
 
 void ComboGlom::set_text(const Glib::ustring& text)
diff --git a/glom/utility_widgets/entryglom.cc b/glom/utility_widgets/entryglom.cc
index 7faf354..ee2594a 100644
--- a/glom/utility_widgets/entryglom.cc
+++ b/glom/utility_widgets/entryglom.cc
@@ -172,23 +172,21 @@ void EntryGlom::on_changed()
 void EntryGlom::set_value(const Gnome::Gda::Value& value)
 {
   sharedptr<const LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
-  if(layout_item)
-  {
-    const Glib::ustring text = Conversions::get_text_for_gda_value(m_glom_type, value, layout_item->get_formatting_used().m_numeric_format);
-    set_text(text);
+  if(!layout_item)
+    return;
 
-    //Show a different color if the value is numeric, if that's specified:
-    if(layout_item->get_glom_type() == Field::TYPE_NUMERIC)
-    {
-      const Glib::ustring fg_color = 
-      layout_item->get_formatting_used().get_text_format_color_foreground_to_use(value);
-      if(!fg_color.empty())
-        modify_text(Gtk::STATE_NORMAL, Gdk::Color(fg_color));
-      else
-        modify_text(Gtk::STATE_NORMAL, Gdk::Color());
-    }
+  const Glib::ustring text = Conversions::get_text_for_gda_value(m_glom_type, value, layout_item->get_formatting_used().m_numeric_format);
+  set_text(text);
 
-    //std::cout << "debug: EntryGlom::set_value(): name=" << layout_item->get_name() << ", text=" << text << std::endl;
+  //Show a different color if the value is numeric, if that's specified:
+  if(layout_item->get_glom_type() == Field::TYPE_NUMERIC)
+  {
+    const Glib::ustring fg_color = 
+    layout_item->get_formatting_used().get_text_format_color_foreground_to_use(value);
+    if(!fg_color.empty())
+      modify_text(Gtk::STATE_NORMAL, Gdk::Color(fg_color));
+    else
+      modify_text(Gtk::STATE_NORMAL, Gdk::Color());
   }
 }
 



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