Remove all calls to hildon_helper_set_logical_* from within Hildon
authorAlberto Garcia <agarcia@igalia.com>
Mon, 27 Jul 2009 11:06:11 +0000 (13:06 +0200)
committerAlberto Garcia <agarcia@igalia.com>
Wed, 29 Jul 2009 18:32:33 +0000 (20:32 +0200)
* hildon/hildon-text-view.c
(+set_logical_color, +hildon_text_view_style_set)
(hildon_text_view_refresh_contents, hildon_text_view_class_init)
(hildon_text_view_init)
* hildon/hildon-entry.c
(+set_logical_color, +hildon_entry_style_set)
(hildon_entry_show_placeholder, hildon_entry_hide_placeholder)
(hildon_entry_class_init, hildon_entry_init)
* hildon/hildon-button.c
(+set_logical_font, +set_logical_color)
(hildon_button_style_set, hildon_button_init)
(hildon_button_set_arrangement, hildon_button_set_style):
Remove all calls to hildon_helper_set_logical_font() and
hildon_helper_set_logical_color(), which are recursive, from
within Hildon.

Fixes: NB#123409 (Showing dialog consumes significant amount of
time)

ChangeLog
hildon/hildon-button.c
hildon/hildon-entry.c
hildon/hildon-text-view.c

index 34e2948..3b9c17a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2009-07-29  Alberto Garcia  <agarcia@igalia.com>
+
+       * hildon/hildon-text-view.c
+       (+set_logical_color, +hildon_text_view_style_set)
+       (hildon_text_view_refresh_contents, hildon_text_view_class_init)
+       (hildon_text_view_init)
+       * hildon/hildon-entry.c
+       (+set_logical_color, +hildon_entry_style_set)
+       (hildon_entry_show_placeholder, hildon_entry_hide_placeholder)
+       (hildon_entry_class_init, hildon_entry_init)
+       * hildon/hildon-button.c
+       (+set_logical_font, +set_logical_color)
+       (hildon_button_style_set, hildon_button_init)
+       (hildon_button_set_arrangement, hildon_button_set_style):
+       Remove all calls to hildon_helper_set_logical_font() and
+       hildon_helper_set_logical_color(), which are recursive, from
+       within Hildon.
+
+       Fixes: NB#123409 (Showing dialog consumes significant amount of
+       time)
+
 2009-07-29  Alejandro G. Castro  <alex@igalia.com>
 
        * hildon/hildon-pannable-area.c,
index dd28e27..bd2b8e3 100644 (file)
@@ -91,7 +91,6 @@
 #include                                        "hildon-button.h"
 #include                                        "hildon-enum-types.h"
 #include                                        "hildon-gtk.h"
-#include                                        "hildon-helper.h"
 
 G_DEFINE_TYPE                                   (HildonButton, hildon_button, GTK_TYPE_BUTTON);
 
@@ -113,6 +112,7 @@ struct                                          _HildonButtonPrivate
     gfloat image_xalign;
     gfloat image_yalign;
     HildonButtonStyle style;
+    guint setting_style : 1;
 };
 
 enum {
@@ -187,6 +187,55 @@ hildon_button_get_property                      (GObject    *object,
 }
 
 static void
+set_logical_font                                (GtkWidget *button)
+{
+    HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
+
+    /* In buttons with vertical arrangement, the 'value' label uses a
+     * different font */
+    if (GTK_IS_VBOX (priv->label_box)) {
+        GtkStyle *style = gtk_rc_get_style_by_paths (
+            gtk_settings_get_default (), "SmallSystemFont", NULL, G_TYPE_NONE);
+        if (style != NULL) {
+            PangoFontDescription *font_desc = style->font_desc;
+            if (font_desc != NULL) {
+                priv->setting_style = TRUE;
+                gtk_widget_modify_font (GTK_WIDGET (priv->value), font_desc);
+                priv->setting_style = FALSE;
+            }
+        }
+    }
+}
+
+static void
+set_logical_color                               (GtkWidget *button)
+{
+    GdkColor color;
+    const gchar *colorname;
+    HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
+    GtkWidget *label = GTK_WIDGET (priv->value);
+
+    switch (priv->style) {
+    case HILDON_BUTTON_STYLE_NORMAL:
+        colorname = "SecondaryTextColor";
+        break;
+    case HILDON_BUTTON_STYLE_PICKER:
+        colorname = "ActiveTextColor";
+        break;
+    default:
+        g_return_if_reached ();
+    }
+
+    gtk_widget_ensure_style (label);
+    if (gtk_style_lookup_color (label->style, colorname, &color) == TRUE) {
+        priv->setting_style = TRUE;
+        gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color);
+        gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color);
+        priv->setting_style = FALSE;
+    }
+}
+
+static void
 hildon_button_style_set                         (GtkWidget *widget,
                                                  GtkStyle  *previous_style)
 {
@@ -196,6 +245,11 @@ hildon_button_style_set                         (GtkWidget *widget,
     if (GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set)
         GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set (widget, previous_style);
 
+    /* Prevent infinite recursion when calling set_logical_font() and
+     * set_logical_color() */
+    if (priv->setting_style)
+        return;
+
     gtk_widget_style_get (widget,
                           "horizontal-spacing", &horizontal_spacing,
                           "vertical-spacing", &vertical_spacing,
@@ -211,6 +265,9 @@ hildon_button_style_set                         (GtkWidget *widget,
     if (GTK_IS_BOX (priv->hbox)) {
         gtk_box_set_spacing (priv->hbox, image_spacing);
     }
+
+    set_logical_font (widget);
+    set_logical_color (widget);
 }
 
 static void
@@ -323,6 +380,8 @@ hildon_button_init                              (HildonButton *self)
     priv->image_yalign = 0.5;
     priv->hbox = NULL;
     priv->label_box = NULL;
+    priv->style = HILDON_BUTTON_STYLE_NORMAL;
+    priv->setting_style = FALSE;
 
     gtk_widget_set_name (GTK_WIDGET (priv->title), "hildon-button-title");
     gtk_widget_set_name (GTK_WIDGET (priv->value), "hildon-button-value");
@@ -509,7 +568,7 @@ hildon_button_set_arrangement                   (HildonButton            *button
     /* Pack everything */
     if (arrangement == HILDON_BUTTON_ARRANGEMENT_VERTICAL) {
         priv->label_box = gtk_vbox_new (FALSE, 0);
-        hildon_helper_set_logical_font (GTK_WIDGET (priv->value), "SmallSystemFont");
+        set_logical_font (GTK_WIDGET (button));
     } else {
         priv->label_box = gtk_hbox_new (FALSE, 0);
     }
@@ -907,27 +966,12 @@ hildon_button_set_style                         (HildonButton      *button,
                                                  HildonButtonStyle  style)
 {
     HildonButtonPrivate *priv;
-    const gchar *color;
 
     g_return_if_fail (HILDON_IS_BUTTON (button));
-
-    switch (style) {
-    case HILDON_BUTTON_STYLE_NORMAL:
-        color = "SecondaryTextColor";
-        break;
-    case HILDON_BUTTON_STYLE_PICKER:
-        color = "ActiveTextColor";
-        break;
-    default:
-        g_return_if_reached ();
-    }
-
     priv = HILDON_BUTTON_GET_PRIVATE (button);
 
-    hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_NORMAL, color);
-    hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_PRELIGHT, color);
-
     priv->style = style;
+    set_logical_color (GTK_WIDGET (button));
 
     g_object_notify (G_OBJECT (button), "style");
 }
index 07f338b..11609a2 100644 (file)
@@ -50,7 +50,6 @@
  */
 
 #include                                        "hildon-entry.h"
-#include                                        "hildon-helper.h"
 
 G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
 
@@ -65,7 +64,8 @@ enum {
 struct                                          _HildonEntryPrivate
 {
     gchar *placeholder;
-    gboolean showing_placeholder;
+    guint showing_placeholder : 1;
+    guint setting_style : 1;
 };
 
 static void
@@ -92,14 +92,49 @@ set_property                                    (GObject      *object,
 }
 
 static void
+set_logical_color                               (HildonEntry *entry)
+{
+    GdkColor color;
+    const gchar *colorname;
+    GtkWidget *widget = GTK_WIDGET (entry);
+    HildonEntryPrivate *priv = entry->priv;
+
+    colorname = priv->showing_placeholder ? "ReversedSecondaryTextColor" : "ReversedTextColor";
+
+    gtk_widget_ensure_style (widget);
+    if (gtk_style_lookup_color (widget->style, colorname, &color) == TRUE) {
+        priv->setting_style = TRUE;
+        gtk_widget_modify_text (widget, GTK_STATE_NORMAL, &color);
+        priv->setting_style = FALSE;
+    }
+}
+
+static void
+hildon_entry_style_set                          (GtkWidget *widget,
+                                                 GtkStyle  *previous_style)
+{
+    HildonEntry *entry = HILDON_ENTRY (widget);
+
+    if (GTK_WIDGET_CLASS (hildon_entry_parent_class)->style_set)
+        GTK_WIDGET_CLASS (hildon_entry_parent_class)->style_set (widget, previous_style);
+
+    /* Prevent infinite recursion when calling set_logical_font() and
+     * set_logical_color() */
+    if (entry->priv->setting_style)
+        return;
+
+    set_logical_color (entry);
+}
+
+static void
 hildon_entry_show_placeholder (HildonEntry *entry)
 {
     HildonEntryPrivate *priv = HILDON_ENTRY (entry)->priv;
 
     priv->showing_placeholder = TRUE;
     gtk_entry_set_text (GTK_ENTRY (entry), priv->placeholder);
-    hildon_helper_set_logical_color (GTK_WIDGET (entry),
-                                    GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedSecondaryTextColor");
+
+    set_logical_color (entry);
 }
 
 static void
@@ -109,8 +144,8 @@ hildon_entry_hide_placeholder (HildonEntry *entry, const gchar *text)
 
     priv->showing_placeholder = FALSE;
     gtk_entry_set_text (GTK_ENTRY (entry), text);
-    hildon_helper_set_logical_color (GTK_WIDGET (entry),
-                                    GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedTextColor");
+
+    set_logical_color (entry);
 }
 
 /**
@@ -260,6 +295,7 @@ hildon_entry_class_init                         (HildonEntryClass *klass)
     gobject_class->finalize = hildon_entry_finalize;
     widget_class->focus_in_event = hildon_entry_focus_in_event;
     widget_class->focus_out_event = hildon_entry_focus_out_event;
+    widget_class->style_set = hildon_entry_style_set;
 
     g_object_class_install_property (
         gobject_class,
@@ -281,4 +317,5 @@ hildon_entry_init                               (HildonEntry *self)
     self->priv = HILDON_ENTRY_GET_PRIVATE (self);
     self->priv->placeholder = g_strdup ("");
     self->priv->showing_placeholder = FALSE;
+    self->priv->setting_style = FALSE;
 }
index 62edec5..c3133a2 100644 (file)
@@ -54,7 +54,6 @@
  */
 
 #include                                        "hildon-text-view.h"
-#include                                        "hildon-helper.h"
 #include <math.h>
 
 #define HILDON_TEXT_VIEW_DRAG_THRESHOLD 16.0
@@ -74,8 +73,45 @@ struct                                          _HildonTextViewPrivate
     gulong changed_id;               /* ID of the main_buffer::changed signal handler */
     gdouble x;                                                      /* tap x position */
     gdouble y;                                                      /* tap y position */
+    guint showing_placeholder : 1;          /* Whether the placeholder is being shown */
+    guint setting_style : 1;                /* Whether the logical color is being set */
 };
 
+
+static void
+set_logical_color                               (GtkWidget *widget)
+{
+    GdkColor color;
+    const gchar *colorname;
+    HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (widget);
+
+    colorname = priv->showing_placeholder ? "ReversedSecondaryTextColor" : "ReversedTextColor";
+
+    gtk_widget_ensure_style (widget);
+    if (gtk_style_lookup_color (widget->style, colorname, &color) == TRUE) {
+        priv->setting_style = TRUE;
+        gtk_widget_modify_text (widget, GTK_STATE_NORMAL, &color);
+        priv->setting_style = FALSE;
+    }
+}
+
+static void
+hildon_text_view_style_set                      (GtkWidget *widget,
+                                                 GtkStyle  *previous_style)
+{
+    HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (widget);
+
+    if (GTK_WIDGET_CLASS (hildon_text_view_parent_class)->style_set)
+        GTK_WIDGET_CLASS (hildon_text_view_parent_class)->style_set (widget, previous_style);
+
+    /* Prevent infinite recursion when calling set_logical_font() and
+     * set_logical_color() */
+    if (priv->setting_style)
+        return;
+
+    set_logical_color (widget);
+}
+
 /* Function used to decide whether to show the placeholder or not */
 static void
 hildon_text_view_refresh_contents               (GtkWidget *text_view)
@@ -83,14 +119,15 @@ hildon_text_view_refresh_contents               (GtkWidget *text_view)
     HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (text_view);
     gint bufsize = gtk_text_buffer_get_char_count (priv->main_buffer);
 
-    if ((bufsize > 0) || GTK_WIDGET_HAS_FOCUS (text_view)) {
-        /* Display the main buffer if it contains text or the widget is focused */
-        hildon_helper_set_logical_color (text_view, GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedTextColor");
-        gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), priv->main_buffer);
-    } else {
-        /* Otherwise, display the placeholder */
-        hildon_helper_set_logical_color (text_view, GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedSecondaryTextColor");
+    /* Display the main buffer if it contains text or the widget is focused */
+    priv->showing_placeholder = (bufsize <= 0) && !(GTK_WIDGET_HAS_FOCUS (text_view));
+
+    set_logical_color (text_view);
+
+    if (priv->showing_placeholder) {
         gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), priv->placeholder_buffer);
+    } else {
+        gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), priv->main_buffer);
     }
 }
 
@@ -324,6 +361,7 @@ hildon_text_view_class_init                     (HildonTextViewClass *klass)
     widget_class->motion_notify_event = NULL;
     widget_class->button_press_event = hildon_text_view_button_press_event;
     widget_class->button_release_event = hildon_text_view_button_release_event;
+    widget_class->style_set = hildon_text_view_style_set;
 
     g_type_class_add_private (klass, sizeof (HildonTextViewPrivate));
 }
@@ -335,6 +373,8 @@ hildon_text_view_init                           (HildonTextView *self)
 
     priv->main_buffer = gtk_text_buffer_new (NULL);
     priv->placeholder_buffer = gtk_text_buffer_new (NULL);
+    priv->showing_placeholder = FALSE;
+    priv->setting_style = FALSE;
 
     hildon_text_view_refresh_contents (GTK_WIDGET (self));