[glom] Add LayoutItem_WithFormatting as a Field/StaticText common base class.



commit 0b6d1df9f9428e57e14bad7d19a3a046705b90f2
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jan 22 11:48:38 2010 +0100

    Add LayoutItem_WithFormatting as a Field/StaticText common base class.
    
    * glom/libglom/data_structure/layout/layoutitem_withformatting.[h|cc]:
    Added LayoutItem_WithFormatting.
    * glom/libglom/data_structure/layout/layoutitem_text.[h|cc]:
    * glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
    Derive from Layout_WithFormatting, so we can use the base class
    polymorphically, making it easier to support formatting for static text
    items.
    * glom/utility_widgets/layoutwidgetbase.[h|cc]: apply_formatting(),
    * glom/print_layout/canvas_layout_item.[h|cc]: apply_formatting():
    Make this generic for LayoutItem_WithFormatting.

 ChangeLog                                          |   15 ++++
 Makefile_libglom.am                                |    2 +
 .../data_structure/layout/layoutitem_field.cc      |   15 ++--
 .../data_structure/layout/layoutitem_field.h       |   10 +--
 .../data_structure/layout/layoutitem_text.cc       |   17 +---
 .../data_structure/layout/layoutitem_text.h        |    9 +--
 .../layout/layoutitem_withformatting.cc            |   78 ++++++++++++++++++++
 .../layout/layoutitem_withformatting.h             |   64 ++++++++++++++++
 glom/mode_data/flowtablewithfields.cc              |    2 +-
 glom/print_layout/canvas_layout_item.cc            |   25 +++++--
 glom/print_layout/canvas_layout_item.h             |    4 +-
 glom/print_layout/canvas_print_layout.cc           |    2 +-
 glom/utility_widgets/datawidget.cc                 |    2 +-
 glom/utility_widgets/db_adddel/db_adddel.cc        |    6 +-
 glom/utility_widgets/db_adddel/db_adddel.h         |    2 +-
 glom/utility_widgets/layoutwidgetbase.cc           |   13 +++-
 glom/utility_widgets/layoutwidgetbase.h            |    2 +-
 17 files changed, 216 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e8995d1..d778e10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2010-01-22  Murray Cumming  <murrayc murrayc com>
 
+	Add LayoutItem_WithFormatting as a Field/StaticText common base class.
+
+	* glom/libglom/data_structure/layout/layoutitem_withformatting.[h|cc]:
+	Added LayoutItem_WithFormatting.
+	* glom/libglom/data_structure/layout/layoutitem_text.[h|cc]:
+	* glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
+	Derive from Layout_WithFormatting, so we can use the base class 
+	polymorphically, making it easier to support formatting for static text 
+	items.
+	* glom/utility_widgets/layoutwidgetbase.[h|cc]: apply_formatting(),
+	* glom/print_layout/canvas_layout_item.[h|cc]: apply_formatting():
+	Make this generic for LayoutItem_WithFormatting.
+
+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():
diff --git a/Makefile_libglom.am b/Makefile_libglom.am
index a113b3d..4f080a5 100644
--- a/Makefile_libglom.am
+++ b/Makefile_libglom.am
@@ -57,6 +57,7 @@ libglom_ds_layout_include_HEADERS =					\
 	glom/libglom/data_structure/layout/layoutitem_placeholder.h	\
 	glom/libglom/data_structure/layout/layoutitem_portal.h		\
 	glom/libglom/data_structure/layout/layoutitem_text.h		\
+	glom/libglom/data_structure/layout/layoutitem_withformatting.h	\
 	glom/libglom/data_structure/layout/usesrelationship.h
 
 libglom_ds_l_report_parts_includedir = $(libglom_ds_layout_includedir)/report_parts
@@ -127,6 +128,7 @@ glom_libglom_libglom_1_12_la_SOURCES =					\
 	glom/libglom/data_structure/layout/layoutitem_placeholder.cc	\
 	glom/libglom/data_structure/layout/layoutitem_portal.cc		\
 	glom/libglom/data_structure/layout/layoutitem_text.cc		\
+	glom/libglom/data_structure/layout/layoutitem_withformatting.cc		\
 	glom/libglom/data_structure/layout/usesrelationship.cc		\
 	glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc	\
 	glom/libglom/data_structure/layout/report_parts/layoutitem_footer.cc		\
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc b/glom/libglom/data_structure/layout/layoutitem_field.cc
index 762aba7..5f205bc 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -34,12 +34,11 @@ LayoutItem_Field::LayoutItem_Field()
 }
 
 LayoutItem_Field::LayoutItem_Field(const LayoutItem_Field& src)
-: LayoutItem(src),
+: LayoutItem_WithFormatting(src),
   UsesRelationship(src),
   m_priv_view(src.m_priv_view),
   m_priv_edit(src.m_priv_edit),
   //m_table_name(src.m_table_name),
-  m_formatting(src.m_formatting),
   m_field_cache_valid(src.m_field_cache_valid),
   m_hidden(src.m_hidden),
   m_formatting_use_default(src.m_formatting_use_default),
@@ -61,13 +60,12 @@ LayoutItem* LayoutItem_Field::clone() const
 
 bool LayoutItem_Field::operator==(const LayoutItem_Field& src) const
 {
-  bool result = LayoutItem::operator==(src) &&
+  bool result = LayoutItem_WithFormatting::operator==(src) &&
     UsesRelationship::operator==(src) &&
     (m_priv_view == src.m_priv_view) &&
     (m_priv_edit == src.m_priv_edit) &&
     (m_hidden == src.m_hidden) &&
     (m_formatting_use_default == src.m_formatting_use_default) &&
-    (m_formatting == src.m_formatting) &&
     (m_field_cache_valid == src.m_field_cache_valid);
 
   if(m_field && src.m_field)
@@ -86,7 +84,7 @@ bool LayoutItem_Field::operator==(const LayoutItem_Field& src) const
 //Avoid using this, for performance:
 LayoutItem_Field& LayoutItem_Field::operator=(const LayoutItem_Field& src)
 {
-  LayoutItem::operator=(src);
+  LayoutItem_WithFormatting::operator=(src);
   UsesRelationship::operator=(src);
 
   m_field = src.m_field;
@@ -98,7 +96,6 @@ LayoutItem_Field& LayoutItem_Field::operator=(const LayoutItem_Field& src)
   m_hidden = src.m_hidden;
 
   m_formatting_use_default = src.m_formatting_use_default;
-  m_formatting = src.m_formatting;
 
   m_title_custom = src.m_title_custom;
 
@@ -110,12 +107,12 @@ void LayoutItem_Field::set_name(const Glib::ustring& name)
   if(get_name() != name)
     m_field_cache_valid = false;
 
-  LayoutItem::set_name(name);
+  LayoutItem_WithFormatting::set_name(name);
 }
 
 Glib::ustring LayoutItem_Field::get_name() const
 {
-  return LayoutItem::get_name();
+  return LayoutItem_WithFormatting::get_name();
 }
 
 Glib::ustring LayoutItem_Field::get_title_or_name_no_custom() const
@@ -251,7 +248,7 @@ void LayoutItem_Field::set_full_field_details(const sharedptr<const Field>& fiel
     m_field = field;
     m_field_cache_valid = true;
 
-    LayoutItem::set_name(field->get_name()); //It seems to be OK to expect get_name() to work after setting _full_ details.
+    LayoutItem_WithFormatting::set_name(field->get_name()); //It seems to be OK to expect get_name() to work after setting _full_ details.
   }
   else
   {
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h b/glom/libglom/data_structure/layout/layoutitem_field.h
index e66c519..a53ad63 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -21,7 +21,7 @@
 #ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_FIELD_H
 #define GLOM_DATASTRUCTURE_LAYOUTITEM_FIELD_H
 
-#include <libglom/data_structure/layout/layoutitem.h>
+#include <libglom/data_structure/layout/layoutitem_withformatting.h>
 #include <libglom/data_structure/layout/usesrelationship.h>
 #include <libglom/data_structure/field.h>
 #include <libglom/data_structure/numeric_format.h>
@@ -61,7 +61,7 @@ private:
  * UsesRelationship::get_related_relationship() in the base class.
  */
 class LayoutItem_Field 
- : public LayoutItem,
+ : public LayoutItem_WithFormatting,
    public UsesRelationship
 {
 public:
@@ -124,8 +124,6 @@ public:
   bool m_priv_view;
   bool m_priv_edit;
 
-  FieldFormatting m_formatting;
-
   /** Discover whether to use the default formatting for this field, 
    * instead of some custom per-layout-item field formatting.
    */
@@ -139,13 +137,13 @@ public:
   /** Get the field formatting used by this layout item, which 
    * may be either custom field formatting or the default field formatting.
    */
-  const FieldFormatting& get_formatting_used() const;
+  virtual const FieldFormatting& get_formatting_used() const;
 
   /** Get the alignment for the formatting used (see get_formatting_used()),
    * choosing an appropriate alignment if it is set to HORIZONTAL_ALIGNMENT_AUTO.
    * Note that this never returns HORIZONTAL_ALIGNMENT_AUTO.
    */
-  FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment() const;
+  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment() const;
 
   /** Compare the name, relationship, and related_relationship.
    */
diff --git a/glom/libglom/data_structure/layout/layoutitem_text.cc b/glom/libglom/data_structure/layout/layoutitem_text.cc
index 452636c..0b45dbc 100644
--- a/glom/libglom/data_structure/layout/layoutitem_text.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_text.cc
@@ -31,8 +31,7 @@ LayoutItem_Text::LayoutItem_Text()
 }
 
 LayoutItem_Text::LayoutItem_Text(const LayoutItem_Text& src)
-: LayoutItem(src),
-  m_formatting(src.m_formatting)
+: LayoutItem_WithFormatting(src)
 {
   //Copy the underlying TranslatableItem, not the shardptr to it:
   const TranslatableItem& src_item = *(src.m_text);
@@ -50,9 +49,8 @@ LayoutItem* LayoutItem_Text::clone() const
 
 bool LayoutItem_Text::operator==(const LayoutItem_Text& src) const
 {
-  bool result = LayoutItem::operator==(src) && 
-                (*m_text == *(src.m_text)) &&  //TODO: Compare the underlying item, not the smartpointer?
-                (m_formatting == src.m_formatting);
+  bool result = LayoutItem_WithFormatting::operator==(src) && 
+                (*m_text == *(src.m_text)); //TODO: Compare the underlying item, not the smartpointer?
 
   return result;
 }
@@ -60,14 +58,12 @@ bool LayoutItem_Text::operator==(const LayoutItem_Text& src) const
 //Avoid using this, for performance:
 LayoutItem_Text& LayoutItem_Text::operator=(const LayoutItem_Text& src)
 {
-  LayoutItem::operator=(src);
+  LayoutItem_WithFormatting::operator=(src);
 
   //Copy the underlying TranslatableItem, not the shardptr to it:
   const TranslatableItem& src_item = *(src.m_text);
   m_text = sharedptr<TranslatableItem>(new TranslatableItem(src_item));
 
-  m_formatting = src.m_formatting;
-
   return *this;
 }
 
@@ -91,10 +87,5 @@ void LayoutItem_Text::set_text(const Glib::ustring& text)
   m_text->set_title(text);
 }
 
-const FieldFormatting& LayoutItem_Text::get_formatting_used() const
-{
-  return m_formatting;
-}
-
 } //namespace Glom
 
diff --git a/glom/libglom/data_structure/layout/layoutitem_text.h b/glom/libglom/data_structure/layout/layoutitem_text.h
index 926aaf9..94cc35d 100644
--- a/glom/libglom/data_structure/layout/layoutitem_text.h
+++ b/glom/libglom/data_structure/layout/layoutitem_text.h
@@ -21,14 +21,14 @@
 #ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_TEXT_H
 #define GLOM_DATASTRUCTURE_LAYOUTITEM_TEXT_H
 
-#include "layoutitem.h"
+#include "layoutitem_withformatting.h"
 #include "fieldformatting.h"
 
 namespace Glom
 {
 
 class LayoutItem_Text 
- : public LayoutItem
+ : public LayoutItem_WithFormatting
 {
 public:
 
@@ -53,11 +53,6 @@ public:
   void set_text(const Glib::ustring& text);
 
   sharedptr<TranslatableItem> m_text; //Reuse the title concept of this class to give us translatable text.
-
-
-  FieldFormatting m_formatting;
-
-  const FieldFormatting& get_formatting_used() const;
 };
 
 } //namespace Glom
diff --git a/glom/libglom/data_structure/layout/layoutitem_withformatting.cc b/glom/libglom/data_structure/layout/layoutitem_withformatting.cc
new file mode 100644
index 0000000..ee35e18
--- /dev/null
+++ b/glom/libglom/data_structure/layout/layoutitem_withformatting.cc
@@ -0,0 +1,78 @@
+/* Glom
+ *
+ * Copyright (C) 2009 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 "layoutitem_withformatting.h"
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+LayoutItem_WithFormatting::LayoutItem_WithFormatting()
+{
+}
+
+LayoutItem_WithFormatting::LayoutItem_WithFormatting(const LayoutItem_WithFormatting& src)
+: LayoutItem(src),
+  m_formatting(src.m_formatting)
+{
+}
+
+LayoutItem_WithFormatting::~LayoutItem_WithFormatting()
+{
+}
+
+bool LayoutItem_WithFormatting::operator==(const LayoutItem_WithFormatting& src) const
+{
+  bool result = LayoutItem::operator==(src) && 
+                (m_formatting == src.m_formatting);
+
+  return result;
+}
+
+//Avoid using this, for performance:
+LayoutItem_WithFormatting& LayoutItem_WithFormatting::operator=(const LayoutItem_WithFormatting& src)
+{
+  LayoutItem::operator=(src);
+
+  m_formatting = src.m_formatting;
+
+  return *this;
+}
+
+const FieldFormatting& LayoutItem_WithFormatting::get_formatting_used() const
+{
+  return m_formatting;
+}
+
+FieldFormatting::HorizontalAlignment LayoutItem_WithFormatting::get_formatting_used_horizontal_alignment() const
+{
+  const FieldFormatting& format = get_formatting_used();
+  FieldFormatting::HorizontalAlignment alignment = 
+    format.get_horizontal_alignment();
+  
+  if(alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO)
+    alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  
+  return alignment;
+}
+
+
+} //namespace Glom
+
diff --git a/glom/libglom/data_structure/layout/layoutitem_withformatting.h b/glom/libglom/data_structure/layout/layoutitem_withformatting.h
new file mode 100644
index 0000000..e78775a
--- /dev/null
+++ b/glom/libglom/data_structure/layout/layoutitem_withformatting.h
@@ -0,0 +1,64 @@
+/* Glom
+ *
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_WITHFORMATTING_H
+#define GLOM_DATASTRUCTURE_LAYOUTITEM_WITHFORMATTING_H
+
+#include "layoutitem.h"
+#include "fieldformatting.h"
+
+namespace Glom
+{
+
+/** A base class for all layout items that may have formatting options.
+ * See get_formatting_used().
+ */
+class LayoutItem_WithFormatting 
+ : public LayoutItem
+{
+public:
+
+  LayoutItem_WithFormatting();
+  LayoutItem_WithFormatting(const LayoutItem_WithFormatting& src);
+  LayoutItem_WithFormatting& operator=(const LayoutItem_WithFormatting& src);
+  virtual ~LayoutItem_WithFormatting();
+
+  bool operator==(const LayoutItem_WithFormatting& src) const;
+
+  FieldFormatting m_formatting;
+
+  /** Get the field formatting used by this layout item, which 
+   * may be either custom field formatting or the default field formatting.
+   */
+  virtual const FieldFormatting& get_formatting_used() const;
+
+  /** Get the alignment for the formatting used (see get_formatting_used()),
+   * choosing an appropriate alignment if it is set to HORIZONTAL_ALIGNMENT_AUTO.
+   * Note that this never returns HORIZONTAL_ALIGNMENT_AUTO.
+   */
+  virtual FieldFormatting::HorizontalAlignment get_formatting_used_horizontal_alignment() const;
+};
+
+} //namespace Glom
+
+#endif //GLOM_DATASTRUCTURE_LAYOUTITEM_WITHFORMATTING_H
+
+
+
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index a6f43ff..edbff0b 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -615,7 +615,7 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
   label->show();
   alignment_label->add(*label);
   
-  apply_formatting(*label, layoutitem_text->get_formatting_used());
+  apply_formatting(*label, layoutitem_text);
 
   add_layoutwidgetbase(label, add_before);
 
diff --git a/glom/print_layout/canvas_layout_item.cc b/glom/print_layout/canvas_layout_item.cc
index ab7e2cf..972458c 100644
--- a/glom/print_layout/canvas_layout_item.cc
+++ b/glom/print_layout/canvas_layout_item.cc
@@ -74,11 +74,26 @@ sharedptr<LayoutItem> CanvasLayoutItem::get_layout_item()
   return m_layout_item;
 }
 
-void CanvasLayoutItem::check_and_apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, FieldFormatting& formatting)
+void CanvasLayoutItem::apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
 {
   if(!canvas_item)
     return;
 
+  if(!layout_item)
+    return;
+
+  //Horizontal alignment:
+  const FieldFormatting::HorizontalAlignment alignment =
+    layout_item->get_formatting_used_horizontal_alignment();
+  const Pango::Alignment x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? Pango::ALIGN_LEFT : Pango::ALIGN_RIGHT);
+#ifdef GLIBMM_PROPERTIES_ENABLED  
+  //TODO: property_alignment() = x_align;
+#else    
+  //TODO: set_property("alignment", alignment);
+#endif
+
+  const FieldFormatting& formatting = layout_item->get_formatting_used();
+
   Glib::ustring font = formatting.get_text_format_font();
   if(font.empty())
   {
@@ -86,7 +101,7 @@ void CanvasLayoutItem::check_and_apply_formatting(const Glib::RefPtr<CanvasTextM
 
     //Set it in the input parameter,
     //so that this is the default:
-    formatting.set_text_format_font(font);    
+    //TODO? formatting.set_text_format_font(font);    
   }
 
   canvas_item->set_font_points(font);
@@ -200,8 +215,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
     canvas_item->set_property("line-width", 0);
     #endif
 
-    FieldFormatting& formatting = text->m_formatting;
-    check_and_apply_formatting(canvas_item, formatting);
+    apply_formatting(canvas_item, text);
 
     canvas_item->set_text(text->get_text());
     child = canvas_item;
@@ -282,8 +296,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
             canvas_item->set_property("line-width", 0);
             #endif
          
-            FieldFormatting& formatting = field->m_formatting;
-            check_and_apply_formatting(canvas_item, formatting);
+            apply_formatting(canvas_item, field);
 
             Glib::ustring name = field->get_name();
             if(name.empty())
diff --git a/glom/print_layout/canvas_layout_item.h b/glom/print_layout/canvas_layout_item.h
index 7fe8a52..47cc4ad 100644
--- a/glom/print_layout/canvas_layout_item.h
+++ b/glom/print_layout/canvas_layout_item.h
@@ -22,7 +22,7 @@
 #define GLOM_MODE_DESIGN_PRINT_LAYOUTS_CANVAS_LAYOUT_ITEM_H
 
 #include <glom/utility_widgets/canvas/canvas_group_resizable.h>
-#include <libglom/data_structure/layout/layoutitem.h>
+#include <libglom/data_structure/layout/layoutitem_withformatting.h>
 #include <libgdamm/value.h>
 
 namespace Glom
@@ -67,7 +67,7 @@ private:
   /// Create the appropriate inner canvas item to represent the layout item.
   static Glib::RefPtr<CanvasItemMovable> create_canvas_item_for_layout_item(const sharedptr<LayoutItem>& layout_item);
 
-  static void check_and_apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, FieldFormatting& formatting);
+  static void apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const sharedptr<const LayoutItem_WithFormatting>& layout_item);
   
   void on_resized();
 
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index ceeca6c..f5353cd 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -842,7 +842,7 @@ void Canvas_PrintLayout::set_canvas_item_field_value(const Glib::RefPtr<Goocanva
     }
 
     //FieldFormatting& formatting = field->m_formatting;
-    //check_and_apply_formatting(canvas_item, formatting);
+    //apply_formatting(canvas_item, formatting);
     const Glib::ustring text = 
       Conversions::get_text_for_gda_value(field->get_glom_type(), value, field->m_formatting.m_numeric_format);
     canvas_text->set_text(text);
diff --git a/glom/utility_widgets/datawidget.cc b/glom/utility_widgets/datawidget.cc
index e416187..6674974 100644
--- a/glom/utility_widgets/datawidget.cc
+++ b/glom/utility_widgets/datawidget.cc
@@ -200,7 +200,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
   if(m_child)
   {
     //Use the text formatting:
-    apply_formatting(*m_child, field->get_formatting_used());
+    apply_formatting(*m_child, field);
     
     bool child_added = false; //Don't use an extra container unless necessary.
 
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index d8665c6..1480871 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -916,7 +916,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
   return pCellRenderer;
 }
 
-void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<LayoutItem_Field>& item_field)
+void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
 {
   Gtk::CellRendererText* text_renderer = dynamic_cast<Gtk::CellRendererText*>(renderer);
   if(!text_renderer)
@@ -926,7 +926,7 @@ void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<Lay
 
   //Horizontal alignment:
   const FieldFormatting::HorizontalAlignment alignment =
-    item_field->get_formatting_used_horizontal_alignment();
+    layout_item->get_formatting_used_horizontal_alignment();
   const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
 #ifdef GLIBMM_PROPERTIES_ENABLED  
       text_renderer->property_xalign() = x_align;
@@ -934,7 +934,7 @@ void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<Lay
       text_renderer->set_property("xalign", alignment);
 #endif
 
-  const FieldFormatting& formatting = item_field->get_formatting_used();
+  const FieldFormatting& formatting = layout_item->get_formatting_used();
 
   const Glib::ustring font_desc = formatting.get_text_format_font();
   if(!font_desc.empty())
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 78eeb4f..2340668 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -383,7 +383,7 @@ private:
   //TODO: Remove this and use AppGlom::get_application() instead?
   App_Glom* get_application();
 
-  static void apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<LayoutItem_Field>& item_field);
+  static void apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<const LayoutItem_WithFormatting>& layout_item);
 
   typedef Gtk::VBox type_base;
 
diff --git a/glom/utility_widgets/layoutwidgetbase.cc b/glom/utility_widgets/layoutwidgetbase.cc
index 593a8cb..a6ba905 100644
--- a/glom/utility_widgets/layoutwidgetbase.cc
+++ b/glom/utility_widgets/layoutwidgetbase.cc
@@ -84,8 +84,19 @@ void LayoutWidgetBase::set_read_only(bool /* read_only */)
 {
 }
 
-void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const FieldFormatting& formatting)
+void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
 {
+  //Horizontal alignment:
+  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);
+  if(misc)
+    misc->set_alignment(x_align);
+
+
+  const FieldFormatting& formatting = layout_item->get_formatting_used();
+
   //Use the text formatting:
   const Glib::ustring font_desc = formatting.get_text_format_font();
   if(!font_desc.empty())
diff --git a/glom/utility_widgets/layoutwidgetbase.h b/glom/utility_widgets/layoutwidgetbase.h
index 8ade99a..64858eb 100644
--- a/glom/utility_widgets/layoutwidgetbase.h
+++ b/glom/utility_widgets/layoutwidgetbase.h
@@ -87,7 +87,7 @@ protected:
   virtual App_Glom* get_application() const; // = 0;
 
 
-  static void apply_formatting(Gtk::Widget& widget, const FieldFormatting& formatting);
+  static void apply_formatting(Gtk::Widget& widget, const sharedptr<const LayoutItem_WithFormatting>& layout_item);
 
 protected: //TODO: Add accessor?
   sharedptr<LayoutItem> m_pLayoutItem;



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