2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
5 <chapter id="gtk-migrating-entry-icons">
7 <title>Migrating from SexyIconEntry to GtkEntry</title>
10 GTK+ 2.16 supports showing icons inside a #GtkEntry, similar to
11 SexyIconEntry. Porting from SexyIconEntry to GtkEntry is relatively
12 straightforward. The main difference between the two APIs is that
13 SexyIconEntry uses #GtkImage widgets in a somewhat awkward way as
14 storage vehicles for icons, while GtkEntry allows to specify icons
15 via pixbufs, stock ids, icon names or #GIcons. So, if your code uses
17 <informalexample><programlisting>
18 image = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
19 sexy_icon_entry_set_icon (entry, SEXY_ICON_ENTRY_PRIMARY, image);
20 </programlisting></informalexample>
21 you can get rid of the @image, and directly write:
22 <informalexample><programlisting>
23 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_NEW);
24 </programlisting></informalexample>
28 The signals SexyIconEntry::icon-pressed and SexyIconEntry::icon-released
29 have been renamed to #GtkEntry::icon-press and #GtkEntry::icon-release
30 to avoid problems due to signal name clashes. Also, the signature of the
31 signals has changed from
32 <informalexample><programlisting>
33 void (*icon_pressed) (SexyIconEntry *entry,
34 SexyIconEntryPosition icon_pos,
36 </programlisting></informalexample>
38 <informalexample><programlisting>
39 void (*icon_press) (GtkEntry *entry,
40 GtkEntryIconPosition icon_pos,
41 GdkEventButton *event)
42 </programlisting></informalexample>
43 The new signature has the advantage that the signal handler can use
44 the timestamp of the event, e.g. for passing it to gtk_menu_popup().
45 When adapting an existing signal handler to the new signature, you
46 should note that the button number is easily available as @event->button,
47 as shown in the following example:
48 <informalexample><programlisting>
50 icon_pressed_cb (SexyIconEntry *entry,
51 SexyIconEntryPosition position,
57 if (position == SEXY_ICON_ENTRY_PRIMARY)
58 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
59 button, GDK_CURRENT_TIME);
61 </programlisting></informalexample>
63 <informalexample><programlisting>
65 icon_press_cb (GtkEntry *entry,
66 GtkEntryIconPosition position,
67 GdkEventButton *event,
72 if (position == GTK_ENTRY_ICON_PRIMARY)
73 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
74 event->button, event->time);
76 </programlisting></informalexample>
80 Another difference is that SexyIconEntry offers manual control of
81 the icon prelighting, via sexy_icon_entry_set_icon_highlight().
82 #GtkEntry prelights automatically when appropriate, depending on
83 whether the icon is activatable and sensitive. You should make
84 sure that your icons are properly marked as activatable or nonactivatable
85 and sensitive or insensitive:
88 Sensitive, but non-activatable icons are
89 good for purely informational purposes.
92 Icons should be marked as insensitive if the
93 function that they trigger is currently not available.
99 GtkEntry has no direct equivalent of the special-purpose function
100 sexy_icon_entry_add_clear_button(). If you need this functionality,
101 the following code works:
102 <informalexample><programlisting>
104 icon_pressed_cb (GtkEntry *entry,
106 GdkEventButton *event,
109 if (position == GTK_ENTRY_ICON_SECONDARY)
110 gtk_entry_set_text (entry, "");
114 text_changed_cb (GtkEntry *entry,
120 has_text = gtk_entry_get_text_length (entry) > 0;
121 gtk_entry_set_icon_sensitive (entry,
122 GTK_ENTRY_ICON_SECONDARY,
129 /* Set up the clear icon */
130 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
131 GTK_ENTRY_ICON_SECONDARY,
133 g_signal_connect (entry, "icon-pressed",
134 G_CALLBACK (icon_pressed_cb), NULL);
135 g_signal_connect (entry, "notify::text",
136 G_CALLBACK (text_changed_cb), find_button);
139 </programlisting></informalexample>