aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/widgets/Makefile.am2
-rw-r--r--lib/widgets/ephy-icon-entry.c342
-rw-r--r--lib/widgets/ephy-icon-entry.h74
-rw-r--r--lib/widgets/ephy-location-entry.c151
-rw-r--r--lib/widgets/testiconentry.c47
5 files changed, 524 insertions, 92 deletions
diff --git a/lib/widgets/Makefile.am b/lib/widgets/Makefile.am
index 92c20183d..adb819b50 100644
--- a/lib/widgets/Makefile.am
+++ b/lib/widgets/Makefile.am
@@ -1,6 +1,8 @@
noinst_LTLIBRARIES = libephywidgets.la
libephywidgets_la_SOURCES = \
+ ephy-icon-entry.c \
+ ephy-icon-entry.h \
ephy-location-entry.c \
ephy-location-entry.h \
ephy-node-view.c \
diff --git a/lib/widgets/ephy-icon-entry.c b/lib/widgets/ephy-icon-entry.c
new file mode 100644
index 000000000..5d871e52e
--- /dev/null
+++ b/lib/widgets/ephy-icon-entry.c
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2003, 2004, 2005 Christian Persch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Adapted and modified from gtk+ code:
+ *
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Modified by the GTK+ Team and others 1997-2005. See the AUTHORS
+ * file in the gtk+ distribution for a list of people on the GTK+ Team.
+ * See the ChangeLog in the gtk+ distribution files for a list of changes.
+ * These files are distributed with GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ *
+ * $Id$
+ */
+
+#include "config.h"
+
+#include "ephy-icon-entry.h"
+
+#include <gtk/gtkentry.h>
+#include <gtk/gtkbox.h>
+#include <gtk/gtkhbox.h>
+
+#define EPHY_ICON_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ICON_ENTRY, EphyIconEntryPrivate))
+
+struct _EphyIconEntryPrivate
+{
+ GtkWidget *hbox;
+};
+
+static GtkWidgetClass *parent_class = NULL;
+
+/* private helper functions */
+
+static gboolean
+entry_focus_change_cb (GtkWidget *widget,
+ GdkEventFocus *event,
+ GtkWidget *entry)
+{
+ gtk_widget_queue_draw (entry);
+
+ return FALSE;
+}
+
+static void
+ephy_icon_entry_paint (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+ GtkWidget *entry_widget = entry->entry;
+ int x = 0, y = 0, width, height, focus_width;
+ gboolean interior_focus;
+
+ gtk_widget_style_get (entry_widget,
+ "interior-focus", &interior_focus,
+ "focus-line-width", &focus_width,
+ NULL);
+
+ gdk_drawable_get_size (widget->window, &width, &height);
+
+ if (GTK_WIDGET_HAS_FOCUS (entry_widget) && !interior_focus)
+ {
+ x += focus_width;
+ y += focus_width;
+ width -= 2 * focus_width;
+ height -= 2 * focus_width;
+ }
+
+ gtk_paint_flat_box (entry_widget->style, widget->window,
+ GTK_WIDGET_STATE (entry_widget), GTK_SHADOW_NONE,
+ NULL, entry_widget, "entry_bg",
+ /* FIXME: was 0, 0 in gtk_entry_expose, but I think this is correct: */
+ x, y, width, height);
+
+ gtk_paint_shadow (entry_widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_IN,
+ NULL, entry_widget, "entry",
+ x, y, width, height);
+
+ if (GTK_WIDGET_HAS_FOCUS (entry_widget) && !interior_focus)
+ {
+ x -= focus_width;
+ y -= focus_width;
+ width += 2 * focus_width;
+ height += 2 * focus_width;
+
+ gtk_paint_focus (entry_widget->style, widget->window,
+ GTK_WIDGET_STATE (entry_widget),
+ NULL, entry_widget, "entry",
+ /* FIXME: was 0, 0 in gtk_entry_draw_frame, but I think this is correct: */
+ x, y, width, height);
+ }
+}
+
+/* Class implementation */
+
+static void
+ephy_icon_entry_init (EphyIconEntry *entry)
+{
+ EphyIconEntryPrivate *priv;
+ GtkWidget *widget = (GtkWidget *) entry;
+
+ priv = entry->priv = EPHY_ICON_ENTRY_GET_PRIVATE (entry);
+
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
+
+ priv->hbox = gtk_hbox_new (FALSE, /* FIXME */ 0);
+ gtk_container_add (GTK_CONTAINER (entry), priv->hbox);
+
+ entry->entry = gtk_entry_new ();
+ gtk_entry_set_has_frame (GTK_ENTRY (entry->entry), FALSE);
+ gtk_box_pack_start (GTK_BOX (priv->hbox), entry->entry, TRUE, TRUE, /* FIXME */ 0);
+
+ /* We need to queue a redraw when focus changes, to comply with themes
+ * (like Clearlooks) which draw focused and unfocused entries differently.
+ */
+ g_signal_connect_after (entry->entry, "focus-in-event",
+ G_CALLBACK (entry_focus_change_cb), entry);
+ g_signal_connect_after (entry->entry, "focus-out-event",
+ G_CALLBACK (entry_focus_change_cb), entry);
+}
+
+static void
+ephy_icon_entry_realize (GtkWidget *widget)
+{
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ gint border_width;
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ border_width = GTK_CONTAINER (widget)->border_width;
+
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - 2 * border_width;
+ attributes.height = widget->allocation.height - 2 * border_width;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.event_mask = gtk_widget_get_events (widget)
+ | GDK_EXPOSURE_MASK;
+
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+ widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (widget->window, widget);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+
+ gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+}
+
+static void
+ephy_icon_entry_get_borders (GtkWidget *widget,
+ GtkWidget *entry,
+ int *xborder,
+ int *yborder)
+{
+ int focus_width;
+
+ g_return_if_fail (entry->style != NULL);
+
+ gtk_widget_style_get (entry,
+ "focus-line-width", &focus_width,
+ NULL);
+
+ *xborder = widget->style->xthickness;
+ *yborder = widget->style->ythickness;
+
+ /* While GtkEntry does this only when !interior-focus, we need this even
+ * with interior-focus, since otherwise we end up being too small.
+ */
+ *xborder += focus_width;
+ *yborder += focus_width;
+}
+
+static void
+ephy_icon_entry_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+ GtkContainer *container = GTK_CONTAINER (widget);
+ GtkBin *bin = GTK_BIN (widget);
+ int xborder, yborder;
+
+ requisition->width = requisition->height = container->border_width * 2;
+
+ gtk_widget_ensure_style (entry->entry);
+ ephy_icon_entry_get_borders (widget, entry->entry, &xborder, &yborder);
+
+ if (GTK_WIDGET_VISIBLE (bin->child))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (bin->child, &child_requisition);
+ requisition->width += child_requisition.width;
+ requisition->height += child_requisition.height;
+ }
+
+ requisition->width += 2 * xborder;
+ requisition->height += 2 * yborder;
+}
+
+static void
+ephy_icon_entry_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EphyIconEntry *entry = EPHY_ICON_ENTRY (widget);
+ GtkContainer *container = GTK_CONTAINER (widget);
+ GtkBin *bin = GTK_BIN (widget);
+ GtkAllocation child_allocation;
+ int xborder, yborder;
+
+ widget->allocation = *allocation;
+
+ ephy_icon_entry_get_borders (widget, entry->entry, &xborder, &yborder);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ child_allocation.x = container->border_width;
+ child_allocation.y = container->border_width;
+ child_allocation.width = MAX (allocation->width - container->border_width * 2, 0);
+ child_allocation.height = MAX (allocation->height - container->border_width * 2, 0);
+
+ gdk_window_move_resize (widget->window,
+ allocation->x + child_allocation.x,
+ allocation->y + child_allocation.y,
+ child_allocation.width,
+ child_allocation.height);
+ }
+
+ child_allocation.x = container->border_width + xborder;
+ child_allocation.y = container->border_width + yborder;
+ child_allocation.width = MAX (allocation->width - (container->border_width + xborder) * 2, 0);
+ child_allocation.height = MAX (allocation->height - (container->border_width + yborder) * 2, 0);
+
+ gtk_widget_size_allocate (bin->child, &child_allocation);
+}
+
+static gboolean
+ephy_icon_entry_expose (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ if (GTK_WIDGET_DRAWABLE (widget) &&
+ event->window == widget->window)
+ {
+ ephy_icon_entry_paint (widget, event);
+ }
+
+ return parent_class->expose_event (widget, event);
+}
+
+static void
+ephy_icon_entry_class_init (EphyIconEntryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ parent_class = GTK_WIDGET_CLASS (g_type_class_peek_parent (klass));
+
+ widget_class->realize = ephy_icon_entry_realize;
+ widget_class->size_request = ephy_icon_entry_size_request;
+ widget_class->size_allocate = ephy_icon_entry_size_allocate;
+ widget_class->expose_event = ephy_icon_entry_expose;
+
+ g_type_class_add_private (object_class, sizeof (EphyIconEntryPrivate));
+}
+
+GType
+ephy_icon_entry_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (EphyIconEntryClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) ephy_icon_entry_class_init,
+ NULL,
+ NULL,
+ sizeof (EphyIconEntry),
+ 0,
+ (GInstanceInitFunc) ephy_icon_entry_init
+ };
+
+ type = g_type_register_static (GTK_TYPE_BIN,
+ "EphyIconEntry",
+ &our_info, 0);
+ }
+
+ return type;
+}
+
+/* public functions */
+
+GtkWidget *
+ephy_icon_entry_new (void)
+{
+ return GTK_WIDGET (g_object_new (EPHY_TYPE_ICON_ENTRY, NULL));
+}
+
+void
+ephy_icon_entry_pack_widget (EphyIconEntry *entry,
+ GtkWidget *widget,
+ gboolean start)
+{
+ EphyIconEntryPrivate *priv;
+
+ g_return_if_fail (EPHY_IS_ICON_ENTRY (entry));
+
+ priv = entry->priv;
+
+ if (start)
+ {
+ gtk_box_pack_start (GTK_BOX (priv->hbox), widget, FALSE, FALSE, /* FIXME */ 2);
+ gtk_box_reorder_child (GTK_BOX (priv->hbox), widget, 0);
+ }
+ else
+ {
+ gtk_box_pack_end (GTK_BOX (priv->hbox), widget, FALSE, FALSE, /* FIXME */ 2);
+ }
+}
diff --git a/lib/widgets/ephy-icon-entry.h b/lib/widgets/ephy-icon-entry.h
new file mode 100644
index 000000000..5077a0ecd
--- /dev/null
+++ b/lib/widgets/ephy-icon-entry.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2003, 2004, 2005 Christian Persch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Adapted and modified from gtk+ code:
+ *
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file in the gtk+ distribution for a list of people on the GTK+ Team.
+ * See the ChangeLog in the gtk+ distribution files for a list of changes.
+ * These files are distributed with GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ *
+ * $Id$
+ */
+
+#ifndef EPHY_ICON_ENTRY_H
+#define EPHY_ICON_ENTRY_H
+
+#include <gtk/gtkbin.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ICON_ENTRY (ephy_icon_entry_get_type())
+#define EPHY_ICON_ENTRY(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_ICON_ENTRY, EphyIconEntry))
+#define EPHY_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_ICON_ENTRY, EphyIconEntryClass))
+#define EPHY_IS_ICON_ENTRY(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_ICON_ENTRY))
+#define EPHY_IS_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_ICON_ENTRY))
+#define EPHY_ICON_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ICON_ENTRY, EphyIconEntryClass))
+
+typedef struct _EphyIconEntryClass EphyIconEntryClass;
+typedef struct _EphyIconEntry EphyIconEntry;
+typedef struct _EphyIconEntryPrivate EphyIconEntryPrivate;
+
+struct _EphyIconEntryClass
+{
+ GtkBinClass parent_class;
+};
+
+struct _EphyIconEntry
+{
+ GtkBin parent_object;
+
+ /*< public >*/
+ GtkWidget *entry;
+
+ /*< private >*/
+ EphyIconEntryPrivate *priv;
+};
+
+GType ephy_icon_entry_get_type (void);
+
+GtkWidget *ephy_icon_entry_new (void);
+
+void ephy_icon_entry_pack_widget (EphyIconEntry *entry,
+ GtkWidget *widget,
+ gboolean start);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index c9c43eada..483361704 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -23,6 +23,7 @@
#include "config.h"
+#include "ephy-icon-entry.h"
#include "ephy-tree-model-node.h"
#include "ephy-location-entry.h"
#include "ephy-marshal.h"
@@ -48,7 +49,6 @@
#include <gtk/gtkvbox.h>
#include <gtk/gtkimagemenuitem.h>
#include <gtk/gtkseparatormenuitem.h>
-#include <gtk/gtkframe.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkclipboard.h>
@@ -59,8 +59,7 @@
struct _EphyLocationEntryPrivate
{
GtkTooltips *tips;
- GtkWidget *ebox;
- GtkWidget *entry;
+ EphyIconEntry *icon_entry;
GtkWidget *icon_ebox;
GtkWidget *icon;
GtkWidget *lock_ebox;
@@ -156,7 +155,8 @@ ephy_location_entry_set_tooltip (GtkToolItem *tool_item,
EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (tool_item);
EphyLocationEntryPrivate *priv = entry->priv;
- gtk_tooltips_set_tip (tooltips, priv->entry, tip_text, tip_private);
+ gtk_tooltips_set_tip (tooltips, priv->icon_entry->entry,
+ tip_text, tip_private);
return TRUE;
}
@@ -239,7 +239,7 @@ update_address_state (EphyLocationEntry *entry)
EphyLocationEntryPrivate *priv = entry->priv;
const char *text;
- text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
+ text = gtk_entry_get_text (GTK_ENTRY (priv->icon_entry->entry));
priv->original_address = text != NULL &&
g_str_hash (text) == priv->hash;
}
@@ -401,16 +401,17 @@ static gboolean
match_selected_cb (GtkEntryCompletion *completion,
GtkTreeModel *model,
GtkTreeIter *iter,
- EphyLocationEntry *le)
+ EphyLocationEntry *entry)
{
+ EphyLocationEntryPrivate *priv = entry->priv;
char *item = NULL;
gtk_tree_model_get (model, iter,
- le->priv->action_col, &item, -1);
+ priv->action_col, &item, -1);
if (item == NULL) return FALSE;
- ephy_location_entry_set_location (le, item, NULL);
- g_signal_emit_by_name (le->priv->entry, "activate");
+ ephy_location_entry_set_location (entry, item, NULL);
+ g_signal_emit_by_name (priv->icon_entry->entry, "activate");
g_free (item);
@@ -470,7 +471,7 @@ entry_clear_activate_cb (GtkMenuItem *item,
EphyLocationEntryPrivate *priv = entry->priv;
priv->user_changed = FALSE;
- gtk_entry_set_text (GTK_ENTRY (priv->entry), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->icon_entry->entry), "");
priv->user_changed = TRUE;
}
@@ -484,6 +485,7 @@ entry_populate_popup_cb (GtkEntry *entry,
GtkWidget *menuitem;
GList *children, *item;
int pos = 0, sep = 0;
+ gboolean is_editable;
/* Clear and Copy mnemonics conflict, make custom menuitem */
image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
@@ -497,8 +499,8 @@ entry_populate_popup_cb (GtkEntry *entry,
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(menuitem), image);
g_signal_connect (menuitem , "activate",
G_CALLBACK (entry_clear_activate_cb), lentry);
- gtk_widget_set_sensitive (menuitem,
- gtk_editable_get_editable (GTK_EDITABLE (priv->entry)));
+ is_editable = gtk_editable_get_editable (GTK_EDITABLE (priv->icon_entry->entry));
+ gtk_widget_set_sensitive (menuitem, is_editable);
gtk_widget_show (menuitem);
/* search for the 2nd separator (the one after Select All) in the context
@@ -563,40 +565,10 @@ lock_button_press_event_cb (GtkWidget *ebox,
}
static void
-modify_background (EphyLocationEntry *entry)
-{
- EphyLocationEntryPrivate *priv = entry->priv;
-
- if (priv->entry->style == NULL || !GTK_WIDGET_REALIZED (priv->ebox)) return;
-
- gtk_widget_modify_bg (priv->ebox, GTK_STATE_NORMAL,
- &priv->entry->style->base[GTK_STATE_NORMAL]);
-}
-
-static void
-entry_style_set_cb (GtkWidget *widget,
- GtkStyle *previous_style,
- EphyLocationEntry *entry)
-{
- LOG ("entry_style_set_cb");
-
- modify_background (entry);
-}
-
-static void
-entry_realize_cb (GtkWidget *widget,
- EphyLocationEntry *entry)
-{
- LOG ("entry_realize_cb");
-
- modify_background (entry);
-}
-
-static void
ephy_location_entry_construct_contents (EphyLocationEntry *entry)
{
EphyLocationEntryPrivate *priv = entry->priv;
- GtkWidget *alignment, *frame, *hbox;
+ GtkWidget *alignment;
LOG ("EphyLocationEntry constructing contents %p", entry);
@@ -604,22 +576,13 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 1, 1);
gtk_container_add (GTK_CONTAINER (entry), alignment);
- frame = gtk_frame_new (NULL);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (alignment), frame);
-
- priv->ebox = gtk_event_box_new ();
- gtk_container_set_border_width (GTK_CONTAINER (priv->ebox), 0);
- gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->ebox), TRUE);
- gtk_container_add (GTK_CONTAINER (frame), priv->ebox);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_container_add (GTK_CONTAINER (priv->ebox), hbox);
+ priv->icon_entry = EPHY_ICON_ENTRY (ephy_icon_entry_new ());
+ gtk_container_add (GTK_CONTAINER (alignment),
+ GTK_WIDGET (priv->icon_entry));
priv->icon_ebox = gtk_event_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (priv->icon_ebox), 2);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->icon_ebox), FALSE);
- gtk_box_pack_start (GTK_BOX (hbox), priv->icon_ebox, FALSE, FALSE, 2);
gtk_drag_source_set (priv->icon_ebox, GDK_BUTTON1_MASK,
url_drag_types, G_N_ELEMENTS (url_drag_types),
GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK);
@@ -629,44 +592,38 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
priv->icon = gtk_image_new ();
gtk_container_add (GTK_CONTAINER (priv->icon_ebox), priv->icon);
- priv->entry = gtk_entry_new ();
- gtk_entry_set_has_frame (GTK_ENTRY (priv->entry), FALSE);
- gtk_box_pack_start (GTK_BOX (hbox), priv->entry, TRUE, TRUE, 0);
+ ephy_icon_entry_pack_widget (priv->icon_entry, priv->icon_ebox, TRUE);
priv->lock_ebox = gtk_event_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (priv->lock_ebox), 2);
- gtk_widget_add_events (priv->lock_ebox, GDK_BUTTON_PRESS_MASK);
+ gtk_widget_add_events (priv->lock_ebox, GDK_BUTTON_PRESS_MASK);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->lock_ebox), FALSE);
- gtk_box_pack_end (GTK_BOX (hbox), priv->lock_ebox, FALSE, FALSE, 2);
priv->lock = gtk_image_new_from_stock (STOCK_LOCK_INSECURE,
GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (priv->lock_ebox), priv->lock);
- gtk_widget_show_all (alignment);
-
- /* monitor entry style so we can set the background behind the icons */
- g_signal_connect_after (priv->entry, "style-set",
- G_CALLBACK (entry_style_set_cb), entry);
- g_signal_connect_after (priv->entry, "realize",
- G_CALLBACK (entry_realize_cb), entry);
+ ephy_icon_entry_pack_widget (priv->icon_entry, priv->lock_ebox, FALSE);
- g_signal_connect (priv->icon_ebox, "drag_data_get",
+ g_signal_connect (priv->icon_ebox, "drag-data-get",
G_CALLBACK (favicon_drag_data_get_cb), entry);
- g_signal_connect (priv->entry, "populate_popup",
+ g_signal_connect (priv->lock_ebox, "button-press-event",
+ G_CALLBACK (lock_button_press_event_cb), entry);
+
+ g_signal_connect (priv->icon_entry->entry, "populate_popup",
G_CALLBACK (entry_populate_popup_cb), entry);
- g_signal_connect (priv->entry, "key-press-event",
+ g_signal_connect (priv->icon_entry->entry, "key-press-event",
G_CALLBACK (entry_key_press_cb), entry);
- g_signal_connect (priv->entry, "button_press_event",
+ g_signal_connect (priv->icon_entry->entry, "button-press-event",
G_CALLBACK (entry_button_press_cb), entry);
- g_signal_connect (priv->entry, "changed",
+ g_signal_connect (priv->icon_entry->entry, "changed",
G_CALLBACK (editable_changed_cb), entry);
- g_signal_connect (priv->entry, "drag_motion",
+ g_signal_connect (priv->icon_entry->entry, "drag-motion",
G_CALLBACK (entry_drag_motion_cb), entry);
- g_signal_connect (priv->entry, "drag_drop",
+ g_signal_connect (priv->icon_entry->entry, "drag-drop",
G_CALLBACK (entry_drag_drop_cb), entry);
- g_signal_connect (priv->lock_ebox, "button-press-event",
- G_CALLBACK (lock_button_press_event_cb), entry);
+
+ gtk_widget_show_all (alignment);
}
static void
@@ -721,6 +678,7 @@ ephy_location_entry_set_completion (EphyLocationEntry *le,
guint keywords_col,
guint relevance_col)
{
+ EphyLocationEntryPrivate *priv = le->priv;
GtkTreeModel *sort_model;
GtkEntryCompletion *completion;
GtkCellRenderer *cell;
@@ -749,7 +707,7 @@ ephy_location_entry_set_completion (EphyLocationEntry *le,
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
cell, "text", text_col);
- gtk_entry_set_completion (GTK_ENTRY (le->priv->entry), completion);
+ gtk_entry_set_completion (GTK_ENTRY (priv->icon_entry->entry), completion);
g_object_unref (completion);
}
@@ -771,17 +729,19 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
* bug #155824. So we save the selection iff the clipboard was owned by
* the location entry.
*/
- if (GTK_WIDGET_REALIZED (priv->entry))
+ if (GTK_WIDGET_REALIZED (GTK_WIDGET (priv->icon_entry)))
{
- clipboard = gtk_widget_get_clipboard (priv->entry,
+ GtkWidget *gtkentry = priv->icon_entry->entry;
+
+ clipboard = gtk_widget_get_clipboard (gtkentry,
GDK_SELECTION_PRIMARY);
g_return_if_fail (clipboard != NULL);
- if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (priv->entry) &&
- gtk_editable_get_selection_bounds (GTK_EDITABLE (priv->entry),
+ if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gtkentry) &&
+ gtk_editable_get_selection_bounds (GTK_EDITABLE (gtkentry),
&start, &end))
{
- selection = gtk_editable_get_chars (GTK_EDITABLE (priv->entry),
+ selection = gtk_editable_get_chars (GTK_EDITABLE (gtkentry),
start, end);
}
}
@@ -803,7 +763,7 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
priv->hash = g_str_hash (address);
priv->user_changed = FALSE;
- gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+ gtk_entry_set_text (GTK_ENTRY (priv->icon_entry->entry), text);
priv->user_changed = TRUE;
update_favicon (entry);
@@ -820,9 +780,11 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
}
const char *
-ephy_location_entry_get_location (EphyLocationEntry *le)
+ephy_location_entry_get_location (EphyLocationEntry *entry)
{
- return gtk_entry_get_text (GTK_ENTRY (le->priv->entry));
+ EphyLocationEntryPrivate *priv = entry->priv;
+
+ return gtk_entry_get_text (GTK_ENTRY (priv->icon_entry->entry));
}
gboolean
@@ -835,7 +797,7 @@ ephy_location_entry_reset (EphyLocationEntry *entry)
g_signal_emit (entry, signals[GET_LOCATION], 0, &url);
text = url != NULL ? url : "";
- old_text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
+ old_text = gtk_entry_get_text (GTK_ENTRY (priv->icon_entry->entry));
old_text = old_text != NULL ? old_text : "";
retval = g_str_hash (text) != g_str_hash (old_text);
@@ -847,22 +809,25 @@ ephy_location_entry_reset (EphyLocationEntry *entry)
}
void
-ephy_location_entry_activate (EphyLocationEntry *le)
+ephy_location_entry_activate (EphyLocationEntry *entry)
{
+ EphyLocationEntryPrivate *priv = entry->priv;
GtkWidget *toplevel;
- toplevel = gtk_widget_get_toplevel (le->priv->entry);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
- gtk_editable_select_region (GTK_EDITABLE(le->priv->entry),
+ gtk_editable_select_region (GTK_EDITABLE(priv->icon_entry->entry),
0, -1);
gtk_window_set_focus (GTK_WINDOW(toplevel),
- le->priv->entry);
+ priv->icon_entry->entry);
}
GtkWidget *
ephy_location_entry_get_entry (EphyLocationEntry *entry)
{
- return entry->priv->entry;
+ EphyLocationEntryPrivate *priv = entry->priv;
+
+ return priv->icon_entry->entry;
}
void
@@ -885,7 +850,9 @@ void
ephy_location_entry_set_show_lock (EphyLocationEntry *entry,
gboolean show_lock)
{
- g_object_set (entry->priv->lock_ebox, "visible", show_lock, NULL);
+ EphyLocationEntryPrivate *priv = entry->priv;
+
+ g_object_set (priv->lock_ebox, "visible", show_lock, NULL);
}
void
diff --git a/lib/widgets/testiconentry.c b/lib/widgets/testiconentry.c
new file mode 100644
index 000000000..622f3ef07
--- /dev/null
+++ b/lib/widgets/testiconentry.c
@@ -0,0 +1,47 @@
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gtk/gtkstock.h>
+
+#include "ephy-icon-entry.h"
+#include "ephy-icon-entry.c"
+
+int main(int argc, char **argv)
+{
+ GtkWidget *window, *vbox, *entry, *image;
+ GtkTooltips *tips;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ vbox = gtk_vbox_new (0, FALSE);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 12);
+
+ entry = ephy_icon_entry_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 10);
+ gtk_entry_set_text (GTK_ENTRY (EPHY_ICON_ENTRY (entry)->entry), "Icon Entry");
+
+ image = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
+ ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry), image, TRUE);
+ image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
+ ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry), image, TRUE);
+ image = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU);
+ ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry), image, TRUE);
+ image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
+ ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry), image, FALSE);
+ image = gtk_image_new_from_stock (GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU);
+ ephy_icon_entry_pack_widget (EPHY_ICON_ENTRY (entry), image, FALSE);
+
+ entry = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 10);
+ gtk_entry_set_text (GTK_ENTRY (entry), "Normal entry");
+
+ gtk_widget_show_all (window);
+
+ g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_main ();
+
+ return 0;
+}