[glom] Field Formatting: Text Formatting: Add horizontal alignment option.



commit 16240b149706c929452f97af02ffa17ee93a49e7
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jan 21 17:58:01 2010 +0100

    Field Formatting: Text Formatting: Add horizontal alignment option.
    
    * glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
    Added get/set_horizontal_alignment().
    * glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
    Added get_formatting_used_horizontal_alignment() to interpret the
    AUTO alignment depending on the fields details.
    * glom/libglom/document/document.cc:
    load_after_layout_item_formatting(), save_before_layout_item_formatting():
    load/save the new setting.
    
    * glom/glom_developer.glade: window_formatting: Added the alignment combo.
    * glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
    Show/Save the alignment.
    * glom/utility_widgets/db_adddel/db_adddel.cc: apply_formatting():
    * glom/utility_widgets/entryglom.cc: init():
    * glom/utility_widgets/comboentryglom.cc: set_layout_item():
    Set xalign from get_formatting_used_horizontal_alignment().

 ChangeLog                                          |   21 ++++++++++
 glom/glom_developer.glade                          |   40 ++++++++++++++++--
 .../data_structure/layout/fieldformatting.cc       |   18 +++++++-
 .../data_structure/layout/fieldformatting.h        |   11 +++++
 .../data_structure/layout/layoutitem_field.cc      |   22 ++++++++++
 .../data_structure/layout/layoutitem_field.h       |    6 +++
 glom/libglom/document/document.cc                  |   23 +++++++++++
 .../layout/layout_item_dialogs/box_formatting.cc   |   42 +++++++++++++++++++-
 .../layout/layout_item_dialogs/box_formatting.h    |   15 +++++++
 glom/print_layout/canvas_layout_item.cc            |    2 +
 glom/utility_widgets/comboentryglom.cc             |   17 ++++++--
 glom/utility_widgets/db_adddel/db_adddel.cc        |   22 +++++++---
 glom/utility_widgets/db_adddel/db_adddel.h         |    2 +-
 glom/utility_widgets/entryglom.cc                  |   16 ++++++--
 14 files changed, 233 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cd56004..358a1e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2010-01-21  Murray Cumming  <murrayc murrayc com>
+
+	Field Formatting: Text Formatting: Add horizontal alignment option.
+
+	* glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
+	Added get/set_horizontal_alignment().
+	* glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
+	Added get_formatting_used_horizontal_alignment() to interpret the 
+	AUTO alignment depending on the fields details.
+	* glom/libglom/document/document.cc: 
+	load_after_layout_item_formatting(), save_before_layout_item_formatting():
+	load/save the new setting.
+
+	* glom/glom_developer.glade: window_formatting: Added the alignment combo.
+	* glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
+	Show/Save the alignment.
+	* glom/utility_widgets/db_adddel/db_adddel.cc: apply_formatting():
+	* glom/utility_widgets/entryglom.cc: set_layout_item():
+	* glom/utility_widgets/comboentryglom.cc: set_layout_item():
+	Set xalign from get_formatting_used_horizontal_alignment().
+
 2010-01-16  Murray Cumming  <murrayc murrayc com>
 
 	Field Formatting: Negative values color: Make this just a bool check box.
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index 6551852..cfe5ada 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -6427,6 +6427,36 @@ Which user should be added to this group?</property>
                 <property name="border_width">6</property>
                 <property name="spacing">6</property>
                 <child>
+                  <object class="GtkHBox" id="hbox_">
+                    <property name="visible">True</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="label_format_text_horizontal_alignment">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Horizontal Alignment:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBox" id="combo_format_text_horizontal_alignment">
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkCheckButton" id="checkbutton_format_text_multiline">
                     <property name="label" translatable="yes">Multi-line</property>
                     <property name="visible">True</property>
@@ -6439,7 +6469,7 @@ Which user should be added to this group?</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">0</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
@@ -6473,7 +6503,7 @@ Which user should be added to this group?</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">1</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
                 <child>
@@ -6511,7 +6541,7 @@ Which user should be added to this group?</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">2</property>
+                    <property name="position">3</property>
                   </packing>
                 </child>
                 <child>
@@ -6549,7 +6579,7 @@ Which user should be added to this group?</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">3</property>
+                    <property name="position">4</property>
                   </packing>
                 </child>
                 <child>
@@ -6587,7 +6617,7 @@ Which user should be added to this group?</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">4</property>
+                    <property name="position">5</property>
                   </packing>
                 </child>
               </object>
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index 2c12a7f..a4ec106 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -32,7 +32,8 @@ FieldFormatting::FieldFormatting()
   m_choices_custom(false),
   m_choices_related(false),
   m_text_format_multiline(false),
-  m_text_multiline_height_lines(MULTILINE_TEXT_DEFAULT_HEIGHT_LINES)
+  m_text_multiline_height_lines(MULTILINE_TEXT_DEFAULT_HEIGHT_LINES),
+  m_horizontal_alignment(HORIZONTAL_ALIGNMENT_AUTO)
 {
 }
 
@@ -48,6 +49,7 @@ FieldFormatting::FieldFormatting(const FieldFormatting& src)
   m_text_font(src.m_text_font),
   m_text_color_foreground(src.m_text_color_foreground),
   m_text_color_background(src.m_text_color_background),
+  m_horizontal_alignment(src.m_horizontal_alignment),
   m_choices_related_field(src.m_choices_related_field),
   m_choices_related_field_second(src.m_choices_related_field_second)
 {
@@ -71,7 +73,8 @@ bool FieldFormatting::operator==(const FieldFormatting& src) const
     (m_text_multiline_height_lines == src.m_text_multiline_height_lines) &&
     (m_text_font == src.m_text_font) &&
     (m_text_color_foreground == src.m_text_color_foreground) &&
-    (m_text_color_background == src.m_text_color_background);
+    (m_text_color_background == src.m_text_color_background) && 
+    (m_horizontal_alignment == src.m_horizontal_alignment);
 }
 
 
@@ -93,6 +96,7 @@ FieldFormatting& FieldFormatting::operator=(const FieldFormatting& src)
   m_text_font = src.m_text_font;
   m_text_color_foreground = src.m_text_color_foreground;
   m_text_color_background = src.m_text_color_background;
+  m_horizontal_alignment = src.m_horizontal_alignment;
 
 //g_warning("FieldFormatting::operator=: m_choices_related_relationship=%s, src.m_choices_related_relationship=%s", m_choices_related_relationship->c_str(), src.m_choices_related_relationship->c_str());
   return *this;
@@ -164,6 +168,16 @@ Glib::ustring FieldFormatting::get_text_format_color_background() const
   return m_text_color_background;
 }
 
+void FieldFormatting::set_horizontal_alignment(HorizontalAlignment alignment)
+{
+  m_horizontal_alignment = alignment;
+}
+
+FieldFormatting::HorizontalAlignment FieldFormatting::get_horizontal_alignment() const
+{
+  return m_horizontal_alignment;
+}
+
 bool FieldFormatting::get_has_choices() const
 {
   return ( m_choices_related && get_has_relationship_name() && !m_choices_related_field.empty() ) ||
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index 373e507..a63585e 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -94,6 +94,16 @@ public:
   void set_text_format_color_background(const Glib::ustring& color);
   Glib::ustring get_text_format_color_background() const;
 
+  enum HorizontalAlignment
+  {
+    HORIZONTAL_ALIGNMENT_AUTO, //For instance, RIGHT for numeric fields.
+    HORIZONTAL_ALIGNMENT_LEFT,
+    HORIZONTAL_ALIGNMENT_RIGHT,
+  };
+
+  void set_horizontal_alignment(HorizontalAlignment alignment);
+  HorizontalAlignment get_horizontal_alignment() const;
+
   void change_field_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
 
   NumericFormat m_numeric_format; //Only used for numeric fields.
@@ -109,6 +119,7 @@ private:
   //Glib::ustring m_text_multiline_width_example; //An example string from which to calculate the width.
   Glib::ustring m_text_font;
   Glib::ustring m_text_color_foreground, m_text_color_background;
+  HorizontalAlignment m_horizontal_alignment;
 
   Glib::ustring m_choices_related_field, m_choices_related_field_second;
 };
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc b/glom/libglom/data_structure/layout/layoutitem_field.cc
index 4666cb6..762aba7 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -219,6 +219,28 @@ const FieldFormatting& LayoutItem_Field::get_formatting_used() const
     return m_formatting;
 }
 
+FieldFormatting::HorizontalAlignment LayoutItem_Field::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)
+  {
+    //By default, right-align numbers unless they are ID fields:
+    if(m_field && !m_field->get_primary_key()) //TODO: Also prevent this when it is a foreign key.
+    {
+      //Align numbers to the right by default:
+      alignment == Field::TYPE_NUMERIC ? FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT : FieldFormatting::HORIZONTAL_ALIGNMENT_RIGHT;
+    }
+    else
+      alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  }
+  
+  return alignment;
+}
+
+
 void LayoutItem_Field::set_full_field_details(const sharedptr<const Field>& field)
 {
 
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h b/glom/libglom/data_structure/layout/layoutitem_field.h
index 39fb6aa..e66c519 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -141,6 +141,12 @@ public:
    */
   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;
+
   /** Compare the name, relationship, and related_relationship.
    */
   bool is_same_field(const sharedptr<const LayoutItem_Field>& field) const;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 3d495c2..d349bf9 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -183,6 +183,11 @@ namespace Glom
 #define GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_FOREGROUND "color_fg"
 #define GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_BACKGROUND "color_bg"
 
+#define GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT "alignment_horizontal"
+#define GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_AUTO "auto"
+#define GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_LEFT "left"
+#define GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_RIGHT "right"
+
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_RESTRICTED "choices_restricted"
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_CUSTOM "choices_custom"
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_CUSTOM_LIST "custom_choice_list"
@@ -1900,6 +1905,15 @@ void Document::load_after_layout_item_formatting(const xmlpp::Element* element,
   format.set_text_format_color_foreground( get_node_attribute_value (element, GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_FOREGROUND) );
   format.set_text_format_color_background( get_node_attribute_value (element, GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_BACKGROUND) );
 
+  //Alignment. Not-specified means auto.
+  FieldFormatting::HorizontalAlignment alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO;
+  const Glib::ustring alignment_str = get_node_attribute_value (element, GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT);
+  if(alignment_str == GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_LEFT)
+    alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  else if(alignment_str == GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_RIGHT)
+    alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_RIGHT;
+
+  format.set_horizontal_alignment(alignment);
 
   //Choices:
   if(!field_name.empty())
@@ -2895,6 +2909,15 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
   set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_FOREGROUND, format.get_text_format_color_foreground());
   set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_TEXT_COLOR_BACKGROUND, format.get_text_format_color_background());
 
+  //Alignment:
+  const FieldFormatting::HorizontalAlignment alignment = format.get_horizontal_alignment();
+  if(alignment != FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO) //Save file-size by not even writing this.
+  {
+    const Glib::ustring alignment_str = 
+      (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT  ? GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_LEFT : GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT_RIGHT);
+    set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_HORIZONTAL_ALIGNMENT, alignment_str);
+  }
+
   //Choices:
   if(field_type != Field::TYPE_INVALID)
   {
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 846be55..38d3bf5 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -34,6 +34,7 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_entry_currency_symbol(0),
   m_checkbox_format_color_negatives(0),
   m_vbox_text_format(0),
+  m_combo_format_text_horizontal_alignment(0),
   m_checkbox_format_text_multiline(0),
   m_label_format_text_multiline_height(0),
   m_spinbutton_format_text_multiline_height(0),
@@ -64,6 +65,7 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
 
   //Text formatting:
   builder->get_widget("vbox_text_format", m_vbox_text_format);
+  builder->get_widget("combo_format_text_horizontal_alignment", m_combo_format_text_horizontal_alignment);
   builder->get_widget("checkbutton_format_text_multiline", m_checkbox_format_text_multiline);
   builder->get_widget("label_format_text_multiline", m_label_format_text_multiline_height);
   builder->get_widget("spinbutton_format_text_multiline_height", m_spinbutton_format_text_multiline_height);
@@ -77,7 +79,25 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   builder->get_widget("colorbutton_background", m_colorbutton_background);
   builder->get_widget("checkbutton_color_background", m_checkbox_format_text_color_background);
 
-
+  //Fill the alignment combo:
+  m_model_alignment = Gtk::ListStore::create(m_columns_alignment);
+
+  Gtk::TreeModel::iterator iter = m_model_alignment->append();
+  (*iter)[m_columns_alignment.m_col_alignment] = FieldFormatting::HORIZONTAL_ALIGNMENT_AUTO;
+  //Translators: This is Automatic text alignment.
+  (*iter)[m_columns_alignment.m_col_title] = _("Automatic");
+  iter = m_model_alignment->append();
+  (*iter)[m_columns_alignment.m_col_alignment] = FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  //Translators: This is Left text alignment.
+  (*iter)[m_columns_alignment.m_col_title] = _("Left");
+  iter = m_model_alignment->append();
+  (*iter)[m_columns_alignment.m_col_alignment] = FieldFormatting::HORIZONTAL_ALIGNMENT_RIGHT;
+  //Translators: This is Right text alignment.
+  (*iter)[m_columns_alignment.m_col_title] = _("Right");
+
+  m_combo_format_text_horizontal_alignment->set_model(m_model_alignment);
+  m_combo_format_text_horizontal_alignment->pack_start(m_columns_alignment.m_col_title);
+  
 
   //Choices:
   builder->get_widget("vbox_choices", m_vbox_choices);
@@ -141,6 +161,7 @@ void Box_Formatting::set_formatting(const FieldFormatting& format)
 {
   m_format = format;
 
+  //Numeric formatting:
   m_checkbox_format_use_thousands->set_active( format.m_numeric_format.m_use_thousands_separator );
   m_checkbox_format_use_decimal_places->set_active( format.m_numeric_format.m_decimal_places_restricted );
 
@@ -153,6 +174,19 @@ void Box_Formatting::set_formatting(const FieldFormatting& format)
   m_checkbox_format_color_negatives->set_active(
     format.m_numeric_format.m_alt_foreground_color_for_negatives );
 
+  //Text formatting
+  const FieldFormatting::HorizontalAlignment alignment = 
+    format.get_horizontal_alignment();
+  Gtk::TreeModel::Children children = m_model_alignment->children(); 
+  for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter)
+  {
+    Gtk::TreeModel::Row row = *iter;
+    if(row[m_columns_alignment.m_col_alignment] == alignment)
+    {
+      m_combo_format_text_horizontal_alignment->set_active(iter);
+      break;
+    }
+  }
 
   m_checkbox_format_text_multiline->set_active(format.get_text_format_multiline());
 
@@ -224,6 +258,12 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
     m_checkbox_format_color_negatives->get_active();
 
   //Text formatting:
+  Gtk::TreeModel::iterator iter = m_combo_format_text_horizontal_alignment->get_active();
+  FieldFormatting::HorizontalAlignment alignment = FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  if(iter)
+    alignment = (*iter)[m_columns_alignment.m_col_alignment];
+  m_format.set_horizontal_alignment(alignment);
+
   m_format.set_text_format_multiline(m_checkbox_format_text_multiline->get_active());
   m_format.set_text_format_multiline_height_lines( m_spinbutton_format_text_multiline_height->get_value_as_int() );
 
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index 3f3955f..090da52 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -72,6 +72,7 @@ private:
   Gtk::CheckButton* m_checkbox_format_color_negatives;
 
   Gtk::VBox* m_vbox_text_format;
+  Gtk::ComboBox* m_combo_format_text_horizontal_alignment;
   Gtk::CheckButton* m_checkbox_format_text_multiline;
   Gtk::Label* m_label_format_text_multiline_height;
   Gtk::SpinButton* m_spinbutton_format_text_multiline_height;
@@ -103,6 +104,20 @@ private:
   //We show different options when 
   //showing this on a print layout.
   bool m_for_print_layout;
+
+
+  class AlignmentColumns: public Gtk::TreeModelColumnRecord
+  {
+  public:
+    AlignmentColumns()
+    { add(m_col_alignment); add(m_col_title); }
+
+    Gtk::TreeModelColumn<FieldFormatting::HorizontalAlignment> m_col_alignment;
+    Gtk::TreeModelColumn<Glib::ustring> m_col_title;
+  };
+
+  AlignmentColumns m_columns_alignment;
+  Glib::RefPtr<Gtk::ListStore> m_model_alignment;
 };
 
 } //namespace Glom
diff --git a/glom/print_layout/canvas_layout_item.cc b/glom/print_layout/canvas_layout_item.cc
index e8d35f8..ab7e2cf 100644
--- a/glom/print_layout/canvas_layout_item.cc
+++ b/glom/print_layout/canvas_layout_item.cc
@@ -91,6 +91,8 @@ void CanvasLayoutItem::check_and_apply_formatting(const Glib::RefPtr<CanvasTextM
 
   canvas_item->set_font_points(font);
 
+  //TODO: Handle horizontal alignment.
+
   //TODO: Are these sensible properties? Maybe we need to use markup:
   //TODO: Use the negative color.
   const Glib::ustring fg = formatting.get_text_format_color_foreground();
diff --git a/glom/utility_widgets/comboentryglom.cc b/glom/utility_widgets/comboentryglom.cc
index 99d2d53..7ada3d0 100644
--- a/glom/utility_widgets/comboentryglom.cc
+++ b/glom/utility_widgets/comboentryglom.cc
@@ -156,10 +156,19 @@ void ComboEntryGlom::set_layout_item(const sharedptr<LayoutItem>& layout_item, c
   //Call base class:
   ComboGlomChoicesBase::set_layout_item(layout_item, table_name);
 
-  //Right-align numbers:
-  sharedptr<const LayoutItem_Field> layout_field = sharedptr<const LayoutItem_Field>::cast_dynamic(get_layout_item());
-  if(layout_field && layout_field->get_glom_type() == Field::TYPE_NUMERIC)
-      get_entry()->set_alignment(1.0); //Align numbers to the right.
+  if(!layout_item)
+    return;
+
+  //Horizontal Alignment:
+  FieldFormatting::HorizontalAlignment alignment = 
+    FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  sharedptr<LayoutItem_Field> layout_field =
+    sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
+  if(layout_field)
+    alignment = layout_field->get_formatting_used_horizontal_alignment();
+
+  const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
+  get_entry()->set_alignment(x_align); 
 }
 
 void ComboEntryGlom::check_for_change()
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index e0289ab..d8665c6 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -748,9 +748,8 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
     } //switch
 
     //Set font and colors:
-    const FieldFormatting& formatting = item_field->get_formatting_used();
     if(pCellRenderer)
-      apply_formatting(pCellRenderer, formatting);
+      apply_formatting(pCellRenderer, item_field);
   }
   else
   {
@@ -823,10 +822,6 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
       //Make it editable:
       pCellRendererText->set_property("editable", true);
 
-      //Align numbers to the right: //TODO: Avoid this for ID keys.
-      if(item_field->get_glom_type() == Field::TYPE_NUMERIC )
-        pCellRendererText->set_property("xalign", 1.0);
-
       //Connect to its signal:
       pCellRendererText->signal_edited().connect(
         sigc::bind( sigc::mem_fun(*this, &DbAddDel::on_treeview_cell_edited), model_column_index, data_model_column_index) );
@@ -921,13 +916,26 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
   return pCellRenderer;
 }
 
-void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const FieldFormatting& formatting)
+void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<LayoutItem_Field>& item_field)
 {
   Gtk::CellRendererText* text_renderer = dynamic_cast<Gtk::CellRendererText*>(renderer);
   if(!text_renderer)
     return;
 
   //Use the text formatting:
+
+  //Horizontal alignment:
+  const FieldFormatting::HorizontalAlignment alignment =
+    item_field->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;
+#else    
+      text_renderer->set_property("xalign", alignment);
+#endif
+
+  const FieldFormatting& formatting = item_field->get_formatting_used();
+
   const Glib::ustring font_desc = formatting.get_text_format_font();
   if(!font_desc.empty())
 #ifdef GLIBMM_PROPERTIES_ENABLED  
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 6924d55..78eeb4f 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 FieldFormatting& formatting);
+  static void apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<LayoutItem_Field>& item_field);
 
   typedef Gtk::VBox type_base;
 
diff --git a/glom/utility_widgets/entryglom.cc b/glom/utility_widgets/entryglom.cc
index ad4ab85..7faf354 100644
--- a/glom/utility_widgets/entryglom.cc
+++ b/glom/utility_widgets/entryglom.cc
@@ -69,9 +69,6 @@ EntryGlom::~EntryGlom()
 
 void EntryGlom::init()
 {
-  if(m_glom_type == Field::TYPE_NUMERIC)
-    set_alignment(1.0); //Align numbers to the right.
-
 #ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
   signal_focus_out_event().connect(sigc::mem_fun(*this, &EntryGlom::on_focus_out_event));
   signal_activate().connect(sigc::mem_fun(*this, &EntryGlom::on_activate));
@@ -84,7 +81,18 @@ void EntryGlom::set_layout_item(const sharedptr<LayoutItem>& layout_item, const
   LayoutWidgetField::set_layout_item(layout_item, table_name);
 #ifdef GTKMM_ATKMM_ENABLED
   get_accessible()->set_name(layout_item->get_name());
-#endif  
+#endif
+
+  //Horizontal Alignment:
+  FieldFormatting::HorizontalAlignment alignment = 
+    FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT;
+  sharedptr<LayoutItem_Field> layout_field =
+    sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+  if(layout_field)
+    alignment = layout_field->get_formatting_used_horizontal_alignment();
+
+  const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
+  set_alignment(x_align);
 }
 
 void EntryGlom::set_glom_type(Field::glom_field_type glom_type)



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