[glom] Details: Static Text items: Use horizontal alignment from formatting.



commit 43dbb6d2f6c04a354fe00cd44a43c7c778c20d61
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 24 10:25:30 2010 +0100

    Details: Static Text items: Use horizontal alignment from formatting.
    
    * glom/utility_widgets/labelglom.[h|cc]: Add a constructor that does not
    take alignment values, like the Gtk::Label base class, so we can easily
    use the default for vertical alignment.
    * glom/mode_data/flowtablewithfields.cc: add_textobject_at_position():
    Use expand=true when adding the widget to the FlowTable, so that labels can
    have the full space in which to actually have alignment.
    * glom/utility_widgets/layoutwidgetbase.cc: apply_formatting: Use appropriate
    multi-line justification for labels, as a user would expect when setting
    horizontal alignment.

 ChangeLog                                |   14 ++++++++++++++
 glom/mode_data/flowtablewithfields.cc    |   20 +++++++++++---------
 glom/utility_widgets/labelglom.cc        |    6 ++++++
 glom/utility_widgets/labelglom.h         |    1 +
 glom/utility_widgets/layoutwidgetbase.cc |   25 ++++++++++++++++++-------
 5 files changed, 50 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 38d0343..a61747c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-01-24  Murray Cumming  <murrayc murrayc com>
+
+  Details: Static Text items: Use horizontal alignment from formatting.
+  
+	* glom/utility_widgets/labelglom.[h|cc]: Add a constructor that does not 
+	take alignment values, like the Gtk::Label base class, so we can easily 
+	use the default for vertical alignment.
+	* glom/mode_data/flowtablewithfields.cc: add_textobject_at_position():
+	Use expand=true when adding the widget to the FlowTable, so that labels can 
+	have the full space in which to actually have alignment.
+	* glom/utility_widgets/layoutwidgetbase.cc: apply_formatting: Use appropriate 
+	multi-line justification for labels, as a user would expect when setting 
+	horizontal alignment.
+
 2010-01-23  Murray Cumming  <murrayc murrayc com>
 
   Details: Buttons: Use background color from formatting.
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index b6afcf3..472e7dc 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -595,6 +595,7 @@ void FlowTableWithFields::add_button_at_position(const sharedptr<LayoutItem_Butt
   add_layoutwidgetbase(button, add_before);
   //add_view(button); //So it can get the document.
 
+  //TODO: Align the button to the right of its space if using right alignment?
   Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
   if(widget)
     insert_before (*button, *widget, false /* expand */);
@@ -607,19 +608,20 @@ void FlowTableWithFields::add_button_at_position(const sharedptr<LayoutItem_Butt
 void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_Text>& layoutitem_text, const Glib::ustring& table_name , const type_list_layoutwidgets::iterator& add_before)
 {
   //Add the widget:
+  
+  const FieldFormatting::HorizontalAlignment alignment =
+    layoutitem_text->get_formatting_used_horizontal_alignment();
+  const Gtk::AlignmentEnum x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? Gtk::ALIGN_LEFT : Gtk::ALIGN_RIGHT);
   Gtk::Alignment* alignment_label = Gtk::manage(new Gtk::Alignment());
-  alignment_label->set(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
+  alignment_label->set(x_align, Gtk::ALIGN_CENTER);
   alignment_label->show();
   
   const Glib::ustring text = layoutitem_text->get_text();
-  LabelGlom* label = Gtk::manage(new LabelGlom(text, 0.0 /* xalign */, 0.5 /* yalign */)); //The alignment here seems to be necessary as well (or instead of) the parent Gtk::Alignment.
+  LabelGlom* label = Gtk::manage(new LabelGlom(text));
   label->set_layout_item(layoutitem_text, table_name);
   label->show();
   alignment_label->add(*label);
   
-  //TODO: Why isn't this formatting used?
-  //std::cout << "DEBUG: Applying formatting for text item: " << text << std::endl;
-  //std::cout << "  DEBUG: font: " << layoutitem_text->get_formatting_used().get_text_format_font() << std::endl;
   apply_formatting(*label, layoutitem_text);
 
   add_layoutwidgetbase(label, add_before);
@@ -629,9 +631,9 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
   {
     Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
     if(widget)
-      insert_before(*alignment_label, *widget, false /* expand */);
+      insert_before(*alignment_label, *widget, true /* expand */);
     else
-      add(*alignment_label, false /* expand */);
+      add(*alignment_label, true /* expand */);
   }
   else
   {
@@ -647,9 +649,9 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
     
     Gtk::Widget* widget = dynamic_cast<Gtk::Widget*>(*add_before);
     if(widget)
-      insert_before (*alignment_title, *alignment_label, *widget, false /* expand */);
+      insert_before (*alignment_title, *alignment_label, *widget, true /* expand */);
     else
-      add(*alignment_title, *alignment_label, false /* expand */);
+      add(*alignment_title, *alignment_label, true /* expand */);
   }
 }
 
diff --git a/glom/utility_widgets/labelglom.cc b/glom/utility_widgets/labelglom.cc
index a4e53af..551278b 100644
--- a/glom/utility_widgets/labelglom.cc
+++ b/glom/utility_widgets/labelglom.cc
@@ -35,6 +35,12 @@ LabelGlom::LabelGlom()
   init();
 }
 
+LabelGlom::LabelGlom(const Glib::ustring& label, bool mnemonic)
+: m_label(label, mnemonic)
+{
+  init();
+}
+
 LabelGlom::LabelGlom(const Glib::ustring& label, float xalign, float yalign, bool mnemonic)
 : m_label(label, xalign, yalign, mnemonic)
 {
diff --git a/glom/utility_widgets/labelglom.h b/glom/utility_widgets/labelglom.h
index bbcd255..45a5e68 100644
--- a/glom/utility_widgets/labelglom.h
+++ b/glom/utility_widgets/labelglom.h
@@ -38,6 +38,7 @@ class LabelGlom
 {
 public:
   LabelGlom();
+  explicit LabelGlom(const Glib::ustring& label, bool mnemonic = false);
   explicit LabelGlom(const Glib::ustring& label, float xalign, float yalign, bool mnemonic = false);
   virtual ~LabelGlom();
   
diff --git a/glom/utility_widgets/layoutwidgetbase.cc b/glom/utility_widgets/layoutwidgetbase.cc
index b030b88..05233ad 100644
--- a/glom/utility_widgets/layoutwidgetbase.cc
+++ b/glom/utility_widgets/layoutwidgetbase.cc
@@ -91,7 +91,7 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
   Gtk::Widget* widget_to_change = &widget;
 
   Gtk::Button* button = dynamic_cast<Gtk::Button*>(&widget);
-  LabelGlom* label = dynamic_cast<LabelGlom*>(&widget);
+  LabelGlom* labelglom = dynamic_cast<LabelGlom*>(&widget);
   if(button)
     widget_to_change = button->get_child();
   else
@@ -99,8 +99,8 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
     TextViewGlom* textview = dynamic_cast<TextViewGlom*>(&widget);
     if(textview)
       widget_to_change = textview->get_textview();
-    else if(label)
-      widget_to_change = label->get_label();
+    else if(labelglom)
+      widget_to_change = labelglom->get_label();
   }
 
   if(!layout_item)
@@ -113,7 +113,18 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
   Gtk::Misc* misc = dynamic_cast<Gtk::Misc*>(widget_to_change);
   if(misc)
     misc->set_alignment(x_align);
-
+    
+  //Set justification on labels:
+  //Assume that people want left/right justification of multi-line text if they chose 
+  //left/right alignment of the text itself.
+  {
+    Gtk::Label* label = dynamic_cast<Gtk::Label*>(widget_to_change);
+    if(label)
+    {    
+      const Gtk::Justification justification = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? Gtk::JUSTIFY_LEFT : Gtk::JUSTIFY_RIGHT);
+      label->set_justify(justification);
+    }
+  }
 
   const FieldFormatting& formatting = layout_item->get_formatting_used();
 
@@ -140,7 +151,7 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
   const Glib::ustring bg = formatting.get_text_format_color_background();
   if(!bg.empty())
   {
-    if(!label && !button)
+    if(!labelglom && !button)
     {
       // "base" is the background color for GtkEntry. "bg" seems to change the border:
       widget_to_change->modify_base(Gtk::STATE_NORMAL, Gdk::Color(bg));
@@ -148,10 +159,10 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const sharedptr<con
     //According to the gtk_widget_modify_base() documentation, 
     //a GtkLabel can only have a background color by, for instance, placing it 
     //in a GtkEventBox. Luckily LabelGlom is actually derived from EventBox.
-    else if(label)
+    else if(labelglom)
     {
       //label->modify_base(Gtk::STATE_NORMAL, Gdk::Color("bg"));
-      label->modify_bg(Gtk::STATE_NORMAL, Gdk::Color(bg));
+      labelglom->modify_bg(Gtk::STATE_NORMAL, Gdk::Color(bg));
     }
     else if(button)
     {



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