Cleanup child indexables in beagle-extract-content. Print timestamp with timezone...
[beagle.git] / glue / search-entry.c
blob9c456f740483faf05ede0841bcf0b2612b98765b
1 #include "search-entry.h"
2 #include "search-entry-watermark.h"
4 #include <librsvg/rsvg.h>
5 #include <string.h>
7 typedef struct {
8 GdkPixbuf *watermark;
9 int width, height;
10 } SearchEntryPrivate;
11 #define SEARCH_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SEARCH_TYPE_ENTRY, SearchEntryPrivate))
13 static void search_entry_class_init (SearchEntryClass *);
14 static void search_entry_init (SearchEntry *);
15 static void search_entry_finalize (GObject *);
17 static void search_entry_realize (GtkWidget *widget);
18 static gboolean search_entry_expose_event (GtkWidget *widget,
19 GdkEventExpose *event);
21 G_DEFINE_TYPE (SearchEntry, search_entry, GTK_TYPE_ENTRY)
23 static void
24 search_entry_class_init (SearchEntryClass *search_entry_class)
26 GObjectClass *g_obj_class = G_OBJECT_CLASS (search_entry_class);
27 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (search_entry_class);
29 g_type_class_add_private (search_entry_class, sizeof (SearchEntryPrivate));
31 widget_class->realize = search_entry_realize;
32 widget_class->expose_event = search_entry_expose_event;
34 g_obj_class->finalize = search_entry_finalize;
37 static void
38 search_entry_init (SearchEntry *entry)
42 static void
43 search_entry_finalize (GObject *object)
45 SearchEntryPrivate *priv = SEARCH_ENTRY_GET_PRIVATE (object);
47 if (priv->watermark)
48 g_object_unref (priv->watermark);
50 G_OBJECT_CLASS (search_entry_parent_class)->finalize (object);
54 static void
55 rsvg_size_callback (int *width, int *height, gpointer user_data)
57 SearchEntryPrivate *priv = user_data;
59 *width = priv->width = priv->height * (double)*width / (double)*height;
60 *height = priv->height;
63 static void
64 search_entry_realize (GtkWidget *widget)
66 SearchEntryPrivate *priv = SEARCH_ENTRY_GET_PRIVATE (widget);
67 int height;
68 GdkColor *gdkcolor;
69 char *svg, color[7];
70 RsvgHandle *rsvg;
72 GTK_WIDGET_CLASS (search_entry_parent_class)->realize (widget);
74 gdk_window_get_geometry (GTK_ENTRY (widget)->text_area,
75 NULL, NULL, NULL, &height, NULL);
77 if (height - 2 == priv->height)
78 return;
79 priv->height = height - 2;
81 gdkcolor = &widget->style->fg[GTK_WIDGET_STATE (widget)];
82 snprintf (color, 6, "%02x%02x%02x",
83 gdkcolor->red >> 8,
84 gdkcolor->green >> 8,
85 gdkcolor->blue >> 8);
86 svg = g_strdup_printf (SEARCH_ENTRY_WATERMARK_SVG, color, color);
88 rsvg = rsvg_handle_new ();
89 rsvg_handle_set_size_callback (rsvg, rsvg_size_callback, priv, NULL);
90 rsvg_handle_write (rsvg, (const guchar *)svg, strlen (svg), NULL);
91 rsvg_handle_close (rsvg, NULL);
92 g_free (svg);
94 if (priv->watermark)
95 g_object_unref (priv->watermark);
96 priv->watermark = rsvg_handle_get_pixbuf (rsvg);
97 rsvg_handle_free (rsvg);
100 static gboolean
101 search_entry_expose_event (GtkWidget *widget, GdkEventExpose *event)
103 SearchEntryPrivate *priv = SEARCH_ENTRY_GET_PRIVATE (widget);
104 GTK_WIDGET_CLASS (search_entry_parent_class)->expose_event (widget, event);
106 if (event->window == GTK_ENTRY (widget)->text_area) {
107 int width, height, x;
109 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) {
110 gdk_drawable_get_size (event->window, &width, &height);
111 x = width - priv->width - 1;
112 } else
113 x = 1;
114 gdk_draw_pixbuf (event->window,
115 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
116 priv->watermark, 0, 0, x, 1,
117 priv->width, priv->height,
118 GDK_RGB_DITHER_NORMAL, 0, 0);
121 return FALSE;
125 GtkWidget *
126 search_entry_new (void)
128 return g_object_new (SEARCH_TYPE_ENTRY, NULL);