set custom entry background?



I'm trying to set a custom background for a GtkEntry (as a temporary thing, by way of an alert for invalid input). I can do that fine for gtk 2 using gtk_widget_modify_base(), but am struggling with gtk 3.

Here's what I've come up with so far (omitting error checking and
clean-up for brevity). It doesn't work, no red background appears. Any suggestions gratefully received.

void entry_alert (GtkWidget *entry)
{
    GtkStyleContext *context;
    PangoLayout *layout;
    PangoRectangle r;
    GdkWindow *win;
    cairo_surface_t *cs;
    cairo_t *cr;

    gtk_widget_grab_focus(entry);
    gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);

    layout = gtk_entry_get_layout(GTK_ENTRY(entry));
    pango_layout_get_pixel_extents(layout, &r, NULL);

    win = gtk_widget_get_window(entry);
    cs = gdk_window_create_similar_surface(win,
                                           CAIRO_CONTENT_COLOR,
                                           r.width,
                                           r.height);
    cr = cairo_create(cs);
    cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); /* red */
    cairo_paint(cr);

    context = gtk_widget_get_style_context(entry);
    gtk_render_background(context, cr, r.x, r.y, r.width, r.height);
}

--
Allin Cottrell
Department of Economics
Wake Forest University, NC



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]