1 #include "search-entry.h"
2 #include "search-entry-watermark.h"
4 #include <librsvg/rsvg.h>
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
)
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
;
38 search_entry_init (SearchEntry
*entry
)
43 search_entry_finalize (GObject
*object
)
45 SearchEntryPrivate
*priv
= SEARCH_ENTRY_GET_PRIVATE (object
);
48 g_object_unref (priv
->watermark
);
50 G_OBJECT_CLASS (search_entry_parent_class
)->finalize (object
);
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
;
64 search_entry_realize (GtkWidget
*widget
)
66 SearchEntryPrivate
*priv
= SEARCH_ENTRY_GET_PRIVATE (widget
);
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
)
79 priv
->height
= height
- 2;
81 gdkcolor
= &widget
->style
->fg
[GTK_WIDGET_STATE (widget
)];
82 snprintf (color
, 6, "%02x%02x%02x",
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
);
95 g_object_unref (priv
->watermark
);
96 priv
->watermark
= rsvg_handle_get_pixbuf (rsvg
);
97 rsvg_handle_free (rsvg
);
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;
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);
126 search_entry_new (void)
128 return g_object_new (SEARCH_TYPE_ENTRY
, NULL
);