diff options
Diffstat (limited to 'libslab/search-entry.c')
-rw-r--r-- | libslab/search-entry.c | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/libslab/search-entry.c b/libslab/search-entry.c index 7ef02e0e..bdab60f6 100644 --- a/libslab/search-entry.c +++ b/libslab/search-entry.c @@ -37,7 +37,11 @@ static void nld_search_entry_init (NldSearchEntry *); static void nld_search_entry_finalize (GObject *); static void nld_search_entry_realize (GtkWidget * widget); +#if GTK_CHECK_VERSION (3, 0, 0) +static gboolean nld_search_entry_draw (GtkWidget * widget, cairo_t * cr); +#else static gboolean nld_search_entry_expose_event (GtkWidget * widget, GdkEventExpose * event); +#endif G_DEFINE_TYPE (NldSearchEntry, nld_search_entry, GTK_TYPE_ENTRY) @@ -49,7 +53,11 @@ static void nld_search_entry_class_init (NldSearchEntryClass * nld_search_entry_ g_type_class_add_private (nld_search_entry_class, sizeof (NldSearchEntryPrivate)); widget_class->realize = nld_search_entry_realize; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->draw = nld_search_entry_draw; +#else widget_class->expose_event = nld_search_entry_expose_event; +#endif g_obj_class->finalize = nld_search_entry_finalize; } @@ -87,16 +95,24 @@ nld_search_entry_realize (GtkWidget * widget) GdkColor *gdkcolor; char *svg, color[7]; RsvgHandle *rsvg; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRectangle text_area; +#endif GTK_WIDGET_CLASS (nld_search_entry_parent_class)->realize (widget); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); + height = text_area.height; +#else gdk_window_get_geometry (GTK_ENTRY (widget)->text_area, NULL, NULL, NULL, &height, NULL); +#endif if (height - 2 == priv->height) return; priv->height = height - 2; - gdkcolor = &widget->style->fg[GTK_WIDGET_STATE (widget)]; + gdkcolor = >k_widget_get_style (widget)->fg[gtk_widget_get_state (widget)]; snprintf (color, 6, "%02x%02x%02x", gdkcolor->red >> 8, gdkcolor->green >> 8, gdkcolor->blue >> 8); svg = g_strdup_printf (SEARCH_ENTRY_WATERMARK_SVG, color, color); @@ -114,31 +130,52 @@ nld_search_entry_realize (GtkWidget * widget) } static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +nld_search_entry_draw (GtkWidget * widget, cairo_t * cr) +#else nld_search_entry_expose_event (GtkWidget * widget, GdkEventExpose * event) +#endif { NldSearchEntryPrivate *priv = NLD_SEARCH_ENTRY_GET_PRIVATE (widget); +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRectangle text_area; + + gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); + GTK_WIDGET_CLASS (nld_search_entry_parent_class)->draw (widget, cr); +#else GTK_WIDGET_CLASS (nld_search_entry_parent_class)->expose_event (widget, event); +#endif +#if !GTK_CHECK_VERSION (3, 0, 0) if (event->window == GTK_ENTRY (widget)->text_area) { +#endif int width, height, x; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) { - #if GTK_CHECK_VERSION(3, 0, 0) - width = gdk_window_get_width(event->window); - height = gdk_window_get_height(event->window); - #else - gdk_drawable_get_size(event->window, &width, &height); - #endif +#if GTK_CHECK_VERSION(3, 0, 0) + width = text_area.width; + height = text_area.height; +#else + gdk_drawable_get_size(event->window, &width, &height); +#endif x = width - priv->width - 1; } else x = 1; +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_pixbuf (cr, priv->watermark, x, 1); + cairo_paint (cr); +#else gdk_draw_pixbuf (event->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], priv->watermark, 0, 0, x, 1, priv->width, priv->height, GDK_RGB_DITHER_NORMAL, 0, 0); +#endif + +#if !GTK_CHECK_VERSION (3, 0, 0) } +#endif return FALSE; } |