Use progress and icon GtkEntry features with GTK+ 2.16

This commit is contained in:
Christian Dywan 2009-04-11 07:05:28 +02:00
parent a9ea07389a
commit 592e55c59b
7 changed files with 54 additions and 38 deletions

View file

@ -864,7 +864,7 @@ static void cm_app_add_browser_cb(MidoriApp *app, MidoriBrowser *browser, Midori
GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_CLEAR);
gtk_icon_entry_set_icon_highlight(GTK_ICON_ENTRY (cmdata->filter_entry),
GTK_ICON_ENTRY_SECONDARY, TRUE);
g_signal_connect(cmdata->filter_entry, "icon_released",
g_signal_connect(cmdata->filter_entry, "icon-release",
G_CALLBACK(cm_filter_entry_clear_icon_released_cb), NULL);
g_signal_connect(cmdata->filter_entry, "changed", G_CALLBACK(cm_filter_entry_changed_cb), cmdata);
g_signal_connect(cmdata->filter_entry, "activate", G_CALLBACK(cm_filter_entry_changed_cb), cmdata);

View file

@ -20,6 +20,24 @@
#include "gtkiconentry.h"
#if GTK_CHECK_VERSION (2, 16, 0)
void
gtk_icon_entry_set_icon_from_pixbuf (GtkEntry* entry,
GtkEntryIconPosition position,
GdkPixbuf* pixbuf)
{
/* Without this ugly hack pixbuf icons don't work */
if (pixbuf)
{
gtk_widget_hide (GTK_WIDGET (entry));
gtk_entry_set_icon_from_pixbuf (entry, position, pixbuf);
gtk_widget_show (GTK_WIDGET (entry));
}
}
#else
#include <string.h>
#if GTK_CHECK_VERSION (2, 14, 0)
@ -61,9 +79,7 @@ typedef struct
GdkCursorType cursor_type;
gboolean custom_cursor;
GtkImageType storage_type;
#if GLIB_CHECK_VERSION (2, 16, 0)
GIcon *gicon;
#endif
gchar *icon_name;
gboolean insensitive;
} EntryIconInfo;
@ -196,17 +212,17 @@ gtk_icon_entry_class_init (GtkIconEntryClass *klass)
G_TYPE_INT);
/**
* GtkIconEntry::icon-released:
* GtkIconEntry::icon-release:
* @entry: The entry on which the signal is emitted.
* @icon_pos: The position of the clicked icon.
* @button: The mouse button clicked.
*
* The ::icon-released signal is emitted on the button release from a
* The ::icon-release signal is emitted on the button release from a
* mouse click.
*/
if (!(signals[ICON_RELEASED] = g_signal_lookup ("icon-released", GTK_TYPE_ENTRY)))
if (!(signals[ICON_RELEASED] = g_signal_lookup ("icon-release", GTK_TYPE_ENTRY)))
signals[ICON_RELEASED] =
g_signal_new ("icon-released",
g_signal_new ("icon-release",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconEntryClass, icon_released),
@ -274,7 +290,6 @@ gtk_icon_entry_class_init (GtkIconEntryClass *klass)
NULL,
GTK_PARAM_WRITABLE));
#if GLIB_CHECK_VERSION (2, 16, 0)
g_object_class_install_property (gobject_class,
PROP_GICON_PRIMARY,
g_param_spec_object ("gicon-primary",
@ -290,7 +305,6 @@ gtk_icon_entry_class_init (GtkIconEntryClass *klass)
P_("GIcon for secondary icon"),
G_TYPE_ICON,
GTK_PARAM_READWRITE));
#endif
g_type_class_add_private (klass, sizeof (GtkIconEntryPrivate));
}
@ -433,7 +447,6 @@ gtk_icon_entry_set_property (GObject *object,
g_value_get_string (value));
break;
#if GLIB_CHECK_VERSION (2, 16, 0)
case PROP_GICON_PRIMARY:
gtk_icon_entry_set_icon_from_gicon (entry,
GTK_ICON_ENTRY_PRIMARY,
@ -445,7 +458,6 @@ gtk_icon_entry_set_property (GObject *object,
GTK_ICON_ENTRY_SECONDARY,
g_value_get_object (value));
break;
#endif
}
}
@ -471,7 +483,6 @@ gtk_icon_entry_get_property (GObject *object,
GTK_ICON_ENTRY_SECONDARY));
break;
#if GLIB_CHECK_VERSION (2, 16, 0)
case PROP_GICON_PRIMARY:
g_value_set_object (value,
gtk_icon_entry_get_gicon (entry,
@ -482,7 +493,6 @@ gtk_icon_entry_get_property (GObject *object,
g_value_set_object (value,
gtk_icon_entry_get_gicon (entry,
GTK_ICON_ENTRY_SECONDARY));
#endif
}
}
@ -1338,8 +1348,6 @@ gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
* instead. If the current icon theme is changed, the icon will be updated
* appropriately.
*/
#if GLIB_CHECK_VERSION (2, 16, 0)
void
gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
@ -1390,7 +1398,6 @@ gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
icon_pos,
pixbuf);
}
#endif
/**
* gtk_icon_entry_set_cursor
@ -1491,9 +1498,6 @@ gtk_icon_entry_get_pixbuf (const GtkIconEntry *entry,
*
* Returns: A #GIcon, or NULL if no icon is set or if the icon is not a GIcon.
*/
#if GLIB_CHECK_VERSION (2, 16, 0)
GIcon *
gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos)
@ -1510,7 +1514,6 @@ gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
return icon_info->storage_type == _GTK_IMAGE_GICON ? icon_info->gicon : NULL;
}
#endif
/**
* gtk_icon_entry_get_icon_highlight
@ -1601,3 +1604,5 @@ gtk_icon_entry_set_icon_sensitive (const GtkIconEntry *icon_entry,
gdk_cursor_unref (cursor);
}
}
#endif

View file

@ -25,14 +25,27 @@
#include <config.h>
#endif
#include <glib.h>
#if GLIB_CHECK_VERSION (2, 16, 0)
#include <gio/gio.h>
#endif
#include <gtk/gtk.h>
G_BEGIN_DECLS
#if GTK_CHECK_VERSION (2, 16, 0)
#define GtkIconEntry GtkEntry
#define GtkIconEntryPosition GtkEntryIconPosition
#define GTK_ICON_ENTRY_PRIMARY GTK_ENTRY_ICON_PRIMARY
#define GTK_ICON_ENTRY_SECONDARY GTK_ENTRY_ICON_SECONDARY
#define GTK_ICON_ENTRY GTK_ENTRY
#define GTK_TYPE_ICON_ENTRY GTK_TYPE_ENTRY
#define gtk_icon_entry_new gtk_entry_new
#define gtk_icon_entry_set_icon_from_stock gtk_entry_set_icon_from_stock
void
gtk_icon_entry_set_icon_from_pixbuf (GtkEntry* entry,
GtkEntryIconPosition position,
GdkPixbuf* pixbuf);
#define gtk_icon_entry_set_icon_highlight gtk_entry_set_icon_activatable
#else
#define GTK_TYPE_ICON_ENTRY (gtk_icon_entry_get_type())
#define GTK_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_ICON_ENTRY, GtkIconEntry))
#define GTK_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_ICON_ENTRY, GtkIconEntryClass))
@ -86,17 +99,15 @@ void gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
const gchar *icon_name);
#if GLIB_CHECK_VERSION (2, 16, 0)
void gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
GIcon *icon);
#endif
GdkPixbuf* gtk_icon_entry_get_pixbuf (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos);
#if GLIB_CHECK_VERSION (2, 16, 0)
GIcon* gtk_icon_entry_get_gicon (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos);
#endif
void gtk_icon_entry_set_icon_highlight (const GtkIconEntry *entry,
GtkIconEntryPosition icon_pos,
@ -117,6 +128,8 @@ void gtk_icon_entry_set_icon_sensitive (const GtkIconEntry *icon_entr
GtkIconEntryPosition icon_pos,
gboolean sensitive);
#endif
G_END_DECLS
#endif /* __GTK_ICON_ENTRY_H__ */

View file

@ -4257,7 +4257,7 @@ midori_browser_init (MidoriBrowser* browser)
GTK_STOCK_CLEAR);
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (browser->find_text),
GTK_ICON_ENTRY_SECONDARY, TRUE);
g_signal_connect (browser->find_text, "icon_released",
g_signal_connect (browser->find_text, "icon-release",
G_CALLBACK (midori_browser_entry_clear_icon_released_cb), NULL);
g_signal_connect (browser->find_text, "activate",
G_CALLBACK (_action_find_next_activate), browser);

View file

@ -847,7 +847,7 @@ midori_location_action_connect_proxy (GtkAction* action,
midori_location_action_key_press_event_cb, action,
"signal::focus-out-event",
midori_location_action_focus_out_event_cb, action,
"signal::icon-released",
"signal::icon-release",
midori_location_action_icon_released_cb, action,
NULL);
}

View file

@ -51,9 +51,7 @@ midori_location_entry_class_init (MidoriLocationEntryClass* class)
}
#define HAVE_ENTRY_PROGRESS 1
#ifdef HAVE_ENTRY_PROGRESS
#if !GTK_CHECK_VERSION (2, 16, 0)
/* GTK+/ GtkEntry internal helper function
Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
@ -345,7 +343,7 @@ entry_expose_event (GtkWidget* entry,
gdk_drawable_get_size (text_area, &width, &height);
if (location_entry->progress > 0.0/* && location_entry->progress < 1.0*/)
if (location_entry->progress > 0.0)
{
gtk_paint_box (entry->style, text_area,
GTK_STATE_SELECTED, GTK_SHADOW_OUT,
@ -362,18 +360,18 @@ void
midori_location_entry_set_progress (MidoriLocationEntry* location_entry,
gdouble progress)
{
#ifdef HAVE_ENTRY_PROGRESS
GtkWidget* child;
#endif
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
location_entry->progress = CLAMP (progress, 0.0, 1.0);
#ifdef HAVE_ENTRY_PROGRESS
child = gtk_bin_get_child (GTK_BIN (location_entry));
#if !GTK_CHECK_VERSION (2, 16, 0)
if (GTK_ENTRY (child)->text_area)
gdk_window_invalidate_rect (GTK_ENTRY (child)->text_area, NULL, FALSE);
#else
gtk_entry_set_progress_fraction (GTK_ENTRY (child), progress);
#endif
}
@ -397,7 +395,7 @@ midori_location_entry_init (MidoriLocationEntry* location_entry)
GTK_ICON_ENTRY_SECONDARY, TRUE);
g_signal_connect_after (entry, "key-press-event",
G_CALLBACK (entry_key_press_event), location_entry);
#ifdef HAVE_ENTRY_PROGRESS
#if !GTK_CHECK_VERSION (2, 16, 0)
g_signal_connect_after (entry, "expose-event",
G_CALLBACK (entry_expose_event), location_entry);
#endif

View file

@ -532,7 +532,7 @@ midori_search_action_connect_proxy (GtkAction* action,
midori_search_action_key_press_event_cb, action,
"signal::focus-out-event",
midori_search_action_focus_out_event_cb, action,
"signal::icon-released",
"signal::icon-release",
midori_search_action_icon_released_cb, action,
"signal::scroll-event",
midori_search_action_scroll_event_cb, action,