[maemo-commits] [maemo-commits] r15372 - in projects/haf/trunk/hildon-1: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Apr 9 12:17:01 EEST 2008
Author: kris
Date: 2008-04-09 12:16:58 +0300 (Wed, 09 Apr 2008)
New Revision: 15372

Modified:
   projects/haf/trunk/hildon-1/ChangeLog
   projects/haf/trunk/hildon-1/src/hildon-banner-private.h
   projects/haf/trunk/hildon-1/src/hildon-banner.c
Log:
2008-04-09  Kristian Rietveld  <kris at imendio.com>

	Fixes: NB#77775: Media Player, Save Now playing list, too long name
	makes banner disappear.
	Fixes: NB#79182: info banner flickering with certain message lengts.

	* src/hildon-banner.c (hildon_banner_constructor),
	(hildon_banner_init), (hildon_banner_set_text),
	(hildon_banner_set_markup): call hildon_banner_reset_wrap_state(),
	(hildon_banner_reset_wrap_state): new function: reset wrap flags to
	FALSE, reset size requests of label and banner,
	(force_to_wrap_truncated): when the text is too wide, always enforce
	the maximum possible width instead of recalculating it from the
	layout; enforce the maximum banner height of 3 lines,
	(hildon_banner_init): set WORD_CHAR wrapping, this will result in
	nicer wrapping and no truncated chars if space gets tight.

	* src/hildon-banner-private.h: add has_been_wrapped and
	has_been_truncated fields.



Modified: projects/haf/trunk/hildon-1/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-1/ChangeLog	2008-04-09 07:20:33 UTC (rev 15371)
+++ projects/haf/trunk/hildon-1/ChangeLog	2008-04-09 09:16:58 UTC (rev 15372)
@@ -1,3 +1,23 @@
+2008-04-09  Kristian Rietveld  <kris at imendio.com>
+
+	Fixes: NB#77775: Media Player, Save Now playing list, too long name
+	makes banner disappear.
+	Fixes: NB#79182: info banner flickering with certain message lengts.
+
+	* src/hildon-banner.c (hildon_banner_constructor),
+	(hildon_banner_init), (hildon_banner_set_text),
+	(hildon_banner_set_markup): call hildon_banner_reset_wrap_state(),
+	(hildon_banner_reset_wrap_state): new function: reset wrap flags to
+	FALSE, reset size requests of label and banner,
+	(force_to_wrap_truncated): when the text is too wide, always enforce
+	the maximum possible width instead of recalculating it from the
+	layout; enforce the maximum banner height of 3 lines,
+	(hildon_banner_init): set WORD_CHAR wrapping, this will result in
+	nicer wrapping and no truncated chars if space gets tight.
+
+	* src/hildon-banner-private.h: add has_been_wrapped and
+	has_been_truncated fields.
+
 2008-04-07  Sven Herzberg  <sven at imendio.com>
 
 	Fixes: NB#78896: libhildon code inspection/coverity: uninitialised

Modified: projects/haf/trunk/hildon-1/src/hildon-banner-private.h
===================================================================
--- projects/haf/trunk/hildon-1/src/hildon-banner-private.h	2008-04-09 07:20:33 UTC (rev 15371)
+++ projects/haf/trunk/hildon-1/src/hildon-banner-private.h	2008-04-09 09:16:58 UTC (rev 15372)
@@ -42,6 +42,8 @@
     gboolean is_timed;
     guint    timeout;
     GtkWindow *parent;
+    gboolean has_been_wrapped;
+    gboolean has_been_truncated;
 };
 
 /* For internal use of hildon libraries only */

Modified: projects/haf/trunk/hildon-1/src/hildon-banner.c
===================================================================
--- projects/haf/trunk/hildon-1/src/hildon-banner.c	2008-04-09 07:20:33 UTC (rev 15371)
+++ projects/haf/trunk/hildon-1/src/hildon-banner.c	2008-04-09 09:16:58 UTC (rev 15372)
@@ -140,6 +140,8 @@
 static gboolean 
 hildon_banner_map_event                         (GtkWidget *widget, 
                                                  GdkEventAny *event);
+static void
+hildon_banner_reset_wrap_state                  (HildonBanner *banner);
 
 static void 
 force_to_wrap_truncated                         (HildonBanner *banner);
@@ -531,6 +533,7 @@
            assertion `nqueue->freeze_count > 0' failed */
 
         g_object_freeze_notify (banner);
+        hildon_banner_reset_wrap_state (HILDON_BANNER (banner));
     }
 
     /* We restart possible timeouts for each new timed banner request */
@@ -605,6 +608,25 @@
 }
 #endif
 
+static void
+hildon_banner_reset_wrap_state (HildonBanner *banner)
+{
+    PangoLayout *layout;
+    HildonBannerPrivate *priv;
+
+    priv = HILDON_BANNER_GET_PRIVATE (banner);
+    g_assert (priv);
+
+    layout = gtk_label_get_layout (GTK_LABEL (priv->label));
+
+    pango_layout_set_width (layout, -1);
+    priv->has_been_wrapped = FALSE;
+    priv->has_been_truncated = FALSE;
+
+    gtk_widget_set_size_request (priv->label, -1, -1);
+    gtk_widget_set_size_request (GTK_WIDGET (banner), -1, -1);
+}
+
 /* force to wrap truncated label by setting explicit size request
  * see N#27000 and G#329646 */
 static void 
@@ -614,30 +636,60 @@
     PangoLayout *layout;
     int width_text, width_max;
     int width = -1;
+    int height = -1;
+    PangoRectangle logical;
+    GtkRequisition requisition;
     HildonBannerPrivate *priv = HILDON_BANNER_GET_PRIVATE (banner);
 
     g_assert (priv);
+
     label = GTK_LABEL (priv->label);
 
     layout = gtk_label_get_layout (label);
-    width_text  = PANGO_PIXELS(pango_layout_get_width (layout));
-    /* = width to which the lines of the PangoLayout should be wrapped */
 
+    pango_layout_get_extents (layout, NULL, &logical);
+    width_text = PANGO_PIXELS (logical.width);
+
     width_max = priv->is_timed ? HILDON_BANNER_LABEL_MAX_TIMED
         : HILDON_BANNER_LABEL_MAX_PROGRESS;
 
-    if (width_text >= width_max) {
-        /* explicitly request maximum size to force wrapping */
-        PangoRectangle logical;
+    /* If the width of the label is going to exceed the maximum allowed
+     * width, enforce the maximum allowed width now.
+     */
+    if (priv->has_been_wrapped
+        || width_text >= width_max) {
+        /* Force wrapping by setting the maximum size */
+        width = width_max;
 
-        pango_layout_set_width (layout, width_max * PANGO_SCALE);
+        priv->has_been_wrapped = TRUE;
+    }
+
+    /* Make the label update its layout */
+    gtk_widget_set_size_request (GTK_WIDGET (label), width, height);
+    gtk_widget_size_request (GTK_WIDGET (label), &requisition);
+
+    /* If the layout has now been wrapped and exceeds 3 lines, we truncate
+     * the rest of the label according to spec.
+     */
+    if (priv->has_been_truncated
+        || (pango_layout_is_wrapped (layout)
+            && pango_layout_get_line_count (layout) > 3)) {
+        int lines;
+
         pango_layout_get_extents (layout, NULL, &logical);
+        lines = pango_layout_get_line_count (layout);
 
-        width = PANGO_PIXELS (logical.width);
+        /* This calculation assumes that the same font is used
+         * throughout the banner -- this is usually the case on maemo
+         *
+         * FIXME: Pango >= 1.20 has pango_layout_set_height().
+         */
+        height = (PANGO_PIXELS (logical.height) * 3) / lines + 1;
+        priv->has_been_truncated = TRUE;
     }
 
-    /* use fixed width when wrapping or natural one otherwise */
-    gtk_widget_set_size_request (GTK_WIDGET (label), width, -1);
+    /* Set the new width/height if applicable */
+    gtk_widget_set_size_request (GTK_WIDGET (label), width, height);
 }
 
 
@@ -768,6 +820,7 @@
 
     priv->label = g_object_new (GTK_TYPE_LABEL, NULL);
     gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
+    gtk_label_set_line_wrap_mode (GTK_LABEL (priv->label), PANGO_WRAP_WORD_CHAR);
 
     gtk_container_set_border_width (GTK_CONTAINER (priv->layout), HILDON_MARGIN_DEFAULT);
     gtk_container_add (GTK_CONTAINER (self), priv->layout);
@@ -779,6 +832,8 @@
     gtk_window_set_is_temporary (GTK_WINDOW (self), TRUE);
 #endif
 
+    hildon_banner_reset_wrap_state (self);
+
     gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_PRESS_MASK);
 }
 
@@ -1102,8 +1157,10 @@
 
     if (existing_text != NULL && 
         text != NULL          &&
-        strcmp (existing_text, text) != 0)
+        strcmp (existing_text, text) != 0) {
             gtk_label_set_text (label, text);
+            hildon_banner_reset_wrap_state (self);
+    }
 
     hildon_banner_check_position (GTK_WIDGET (self));
 }
@@ -1131,6 +1188,8 @@
     label = GTK_LABEL (priv->label);
     gtk_label_set_markup (label, markup);
 
+    hildon_banner_reset_wrap_state (self);
+
     hildon_banner_check_position (GTK_WIDGET(self));
 }
 


More information about the maemo-commits mailing list