[glom] Really use formatting for multi-line fields.



commit 4f1bd97d7cea10459672b0dfa12aedc169a88706
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jan 22 17:12:06 2010 +0100

    Really use formatting for multi-line fields.
    
    * glom/utility_widgets/textviewglom.[h|cc]: Added get_textview().
    * glom/utility_widgets/layoutwidgetbase.cc: apply_formatting():
    Get the appropriate child for buttons and textviews, making this work
    for textviews (multi line fields), but it still does not work for
    labels (static text items) and buttons.

 ChangeLog                                |   10 ++++++++++
 glom/utility_widgets/layoutwidgetbase.cc |   22 ++++++++++++++++++----
 glom/utility_widgets/textviewglom.cc     |    5 +++++
 glom/utility_widgets/textviewglom.h      |   14 +++++++++-----
 4 files changed, 42 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fda6fe5..5e6337a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-01-22  Murray Cumming  <murrayc murrayc com>
+
+	Really use formatting for multi-line fields.
+
+	* glom/utility_widgets/textviewglom.[h|cc]: Added get_textview().
+	* glom/utility_widgets/layoutwidgetbase.cc: apply_formatting(): 
+	Get the appropriate child for buttons and textviews, making this work 
+	for textviews (multi line fields), but it still does not work for 
+	labels (static text items) and buttons.
+
 2010-01-22  Murray Cumming  <murrayc murrayc com>>
 
 	Allow custom text formatting of Buttons as well as text items and fields.
diff --git a/glom/utility_widgets/layoutwidgetbase.cc b/glom/utility_widgets/layoutwidgetbase.cc
index 491d90b..1a3bf41 100644
--- a/glom/utility_widgets/layoutwidgetbase.cc
+++ b/glom/utility_widgets/layoutwidgetbase.cc
@@ -21,6 +21,7 @@
 #include "layoutwidgetbase.h"
 #include <glibmm/i18n.h>
 #include <glom/application.h>
+#include <glom/utility_widgets/textviewglom.h>
 
 namespace Glom
 {
@@ -86,6 +87,17 @@ void LayoutWidgetBase::set_read_only(bool /* read_only */)
 
 void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
 {
+  Gtk::Widget* widget_to_change = &widget;
+
+  Gtk::Button* button = dynamic_cast<Gtk::Button*>(&widget);
+  if(button)
+    widget_to_change = button->get_child();
+
+  Glom::TextViewGlom* textview = dynamic_cast<Glom::TextViewGlom*>(&widget);
+  if(textview)
+    widget_to_change = textview->get_textview();
+
+
   if(!layout_item)
     return;
 
@@ -93,7 +105,7 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
   const FieldFormatting::HorizontalAlignment alignment =
     layout_item->get_formatting_used_horizontal_alignment();
   const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
-  Gtk::Misc* misc = dynamic_cast<Gtk::Misc*>(&widget);
+  Gtk::Misc* misc = dynamic_cast<Gtk::Misc*>(widget_to_change);
   if(misc)
     misc->set_alignment(x_align);
 
@@ -103,17 +115,19 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
   //Use the text formatting:
   const Glib::ustring font_desc = formatting.get_text_format_font();
   if(!font_desc.empty())
-    widget.modify_font( Pango::FontDescription(font_desc) );
+  {
+    widget_to_change->modify_font( Pango::FontDescription(font_desc) );
+  }
 
   // "text" is the text color. "fg" doesn't seem to have any effect:
   const Glib::ustring fg = formatting.get_text_format_color_foreground();
   if(!fg.empty())
-    widget.modify_text(Gtk::STATE_NORMAL, Gdk::Color(fg));
+    widget_to_change->modify_text(Gtk::STATE_NORMAL, Gdk::Color(fg));
 
   // "base" is the background color. "bg" seems to change the border:
   const Glib::ustring bg = formatting.get_text_format_color_background();
   if(!bg.empty())
-    widget.modify_base(Gtk::STATE_NORMAL, Gdk::Color(bg));
+    widget_to_change->modify_base(Gtk::STATE_NORMAL, Gdk::Color(bg));
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/utility_widgets/textviewglom.cc b/glom/utility_widgets/textviewglom.cc
index 0ef6815..d8c80d3 100644
--- a/glom/utility_widgets/textviewglom.cc
+++ b/glom/utility_widgets/textviewglom.cc
@@ -219,4 +219,9 @@ App_Glom* TextViewGlom::get_application()
   return dynamic_cast<App_Glom*>(pWindow);
 }
 
+TextViewGlom::type_text_view* TextViewGlom::get_textview()
+{
+  return &m_TextView;
+}
+
 } //namespace Glom
diff --git a/glom/utility_widgets/textviewglom.h b/glom/utility_widgets/textviewglom.h
index ccd0371..acc3b31 100644
--- a/glom/utility_widgets/textviewglom.h
+++ b/glom/utility_widgets/textviewglom.h
@@ -58,6 +58,14 @@ public:
 
   virtual Gnome::Gda::Value get_value() const;
 
+#ifdef GLOM_ENABLE_MAEMO
+  typedef Hildon::TextView type_text_view;
+#else
+  typedef Gtk::TextView type_text_view;
+#endif
+  
+  type_text_view* get_textview();
+
 private:
   void init();
 
@@ -80,11 +88,7 @@ private:
 
   //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
 
-#ifdef GLOM_ENABLE_MAEMO
-  Hildon::TextView m_TextView;
-#else
-  Gtk::TextView m_TextView;
-#endif
+  type_text_view m_TextView;
 };
 
 } //namespace Glom



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