diff options
| author | Alex Valavanis <valavanisalex@gmail.com> | 2012-06-24 23:19:00 +0000 |
|---|---|---|
| committer | Alex Valavanis <valavanisalex@gmail.com> | 2012-06-24 23:19:00 +0000 |
| commit | 03f70d60a8180b2a12ade8000a5470ff3a8d1e00 (patch) | |
| tree | 5a4efcadea1bdfa044978b3018ebeb09a6993f25 /src | |
| parent | Use orientable widgets in GTK+ 3 build (diff) | |
| download | inkscape-03f70d60a8180b2a12ade8000a5470ff3a8d1e00.tar.gz inkscape-03f70d60a8180b2a12ade8000a5470ff3a8d1e00.zip | |
Migrate some widgets to GtkStyleContext
(bzr r11513)
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/sp-canvas.cpp | 22 | ||||
| -rw-r--r-- | src/widgets/eek-preview.cpp | 73 | ||||
| -rw-r--r-- | src/widgets/icon.cpp | 8 | ||||
| -rw-r--r-- | src/widgets/ruler.cpp | 41 | ||||
| -rw-r--r-- | src/widgets/sp-color-slider.cpp | 54 |
5 files changed, 126 insertions, 72 deletions
diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 74c39f580..4e01ada36 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -1438,9 +1438,11 @@ void SPCanvasImpl::realize(GtkWidget *widget) if ( prefs->getBool("/options/useextinput/value", true) ) gtk_widget_set_events(widget, attributes.event_mask); +#if !GTK_CHECK_VERSION(3,0,0) + // This does nothing in GTK+ 3 GtkStyle *style = gtk_widget_get_style (widget); - gtk_widget_set_style (widget, gtk_style_attach (style, window)); +#endif gtk_widget_set_realized (widget, TRUE); } @@ -1492,8 +1494,9 @@ void SPCanvasImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation) gtk_widget_get_allocation (widget, &widg_allocation); - Geom::IntRect old_area = Geom::IntRect::from_xywh(canvas->x0, canvas->y0, - widg_allocation.width, widg_allocation.height); +// Geom::IntRect old_area = Geom::IntRect::from_xywh(canvas->x0, canvas->y0, +// widg_allocation.width, widg_allocation.height); + Geom::IntRect new_area = Geom::IntRect::from_xywh(canvas->x0, canvas->y0, allocation->width, allocation->height); @@ -1882,7 +1885,6 @@ int SPCanvasImpl::handleMotion(GtkWidget *widget, GdkEventMotion *event) void SPCanvasImpl::sp_canvas_paint_single_buffer(SPCanvas *canvas, Geom::IntRect const &paint_rect, Geom::IntRect const &canvas_rect, int /*sw*/) { GtkWidget *widget = GTK_WIDGET (canvas); - GtkStyle *style; // Mark the region clean sp_canvas_mark_rect(canvas, paint_rect, 0); @@ -1918,8 +1920,18 @@ void SPCanvasImpl::sp_canvas_paint_single_buffer(SPCanvas *canvas, Geom::IntRect //cairo_stroke_preserve(buf.ct); //cairo_clip(buf.ct); - style = gtk_widget_get_style (widget); +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context(widget); + GdkRGBA color; + gtk_style_context_get_background_color(context, + gtk_widget_get_state_flags(widget), + &color); + gdk_cairo_set_source_rgba(buf.ct, &color); +#else + GtkStyle *style = gtk_widget_get_style (widget); gdk_cairo_set_source_color(buf.ct, &style->bg[GTK_STATE_NORMAL]); +#endif + cairo_set_operator(buf.ct, CAIRO_OPERATOR_SOURCE); //cairo_rectangle(buf.ct, 0, 0, paint_rect.width(), paint_rec.height()); cairo_paint(buf.ct); diff --git a/src/widgets/eek-preview.cpp b/src/widgets/eek-preview.cpp index f6c0f99ce..595c289f2 100644 --- a/src/widgets/eek-preview.cpp +++ b/src/widgets/eek-preview.cpp @@ -37,6 +37,9 @@ # include "config.h" #endif +#include <algorithm> +using std::min; + #include <gtk/gtk.h> #include "eek-preview.h" @@ -222,7 +225,6 @@ static gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* /* static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) { GtkStyle* style = gtk_widget_get_style(widget); - GdkWindow* window = gtk_widget_get_window(widget); GtkAllocation allocation; gtk_widget_get_allocation (widget, &allocation); EekPreview* preview = EEK_PREVIEW(widget); @@ -231,15 +233,20 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) gint insetY = 0; #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_flat_box( style, - cr, - (GtkStateType)gtk_widget_get_state(widget), - GTK_SHADOW_NONE, - widget, - NULL, - 0, 0, - allocation.width, allocation.height); + GtkStyleContext *context = gtk_widget_get_style_context(widget); + + gtk_render_frame(context, + cr, + 0, 0, + allocation.width, allocation.height); + + gtk_render_background(context, + cr, + 0, 0, + allocation.width, allocation.height); #else + GdkWindow* window = gtk_widget_get_window(widget); + gtk_paint_flat_box( style, window, (GtkStateType)gtk_widget_get_state(widget), @@ -311,17 +318,12 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) if ( preview->_linked & PREVIEW_LINK_IN ) { #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_arrow( style, + gtk_render_arrow(context, cr, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_IN, - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_DOWN, - FALSE, + G_PI, // Down-pointing arrow area.x, area.y, - area.width, area.height - ); + min(area.width, area.height) + ); #else gtk_paint_arrow( style, window, @@ -345,17 +347,12 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) } #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_arrow( style, + gtk_render_arrow(context, cr, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_DOWN, - FALSE, + G_PI, // Down-pointing arrow otherArea.x, otherArea.y, - otherArea.width, otherArea.height - ); + min(otherArea.width, otherArea.height) + ); #else gtk_paint_arrow( style, window, @@ -379,16 +376,11 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) } #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_arrow( style, + gtk_render_arrow(context, cr, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_LEFT, - FALSE, + 1.5*G_PI, // Left-pointing arrow otherArea.x, otherArea.y, - otherArea.width, otherArea.height + min(otherArea.width, otherArea.height) ); #else gtk_paint_arrow( style, @@ -415,12 +407,8 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) otherArea.y = possible.y + (possible.height - otherArea.height) / 2; } #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_check( style, + gtk_render_check(context, cr, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - widget, - NULL, otherArea.x, otherArea.y, otherArea.width, otherArea.height ); #else @@ -471,11 +459,8 @@ static gboolean eek_preview_draw(GtkWidget* widget, cairo_t* cr) gtk_widget_get_allocation (widget, &allocation); #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_focus( style, + gtk_render_focus(context, cr, - GTK_STATE_NORMAL, - widget, - NULL, 0 + 1, 0 + 1, allocation.width - 2, allocation.height - 2 ); #else diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index d78ba01dd..c02f4bceb 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -281,10 +281,18 @@ gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) gtk_icon_source_set_pixbuf(source, icon->pb); gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used gtk_icon_source_set_size_wildcarded(source, FALSE); + +#if GTK_CHECK_VERSION(3,0,0) + image = gtk_render_icon_pixbuf(gtk_widget_get_style_context(widget), + source, + (GtkIconSize)-1); +#else image = gtk_style_render_icon(gtk_widget_get_style(widget), source, gtk_widget_get_direction(widget), (GtkStateType) gtk_widget_get_state(widget), (GtkIconSize)-1, widget, "gtk-image"); +#endif + gtk_icon_source_free(source); unref_image = true; } diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index e8636899e..72c839b19 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -489,9 +489,14 @@ static void sp_ruler_realize(GtkWidget *widget) gtk_widget_set_window(widget, window); gdk_window_set_user_data(window, ruler); +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_set_background(gtk_widget_get_style_context(widget), + window); +#else gtk_widget_style_attach(widget); gtk_style_set_background(gtk_widget_get_style(widget), window, GTK_STATE_ACTIVE); +#endif sp_ruler_make_pixmap (ruler); } @@ -756,7 +761,6 @@ static void sp_ruler_real_draw_ticks(SPRuler *ruler, cairo_t *cr) g_object_get(G_OBJECT(ruler), "orientation", &orientation, NULL); GtkWidget *widget = GTK_WIDGET (ruler); - GtkStyle *style = gtk_widget_get_style (widget); PangoContext *pango_context = gtk_widget_get_pango_context (widget); PangoLayout *pango_layout = pango_layout_new (pango_context); @@ -766,8 +770,19 @@ static void sp_ruler_real_draw_ticks(SPRuler *ruler, cairo_t *cr) pango_font_description_free (fs); gint digit_height = (int) floor (RULER_FONT_SIZE * RULER_FONT_VERTICAL_SPACING / PANGO_SCALE + 0.5); + +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context(widget); + GtkStateFlags state = gtk_widget_get_state_flags(widget); + GtkBorder padding; + gtk_style_context_get_padding(context, state, &padding); + gint xthickness = padding.left; + gint ythickness = padding.top; +#else + GtkStyle *style = gtk_widget_get_style(widget); gint xthickness = style->xthickness; gint ythickness = style->ythickness; +#endif gtk_widget_get_allocation (widget, &allocation); @@ -780,12 +795,15 @@ static void sp_ruler_real_draw_ticks(SPRuler *ruler, cairo_t *cr) } #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_box(style, cr, - GTK_STATE_NORMAL, GTK_SHADOW_NONE, - widget, - orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler", - 0, 0, - allocation.width, allocation.height); + gtk_render_frame(context, + cr, + 0, 0, + allocation.width, allocation.height); + + gtk_render_background(context, + cr, + 0, 0, + allocation.width, allocation.height); #else gtk_paint_box(style, priv->backing_store, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, @@ -795,7 +813,16 @@ static void sp_ruler_real_draw_ticks(SPRuler *ruler, cairo_t *cr) #endif cairo_set_line_width(cr, 1.0); + +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA color; + gtk_style_context_get_color(context, + gtk_widget_get_state_flags(widget), + &color); + gdk_cairo_set_source_rgba(cr, &color); +#else gdk_cairo_set_source_color(cr, &style->fg[gtk_widget_get_state(widget)]); +#endif gdouble upper = priv->upper / priv->metric->pixels_per_unit; // upper and lower are expressed in ruler units gdouble lower = priv->lower / priv->metric->pixels_per_unit; diff --git a/src/widgets/sp-color-slider.cpp b/src/widgets/sp-color-slider.cpp index 7934a4118..d58d495bb 100644 --- a/src/widgets/sp-color-slider.cpp +++ b/src/widgets/sp-color-slider.cpp @@ -230,9 +230,12 @@ sp_color_slider_realize (GtkWidget *widget) gdk_window_set_user_data(gtk_widget_get_window(widget), widget); +#if !GTK_CHECK_VERSION(3,0,0) + // This doesn't do anything in GTK+ 3 gtk_widget_set_style(widget, - gtk_style_attach(gtk_widget_get_style(widget), - gtk_widget_get_window(widget))); + gtk_style_attach(gtk_widget_get_style(widget), + gtk_widget_get_window(widget))); +#endif } static void @@ -507,7 +510,6 @@ sp_color_slider_adjustment_value_changed (GtkAdjustment *adjustment, SPColorSlid static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) { - GdkWindow *window = gtk_widget_get_window(widget); SPColorSlider *slider = SP_COLOR_SLIDER(widget); gboolean colorsOnTop = Inkscape::Preferences::get()->getBool("/options/workarounds/colorsontop", false); @@ -515,16 +517,20 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context(widget); +#else + GdkWindow *window = gtk_widget_get_window(widget); GtkStyle *style = gtk_widget_get_style(widget); +#endif // Draw shadow if (colorsOnTop) { #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_shadow( style, cr, - gtk_widget_get_state(widget), GTK_SHADOW_IN, - widget, "colorslider", - 0, 0, - allocation.width, allocation.height); + gtk_render_frame(context, + cr, + 0, 0, + allocation.width, allocation.height); #else gtk_paint_shadow( style, window, gtk_widget_get_state(widget), GTK_SHADOW_IN, @@ -536,8 +542,21 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) /* Paintable part of color gradient area */ GdkRectangle carea; + +#if GTK_CHECK_VERSION(3,0,0) + GtkBorder padding; + + gtk_style_context_get_padding(context, + gtk_widget_get_state_flags(widget), + &padding); + + carea.x = padding.left; + carea.y = padding.top; +#else carea.x = style->xthickness; carea.y = style->ythickness; +#endif + carea.width = allocation.width - 2 * carea.x; carea.height = allocation.height - 2 * carea.y; @@ -554,7 +573,7 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) GdkPixbuf *pb = gdk_pixbuf_new_from_data (b, GDK_COLORSPACE_RGB, 0, 8, carea.width, carea.height, carea.width * 3, NULL, NULL); - gdk_cairo_set_source_pixbuf(cr, pb, carea.x, carea.y); + gdk_cairo_set_source_pixbuf(cr, pb, carea.x, carea.y); cairo_paint(cr); g_object_unref(pb); } @@ -612,11 +631,10 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) /* Draw shadow */ if (!colorsOnTop) { #if GTK_CHECK_VERSION(3,0,0) - gtk_paint_shadow( style, cr, - gtk_widget_get_state(widget), GTK_SHADOW_IN, - widget, "colorslider", - 0, 0, - allocation.width, allocation.height); + gtk_render_frame(context, + cr, + 0, 0, + allocation.width, allocation.height); #else gtk_paint_shadow( style, window, gtk_widget_get_state(widget), GTK_SHADOW_IN, @@ -633,9 +651,13 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) gint w = ARROW_SIZE; cairo_set_line_width(cr, 1.0); + GdkColor white, black; + gdk_color_parse("#fff", &white); + gdk_color_parse("#000", &black); + while ( w > 0 ) { - gdk_cairo_set_source_color(cr, &style->white); + gdk_cairo_set_source_color(cr, &white); cairo_move_to(cr, x - 0.5, y1 + 0.5); cairo_line_to(cr, x + w - 1 + 0.5, y1 + 0.5); cairo_move_to(cr, x - 0.5, y2 + 0.5); @@ -645,7 +667,7 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) x++; if ( w > 0 ) { - gdk_cairo_set_source_color(cr, &style->black); + gdk_cairo_set_source_color(cr, &black); cairo_move_to(cr, x - 0.5, y1 + 0.5); cairo_line_to(cr, x + w - 1 + 0.5, y1 + 0.5); cairo_move_to(cr, x - 0.5, y2 + 0.5); |
