From 22472c19248267ce35e7185fdd3988bb0cd86efc Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 5 Nov 2017 06:45:01 +0100 Subject: [PATCH] entry: Remove surface icons We have texture icons. --- docs/reference/gtk/gtk4-sections.txt | 2 - gtk/gtkentry.c | 157 +-------------------------- gtk/gtkentry.h | 7 -- tests/testentryicons.c | 18 ++- 4 files changed, 8 insertions(+), 176 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 27c8de3280..a891386f04 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -914,12 +914,10 @@ gtk_entry_reset_im_context gtk_entry_set_tabs gtk_entry_get_tabs GtkEntryIconPosition -gtk_entry_set_icon_from_surface gtk_entry_set_icon_from_texture gtk_entry_set_icon_from_icon_name gtk_entry_set_icon_from_gicon gtk_entry_get_icon_storage_type -gtk_entry_get_icon_surface gtk_entry_get_icon_texture gtk_entry_get_icon_name gtk_entry_get_icon_gicon diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 8c8fe731a5..7056b82556 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -339,8 +339,6 @@ enum { PROP_CAPS_LOCK_WARNING, PROP_PROGRESS_FRACTION, PROP_PROGRESS_PULSE_STEP, - PROP_SURFACE_PRIMARY, - PROP_SURFACE_SECONDARY, PROP_TEXTURE_PRIMARY, PROP_TEXTURE_SECONDARY, PROP_ICON_NAME_PRIMARY, @@ -1008,34 +1006,6 @@ gtk_entry_class_init (GtkEntryClass *class) NULL, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); - /** - * GtkEntry:primary-icon-surface: - * - * A surface to use as the primary icon for the entry. - * - * Since: 2.16 - */ - entry_props[PROP_SURFACE_PRIMARY] = - g_param_spec_boxed ("primary-icon-surface", - P_("Primary surface"), - P_("Primary surface for the entry"), - CAIRO_GOBJECT_TYPE_SURFACE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); - - /** - * GtkEntry:secondary-icon-surface: - * - * An surface to use as the secondary icon for the entry. - * - * Since: 2.16 - */ - entry_props[PROP_SURFACE_SECONDARY] = - g_param_spec_boxed ("secondary-icon-surface", - P_("Secondary surface"), - P_("Secondary surface for the entry"), - CAIRO_GOBJECT_TYPE_SURFACE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); - /** * GtkEntry:primary-icon-texture: * @@ -2059,18 +2029,6 @@ gtk_entry_set_property (GObject *object, gtk_entry_set_placeholder_text (entry, g_value_get_string (value)); break; - case PROP_SURFACE_PRIMARY: - gtk_entry_set_icon_from_surface (entry, - GTK_ENTRY_ICON_PRIMARY, - g_value_get_boxed (value)); - break; - - case PROP_SURFACE_SECONDARY: - gtk_entry_set_icon_from_surface (entry, - GTK_ENTRY_ICON_SECONDARY, - g_value_get_boxed (value)); - break; - case PROP_TEXTURE_PRIMARY: gtk_entry_set_icon_from_texture (entry, GTK_ENTRY_ICON_PRIMARY, @@ -2314,18 +2272,6 @@ gtk_entry_get_property (GObject *object, g_value_set_string (value, gtk_entry_get_placeholder_text (entry)); break; - case PROP_SURFACE_PRIMARY: - g_value_set_boxed (value, - gtk_entry_get_icon_surface (entry, - GTK_ENTRY_ICON_PRIMARY)); - break; - - case PROP_SURFACE_SECONDARY: - g_value_set_boxed (value, - gtk_entry_get_icon_surface (entry, - GTK_ENTRY_ICON_SECONDARY)); - break; - case PROP_TEXTURE_PRIMARY: g_value_set_object (value, gtk_entry_get_icon_texture (entry, @@ -6661,13 +6607,6 @@ gtk_entry_clear_icon (GtkEntry *entry, switch (storage_type) { - case GTK_IMAGE_SURFACE: - g_object_notify_by_pspec (G_OBJECT (entry), - entry_props[icon_pos == GTK_ENTRY_ICON_PRIMARY - ? PROP_SURFACE_PRIMARY - : PROP_SURFACE_SECONDARY]); - break; - case GTK_IMAGE_TEXTURE: g_object_notify_by_pspec (G_OBJECT (entry), entry_props[icon_pos == GTK_ENTRY_ICON_PRIMARY @@ -6689,6 +6628,7 @@ gtk_entry_clear_icon (GtkEntry *entry, : PROP_GICON_SECONDARY]); break; + case GTK_IMAGE_SURFACE: case GTK_IMAGE_EMPTY: default: g_assert_not_reached (); @@ -7555,65 +7495,6 @@ gtk_entry_get_alignment (GtkEntry *entry) return entry->priv->xalign; } -/** - * gtk_entry_set_icon_from_surface: - * @entry: a #GtkEntry - * @icon_pos: Icon position - * @surface: (allow-none): An image #cairo_surface, or %NULL - * - * Sets the icon shown in the specified position using a image surface. - * - * If @surface is %NULL, no icon will be shown in the specified position. - * - * Since: 3.94 - */ -void -gtk_entry_set_icon_from_surface (GtkEntry *entry, - GtkEntryIconPosition icon_pos, - cairo_surface_t *surface) -{ - GtkEntryPrivate *priv; - EntryIconInfo *icon_info; - - g_return_if_fail (GTK_IS_ENTRY (entry)); - g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos)); - - priv = entry->priv; - - if ((icon_info = priv->icons[icon_pos]) == NULL) - icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos); - - g_object_freeze_notify (G_OBJECT (entry)); - - if (surface) - cairo_surface_reference (surface); - - if (surface) - { - gtk_image_set_from_surface (GTK_IMAGE (icon_info->widget), surface); - - if (icon_pos == GTK_ENTRY_ICON_PRIMARY) - { - g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SURFACE_PRIMARY]); - g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_STORAGE_TYPE_PRIMARY]); - } - else - { - g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SURFACE_SECONDARY]); - g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_STORAGE_TYPE_SECONDARY]); - } - - cairo_surface_destroy (surface); - } - else - gtk_entry_clear_icon (entry, icon_pos); - - if (gtk_widget_get_visible (GTK_WIDGET (entry))) - gtk_widget_queue_resize (GTK_WIDGET (entry)); - - g_object_thaw_notify (G_OBJECT (entry)); -} - /** * gtk_entry_set_icon_from_texture: * @entry: a #GtkEntry @@ -7857,42 +7738,6 @@ gtk_entry_get_icon_activatable (GtkEntry *entry, return (!icon_info || !icon_info->nonactivatable); } -/** - * gtk_entry_get_icon_surface: - * @entry: A #GtkEntry - * @icon_pos: Icon position - * - * Retrieves the image used for the icon. - * - * Unlike the other methods of setting and getting icon data, this - * method will work regardless of whether the icon was set using a - * #cairo_surface_t, a #GIcon or an icon name. - * - * Returns: (transfer none) (nullable): A #cairo_surface_t, or %NULL if no icon is - * set for this position. - * - * Since: 3.94 - */ -cairo_surface_t * -gtk_entry_get_icon_surface (GtkEntry *entry, - GtkEntryIconPosition icon_pos) -{ - GtkEntryPrivate *priv; - EntryIconInfo *icon_info; - - g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL); - g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL); - - priv = entry->priv; - - icon_info = priv->icons[icon_pos]; - - if (!icon_info) - return NULL; - - return gtk_image_get_surface (GTK_IMAGE (icon_info->widget)); -} - /** * gtk_entry_get_icon_texture: * @entry: A #GtkEntry diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h index e2cbd7d605..6ef24df6da 100644 --- a/gtk/gtkentry.h +++ b/gtk/gtkentry.h @@ -284,10 +284,6 @@ void gtk_entry_set_placeholder_text (GtkEntry *entry, /* Setting and managing icons */ GDK_AVAILABLE_IN_3_94 -void gtk_entry_set_icon_from_surface (GtkEntry *entry, - GtkEntryIconPosition icon_pos, - cairo_surface_t *surface); -GDK_AVAILABLE_IN_3_94 void gtk_entry_set_icon_from_texture (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkTexture *texture); @@ -303,9 +299,6 @@ GDK_AVAILABLE_IN_ALL GtkImageType gtk_entry_get_icon_storage_type (GtkEntry *entry, GtkEntryIconPosition icon_pos); GDK_AVAILABLE_IN_3_94 -cairo_surface_t*gtk_entry_get_icon_surface (GtkEntry *entry, - GtkEntryIconPosition icon_pos); -GDK_AVAILABLE_IN_3_94 GdkTexture * gtk_entry_get_icon_texture (GtkEntry *entry, GtkEntryIconPosition icon_pos); GDK_AVAILABLE_IN_ALL diff --git a/tests/testentryicons.c b/tests/testentryicons.c index 4a8fdb8dab..124f1b645d 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -80,20 +80,16 @@ set_gicon (GtkWidget *button, } static void -set_surface (GtkWidget *button, +set_texture (GtkWidget *button, GtkEntry *entry) { - GdkPixbuf *pixbuf; - cairo_surface_t *surface; + GdkTexture *texture; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) { - pixbuf = gdk_pixbuf_new_from_resource ("/org/gtk/libgtk/inspector/logo.png", NULL); - surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, gtk_widget_get_window (button)); - g_object_unref (pixbuf); - - gtk_entry_set_icon_from_surface (entry, GTK_ENTRY_ICON_SECONDARY, surface); - cairo_surface_destroy (surface); + texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/inspector/logo.png"); + gtk_entry_set_icon_from_texture (entry, GTK_ENTRY_ICON_SECONDARY, texture); + g_object_unref (texture); } } @@ -273,10 +269,10 @@ main (int argc, char **argv) gtk_radio_button_join_group (GTK_RADIO_BUTTON (button3), GTK_RADIO_BUTTON (button1)); g_signal_connect (button3, "toggled", G_CALLBACK (set_gicon), entry); gtk_container_add (GTK_CONTAINER (box), button3); - button4 = gtk_radio_button_new_with_label (NULL, "Surface"); + button4 = gtk_radio_button_new_with_label (NULL, "Texture"); gtk_widget_set_valign (button4, GTK_ALIGN_START); gtk_radio_button_join_group (GTK_RADIO_BUTTON (button4), GTK_RADIO_BUTTON (button1)); - g_signal_connect (button4, "toggled", G_CALLBACK (set_surface), entry); + g_signal_connect (button4, "toggled", G_CALLBACK (set_texture), entry); gtk_container_add (GTK_CONTAINER (box), button4); label = gtk_label_new ("Emoji:"); -- 2.30.2