[glabels/vala] Refactoring of text object code. Autosize object unless size explicitly set.



commit 99371508e3c4c7194a0be3669b8633938097a05b
Author: Jim Evins <evins snaught com>
Date:   Sat Aug 4 22:25:56 2012 -0400

    Refactoring of text object code.  Autosize object unless size explicitly set.

 glabels/label_object.vala      |  202 ++-----------------------
 glabels/label_object_text.vala |  329 ++++++++++++++++++++++++++++++++++++++++
 glabels/object_editor.vala     |  210 ++++++++++++++++---------
 glabels/view.vala              |   11 +-
 glabels/xml_label.vala         |    4 +-
 5 files changed, 489 insertions(+), 267 deletions(-)
---
diff --git a/glabels/label_object.vala b/glabels/label_object.vala
index a292bd5..ab11eee 100644
--- a/glabels/label_object.vala
+++ b/glabels/label_object.vala
@@ -85,7 +85,7 @@ namespace glabels
 		/**
 		 * Width of bounding box
 		 */
-		public double w
+		public virtual double w
 		{
 			get { return _w; }
 
@@ -105,7 +105,7 @@ namespace glabels
 		/**
 		 * Height of bounding box
 		 */
-		public double h
+		public virtual double h
 		{
 			get { return _h; }
 
@@ -142,174 +142,17 @@ namespace glabels
 
 
 		/**
-		 * Font family
+		 * Text parameters interface
 		 */
-		public string font_family
-		{
-			get { return _font_family; }
-
-			set
-			{
-				if ( _font_family != value )
-				{
-					_font_family = value;
-					changed();
-				}
-			}
-		}
-		private string _font_family;
-
-
-		/**
-		 * Font size
-		 */
-		public double font_size
-		{
-			get { return _font_size; }
-
-			set
-			{
-				if ( _font_size != value )
-				{
-					_font_size = value;
-					changed();
-				}
-			}
-		}
-		private double _font_size;
-
-
-		/**
-		 * Font weight
-		 */
-		public Pango.Weight font_weight
-		{
-			get { return _font_weight; }
-
-			set
-			{
-				if ( _font_weight != value )
-				{
-					_font_weight = value;
-					changed();
-				}
-			}
-		}
-		private Pango.Weight _font_weight = Pango.Weight.NORMAL;
-
-
-		/**
-		 * Font italic flag
-		 */
-		public bool font_italic_flag
-		{
-			get { return _font_italic_flag; }
-
-			set
-			{
-				if ( _font_italic_flag != value )
-				{
-					_font_italic_flag = value;
-					changed();
-				}
-			}
-		}
-		private bool _font_italic_flag;
-
-
-		/**
-		 * Font underline flag
-		 */
-		public bool font_underline_flag
-		{
-			get { return _font_underline_flag; }
-
-			set
-			{
-				if ( _font_underline_flag != value )
-				{
-					_font_underline_flag = value;
-					changed();
-				}
-			}
-		}
-		private bool _font_underline_flag;
-
-
-		/**
-		 * Text color node
-		 */
-		public ColorNode text_color_node
-		{
-			get { return _text_color_node; }
-
-			set
-			{
-				if ( _text_color_node != value )
-				{
-					_text_color_node = value;
-					changed();
-				}
-			}
-		}
-		private ColorNode _text_color_node;
-
-
-		/**
-		 * Text alignment
-		 */
-		public Pango.Alignment text_alignment
-		{
-			get { return _text_alignment; }
-
-			set
-			{
-				if ( _text_alignment != value )
-				{
-					_text_alignment = value;
-					changed();
-				}
-			}
-		}
-		private Pango.Alignment _text_alignment;
-
-
-		/**
-		 * Text vertical alignment
-		 */
-		public ValignType text_valignment
-		{
-			get { return _text_valignment; }
-
-			set
-			{
-				if ( _text_valignment != value )
-				{
-					_text_valignment = value;
-					changed();
-				}
-			}
-		}
-		private ValignType _text_valignment;
-
-
-		/**
-		 * Text line spacing
-		 */
-		public double text_line_spacing
-		{
-			get { return _text_line_spacing; }
-
-			set
-			{
-				if ( _text_line_spacing != value )
-				{
-					_text_line_spacing = value;
-					changed();
-				}
-			}
-		}
-		private double _text_line_spacing;
+		public virtual string          font_family         { get; set; }
+		public virtual double          font_size           { get; set; }
+		public virtual Pango.Weight    font_weight         { get; set; }
+		public virtual bool            font_italic_flag    { get; set; }
+		public virtual bool            font_underline_flag { get; set; }
+		public virtual ColorNode       text_color_node     { get; set; }
+		public virtual Pango.Alignment text_alignment      { get; set; }
+		public virtual ValignType      text_valignment     { get; set; }
+		public virtual double          text_line_spacing   { get; set; }
 
 
 		/**
@@ -486,16 +329,6 @@ namespace glabels
 
 			Prefs prefs = new Prefs();
 
-			_font_family             = prefs.default_font_family;
-			_font_size               = prefs.default_font_size;
-			_font_weight             = prefs.default_font_weight;
-			_font_italic_flag        = prefs.default_font_italic_flag;
-			_font_underline_flag     = false;
-			_text_color_node         = ColorNode.from_color( prefs.default_text_color );
-			_text_alignment          = prefs.default_text_alignment;
-			_text_valignment         = ValignType.TOP;
-			_text_line_spacing       = prefs.default_text_line_spacing;
-
 			_line_width              = prefs.default_line_width;
 			_line_color_node         = ColorNode.from_color( prefs.default_line_color );
 			_fill_color_node         = ColorNode.from_color( prefs.default_fill_color );
@@ -601,15 +434,10 @@ namespace glabels
 		public void set_size( double w,
 		                      double h )
 		{
-			if ( ( _w != w ) || ( _h != h ) )
-			{
-				_w = w;
-				_h = h;
+			this.w = w;
+			this.h = h;
 
-				aspect_ratio = _h / _w;
-
-				changed();
-			}
+			aspect_ratio = h / w;
 		}
 
 
diff --git a/glabels/label_object_text.vala b/glabels/label_object_text.vala
index b7d5e6b..ffff25e 100644
--- a/glabels/label_object_text.vala
+++ b/glabels/label_object_text.vala
@@ -40,6 +40,258 @@ namespace glabels
 		public bool auto_shrink { get; set; default = false; }
 
 
+		/**
+		 * Raw width of bounding box
+		 */
+		public double w_raw
+		{
+			get { return _w_raw; }
+		}
+		private double _w_raw;
+
+
+		/**
+		 * Raw height of bounding box
+		 */
+		public double h_raw
+		{
+			get { return _h_raw; }
+		}
+		private double _h_raw;
+
+
+		/**
+		 * Width of bounding box
+		 */
+		public override double w
+		{
+			get
+			{
+				if (size_changed)
+				{
+					recalculate_size();
+				}
+				return _w;
+			}
+
+			set
+			{
+				if ( _w_raw != value )
+				{
+					_w_raw = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private double _w;
+
+
+		/**
+		 * Height of bounding box
+		 */
+		public override double h
+		{
+			get
+			{
+				if (size_changed)
+				{
+					recalculate_size();
+				}
+				return _h;
+			}
+
+			set
+			{
+				if ( _h_raw != value )
+				{
+					_h_raw = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private double _h;
+
+
+		/**
+		 * Font family
+		 */
+		public override string font_family
+		{
+			get { return _font_family; }
+
+			set
+			{
+				if ( _font_family != value )
+				{
+					_font_family = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private string _font_family;
+
+
+		/**
+		 * Font size
+		 */
+		public override double font_size
+		{
+			get { return _font_size; }
+
+			set
+			{
+				if ( _font_size != value )
+				{
+					_font_size = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private double _font_size;
+
+
+		/**
+		 * Font weight
+		 */
+		public override Pango.Weight font_weight
+		{
+			get { return _font_weight; }
+
+			set
+			{
+				if ( _font_weight != value )
+				{
+					_font_weight = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private Pango.Weight _font_weight = Pango.Weight.NORMAL;
+
+
+		/**
+		 * Font italic flag
+		 */
+		public override bool font_italic_flag
+		{
+			get { return _font_italic_flag; }
+
+			set
+			{
+				if ( _font_italic_flag != value )
+				{
+					_font_italic_flag = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private bool _font_italic_flag;
+
+
+		/**
+		 * Font underline flag
+		 */
+		public override bool font_underline_flag
+		{
+			get { return _font_underline_flag; }
+
+			set
+			{
+				if ( _font_underline_flag != value )
+				{
+					_font_underline_flag = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private bool _font_underline_flag;
+
+
+		/**
+		 * Text color node
+		 */
+		public override ColorNode text_color_node
+		{
+			get { return _text_color_node; }
+
+			set
+			{
+				if ( _text_color_node != value )
+				{
+					_text_color_node = value;
+					changed();
+				}
+			}
+		}
+		private ColorNode _text_color_node;
+
+
+		/**
+		 * Text alignment
+		 */
+		public override Pango.Alignment text_alignment
+		{
+			get { return _text_alignment; }
+
+			set
+			{
+				if ( _text_alignment != value )
+				{
+					_text_alignment = value;
+					changed();
+				}
+			}
+		}
+		private Pango.Alignment _text_alignment;
+
+
+		/**
+		 * Text vertical alignment
+		 */
+		public override ValignType text_valignment
+		{
+			get { return _text_valignment; }
+
+			set
+			{
+				if ( _text_valignment != value )
+				{
+					_text_valignment = value;
+					changed();
+				}
+			}
+		}
+		private ValignType _text_valignment;
+
+
+		/**
+		 * Text line spacing
+		 */
+		public override double text_line_spacing
+		{
+			get { return _text_line_spacing; }
+
+			set
+			{
+				if ( _text_line_spacing != value )
+				{
+					_text_line_spacing = value;
+					size_changed = true;
+					changed();
+				}
+			}
+		}
+		private double _text_line_spacing;
+
+
+
 		public LabelObjectText()
 		{
 			handles.append( new HandleSouthEast( this ) );
@@ -53,6 +305,18 @@ namespace glabels
 
 			outline = new Outline( this );
 
+			Prefs prefs = new Prefs();
+
+			_font_family             = prefs.default_font_family;
+			_font_size               = prefs.default_font_size;
+			_font_weight             = prefs.default_font_weight;
+			_font_italic_flag        = prefs.default_font_italic_flag;
+			_font_underline_flag     = false;
+			_text_color_node         = ColorNode.from_color( prefs.default_text_color );
+			_text_alignment          = prefs.default_text_alignment;
+			_text_valignment         = ValignType.TOP;
+			_text_line_spacing       = prefs.default_text_line_spacing;
+
 			tag_table    = new Gtk.TextTagTable();
 			buffer       = new Gtk.TextBuffer( tag_table );
 			size_changed = true;
@@ -316,6 +580,71 @@ namespace glabels
 		}
 
 
+		private void recalculate_size()
+		{
+			Pango.Context context = Gdk.pango_context_get();
+			Cairo.FontOptions font_options = new Cairo.FontOptions();
+			font_options.set_hint_metrics( Cairo.HintMetrics.OFF );
+			Pango.cairo_context_set_font_options( context, font_options );
+
+			Pango.Layout layout = new Pango.Layout( context );
+			Pango.FontDescription desc = new Pango.FontDescription();
+
+			if ( buffer.get_char_count() != 0 )
+			{
+				desc.set_family( font_family );
+				desc.set_weight( font_weight );
+				desc.set_style( font_italic_flag ? Pango.Style.ITALIC : Pango.Style.NORMAL );
+				desc.set_size( (int)(font_size * FONT_SCALE * Pango.SCALE + 0.5) );
+				layout.set_font_description( desc );
+				layout.set_spacing( (int)(font_size * FONT_SCALE * (text_line_spacing-1) * Pango.SCALE + 0.5) );
+				layout.set_text( get_lines().expand( null ), -1 );
+			}
+			else
+			{
+				desc.set_family( "Sans" );
+				desc.set_weight( Pango.Weight.NORMAL );
+				desc.set_style( Pango.Style.NORMAL );
+				desc.set_size( (int)(12 * FONT_SCALE * Pango.SCALE + 0.5) );
+				layout.set_font_description( desc );
+				layout.set_text( _("Text"), -1 );
+			}
+
+			if ( _w_raw == 0 )
+			{
+				layout.set_width( -1 );
+			}
+			else
+			{
+				layout.set_width( (int)(_w_raw * Pango.SCALE + 0.5) );
+			}
+
+			int iw, ih;
+			layout.get_size( out iw, out ih );
+
+			if ( _w_raw != 0.0 )
+			{
+				_w = _w_raw;
+			}
+			else
+			{
+				_w = iw / Pango.SCALE + 2*TEXT_MARGIN;
+			}
+
+			double h_temp = ih / Pango.SCALE;
+			if ( h_temp < _h_raw )
+			{
+				_h = h_raw;
+			}
+			else
+			{
+				_h = h_temp;
+			}
+
+			size_changed = false;
+		}
+
+
 		private void on_buffer_begin_user_action()
 		{
 		}
diff --git a/glabels/object_editor.vala b/glabels/object_editor.vala
index 060878d..bee6328 100644
--- a/glabels/object_editor.vala
+++ b/glabels/object_editor.vala
@@ -34,6 +34,7 @@ namespace glabels
 		private LabelObject?     object;
 
 
+		/* Widgets */
 		private Gtk.Image        title_image;
 		private Gtk.Label        title_label;
 		private Gtk.Notebook     notebook;
@@ -92,6 +93,41 @@ namespace glabels
 		private Gtk.SpinButton   shadow_opacity_spin;
 
 
+		/* Signal IDs */
+		private ulong sigid_text_font_family_button_changed;
+		private ulong sigid_text_font_size_spin_changed;
+		private ulong sigid_text_font_bold_toggle_toggled;
+		private ulong sigid_text_font_italic_toggle_toggled;
+		private ulong sigid_text_font_underline_toggle_toggled;
+		private ulong sigid_text_color_button_changed;
+		private ulong sigid_text_halign_left_toggle_toggled;
+		private ulong sigid_text_halign_center_toggle_toggled;
+		private ulong sigid_text_halign_right_toggle_toggled;
+		private ulong sigid_text_valign_top_toggle_toggled;
+		private ulong sigid_text_valign_middle_toggle_toggled;
+		private ulong sigid_text_valign_bottom_toggle_toggled;
+		private ulong sigid_text_line_spacing_spin_changed;
+		private ulong sigid_text_insert_field_button_key_selected;
+
+		private ulong sigid_line_width_spin_changed;
+		private ulong sigid_line_color_button_changed;
+
+		private ulong sigid_fill_color_button_changed;
+
+		private ulong sigid_pos_x_spin_changed;
+		private ulong sigid_pos_y_spin_changed;
+
+		private ulong sigid_size_w_spin_changed;
+		private ulong sigid_size_h_spin_changed;
+
+		private ulong sigid_shadow_enable_check_changed;
+		private ulong sigid_shadow_x_spin_changed;
+		private ulong sigid_shadow_y_spin_changed;
+		private ulong sigid_shadow_color_button_changed;
+		private ulong sigid_shadow_opacity_spin_changed;
+
+
+
 		public ObjectEditor()
 		{
 			/* Load the user interface. */
@@ -161,20 +197,34 @@ namespace glabels
 			text_insert_field_button = new FieldButton( _("Insert merge field") );
 			text_insert_field_box.pack_start( text_insert_field_button, true, true, 0 );
 
-			text_font_family_button.changed.connect( on_text_font_family_button_changed );
-			text_font_size_spin.value_changed.connect( on_text_font_size_spin_changed );
-			text_font_bold_toggle.toggled.connect( on_text_font_bold_toggle_toggled );
-			text_font_italic_toggle.toggled.connect( on_text_font_italic_toggle_toggled );
-			text_font_underline_toggle.toggled.connect( on_text_font_underline_toggle_toggled );
-			text_color_button.color_changed.connect( on_text_color_button_changed );
-			text_halign_left_toggle.toggled.connect( on_text_halign_left_toggle_toggled );
-			text_halign_center_toggle.toggled.connect( on_text_halign_center_toggle_toggled );
-			text_halign_right_toggle.toggled.connect( on_text_halign_right_toggle_toggled );
-			text_valign_top_toggle.toggled.connect( on_text_valign_top_toggle_toggled );
-			text_valign_middle_toggle.toggled.connect( on_text_valign_middle_toggle_toggled );
-			text_valign_bottom_toggle.toggled.connect( on_text_valign_bottom_toggle_toggled );
-			text_line_spacing_spin.value_changed.connect( on_text_line_spacing_spin_changed );
-			text_insert_field_button.key_selected.connect( on_text_insert_field_button_key_selected );
+			sigid_text_font_family_button_changed =
+				text_font_family_button.changed.connect( on_text_font_family_button_changed );
+			sigid_text_font_size_spin_changed =
+				text_font_size_spin.value_changed.connect( on_text_font_size_spin_changed );
+			sigid_text_font_bold_toggle_toggled =
+				text_font_bold_toggle.toggled.connect( on_text_font_bold_toggle_toggled );
+			sigid_text_font_italic_toggle_toggled =
+				text_font_italic_toggle.toggled.connect( on_text_font_italic_toggle_toggled );
+			sigid_text_font_underline_toggle_toggled =
+				text_font_underline_toggle.toggled.connect( on_text_font_underline_toggle_toggled );
+			sigid_text_color_button_changed =
+				text_color_button.color_changed.connect( on_text_color_button_changed );
+			sigid_text_halign_left_toggle_toggled =
+				text_halign_left_toggle.toggled.connect( on_text_halign_left_toggle_toggled );
+			sigid_text_halign_center_toggle_toggled =
+				text_halign_center_toggle.toggled.connect( on_text_halign_center_toggle_toggled );
+			sigid_text_halign_right_toggle_toggled =
+				text_halign_right_toggle.toggled.connect( on_text_halign_right_toggle_toggled );
+			sigid_text_valign_top_toggle_toggled =
+				text_valign_top_toggle.toggled.connect( on_text_valign_top_toggle_toggled );
+			sigid_text_valign_middle_toggle_toggled =
+				text_valign_middle_toggle.toggled.connect( on_text_valign_middle_toggle_toggled );
+			sigid_text_valign_bottom_toggle_toggled =
+				text_valign_bottom_toggle.toggled.connect( on_text_valign_bottom_toggle_toggled );
+			sigid_text_line_spacing_spin_changed =
+				text_line_spacing_spin.value_changed.connect( on_text_line_spacing_spin_changed );
+			sigid_text_insert_field_button_key_selected =
+				text_insert_field_button.key_selected.connect( on_text_insert_field_button_key_selected );
 
 
 			/* Line widgets. */
@@ -184,8 +234,10 @@ namespace glabels
 			line_color_button = new ColorButton( _("No line"), Color.none(), Color.black() );
 			line_color_box.pack_start( line_color_button, true, true, 0 );
 
-			line_width_spin.value_changed.connect( on_line_width_spin_changed );
-			line_color_button.color_changed.connect( on_line_color_button_changed );
+			sigid_line_width_spin_changed =
+			    line_width_spin.value_changed.connect( on_line_width_spin_changed );
+			sigid_line_color_button_changed =
+			    line_color_button.color_changed.connect( on_line_color_button_changed );
 
 
 			/* Fill widgets. */
@@ -194,7 +246,8 @@ namespace glabels
 			fill_color_button       = new ColorButton( _("No fill"), Color.none(), Color.black() );
 			fill_color_box.pack_start( fill_color_button, true, true, 0 );
 
-			fill_color_button.color_changed.connect( on_fill_color_button_changed );
+			sigid_fill_color_button_changed =
+			    fill_color_button.color_changed.connect( on_fill_color_button_changed );
 
 
 			/* Position widgets. */
@@ -203,8 +256,8 @@ namespace glabels
 			pos_x_units_label       = builder.get_object( "pos_x_units_label" )       as Gtk.Label;
 			pos_y_units_label       = builder.get_object( "pos_y_units_label" )       as Gtk.Label;
 
-			pos_x_spin.value_changed.connect( on_pos_x_spin_changed );
-			pos_y_spin.value_changed.connect( on_pos_y_spin_changed );
+			sigid_pos_x_spin_changed = pos_x_spin.value_changed.connect( on_pos_x_spin_changed );
+			sigid_pos_y_spin_changed = pos_y_spin.value_changed.connect( on_pos_y_spin_changed );
 
 
 			/* Size widgets. */
@@ -215,8 +268,8 @@ namespace glabels
 			size_aspect_check       = builder.get_object( "size_aspect_check" )       as Gtk.CheckButton;
 			size_reset_image_button = builder.get_object( "size_reset_image_button" ) as Gtk.Button;
 
-			size_w_spin.value_changed.connect( on_size_w_spin_changed );
-			size_h_spin.value_changed.connect( on_size_h_spin_changed );
+			sigid_size_w_spin_changed = size_w_spin.value_changed.connect( on_size_w_spin_changed );
+			sigid_size_h_spin_changed = size_h_spin.value_changed.connect( on_size_h_spin_changed );
 
 
 			/* Shadow widgets. */
@@ -232,11 +285,16 @@ namespace glabels
 			shadow_color_button = new ColorButton( _("Default"), Color.black(), Color.black() );
 			shadow_color_box.pack_start(shadow_color_button, true, true, 0 );
 
-			shadow_enable_check.toggled.connect( on_shadow_enable_check_changed );
-			shadow_x_spin.value_changed.connect( on_shadow_x_spin_changed );
-			shadow_y_spin.value_changed.connect( on_shadow_y_spin_changed );
-			shadow_color_button.color_changed.connect( on_shadow_color_button_changed );
-			shadow_opacity_spin.value_changed.connect( on_shadow_opacity_spin_changed );
+			sigid_shadow_enable_check_changed =
+				shadow_enable_check.toggled.connect( on_shadow_enable_check_changed );
+			sigid_shadow_x_spin_changed =
+				shadow_x_spin.value_changed.connect( on_shadow_x_spin_changed );
+			sigid_shadow_y_spin_changed =
+				shadow_y_spin.value_changed.connect( on_shadow_y_spin_changed );
+			sigid_shadow_color_button_changed =
+				shadow_color_button.color_changed.connect( on_shadow_color_button_changed );
+			sigid_shadow_opacity_spin_changed =
+				shadow_opacity_spin.value_changed.connect( on_shadow_opacity_spin_changed );
 
 
 			notebook.hide();
@@ -461,11 +519,11 @@ namespace glabels
 		{
 			if ( (object != null) && object.can_text() )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_font_family_button, (void*)on_text_font_family_button_changed, this );
+				GLib.SignalHandler.block( (void*)text_font_family_button, sigid_text_font_family_button_changed );
 
 				text_font_family_button.set_family( object.font_family );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_font_family_button, (void*)on_text_font_family_button_changed, this );
+				GLib.SignalHandler.unblock( (void*)text_font_family_button, sigid_text_font_family_button_changed );
 			}
 		}
 
@@ -486,11 +544,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_font_size_spin, (void*)on_text_font_size_spin_changed, this );
+				GLib.SignalHandler.block( (void*)text_font_size_spin, sigid_text_font_size_spin_changed );
 
 				text_font_size_spin.set_value( object.font_size );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_font_size_spin, (void*)on_text_font_size_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)text_font_size_spin, sigid_text_font_size_spin_changed );
 			}
 		}
 
@@ -511,11 +569,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_font_bold_toggle, (void*)on_text_font_bold_toggle_toggled, this );
+				GLib.SignalHandler.block( (void*)text_font_bold_toggle, sigid_text_font_bold_toggle_toggled );
 
 				text_font_bold_toggle.set_active( object.font_weight == Pango.Weight.BOLD );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_font_bold_toggle, (void*)on_text_font_bold_toggle_toggled, this );
+				GLib.SignalHandler.unblock( (void*)text_font_bold_toggle, sigid_text_font_bold_toggle_toggled );
 			}
 		}
 
@@ -536,11 +594,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_font_italic_toggle, (void*)on_text_font_italic_toggle_toggled, this );
+				GLib.SignalHandler.block( (void*)text_font_italic_toggle, sigid_text_font_italic_toggle_toggled );
 
 				text_font_italic_toggle.set_active( object.font_italic_flag );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_font_italic_toggle, (void*)on_text_font_italic_toggle_toggled, this );
+				GLib.SignalHandler.unblock( (void*)text_font_italic_toggle, sigid_text_font_italic_toggle_toggled );
 			}
 		}
 
@@ -561,11 +619,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_font_underline_toggle, (void*)on_text_font_underline_toggle_toggled, this );
+				GLib.SignalHandler.block( (void*)text_font_underline_toggle, sigid_text_font_underline_toggle_toggled );
 
 				text_font_underline_toggle.set_active( object.font_underline_flag );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_font_underline_toggle, (void*)on_text_font_underline_toggle_toggled, this );
+				GLib.SignalHandler.unblock( (void*)text_font_underline_toggle, sigid_text_font_underline_toggle_toggled );
 			}
 		}
 
@@ -588,11 +646,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_color_button, (void*)on_text_color_button_changed, this );
+				GLib.SignalHandler.block( (void*)text_color_button, sigid_text_color_button_changed );
 
 				text_color_button.set_color_node( object.text_color_node );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_color_button, (void*)on_text_color_button_changed, this );
+				GLib.SignalHandler.unblock( (void*)text_color_button, sigid_text_color_button_changed );
 			}
 		}
 
@@ -649,9 +707,9 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_halign_left_toggle, (void*)on_text_halign_left_toggle_toggled, this );
-				GLib.SignalHandler.block_by_func( (void*)text_halign_center_toggle, (void*)on_text_halign_center_toggle_toggled, this );
-				GLib.SignalHandler.block_by_func( (void*)text_halign_right_toggle, (void*)on_text_halign_right_toggle_toggled, this );
+				GLib.SignalHandler.block( (void*)text_halign_left_toggle, sigid_text_halign_left_toggle_toggled );
+				GLib.SignalHandler.block( (void*)text_halign_center_toggle, sigid_text_halign_center_toggle_toggled );
+				GLib.SignalHandler.block( (void*)text_halign_right_toggle, sigid_text_halign_right_toggle_toggled );
 
 				switch ( object.text_alignment )
 				{
@@ -674,9 +732,9 @@ namespace glabels
 					assert_not_reached();
 				}
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_halign_left_toggle, (void*)on_text_halign_left_toggle_toggled, this );
-				GLib.SignalHandler.unblock_by_func( (void*)text_halign_center_toggle, (void*)on_text_halign_center_toggle_toggled, this );
-				GLib.SignalHandler.unblock_by_func( (void*)text_halign_right_toggle, (void*)on_text_halign_right_toggle_toggled, this );
+				GLib.SignalHandler.unblock( (void*)text_halign_left_toggle, sigid_text_halign_left_toggle_toggled );
+				GLib.SignalHandler.unblock( (void*)text_halign_center_toggle, sigid_text_halign_center_toggle_toggled );
+				GLib.SignalHandler.unblock( (void*)text_halign_right_toggle, sigid_text_halign_right_toggle_toggled );
 			}
 		}
 
@@ -733,9 +791,9 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_valign_top_toggle, (void*)on_text_valign_top_toggle_toggled, this );
-				GLib.SignalHandler.block_by_func( (void*)text_valign_middle_toggle, (void*)on_text_valign_middle_toggle_toggled, this );
-				GLib.SignalHandler.block_by_func( (void*)text_valign_bottom_toggle, (void*)on_text_valign_bottom_toggle_toggled, this );
+				GLib.SignalHandler.block( (void*)text_valign_top_toggle, sigid_text_valign_top_toggle_toggled );
+				GLib.SignalHandler.block( (void*)text_valign_middle_toggle, sigid_text_valign_middle_toggle_toggled );
+				GLib.SignalHandler.block( (void*)text_valign_bottom_toggle, sigid_text_valign_bottom_toggle_toggled );
 
 				switch ( object.text_valignment )
 				{
@@ -758,9 +816,9 @@ namespace glabels
 					assert_not_reached();
 				}
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_valign_top_toggle, (void*)on_text_valign_top_toggle_toggled, this );
-				GLib.SignalHandler.unblock_by_func( (void*)text_valign_middle_toggle, (void*)on_text_valign_middle_toggle_toggled, this );
-				GLib.SignalHandler.unblock_by_func( (void*)text_valign_bottom_toggle, (void*)on_text_valign_bottom_toggle_toggled, this );
+				GLib.SignalHandler.unblock( (void*)text_valign_top_toggle, sigid_text_valign_top_toggle_toggled );
+				GLib.SignalHandler.unblock( (void*)text_valign_middle_toggle, sigid_text_valign_middle_toggle_toggled );
+				GLib.SignalHandler.unblock( (void*)text_valign_bottom_toggle, sigid_text_valign_bottom_toggle_toggled );
 			}
 		}
 
@@ -781,11 +839,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)text_line_spacing_spin, (void*)on_text_line_spacing_spin_changed, this );
+				GLib.SignalHandler.block( (void*)text_line_spacing_spin, sigid_text_line_spacing_spin_changed );
 
 				text_line_spacing_spin.set_value( object.text_line_spacing );
 
-				GLib.SignalHandler.unblock_by_func( (void*)text_line_spacing_spin, (void*)on_text_line_spacing_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)text_line_spacing_spin, sigid_text_line_spacing_spin_changed );
 			}
 		}
 
@@ -839,11 +897,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)line_width_spin, (void*)on_line_width_spin_changed, this );
+				GLib.SignalHandler.block( (void*)line_width_spin, sigid_line_width_spin_changed );
 
 				line_width_spin.set_value( object.line_width );
 
-				GLib.SignalHandler.unblock_by_func( (void*)line_width_spin, (void*)on_line_width_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)line_width_spin, sigid_line_width_spin_changed );
 			}
 		}
 
@@ -866,11 +924,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)line_color_button, (void*)on_line_color_button_changed, this );
+				GLib.SignalHandler.block( (void*)line_color_button, sigid_line_color_button_changed );
 
 				line_color_button.set_color_node( object.line_color_node );
 
-				GLib.SignalHandler.unblock_by_func( (void*)line_color_button, (void*)on_line_color_button_changed, this );
+				GLib.SignalHandler.unblock( (void*)line_color_button, sigid_line_color_button_changed );
 			}
 		}
 
@@ -893,11 +951,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)fill_color_button, (void*)on_fill_color_button_changed, this );
+				GLib.SignalHandler.block( (void*)fill_color_button, sigid_fill_color_button_changed );
 
 				fill_color_button.set_color_node( object.fill_color_node );
 
-				GLib.SignalHandler.unblock_by_func( (void*)fill_color_button, (void*)on_fill_color_button_changed, this );
+				GLib.SignalHandler.unblock( (void*)fill_color_button, sigid_fill_color_button_changed );
 			}
 		}
 
@@ -918,11 +976,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)pos_x_spin, (void*)on_pos_x_spin_changed, this );
+				GLib.SignalHandler.block( (void*)pos_x_spin, sigid_pos_x_spin_changed );
 
 				pos_x_spin.set_value( object.x0 * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)pos_x_spin, (void*)on_pos_x_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)pos_x_spin, sigid_pos_x_spin_changed );
 			}
 		}
 
@@ -943,11 +1001,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)pos_y_spin, (void*)on_pos_y_spin_changed, this );
+				GLib.SignalHandler.block( (void*)pos_y_spin, sigid_pos_y_spin_changed );
 
 				pos_y_spin.set_value( object.y0 * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)pos_y_spin, (void*)on_pos_y_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)pos_y_spin, sigid_pos_y_spin_changed );
 			}
 		}
 
@@ -977,11 +1035,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)size_w_spin, (void*)on_size_w_spin_changed, this );
+				GLib.SignalHandler.block( (void*)size_w_spin, sigid_size_w_spin_changed );
 
 				size_w_spin.set_value( object.w * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)size_w_spin, (void*)on_size_w_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)size_w_spin, sigid_size_w_spin_changed );
 			}
 		}
 
@@ -1011,11 +1069,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)size_h_spin, (void*)on_size_h_spin_changed, this );
+				GLib.SignalHandler.block( (void*)size_h_spin, sigid_size_h_spin_changed );
 
 				size_h_spin.set_value( object.h * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)size_h_spin, (void*)on_size_h_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)size_h_spin, sigid_size_h_spin_changed );
 			}
 		}
 
@@ -1037,12 +1095,12 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)shadow_enable_check, (void*)on_shadow_enable_check_changed, this );
+				GLib.SignalHandler.block( (void*)shadow_enable_check, sigid_shadow_enable_check_changed );
 
 				shadow_enable_check.set_active( object.shadow_state );
 				shadow_controls_grid.set_sensitive( object.shadow_state );
 
-				GLib.SignalHandler.unblock_by_func( (void*)shadow_enable_check, (void*)on_shadow_enable_check_changed, this );
+				GLib.SignalHandler.unblock( (void*)shadow_enable_check, sigid_shadow_enable_check_changed );
 			}
 		}
 
@@ -1063,11 +1121,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)shadow_x_spin, (void*)on_shadow_x_spin_changed, this );
+				GLib.SignalHandler.block( (void*)shadow_x_spin, sigid_shadow_x_spin_changed );
 
 				shadow_x_spin.set_value( object.shadow_x * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)shadow_x_spin, (void*)on_shadow_x_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)shadow_x_spin, sigid_shadow_x_spin_changed );
 			}
 		}
 
@@ -1088,11 +1146,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)shadow_y_spin, (void*)on_shadow_y_spin_changed, this );
+				GLib.SignalHandler.block( (void*)shadow_y_spin, sigid_shadow_y_spin_changed );
 
 				shadow_y_spin.set_value( object.shadow_y * units.units_per_point );
 
-				GLib.SignalHandler.unblock_by_func( (void*)shadow_y_spin, (void*)on_shadow_y_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)shadow_y_spin, sigid_shadow_y_spin_changed );
 			}
 		}
 
@@ -1115,11 +1173,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)shadow_color_button, (void*)on_shadow_color_button_changed, this );
+				GLib.SignalHandler.block( (void*)shadow_color_button, sigid_shadow_color_button_changed );
 
 				shadow_color_button.set_color_node( object.shadow_color_node );
 
-				GLib.SignalHandler.unblock_by_func( (void*)shadow_color_button, (void*)on_shadow_color_button_changed, this );
+				GLib.SignalHandler.unblock( (void*)shadow_color_button, sigid_shadow_color_button_changed );
 			}
 		}
 
@@ -1140,11 +1198,11 @@ namespace glabels
 		{
 			if ( object != null )
 			{
-				GLib.SignalHandler.block_by_func( (void*)shadow_opacity_spin, (void*)on_shadow_opacity_spin_changed, this );
+				GLib.SignalHandler.block( (void*)shadow_opacity_spin, sigid_shadow_opacity_spin_changed );
 
 				shadow_opacity_spin.set_value( object.shadow_opacity * 100 );
 
-				GLib.SignalHandler.unblock_by_func( (void*)shadow_opacity_spin, (void*)on_shadow_opacity_spin_changed, this );
+				GLib.SignalHandler.unblock( (void*)shadow_opacity_spin, sigid_shadow_opacity_spin_changed );
 			}
 		}
 
diff --git a/glabels/view.vala b/glabels/view.vala
index c01e5a8..55f568f 100644
--- a/glabels/view.vala
+++ b/glabels/view.vala
@@ -1101,9 +1101,16 @@ namespace glabels
 					Gdk.Cursor cursor = new Gdk.Cursor( Gdk.CursorType.LEFT_PTR );
 					window.set_cursor( cursor );
 
-					if ( (create_object.w < 2) && (create_object.h < 2) )
+					if ( (create_object.w < 4) && (create_object.h < 4) )
 					{
-						create_object.set_size( 72, 72 );
+						if ( create_object is LabelObjectText )
+						{
+							create_object.set_size( 0, 0 );
+						}
+						else
+						{
+							create_object.set_size( 72, 72 );
+						}
 					}
 
 					in_object_create_mode = false;
diff --git a/glabels/xml_label.vala b/glabels/xml_label.vala
index e0d7ea2..fad305b 100644
--- a/glabels/xml_label.vala
+++ b/glabels/xml_label.vala
@@ -578,8 +578,8 @@ namespace glabels
 			XmlUtil.set_prop_length( node, "y", object.y0 );
 
 			/* size attrs */
-			XmlUtil.set_prop_length( node, "w", object.w );
-			XmlUtil.set_prop_length( node, "h", object.h );
+			XmlUtil.set_prop_length( node, "w", object.w_raw );
+			XmlUtil.set_prop_length( node, "h", object.h_raw );
 
 			/* align attr */
 			XmlUtil.set_prop_string( node, "align", EnumUtil.align_to_string( object.text_alignment ) );



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