blam r544 - in trunk: . libblam src



Author: cmartin
Date: Mon Apr 14 15:18:13 2008
New Revision: 544
URL: http://svn.gnome.org/viewvc/blam?rev=544&view=rev

Log:
Remove manual ellipsizing and let pango do it for us.

This removes another call into unmanaged code and simplifies Blam.


Modified:
   trunk/ChangeLog
   trunk/libblam/blam-utils.c
   trunk/src/ItemList.cs
   trunk/src/Utils.cs

Modified: trunk/libblam/blam-utils.c
==============================================================================
--- trunk/libblam/blam-utils.c	(original)
+++ trunk/libblam/blam-utils.c	Mon Apr 14 15:18:13 2008
@@ -47,63 +47,3 @@
 					 func,
 					 NULL);
 }
-
-static void
-ellipsize_string (gchar *str, gint len)
-{
-	gchar *tmp;
-
-	if (g_utf8_strlen (str, -1) > len + 4) {
-		tmp = g_utf8_offset_to_pointer (str, len);
-
-		tmp[0] = '.';
-		tmp[1] = '.';
-		tmp[2] = '.';
-		tmp[3] = '\0';
-	}
-}
-
-#define ELLIPSIS_LIMIT 6
-#define TREE_INDENT 30
-
-gchar *
-blam_ellipsize_and_delimit_string (GtkWidget   *widget, 
-				   const gchar *str, 
-				   gint         width)
-{
-	PangoLayout    *layout;
-	PangoRectangle  rect;
-	gint            len_str;
-	gint            width_str;
-	gchar          *ret_val;
-
-	ret_val = g_strdup (str);
-
-	g_strdelimit (ret_val, "\n\r\t", '\0');
-
-	len_str = g_utf8_strlen (ret_val, -1);
-
-	if (len_str < ELLIPSIS_LIMIT) {
-		return ret_val;
-	}
-
-	layout = gtk_widget_create_pango_layout (widget, NULL);
-	
-	pango_layout_set_text (layout, ret_val, -1);
-	pango_layout_get_extents (layout, NULL, &rect);
-	width_str = rect.width / PANGO_SCALE;
-
-	while (len_str >= ELLIPSIS_LIMIT && width_str > width) {
-		len_str--;
-		ellipsize_string (ret_val, len_str);
-		
-		pango_layout_set_text (layout, ret_val, -1);
-		pango_layout_get_extents (layout, NULL, &rect);
-		
-		width_str = rect.width / PANGO_SCALE;
-	}
-
-	g_object_unref (layout);
-
-	return ret_val;
-}

Modified: trunk/src/ItemList.cs
==============================================================================
--- trunk/src/ItemList.cs	(original)
+++ trunk/src/ItemList.cs	Mon Apr 14 15:18:13 2008
@@ -259,21 +259,14 @@
 	    Imendio.Blam.Item item = (Imendio.Blam.Item)model.GetValue(iter, 0);
 	    
 	    int weight = (int)Pango.Weight.Normal;
-	    int width;
 
 	    if (item.Unread) {
 		weight = (int) Pango.Weight.Bold;
-		width = (int) (this.Allocation.Width * 0.85);
-	    } else {
-		width = (int) (this.Allocation.Width * 0.95);
 	    }
 
-	    ((CellRendererText)cell).Text = 
-		Utils.EllipsizeAndDelimitString(Handle, 
-						item.Title,
-						width);
-
-	    ((CellRendererText)cell).Weight = weight;
+        ((CellRendererText)cell).Text = item.Title;
+        ((CellRendererText)cell).Weight = weight;
+        ((CellRendererText)cell).Ellipsize = Pango.EllipsizeMode.End;
 	}
 	
 	private void EmitItemSelected (Imendio.Blam.Item item) 

Modified: trunk/src/Utils.cs
==============================================================================
--- trunk/src/Utils.cs	(original)
+++ trunk/src/Utils.cs	Mon Apr 14 15:18:13 2008
@@ -39,12 +39,6 @@
 	    blam_tree_model_set_sort_func (w, col, f);
 	}
 
-	[DllImport("libblam.so")]
-	    static extern IntPtr blam_ellipsize_and_delimit_string(IntPtr w, string str, int width);
-	public static string EllipsizeAndDelimitString(IntPtr w, string str, int width)
-	{
-	    return Marshaller.PtrToStringGFree(blam_ellipsize_and_delimit_string(w, str, width));
-	}
         
         [DllImport("libblam.so")]
             static extern void blam_gecko_utils_init_services ();



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