From: Carlos Garcia Campos Date: Tue, 21 Dec 2010 18:08:24 +0000 (+0100) Subject: libview: Port EvView and EvPixbufCache to GtkStyleContext X-Git-Tag: EVINCE_2_91_4~10 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=7d5e358fb59172812ea0a4bf8ee6502405abc58e;p=evince.git libview: Port EvView and EvPixbufCache to GtkStyleContext --- diff --git a/libview/ev-pixbuf-cache.c b/libview/ev-pixbuf-cache.c index ee683545..98719a36 100644 --- a/libview/ev-pixbuf-cache.c +++ b/libview/ev-pixbuf-cache.c @@ -602,17 +602,25 @@ ev_pixbuf_cache_clear_job_sizes (EvPixbufCache *pixbuf_cache, } static void -get_selection_colors (GtkWidget *widget, GdkColor **text, GdkColor **base) +get_selection_colors (GtkWidget *widget, GdkColor *text, GdkColor *base) { - GtkStyle *style = gtk_widget_get_style (widget); - - if (gtk_widget_has_focus (widget)) { - *text = &style->text [GTK_STATE_SELECTED]; - *base = &style->base [GTK_STATE_SELECTED]; - } else { - *text = &style->text [GTK_STATE_ACTIVE]; - *base = &style->base [GTK_STATE_ACTIVE]; - } + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkStateFlags state = 0; + GdkRGBA fg, bg; + + state |= gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE; + + gtk_style_context_get_color (context, state, &fg); + text->pixel = 0; + text->red = CLAMP ((guint) (fg.red * 65535), 0, 65535); + text->green = CLAMP ((guint) (fg.green * 65535), 0, 65535); + text->blue = CLAMP ((guint) (fg.blue * 65535), 0, 65535); + + gtk_style_context_get_background_color (context, state, &bg); + base->pixel = 0; + base->red = CLAMP ((guint) (bg.red * 65535), 0, 65535); + base->green = CLAMP ((guint) (bg.green * 65535), 0, 65535); + base->blue = CLAMP ((guint) (bg.blue * 65535), 0, 65535); } static void @@ -637,14 +645,13 @@ add_job (EvPixbufCache *pixbuf_cache, width, height); if (new_selection_surface_needed (pixbuf_cache, job_info, page, scale)) { - GdkColor *text, *base; + GdkColor text, base; - gtk_widget_ensure_style (pixbuf_cache->view); get_selection_colors (pixbuf_cache->view, &text, &base); ev_job_render_set_selection_info (EV_JOB_RENDER (job_info->job), &(job_info->target_points), job_info->selection_style, - text, base); + &text, &base); } g_signal_connect (job_info->job, "finished", @@ -952,7 +959,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache, */ if (ev_rect_cmp (&(job_info->target_points), &(job_info->selection_points))) { EvRectangle *old_points; - GdkColor *text, *base; + GdkColor text, base; EvRenderContext *rc; EvPage *ev_page; @@ -977,8 +984,6 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache, rc, job_info->selection_style, &(job_info->target_points)); - gtk_widget_ensure_style (pixbuf_cache->view); - get_selection_colors (pixbuf_cache->view, &text, &base); ev_selection_render_selection (EV_SELECTION (pixbuf_cache->document), @@ -986,7 +991,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache, &(job_info->target_points), old_points, job_info->selection_style, - text, base); + &text, &base); job_info->selection_points = job_info->target_points; g_object_unref (rc); ev_document_doc_mutex_unlock (); diff --git a/libview/ev-view.c b/libview/ev-view.c index bdf738f8..971dfe08 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -171,8 +171,7 @@ static gboolean ev_view_enter_notify_event (GtkWidget GdkEventCrossing *event); static gboolean ev_view_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event); -static void ev_view_style_set (GtkWidget *widget, - GtkStyle *old_style); +static void ev_view_style_updated (GtkWidget *widget); static void ev_view_remove_all (EvView *view); static AtkObject *ev_view_get_accessible (GtkWidget *widget); @@ -4182,13 +4181,12 @@ ev_view_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event) } static void -ev_view_style_set (GtkWidget *widget, - GtkStyle *old_style) +ev_view_style_updated (GtkWidget *widget) { if (EV_VIEW (widget)->pixbuf_cache) ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache); - GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style); + GTK_WIDGET_CLASS (ev_view_parent_class)->style_updated (widget); } /*** Drawing ***/ @@ -4199,19 +4197,14 @@ draw_rubberband (EvView *view, const GdkRectangle *rect, gdouble alpha) { - GtkStyle *style; - const GdkColor *fill_color_gdk; - gdouble r, g, b; - - style = gtk_widget_get_style (GTK_WIDGET (view)); - fill_color_gdk = &style->base[GTK_STATE_SELECTED]; - r = fill_color_gdk->red / 65535.; - g = fill_color_gdk->green / 65535.; - b = fill_color_gdk->blue / 65535.; + GtkStyleContext *context; + GdkRGBA color; + context = gtk_widget_get_style_context (GTK_WIDGET (view)); + gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color); cairo_save (cr); - cairo_set_source_rgba (cr, r, g, b, alpha); + cairo_set_source_rgba (cr, color.red, color.green, color.blue, alpha); cairo_rectangle (cr, rect->x - view->scroll_x, rect->y - view->scroll_y, @@ -4219,7 +4212,7 @@ draw_rubberband (EvView *view, cairo_fill_preserve (cr); cairo_set_line_width (cr, 0.5); - cairo_set_source_rgb (cr, r, g, b); + cairo_set_source_rgb (cr, color.red, color.green, color.blue); cairo_stroke (cr); cairo_restore (cr); @@ -4290,13 +4283,11 @@ focus_annotation (EvView *view, doc_rect_to_view_rect (view, page, &mapping->area, &rect); - gtk_paint_focus (gtk_widget_get_style (widget), - cr, - gtk_widget_get_state (widget), - widget, NULL, - rect.x - view->scroll_x, - rect.y - view->scroll_y, - rect.width + 1, rect.height + 1); + gtk_render_focus (gtk_widget_get_style_context (widget), + cr, + rect.x - view->scroll_x, + rect.y - view->scroll_y, + rect.width + 1, rect.height + 1); } static void @@ -4694,7 +4685,7 @@ ev_view_class_init (EvViewClass *class) widget_class->scroll_event = ev_view_scroll_event; widget_class->enter_notify_event = ev_view_enter_notify_event; widget_class->leave_notify_event = ev_view_leave_notify_event; - widget_class->style_set = ev_view_style_set; + widget_class->style_updated = ev_view_style_updated; widget_class->drag_data_get = ev_view_drag_data_get; widget_class->drag_motion = ev_view_drag_motion; widget_class->popup_menu = ev_view_popup_menu;