]> spindle.queued.net Git - midori/commitdiff
sokoke_entry_set_default_text becomes gtk_entry_set_placeholder_text
authorChristian Dywan <christian@twotoasts.de>
Wed, 9 Nov 2011 20:45:23 +0000 (21:45 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 9 Nov 2011 21:06:10 +0000 (22:06 +0100)
GTK+ 3.2 and Hildon 2.2 have the exact same feature built-in.

katze/gtk3-compat.c
katze/gtk3-compat.h
midori/midori-searchaction.c
midori/sokoke.c

index cffff31bad8b3b8640d5f9b2b58b2d6cb9051da3..0c0a4369d67241fd706ca599c3a1d38cf0f44a07 100644 (file)
@@ -1,5 +1,108 @@
 #include "katze/gtk3-compat.h"
 
+#if !GTK_CHECK_VERSION (3, 2, 0) && !defined (HAVE_HILDON_2_2)
+static void
+sokoke_widget_set_pango_font_style (GtkWidget* widget,
+                                    PangoStyle style)
+{
+    /* Conveniently change the pango font style
+       For some reason we need to reset if we actually want the normal style */
+    if (style == PANGO_STYLE_NORMAL)
+        gtk_widget_modify_font (widget, NULL);
+    else
+    {
+        PangoFontDescription* font_description = pango_font_description_new ();
+        pango_font_description_set_style (font_description, PANGO_STYLE_ITALIC);
+        gtk_widget_modify_font (widget, font_description);
+        pango_font_description_free (font_description);
+    }
+}
+
+static gboolean
+sokoke_on_entry_focus_in_event (GtkEntry*      entry,
+                                GdkEventFocus* event,
+                                gpointer       userdata)
+{
+    gint has_default = GPOINTER_TO_INT (
+        g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
+    if (has_default)
+    {
+        gtk_entry_set_text (entry, "");
+        g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
+                           GINT_TO_POINTER (0));
+        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+                                            PANGO_STYLE_NORMAL);
+    }
+    return FALSE;
+}
+
+static gboolean
+sokoke_on_entry_focus_out_event (GtkEntry*      entry,
+                                 GdkEventFocus* event,
+                                 gpointer       userdata)
+{
+    const gchar* text = gtk_entry_get_text (entry);
+    if (text && !*text)
+    {
+        const gchar* default_text = (const gchar*)g_object_get_data (
+            G_OBJECT (entry), "sokoke_default_text");
+        gtk_entry_set_text (entry, default_text);
+        g_object_set_data (G_OBJECT (entry),
+                           "sokoke_has_default", GINT_TO_POINTER (1));
+        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+                                            PANGO_STYLE_ITALIC);
+    }
+    return FALSE;
+}
+
+static void
+sokoke_on_entry_drag_data_received (GtkEntry*       entry,
+                                    GdkDragContext* drag_context,
+                                    gint            x,
+                                    gint            y,
+                                    guint           timestamp,
+                                    gpointer        user_data)
+{
+    sokoke_on_entry_focus_in_event (entry, NULL, NULL);
+}
+
+void
+gtk_entry_set_placeholder_text (GtkEntry*    entry,
+                                const gchar* default_text)
+{
+    /* Note: The default text initially overwrites any previous text */
+    gchar* old_value = g_object_get_data (G_OBJECT (entry),
+                                          "sokoke_default_text");
+    if (!old_value)
+    {
+        g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
+                           GINT_TO_POINTER (1));
+        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+                                            PANGO_STYLE_ITALIC);
+        gtk_entry_set_text (entry, default_text);
+        g_signal_connect (entry, "drag-data-received",
+            G_CALLBACK (sokoke_on_entry_drag_data_received), NULL);
+        g_signal_connect (entry, "focus-in-event",
+            G_CALLBACK (sokoke_on_entry_focus_in_event), NULL);
+        g_signal_connect (entry, "focus-out-event",
+           G_CALLBACK (sokoke_on_entry_focus_out_event), NULL);
+    }
+    else if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
+    {
+        gint has_default = GPOINTER_TO_INT (
+            g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
+        if (has_default)
+        {
+            gtk_entry_set_text (entry, default_text);
+            sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
+                                                PANGO_STYLE_ITALIC);
+        }
+    }
+    g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
+                       (gpointer)default_text);
+}
+#endif
+
 #if !GTK_CHECK_VERSION (2, 12, 0)
 
 void
index 2f058debe8b0c219ad5d0f67057c535e6d7c668a..a59ff936f78e059a16fdb15c961ac94d3baf1cbd 100644 (file)
@@ -63,6 +63,12 @@ G_BEGIN_DECLS
     #define GTK_DIALOG_NO_SEPARATOR 0
 #endif
 
+#if !GTK_CHECK_VERSION (3, 2, 0) && defined (HAVE_HILDON_2_2)
+    #define gtk_entry_set_placeholder_text hildon_gtk_entry_set_placeholder_text
+#elif !GTK_CHECK_VERSION (3, 2, 0)
+    #define gtk_entry_set_placeholder_text sokoke_entry_set_default_text
+#endif
+
 #if !GTK_CHECK_VERSION(2, 12, 0)
 
 void
index 687cb77fb8258ed04543b721a4c1cc2f10d366b4..00425812aad7a79c10755f59e155accb22f4205c 100644 (file)
@@ -536,7 +536,7 @@ midori_search_action_set_entry_icon (MidoriSearchAction* search_action,
         else
             gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
                 GTK_ICON_ENTRY_PRIMARY, icon_name);
-        sokoke_entry_set_default_text (GTK_ENTRY (entry),
+        gtk_entry_set_placeholder_text (GTK_ENTRY (entry),
             katze_item_get_name (search_action->current_item));
     }
     else
@@ -544,7 +544,7 @@ midori_search_action_set_entry_icon (MidoriSearchAction* search_action,
         gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
                                             GTK_ICON_ENTRY_PRIMARY,
                                             GTK_STOCK_FIND);
-        sokoke_entry_set_default_text (GTK_ENTRY (entry), "");
+        gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "");
     }
 }
 
index 6387491748620704d116b9bcd5fed6b371cf3a09..2c2ee9d1fc6bf051ba93a428625981ebe651a4d0 100644 (file)
@@ -850,107 +850,6 @@ sokoke_xfce_header_new (const gchar* icon,
     return NULL;
 }
 
-static void
-sokoke_widget_set_pango_font_style (GtkWidget* widget,
-                                    PangoStyle style)
-{
-    /* Conveniently change the pango font style
-       For some reason we need to reset if we actually want the normal style */
-    if (style == PANGO_STYLE_NORMAL)
-        gtk_widget_modify_font (widget, NULL);
-    else
-    {
-        PangoFontDescription* font_description = pango_font_description_new ();
-        pango_font_description_set_style (font_description, PANGO_STYLE_ITALIC);
-        gtk_widget_modify_font (widget, font_description);
-        pango_font_description_free (font_description);
-    }
-}
-
-static gboolean
-sokoke_on_entry_focus_in_event (GtkEntry*      entry,
-                                GdkEventFocus* event,
-                                gpointer       userdata)
-{
-    gint has_default = GPOINTER_TO_INT (
-        g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
-    if (has_default)
-    {
-        gtk_entry_set_text (entry, "");
-        g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
-                           GINT_TO_POINTER (0));
-        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
-                                            PANGO_STYLE_NORMAL);
-    }
-    return FALSE;
-}
-
-static gboolean
-sokoke_on_entry_focus_out_event (GtkEntry*      entry,
-                                 GdkEventFocus* event,
-                                 gpointer       userdata)
-{
-    const gchar* text = gtk_entry_get_text (entry);
-    if (text && !*text)
-    {
-        const gchar* default_text = (const gchar*)g_object_get_data (
-            G_OBJECT (entry), "sokoke_default_text");
-        gtk_entry_set_text (entry, default_text);
-        g_object_set_data (G_OBJECT (entry),
-                           "sokoke_has_default", GINT_TO_POINTER (1));
-        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
-                                            PANGO_STYLE_ITALIC);
-    }
-    return FALSE;
-}
-
-static void
-sokoke_on_entry_drag_data_received (GtkEntry*       entry,
-                                    GdkDragContext* drag_context,
-                                    gint            x,
-                                    gint            y,
-                                    guint           timestamp,
-                                    gpointer        user_data)
-{
-    sokoke_on_entry_focus_in_event (entry, NULL, NULL);
-}
-
-void
-sokoke_entry_set_default_text (GtkEntry*    entry,
-                               const gchar* default_text)
-{
-    /* Note: The default text initially overwrites any previous text */
-    gchar* old_value = g_object_get_data (G_OBJECT (entry),
-                                          "sokoke_default_text");
-    if (!old_value)
-    {
-        g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
-                           GINT_TO_POINTER (1));
-        sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
-                                            PANGO_STYLE_ITALIC);
-        gtk_entry_set_text (entry, default_text);
-        g_signal_connect (entry, "drag-data-received",
-            G_CALLBACK (sokoke_on_entry_drag_data_received), NULL);
-        g_signal_connect (entry, "focus-in-event",
-            G_CALLBACK (sokoke_on_entry_focus_in_event), NULL);
-        g_signal_connect (entry, "focus-out-event",
-           G_CALLBACK (sokoke_on_entry_focus_out_event), NULL);
-    }
-    else if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
-    {
-        gint has_default = GPOINTER_TO_INT (
-            g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
-        if (has_default)
-        {
-            gtk_entry_set_text (entry, default_text);
-            sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
-                                                PANGO_STYLE_ITALIC);
-        }
-    }
-    g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
-                       (gpointer)default_text);
-}
-
 gchar*
 sokoke_key_file_get_string_default (GKeyFile*    key_file,
                                     const gchar* group,