diff options
Diffstat (limited to 'src')
108 files changed, 2688 insertions, 1410 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 9675df8e3..c35e0041f 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -86,10 +86,10 @@ GType sp_arc_context_get_type() static void sp_arc_context_class_init(SPArcContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*) g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_arc_context_dispose; @@ -127,8 +127,8 @@ static void sp_arc_context_finish(SPEventContext *ec) sp_arc_finish(ac); ac->sel_changed_connection.disconnect(); - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->finish) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->finish(ec); } } @@ -174,8 +174,8 @@ static void sp_arc_context_setup(SPEventContext *ec) SPArcContext *ac = SP_ARC_CONTEXT(ec); Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } ec->shape_editor = new ShapeEditor(ec->desktop); @@ -219,8 +219,8 @@ static gint sp_arc_context_item_handler(SPEventContext *event_context, SPItem *i break; } - if (((SPEventContextClass *) parent_class)->item_handler) { - ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler(event_context, item, event); } return ret; @@ -401,8 +401,8 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } } diff --git a/src/attributes.cpp b/src/attributes.cpp index 7d6f8614d..30cf30f30 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -258,9 +258,6 @@ static SPStyleProp const props[] = { {SP_ATTR_POINTSATY, "pointsAtY"}, {SP_ATTR_POINTSATZ, "pointsAtZ"}, {SP_ATTR_LIMITINGCONEANGLE, "limitingConeAngle"}, - /*feFlood*/ - {SP_ATTR_FLOODCOLOR, "flood-color"}, - {SP_ATTR_FLOODOPACITY, "flood-opacity"}, /* SPGaussianBlur */ {SP_ATTR_STDDEVIATION, "stdDeviation"}, /*feImage*/ diff --git a/src/attributes.h b/src/attributes.h index d8eb087b2..87cd9ed45 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -258,9 +258,6 @@ enum SPAttributeEnum { SP_ATTR_POINTSATY, SP_ATTR_POINTSATZ, SP_ATTR_LIMITINGCONEANGLE, - /*feFlood*/ - SP_ATTR_FLOODCOLOR, - SP_ATTR_FLOODOPACITY, /* SPGaussianBlur */ SP_ATTR_STDDEVIATION, /*feImage*/ diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 5f87ab712..db2e049c7 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -287,13 +287,10 @@ sp_connector_context_get_type(void) static void sp_connector_context_class_init(SPConnectorContextClass *klass) { - GObjectClass *object_class; - SPEventContextClass *event_context_class; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - object_class = (GObjectClass *) klass; - event_context_class = (SPEventContextClass *) klass; - - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_connector_context_dispose; @@ -405,8 +402,8 @@ sp_connector_context_setup(SPEventContext *ec) SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); SPDesktop *dt = ec->desktop; - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } cc->selection = sp_desktop_selection(dt); @@ -514,8 +511,8 @@ sp_connector_context_finish(SPEventContext *ec) spcc_connector_finish(cc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->finish) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->finish(ec); } if (cc->selection) { @@ -735,7 +732,7 @@ sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event) if (!ret) { gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) parent_class)->root_handler; + = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler; if (parent_root_handler) { ret = parent_root_handler(ec, event); } @@ -1939,12 +1936,12 @@ void cc_selection_set_avoid(bool const set_avoid) Inkscape::Selection *selection = sp_desktop_selection(desktop); - GSList *l = (GSList *) selection->itemList(); + GSList *l = const_cast<GSList *>(selection->itemList()); int changes = 0; while (l) { - SPItem *item = (SPItem *) l->data; + SPItem *item = SP_ITEM(l->data); char const *value = (set_avoid) ? "true" : NULL; diff --git a/src/dialogs/dialog-events.cpp b/src/dialogs/dialog-events.cpp index 49fcfd3a4..1fb823bf0 100644 --- a/src/dialogs/dialog-events.cpp +++ b/src/dialogs/dialog-events.cpp @@ -47,7 +47,7 @@ sp_dialog_defocus (GtkWindow *win) { GtkWindow *w; //find out the document window we're transient for - w = gtk_window_get_transient_for ((GtkWindow *) win); + w = gtk_window_get_transient_for(GTK_WINDOW(win)); //switch to it if (w) { @@ -65,10 +65,9 @@ void sp_dialog_defocus_callback_cpp(Gtk::Entry *e) } void -sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data) +sp_dialog_defocus_callback (GtkWindow * /*win*/, gpointer data) { - sp_dialog_defocus ((GtkWindow *) - gtk_widget_get_toplevel ((GtkWidget *) data)); + sp_dialog_defocus( GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(data))) ); } @@ -93,7 +92,7 @@ sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data) { // if the focus is inside the Text and Font textview, do nothing - GObject *dlg = (GObject *) data; + GObject *dlg = G_OBJECT(data); if (g_object_get_data (dlg, "eatkeys")) { return FALSE; } @@ -121,12 +120,12 @@ sp_dialog_event_handler (GtkWindow *win, GdkEvent *event, gpointer data) * its position. */ GdkEventAny event; - GtkWidget *widget = (GtkWidget *) win; + GtkWidget *widget = GTK_WIDGET(win); event.type = GDK_DELETE; event.window = gtk_widget_get_window (widget); event.send_event = TRUE; g_object_ref (G_OBJECT (event.window)); - gtk_main_do_event ((GdkEvent*)&event); + gtk_main_do_event(reinterpret_cast<GdkEvent*>(&event)); g_object_unref (G_OBJECT (event.window)); ret = TRUE; @@ -218,7 +217,7 @@ void on_dialog_unhide (GtkWidget *w) gboolean sp_dialog_hide(GObject * /*object*/, gpointer data) { - GtkWidget *dlg = (GtkWidget *) data; + GtkWidget *dlg = GTK_WIDGET(data); if (dlg) gtk_widget_hide (dlg); @@ -231,7 +230,7 @@ sp_dialog_hide(GObject * /*object*/, gpointer data) gboolean sp_dialog_unhide(GObject * /*object*/, gpointer data) { - GtkWidget *dlg = (GtkWidget *) data; + GtkWidget *dlg = GTK_WIDGET(data); if (dlg) gtk_widget_show (dlg); diff --git a/src/dialogs/find.cpp b/src/dialogs/find.cpp index 8acc96596..2810f065c 100644 --- a/src/dialogs/find.cpp +++ b/src/dialogs/find.cpp @@ -111,7 +111,7 @@ sp_find_squeeze_window() #else gtk_widget_size_request(dlg, &r); #endif - gtk_window_resize ((GtkWindow *) dlg, r.width, r.height); + gtk_window_resize (GTK_WINDOW(dlg), r.width, r.height); } static bool @@ -156,7 +156,7 @@ item_text_match (SPItem *item, const gchar *text, bool exact) //FIXME: strcasestr ret = ((bool) (strstr(item_text, text) != NULL)); } - g_free ((void*) item_text); + g_free(static_cast<void*>(g_strdup(item_text))); return ret; } return false; @@ -327,8 +327,8 @@ all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) { - if ( SP_IS_ITEM(i->data) && !reinterpret_cast<SPObject*>(i->data)->cloned && !desktop->isLayer(SP_ITEM(i->data))) { + for (GSList *i = const_cast<GSList *>(s->itemList()); i != NULL; i = i->next) { + if ( SP_IS_ITEM(i->data) && !SP_OBJECT(i->data)->cloned && !desktop->isLayer(SP_ITEM(i->data))) { SPItem * item = SP_ITEM(i->data); if (!ancestor || ancestor->isAncestorOf(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { @@ -511,7 +511,7 @@ sp_find_types_checkbox (GtkWidget *w, const gchar *data, gboolean active, { GtkWidget *b = gtk_check_button_new_with_label (label); gtk_widget_show (b); - gtk_toggle_button_set_active ((GtkToggleButton *) b, active); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), active); g_object_set_data (G_OBJECT (w), data, b); gtk_widget_set_tooltip_text (b, tip); if (toggled) @@ -709,9 +709,9 @@ sp_find_dialog_old (void) // if (y<0) y=0; if (w && h) - gtk_window_resize ((GtkWindow *) dlg, w, h); + gtk_window_resize(GTK_WINDOW(dlg), w, h); if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) { - gtk_window_move ((GtkWindow *) dlg, x, y); + gtk_window_move(GTK_WINDOW(dlg), x, y); } else { gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER); } @@ -764,7 +764,7 @@ sp_find_dialog_old (void) { GtkWidget *b = gtk_check_button_new_with_mnemonic (_("Search in s_election")); gtk_widget_show (b); - gtk_toggle_button_set_active ((GtkToggleButton *) b, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), FALSE); g_object_set_data (G_OBJECT (dlg), "inselection", b); gtk_widget_set_tooltip_text (b, _("Limit search to the current selection")); gtk_box_pack_start (GTK_BOX (vb), b, FALSE, FALSE, 0); @@ -773,7 +773,7 @@ sp_find_dialog_old (void) { GtkWidget *b = gtk_check_button_new_with_mnemonic (_("Search in current _layer")); gtk_widget_show (b); - gtk_toggle_button_set_active ((GtkToggleButton *) b, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), FALSE); g_object_set_data (G_OBJECT (dlg), "inlayer", b); gtk_widget_set_tooltip_text (b, _("Limit search to the current layer")); gtk_box_pack_start (GTK_BOX (vb), b, FALSE, FALSE, 0); @@ -782,7 +782,7 @@ sp_find_dialog_old (void) { GtkWidget *b = gtk_check_button_new_with_mnemonic (_("Include _hidden")); gtk_widget_show (b); - gtk_toggle_button_set_active ((GtkToggleButton *) b, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), FALSE); g_object_set_data (G_OBJECT (dlg), "includehidden", b); gtk_widget_set_tooltip_text (b, _("Include hidden objects in search")); gtk_box_pack_start (GTK_BOX (vb), b, FALSE, FALSE, 0); @@ -791,7 +791,7 @@ sp_find_dialog_old (void) { GtkWidget *b = gtk_check_button_new_with_mnemonic (_("Include l_ocked")); gtk_widget_show (b); - gtk_toggle_button_set_active ((GtkToggleButton *) b, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), FALSE); g_object_set_data (G_OBJECT (dlg), "includelocked", b); gtk_widget_set_tooltip_text (b, _("Include locked objects in search")); gtk_box_pack_start (GTK_BOX (vb), b, FALSE, FALSE, 0); @@ -814,8 +814,8 @@ sp_find_dialog_old (void) } } - gtk_widget_show((GtkWidget *) dlg); - gtk_window_present ((GtkWindow *) dlg); + gtk_widget_show(GTK_WIDGET(dlg)); + gtk_window_present(GTK_WINDOW(dlg)); sp_find_dialog_reset (NULL, G_OBJECT (dlg)); return dlg; diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 2e2eb42dd..692e31837 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -24,6 +24,7 @@ #include <2geom/transforms.h> #include <2geom/sbasis-to-bezier.h> #include "color.h" +#include "style.h" #include "helper/geom-curves.h" namespace Inkscape { @@ -276,6 +277,43 @@ feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv) } } +SPColorInterpolation +get_cairo_surface_ci(cairo_surface_t *surface) { + void* data = cairo_surface_get_user_data( surface, &ci_key ); + if( data != NULL ) { + return (SPColorInterpolation)GPOINTER_TO_INT( data ); + } else { + return SP_CSS_COLOR_INTERPOLATION_AUTO; + } +} + +/** Set the color_interpolation_value for a Cairo surface. + * Transform the surface between sRGB and linearRGB if necessary. */ +void +set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation ci) { + + if( cairo_surface_get_content( surface ) != CAIRO_CONTENT_ALPHA ) { + + SPColorInterpolation ci_in = get_cairo_surface_ci( surface ); + + if( ci_in == SP_CSS_COLOR_INTERPOLATION_SRGB && + ci == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { + ink_cairo_surface_srgb_to_linear( surface ); + } + if( ci_in == SP_CSS_COLOR_INTERPOLATION_LINEARRGB && + ci == SP_CSS_COLOR_INTERPOLATION_SRGB ) { + ink_cairo_surface_linear_to_srgb( surface ); + } + + cairo_surface_set_user_data(surface, &ci_key, GINT_TO_POINTER (ci), NULL); + } +} + +void +copy_cairo_surface_ci(cairo_surface_t *in, cairo_surface_t *out) { + cairo_surface_set_user_data(out, &ci_key, cairo_surface_get_user_data(in, &ci_key), NULL); +} + void ink_cairo_set_source_rgba32(cairo_t *ct, guint32 rgba) { @@ -395,6 +433,7 @@ cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s) { cairo_surface_t *ns = ink_cairo_surface_create_same_size(s, cairo_surface_get_content(s)); + cairo_surface_set_user_data(ns, &ci_key, cairo_surface_get_user_data(s, &ci_key), NULL); return ns; } @@ -547,6 +586,92 @@ void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, a = CLAMP(a, 0.0, 1.0); } +void srgb_to_linear( guint32* c, guint32 a ) { + + *c = unpremul_alpha( *c, a ); + + double cc = *c/255.0; + + if( cc < 0.04045 ) { + cc /= 12.92; + } else { + cc = pow( (cc+0.055)/1.055, 2.4 ); + } + cc *= 255.0; + + *c = (int)cc; + + *c = premul_alpha( *c, a ); +} + +void linear_to_srgb( guint32* c, guint32 a ) { + + *c = unpremul_alpha( *c, a ); + + double cc = *c/255.0; + + if( cc < 0.0031308 ) { + cc *= 12.92; + } else { + cc = pow( cc, 1.0/2.4 )*1.055-0.055; + } + cc *= 255.0; + + *c = (int)cc; + + *c = premul_alpha( *c, a ); +} + +int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface) +{ + cairo_surface_flush(surface); + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + int stride = cairo_image_surface_get_stride(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + + /* TODO convert this to OpenMP somehow */ + for (int y = 0; y < height; ++y, data += stride) { + for (int x = 0; x < width; ++x) { + guint32 px = *reinterpret_cast<guint32*>(data + 4*x); + EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting + if( a != 0 ) { + srgb_to_linear( &r, a ); + srgb_to_linear( &g, a ); + srgb_to_linear( &b, a ); + } + ASSEMBLE_ARGB32(px2, a,r,g,b); + *reinterpret_cast<guint32*>(data + 4*x) = px2; + } + } + return width * height; +} + +int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface) +{ + cairo_surface_flush(surface); + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + int stride = cairo_image_surface_get_stride(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + + /* TODO convert this to OpenMP somehow */ + for (int y = 0; y < height; ++y, data += stride) { + for (int x = 0; x < width; ++x) { + guint32 px = *reinterpret_cast<guint32*>(data + 4*x); + EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting + if( a != 0 ) { + linear_to_srgb( &r, a ); + linear_to_srgb( &g, a ); + linear_to_srgb( &b, a ); + } + ASSEMBLE_ARGB32(px2, a,r,g,b); + *reinterpret_cast<guint32*>(data + 4*x) = px2; + } + } + return width * height; +} + cairo_pattern_t * ink_cairo_pattern_create_checkerboard() { diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index e67872891..d240545eb 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -15,6 +15,7 @@ #include <glib.h> #include <cairomm/cairomm.h> #include <2geom/forward.h> +#include "style.h" struct SPColor; struct _GdkPixbuf; @@ -81,6 +82,17 @@ public: } // namespace Inkscape +/** + * Key for cairo_surface_t to keep track of current color interpolation value + * Only the address of the structure is used, it is never initialized. See: + * http://www.cairographics.org/manual/cairo-Types.html#cairo-user-data-key-t + */ +static cairo_user_data_key_t ci_key; +SPColorInterpolation get_cairo_surface_ci(cairo_surface_t *surface); +void set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation cif); +void copy_cairo_surface_ci(cairo_surface_t *in, cairo_surface_t *out); +void convert_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation cif); + void ink_cairo_set_source_color(cairo_t *ct, SPColor const &color, double opacity); void ink_cairo_set_source_rgba32(cairo_t *ct, guint32 rgba); void ink_cairo_transform(cairo_t *ct, Geom::Affine const &m); @@ -102,6 +114,9 @@ guint32 ink_cairo_surface_average_color(cairo_surface_t *surface); void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a); void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a); +int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface); +int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface); + cairo_pattern_t *ink_cairo_pattern_create_checkerboard(); void convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int rs); diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 77f24caf3..171cc014f 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -4,8 +4,9 @@ *//* * Authors: * Krzysztof KosiÅ„ski <tweenk.pl@gmail.com> + * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - * Copyright (C) 2011 Authors + * Copyright (C) 2011-2012 Authors * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -14,6 +15,12 @@ #include "nr-filter-gaussian.h" #include "nr-filter-types.h" +//grayscale colormode: +#include "nr-filter-colormatrix.h" +#include "cairo-templates.h" +#include "drawing-context.h" + + namespace Inkscape { Drawing::Drawing(SPCanvasArena *arena) @@ -145,12 +152,37 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl _pickItemsForCaching(); } +// hardcoded grayscale color matrix values. could be turned into preference settings in future. +static const gdouble grayscale_value_matrix[] = { + 0.21, 0.72, 0.072, 0, 0, + 0.21, 0.72, 0.072, 0, 0, + 0.21, 0.72, 0.072, 0, 0, + 0 , 0 , 0 , 1, 0 +}; +static Filters::FilterColorMatrix::ColorMatrixMatrix grayscale_colormatrix( + std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + sizeof(grayscale_value_matrix) / sizeof(grayscale_value_matrix[0]) ) +); + void Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) { if (_root) { _root->render(ct, area, flags); } + + if (colorMode() == COLORMODE_GRAYSCALE) { + // apply grayscale filter on top of everything + cairo_surface_t *input = ct.rawTarget(); + cairo_surface_t *out = ink_cairo_surface_create_identical(input); + ink_cairo_surface_filter(input, out, grayscale_colormatrix); + Geom::Point origin = ct.targetLogicalBounds().min(); + ct.setSource(out, origin[Geom::X], origin[Geom::Y]); + ct.setOperator(CAIRO_OPERATOR_SOURCE); + ct.paint(); + ct.setOperator(CAIRO_OPERATOR_OVER); + + cairo_surface_destroy(out); + } } DrawingItem * diff --git a/src/display/nr-filter-blend.cpp b/src/display/nr-filter-blend.cpp index 267883b4b..a08191f67 100644 --- a/src/display/nr-filter-blend.cpp +++ b/src/display/nr-filter-blend.cpp @@ -146,13 +146,23 @@ void FilterBlend::render_cairo(FilterSlot &slot) cairo_surface_t *input1 = slot.getcairo(_input); cairo_surface_t *input2 = slot.getcairo(_input2); - cairo_content_t ct1 = cairo_surface_get_content(input1); - cairo_content_t ct2 = cairo_surface_get_content(input2); + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci( input1, ci_fp ); + set_cairo_surface_ci( input2, ci_fp ); // input2 is the "background" image // out should be ARGB32 if any of the inputs is ARGB32 cairo_surface_t *out = ink_cairo_surface_create_output(input1, input2); + set_cairo_surface_ci( out, ci_fp ); + cairo_content_t ct1 = cairo_surface_get_content(input1); + cairo_content_t ct2 = cairo_surface_get_content(input2); if ((ct1 == CAIRO_CONTENT_ALPHA && ct2 == CAIRO_CONTENT_ALPHA) || _blend_mode == BLEND_NORMAL) { diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp index 33718ed68..77873d523 100644 --- a/src/display/nr-filter-colormatrix.cpp +++ b/src/display/nr-filter-colormatrix.cpp @@ -32,50 +32,47 @@ FilterPrimitive * FilterColorMatrix::create() { FilterColorMatrix::~FilterColorMatrix() {} -struct ColorMatrixMatrix { - ColorMatrixMatrix(std::vector<double> const &values) { - unsigned limit = std::min(static_cast<size_t>(20), values.size()); - for (unsigned i = 0; i < limit; ++i) { - if (i % 5 == 4) { - _v[i] = round(values[i]*255*255); - } else { - _v[i] = round(values[i]*255); - } - } - for (unsigned i = limit; i < 20; ++i) { - _v[i] = 0; +FilterColorMatrix::ColorMatrixMatrix::ColorMatrixMatrix(std::vector<double> const &values) { + unsigned limit = std::min(static_cast<size_t>(20), values.size()); + for (unsigned i = 0; i < limit; ++i) { + if (i % 5 == 4) { + _v[i] = round(values[i]*255*255); + } else { + _v[i] = round(values[i]*255); } } + for (unsigned i = limit; i < 20; ++i) { + _v[i] = 0; + } +} - guint32 operator()(guint32 in) { - EXTRACT_ARGB32(in, a, r, g, b) - // we need to un-premultiply alpha values for this type of matrix - // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel - if (a != 0) { - r = unpremul_alpha(r, a); - g = unpremul_alpha(g, a); - b = unpremul_alpha(b, a); - } - - gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4]; - gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9]; - gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14]; - gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19]; - ro = (pxclamp(ro, 0, 255*255) + 127) / 255; - go = (pxclamp(go, 0, 255*255) + 127) / 255; - bo = (pxclamp(bo, 0, 255*255) + 127) / 255; - ao = (pxclamp(ao, 0, 255*255) + 127) / 255; +guint32 FilterColorMatrix::ColorMatrixMatrix::operator()(guint32 in) { + EXTRACT_ARGB32(in, a, r, g, b) + // we need to un-premultiply alpha values for this type of matrix + // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel + if (a != 0) { + r = unpremul_alpha(r, a); + g = unpremul_alpha(g, a); + b = unpremul_alpha(b, a); + } - ro = premul_alpha(ro, ao); - go = premul_alpha(go, ao); - bo = premul_alpha(bo, ao); + gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4]; + gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9]; + gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14]; + gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19]; + ro = (pxclamp(ro, 0, 255*255) + 127) / 255; + go = (pxclamp(go, 0, 255*255) + 127) / 255; + bo = (pxclamp(bo, 0, 255*255) + 127) / 255; + ao = (pxclamp(ao, 0, 255*255) + 127) / 255; + + ro = premul_alpha(ro, ao); + go = premul_alpha(go, ao); + bo = premul_alpha(bo, ao); + + ASSEMBLE_ARGB32(pxout, ao, ro, go, bo) + return pxout; +} - ASSEMBLE_ARGB32(pxout, ao, ro, go, bo) - return pxout; - } -private: - gint32 _v[20]; -}; struct ColorMatrixSaturate { ColorMatrixSaturate(double v_in) { @@ -155,15 +152,27 @@ void FilterColorMatrix::render_cairo(FilterSlot &slot) { cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = NULL; + + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci( input, ci_fp ); + if (type == COLORMATRIX_LUMINANCETOALPHA) { out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_ALPHA); } else { out = ink_cairo_surface_create_identical(input); + // Set ci to that used for computation + set_cairo_surface_ci(out, ci_fp); } switch (type) { case COLORMATRIX_MATRIX: - ink_cairo_surface_filter(input, out, ColorMatrixMatrix(values)); + ink_cairo_surface_filter(input, out, FilterColorMatrix::ColorMatrixMatrix(values)); break; case COLORMATRIX_SATURATE: ink_cairo_surface_filter(input, out, ColorMatrixSaturate(value)); diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h index 5f21a4210..c7e5e91d9 100644 --- a/src/display/nr-filter-colormatrix.h +++ b/src/display/nr-filter-colormatrix.h @@ -42,6 +42,15 @@ public: virtual void set_type(FilterColorMatrixType type); virtual void set_value(gdouble value); virtual void set_values(std::vector<gdouble> const &values); + +public: + struct ColorMatrixMatrix { + ColorMatrixMatrix(std::vector<double> const &values); + guint32 operator()(guint32 in); + private: + gint32 _v[20]; + }; + private: std::vector<gdouble> values; gdouble value; diff --git a/src/display/nr-filter-component-transfer.cpp b/src/display/nr-filter-component-transfer.cpp index 226a73cef..3bc00d2d7 100644 --- a/src/display/nr-filter-component-transfer.cpp +++ b/src/display/nr-filter-component-transfer.cpp @@ -238,6 +238,17 @@ void FilterComponentTransfer::render_cairo(FilterSlot &slot) { cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + set_cairo_surface_ci(out, ci_fp ); + } + set_cairo_surface_ci( input, ci_fp ); + //cairo_surface_t *outtemp = ink_cairo_surface_create_identical(out); ink_cairo_surface_blit(input, out); diff --git a/src/display/nr-filter-composite.cpp b/src/display/nr-filter-composite.cpp index 040424cb3..f6decad0d 100644 --- a/src/display/nr-filter-composite.cpp +++ b/src/display/nr-filter-composite.cpp @@ -66,7 +66,18 @@ void FilterComposite::render_cairo(FilterSlot &slot) cairo_surface_t *input1 = slot.getcairo(_input); cairo_surface_t *input2 = slot.getcairo(_input2); + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci( input1, ci_fp ); + set_cairo_surface_ci( input2, ci_fp ); + cairo_surface_t *out = ink_cairo_surface_create_output(input1, input2); + set_cairo_surface_ci(out, ci_fp ); if (op == COMPOSITE_ARITHMETIC) { ink_cairo_surface_blend(input1, input2, out, ComposeArithmetic(k1, k2, k3, k4)); diff --git a/src/display/nr-filter-convolve-matrix.cpp b/src/display/nr-filter-convolve-matrix.cpp index 5469aff88..2aad528a6 100644 --- a/src/display/nr-filter-convolve-matrix.cpp +++ b/src/display/nr-filter-convolve-matrix.cpp @@ -104,8 +104,6 @@ void FilterConvolveMatrix::render_cairo(FilterSlot &slot) static bool bias_warning = false; static bool edge_warning = false; - cairo_surface_t *input = slot.getcairo(_input); - if (orderX<=0 || orderY<=0) { g_warning("Empty kernel!"); return; @@ -119,8 +117,19 @@ void FilterConvolveMatrix::render_cairo(FilterSlot &slot) return; } + cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_identical(input); + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + set_cairo_surface_ci(out, ci_fp); + } + set_cairo_surface_ci( input, ci_fp ); + if (bias!=0 && !bias_warning) { g_warning("It is unknown whether Inkscape's implementation of bias in feConvolveMatrix " "is correct!"); diff --git a/src/display/nr-filter-diffuselighting.cpp b/src/display/nr-filter-diffuselighting.cpp index fcc986189..faf56a4ca 100644 --- a/src/display/nr-filter-diffuselighting.cpp +++ b/src/display/nr-filter-diffuselighting.cpp @@ -126,6 +126,13 @@ void FilterDiffuseLighting::render_cairo(FilterSlot &slot) cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + // Only alpha channel of input is used, no need to check input color_interpolation_filter value. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci(out, ci_fp ); + Geom::Rect slot_area = slot.get_slot_area(); Geom::Point p = slot_area.min(); Geom::Affine trans = slot.get_units().get_matrix_primitiveunits2pb(); diff --git a/src/display/nr-filter-displacement-map.cpp b/src/display/nr-filter-displacement-map.cpp index 9b44c2302..1b979fa6c 100644 --- a/src/display/nr-filter-displacement-map.cpp +++ b/src/display/nr-filter-displacement-map.cpp @@ -74,6 +74,17 @@ void FilterDisplacementMap::render_cairo(FilterSlot &slot) cairo_surface_t *texture = slot.getcairo(_input); cairo_surface_t *map = slot.getcairo(_input2); cairo_surface_t *out = ink_cairo_surface_create_identical(texture); + // color_interpolation_filters for out same as texture. See spec. + copy_cairo_surface_ci( texture, out ); + + // We may need to transform map surface to correct color interpolation space. The map surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the map before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci( map, ci_fp ); Geom::Affine trans = slot.get_units().get_matrix_primitiveunits2pb(); double scalex = scale * trans.expansionX(); diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 56a27ecd7..7117e0343 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -45,6 +45,8 @@ void FilterFlood::render_cairo(FilterSlot &slot) #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) + // DOES THIS REALLY BELONG HERE? SHOULDN'T ICC BE APPLIED AFTER ALL COMPOSITING? + // What if color_interpolation_filter is set to linear RGB? if (icc) { guchar ru, gu, bu; icc_color_to_sRGB(icc, &ru, &gu, &bu); @@ -55,6 +57,10 @@ void FilterFlood::render_cairo(FilterSlot &slot) #endif cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + // color_interpolation_filter is determined by CSS value (see spec. Turbulence). + if( _style ) { + set_cairo_surface_ci(out, (SPColorInterpolation)_style->color_interpolation_filters.computed ); + } // Get filter primitive area in user units Geom::Rect fp = filter_primitive_area( slot.get_units() ); diff --git a/src/display/nr-filter-gaussian.cpp b/src/display/nr-filter-gaussian.cpp index 6ef321992..9d7c32585 100644 --- a/src/display/nr-filter-gaussian.cpp +++ b/src/display/nr-filter-gaussian.cpp @@ -553,6 +553,15 @@ void FilterGaussian::render_cairo(FilterSlot &slot) cairo_surface_t *in = slot.getcairo(_input); if (!in) return; + // We may need to transform input surface to correct color interpolation space. The input surface + // might be used as input to another primitive but it is likely that all the primitives in a given + // filter use the same color interpolation space so we don't copy the input before converting. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci( in, ci_fp ); + // zero deviation = no change in output if (_deviation_x <= 0 && _deviation_y <= 0) { cairo_surface_t *cp = ink_cairo_surface_copy(in); @@ -660,10 +669,14 @@ void FilterGaussian::render_cairo(FilterSlot &slot) cairo_paint(ct); cairo_destroy(ct); + set_cairo_surface_ci( upsampled, ci_fp ); + slot.set(_output, upsampled); cairo_surface_destroy(upsampled); cairo_surface_destroy(downsampled); } else { + set_cairo_surface_ci( downsampled, ci_fp ); + slot.set(_output, downsampled); cairo_surface_destroy(downsampled); } diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index bc18cbcc6..fca8fdba3 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -120,6 +120,9 @@ void FilterImage::render_cairo(FilterSlot &slot) drawing.render(ct, render_rect); SVGElem->invoke_hide(key); + // For the moment, we'll assume that any image is in sRGB color space + set_cairo_surface_ci(out, SP_CSS_COLOR_INTERPOLATION_SRGB); + slot.set(_output, out); cairo_surface_destroy(out); return; @@ -185,6 +188,9 @@ void FilterImage::render_cairo(FilterSlot &slot) cairo_surface_t *out = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, sa.width(), sa.height()); + // For the moment, we'll assume that any image is in sRGB color space + set_cairo_surface_ci(out, SP_CSS_COLOR_INTERPOLATION_SRGB); + cairo_t *ct = cairo_create(out); cairo_translate(ct, -sa.min()[Geom::X], -sa.min()[Geom::Y]); diff --git a/src/display/nr-filter-merge.cpp b/src/display/nr-filter-merge.cpp index 759d7d6d1..2b9a24f25 100644 --- a/src/display/nr-filter-merge.cpp +++ b/src/display/nr-filter-merge.cpp @@ -33,6 +33,11 @@ void FilterMerge::render_cairo(FilterSlot &slot) { if (_input_image.empty()) return; + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + // output is RGBA if at least one input is RGBA bool rgba32 = false; cairo_surface_t *out = NULL; @@ -40,6 +45,7 @@ void FilterMerge::render_cairo(FilterSlot &slot) cairo_surface_t *in = slot.getcairo(*i); if (cairo_surface_get_content(in) == CAIRO_CONTENT_COLOR_ALPHA) { out = ink_cairo_surface_create_identical(in); + set_cairo_surface_ci( out, ci_fp ); rgba32 = true; break; } @@ -52,6 +58,8 @@ void FilterMerge::render_cairo(FilterSlot &slot) for (std::vector<int>::iterator i = _input_image.begin(); i != _input_image.end(); ++i) { cairo_surface_t *in = slot.getcairo(*i); + + set_cairo_surface_ci( in, ci_fp ); cairo_set_source_surface(out_ct, in, 0, 0); cairo_paint(out_ct); } diff --git a/src/display/nr-filter-morphology.cpp b/src/display/nr-filter-morphology.cpp index 18f99cdcd..b058307cf 100644 --- a/src/display/nr-filter-morphology.cpp +++ b/src/display/nr-filter-morphology.cpp @@ -164,6 +164,7 @@ void FilterMorphology::render_cairo(FilterSlot &slot) if (xradius == 0.0 || yradius == 0.0) { // output is transparent black cairo_surface_t *out = ink_cairo_surface_create_identical(input); + copy_cairo_surface_ci(input, out); slot.set(_output, out); cairo_surface_destroy(out); return; @@ -192,6 +193,9 @@ void FilterMorphology::render_cairo(FilterSlot &slot) cairo_surface_t *out = ink_cairo_surface_create_identical(interm); + // color_interpolation_filters for out same as input. See spec (DisplacementMap). + copy_cairo_surface_ci(input, out); + if (Operator == MORPHOLOGY_OPERATOR_DILATE) { if (bpp == 1) { morphologicalFilter1D< std::greater<unsigned char>, Geom::Y, 1 >(interm, out, yr); diff --git a/src/display/nr-filter-offset.cpp b/src/display/nr-filter-offset.cpp index 833f6ecc9..01d6ffe56 100644 --- a/src/display/nr-filter-offset.cpp +++ b/src/display/nr-filter-offset.cpp @@ -35,6 +35,9 @@ void FilterOffset::render_cairo(FilterSlot &slot) { cairo_surface_t *in = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_identical(in); + // color_interpolation_filters for out same as in. See spec (DisplacementMap). + copy_cairo_surface_ci(in, out); + cairo_t *ct = cairo_create(out); Geom::Affine trans = slot.get_units().get_matrix_primitiveunits2pb(); diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp index ce562668a..fca82c810 100644 --- a/src/display/nr-filter-primitive.cpp +++ b/src/display/nr-filter-primitive.cpp @@ -20,6 +20,7 @@ #include "desktop-handles.h" #include "document.h" #include "sp-root.h" +#include "style.h" namespace Inkscape { namespace Filters { @@ -45,11 +46,14 @@ FilterPrimitive::FilterPrimitive() _subregion_y.unset(SVGLength::PERCENT, 0, 0); _subregion_width.unset(SVGLength::PERCENT, 1, 0); _subregion_height.unset(SVGLength::PERCENT, 1, 0); + + _style = NULL; } FilterPrimitive::~FilterPrimitive() { - // Nothing to do here + if(_style) + sp_style_unref(_style); } void FilterPrimitive::render_cairo(FilterSlot &slot) @@ -179,6 +183,14 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) return area; } +void FilterPrimitive::setStyle(SPStyle *style) +{ + if (style) sp_style_ref(style); + if (_style) sp_style_unref(_style); + _style = style; +} + + } /* namespace Filters */ } /* namespace Inkscape */ diff --git a/src/display/nr-filter-primitive.h b/src/display/nr-filter-primitive.h index da2097156..214b2cfc5 100644 --- a/src/display/nr-filter-primitive.h +++ b/src/display/nr-filter-primitive.h @@ -16,6 +16,8 @@ #include "display/nr-filter-types.h" #include "svg/svg-length.h" +class SPStyle; + namespace Inkscape { namespace Filters { @@ -113,6 +115,11 @@ public: */ virtual bool can_handle_affine(Geom::Affine const &) { return false; } + /** + * Sets style for access to properties used by filter primitives. + */ + void setStyle(SPStyle *style); + protected: int _input; int _output; @@ -122,6 +129,8 @@ protected: SVGLength _subregion_y; SVGLength _subregion_width; SVGLength _subregion_height; + + SPStyle *_style; }; diff --git a/src/display/nr-filter-slot.cpp b/src/display/nr-filter-slot.cpp index 4f7a8849e..fe67972d6 100644 --- a/src/display/nr-filter-slot.cpp +++ b/src/display/nr-filter-slot.cpp @@ -129,6 +129,9 @@ cairo_surface_t *FilterSlot::_get_transformed_source_graphic() if (trans.isTranslation()) { cairo_surface_reference(_source_graphic); + + // Assume all source graphics are sRGB + set_cairo_surface_ci( _source_graphic, SP_CSS_COLOR_INTERPOLATION_SRGB ); return _source_graphic; } @@ -145,6 +148,8 @@ cairo_surface_t *FilterSlot::_get_transformed_source_graphic() cairo_paint(tsg_ct); cairo_destroy(tsg_ct); + // Assume all source graphics are sRGB + set_cairo_surface_ci( tsg, SP_CSS_COLOR_INTERPOLATION_SRGB ); return tsg; } @@ -172,6 +177,9 @@ cairo_surface_t *FilterSlot::_get_transformed_background() tbg = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, _slot_w, _slot_h); } + // Assume all source graphics are sRGB + set_cairo_surface_ci( tbg, SP_CSS_COLOR_INTERPOLATION_SRGB ); + return tbg; } diff --git a/src/display/nr-filter-specularlighting.cpp b/src/display/nr-filter-specularlighting.cpp index 0242754eb..50f1b48c5 100644 --- a/src/display/nr-filter-specularlighting.cpp +++ b/src/display/nr-filter-specularlighting.cpp @@ -139,6 +139,13 @@ void FilterSpecularLighting::render_cairo(FilterSlot &slot) cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + // Only alpha channel of input is used, no need to check input color_interpolation_filter value. + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; + if( _style ) { + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + } + set_cairo_surface_ci(out, ci_fp ); + Geom::Affine trans = slot.get_units().get_matrix_primitiveunits2pb(); Geom::Point p = slot.get_slot_area().min(); double x0 = p[Geom::X]; diff --git a/src/display/nr-filter-turbulence.cpp b/src/display/nr-filter-turbulence.cpp index bce532f21..76b877fbc 100644 --- a/src/display/nr-filter-turbulence.cpp +++ b/src/display/nr-filter-turbulence.cpp @@ -375,6 +375,11 @@ void FilterTurbulence::render_cairo(FilterSlot &slot) cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + // color_interpolation_filter is determined by CSS value (see spec. Turbulence). + if( _style ) { + set_cairo_surface_ci(out, (SPColorInterpolation)_style->color_interpolation_filters.computed ); + } + if (!gen->ready()) { Geom::Point ta(fTileX, fTileY); Geom::Point tb(fTileX + fTileWidth, fTileY + fTileHeight); diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index f580a5044..eeba94d7c 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -38,6 +38,7 @@ #include "display/nr-filter-tile.h" #include "display/nr-filter-turbulence.h" +#include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-item.h" #include "display/drawing-context.h" @@ -159,6 +160,10 @@ int Filter::render(Inkscape::DrawingItem const *item, DrawingContext &graphic, D Geom::Point origin = graphic.targetLogicalBounds().min(); cairo_surface_t *result = slot.get_result(_output_slot); + + // Assume for the moment that we paint the filter in sRGB + set_cairo_surface_ci( result, SP_CSS_COLOR_INTERPOLATION_SRGB ); + graphic.setSource(result, origin[Geom::X], origin[Geom::Y]); graphic.setOperator(CAIRO_OPERATOR_SOURCE); graphic.paint(); diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index d0c6d2d56..0d1b56d54 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -16,7 +16,7 @@ #include <2geom/transforms.h> #include <cairo.h> #include <vector> -#include "style.h" +#include "sp-object.h" #include "svg/svg.h" #include "display/cairo-utils.h" #include "display/nr-svgfonts.h" diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 536c54609..eb51860ab 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -291,7 +291,7 @@ public: #if GTK_CHECK_VERSION(3,0,0) static gboolean handleDraw(GtkWidget *widget, cairo_t *cr); #else - static gint handleExpose(GtkWidget *widget, GdkEventExpose *event); + static gboolean handleExpose(GtkWidget *widget, GdkEventExpose *event); #endif /** @@ -2178,23 +2178,24 @@ void SPCanvas::endForcedFullRedraws() } #if GTK_CHECK_VERSION(3,0,0) - -//TODO: This could probably be done much more efficiently gboolean SPCanvasImpl::handleDraw(GtkWidget *widget, cairo_t *cr) { SPCanvas *canvas = SP_CANVAS(widget); - gint width = gtk_widget_get_allocated_width(widget); - gint height = gtk_widget_get_allocated_height(widget); - Geom::IntRect r = Geom::IntRect::from_xywh( - canvas->x0, canvas->y0, - width, height); + cairo_rectangle_list_t *rects = cairo_copy_clip_rectangle_list(cr); + + for (int i = 0; i < rects->num_rectangles; i++) { + cairo_rectangle_t rectangle = rects->rectangles[i]; + + Geom::IntRect r = Geom::IntRect::from_xywh(rectangle.x + canvas->x0, rectangle.y + canvas->y0, + rectangle.width, rectangle.height); - canvas->requestRedraw(r.left(), r.top(), r.right(), r.bottom()); + canvas->requestRedraw(r.left(), r.top(), r.right(), r.bottom()); + } return FALSE; } #else -gint SPCanvasImpl::handleExpose(GtkWidget *widget, GdkEventExpose *event) +gboolean SPCanvasImpl::handleExpose(GtkWidget *widget, GdkEventExpose *event) { SPCanvas *canvas = SP_CANVAS(widget); @@ -2203,43 +2204,23 @@ gint SPCanvasImpl::handleExpose(GtkWidget *widget, GdkEventExpose *event) return FALSE; } -#if GTK_CHECK_VERSION(3,0,0) - int n_rects = cairo_region_num_rectangles(event->region); -#else int n_rects = 0; GdkRectangle *rects = NULL; gdk_region_get_rectangles(event->region, &rects, &n_rects); if(rects == NULL) - return FALSE; -#endif - - if (n_rects == 0) - { return FALSE; - } - else - { - for (int i = 0; i < n_rects; i++) { -#if GTK_CHECK_VERSION(3,0,0) - cairo_rectangle_int_t rectangle; - cairo_region_get_rectangle(event->region, i, &rectangle); -#else - GdkRectangle rectangle = rects[i]; -#endif - - Geom::IntRect r = Geom::IntRect::from_xywh( - rectangle.x + canvas->x0, rectangle.y + canvas->y0, - rectangle.width, rectangle.height); + + for (int i = 0; i < n_rects; i++) { + GdkRectangle rectangle = rects[i]; + + Geom::IntRect r = Geom::IntRect::from_xywh(rectangle.x + canvas->x0, rectangle.y + canvas->y0, + rectangle.width, rectangle.height); - canvas->requestRedraw(r.left(), r.top(), r.right(), r.bottom()); - } - -#if !GTK_CHECK_VERSION(3,0,0) - g_free (rects); -#endif - return FALSE; + canvas->requestRedraw(r.left(), r.top(), r.right(), r.bottom()); } + + return FALSE; } #endif diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp index 8b293a9d9..38b981444 100644 --- a/src/dropper-context.cpp +++ b/src/dropper-context.cpp @@ -84,9 +84,9 @@ GType sp_dropper_context_get_type() static void sp_dropper_context_class_init(SPDropperContextClass *klass) { - SPEventContextClass *ec_class = (SPEventContextClass *) klass; + SPEventContextClass *ec_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); ec_class->setup = sp_dropper_context_setup; ec_class->finish = sp_dropper_context_finish; @@ -109,8 +109,8 @@ static void sp_dropper_context_setup(SPEventContext *ec) { SPDropperContext *dc = SP_DROPPER_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */ @@ -206,7 +206,7 @@ guint32 sp_dropper_context_get_color(SPEventContext *ec) static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEvent *event) { - SPDropperContext *dc = (SPDropperContext *) event_context; + SPDropperContext *dc = SP_DROPPER_CONTEXT(event_context); int ret = FALSE; SPDesktop *desktop = event_context->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -423,8 +423,8 @@ static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEv } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } } diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 3f488eca4..b30950f5a 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -128,10 +128,10 @@ GType sp_dyna_draw_context_get_type(void) static void sp_dyna_draw_context_class_init(SPDynaDrawContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - dd_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + dd_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_dyna_draw_context_dispose; @@ -195,8 +195,8 @@ sp_dyna_draw_context_setup(SPEventContext *ec) { SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - if (((SPEventContextClass *) dd_parent_class)->setup) - ((SPEventContextClass *) dd_parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(dd_parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(dd_parent_class))->setup(ec); ddc->accumulated = new SPCurve(); ddc->currentcurve = new SPCurve(); @@ -974,8 +974,8 @@ sp_dyna_draw_context_root_handler(SPEventContext *event_context, } if (!ret) { - if (((SPEventContextClass *) dd_parent_class)->root_handler) { - ret = ((SPEventContextClass *) dd_parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(dd_parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(dd_parent_class))->root_handler(event_context, event); } } diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index 76ea5c252..c4560d462 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -131,10 +131,10 @@ GType sp_eraser_context_get_type(void) static void sp_eraser_context_class_init(SPEraserContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - eraser_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + eraser_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_eraser_context_dispose; @@ -165,8 +165,8 @@ sp_eraser_context_setup(SPEventContext *ec) SPEraserContext *erc = SP_ERASER_CONTEXT(ec); SPDesktop *desktop = ec->desktop; - if (((SPEventContextClass *) eraser_parent_class)->setup) - ((SPEventContextClass *) eraser_parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(eraser_parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(eraser_parent_class))->setup(ec); erc->accumulated = new SPCurve(); erc->currentcurve = new SPCurve(); @@ -689,8 +689,8 @@ sp_eraser_context_root_handler(SPEventContext *event_context, } if (!ret) { - if (((SPEventContextClass *) eraser_parent_class)->root_handler) { - ret = ((SPEventContextClass *) eraser_parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(eraser_parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(eraser_parent_class))->root_handler(event_context, event); } } diff --git a/src/event-context.cpp b/src/event-context.cpp index e9d0aa935..71d4a5fb9 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -106,11 +106,9 @@ GType sp_event_context_get_type(void) { * Callback to set up the SPEventContext vtable. */ static void sp_event_context_class_init(SPEventContextClass *klass) { - GObjectClass *object_class; + GObjectClass *object_class = G_OBJECT_CLASS(klass); - object_class = (GObjectClass *) klass; - - parent_class = (GObjectClass*) g_type_class_peek_parent(klass); + parent_class = G_OBJECT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_event_context_dispose; @@ -464,10 +462,23 @@ static gint sp_event_context_private_root_handler( break; case GDK_MOTION_NOTIFY: if (panning) { + if (panning == 4 && !xp && !yp ) { + // <Space> + mouse panning started, save location and grab canvas + xp = event->motion.x; + yp = event->motion.y; + button_w = Geom::Point(event->motion.x, event->motion.y); + + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK, NULL, + event->motion.time - 1); + + + } if ((panning == 2 && !(event->motion.state & GDK_BUTTON2_MASK)) - || (panning == 1 && !(event->motion.state - & GDK_BUTTON1_MASK)) || (panning == 3 - && !(event->motion.state & GDK_BUTTON3_MASK))) { + || (panning == 1 && !(event->motion.state & GDK_BUTTON1_MASK)) + || (panning == 3 && !(event->motion.state & GDK_BUTTON3_MASK))) { /* Gdk seems to lose button release for us sometimes :-( */ panning = 0; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), @@ -570,6 +581,7 @@ static gint sp_event_context_private_root_handler( } ret = TRUE; } + break; case GDK_KEY_PRESS: { double const acceleration = prefs->getDoubleLimited( @@ -672,15 +684,13 @@ static gint sp_event_context_private_root_handler( } break; case GDK_KEY_space: - if (prefs->getBool("/options/spacepans/value")) { - event_context->space_panning = true; - event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, - _("<b>Space+mouse drag</b> to pan canvas")); - ret = TRUE; - } else { - sp_toggle_selector(desktop); - ret = TRUE; - } + xp = yp = 0; + within_tolerance = true; + panning = 4; + event_context->space_panning = true; + event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, + _("<b>Space+mouse move</b> to pan canvas")); + ret = TRUE; break; case GDK_KEY_z: case GDK_KEY_Z: @@ -695,18 +705,32 @@ static gint sp_event_context_private_root_handler( } break; case GDK_KEY_RELEASE: + + // Stop panning on any key release + if (event_context->space_panning) { + event_context->space_panning = false; + event_context->_message_context->clear(); + } + + if (panning) { + panning = 0; + xp = yp = 0; + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), + event->key.time); + desktop->updateNow(); + } + + if (panning_cursor == 1) { + panning_cursor = 0; + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); + gdk_window_set_cursor(gtk_widget_get_window (w), event_context->cursor); + } + switch (get_group0_keyval(&event->key)) { case GDK_KEY_space: - if (event_context->space_panning) { - event_context->space_panning = false; - event_context->_message_context->clear(); - - if (panning == 1) { - panning = 0; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), - event->key.time); - desktop->updateNow(); - } + if (within_tolerance == true) { + // Space was pressed, but not panned + sp_toggle_selector(desktop); ret = TRUE; } break; @@ -1377,17 +1401,16 @@ gboolean sp_event_context_snap_watchdog_callback(gpointer data) { sp_event_context_virtual_root_handler(ec, dse->getEvent()); break; case DelayedSnapEvent::EVENTCONTEXT_ITEM_HANDLER: { - SPItem* item = NULL; - item = SP_ITEM(dse->getItem()); + gpointer item = dse->getItem(); if (item && SP_IS_ITEM(item)) { - sp_event_context_virtual_item_handler(ec, item, dse->getEvent()); + sp_event_context_virtual_item_handler(ec, SP_ITEM(item), dse->getEvent()); } } break; case DelayedSnapEvent::KNOT_HANDLER: { - SPKnot* knot = SP_KNOT(dse->getItem2()); + gpointer knot = dse->getItem2(); if (knot && SP_IS_KNOT(knot)) { - sp_knot_handler_request_position(dse->getEvent(), knot); + sp_knot_handler_request_position(dse->getEvent(), SP_KNOT(knot)); } } break; diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp index 53fcc0fbf..a17a2bb30 100644 --- a/src/extension/internal/image-resolution.cpp +++ b/src/extension/internal/image-resolution.cpp @@ -27,27 +27,30 @@ namespace Extension { namespace Internal { ImageResolution::ImageResolution(char const *fn) { - ok_ = false; - - readpng(fn); - if (!ok_) - readexif(fn); - if (!ok_) - readexiv(fn); - if (!ok_) - readjfif(fn); + ok_ = false; + + readpng(fn); + if (!ok_) { + readexiv(fn); + } + if (!ok_) { + readjfif(fn); + } + if (!ok_) { + readexif(fn); + } } bool ImageResolution::ok() const { - return ok_; + return ok_; } double ImageResolution::x() const { - return x_; + return x_; } double ImageResolution::y() const { - return y_; + return y_; } @@ -57,60 +60,62 @@ double ImageResolution::y() const { #include <png.h> static bool haspngheader(FILE *fp) { - unsigned char header[8]; - if (fread(header, 1, 8, fp)!=8) - return false; + unsigned char header[8]; + if ( fread(header, 1, 8, fp) != 8 ) { + return false; + } - fseek(fp, 0, SEEK_SET); - - if (png_sig_cmp(header, 0, 8)) - return false; + fseek(fp, 0, SEEK_SET); + + if (png_sig_cmp(header, 0, 8)) { + return false; + } - return true; + return true; } // Implementation using libpng void ImageResolution::readpng(char const *fn) { - FILE *fp = fopen(fn, "rb"); - if (!fp) - return; + FILE *fp = fopen(fn, "rb"); + if (!fp) + return; - if (!haspngheader(fp)) { - fclose(fp); - return; - } + if (!haspngheader(fp)) { + fclose(fp); + return; + } - png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - if (!png_ptr) - return; - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!png_ptr) { - png_destroy_read_struct(&png_ptr, 0, 0); - return; - } - - if (setjmp(png_jmpbuf(png_ptr))) { - png_destroy_read_struct(&png_ptr, &info_ptr, 0); - fclose(fp); - return; - } + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); + if (!png_ptr) + return; + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, 0, 0); + return; + } + + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, 0); + fclose(fp); + return; + } - png_init_io(png_ptr, fp); - png_read_info(png_ptr, info_ptr); + png_init_io(png_ptr, fp); + png_read_info(png_ptr, info_ptr); - png_uint_32 res_x, res_y; - int unit_type; - png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); + png_uint_32 res_x, res_y; + int unit_type; + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); - png_destroy_read_struct(&png_ptr, &info_ptr, 0); - fclose(fp); + png_destroy_read_struct(&png_ptr, &info_ptr, 0); + fclose(fp); - if (unit_type == PNG_RESOLUTION_METER) { - ok_ = true; - x_ = res_x * 2.54/100; - y_ = res_y * 2.54/100; - } + if (unit_type == PNG_RESOLUTION_METER) { + ok_ = true; + x_ = res_x * 2.54 / 100; + y_ = res_y * 2.54 / 100; + } } #else @@ -126,63 +131,71 @@ void ImageResolution::readpng(char const *) { #include <libexif/exif-data.h> static double exifDouble(ExifEntry *entry, ExifByteOrder byte_order) { - switch (entry->format) { - case EXIF_FORMAT_BYTE: - return double(entry->data[0]); - case EXIF_FORMAT_SHORT: - return double(exif_get_short(entry->data, byte_order)); - case EXIF_FORMAT_LONG: - return double(exif_get_long(entry->data, byte_order)); - case EXIF_FORMAT_RATIONAL: { - ExifRational r = exif_get_rational(entry->data, byte_order); - return double(r.numerator)/double(r.denominator); - } - case EXIF_FORMAT_SBYTE: - return double(*(signed char *)entry->data); - case EXIF_FORMAT_SSHORT: - return double(exif_get_sshort(entry->data, byte_order)); - case EXIF_FORMAT_SLONG: - return double(exif_get_slong(entry->data, byte_order)); - case EXIF_FORMAT_SRATIONAL: { - ExifSRational r = exif_get_srational(entry->data, byte_order); - return double(r.numerator)/double(r.denominator); - } - case EXIF_FORMAT_FLOAT: - return double(((float *)entry->data)[0]); - case EXIF_FORMAT_DOUBLE: - return ((double *)entry->data)[0]; - default: - return nan(0); - } + switch (entry->format) { + case EXIF_FORMAT_BYTE: { + return double(entry->data[0]); + } + case EXIF_FORMAT_SHORT: { + return double(exif_get_short(entry->data, byte_order)); + } + case EXIF_FORMAT_LONG: { + return double(exif_get_long(entry->data, byte_order)); + } + case EXIF_FORMAT_RATIONAL: { + ExifRational r = exif_get_rational(entry->data, byte_order); + return double(r.numerator) / double(r.denominator); + } + case EXIF_FORMAT_SBYTE: { + return double(*(signed char *)entry->data); + } + case EXIF_FORMAT_SSHORT: { + return double(exif_get_sshort(entry->data, byte_order)); + } + case EXIF_FORMAT_SLONG: { + return double(exif_get_slong(entry->data, byte_order)); + } + case EXIF_FORMAT_SRATIONAL: { + ExifSRational r = exif_get_srational(entry->data, byte_order); + return double(r.numerator) / double(r.denominator); + } + case EXIF_FORMAT_FLOAT: { + return double(((float *)entry->data)[0]); + } + case EXIF_FORMAT_DOUBLE: { + return ((double *)entry->data)[0]; + } + default: { + return nan(0); + } + } } // Implementation using libexif void ImageResolution::readexif(char const *fn) { - ExifData *ed; - ed = exif_data_new_from_file(fn); - if (!ed) - return; - ExifByteOrder byte_order = exif_data_get_byte_order(ed); - - ExifEntry *xres = exif_content_get_entry(ed->ifd[EXIF_IFD_0], - EXIF_TAG_X_RESOLUTION); - ExifEntry *yres = exif_content_get_entry(ed->ifd[EXIF_IFD_0], - EXIF_TAG_Y_RESOLUTION); - ExifEntry *unit = exif_content_get_entry(ed->ifd[EXIF_IFD_0], - EXIF_TAG_RESOLUTION_UNIT); - if (xres && yres) { - x_ = exifDouble(xres, byte_order); - y_ = exifDouble(yres, byte_order); - if (unit) { - double u = exifDouble(unit, byte_order); - if (u==3) { - x_ *= 2.54; - y_ *= 2.54; - } + ExifData *ed; + ed = exif_data_new_from_file(fn); + if (!ed) + return; + + ExifByteOrder byte_order = exif_data_get_byte_order(ed); + + ExifEntry *xres = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_X_RESOLUTION); + ExifEntry *yres = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_Y_RESOLUTION); + ExifEntry *unit = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_RESOLUTION_UNIT); + + if ( xres && yres ) { + x_ = exifDouble(xres, byte_order); + y_ = exifDouble(yres, byte_order); + if (unit) { + double u = exifDouble(unit, byte_order); + if ( u == 3 ) { + x_ *= 2.54; + y_ *= 2.54; + } + } + ok_ = true; } - ok_ = true; - } - exif_data_free(ed); + exif_data_free(ed); } #else @@ -196,43 +209,43 @@ void ImageResolution::readexif(char const *) { #if IR_TRY_EXIV void ImageResolution::readexiv(char const *fn) { - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fn); - if (!image.get()) - return; - - image->readMetadata(); - Exiv2::ExifData &exifData = image->exifData(); - if (exifData.empty()) - return; - - Exiv2::ExifData::const_iterator end = exifData.end(); - bool havex = false; - bool havey = false; - bool haveunit = false; - int unit; - for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { - if (ok_) - break; - if (i->tag()==0x011a) { - // X Resolution - x_ = i->toFloat(); - havex = true; - } else if (i->tag()==0x011b) { - // Y Resolution - y_ = i->toFloat(); - havey = true; - } else if (i->tag()==0x0128) { - unit = i->toLong(); + Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fn); + if (!image.get()) + return; + + image->readMetadata(); + Exiv2::ExifData &exifData = image->exifData(); + if (exifData.empty()) + return; + + Exiv2::ExifData::const_iterator end = exifData.end(); + bool havex = false; + bool havey = false; + bool haveunit = false; + int unit; + for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { + if (ok_) + break; + if ( i->tag() == 0x011a ) { + // X Resolution + x_ = i->toFloat(); + havex = true; + } else if ( i->tag() == 0x011b ) { + // Y Resolution + y_ = i->toFloat(); + havey = true; + } else if ( i->tag() == 0x0128 ) { + unit = i->toLong(); + } + ok_ = havex && havey && haveunit; } - ok_ = havex && havey && haveunit; - } - if (haveunit) { - if (unit==3) { - x_ *= 2.54; - y_ *= 2.54; + if (haveunit) { + if ( unit == 3 ) { + x_ *= 2.54; + y_ *= 2.54; + } } - } - ok_ = havex && havey; + ok_ = havex && havey; } #else @@ -249,7 +262,7 @@ void ImageResolution::readexiv(char const *) { #include <setjmp.h> static void irjfif_error_exit(j_common_ptr cinfo) { - longjmp(*(jmp_buf*)cinfo->client_data, 1); + longjmp(*(jmp_buf*)cinfo->client_data, 1); } static void irjfif_emit_message(j_common_ptr, int) { @@ -265,44 +278,52 @@ static void irjfif_reset(j_common_ptr) { } void ImageResolution::readjfif(char const *fn) { - FILE *ifd = fopen(fn, "rb"); - if (!ifd) - return; - - struct jpeg_decompress_struct cinfo; - jmp_buf jbuf; - struct jpeg_error_mgr jerr; - bool constr = false; + FILE *ifd = fopen(fn, "rb"); + if (!ifd) { + return; + } - if (setjmp(jbuf)) { + struct jpeg_decompress_struct cinfo; + jmp_buf jbuf; + struct jpeg_error_mgr jerr; + bool constr = false; + + if (setjmp(jbuf)) { + fclose(ifd); + if (constr) { + jpeg_destroy_decompress(&cinfo); + } + return; + } + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jerr.error_exit = &irjfif_error_exit; + jerr.emit_message = &irjfif_emit_message; + jerr.output_message = &irjfif_output_message; + jerr.format_message = &irjfif_format_message; + jerr.reset_error_mgr = &irjfif_reset; + cinfo.client_data = (void*)&jbuf; + + constr = true; + + jpeg_stdio_src(&cinfo, ifd); + jpeg_read_header(&cinfo, TRUE); + + if (cinfo.saw_JFIF_marker) { // JFIF APP0 marker was seen + if ( cinfo.density_unit == 1 ) { // dots/inch + x_ = cinfo.X_density; + y_ = cinfo.Y_density; + ok_ = true; + } else if ( cinfo.density_unit == 2 ) { // dots/cm + x_ = cinfo.X_density * 2.54; + y_ = cinfo.Y_density * 2.54; + ok_ = true; + } + } + constr = false; + jpeg_destroy_decompress(&cinfo); fclose(ifd); - if (constr) - jpeg_destroy_decompress(&cinfo); - return; - } - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - jerr.error_exit = &irjfif_error_exit; - jerr.emit_message = &irjfif_emit_message; - jerr.output_message = &irjfif_output_message; - jerr.format_message = &irjfif_format_message; - jerr.reset_error_mgr = &irjfif_reset; - cinfo.client_data = (void*)&jbuf; - constr = true; - - jpeg_stdio_src(&cinfo, ifd); - jpeg_read_header(&cinfo, TRUE); - - if (cinfo.density_unit==1) { - x_ = cinfo.X_density; - y_ = cinfo.Y_density; - ok_ = true; - } - - constr = false; - jpeg_destroy_decompress(&cinfo); - fclose(ifd); } #else @@ -312,7 +333,7 @@ void ImageResolution::readjfif(char const *) { } #endif - + } } } diff --git a/src/extension/internal/pdf-input-cairo.cpp b/src/extension/internal/pdf-input-cairo.cpp index 03b7c0a90..0a9dd8399 100644 --- a/src/extension/internal/pdf-input-cairo.cpp +++ b/src/extension/internal/pdf-input-cairo.cpp @@ -229,7 +229,7 @@ PdfImportCairoDialog::PdfImportCairoDialog(PopplerDocument *doc) this->get_vbox()->pack_start(*hbox1); this->set_title(_("PDF Import Settings")); this->set_modal(true); - sp_transientize((GtkWidget *)this->gobj()); //Make transient + sp_transientize(GTK_WIDGET(this->gobj())); //Make transient this->property_window_position().set_value(Gtk::WIN_POS_NONE); this->set_resizable(true); this->property_destroy_with_parent().set_value(false); @@ -416,7 +416,7 @@ static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, cairo_height = gdk_pixbuf_get_height (pixbuf); for (y = 0; y < cairo_height; y++) { - src = (unsigned int *) (cairo_data + y * cairo_rowstride); + src = reinterpret_cast<unsigned int *>(cairo_data + y * cairo_rowstride); dst = pixbuf_data + y * pixbuf_rowstride; for (x = 0; x < cairo_width; x++) { @@ -622,8 +622,8 @@ PdfInputCairo::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { static cairo_status_t _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length) { - Glib::ustring* stream = (Glib::ustring*)closure; - stream->append((const char*)data, length); + Glib::ustring* stream = static_cast<Glib::ustring*>(closure); + stream->append(reinterpret_cast<const char*>(data), length); return CAIRO_STATUS_SUCCESS; } diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 688e3f612..90d53c6b0 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -245,7 +245,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) this->get_vbox()->pack_start(*hbox1); this->set_title(_("PDF Import Settings")); this->set_modal(true); - sp_transientize((GtkWidget *)this->gobj()); //Make transient + sp_transientize(GTK_WIDGET(this->gobj())); //Make transient this->property_window_position().set_value(Gtk::WIN_POS_NONE); this->set_resizable(true); this->property_destroy_with_parent().set_value(false); @@ -446,7 +446,7 @@ static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, cairo_height = gdk_pixbuf_get_height (pixbuf); for (y = 0; y < cairo_height; y++) { - src = (unsigned int *) (cairo_data + y * cairo_rowstride); + src = reinterpret_cast<unsigned int *>(cairo_data + y * cairo_rowstride); dst = pixbuf_data + y * pixbuf_rowstride; for (x = 0; x < cairo_width; x++) { @@ -603,7 +603,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { PDFDoc *pdf_doc = new PDFDoc(filename_goo, NULL, NULL, NULL); // TODO: Could ask for password //delete filename_goo; #else - wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL); + wchar_t *wfilename = reinterpret_cast<wchar_t*>(g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL)); if (wfilename == NULL) { return NULL; diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 6d71ce72a..187318417 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -142,7 +142,7 @@ VsdImportDialog::VsdImportDialog(const std::vector<WPXString> &vec) this->get_vbox()->pack_start(*vbox2); this->set_title(_("Page Selector")); this->set_modal(true); - sp_transientize((GtkWidget *)this->gobj()); //Make transient + sp_transientize(GTK_WIDGET(this->gobj())); //Make transient this->property_window_position().set_value(Gtk::WIN_POS_NONE); this->set_resizable(true); this->property_destroy_with_parent().set_value(false); @@ -261,6 +261,7 @@ SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u void VsdInput::init(void) { + /* VSD */ Inkscape::Extension::build_from_mem( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>" N_("VSD Input") "</name>\n" @@ -272,6 +273,48 @@ void VsdInput::init(void) "<filetypetooltip>" N_("File format used by Microsoft Visio 6 and later") "</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", new VsdInput()); + + /* VDX */ + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("VDX Input") "</name>\n" + "<id>org.inkscape.input.vdx</id>\n" + "<input>\n" + "<extension>.vdx</extension>\n" + "<mimetype>application/vnd.visio</mimetype>\n" + "<filetypename>" N_("Microsoft Visio XML Diagram (*.vdx)") "</filetypename>\n" + "<filetypetooltip>" N_("File format used by Microsoft Visio 2010 and later") "</filetypetooltip>\n" + "</input>\n" + "</inkscape-extension>", new VsdInput()); + + /* VSDM */ + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("VSDM Input") "</name>\n" + "<id>org.inkscape.input.vsdm</id>\n" + "<input>\n" + "<extension>.vsdm</extension>\n" + "<mimetype>application/vnd.visio</mimetype>\n" + "<filetypename>" N_("Microsoft Visio 2013 drawing (*.vsdm)") "</filetypename>\n" + "<filetypetooltip>" N_("File format used by Microsoft Visio 2013 and later") "</filetypetooltip>\n" + "</input>\n" + "</inkscape-extension>", new VsdInput()); + + /* VSDX */ + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("VSDX Input") "</name>\n" + "<id>org.inkscape.input.vsdx</id>\n" + "<input>\n" + "<extension>.vsdx</extension>\n" + "<mimetype>application/vnd.visio</mimetype>\n" + "<filetypename>" N_("Microsoft Visio 2013 drawing (*.vsdx)") "</filetypename>\n" + "<filetypetooltip>" N_("File format used by Microsoft Visio 2013 and later") "</filetypetooltip>\n" + "</input>\n" + "</inkscape-extension>", new VsdInput()); + + return; + } // init } } } /* namespace Inkscape, Extension, Implementation */ diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index b4d4cbd16..85cb5d04c 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -206,14 +206,16 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast<Parameter *>(list->data); Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); - gchar const * tip = param->get_tooltip(); -// printf("Tip: '%s'\n", tip); - vbox->pack_start(*widg, false, false, 2); - if (tip) { - widg->set_tooltip_text(tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); + if (widg) { + gchar const * tip = param->get_tooltip(); + // printf("Tip: '%s'\n", tip); + vbox->pack_start(*widg, false, false, 2); + if (tip) { + widg->set_tooltip_text(tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } } } diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp index 2d2604c7f..649dc398a 100644 --- a/src/extension/prefdialog.cpp +++ b/src/extension/prefdialog.cpp @@ -88,7 +88,12 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co _param_preview = Parameter::make(doc->root(), _effect); } +#if WITH_GTKMM_3_0 + Gtk::Separator * sep = Gtk::manage(new Gtk::Separator()); +#else Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator()); +#endif + sep->show(); this->get_vbox()->pack_start(*sep, true, true, 4); diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index fc74ee8a2..14bd00057 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -98,7 +98,10 @@ SPFilter *new_filter(SPDocument *document) Inkscape::XML::Node *repr; repr = xml_doc->createElement("svg:filter"); - // Inkscape only supports sRGB. See note in sp-filter.cpp. + // Inkscape now supports both sRGB and linear color-interpolation-filters. + // But, for the moment, keep sRGB as default value for new filters + // (historically set to sRGB and doesn't require conversion between + // filter cairo surfaces and other types of cairo surfaces). SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB"); sp_repr_css_change(repr, css, "style"); diff --git a/src/helper/unit-menu.cpp b/src/helper/unit-menu.cpp index 964ca9d67..bb2254a1b 100644 --- a/src/helper/unit-menu.cpp +++ b/src/helper/unit-menu.cpp @@ -84,7 +84,7 @@ static void sp_unit_selector_class_init(SPUnitSelectorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - unit_selector_parent_class = (GtkHBoxClass*)g_type_class_peek_parent(klass); + unit_selector_parent_class = GTK_HBOX_CLASS(g_type_class_peek_parent(klass)); signals[SET_UNIT] = g_signal_new("set_unit", G_TYPE_FROM_CLASS(klass), @@ -148,17 +148,17 @@ sp_unit_selector_finalize(GObject *object) GtkWidget * sp_unit_selector_new(guint bases) { - SPUnitSelector *us = (SPUnitSelector*)g_object_new(SP_TYPE_UNIT_SELECTOR, NULL); + SPUnitSelector *us = SP_UNIT_SELECTOR(g_object_new(SP_TYPE_UNIT_SELECTOR, NULL)); sp_unit_selector_set_bases(us, bases); - return (GtkWidget *) us; + return GTK_WIDGET(us); } void sp_unit_selector_setsize(GtkWidget *us, guint w, guint h) { - gtk_widget_set_size_request(((SPUnitSelector *) us)->combo_box, w, h); + gtk_widget_set_size_request((SP_UNIT_SELECTOR(us))->combo_box, w, h); } SPUnit const * @@ -180,7 +180,7 @@ on_combo_box_changed (GtkComboBox *widget, SPUnitSelector *us) } SPUnit const *unit = NULL; - gtk_tree_model_get ((GtkTreeModel *)us->store, &iter, COMBO_COL_UNIT, &unit, -1); + gtk_tree_model_get (GTK_TREE_MODEL(us->store), &iter, COMBO_COL_UNIT, &unit, -1); g_return_if_fail(unit != NULL); @@ -242,7 +242,7 @@ spus_rebuild_menu(SPUnitSelector *us) gint pos = 0; gint p = 0; for (GSList *l = us->units; l != NULL; l = l->next) { - SPUnit const *u = (SPUnit*)l->data; + SPUnit const *u = static_cast<SPUnit const*>(l->data); // use only abbreviations in the menu // i = gtk_menu_item_new_with_label((us->abbr) ? (us->plural) ? u->abbr_plural : u->abbr : (us->plural) ? u->plural : u->name); @@ -272,7 +272,7 @@ sp_unit_selector_set_bases(SPUnitSelector *us, guint bases) g_return_if_fail(units != NULL); sp_unit_free_list(us->units); us->units = units; - us->unit = (SPUnit*)units->data; + us->unit = static_cast<SPUnit *>(units->data); spus_rebuild_menu(us); } diff --git a/src/select-context.cpp b/src/select-context.cpp index bc096d528..5934d615c 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -97,10 +97,10 @@ sp_select_context_get_type(void) static void sp_select_context_class_init(SPSelectContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_select_context_dispose; @@ -188,8 +188,8 @@ sp_select_context_setup(SPEventContext *ec) { SPSelectContext *select_context = SP_SELECT_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } SPDesktop *desktop = ec->desktop; @@ -432,8 +432,8 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE } if (!ret) { - if (((SPEventContextClass *) parent_class)->item_handler) - ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler) + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler(event_context, item, event); } return ret; @@ -1150,8 +1150,8 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } return ret; diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index d74eaa6fb..6fe3a599b 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -369,6 +369,7 @@ static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape:: sp_arc_set_elliptical_path_attribute(SP_ARC(object), object->getRepr()); } } + sp_genericellipse_set_shape ((SPShape *) ellipse); // evaluate SPCurve if (((SPObjectClass *) ge_parent_class)->write) { ((SPObjectClass *) ge_parent_class)->write(object, xml_doc, repr, flags); diff --git a/src/sp-filter-primitive.cpp b/src/sp-filter-primitive.cpp index b63a05b4b..7ddf3b065 100644 --- a/src/sp-filter-primitive.cpp +++ b/src/sp-filter-primitive.cpp @@ -20,6 +20,7 @@ #include <string.h> #include "attributes.h" +#include "style.h" #include "sp-filter-primitive.h" #include "xml/repr.h" #include "sp-filter.h" @@ -100,16 +101,17 @@ static void sp_filter_primitive_init(SPFilterPrimitive *filter_primitive) static void sp_filter_primitive_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if ((static_cast<SPObjectClass *>(filter_primitive_parent_class))->build) { - (static_cast<SPObjectClass *>(filter_primitive_parent_class))->build(object, document, repr); - } - + object->readAttr( "style" ); // struct not derived from SPItem, we need to do this ourselves. object->readAttr( "in" ); object->readAttr( "result" ); object->readAttr( "x" ); object->readAttr( "y" ); object->readAttr( "width" ); object->readAttr( "height" ); + + if ((static_cast<SPObjectClass *>(filter_primitive_parent_class))->build) { + (static_cast<SPObjectClass *>(filter_primitive_parent_class))->build(object, document, repr); + } } /** @@ -188,7 +190,9 @@ sp_filter_primitive_update(SPObject *object, SPCtx *ctx, guint flags) { //SPFilterPrimitive *filter_primitive = SP_FILTER_PRIMITIVE(object); + // Is this required? if (flags & SP_OBJECT_MODIFIED_FLAG) { + object->readAttr( "style" ); object->readAttr( "in" ); object->readAttr( "result" ); object->readAttr( "x" ); @@ -311,6 +315,9 @@ void sp_filter_primitive_renderer_common(SPFilterPrimitive *sp_prim, Inkscape::F /* TODO: place here code to handle input images, filter area etc. */ nr_prim->set_subregion( sp_prim->x, sp_prim->y, sp_prim->width, sp_prim->height ); + + // Give renderer access to filter properties + nr_prim->setStyle( sp_prim->style ); } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index a20856f53..c7dce3850 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -130,11 +130,8 @@ sp_filter_init(SPFilter *filter) static void sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) filter_parent_class)->build) { - ((SPObjectClass *) filter_parent_class)->build(object, document, repr); - } - //Read values of key attributes from XML nodes into object. + object->readAttr( "style" ); // struct not derived from SPItem, we need to do this ourselves. object->readAttr( "filterUnits" ); object->readAttr( "primitiveUnits" ); object->readAttr( "x" ); @@ -144,6 +141,10 @@ sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep object->readAttr( "filterRes" ); object->readAttr( "xlink:href" ); + if (((SPObjectClass *) filter_parent_class)->build) { + ((SPObjectClass *) filter_parent_class)->build(object, document, repr); + } + //is this necessary? document->addResource("filter", object); } @@ -366,25 +367,6 @@ sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::N g_free(uri_string); } - // TODO: This is evil, correctly implement support for color-interpolation-filters!!! - // The color-interpolation-filters attribute is initially set to linearRGB according to the SVG standard. - // However, Inkscape completely ignores it and implicitly assumes that it is sRGB (like color-interpolation). - // This results in a discrepancy between Inkscape and other renderers in how they render filters. - // To mitigate this problem I've (Jasper van de Gronde,th.v.d.gronde@hccnet.nl) added this to ensure that at least - // any filters written by Inkscape will henceforth be rendered the same in other renderers. - // In the future Inkscape should have proper support for the color-interpolation properties and this should be changed. - - // repr->setAttribute("color-interpolation-filters", "sRGB"); - - // Actually, the above line is not correct as the attribute is only allowed on filter - // primitives and not <filter> objects. However, it is allowed as a property in a style - // attribute. Note, this property must also be set in sp-filter-chemistry, filter_new() as the - // code here is not necessarily called when a new filter is created. 29 Aug 2011 Tav. - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property(css, "color-interpolation-filters", "sRGB"); - sp_repr_css_change(repr, css, "style"); - sp_repr_css_attr_unref(css); - if (((SPObjectClass *) filter_parent_class)->write) { ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags); } diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 363aa8c17..a8e525bd5 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -552,6 +552,7 @@ void SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value) void SPItem::clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item) { + item->bbox_valid = FALSE; // force a re-evaluation if (old_clip) { SPItemView *v; /* Hide clippath */ diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 22a403345..f33d234ee 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -207,6 +207,8 @@ sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: sp_repr_set_svg_double(repr, "x", rect->x.computed); sp_repr_set_svg_double(repr, "y", rect->y.computed); + sp_rect_set_shape ((SPShape *) rect); // evaluate SPCurve + if (((SPObjectClass *) parent_class)->write) ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 052c9e853..404b0ec1c 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -84,10 +84,10 @@ sp_spiral_context_get_type() static void sp_spiral_context_class_init(SPSpiralContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_spiral_context_dispose; @@ -123,15 +123,15 @@ sp_spiral_context_init(SPSpiralContext *spiral_context) static void sp_spiral_context_finish(SPEventContext *ec) { SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; + SPDesktop *desktop = ec->desktop; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); - sp_spiral_finish(sc); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); + sp_spiral_finish(sc); sc->sel_changed_connection.disconnect(); - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); - } + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->finish) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->finish(ec); + } } static void @@ -177,8 +177,8 @@ sp_spiral_context_setup(SPEventContext *ec) { SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); sp_event_context_read(ec, "expansion"); sp_event_context_read(ec, "revolution"); @@ -398,8 +398,8 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } return ret; @@ -426,7 +426,7 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat // Set style sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/spiral", false); - sc->item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr); + sc->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); sc->item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); sc->item->updateRepr(); diff --git a/src/spray-context.cpp b/src/spray-context.cpp index 07539a080..8d74477c3 100644 --- a/src/spray-context.cpp +++ b/src/spray-context.cpp @@ -121,10 +121,10 @@ GType sp_spray_context_get_type(void) static void sp_spray_context_class_init(SPSprayContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_spray_context_dispose; @@ -223,7 +223,7 @@ static void sp_spray_update_cursor(SPSprayContext *tc, bool /*with_shift*/) guint num = 0; gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length((GSList *) desktop->selection->itemList()); + num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num); } else { sel_message = g_strdup_printf(_("<b>Nothing</b> selected")); @@ -251,8 +251,8 @@ static void sp_spray_context_setup(SPEventContext *ec) { SPSprayContext *tc = SP_SPRAY_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } { @@ -460,7 +460,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); - item_copied = (SPItem *) new_obj; //convertion object->item + item_copied = SP_ITEM(new_obj); //convertion object->item Geom::Point center=item->getCenter(); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale)); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); @@ -480,11 +480,11 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *son = NULL; //father copy int i=1; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); + for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); items != NULL; items = items->next) { - SPItem *item1 = (SPItem *) items->data; + SPItem *item1 = SP_ITEM(items->data); if (i == 1) { father = item1; } @@ -504,7 +504,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *copy1 = old_repr->duplicate(xml_doc); parent->appendChild(copy1); SPObject *new_obj1 = doc->getObjectByRepr(copy1); - son = (SPItem *) new_obj1; // conversion object->item + son = SP_ITEM(new_obj1); // conversion object->item unionResult = son; Inkscape::GC::release(copy1); } @@ -514,7 +514,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::XML::Node *copy2 = old_repr->duplicate(xml_doc); parent->appendChild(copy2); SPObject *new_obj2 = doc->getObjectByRepr(copy2); - item_copied = (SPItem *) new_obj2; + item_copied = SP_ITEM(new_obj2); // Move around the cursor Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); @@ -554,7 +554,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPObject *clone_object = doc->getObjectByRepr(clone); // conversion object->item - item_copied = (SPItem *) clone_object; + item_copied = SP_ITEM(clone_object); Geom::Point center = item->getCenter(); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); @@ -599,11 +599,11 @@ static bool sp_spray_dilate(SPSprayContext *tc, Geom::Point /*event_p*/, Geom::P double move_mean = get_move_mean(tc); double move_standard_deviation = get_move_standard_deviation(tc); - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); + for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); items != NULL; items = items->next) { - SPItem *item = (SPItem *) items->data; + SPItem *item = SP_ITEM(items->data); if (is_transform_modes(tc->mode)) { if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) @@ -701,7 +701,7 @@ gint sp_spray_context_root_handler(SPEventContext *event_context, GdkEvent *even guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length((GSList *) desktop->selection->itemList()); + num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); } if (num == 0) { tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray.")); @@ -926,8 +926,8 @@ gint sp_spray_context_root_handler(SPEventContext *event_context, GdkEvent *even } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } } diff --git a/src/star-context.cpp b/src/star-context.cpp index 66e6b3116..ae12e8c35 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -88,10 +88,10 @@ sp_star_context_get_type (void) static void sp_star_context_class_init (SPStarContextClass * klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent (klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent (klass)); object_class->dispose = sp_star_context_dispose; @@ -128,15 +128,15 @@ sp_star_context_init (SPStarContext * star_context) static void sp_star_context_finish(SPEventContext *ec) { SPStarContext *sc = SP_STAR_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; + SPDesktop *desktop = ec->desktop; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); - sp_star_finish(sc); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); + sp_star_finish(sc); sc->sel_changed_connection.disconnect(); - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); - } + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->finish) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->finish(ec); + } } @@ -187,8 +187,8 @@ sp_star_context_setup (SPEventContext *ec) { SPStarContext *sc = SP_STAR_CONTEXT (ec); - if (((SPEventContextClass *) parent_class)->setup) - ((SPEventContextClass *) parent_class)->setup (ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup (ec); sp_event_context_read (ec, "magnitude"); sp_event_context_read (ec, "proportion"); @@ -413,8 +413,8 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) - ret = ((SPEventContextClass *) parent_class)->root_handler (event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler (event_context, event); } return ret; diff --git a/src/style.cpp b/src/style.cpp index 3e58a0404..650b08aea 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -677,9 +677,9 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr) } } /* color interpolation */ - SPS_READ_PENUM_IF_UNSET(&style->color_interpolation, repr, "color_interpolation", enum_color_interpolation, true); + SPS_READ_PENUM_IF_UNSET(&style->color_interpolation, repr, "color-interpolation", enum_color_interpolation, true); /* color interpolation filters*/ - SPS_READ_PENUM_IF_UNSET(&style->color_interpolation_filters, repr, "color_interpolation_filters", enum_color_interpolation, true); + SPS_READ_PENUM_IF_UNSET(&style->color_interpolation_filters, repr, "color-interpolation-filters", enum_color_interpolation, true); /* fill */ if (!style->fill.set) { val = repr->attribute("fill"); @@ -1234,11 +1234,7 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) } break; case SP_PROP_COLOR_INTERPOLATION_FILTERS: - // We read it but issue warning SPS_READ_IENUM_IF_UNSET(&style->color_interpolation_filters, val, enum_color_interpolation, true); - if( style->color_interpolation_filters.value != SP_CSS_COLOR_INTERPOLATION_SRGB ) { - g_warning("Inkscape currently only supports color-interpolation-filters = sRGB"); - } break; case SP_PROP_COLOR_PROFILE: g_warning("Unimplemented style property SP_PROP_COLOR_PROFILE: value: %s", val); diff --git a/src/text-context.cpp b/src/text-context.cpp index d4b53f6a4..90715b805 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -104,10 +104,10 @@ GType sp_text_context_get_type() static void sp_text_context_class_init(SPTextContextClass *klass) { - GObjectClass *object_class=(GObjectClass *)klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class=G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_text_context_dispose; @@ -236,8 +236,8 @@ static void sp_text_context_setup(SPEventContext *ec) } } - if (((SPEventContextClass *) parent_class)->setup) - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -455,8 +455,8 @@ static gint sp_text_context_item_handler(SPEventContext *event_context, SPItem * } if (!ret) { - if (((SPEventContextClass *) parent_class)->item_handler) - ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler) + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler(event_context, item, event); } return ret; @@ -1324,8 +1324,8 @@ static gint sp_text_context_root_handler(SPEventContext *const event_context, Gd } // if nobody consumed it so far - if (((SPEventContextClass *) parent_class)->root_handler) { // and there's a handler in parent context, - return ((SPEventContextClass *) parent_class)->root_handler(event_context, event); // send event to parent + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { // and there's a handler in parent context, + return (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); // send event to parent } else { return FALSE; // return "I did nothing" value so that global shortcuts can be activated } @@ -1428,7 +1428,7 @@ SPCSSAttr *sp_text_get_style_at_cursor(SPEventContext const *ec) SPObject const *obj = sp_te_object_at_position(tc->text, tc->text_sel_end); if (obj) - return take_style_from_item((SPItem *) obj); + return take_style_from_item(SP_ITEM(obj)); return NULL; } diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 33dab447c..870b9cce1 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -114,10 +114,10 @@ sp_tweak_context_get_type(void) static void sp_tweak_context_class_init(SPTweakContextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_tweak_context_dispose; @@ -200,7 +200,7 @@ sp_tweak_update_cursor (SPTweakContext *tc, bool with_shift) guint num = 0; gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length((GSList *) desktop->selection->itemList()); + num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num); } else { sel_message = g_strdup_printf(_("<b>Nothing</b> selected")); @@ -277,7 +277,7 @@ sp_tweak_context_style_set(SPCSSAttr const *css, SPTweakContext *tc) { if (tc->mode == TWEAK_MODE_COLORPAINT) { // intercept color setting only in this mode // we cannot store properties with uris - css = sp_css_attr_unset_uris ((SPCSSAttr *) css); + css = sp_css_attr_unset_uris (const_cast<SPCSSAttr *>(css)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setStyle("/tools/tweak/style", const_cast<SPCSSAttr*>(css)); return true; @@ -290,8 +290,8 @@ sp_tweak_context_setup(SPEventContext *ec) { SPTweakContext *tc = SP_TWEAK_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); } { @@ -419,9 +419,9 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P SPDocument *doc = item->document; sp_item_list_to_curves (items, &selected, &to_select); g_slist_free (items); - SPObject* newObj = doc->getObjectByRepr((Inkscape::XML::Node *) to_select->data); + SPObject* newObj = doc->getObjectByRepr(static_cast<Inkscape::XML::Node *>(to_select->data)); g_slist_free (to_select); - item = (SPItem *) newObj; + item = SP_ITEM(newObj); selection->add(item); } @@ -1110,11 +1110,11 @@ sp_tweak_dilate (SPTweakContext *tc, Geom::Point event_p, Geom::Point p, Geom::P double move_force = get_move_force(tc); double color_force = MIN(sqrt(path_force)/20.0, 1); - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); + for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); items != NULL; items = items->next) { - SPItem *item = (SPItem *) items->data; + SPItem *item = SP_ITEM(items->data); if (is_color_mode (tc->mode)) { if (do_fill || do_stroke || do_opacity) { @@ -1227,7 +1227,7 @@ sp_tweak_context_root_handler(SPEventContext *event_context, guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length((GSList *) desktop->selection->itemList()); + num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); } if (num == 0) { tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak.")); @@ -1535,8 +1535,8 @@ sp_tweak_context_root_handler(SPEventContext *event_context, } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); } } diff --git a/src/ui/dialog/debug.cpp b/src/ui/dialog/debug.cpp index da38e2dde..429ed57bf 100644 --- a/src/ui/dialog/debug.cpp +++ b/src/ui/dialog/debug.cpp @@ -126,7 +126,7 @@ void DebugDialogImpl::show() { //call super() Gtk::Dialog::show(); - //sp_transientize((GtkWidget *)gobj()); //Make transient + //sp_transientize(GTK_WIDGET(gobj())); //Make transient raise(); Gtk::Dialog::present(); } diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index ab1e8fbd8..460e223a3 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -103,7 +103,7 @@ DocumentProperties::DocumentProperties() _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false), _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false), _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false), - _rcp_bg(_("Back_ground color:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr), + _rcp_bg(_("Back_ground color:"), _("Background color"), _("Color of the page background. Note: transparency setting ignored while editing but used when exporting to bitmap."), "pagecolor", "inkscape:pageopacity", _wr), _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr), _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr), _page_sizer(_wr), diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 553acac84..75f80ed4a 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -100,9 +100,9 @@ findEntryWidgets(Gtk::Container *parent, Gtk::Widget *child = children[i]; GtkWidget *wid = child->gobj(); if (GTK_IS_ENTRY(wid)) - result.push_back((Gtk::Entry *)child); + result.push_back(dynamic_cast<Gtk::Entry *>(child)); else if (GTK_IS_CONTAINER(wid)) - findEntryWidgets((Gtk::Container *)child, result); + findEntryWidgets(dynamic_cast<Gtk::Container *>(child), result); } } @@ -119,9 +119,9 @@ findExpanderWidgets(Gtk::Container *parent, Gtk::Widget *child = children[i]; GtkWidget *wid = child->gobj(); if (GTK_IS_EXPANDER(wid)) - result.push_back((Gtk::Expander *)child); + result.push_back(dynamic_cast<Gtk::Expander *>(child)); else if (GTK_IS_CONTAINER(wid)) - findExpanderWidgets((Gtk::Container *)child, result); + findExpanderWidgets(dynamic_cast<Gtk::Container *>(child), result); } } @@ -522,7 +522,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); - gchar *fName = (gchar *)fileNameUtf8.c_str(); + gchar *fName = const_cast<gchar *>(fileNameUtf8.c_str()); struct stat info; if (g_stat(fName, &info)) { @@ -898,7 +898,7 @@ bool FileOpenDialogImplGtk::show() { set_modal (TRUE); //Window - sp_transientize((GtkWidget *)gobj()); //Make transient + sp_transientize(GTK_WIDGET(gobj())); //Make transient gint b = run(); //Dialog svgPreview.showNoPreview(); hide(); @@ -1241,7 +1241,7 @@ FileSaveDialogImplGtk::show() { change_path(myFilename); set_modal (TRUE); //Window - sp_transientize((GtkWidget *)gobj()); //Make transient + sp_transientize(GTK_WIDGET(gobj())); //Make transient gint b = run(); //Dialog svgPreview.showNoPreview(); set_preview_widget_active(false); @@ -1688,7 +1688,7 @@ FileExportDialogImpl::show() s = getcwd (NULL, 0); set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing set_modal (TRUE); //Window - sp_transientize((GtkWidget *)gobj()); //Make transient + sp_transientize(GTK_WIDGET(gobj())); //Make transient gint b = run(); //Dialog svgPreview.showNoPreview(); hide(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index ddafcd481..7574b9266 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1454,6 +1454,41 @@ Glib::PropertyProxy<void*> FilterEffectsDialog::CellRendererConnection::property return _primitive.get_proxy(); } +#if WITH_GTKMM_3_0 +void FilterEffectsDialog::CellRendererConnection::get_preferred_width_vfunc(Gtk::Widget& widget, + int& minimum_width, + int& natural_width) const +{ + PrimitiveList& primlist = dynamic_cast<PrimitiveList&>(widget); + minimum_width = natural_width = size * primlist.primitive_count() + primlist.get_input_type_width() * 6; +} + +void FilterEffectsDialog::CellRendererConnection::get_preferred_width_for_height_vfunc(Gtk::Widget& widget, + int /* height */, + int& minimum_width, + int& natural_width) const +{ + get_preferred_width(widget, minimum_width, natural_width); +} + +void FilterEffectsDialog::CellRendererConnection::get_preferred_height_vfunc(Gtk::Widget& widget, + int& minimum_height, + int& natural_height) const +{ + // Scale the height depending on the number of inputs, unless it's + // the first primitive, in which case there are no connections + SPFilterPrimitive* prim = SP_FILTER_PRIMITIVE(_primitive.get_value()); + minimum_height = natural_height = size * input_count(prim); +} + +void FilterEffectsDialog::CellRendererConnection::get_preferred_height_for_width_vfunc(Gtk::Widget& widget, + int /* width */, + int& minimum_height, + int& natural_height) const +{ + get_preferred_height(widget, minimum_height, natural_height); +} +#else void FilterEffectsDialog::CellRendererConnection::get_size_vfunc( Gtk::Widget& widget, const Gdk::Rectangle* /*cell_area*/, int* x_offset, int* y_offset, int* width, int* height) const @@ -1473,6 +1508,7 @@ void FilterEffectsDialog::CellRendererConnection::get_size_vfunc( (*height) = size * input_count(prim); } } +#endif /*** PrimitiveList ***/ FilterEffectsDialog::PrimitiveList::PrimitiveList(FilterEffectsDialog& d) @@ -1481,8 +1517,8 @@ FilterEffectsDialog::PrimitiveList::PrimitiveList(FilterEffectsDialog& d) _observer(new Inkscape::XML::SignalObserver) { #if WITH_GTKMM_3_0 - d.signal_draw().connect(sigc::mem_fun(*this, &PrimitiveList::on_draw)); - signal_draw().connect(sigc::mem_fun(*this, &PrimitiveList::on_draw)); + d.signal_draw().connect(sigc::mem_fun(*this, &PrimitiveList::on_draw_signal)); + signal_draw().connect(sigc::mem_fun(*this, &PrimitiveList::on_draw_signal)); #else d.signal_expose_event().connect(sigc::mem_fun(*this, &PrimitiveList::on_expose_signal)); signal_expose_event().connect(sigc::mem_fun(*this, &PrimitiveList::on_expose_signal)); @@ -1496,6 +1532,7 @@ FilterEffectsDialog::PrimitiveList::PrimitiveList(FilterEffectsDialog& d) set_model(_model); append_column(_("_Effect"), _columns.type); + set_headers_visible(); _observer->signal_changed().connect(signal_primitive_changed().make_slot()); get_selection()->signal_changed().connect(sigc::mem_fun(*this, &PrimitiveList::on_primitive_selection_changed)); @@ -1648,19 +1685,32 @@ void FilterEffectsDialog::PrimitiveList::remove_selected() } #if !WITH_GTKMM_3_0 -bool FilterEffectsDialog::PrimitiveList::on_expose_signal(GdkEventExpose* /*e*/) +bool FilterEffectsDialog::PrimitiveList::on_expose_signal(GdkEventExpose *e) { - Glib::RefPtr<Gdk::Window> win = get_bin_window(); - Cairo::RefPtr<Cairo::Context> cr = win->create_cairo_context(); - return on_draw(cr); + bool result = false; + + if (get_is_drawable()) + { + Cairo::RefPtr<Cairo::Context> cr = get_bin_window()->create_cairo_context(); + result = on_draw_signal(cr); + } + + return result; } #endif -bool FilterEffectsDialog::PrimitiveList::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) +bool FilterEffectsDialog::PrimitiveList::on_draw_signal(const Cairo::RefPtr<Cairo::Context> & cr) { cr->set_line_width(1.0); #if GTK_CHECK_VERSION(3,0,0) + // In GTK+ 3, the draw function receives the widget window, not the + // bin_window (i.e., just the area under the column headers). We + // therefore translate the origin of our coordinate system to account for this + int x_origin, y_origin; + convert_bin_window_to_widget_coords(0,0,x_origin,y_origin); + cr->translate(x_origin, y_origin); + GtkStyleContext *sc = gtk_widget_get_style_context(GTK_WIDGET(gobj())); GdkRGBA bg_color, fg_color; gtk_style_context_get_background_color(sc, GTK_STATE_FLAG_NORMAL, &bg_color); @@ -2380,7 +2430,12 @@ FilterEffectsDialog::FilterEffectsDialog() _add_primitive_type.remove_row(NR_FILTER_COMPONENTTRANSFER); // Initialize widget hierarchy +#if WITH_GTKMM_3_0 + Gtk::Paned* hpaned = Gtk::manage(new Gtk::Paned); +#else Gtk::HPaned* hpaned = Gtk::manage(new Gtk::HPaned); +#endif + Gtk::ScrolledWindow* sw_prims = Gtk::manage(new Gtk::ScrolledWindow); Gtk::HBox* infobox = Gtk::manage(new Gtk::HBox(/*homogeneous:*/false, /*spacing:*/4)); Gtk::HBox* hb_prims = Gtk::manage(new Gtk::HBox); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 1652a314f..355a8b1b2 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -151,8 +151,28 @@ private: static const int size = 24; protected: +#if WITH_GTKMM_3_0 + virtual void get_preferred_width_vfunc(Gtk::Widget& widget, + int& minimum_width, + int& natural_width) const; + + virtual void get_preferred_width_for_height_vfunc(Gtk::Widget& widget, + int height, + int& minimum_width, + int& natural_width) const; + + virtual void get_preferred_height_vfunc(Gtk::Widget& widget, + int& minimum_height, + int& natural_height) const; + + virtual void get_preferred_height_for_width_vfunc(Gtk::Widget& widget, + int width, + int& minimum_height, + int& natural_height) const; +#else virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area, int* x_offset, int* y_offset, int* width, int* height) const; +#endif private: // void* should be SPFilterPrimitive*, some weirdness with properties prevents this Glib::Property<void*> _primitive; @@ -177,7 +197,7 @@ private: int get_input_type_width() const; protected: - bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr); + bool on_draw_signal(const Cairo::RefPtr<Cairo::Context> &cr); #if !WITH_GTKMM_3_0 bool on_expose_signal(GdkEventExpose*); diff --git a/src/ui/dialog/find.h b/src/ui/dialog/find.h index 64fb4cc3d..77a6c9d02 100644 --- a/src/ui/dialog/find.h +++ b/src/ui/dialog/find.h @@ -12,6 +12,10 @@ #ifndef INKSCAPE_UI_DIALOG_FIND_H #define INKSCAPE_UI_DIALOG_FIND_H +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include "ui/widget/panel.h" #include "ui/widget/button.h" #include "ui/widget/entry.h" @@ -280,7 +284,13 @@ private: Gtk::Label status; UI::Widget::Button button_find; UI::Widget::Button button_replace; + +#if WITH_GTKMM_3_0 + Gtk::ButtonBox box_buttons; +#else Gtk::HButtonBox box_buttons; +#endif + Gtk::HBox hboxbutton_row; /** diff --git a/src/ui/dialog/icon-preview.h b/src/ui/dialog/icon-preview.h index 42f9176b0..8a6e19a25 100644 --- a/src/ui/dialog/icon-preview.h +++ b/src/ui/dialog/icon-preview.h @@ -66,7 +66,12 @@ private: gdouble minDelay; Gtk::VBox iconBox; + +#if WITH_GTKMM_3_0 + Gtk::Paned splitter; +#else Gtk::HPaned splitter; +#endif Glib::ustring targetId; int hot; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 291059999..20e5d3ca6 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -1162,9 +1162,11 @@ void InkscapePreferences::initPageBehavior() _scroll_auto_thres.init ( "/options/autoscrolldistance/value", -600.0, 600.0, 1.0, 1.0, -10.0, true, false); _page_scrolling.add_line( true, _("_Threshold:"), _scroll_auto_thres, _("pixels"), _("How far (in screen pixels) you need to be from the canvas edge to trigger autoscroll; positive is outside the canvas, negative is within the canvas"), false); +/* _scroll_space.init ( _("Left mouse button pans when Space is pressed"), "/options/spacepans/value", false); _page_scrolling.add_line( false, "", _scroll_space, "", _("When on, pressing and holding Space and dragging with left mouse button pans canvas (as in Adobe Illustrator); when off, Space temporarily switches to Selector tool (default)")); +*/ _wheel_zoom.init ( _("Mouse wheel zooms by default"), "/options/wheelzooms/value", false); _page_scrolling.add_line( false, "", _wheel_zoom, "", _("When on, mouse wheel zooms without Ctrl and scrolls canvas with Ctrl; when off, it zooms with Ctrl and scrolls without Ctrl")); @@ -1459,7 +1461,12 @@ void InkscapePreferences::initKeyboardShortcuts(Gtk::TreeModel::iterator iter_ui _page_keyshortcuts.attach(*scroller, 0, 2, row, row+1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL); row++; +#if WITH_GTKMM_3_0 + Gtk::ButtonBox *box_buttons = manage(new Gtk::ButtonBox); +#else Gtk::HButtonBox *box_buttons = manage (new Gtk::HButtonBox); +#endif + box_buttons->set_layout(Gtk::BUTTONBOX_END); box_buttons->set_spacing(4); _page_keyshortcuts.attach(*box_buttons, 0, 3, row, row+1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 4c567a6e3..6aff67f69 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -424,7 +424,12 @@ private: Gtk::CheckButton useExt; Gtk::Button save; +#if WITH_GTKMM_3_0 + Gtk::Paned pane; +#else Gtk::HPaned pane; +#endif + Gtk::VBox detailsBox; Gtk::HBox titleFrame; Gtk::Label titleLabel; @@ -485,8 +490,15 @@ private: Inkscape::UI::Widget::Frame axisFrame; Gtk::ScrolledWindow treeScroller; Gtk::ScrolledWindow detailScroller; + +#if WITH_GTKMM_3_0 + Gtk::Paned splitter; + Gtk::Paned split2; +#else Gtk::HPaned splitter; Gtk::VPaned split2; +#endif + Gtk::Label devName; Gtk::Label devKeyCount; Gtk::Label devAxesCount; @@ -589,7 +601,11 @@ InputDialogImpl::InputDialogImpl() : treeScroller(), detailScroller(), splitter(), +#if WITH_GTKMM_3_0 + split2(Gtk::ORIENTATION_VERTICAL), +#else split2(), +#endif axisTable(11, 2), linkCombo(), topHolder(), @@ -1048,7 +1064,12 @@ InputDialogImpl::ConfPanel::ConfPanel() : useExt.set_active(Preferences::get()->getBool("/options/useextinput/value")); useExt.signal_toggled().connect(sigc::mem_fun(*this, &InputDialogImpl::ConfPanel::useExtToggled)); +#if WITH_GTKMM_3_0 + Gtk::ButtonBox *buttonBox = manage(new Gtk::ButtonBox); +#else Gtk::HButtonBox *buttonBox = manage (new Gtk::HButtonBox); +#endif + buttonBox->set_layout (Gtk::BUTTONBOX_END); //Gtk::Alignment *align = new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_START, 0, 0); buttonBox->add(save); diff --git a/src/ui/dialog/object-properties.cpp b/src/ui/dialog/object-properties.cpp index 12ee2f762..f0801734a 100644 --- a/src/ui/dialog/object-properties.cpp +++ b/src/ui/dialog/object-properties.cpp @@ -69,15 +69,15 @@ ObjectProperties::ObjectProperties (void) : subselChangedConn() { //initialize labels for the table at the bottom of the dialog - int_labels.push_back("onclick:"); - int_labels.push_back("onmouseover:"); - int_labels.push_back("onmouseout:"); - int_labels.push_back("onmousedown:"); - int_labels.push_back("onmouseup:"); - int_labels.push_back("onmousemove:"); - int_labels.push_back("onfocusin:"); - int_labels.push_back("onfocusout:"); - int_labels.push_back("onload:"); + int_labels.push_back("onclick"); + int_labels.push_back("onmouseover"); + int_labels.push_back("onmouseout"); + int_labels.push_back("onmousedown"); + int_labels.push_back("onmouseup"); + int_labels.push_back("onmousemove"); + int_labels.push_back("onfocusin"); + int_labels.push_back("onfocusout"); + int_labels.push_back("onload"); desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &ObjectProperties::setTargetDesktop) ); deskTrack.connect(GTK_WIDGET(gobj())); diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index c7bff185c..82bc85099 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -139,7 +139,7 @@ bool ExportDialog::show() { set_modal (TRUE); //Window - sp_transientize((GtkWidget *)gobj()); //Make transient + sp_transientize(GTK_WIDGET(gobj())); //Make transient gint b = run(); //Dialog hide(); @@ -244,7 +244,7 @@ bool ExportPasswordDialog::show() { set_modal (TRUE); //Window - sp_transientize((GtkWidget *)gobj()); //Make transient + sp_transientize(GTK_WIDGET(gobj())); //Make transient gint b = run(); //Dialog hide(); @@ -957,40 +957,40 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next) { // Get items information - if (strcmp((const char*)cur_node->name, "rss")) // Avoid the root + if (strcmp(reinterpret_cast<const char*>(cur_node->name), "rss")) // Avoid the root if (cur_node->type == XML_ELEMENT_NODE && - (cur_node->parent->name && !strcmp((const char*)cur_node->parent->name, "item"))) + (cur_node->parent->name && !strcmp(reinterpret_cast<const char*>(cur_node->parent->name), "item"))) { - if (!strcmp((const char*)cur_node->name, "title")) + if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "title")) { row_num = append(""); xmlChar *xml_title = xmlNodeGetContent(cur_node); - char* title = (char*) xml_title; + char* title = reinterpret_cast<char*>(xml_title); set_text(row_num, RESULTS_COLUMN_TITLE, title); xmlFree(title); } - else if (!strcmp((const char*)cur_node->name, "pubDate")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "pubDate")) { xmlChar *xml_date = xmlNodeGetContent(cur_node); - char* date = (char*) xml_date; + char* date = reinterpret_cast<char*>(xml_date); set_text(row_num, RESULTS_COLUMN_DATE, date); xmlFree(xml_date); } - else if (!strcmp((const char*)cur_node->name, "creator")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "creator")) { xmlChar *xml_creator = xmlNodeGetContent(cur_node); - char* creator = (char*) xml_creator; + char* creator = reinterpret_cast<char*>(xml_creator); set_text(row_num, RESULTS_COLUMN_CREATOR, creator); xmlFree(xml_creator); } - else if (!strcmp((const char*)cur_node->name, "description")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "description")) { xmlChar *xml_description = xmlNodeGetContent(cur_node); //char* final_description; - char* stripped_description = g_strstrip((char*) xml_description); + char* stripped_description = g_strstrip(reinterpret_cast<char*>(xml_description)); if (!strcmp(stripped_description, "")) { stripped_description = _("No description"); @@ -1002,30 +1002,30 @@ void SearchResultList::populate_from_xml(xmlNode * a_node) set_text(row_num, RESULTS_COLUMN_DESCRIPTION, stripped_description); xmlFree(xml_description); } - else if (!strcmp((const char*)cur_node->name, "enclosure")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "enclosure")) { - xmlChar *xml_url = xmlGetProp(cur_node, (xmlChar*) "url"); - char* url = (char*) xml_url; + xmlChar *xml_url = xmlGetProp(cur_node, reinterpret_cast<xmlChar*>(g_strdup("url"))); + char* url = reinterpret_cast<char*>(xml_url); char* filename = g_path_get_basename(url); set_text(row_num, RESULTS_COLUMN_URL, url); set_text(row_num, RESULTS_COLUMN_FILENAME, filename); xmlFree(xml_url); } - else if (!strcmp((const char*)cur_node->name, "thumbnail")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "thumbnail")) { - xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, (xmlChar*) "url"); - char* thumbnail_url = (char*) xml_thumbnail_url; + xmlChar *xml_thumbnail_url = xmlGetProp(cur_node, reinterpret_cast<xmlChar*>(g_strdup("url"))); + char* thumbnail_url = reinterpret_cast<char*>(xml_thumbnail_url); char* thumbnail_filename = g_path_get_basename(thumbnail_url); set_text(row_num, RESULTS_COLUMN_THUMBNAIL_URL, thumbnail_url); set_text(row_num, RESULTS_COLUMN_THUMBNAIL_FILENAME, thumbnail_filename); xmlFree(xml_thumbnail_url); } - else if (!strcmp((const char*)cur_node->name, "guid")) + else if (!strcmp(reinterpret_cast<const char*>(cur_node->name), "guid")) { xmlChar *xml_guid = xmlNodeGetContent(cur_node); - char* guid_url = (char*) xml_guid; + char* guid_url = reinterpret_cast<char*>(xml_guid); char* guid = g_path_get_basename(guid_url); set_text(row_num, RESULTS_COLUMN_GUID, guid); @@ -1196,7 +1196,13 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types // Creation Gtk::VBox *vbox = new Gtk::VBox(false, 0); + +#if WITH_GTKMM_3_0 + Gtk::ButtonBox *hbuttonbox_bottom = new Gtk::ButtonBox(); +#else Gtk::HButtonBox *hbuttonbox_bottom = new Gtk::HButtonBox(); +#endif + Gtk::HBox *hbox_bottom = new Gtk::HBox(false, 12); BaseBox *basebox_logo = new BaseBox(); BaseBox *basebox_no_search_results = new BaseBox(); @@ -1204,7 +1210,13 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types label_description = new Gtk::Label(); entry_search = new SearchEntry(); button_search = new Gtk::Button(_("Search")); + +#if WITH_GTKMM_3_0 + Gtk::ButtonBox* hbuttonbox_search = new Gtk::ButtonBox(); +#else Gtk::HButtonBox* hbuttonbox_search = new Gtk::HButtonBox(); +#endif + Gtk::ScrolledWindow* scrolledwindow_preview = new Gtk::ScrolledWindow(); preview_files = new PreviewWidget(); /// Add the buttons in the bottom of the dialog diff --git a/src/ui/dialog/spellcheck.h b/src/ui/dialog/spellcheck.h index 8eb240097..ab75809f3 100644 --- a/src/ui/dialog/spellcheck.h +++ b/src/ui/dialog/spellcheck.h @@ -240,10 +240,20 @@ private: GtkWidget * dictionary_combo; Gtk::HBox dictionary_hbox; +#if WITH_GTKMM_3_0 + Gtk::Separator action_sep; +#else Gtk::HSeparator action_sep; +#endif + Gtk::Button stop_button; Gtk::Button start_button; + +#if WITH_GTKMM_3_0 + Gtk::ButtonBox actionbutton_hbox; +#else Gtk::HButtonBox actionbutton_hbox; +#endif SPDesktop * desktop; DesktopTracker deskTrack; diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 9d4ab5d8a..3188f1681 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -14,6 +14,9 @@ #include <iostream> #include <algorithm> +#include <locale> +#include <functional> +#include <sstream> #include <glibmm/i18n.h> @@ -43,6 +46,11 @@ #include "sp-use.h" #include "sp-symbol.h" +#ifdef WITH_LIBVISIO +#include <libvisio/libvisio.h> +#include <libwpd-stream/libwpd-stream.h> +#endif + #include "verbs.h" #include "xml/repr.h" @@ -289,6 +297,78 @@ void SymbolsDialog::iconChanged() { } } +#ifdef WITH_LIBVISIO +// Read Visio stencil files +SPDocument* read_vss( gchar* fullname, gchar* filename ) { + + WPXFileStream input(fullname); + + if (!libvisio::VisioDocument::isSupported(&input)) { + return NULL; + } + + libvisio::VSDStringVector output; + if (!libvisio::VisioDocument::generateSVGStencils(&input, output)) { + return NULL; + } + + if (output.empty()) { + return NULL; + } + + Glib::ustring tmpSVGOutput; + tmpSVGOutput += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; + tmpSVGOutput += "<svg\n"; + tmpSVGOutput += " xmlns=\"http://www.w3.org/2000/svg\"\n"; + tmpSVGOutput += " xmlns:svg=\"http://www.w3.org/2000/svg\"\n"; + tmpSVGOutput += " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"; + tmpSVGOutput += " version=\"1.1\"\n"; + tmpSVGOutput += " style=\"fill:none;stroke:#000000;stroke-width:2\">\n"; + tmpSVGOutput += " <title>"; + tmpSVGOutput += filename; + tmpSVGOutput += "</title>\n"; + tmpSVGOutput += " <defs>\n"; + + // Create a string we can use for the symbol id (libvisio doesn't give us a name) + std::string sanitized( filename ); + sanitized.erase( sanitized.find_last_of(".vss")-3 ); + sanitized.erase( std::remove_if( sanitized.begin(), sanitized.end(), ispunct ), sanitized.end() ); + std::replace( sanitized.begin(), sanitized.end(), ' ', '_' ); + // std::cout << filename << " |" << sanitized << "|" << std::endl; + + // Each "symbol" is in it's own SVG file, we wrap with <symbol> and merge into one file. + for (unsigned i=0; i<output.size(); ++i) { + + std::stringstream ss; + ss << i; + + tmpSVGOutput += " <symbol id=\""; + tmpSVGOutput += sanitized; + tmpSVGOutput += "_"; + tmpSVGOutput += ss.str(); + tmpSVGOutput += "\">\n"; + + std::istringstream iss( output[i].cstr() ); + std::string line; + while( std::getline( iss, line ) ) { + // std::cout << line << std::endl; + if( line.find( "svg:svg" ) == std::string::npos ) { + tmpSVGOutput += line; + tmpSVGOutput += "\n"; + } + } + + tmpSVGOutput += " </symbol>\n"; + } + + tmpSVGOutput += " </defs>\n"; + tmpSVGOutput += "</svg>\n"; + + return SPDocument::createNewDocFromMem( tmpSVGOutput.c_str(), strlen( tmpSVGOutput.c_str()), 0 ); + +} +#endif + /* Hunts preference directories for symbol files */ void SymbolsDialog::get_symbols() { @@ -317,11 +397,31 @@ void SymbolsDialog::get_symbols() { if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) ) { - SPDocument* symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); - if( symbol_doc ) { - symbolSets[Glib::ustring(filename)]= symbol_doc; - symbolSet->append(filename); + Glib::ustring fn( filename ); + Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); + + SPDocument* symbol_doc = NULL; + +#ifdef WITH_LIBVISIO + if( tag.compare( "vss" ) == 0 ) { + + symbol_doc = read_vss( fullname, filename ); + if( symbol_doc ) { + symbolSets[Glib::ustring(filename)]= symbol_doc; + symbolSet->append(filename); + } } +#endif + // Try to read all remaining files as SVG + if( !symbol_doc ) { + + symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); + if( symbol_doc ) { + symbolSets[Glib::ustring(filename)]= symbol_doc; + symbolSet->append(filename); + } + } + } g_free( fullname ); } diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 6696db083..97cd28cdd 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -95,11 +95,21 @@ TextEdit::TextEdit() styleButton(&align_center, _("Align center"), GTK_STOCK_JUSTIFY_CENTER, &align_left); styleButton(&align_right, _("Align right"), GTK_STOCK_JUSTIFY_RIGHT, &align_left); styleButton(&align_justify, _("Justify (only flowed text)"), GTK_STOCK_JUSTIFY_FILL, &align_left); + +#if WITH_GTKMM_3_0 + align_sep.set_orientation(Gtk::ORIENTATION_VERTICAL); +#endif + layout_hbox.pack_start(align_sep, false, false, 10); /* Direction buttons */ styleButton(&text_horizontal, _("Horizontal text"), INKSCAPE_ICON("format-text-direction-horizontal"), NULL); styleButton(&text_vertical, _("Vertical text"), INKSCAPE_ICON("format-text-direction-vertical"), &text_horizontal); + +#if WITH_GTKMM_3_0 + text_sep.set_orientation(Gtk::ORIENTATION_VERTICAL); +#endif + layout_hbox.pack_start(text_sep, false, false, 10); /* Line Spacing */ diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h index 9fd9baa30..bca6cee90 100644 --- a/src/ui/dialog/text-edit.h +++ b/src/ui/dialog/text-edit.h @@ -172,10 +172,22 @@ private: Gtk::RadioButton align_center; Gtk::RadioButton align_right; Gtk::RadioButton align_justify; + +#if WITH_GTKMM_3_0 + Gtk::Separator align_sep; +#else Gtk::VSeparator align_sep; +#endif + Gtk::RadioButton text_vertical; Gtk::RadioButton text_horizontal; + +#if WITH_GTKMM_3_0 + Gtk::Separator text_sep; +#else Gtk::VSeparator text_sep; +#endif + GtkWidget *spacing_combo; Gtk::Label preview_label; diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 1ce78a278..410cdbda9 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -194,7 +194,7 @@ void TileDialog::Grid_Arrange () g_return_if_fail(selection); const GSList *items2 = selection->itemList(); - GSList *rev = g_slist_copy((GSList *) items2); + GSList *rev = g_slist_copy(const_cast<GSList *>(items2)); GSList *sorted = NULL; rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); @@ -667,7 +667,7 @@ TileDialog::TileDialog() NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_col_spinbutton_changed)); NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); + gtk_size_group_add_widget(_col1, GTK_WIDGET(NoOfRowsBox.gobj())); RowHeightButton.set_label(_("Equal _height")); RowHeightButton.set_use_underline(true); @@ -724,7 +724,7 @@ TileDialog::TileDialog() XByYLabel.set_markup(" × "); XByYLabelVBox.pack_start(XByYLabel, false, false, MARGIN); SpinsHBox.pack_start(XByYLabelVBox, false, false, MARGIN); - gtk_size_group_add_widget(_col2, (GtkWidget *) XByYLabelVBox.gobj()); + gtk_size_group_add_widget(_col2, GTK_WIDGET(XByYLabelVBox.gobj())); /*#### Number of columns ####*/ @@ -739,7 +739,7 @@ TileDialog::TileDialog() NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_row_spinbutton_changed)); NoOfColsSpinner.set_tooltip_text(_("Number of columns")); NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); + gtk_size_group_add_widget(_col3, GTK_WIDGET(NoOfColsBox.gobj())); ColumnWidthButton.set_label(_("Equal _width")); ColumnWidthButton.set_use_underline(true); diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index b21932f99..29dbc4b93 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -79,7 +79,11 @@ XmlTree::XmlTree (void) : xml_attribute_delete_button (_("Delete attribute")), text_container (), attr_container (), - attr_subpaned_container (), +#if WITH_GTKMM_3_0 + attr_subpaned_container(Gtk::ORIENTATION_VERTICAL), +#else + attr_subpaned_container(), +#endif set_attr (_("Set")), new_window(NULL) { diff --git a/src/ui/dialog/xml-tree.h b/src/ui/dialog/xml-tree.h index ee1dadc14..9d2fac71f 100644 --- a/src/ui/dialog/xml-tree.h +++ b/src/ui/dialog/xml-tree.h @@ -13,6 +13,10 @@ #ifndef SEEN_DIALOGS_XML_TREE_H #define SEEN_DIALOGS_XML_TREE_H +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include "ui/widget/panel.h" #include <gtkmm/entry.h> #include <gtkmm/textview.h> @@ -215,7 +219,12 @@ private: Gtk::Button *create_button; Gtk::Entry *name_entry; +#if WITH_GTKMM_3_0 + Gtk::Paned paned; +#else Gtk::HPaned paned; +#endif + Gtk::VBox left_box; Gtk::VBox right_box; Gtk::HBox status_box; @@ -239,7 +248,13 @@ private: Gtk::ScrolledWindow text_container; Gtk::HBox attr_hbox; Gtk::VBox attr_container; + +#if WITH_GTKMM_3_0 + Gtk::Paned attr_subpaned_container; +#else Gtk::VPaned attr_subpaned_container; +#endif + Gtk::Button set_attr; GtkWidget *new_window; diff --git a/src/ui/widget/color-preview.cpp b/src/ui/widget/color-preview.cpp index 3ebb282ec..4b4a7b738 100644 --- a/src/ui/widget/color-preview.cpp +++ b/src/ui/widget/color-preview.cpp @@ -26,13 +26,6 @@ ColorPreview::ColorPreview (guint32 rgba) } void -ColorPreview::on_size_request (Gtk::Requisition *req) -{ - req->width = SPCP_DEFAULT_WIDTH; - req->height = SPCP_DEFAULT_HEIGHT; -} - -void ColorPreview::on_size_allocate (Gtk::Allocation &all) { set_allocation (all); @@ -40,14 +33,55 @@ ColorPreview::on_size_allocate (Gtk::Allocation &all) queue_draw(); } +#if WITH_GTKMM_3_0 +void +ColorPreview::get_preferred_height_vfunc(int& minimum_height, int& natural_height) const +{ + minimum_height = natural_height = SPCP_DEFAULT_HEIGHT; +} + +void +ColorPreview::get_preferred_height_for_width_vfunc(int /* width */, int& minimum_height, int& natural_height) const +{ + minimum_height = natural_height = SPCP_DEFAULT_HEIGHT; +} + +void +ColorPreview::get_preferred_width_vfunc(int& minimum_width, int& natural_width) const +{ + minimum_width = natural_width = SPCP_DEFAULT_WIDTH; +} + +void +ColorPreview::get_preferred_width_for_height_vfunc(int /* height */, int& minimum_width, int& natural_width) const +{ + minimum_width = natural_width = SPCP_DEFAULT_WIDTH; +} +#else +void +ColorPreview::on_size_request (Gtk::Requisition *req) +{ + req->width = SPCP_DEFAULT_WIDTH; + req->height = SPCP_DEFAULT_HEIGHT; +} + bool ColorPreview::on_expose_event (GdkEventExpose *event) { + bool result = true; + if (get_is_drawable()) - paint (&event->area); + { + Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context(); + cr->rectangle(event->area.x, event->area.y, + event->area.width, event->area.height); + cr->clip(); + result = on_draw(cr); + } - return true; + return result; } +#endif void ColorPreview::setRgba32 (guint32 rgba) @@ -58,11 +92,10 @@ ColorPreview::setRgba32 (guint32 rgba) queue_draw(); } -void -ColorPreview::paint (GdkRectangle *area) +bool +ColorPreview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { GdkRectangle warea, carea; - GdkRectangle wpaint, cpaint; gint w2; const Gtk::Allocation& allocation = get_allocation(); @@ -71,12 +104,6 @@ ColorPreview::paint (GdkRectangle *area) warea.width = allocation.get_width(); warea.height = allocation.get_height(); - if (!gdk_rectangle_intersect (area, &warea, &wpaint)) - return; - - GtkWidget *widget = GTK_WIDGET(this->gobj()); - cairo_t *ct = gdk_cairo_create(gtk_widget_get_window(widget)); - /* Transparent area */ w2 = warea.width / 2; @@ -86,17 +113,15 @@ ColorPreview::paint (GdkRectangle *area) carea.width = w2; carea.height = warea.height; - if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - cairo_pattern_t *checkers = ink_cairo_pattern_create_checkerboard(); + cairo_pattern_t *checkers = ink_cairo_pattern_create_checkerboard(); - cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); - cairo_set_source(ct, checkers); - cairo_fill_preserve(ct); - ink_cairo_set_source_rgba32(ct, _rgba); - cairo_fill(ct); + cr->rectangle(carea.x, carea.y, carea.width, carea.height); + cairo_set_source(cr->cobj(), checkers); + cr->fill_preserve(); + ink_cairo_set_source_rgba32(cr->cobj(), _rgba); + cr->fill(); - cairo_pattern_destroy(checkers); - } + cairo_pattern_destroy(checkers); /* Solid area */ @@ -105,13 +130,11 @@ ColorPreview::paint (GdkRectangle *area) carea.width = warea.width - w2; carea.height = warea.height; - if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); - ink_cairo_set_source_rgba32(ct, _rgba | 0xff); - cairo_fill(ct); - } + cr->rectangle(carea.x, carea.y, carea.width, carea.height); + ink_cairo_set_source_rgba32(cr->cobj(), _rgba | 0xff); + cr->fill(); - cairo_destroy(ct); + return true; } GdkPixbuf* @@ -173,3 +196,4 @@ ColorPreview::toPixbuf (int width, int height) fill-column:99 End: */ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/color-preview.h b/src/ui/widget/color-preview.h index d6d3da01c..caddfb9a2 100644 --- a/src/ui/widget/color-preview.h +++ b/src/ui/widget/color-preview.h @@ -11,6 +11,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include <gtkmm/widget.h> namespace Inkscape { @@ -27,10 +31,19 @@ public: GdkPixbuf* toPixbuf (int width, int height); protected: - virtual void on_size_request (Gtk::Requisition *req); virtual void on_size_allocate (Gtk::Allocation &all); - virtual bool on_expose_event (GdkEventExpose *event); - void paint (GdkRectangle *area); + +#if WITH_GTKMM_3_0 + virtual void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const; + virtual void get_preferred_height_for_width_vfunc(int width, int& minimum_height, int& natural_height) const; + virtual void get_preferred_width_vfunc(int& minimum_width, int& natural_width) const; + virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const; +#else + virtual void on_size_request (Gtk::Requisition *req); + virtual bool on_expose_event(GdkEventExpose *event); +#endif + + virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr); guint32 _rgba; }; diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index 567608ef8..1c36dc36e 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -117,7 +117,7 @@ bool ImageIcon::showSvgDocument(const SPDocument *docArg) viewerGtkmm->show(); pack_start(*viewerGtkmm, TRUE, TRUE, 0); - //GtkWidget *vbox = (GtkWidget *)gobj(); + //GtkWidget *vbox = GTK_WIDGET(gobj()); //gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0); return true; @@ -306,7 +306,7 @@ void ImageIcon::showBrokenImage(const Glib::ustring &errorMessage) "</svg>"; //Fill in the template - char *cErrorMessage = (char *)errorMessage.c_str(); + char *cErrorMessage = const_cast<char *>(errorMessage.c_str()); gchar *xmlBuffer = g_strdup_printf(xformat, cErrorMessage); //g_message("%s\n", xmlBuffer); @@ -375,7 +375,7 @@ bool ImageIcon::show(const Glib::ustring &fileName) if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) return false; - gchar *fName = (gchar *)fileName.c_str(); + gchar *fName = const_cast<gchar *>(fileName.c_str()); //g_message("fname:%s\n", fName); diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index 2789676ea..537db0fdd 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -89,8 +89,8 @@ ObjectCompositeSettings::ObjectCompositeSettings(unsigned int verb_code, char co /* SizeGroup keeps the blur and opacity labels aligned in Fill & Stroke dlg */ /* GtkSizeGroup *labels = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget(labels, (GtkWidget *) _opacity_label.gobj()); - gtk_size_group_add_widget(labels, (GtkWidget *) _fe_cb.get_blur_label()->gobj()); + gtk_size_group_add_widget(labels, GTK_WIDGET(_opacity_label.gobj())); + gtk_size_group_add_widget(labels, GTK_WIDGET(_fe_cb.get_blur_label()->gobj())); */ show_all_children(); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 2ab72d6c7..fa3f8e3a1 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -330,14 +330,36 @@ PageSizer::PageSizer(Registry & _wr) pack_start (_customFrame, false, false, 0); _customFrame.add(_customDimTable); - _customDimTable.resize(3, 2); _customDimTable.set_border_width(4); + +#if WITH_GTKMM_3_0 + _customDimTable.set_row_spacing(4); + _customDimTable.set_column_spacing(4); + + _dimensionWidth.set_hexpand(); + _dimensionWidth.set_vexpand(); + _customDimTable.attach(_dimensionWidth, 0, 0, 1, 1); + + _dimensionUnits.set_hexpand(); + _dimensionUnits.set_vexpand(); + _customDimTable.attach(_dimensionUnits, 1, 0, 1, 1); + + _dimensionHeight.set_hexpand(); + _dimensionHeight.set_vexpand(); + _customDimTable.attach(_dimensionHeight, 0, 1, 1, 1); + + _fitPageMarginExpander.set_hexpand(); + _fitPageMarginExpander.set_vexpand(); + _customDimTable.attach(_fitPageMarginExpander, 0, 2, 2, 1); +#else + _customDimTable.resize(3, 2); _customDimTable.set_row_spacings(4); _customDimTable.set_col_spacings(4); _customDimTable.attach(_dimensionWidth, 0,1, 0,1); _customDimTable.attach(_dimensionUnits, 1,2, 0,1); _customDimTable.attach(_dimensionHeight, 0,1, 1,2); _customDimTable.attach(_fitPageMarginExpander, 0,2, 2,3); +#endif _dimTabOrderGList = NULL; _dimTabOrderGList = g_list_append(_dimTabOrderGList, _dimensionWidth.gobj()); @@ -353,7 +375,32 @@ PageSizer::PageSizer(Registry & _wr) _fitPageMarginExpander.add(_marginTable); //## Set up margin settings - _marginTable.resize(4, 2); + _marginTable.set_border_width(4); + +#if WITH_GTKMM_3_0 + _marginTable.set_row_spacing(4); + _marginTable.set_column_spacing(4); + + _marginTopAlign.set_hexpand(); + _marginTopAlign.set_vexpand(); + _marginTable.attach(_marginTopAlign, 0, 0, 2, 1); + + _marginLeftAlign.set_hexpand(); + _marginLeftAlign.set_vexpand(); + _marginTable.attach(_marginLeftAlign, 0, 1, 1, 1); + + _marginRightAlign.set_hexpand(); + _marginRightAlign.set_vexpand(); + _marginTable.attach(_marginRightAlign, 1, 1, 1, 1); + + _marginBottomAlign.set_hexpand(); + _marginBottomAlign.set_vexpand(); + _marginTable.attach(_marginBottomAlign, 0, 2, 2, 1); + + _fitPageButtonAlign.set_hexpand(); + _fitPageButtonAlign.set_vexpand(); + _marginTable.attach(_fitPageButtonAlign, 0, 3, 2, 1); +#else _marginTable.set_border_width(4); _marginTable.set_row_spacings(4); _marginTable.set_col_spacings(4); @@ -362,6 +409,7 @@ PageSizer::PageSizer(Registry & _wr) _marginTable.attach(_marginRightAlign, 1,2, 1,2); _marginTable.attach(_marginBottomAlign, 0,2, 2,3); _marginTable.attach(_fitPageButtonAlign, 0,2, 3,4); +#endif _marginTopAlign.set(0.5, 0.5, 0.0, 1.0); _marginTopAlign.add(_marginTop); diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 17fd7b1ea..d1fbb56e0 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -10,6 +10,10 @@ #ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER_H #define INKSCAPE_UI_WIDGET_PAGE_SIZER_H +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include <stddef.h> #include "ui/widget/registered-widget.h" #include <sigc++/sigc++.h> @@ -21,7 +25,13 @@ #include <gtkmm/frame.h> #include <gtkmm/liststore.h> #include <gtkmm/scrolledwindow.h> -#include <gtkmm/table.h> + +#if WITH_GTKMM_3_0 +# include <gtkmm/grid.h> +#else +# include <gtkmm/table.h> +#endif + #include <gtkmm/radiobutton.h> namespace Inkscape { @@ -207,7 +217,13 @@ protected: //### Custom size frame Gtk::Frame _customFrame; + +#if WITH_GTKMM_3_0 + Gtk::Grid _customDimTable; +#else Gtk::Table _customDimTable; +#endif + RegisteredUnitMenu _dimensionUnits; RegisteredScalarUnit _dimensionWidth; RegisteredScalarUnit _dimensionHeight; @@ -215,7 +231,13 @@ protected: //### Fit Page options Gtk::Expander _fitPageMarginExpander; + +#if WITH_GTKMM_3_0 + Gtk::Grid _marginTable; +#else Gtk::Table _marginTable; +#endif + Gtk::Alignment _marginTopAlign; Gtk::Alignment _marginLeftAlign; Gtk::Alignment _marginRightAlign; diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index dcf5956bf..48749fda2 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -591,7 +591,13 @@ void Panel::_addResponseButton(Gtk::Button *button, int response_id, bool pack_s { // Create a button box for the response buttons if it's the first button to be added if (!_action_area) { +#if WITH_GTKMM_3_0 + _action_area = new Gtk::ButtonBox(); + _action_area->set_layout(Gtk::BUTTONBOX_END); + _action_area->set_spacing(6); +#else _action_area = new Gtk::HButtonBox(Gtk::BUTTONBOX_END, 6); +#endif _action_area->set_border_width(4); pack_end(*_action_area, Gtk::PACK_SHRINK, 0); } diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index b4cc04809..5bb054577 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -13,6 +13,10 @@ #ifndef SEEN_INKSCAPE_UI_WIDGET_PANEL_H #define SEEN_INKSCAPE_UI_WIDGET_PANEL_H +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include <gtkmm/box.h> #include <gtkmm/arrow.h> #include <gtkmm/button.h> @@ -27,7 +31,13 @@ class SPDocument; namespace Gtk { class CheckMenuItem; + +#if WITH_GTKMM_3_0 + class ButtonBox; +#else class HButtonBox; +#endif + class MenuItem; } @@ -157,7 +167,13 @@ private: Gtk::EventBox _menu_popper; Gtk::Button _close_button; Gtk::Menu *_menu; + +#if WITH_GTKMM_3_0 + Gtk::ButtonBox *_action_area; //< stores response buttons +#else Gtk::HButtonBox *_action_area; //< stores response buttons +#endif + std::vector<Gtk::Widget *> _non_horizontal; std::vector<Gtk::Widget *> _non_vertical; PreviewFillable *_fillable; diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index e7e317d11..e5b062ec9 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -373,10 +373,27 @@ ZoomCorrRuler::draw_marks(Cairo::RefPtr<Cairo::Context> cr, double dist, int maj } } -void -ZoomCorrRuler::redraw() { +#if !WITH_GTKMM_3_0 +bool +ZoomCorrRuler::on_expose_event(GdkEventExpose *event) { + bool result = false; + + if(get_is_drawable()) + { + Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context(); + cr->rectangle(event->area.x, event->area.y, + event->area.width, event->area.height); + cr->clip(); + result = on_draw(cr); + } + + return result; +} +#endif + +bool +ZoomCorrRuler::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { Glib::RefPtr<Gdk::Window> window = get_window(); - Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); int w = window->get_width(); _drawing_width = w - _border * 2; @@ -415,14 +432,11 @@ ZoomCorrRuler::redraw() { draw_marks(cr, 1, 1); } cr->stroke(); -} -bool -ZoomCorrRuler::on_expose_event(GdkEventExpose */*event*/) { - this->redraw(); return true; } + void ZoomCorrRulerSlider::on_slider_value_changed() { @@ -432,7 +446,7 @@ ZoomCorrRulerSlider::on_slider_value_changed() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/options/zoomcorrection/value", _slider.get_value() / 100.0); _sb.set_value(_slider.get_value()); - _ruler.redraw(); + _ruler.queue_draw(); freeze = false; } } @@ -446,7 +460,7 @@ ZoomCorrRulerSlider::on_spinbutton_value_changed() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/options/zoomcorrection/value", _sb.get_value() / 100.0); _slider.set_value(_sb.get_value()); - _ruler.redraw(); + _ruler.queue_draw(); freeze = false; } } @@ -463,7 +477,7 @@ ZoomCorrRulerSlider::on_unit_changed() { double conv = _unit.getConversion(_unit.getUnitAbbr(), "px"); _ruler.set_unit_conversion(conv); if (_ruler.get_visible()) { - _ruler.redraw(); + _ruler.queue_draw(); } } diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index bfe0deaba..646a8b2fa 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -101,8 +101,6 @@ public: ZoomCorrRuler(int width = 100, int height = 20); void set_size(int x, int y); void set_unit_conversion(double conv) { _unitconv = conv; } - void set_cairo_context(Cairo::RefPtr<Cairo::Context> cr); - void redraw(); int width() { return _min_width + _border*2; } @@ -110,7 +108,12 @@ public: static const double textpadding; private: +#if !WITH_GTKMM_3_0 bool on_expose_event(GdkEventExpose *event); +#endif + + bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr); + void draw_marks(Cairo::RefPtr<Cairo::Context> cr, double dist, int major_interval); double _unitconv; diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 1ac083276..d7be6c9f0 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -76,11 +76,11 @@ GType sp_button_get_type(void) static void sp_button_class_init (SPButtonClass *klass) { - GObjectClass *object_class=(GObjectClass *)klass; - GtkWidgetClass *widget_class=(GtkWidgetClass *)klass; - GtkButtonClass *button_class=(GtkButtonClass *)klass; + GObjectClass *object_class=G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class=GTK_WIDGET_CLASS(klass); + GtkButtonClass *button_class=GTK_BUTTON_CLASS(klass); - parent_class = (GtkToggleButtonClass *)g_type_class_peek_parent (klass); + parent_class = GTK_TOGGLE_BUTTON_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_button_dispose; #if GTK_CHECK_VERSION(3,0,0) @@ -123,7 +123,7 @@ static void sp_button_dispose(GObject *object) button->c_set_active.~connection(); button->c_set_sensitive.~connection(); - ((GObjectClass *) (parent_class))->dispose(object); + (G_OBJECT_CLASS(parent_class))->dispose(object); } @@ -185,7 +185,7 @@ sp_button_clicked (GtkButton *button) SPButton *sp_button=SP_BUTTON (button); if (sp_button->type == SP_BUTTON_TYPE_TOGGLE) { - ((GtkButtonClass *) (parent_class))->clicked (button); + (GTK_BUTTON_CLASS(parent_class))->clicked (button); } } @@ -230,7 +230,7 @@ sp_button_new( Inkscape::IconSize size, SPButtonType type, SPAction *action, SPA // The Inkscape style is no-relief buttons gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); - return (GtkWidget *) button; + return GTK_WIDGET(button); } void @@ -287,7 +287,7 @@ sp_button_set_action (SPButton *button, SPAction *action) } } - sp_button_set_composed_tooltip ((GtkWidget *) button, action); + sp_button_set_composed_tooltip(GTK_WIDGET(button), action); } static void diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 3791ec73c..a7432c32a 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -303,8 +303,8 @@ sp_desktop_widget_class_init (SPDesktopWidgetClass *klass) { dtw_parent_class = SP_VIEW_WIDGET_CLASS(g_type_class_peek_parent(klass)); - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); object_class->dispose = sp_desktop_widget_dispose; @@ -321,8 +321,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) new (&dtw->modified_connection) sigc::connection(); - GtkWidget *widget = GTK_WIDGET (dtw); - dtw->window = 0; dtw->desktop = NULL; dtw->_interaction_disabled_counter = 0; @@ -330,7 +328,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) /* Main table */ #if GTK_CHECK_VERSION(3,0,0) dtw->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_box_set_homogeneous(GTK_BOX(dtw->vbox), FALSE); #else dtw->vbox = gtk_vbox_new (FALSE, 0); #endif @@ -338,7 +335,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) dtw->statusbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous(GTK_BOX(dtw->statusbar), FALSE); #else dtw->statusbar = gtk_hbox_new (FALSE, 0); #endif @@ -355,7 +351,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) dtw->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous(GTK_BOX(dtw->hbox), FALSE); #else dtw->hbox = gtk_hbox_new(FALSE, 0); #endif @@ -381,11 +376,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) GtkWidget *eventbox = gtk_event_box_new (); dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL); dtw->hruler_box = eventbox; - sp_ruler_set_metric(SP_RULER(dtw->hruler), SP_PT); + sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT); gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler); - guint xthickness = gtk_widget_get_style(widget)->xthickness; - guint ythickness = gtk_widget_get_style(widget)->ythickness; g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_hruler_event), dtw); @@ -394,21 +387,16 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) GtkWidget *tbl = gtk_grid_new(); GtkWidget *canvas_tbl = gtk_grid_new(); - gtk_widget_set_margin_left(eventbox, xthickness); - gtk_widget_set_margin_right(eventbox, xthickness); - - gtk_widget_set_halign(eventbox, GTK_ALIGN_FILL); - gtk_widget_set_hexpand(eventbox, TRUE); - gtk_widget_set_valign(eventbox, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(canvas_tbl), eventbox, 1, 0, 1, 1); #else GtkWidget *tbl = gtk_table_new(2, 3, FALSE); GtkWidget *canvas_tbl = gtk_table_new(3, 3, FALSE); - gtk_table_attach(GTK_TABLE (canvas_tbl), eventbox, 1, 2, 0, 1, - GTK_FILL, GTK_FILL, - xthickness, 0); + gtk_table_attach(GTK_TABLE(canvas_tbl), + eventbox, + 1, 2, 0, 1, + GTK_FILL, GTK_FILL, + 0, 0); #endif gtk_box_pack_start( GTK_BOX(dtw->hbox), tbl, TRUE, TRUE, 1 ); @@ -417,23 +405,18 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) eventbox = gtk_event_box_new (); dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL); dtw->vruler_box = eventbox; - sp_ruler_set_metric (SP_RULER (dtw->vruler), SP_PT); + sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT); gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_margin_top(eventbox, ythickness); - gtk_widget_set_margin_bottom(eventbox, ythickness); - - gtk_widget_set_halign(eventbox, GTK_ALIGN_START); - gtk_widget_set_valign(eventbox, GTK_ALIGN_FILL); - gtk_widget_set_vexpand(eventbox, TRUE); - gtk_grid_attach(GTK_GRID(canvas_tbl), eventbox, 0, 1, 1, 1); #else - gtk_table_attach(GTK_TABLE (canvas_tbl), eventbox, 0, 1, 1, 2, - GTK_FILL, GTK_FILL, - 0, ythickness); + gtk_table_attach(GTK_TABLE (canvas_tbl), + eventbox, + 0, 1, 1, 2, + GTK_FILL, GTK_FILL, + 0, 0); #endif g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_vruler_event), dtw); @@ -441,15 +424,12 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_vruler_event), dtw); // Horizontal scrollbar - dtw->hadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0); + dtw->hadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0)); #if GTK_CHECK_VERSION(3,0,0) dtw->hscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (dtw->hadj)); - gtk_widget_set_halign(dtw->hscrollbar, GTK_ALIGN_FILL); - gtk_widget_set_hexpand(dtw->hscrollbar, TRUE); gtk_grid_attach(GTK_GRID(canvas_tbl), dtw->hscrollbar, 1, 2, 1, 1); dtw->vscrollbar_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_box_set_homogeneous(GTK_BOX(dtw->vscrollbar_box), FALSE); #else dtw->hscrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (dtw->hadj)); gtk_table_attach(GTK_TABLE (canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, @@ -469,7 +449,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) g_signal_connect (G_OBJECT (dtw->sticky_zoom), "toggled", G_CALLBACK (sp_dtw_sticky_zoom_toggled), dtw); // Vertical scrollbar - dtw->vadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0); + dtw->vadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0)); #if GTK_CHECK_VERSION(3,0,0) dtw->vscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT(dtw->vadj)); @@ -480,8 +460,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->vscrollbar, TRUE, TRUE, 0); #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_valign(dtw->vscrollbar, GTK_ALIGN_FILL); - gtk_widget_set_vexpand(dtw->vscrollbar, TRUE); gtk_grid_attach(GTK_GRID(canvas_tbl), dtw->vscrollbar_box, 2, 0, 1, 2); #else gtk_table_attach(GTK_TABLE(canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, @@ -561,8 +539,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) g_signal_connect (G_OBJECT (dtw->canvas), "event", G_CALLBACK (sp_desktop_widget_event), dtw); #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_halign(GTK_WIDGET(dtw->canvas), GTK_ALIGN_FILL); - gtk_widget_set_valign(GTK_WIDGET(dtw->canvas), GTK_ALIGN_FILL); gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(dtw->canvas), TRUE); gtk_grid_attach(GTK_GRID(canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 1, 1, 1); @@ -578,7 +554,12 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) if (create_dock) { dtw->dock = new Inkscape::UI::Widget::Dock(); +#if WITH_GTKMM_3_0 + Gtk::Paned *paned = new Gtk::Paned(); +#else Gtk::HPaned *paned = new Gtk::HPaned(); +#endif + paned->pack1(*Glib::wrap(canvas_tbl)); paned->pack2(dtw->dock->getWidget(), Gtk::FILL); @@ -591,8 +572,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(paned->gobj()), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(paned->gobj()), TRUE); - gtk_widget_set_halign(GTK_WIDGET(paned->gobj()), GTK_ALIGN_FILL); - gtk_widget_set_valign(GTK_WIDGET(paned->gobj()), GTK_ALIGN_FILL); gtk_grid_attach(GTK_GRID(tbl), GTK_WIDGET (paned->gobj()), 1, 1, 1, 1); #else gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (paned->gobj()), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), @@ -603,8 +582,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(canvas_tbl), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(canvas_tbl), TRUE); - gtk_widget_set_halign(GTK_WIDGET(canvas_tbl), GTK_ALIGN_FILL); - gtk_widget_set_valign(GTK_WIDGET(canvas_tbl), GTK_ALIGN_FILL); gtk_grid_attach(GTK_GRID(tbl), GTK_WIDGET (canvas_tbl), 1, 1, 1, 1); #else gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), @@ -811,7 +788,7 @@ static void sp_desktop_widget_dispose(GObject *object) void SPDesktopWidget::updateTitle(gchar const* uri) { - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (window) { gchar const *fname = uri; @@ -1121,7 +1098,7 @@ SPDesktopWidget::shutdown() switch (response) { case GTK_RESPONSE_YES: { - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); doc->doRef(); sp_namedview_document_from_window(desktop); @@ -1185,7 +1162,7 @@ SPDesktopWidget::shutdown() { doc->doRef(); - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (sp_file_save_dialog(*window, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG)) { doc->doUnref(); @@ -1297,7 +1274,7 @@ SPDesktopWidget::getWindowGeometry (gint &x, gint &y, gint &w, gint &h) gboolean vis = gtk_widget_get_visible (GTK_WIDGET(this)); (void)vis; // TODO figure out why it is here but not used. - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (window) { @@ -1309,7 +1286,7 @@ SPDesktopWidget::getWindowGeometry (gint &x, gint &y, gint &w, gint &h) void SPDesktopWidget::setWindowPosition (Geom::Point p) { - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (window) { @@ -1320,7 +1297,7 @@ SPDesktopWidget::setWindowPosition (Geom::Point p) void SPDesktopWidget::setWindowSize (gint w, gint h) { - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (window) { @@ -1338,10 +1315,10 @@ SPDesktopWidget::setWindowSize (gint w, gint h) void SPDesktopWidget::setWindowTransient (void *p, int transient_policy) { - Gtk::Window *window = (Gtk::Window*)g_object_get_data(G_OBJECT(this), "window"); + Gtk::Window *window = static_cast<Gtk::Window*>(g_object_get_data(G_OBJECT(this), "window")); if (window) { - GtkWindow *w = (GtkWindow *) window->gobj(); + GtkWindow *w = GTK_WINDOW(window->gobj()); gtk_window_set_transient_for (GTK_WINDOW(p), w); /* @@ -1586,7 +1563,7 @@ SPDesktopWidget::setToolboxSelectOneValue (gchar const *id, int value) { gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) id); if (hb) { - ege_select_one_action_set_active((EgeSelectOneAction*) hb, value); + ege_select_one_action_set_active(EGE_SELECT_ONE_ACTION(hb), value); } } @@ -1712,55 +1689,28 @@ void SPDesktopWidget::viewSetPosition (Geom::Point p) { Geom::Point const origin = ( p - ruler_origin ); - gdouble hlower, hupper, hmax_range; - gdouble vlower, vupper, vmax_range; - sp_ruler_get_range(SP_RULER(hruler), &hlower, &hupper, NULL, &hmax_range); - sp_ruler_set_range(SP_RULER(hruler), hlower, hupper, origin[Geom::X], hmax_range); - sp_ruler_get_range(SP_RULER(vruler), &vlower, &vupper, NULL, &vmax_range); - sp_ruler_set_range(SP_RULER(vruler), vlower, vupper, origin[Geom::Y], vmax_range); + sp_ruler_set_position(SP_RULER(hruler), origin[Geom::X]); + sp_ruler_set_position(SP_RULER(vruler), origin[Geom::Y]); } void sp_desktop_widget_update_rulers (SPDesktopWidget *dtw) { - sp_desktop_widget_update_hruler(dtw); - sp_desktop_widget_update_vruler(dtw); -} - -void -sp_desktop_widget_update_hruler (SPDesktopWidget *dtw) -{ - /* The viewbox (in integers) must exactly match the size of SPCanvasbuf's pixel buffer. - * This is important because the former is being used for drawing the ruler, whereas - * the latter is used for drawing e.g. the grids and guides. Only when the viewbox - * coincides with the pixel buffer, everything will line up nicely. - */ - Geom::IntRect viewbox = dtw->canvas->getViewboxIntegers(); - gdouble position; + Geom::Rect viewbox = dtw->desktop->get_display_area(); - double const scale = dtw->desktop->current_zoom(); - double s = viewbox.min()[Geom::X] / scale - dtw->ruler_origin[Geom::X]; - double e = viewbox.max()[Geom::X] / scale - dtw->ruler_origin[Geom::X]; - sp_ruler_get_range(SP_RULER(dtw->hruler), NULL, NULL, &position, NULL); - sp_ruler_set_range(SP_RULER(dtw->hruler), s, e, position, (e - s)); -} - -void -sp_desktop_widget_update_vruler (SPDesktopWidget *dtw) -{ - /* The viewbox (in integers) must exactly match the size of SPCanvasbuf's pixel buffer. - * This is important because the former is being used for drawing the ruler, whereas - * the latter is used for drawing e.g. the grids and guides. Only when the viewbox - * coincides with the pixel buffer, everything will line up nicely. - */ - Geom::IntRect viewbox = dtw->canvas->getViewboxIntegers(); - gdouble position; + double lower_x = dtw->dt2r * (viewbox.left() - dtw->ruler_origin[Geom::X]); + double upper_x = dtw->dt2r * (viewbox.right() - dtw->ruler_origin[Geom::X]); + sp_ruler_set_range(SP_RULER(dtw->hruler), + lower_x, + upper_x, + (upper_x - lower_x)); - double const scale = dtw->desktop->current_zoom(); - double s = viewbox.min()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; - double e = viewbox.max()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; - sp_ruler_get_range(SP_RULER(dtw->vruler), NULL, NULL, &position, NULL); - sp_ruler_set_range(SP_RULER(dtw->vruler), s, e, position, (e - s)); + double lower_y = dtw->dt2r * (viewbox.bottom() - dtw->ruler_origin[Geom::Y]); + double upper_y = dtw->dt2r * (viewbox.top() - dtw->ruler_origin[Geom::Y]); + sp_ruler_set_range(SP_RULER(dtw->vruler), + lower_y, + upper_y, + (upper_y - lower_y)); } @@ -1772,8 +1722,8 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) this->dt2r = 1.0 / nv->doc_units->unittobase; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? - sp_ruler_set_metric(SP_RULER (this->vruler), nv->getDefaultMetric()); - sp_ruler_set_metric(SP_RULER (this->hruler), nv->getDefaultMetric()); + sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); + sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultMetric()); /* This loops through all the grandchildren of aux toolbox, * and for each that it finds, it performs an sp_search_by_data_recursive(), diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index dde511612..b17dcf470 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -113,7 +113,7 @@ GType sp_font_selector_get_type() static void sp_font_selector_class_init(SPFontSelectorClass *c) { - GObjectClass *object_class = (GObjectClass *) c; + GObjectClass *object_class = G_OBJECT_CLASS(c); fs_parent_class = (GtkHBoxClass* )g_type_class_peek_parent (c); @@ -285,7 +285,7 @@ static void sp_font_selector_family_select_row(GtkTreeSelection *selection, for ( ; list ; list = list->next ) { gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, (char*)list->data, -1); + gtk_list_store_set (store, &iter, 0, static_cast<char*>(list->data), -1); } gtk_tree_view_set_model (GTK_TREE_VIEW (fsel->style_treeview), GTK_TREE_MODEL (store)); @@ -433,7 +433,7 @@ GtkWidget *sp_font_selector_new() { SPFontSelector *fsel = SP_FONT_SELECTOR(g_object_new(SP_TYPE_FONT_SELECTOR, NULL)); - return (GtkWidget *) fsel; + return GTK_WIDGET(fsel); } /* @@ -453,7 +453,7 @@ unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) char *incomingFontString = pango_font_description_to_string(incomingFont); - tempFont = (font_factory::Default())->FaceFromUIStrings(family.c_str(), (char*)list->data); + tempFont = (font_factory::Default())->FaceFromUIStrings(family.c_str(), static_cast<char*>(list->data)); PangoFontDescription *bestMatchForFont = NULL; if (tempFont) { @@ -469,7 +469,7 @@ unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) while (list) { currentStyleNumber++; - tempFont = font_factory::Default()->FaceFromUIStrings(family.c_str(), (char*)list->data); + tempFont = font_factory::Default()->FaceFromUIStrings(family.c_str(), static_cast<char*>(list->data)); PangoFontDescription *currentMatchForFont = NULL; if (tempFont) { diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp index 359a41167..2d58355db 100644 --- a/src/widgets/gradient-image.cpp +++ b/src/widgets/gradient-image.cpp @@ -69,8 +69,8 @@ GType sp_gradient_image_get_type(void) static void sp_gradient_image_class_init(SPGradientImageClass *klass) { - GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; - parent_class = (GtkWidgetClass*)g_type_class_peek_parent (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + parent_class = GTK_WIDGET_CLASS(g_type_class_peek_parent (klass)); #if GTK_CHECK_VERSION(3,0,0) // GObjectClass *object_class = G_OBJECT_CLASS(klass); @@ -80,7 +80,7 @@ static void sp_gradient_image_class_init(SPGradientImageClass *klass) widget_class->draw = sp_gradient_image_draw; widget_class->destroy = sp_gradient_image_destroy; #else - GtkObjectClass *object_class = (GtkObjectClass *) klass; + GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); object_class->destroy = sp_gradient_image_destroy; widget_class->size_request = sp_gradient_image_size_request; @@ -120,8 +120,8 @@ static void sp_gradient_image_destroy(GtkObject *object) if (parent_class->destroy) (* (parent_class)->destroy) (object); #else - if (((GtkObjectClass *) (parent_class))->destroy) - (* ((GtkObjectClass *) (parent_class))->destroy) (object); + if ((GTK_OBJECT_CLASS(parent_class))->destroy) + (* (GTK_OBJECT_CLASS(parent_class))->destroy) (object); #endif } @@ -196,7 +196,7 @@ sp_gradient_image_new (SPGradient *gradient) sp_gradient_image_set_gradient (image, gradient); - return (GtkWidget *) image; + return GTK_WIDGET(image); } GdkPixbuf* diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index 89a891284..2c6774fe9 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -86,9 +86,9 @@ GType sp_gradient_selector_get_type(void) static void sp_gradient_selector_class_init(SPGradientSelectorClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); - parent_class = (GtkVBoxClass*)g_type_class_peek_parent (klass); + parent_class = GTK_VBOX_CLASS(g_type_class_peek_parent (klass)); signals[GRABBED] = g_signal_new ("grabbed", G_TYPE_FROM_CLASS(object_class), @@ -196,7 +196,7 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_box_pack_start( GTK_BOX(sel), hb, FALSE, FALSE, 0 ); sel->add = gtk_button_new (); - gtk_button_set_image((GtkButton*)sel->add , gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); + gtk_button_set_image(GTK_BUTTON(sel->add), gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); sel->nonsolid.push_back(sel->add); gtk_box_pack_start (GTK_BOX (hb), sel->add, FALSE, FALSE, 0); @@ -207,7 +207,7 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_widget_set_tooltip_text( sel->add, _("Create a duplicate gradient")); sel->edit = gtk_button_new (); - gtk_button_set_image((GtkButton*)sel->edit , gtk_image_new_from_stock ( GTK_STOCK_EDIT, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); + gtk_button_set_image(GTK_BUTTON(sel->edit), gtk_image_new_from_stock ( GTK_STOCK_EDIT, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); sel->nonsolid.push_back(sel->edit); gtk_box_pack_start (GTK_BOX (hb), sel->edit, FALSE, FALSE, 0); @@ -217,7 +217,7 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_widget_set_tooltip_text( sel->edit, _("Edit gradient")); sel->del = gtk_button_new (); - gtk_button_set_image((GtkButton*)sel->del , gtk_image_new_from_stock ( GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); + gtk_button_set_image(GTK_BUTTON(sel->del), gtk_image_new_from_stock ( GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR ) ); sel->swatch_widgets.push_back(sel->del); gtk_box_pack_start (GTK_BOX (hb), sel->del, FALSE, FALSE, 0); @@ -251,8 +251,8 @@ static void sp_gradient_selector_dispose(GObject *object) sel->text_renderer = NULL; } - if (((GObjectClass *) (parent_class))->dispose) { - (* ((GObjectClass *) (parent_class))->dispose) (object); + if ((G_OBJECT_CLASS(parent_class))->dispose) { + (* (G_OBJECT_CLASS(parent_class))->dispose) (object); } } @@ -267,7 +267,7 @@ GtkWidget *sp_gradient_selector_new() { SPGradientSelector *sel = SP_GRADIENT_SELECTOR(g_object_new (SP_TYPE_GRADIENT_SELECTOR, NULL)); - return (GtkWidget *) sel; + return GTK_WIDGET(sel); } void SPGradientSelector::setMode(SelectorMode mode) diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 51013a2cd..3a95b552a 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -609,7 +609,7 @@ static void update_stop_list( GtkWidget *vb, SPGradient *gradient, SPStop *new_s if (!combo_box) { return; } - GtkListStore *store = (GtkListStore *)gtk_combo_box_get_model (GTK_COMBO_BOX(combo_box)); + GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box))); if (!store) { return; } @@ -720,7 +720,7 @@ static SPStop *get_selected_stop( GtkWidget *vb) if (combo_box) { GtkTreeIter iter; if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX(combo_box), &iter)) { - GtkListStore *store = (GtkListStore *)gtk_combo_box_get_model (GTK_COMBO_BOX(combo_box)); + GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box))); gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, 2, &stop, -1); } } @@ -931,7 +931,7 @@ static GtkWidget * sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *s /* Adjustment */ GtkAdjustment *Offset_adj = NULL; - Offset_adj= (GtkAdjustment *) gtk_adjustment_new(0.0, 0.0, 1.0, 0.01, 0.01, 0.0); + Offset_adj= GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 1.0, 0.01, 0.01, 0.0)); g_object_set_data(G_OBJECT(vb), "offset", Offset_adj); SPStop *stop = get_selected_stop(vb); @@ -1197,10 +1197,10 @@ static void sp_gradient_vector_widget_destroy(GtkWidget *object, gpointer /*data static void sp_gradient_vector_widget_destroy(GtkObject *object, gpointer /*data*/) #endif { - SPObject *gradient = reinterpret_cast<SPObject*>(g_object_get_data(G_OBJECT(object), "gradient")); + SPObject *gradient = SP_OBJECT(g_object_get_data(G_OBJECT(object), "gradient")); - sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(object), "gradient_release_connection"); - sigc::connection *modified_connection = (sigc::connection *)g_object_get_data(G_OBJECT(object), "gradient_modified_connection"); + sigc::connection *release_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(object), "gradient_release_connection")); + sigc::connection *modified_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(object), "gradient_modified_connection")); if (gradient) { g_assert( release_connection != NULL ); @@ -1316,7 +1316,7 @@ static void sp_gradient_vector_color_changed(SPColorSelector *csel, GObject *obj if (combo_box) { GtkTreeIter iter; if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX(combo_box), &iter)) { - GtkListStore *store = (GtkListStore *)gtk_combo_box_get_model (GTK_COMBO_BOX(combo_box)); + GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box))); Inkscape::UI::Widget::ColorPreview *cp = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(sp_stop_get_rgba32(stop))); GdkPixbuf *pb = cp->toPixbuf(64, 16); diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index d3b7e2dbb..ff443504d 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -164,13 +164,10 @@ GType SPIcon::getType() void IconImpl::classInit(SPIconClass *klass) { - GObjectClass *object_class; - GtkWidgetClass *widget_class; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - object_class = (GObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - parent_class = (GtkWidgetClass*)g_type_class_peek_parent(klass); + parent_class = GTK_WIDGET_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = IconImpl::dispose; @@ -205,7 +202,7 @@ void IconImpl::dispose(GObject *object) icon->name = 0; } - ((GObjectClass *) (parent_class))->dispose(object); + (G_OBJECT_CLASS(parent_class))->dispose(object); } void IconImpl::reset( SPIcon *icon ) @@ -865,7 +862,7 @@ GtkWidget *IconImpl::newFull( Inkscape::IconSize lsize, gchar const *name ) if ( dump ) { g_message( "skipped gtk '%s' %d (not GTK_IMAGE_STOCK)", name, lsize ); } - //g_object_unref( (GObject *)img ); + //g_object_unref(G_OBJECT(img)); img = 0; } } @@ -1022,7 +1019,7 @@ int IconImpl::getPhysSize(int size) "inkscape-decoration" }; - GtkWidget *icon = (GtkWidget *)g_object_new(SP_TYPE_ICON, NULL); + GtkWidget *icon = GTK_WIDGET(g_object_new(SP_TYPE_ICON, NULL)); for (unsigned i = 0; i < G_N_ELEMENTS(gtkSizes); ++i) { guint const val_ix = (gtkSizes[i] <= GTK_ICON_SIZE_DIALOG) ? (guint)gtkSizes[i] : (guint)Inkscape::ICON_SIZE_DECORATION; @@ -1075,7 +1072,7 @@ int IconImpl::getPhysSize(int size) GdkPixbuf *IconImpl::loadPixmap(gchar const *name, unsigned /*lsize*/, unsigned psize) { - gchar *path = (gchar *) g_strdup_printf("%s/%s.png", INKSCAPE_PIXMAPDIR, name); + gchar *path = g_strdup_printf("%s/%s.png", INKSCAPE_PIXMAPDIR, name); // TODO: bulia, please look over gsize bytesRead = 0; gsize bytesWritten = 0; @@ -1089,7 +1086,7 @@ GdkPixbuf *IconImpl::loadPixmap(gchar const *name, unsigned /*lsize*/, unsigned g_free(localFilename); g_free(path); if (!pb) { - path = (gchar *) g_strdup_printf("%s/%s.xpm", INKSCAPE_PIXMAPDIR, name); + path = g_strdup_printf("%s/%s.xpm", INKSCAPE_PIXMAPDIR, name); // TODO: bulia, please look over gsize bytesRead = 0; gsize bytesWritten = 0; diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 5a6e774f5..b0738b6a6 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -157,9 +157,9 @@ GType sp_paint_selector_get_type(void) static void sp_paint_selector_class_init(SPPaintSelectorClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = G_OBJECT_CLASS(klass); - parent_class = (GtkVBoxClass*)g_type_class_peek_parent(klass); + parent_class = GTK_VBOX_CLASS(g_type_class_peek_parent(klass)); psel_signals[MODE_CHANGED] = g_signal_new("mode_changed", G_TYPE_FROM_CLASS(object_class), @@ -311,8 +311,8 @@ static void sp_paint_selector_dispose(GObject *object) // clean up our long-living pattern menu g_object_set_data(G_OBJECT(psel),"patternmenu",NULL); - if (((GObjectClass *) parent_class)->dispose) - (* ((GObjectClass *) parent_class)->dispose)(object); + if ((G_OBJECT_CLASS(parent_class))->dispose) + (* (G_OBJECT_CLASS(parent_class))->dispose)(object); } static GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, @@ -655,7 +655,7 @@ static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelec if ((psel->mode == SPPaintSelector::MODE_COLOR_RGB) || (psel->mode == SPPaintSelector::MODE_COLOR_CMYK)) { /* Already have color selector */ - csel = (GtkWidget*)g_object_get_data(G_OBJECT(psel->selector), "color-selector"); + csel = GTK_WIDGET(g_object_get_data(G_OBJECT(psel->selector), "color-selector")); } else { sp_paint_selector_clear_frame(psel); @@ -732,7 +732,7 @@ static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSe if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) { /* Already have gradient selector */ - gsel = (GtkWidget*)g_object_get_data(G_OBJECT(psel->selector), "gradient-selector"); + gsel = GTK_WIDGET(g_object_get_data(G_OBJECT(psel->selector), "gradient-selector")); } else { sp_paint_selector_clear_frame(psel); /* Create new gradient selector */ @@ -799,7 +799,7 @@ ink_pattern_list_get (SPDocument *source) GSList *pl = NULL; GSList const *patterns = source->getResourceList("pattern"); - for (GSList *l = (GSList *) patterns; l != NULL; l = l->next) { + for (GSList *l = const_cast<GSList *>(patterns); l != NULL; l = l->next) { if (SP_PATTERN(l->data) == pattern_getroot(SP_PATTERN(l->data))) { // only if this is a root pattern pl = g_slist_prepend(pl, l->data); } @@ -995,7 +995,7 @@ static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSel if (psel->mode == SPPaintSelector::MODE_PATTERN) { /* Already have pattern menu */ - tbl = (GtkWidget*)g_object_get_data(G_OBJECT(psel->selector), "pattern-selector"); + tbl = GTK_WIDGET(g_object_get_data(G_OBJECT(psel->selector), "pattern-selector")); } else { sp_paint_selector_clear_frame(psel); @@ -1081,7 +1081,7 @@ SPPattern *SPPaintSelector::getPattern() SPPattern *pat = 0; g_return_val_if_fail((mode == MODE_PATTERN) , NULL); - GtkWidget *combo = (GtkWidget *) g_object_get_data(G_OBJECT(this), "patternmenu"); + GtkWidget *combo = GTK_WIDGET(g_object_get_data(G_OBJECT(this), "patternmenu")); /* no pattern menu if we were just selected */ if ( combo == NULL ) { diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index d0e71d2b0..87942f141 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -242,7 +242,7 @@ static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GObject *obj) // fixme: make settable gdouble tolerance = 4; - adj = (GtkAdjustment*)g_object_get_data(obj, "tolerance"); + adj = GTK_ADJUSTMENT(g_object_get_data(obj, "tolerance")); gtk_adjustment_set_value(adj, tolerance); gtk_adjustment_value_changed(adj); @@ -282,7 +282,7 @@ public: } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - GtkAdjustment * adj = (GtkAdjustment*)g_object_get_data(tbl, "tolerance"); + GtkAdjustment * adj = GTK_ADJUSTMENT(g_object_get_data(tbl, "tolerance")); double v = val.getDouble(adj->value); gtk_adjustment_set_value(adj, v); diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index 5104d5a9d..c1f9be2a5 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -1,5 +1,18 @@ /* - * Customized ruler class for inkscape + * Customized ruler class for inkscape. Note that this is a fork of + * the GimpRuler widget from GIMP: libgimpwidgets/gimpruler.c. + * The GIMP code is released under the GPL 3. The GIMP code itself + * is a fork of the now-obsolete GtkRuler widget from GTK+ 2. + * + * Major differences between implementations in Inkscape and GIMP are + * as follows: + * - We use a 1,2,4,8... scale for inches and 1,2,5,10... for everything + * else. GIMP uses 1,2,5,10... for everything. + * + * - We use a default font size of PANGO_SCALE_X_SMALL for labels, + * GIMP uses PANGO_SCALE_SMALL (i.e., a bit larger than ours). + * + * - We abbreviate large numbers in tick-labels (e.g., 10000 -> 10k) * * Authors: * Lauris Kaplinski <lauris@kaplinski.com> @@ -7,6 +20,7 @@ * bulia byak <buliabyak@users.sf.net> * Diederik van Lierop <mail@diedenrezi.nl> * Jon A. Cruz <jon@joncruz.org> + * Alex Valavanis <valavanisalex@gmail.com> * * Copyright (C) 1999-2011 authors * @@ -18,143 +32,178 @@ #include <cstdio> #include "widget-sizes.h" -#include "desktop-widget.h" #include "ruler.h" #include "unit-constants.h" #include "round.h" #include <glibmm/i18n.h> -#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB - -#define MINIMUM_INCR 5 -#define MAXIMUM_SUBDIVIDE 5 -#define MAXIMUM_SCALES 10 - #define ROUND(x) ((int) ((x) + 0.5)) -struct _SPRulerPrivate -{ - GtkOrientation orientation; - SPRulerMetric *metric; +#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB + +#define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL +#define MINIMUM_INCR 5 -#if GTK_CHECK_VERSION(3,0,0) - cairo_surface_t *backing_store; -#else - GdkPixmap *backing_store; -#endif - - gint slider_size; - gint xsrc; - gint ysrc; - - gdouble lower; /* The upper limit of the ruler (in points) */ - gdouble upper; /* The lower limit of the ruler */ - gdouble position; /* The position of the mark on the ruler */ - gdouble max_size; /* The maximum size of the ruler */ -}; enum { PROP_0, PROP_ORIENTATION, + PROP_UNIT, PROP_LOWER, PROP_UPPER, PROP_POSITION, - PROP_MAX_SIZE, - PROP_METRIC + PROP_MAX_SIZE }; -static void sp_ruler_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void sp_ruler_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void sp_ruler_realize (GtkWidget *widget); -static void sp_ruler_unrealize (GtkWidget *widget); -static void sp_ruler_size_request (GtkWidget *widget, - GtkRequisition *requisition); -#if GTK_CHECK_VERSION(3,0,0) -static void sp_ruler_get_preferred_width (GtkWidget *widget, - gint *minimal_width, - gint *natural_width); +/* All distances below are in 1/72nd's of an inch. (According to + * Adobe, that's a point, but points are really 1/72.27 in.) + */ +typedef struct +{ + GtkOrientation orientation; + SPMetric unit; + gdouble lower; + gdouble upper; + gdouble position; + gdouble max_size; + + GdkWindow *input_window; + cairo_surface_t *backing_store; + PangoLayout *layout; + gdouble font_scale; + + gint xsrc; + gint ysrc; -static void sp_ruler_get_preferred_height (GtkWidget *widget, - gint *minimal_height, - gint *natural_height); -#endif + GList *track_widgets; +} SPRulerPrivate; + +#define SP_RULER_GET_PRIVATE(ruler) \ + G_TYPE_INSTANCE_GET_PRIVATE (ruler, SP_TYPE_RULER, SPRulerPrivate) + + +struct SPRulerMetric +{ + gdouble ruler_scale[16]; + gint subdivide[5]; +}; + +// Ruler metric for general use. +static SPRulerMetric const ruler_metric_general = { + { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 }, + { 1, 5, 10, 50, 100 } +}; + +// Ruler metric for inch scales. +static SPRulerMetric const ruler_metric_inches = { + { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }, + { 1, 2, 4, 8, 16 } +}; + +static void sp_ruler_dispose (GObject *object); +static void sp_ruler_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void sp_ruler_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void sp_ruler_realize (GtkWidget *widget); +static void sp_ruler_unrealize (GtkWidget *widget); +static void sp_ruler_map (GtkWidget *widget); +static void sp_ruler_unmap (GtkWidget *widget); +static void sp_ruler_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); -static void sp_ruler_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gboolean sp_ruler_motion_notify (GtkWidget *widget, - GdkEventMotion *event); #if GTK_CHECK_VERSION(3,0,0) -static gboolean sp_ruler_draw (GtkWidget *widget, - cairo_t *cr); +static void sp_ruler_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); + +static void sp_ruler_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height); +static void sp_ruler_style_updated (GtkWidget *widget); #else -static gboolean sp_ruler_expose (GtkWidget *widget, - GdkEventExpose *event); +static void sp_ruler_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void sp_ruler_style_set (GtkWidget *widget, + GtkStyle *prev_style); #endif -static void sp_ruler_make_pixmap (SPRuler *ruler); -static void sp_ruler_draw_ticks (SPRuler *ruler); -static void sp_ruler_real_draw_ticks (SPRuler *ruler, - cairo_t *cr); -static void sp_ruler_real_draw_pos (SPRuler *ruler, - cairo_t *cr); - -#define SP_RULER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SP_TYPE_RULER, SPRulerPrivate)) - -// Note: const casts are due to SPRuler being const-broken and not scheduled for any more fixes. -/// Ruler metrics. -static SPRulerMetric const sp_ruler_metrics[] = { - // NOTE: the order of records in this struct must correspond to the SPMetric enum. - {const_cast<gchar*>("NONE"), const_cast<gchar*>(""), 1, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("millimeters"), const_cast<gchar*>("mm"), PX_PER_MM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("centimeters"), const_cast<gchar*>("cm"), PX_PER_CM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("inches"), const_cast<gchar*>("in"), PX_PER_IN, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }}, - {const_cast<gchar*>("feet"), const_cast<gchar*>("ft"), PX_PER_FT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("points"), const_cast<gchar*>("pt"), PX_PER_PT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("picas"), const_cast<gchar*>("pc"), PX_PER_PC, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("pixels"), const_cast<gchar*>("px"), PX_PER_PX, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, - {const_cast<gchar*>("meters"), const_cast<gchar*>("m"), PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, -}; -G_DEFINE_TYPE_WITH_CODE (SPRuler, sp_ruler, GTK_TYPE_WIDGET, - G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, - NULL)) +static gboolean sp_ruler_motion_notify (GtkWidget *widget, + GdkEventMotion *event); +static gboolean sp_ruler_draw (GtkWidget *widget, + cairo_t *cr); +#if !GTK_CHECK_VERSION(3,0,0) +static gboolean sp_ruler_expose (GtkWidget *widget, + GdkEventExpose *event); +#endif +static void sp_ruler_draw_ticks (SPRuler *ruler); +static void sp_ruler_draw_pos (SPRuler *ruler); +static void sp_ruler_make_pixmap (SPRuler *ruler); + +static PangoLayout * sp_ruler_get_layout (GtkWidget *widget, + const gchar *text); + + +G_DEFINE_TYPE (SPRuler, sp_ruler, GTK_TYPE_WIDGET) + +#define parent_class sp_ruler_parent_class + static void sp_ruler_class_init (SPRulerClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gobject_class->set_property = sp_ruler_set_property; - gobject_class->get_property = sp_ruler_get_property; + object_class->dispose = sp_ruler_dispose; + object_class->set_property = sp_ruler_set_property; + object_class->get_property = sp_ruler_get_property; - widget_class->realize = sp_ruler_realize; - widget_class->unrealize = sp_ruler_unrealize; + widget_class->realize = sp_ruler_realize; + widget_class->unrealize = sp_ruler_unrealize; + widget_class->map = sp_ruler_map; + widget_class->unmap = sp_ruler_unmap; + widget_class->size_allocate = sp_ruler_size_allocate; #if GTK_CHECK_VERSION(3,0,0) - widget_class->get_preferred_width = sp_ruler_get_preferred_width; + widget_class->get_preferred_width = sp_ruler_get_preferred_width; widget_class->get_preferred_height = sp_ruler_get_preferred_height; - widget_class->draw = sp_ruler_draw; + widget_class->style_updated = sp_ruler_style_updated; + widget_class->draw = sp_ruler_draw; #else - widget_class->size_request = sp_ruler_size_request; - widget_class->expose_event = sp_ruler_expose; + widget_class->size_request = sp_ruler_size_request; + widget_class->style_set = sp_ruler_style_set; + widget_class->expose_event = sp_ruler_expose; #endif - widget_class->size_allocate = sp_ruler_size_allocate; widget_class->motion_notify_event = sp_ruler_motion_notify; - klass->draw_ticks = sp_ruler_real_draw_ticks; - klass->draw_pos = sp_ruler_real_draw_pos; - - g_object_class_override_property (gobject_class, - PROP_ORIENTATION, - "orientation"); - - g_object_class_install_property (gobject_class, + g_type_class_add_private (object_class, sizeof (SPRulerPrivate)); + + g_object_class_install_property (object_class, + PROP_ORIENTATION, + g_param_spec_enum ("orientation", + _("Orientation"), + _("The orientation of the ruler"), + GTK_TYPE_ORIENTATION, + GTK_ORIENTATION_HORIZONTAL, + static_cast<GParamFlags>(GTK_PARAM_READWRITE))); + + /* FIXME: Should probably use g_param_spec_enum */ + g_object_class_install_property (object_class, + PROP_UNIT, + g_param_spec_uint ("unit", + _("Unit"), + _("Unit of the ruler"), + 0, 8, + SP_PX, + static_cast<GParamFlags>(GTK_PARAM_READWRITE))); + + g_object_class_install_property (object_class, PROP_LOWER, g_param_spec_double ("lower", _("Lower"), @@ -164,7 +213,7 @@ sp_ruler_class_init (SPRulerClass *klass) 0.0, static_cast<GParamFlags>(GTK_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, + g_object_class_install_property (object_class, PROP_UPPER, g_param_spec_double ("upper", _("Upper"), @@ -174,7 +223,7 @@ sp_ruler_class_init (SPRulerClass *klass) 0.0, static_cast<GParamFlags>(GTK_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, + g_object_class_install_property (object_class, PROP_POSITION, g_param_spec_double ("position", _("Position"), @@ -184,7 +233,7 @@ sp_ruler_class_init (SPRulerClass *klass) 0.0, static_cast<GParamFlags>(GTK_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, + g_object_class_install_property (object_class, PROP_MAX_SIZE, g_param_spec_double ("max-size", _("Max Size"), @@ -193,75 +242,65 @@ sp_ruler_class_init (SPRulerClass *klass) G_MAXDOUBLE, 0.0, static_cast<GParamFlags>(GTK_PARAM_READWRITE))); - /** - * SPRuler:metric: - * - * The metric used for the ruler. - * - * TODO: This should probably use g_param_spec_enum - */ - g_object_class_install_property (gobject_class, - PROP_METRIC, - g_param_spec_uint("metric", - _("Metric"), - _("The metric used for the ruler"), - 0, 8, - SP_PX, - static_cast<GParamFlags>(GTK_PARAM_READWRITE))); - g_type_class_add_private (gobject_class, sizeof (SPRulerPrivate)); + gtk_widget_class_install_style_property (widget_class, + g_param_spec_double ("font-scale", + NULL, NULL, + 0.0, + G_MAXDOUBLE, + DEFAULT_RULER_FONT_SCALE, + G_PARAM_READABLE)); } static void sp_ruler_init (SPRuler *ruler) { - ruler->priv = G_TYPE_INSTANCE_GET_PRIVATE(ruler, - SP_TYPE_RULER, - SPRulerPrivate); - - SPRulerPrivate *priv = ruler->priv; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - priv->orientation = GTK_ORIENTATION_HORIZONTAL; + gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); + priv->orientation = GTK_ORIENTATION_HORIZONTAL; + priv->unit = SP_PX; + priv->lower = 0; + priv->upper = 0; + priv->position = 0; + priv->max_size = 0; priv->backing_store = NULL; - priv->xsrc = 0; - priv->ysrc = 0; - priv->slider_size = 0; - priv->lower = 0; - priv->upper = 0; - priv->position = 0; - priv->max_size = 0; + priv->font_scale = DEFAULT_RULER_FONT_SCALE; - sp_ruler_set_metric(ruler, SP_PX); +#if GTK_CHECK_VERSION(3,0,0) + const gchar *str = + "SPRuler {\n" + " background-color: @bg_color;\n" + "}\n"; + + GtkCssProvider *css = gtk_css_provider_new (); + gtk_css_provider_load_from_data (css, str, -1, NULL); + gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (ruler)), + GTK_STYLE_PROVIDER (css), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (css); +#endif } - -/** - * sp_ruler_invalidate_ticks: - * @ruler: the ruler to invalidate - * - * For performance reasons, #SPRuler keeps a backbuffer containing the - * prerendered contents of the ticks. To cause a repaint of this buffer, - * call this function instead of gtk_widget_queue_draw(). - **/ -static void sp_ruler_invalidate_ticks(SPRuler *ruler) +static void +sp_ruler_dispose (GObject *object) { - g_return_if_fail(SP_IS_RULER(ruler)); + SPRuler *ruler = SP_RULER (object); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - if(ruler->priv->backing_store == NULL) - return; + while (priv->track_widgets) + sp_ruler_remove_track_widget (ruler, GTK_WIDGET(priv->track_widgets->data)); - sp_ruler_draw_ticks(ruler); - gtk_widget_queue_draw(GTK_WIDGET(ruler)); + G_OBJECT_CLASS (parent_class)->dispose (object); } /** * sp_ruler_set_range: - * @ruler: the gtkdeprecatedruler + * @ruler: the SPRuler * @lower: the lower limit of the ruler * @upper: the upper limit of the ruler - * @position: the mark on the ruler * @max_size: the maximum size of the ruler used when calculating the space to * leave for the text * @@ -269,14 +308,15 @@ static void sp_ruler_invalidate_ticks(SPRuler *ruler) */ void sp_ruler_set_range (SPRuler *ruler, - gdouble lower, - gdouble upper, - gdouble position, - gdouble max_size) + gdouble lower, + gdouble upper, + gdouble max_size) { + SPRulerPrivate *priv; + g_return_if_fail (SP_IS_RULER (ruler)); - SPRulerPrivate *priv = ruler->priv; + priv = SP_RULER_GET_PRIVATE (ruler); g_object_freeze_notify (G_OBJECT (ruler)); if (priv->lower != lower) @@ -289,11 +329,6 @@ sp_ruler_set_range (SPRuler *ruler, priv->upper = upper; g_object_notify (G_OBJECT (ruler), "upper"); } - if (priv->position != position) - { - priv->position = position; - g_object_notify (G_OBJECT (ruler), "position"); - } if (priv->max_size != max_size) { priv->max_size = max_size; @@ -301,7 +336,7 @@ sp_ruler_set_range (SPRuler *ruler, } g_object_thaw_notify (G_OBJECT (ruler)); - sp_ruler_invalidate_ticks(ruler); + gtk_widget_queue_draw (GTK_WIDGET (ruler)); } /** @@ -309,7 +344,6 @@ sp_ruler_set_range (SPRuler *ruler, * @ruler: a #SPRuler * @lower: (allow-none): location to store lower limit of the ruler, or %NULL * @upper: (allow-none): location to store upper limit of the ruler, or %NULL - * @position: (allow-none): location to store the current position of the mark on the ruler, or %NULL * @max_size: location to store the maximum size of the ruler used when calculating * the space to leave for the text, or %NULL. * @@ -320,19 +354,18 @@ void sp_ruler_get_range (SPRuler *ruler, gdouble *lower, gdouble *upper, - gdouble *position, gdouble *max_size) { + SPRulerPrivate *priv; + g_return_if_fail (SP_IS_RULER (ruler)); - SPRulerPrivate *priv = ruler->priv; + priv = SP_RULER_GET_PRIVATE (ruler); if (lower) *lower = priv->lower; if (upper) *upper = priv->upper; - if (position) - *position = priv->position; if (max_size) *max_size = priv->max_size; } @@ -344,7 +377,7 @@ sp_ruler_set_property (GObject *object, GParamSpec *pspec) { SPRuler *ruler = SP_RULER (object); - SPRulerPrivate *priv = ruler->priv; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); switch (prop_id) { @@ -352,25 +385,35 @@ sp_ruler_set_property (GObject *object, priv->orientation = static_cast<GtkOrientation>(g_value_get_enum (value)); gtk_widget_queue_resize (GTK_WIDGET (ruler)); break; + + case PROP_UNIT: + sp_ruler_set_unit (ruler, static_cast<SPMetric>(g_value_get_int (value))); + break; + case PROP_LOWER: - sp_ruler_set_range (ruler, g_value_get_double (value), priv->upper, - priv->position, priv->max_size); + sp_ruler_set_range (ruler, + g_value_get_double (value), + priv->upper, + priv->max_size); break; case PROP_UPPER: - sp_ruler_set_range (ruler, priv->lower, g_value_get_double (value), - priv->position, priv->max_size); + sp_ruler_set_range (ruler, + priv->lower, + g_value_get_double (value), + priv->max_size); break; + case PROP_POSITION: - sp_ruler_set_range (ruler, priv->lower, priv->upper, - g_value_get_double (value), priv->max_size); + sp_ruler_set_position (ruler, g_value_get_double (value)); break; + case PROP_MAX_SIZE: - sp_ruler_set_range (ruler, priv->lower, priv->upper, - priv->position, g_value_get_double (value)); - break; - case PROP_METRIC: - sp_ruler_set_metric(ruler, static_cast<SPMetric>(g_value_get_enum (value))); + sp_ruler_set_range (ruler, + priv->lower, + priv->upper, + g_value_get_double (value)); break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -384,13 +427,17 @@ sp_ruler_get_property (GObject *object, GParamSpec *pspec) { SPRuler *ruler = SP_RULER (object); - SPRulerPrivate *priv = ruler->priv; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); switch (prop_id) { case PROP_ORIENTATION: g_value_set_enum (value, priv->orientation); break; + + case PROP_UNIT: + g_value_set_int (value, priv->unit); + break; case PROP_LOWER: g_value_set_double (value, priv->lower); break; @@ -403,262 +450,326 @@ sp_ruler_get_property (GObject *object, case PROP_MAX_SIZE: g_value_set_double (value, priv->max_size); break; - case PROP_METRIC: - g_value_set_enum(value, sp_ruler_get_metric(ruler)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } - -/** - * sp_ruler_get_metric: - * @ruler: a #SPRuler - * - * Gets the units used for a #SPRuler. See sp_ruler_set_metric(). - * - * Return value: the units currently used for @ruler - **/ -SPMetric sp_ruler_get_metric(SPRuler *ruler) +static void +sp_ruler_realize (GtkWidget *widget) { - g_return_val_if_fail(SP_IS_RULER(ruler), static_cast<SPMetric>(0)); - SPRulerPrivate *priv = ruler->priv; - - for (size_t i = 0; i < G_N_ELEMENTS(sp_ruler_metrics); i++) { - if (priv->metric == &sp_ruler_metrics[i]) { - return static_cast<SPMetric>(i); - } - } - - g_assert_not_reached (); - - return static_cast<SPMetric>(0); -} - + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + GdkWindowAttr attributes; + gint attributes_mask; -static void sp_ruler_draw_ticks(SPRuler *ruler) -{ - g_return_if_fail(SP_IS_RULER(ruler)); - SPRulerPrivate *priv = ruler->priv; + GTK_WIDGET_CLASS (sp_ruler_parent_class)->realize (widget); + + gtk_widget_get_allocation (widget, &allocation); + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; + attributes.wclass = GDK_INPUT_ONLY; #if GTK_CHECK_VERSION(3,0,0) - cairo_t *cr = cairo_create(priv->backing_store); + attributes.event_mask = (gtk_widget_get_events (widget) | + GDK_EXPOSURE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_POINTER_MOTION_HINT_MASK); #else - cairo_t *cr = gdk_cairo_create(priv->backing_store); + attributes.event_mask = (gtk_widget_get_events (widget) | + GDK_EXPOSURE_MASK | + GDK_POINTER_MOTION_MASK); #endif - if (SP_RULER_GET_CLASS(ruler)->draw_ticks) - SP_RULER_GET_CLASS(ruler)->draw_ticks(ruler, cr); + attributes_mask = GDK_WA_X | GDK_WA_Y; - cairo_destroy(cr); -} + priv->input_window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, attributes_mask); + gdk_window_set_user_data (priv->input_window, ruler); + sp_ruler_make_pixmap (ruler); +} -static void sp_ruler_realize(GtkWidget *widget) +static void +sp_ruler_unrealize(GtkWidget *widget) { - GtkAllocation allocation; - SPRuler *ruler; - GdkWindow *window; - GdkWindowAttr attributes; - gint attributes_mask; + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - ruler = SP_RULER (widget); + if (priv->backing_store) + { + cairo_surface_destroy (priv->backing_store); + priv->backing_store = NULL; + } + + if (priv->layout) + { + g_object_unref (priv->layout); + priv->layout = NULL; + } - gtk_widget_set_realized (widget, TRUE); + if (priv->input_window) + { + gdk_window_destroy (priv->input_window); + priv->input_window = NULL; + } - gtk_widget_get_allocation(widget, &allocation); + GTK_WIDGET_CLASS (sp_ruler_parent_class)->unrealize (widget); +} - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = allocation.x; - attributes.y = allocation.y; - attributes.width = allocation.width; - attributes.height = allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; - - window = gdk_window_new(gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gtk_widget_set_window(widget, window); - gdk_window_set_user_data(window, ruler); +static void +sp_ruler_map (GtkWidget *widget) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); -#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 + GTK_WIDGET_CLASS (sp_ruler_parent_class)->map (widget); - sp_ruler_make_pixmap (ruler); + if (priv->input_window) + gdk_window_show (priv->input_window); } -static void sp_ruler_unrealize(GtkWidget *widget) +static void +sp_ruler_unmap (GtkWidget *widget) { - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = ruler->priv; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - if (priv->backing_store) + if (priv->input_window) + gdk_window_hide (priv->input_window); + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->unmap (widget); +} + +static void +sp_ruler_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + SPRuler *ruler = SP_RULER(widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation widget_allocation; + gboolean resized; + + gtk_widget_get_allocation (widget, &widget_allocation); + + resized = (widget_allocation.width != allocation->width || + widget_allocation.height != allocation->height); + + gtk_widget_set_allocation(widget, allocation); + + if (gtk_widget_get_realized (widget)) { -#if GTK_CHECK_VERSION(3,0,0) - cairo_surface_destroy(priv->backing_store); -#else - g_object_unref(priv->backing_store); -#endif - priv->backing_store = NULL; + gdk_window_move_resize (priv->input_window, + allocation->x, allocation->y, + allocation->width, allocation->height); + + if (resized) + sp_ruler_make_pixmap (ruler); } - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->unrealize (widget); } -static void sp_ruler_size_request(GtkWidget *widget, - GtkRequisition *requisition) +static void +sp_ruler_size_request (GtkWidget *widget, + GtkRequisition *requisition) { - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - GtkStyle *style = gtk_widget_get_style(widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + PangoLayout *layout; + PangoRectangle ink_rect; + gint size; + + layout = sp_ruler_get_layout (widget, "0123456789"); + pango_layout_get_pixel_extents (layout, &ink_rect, NULL); + + size = 2 + ink_rect.height * 1.7; + +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder border; + + gtk_style_context_get_border (context, static_cast<GtkStateFlags>(0), &border); + + requisition->width = border.left + border.right; + requisition->height = border.top + border.bottom; +#else + GtkStyle *style = gtk_widget_get_style(widget); +#endif if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { +#if GTK_CHECK_VERSION(3,0,0) + requisition->width += 1; + requisition->height += size; +#else requisition->width = style->xthickness * 2 + 1; - requisition->height = style->ythickness * 2 + RULER_WIDTH; + requisition->height = style->ythickness * 2 + size; +#endif } else { - requisition->width = style->xthickness * 2 + RULER_WIDTH; +#if GTK_CHECK_VERSION(3,0,0) + requisition->width += size; + requisition->height += 1; +#else + requisition->width = style->xthickness * 2 + size; requisition->height = style->ythickness * 2 + 1; +#endif } } +static void #if GTK_CHECK_VERSION(3,0,0) -static void sp_ruler_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) +sp_ruler_style_updated (GtkWidget *widget) +#else +sp_ruler_style_set (GtkWidget *widget, + GtkStyle *prev_style) +#endif { - GtkRequisition requisition; - sp_ruler_size_request(widget, &requisition); - *minimal_width = *natural_width = requisition.width; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + +#if GTK_CHECK_VERSION(3,0,0) + GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_updated (widget); +#else + GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_set (widget, prev_style); +#endif + + gtk_widget_style_get (widget, + "font-scale", &priv->font_scale, + NULL); + + if (priv->layout) + { + g_object_unref (priv->layout); + priv->layout = NULL; + } } -static void sp_ruler_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height) +#if GTK_CHECK_VERSION(3,0,0) +static void +sp_ruler_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) { - GtkRequisition requisition; - sp_ruler_size_request(widget, &requisition); - *minimal_height = *natural_height = requisition.height; + GtkRequisition requisition; + + sp_ruler_size_request (widget, &requisition); + + *minimum_width = *natural_width = requisition.width; } -#endif -static void sp_ruler_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +static void +sp_ruler_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) { - SPRuler *ruler = SP_RULER(widget); - GtkAllocation old_allocation; - gtk_widget_get_allocation(widget, &old_allocation); + GtkRequisition requisition; + + sp_ruler_size_request(widget, &requisition); + + *minimum_height = *natural_height = requisition.height; +} +#else +static gboolean +sp_ruler_expose (GtkWidget *widget, + GdkEventExpose *event) +{ + cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget)); + GtkAllocation allocation; + + gdk_cairo_region (cr, event->region); + cairo_clip (cr); - gboolean resized = (old_allocation.width != allocation->width || - old_allocation.height != allocation->height); + gtk_widget_get_allocation (widget, &allocation); + cairo_translate (cr, allocation.x, allocation.y); - gtk_widget_set_allocation(widget, allocation); + gboolean result = sp_ruler_draw (widget, cr); - if (gtk_widget_get_realized (widget)) - { - gdk_window_move_resize(gtk_widget_get_window(widget), - allocation->x, allocation->y, - allocation->width, allocation->height); + cairo_destroy (cr); - if(resized) - sp_ruler_make_pixmap (ruler); - } + return result; } - -#if GTK_CHECK_VERSION(3,0,0) -static gboolean sp_ruler_draw(GtkWidget *widget, - cairo_t *cr) -#else -static gboolean sp_ruler_expose(GtkWidget *widget, - GdkEventExpose *event) #endif + +static gboolean +sp_ruler_draw (GtkWidget *widget, + cairo_t *cr) { - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = ruler->priv; + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + sp_ruler_draw_ticks (ruler); -#if GTK_CHECK_VERSION(3,0,0) cairo_set_source_surface(cr, priv->backing_store, 0, 0); cairo_paint(cr); -#else - cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget)); - gdk_cairo_set_source_pixmap(cr, priv->backing_store, 0, 0); - gdk_cairo_region(cr, event->region); - cairo_fill(cr); -#endif - - if (SP_RULER_GET_CLASS(ruler)->draw_pos) - SP_RULER_GET_CLASS(ruler)->draw_pos(ruler, cr); -#if !GTK_CHECK_VERSION(3,0,0) - cairo_destroy (cr); -#endif + sp_ruler_draw_pos (ruler); return FALSE; } -static void sp_ruler_make_pixmap(SPRuler *ruler) +static void +sp_ruler_make_pixmap (SPRuler *ruler) { - SPRulerPrivate *priv = ruler->priv; - GtkWidget *widget = GTK_WIDGET(ruler); + GtkWidget *widget = GTK_WIDGET (ruler); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; - GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); if (priv->backing_store) -#if GTK_CHECK_VERSION(3,0,0) - cairo_surface_destroy(priv->backing_store); - - priv->backing_store = gdk_window_create_similar_surface(gtk_widget_get_window(widget), - CAIRO_CONTENT_COLOR, - allocation.width, - allocation.height); -#else - g_object_unref(priv->backing_store); - - priv->backing_store = gdk_pixmap_new(gtk_widget_get_window(widget), - allocation.width, - allocation.height, - -1); -#endif - - priv->xsrc = 0; - priv->ysrc = 0; + cairo_surface_destroy (priv->backing_store); - sp_ruler_draw_ticks(ruler); + priv->backing_store = + gdk_window_create_similar_surface (gtk_widget_get_window (widget), + CAIRO_CONTENT_COLOR, + allocation.width, + allocation.height); } - -static void sp_ruler_real_draw_pos(SPRuler *ruler, - cairo_t *cr) +static void +sp_ruler_draw_pos (SPRuler *ruler) { - GtkAllocation allocation; - GtkWidget *widget = GTK_WIDGET (ruler); - SPRulerPrivate *priv = ruler->priv; - gint x, y; - gint bs_width, bs_height; - gdouble increment; + GtkWidget *widget = GTK_WIDGET (ruler); + +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder border; + GdkRGBA color; +#else + GtkStyle *style = gtk_widget_get_style (widget); + GtkStateType state = gtk_widget_get_state (widget); + gint xthickness; + gint ythickness; +#endif + + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + gint x, y; + gint width, height; + gint bs_width, bs_height; + + if (! gtk_widget_is_drawable (widget)) + return; - GtkStyle *style = gtk_widget_get_style(widget); gtk_widget_get_allocation(widget, &allocation); - gint xthickness = style->xthickness; - gint ythickness = style->ythickness; - gint width = allocation.width; - gint height = allocation.height; +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_border (context, static_cast<GtkStateFlags>(0), &border); +#else + xthickness = style->xthickness; + ythickness = style->ythickness; +#endif if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { - height -= ythickness * 2; + width = allocation.width; +#if GTK_CHECK_VERSION(3,0,0) + height = allocation.height - (border.top + border.bottom); +#else + height = allocation.height - ythickness * 2; +#endif bs_width = height / 2 + 2; bs_width |= 1; /* make sure it's odd */ @@ -666,7 +777,12 @@ static void sp_ruler_real_draw_pos(SPRuler *ruler, } else { - width -= xthickness * 2; +#if GTK_CHECK_VERSION(3,0,0) + width = allocation.width - (border.left + border.right); +#else + width = allocation.width - xthickness * 2; +#endif + height = allocation.height; bs_height = width / 2 + 2; bs_height |= 1; /* make sure it's odd */ @@ -675,28 +791,62 @@ static void sp_ruler_real_draw_pos(SPRuler *ruler, if ((bs_width > 0) && (bs_height > 0)) { + cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); + gdouble lower; + gdouble upper; + gdouble position; + gdouble increment; + + cairo_rectangle (cr, + allocation.x, allocation.y, + allocation.width, allocation.height); + cairo_clip (cr); + + cairo_translate (cr, allocation.x, allocation.y); + + /* If a backing store exists, restore the ruler */ + if (priv->backing_store) + { + cairo_set_source_surface (cr, priv->backing_store, 0, 0); + cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height); + cairo_fill (cr); + } + + position = sp_ruler_get_position (ruler); + + sp_ruler_get_range (ruler, &lower, &upper, NULL); + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { - increment = (gdouble) width / (priv->upper - priv->lower); + increment = (gdouble) width / (upper - lower); - x = ROUND ((priv->position - priv->lower) * increment) + (xthickness - bs_width) / 2 - 1; +#if GTK_CHECK_VERSION(3,0,0) + x = ROUND ((position - lower) * increment) + (border.left - bs_width) / 2 - 1; + y = (height + bs_height) / 2 + border.top; +#else + x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1; y = (height + bs_height) / 2 + ythickness; +#endif } else { - increment = (gdouble) height / (priv->upper - priv->lower); + increment = (gdouble) height / (upper - lower); +#if GTK_CHECK_VERSION(3,0,0) + x = (width + bs_width) / 2 + border.left; + y = ROUND ((position - lower) * increment) + (border.top - bs_height) / 2 - 1; +#else x = (width + bs_width) / 2 + xthickness; - y = ROUND ((priv->position - priv->lower) * increment) + (ythickness - bs_height) / 2 - 1; + y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1; +#endif } #if GTK_CHECK_VERSION(3,0,0) - GtkStyleContext *sc = gtk_widget_get_style_context(widget); - GdkRGBA color; - gtk_style_context_get_color(sc, gtk_widget_get_state_flags(widget), &color); - gdk_cairo_set_source_rgba(cr, &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)]); + gdk_cairo_set_source_color (cr, &style->fg[state]); #endif cairo_move_to (cr, x, y); @@ -714,246 +864,636 @@ static void sp_ruler_real_draw_pos(SPRuler *ruler, cairo_fill (cr); + cairo_destroy (cr); + priv->xsrc = x; priv->ysrc = y; } } +/** + * sp_ruler_new: + * @orientation: the ruler's orientation + * + * Creates a new ruler. + * + * Return value: a new #SPRuler widget. + */ +GtkWidget * +sp_ruler_new (GtkOrientation orientation) +{ + return GTK_WIDGET (g_object_new (SP_TYPE_RULER, + "orientation", orientation, + NULL)); +} -#define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler +static void +sp_ruler_update_position (SPRuler *ruler, + gdouble x, + gdouble y) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + gdouble lower; + gdouble upper; + + gtk_widget_get_allocation (GTK_WIDGET (ruler), &allocation); + sp_ruler_get_range (ruler, &lower, &upper, NULL); -GtkWidget* sp_ruler_new(GtkOrientation orientation) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + sp_ruler_set_position (ruler, + lower + + (upper - lower) * x / allocation.width); + } + else + { + sp_ruler_set_position (ruler, + lower + + (upper - lower) * y / allocation.height); + } +} + +/* Returns TRUE if a translation should be done */ +static gboolean +gtk_widget_get_translation_to_window (GtkWidget *widget, + GdkWindow *window, + int *x, + int *y) { - return GTK_WIDGET(g_object_new(SP_TYPE_RULER, - "orientation", orientation, - NULL)); + GdkWindow *w, *widget_window; + + if (! gtk_widget_get_has_window (widget)) + { + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + + *x = -allocation.x; + *y = -allocation.y; + } + else + { + *x = 0; + *y = 0; + } + + widget_window = gtk_widget_get_window (widget); + + for (w = window; + w && w != widget_window; + w = gdk_window_get_effective_parent (w)) + { + gdouble px, py; + + gdk_window_coords_to_parent (w, *x, *y, &px, &py); + + *x += px; + *y += px; + } + + if (w == NULL) + { + *x = 0; + *y = 0; + return FALSE; + } + + return TRUE; } -static gboolean sp_ruler_motion_notify(GtkWidget *widget, - GdkEventMotion *event) +static void +sp_ruler_event_to_widget_coords (GtkWidget *widget, + GdkWindow *window, + gdouble event_x, + gdouble event_y, + gint *widget_x, + gint *widget_y) { - GtkAllocation allocation; - SPRuler *ruler = SP_RULER(widget); - SPRulerPrivate *priv = ruler->priv; - - gdk_event_request_motions(event); - gint x = event->x; - gint y = event->y; - - gtk_widget_get_allocation(widget, &allocation); + gint tx, ty; + + if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty)) + { + event_x += tx; + event_y += ty; + } + + *widget_x = event_x; + *widget_y = event_y; +} + +static gboolean +sp_ruler_track_widget_motion_notify (GtkWidget *widget, + GdkEventMotion *mevent, + SPRuler *ruler) +{ + gint widget_x; + gint widget_y; + gint ruler_x; + gint ruler_y; + + widget = gtk_get_event_widget (reinterpret_cast<GdkEvent *>(mevent)); + + sp_ruler_event_to_widget_coords (widget, mevent->window, + mevent->x, mevent->y, + &widget_x, &widget_y); + + if (gtk_widget_translate_coordinates (widget, GTK_WIDGET (ruler), + widget_x, widget_y, + &ruler_x, &ruler_y)) + { + sp_ruler_update_position (ruler, ruler_x, ruler_y); + } + + return FALSE; +} + +void +sp_ruler_add_track_widget (SPRuler *ruler, + GtkWidget *widget) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + g_return_if_fail (GTK_IS_WIDGET (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - priv->position = priv->lower + (priv->upper - priv->lower) * (x + UNUSED_PIXELS) / (allocation.width + 2*UNUSED_PIXELS); - else - priv->position = priv->lower + (priv->upper - priv->lower) * (y + UNUSED_PIXELS) / (allocation.height + 2*UNUSED_PIXELS); + g_return_if_fail (g_list_find (priv->track_widgets, widget) == NULL); - g_object_notify(G_OBJECT(ruler), "position"); + priv->track_widgets = g_list_prepend (priv->track_widgets, widget); - gtk_widget_queue_draw(widget); + g_signal_connect (widget, "motion-notify-event", + G_CALLBACK (sp_ruler_track_widget_motion_notify), + ruler); + g_signal_connect (widget, "destroy", + G_CALLBACK (sp_ruler_remove_track_widget), + ruler); +} - return FALSE; +/** + * sp_ruler_remove_track_widget: + * @ruler: an #SPRuler + * @widget: the track widget to remove + * + * Removes a previously added track widget from the ruler. See + * sp_ruler_add_track_widget(). + */ +void +sp_ruler_remove_track_widget (SPRuler *ruler, + GtkWidget *widget) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + g_return_if_fail (GTK_IS_WIDGET (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + g_return_if_fail (g_list_find (priv->track_widgets, widget) != NULL); + + priv->track_widgets = g_list_remove (priv->track_widgets, widget); + + g_signal_handlers_disconnect_by_func (widget, + (gpointer) G_CALLBACK (sp_ruler_track_widget_motion_notify), + ruler); + g_signal_handlers_disconnect_by_func (widget, + (gpointer) G_CALLBACK (sp_ruler_remove_track_widget), + ruler); } -static void sp_ruler_real_draw_ticks(SPRuler *ruler, cairo_t *cr) +/** + * sp_ruler_set_unit: + * @ruler: a #SPRuler + * @unit: the #SPMetric to set the ruler to + * + * This sets the unit of the ruler. + */ +void +sp_ruler_set_unit (SPRuler *ruler, + SPMetric unit) { - SPRulerPrivate *priv = ruler->priv; - gint width = 0; - gint height = 0; - gchar unit_str[32]; - gchar digit_str[2] = { '\0', '\0' }; - GtkOrientation orientation; - GtkAllocation allocation; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + g_return_if_fail (SP_IS_RULER (ruler)); - g_return_if_fail (ruler != NULL); + if (priv->unit != unit) + { + priv->unit = unit; + g_object_notify(G_OBJECT(ruler), "unit"); - g_object_get(G_OBJECT(ruler), "orientation", &orientation, NULL); - GtkWidget *widget = GTK_WIDGET (ruler); + gtk_widget_queue_draw (GTK_WIDGET (ruler)); + } +} - PangoContext *pango_context = gtk_widget_get_pango_context (widget); - PangoLayout *pango_layout = pango_layout_new (pango_context); - PangoFontDescription *fs = pango_font_description_new (); - pango_font_description_set_size (fs, RULER_FONT_SIZE); - pango_layout_set_font_description (pango_layout, fs); - pango_font_description_free (fs); +/** + * sp_ruler_get_unit: + * @ruler: a #SPRuler + * + * Return value: the unit currently used in the @ruler widget. + **/ +SPMetric +sp_ruler_get_unit (SPRuler *ruler) +{ + g_return_val_if_fail(SP_IS_RULER(ruler), static_cast<SPMetric>(0)); + + return SP_RULER_GET_PRIVATE (ruler)->unit; +} + +/** + * sp_ruler_set_position: + * @ruler: a #SPRuler + * @position: the position to set the ruler to + * + * This sets the position of the ruler. + */ +void +sp_ruler_set_position (SPRuler *ruler, + gdouble position) +{ + SPRulerPrivate *priv; - gint digit_height = (int) floor (RULER_FONT_SIZE * RULER_FONT_VERTICAL_SPACING / PANGO_SCALE + 0.5); + g_return_if_fail (SP_IS_RULER (ruler)); + priv = SP_RULER_GET_PRIVATE (ruler); + + if (priv->position != position) + { + priv->position = position; + g_object_notify (G_OBJECT (ruler), "position"); + + sp_ruler_draw_pos (ruler); + } +} + +/** + * sp_ruler_get_position: + * @ruler: a #SPRuler + * + * Return value: the current position of the @ruler widget. + */ +gdouble +sp_ruler_get_position (SPRuler *ruler) +{ + g_return_val_if_fail (SP_IS_RULER (ruler), 0.0); + + return SP_RULER_GET_PRIVATE (ruler)->position; +} + +static gboolean +sp_ruler_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + SPRuler *ruler = SP_RULER(widget); + + sp_ruler_update_position (ruler, event->x, event->y); + + return FALSE; +} + +static void +sp_ruler_draw_ticks (SPRuler *ruler) +{ + GtkWidget *widget = GTK_WIDGET (ruler); + #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; + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder border; + GdkRGBA color; #else - GtkStyle *style = gtk_widget_get_style(widget); - gint xthickness = style->xthickness; - gint ythickness = style->ythickness; + GtkStyle *style = gtk_widget_get_style (widget); + GtkStateType state = gtk_widget_get_state (widget); + gint xthickness; + gint ythickness; #endif + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + cairo_t *cr; + gint i; + gint width, height; + gint length, ideal_length; + gdouble lower, upper; /* Upper and lower limits, in ruler units */ + gdouble increment; /* Number of pixels per unit */ + guint scale; /* Number of units per major unit */ + gdouble start, end, cur; + gchar unit_str[32]; + gint digit_height; + gint digit_offset; + gchar digit_str[2] = { '\0', '\0' }; + gint text_size; + gint pos; + gdouble max_size; + SPMetric unit; + SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ + PangoLayout *layout; + PangoRectangle logical_rect, ink_rect; + + if (! gtk_widget_is_drawable (widget)) + return; + gtk_widget_get_allocation (widget, &allocation); + +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_border (context, static_cast<GtkStateFlags>(0), &border); +#else + xthickness = style->xthickness; + ythickness = style->ythickness; +#endif + + layout = sp_ruler_get_layout (widget, "0123456789"); + pango_layout_get_extents (layout, &ink_rect, &logical_rect); - if (orientation == GTK_ORIENTATION_HORIZONTAL) { - width = allocation.width; // in pixels; is apparently 2 pixels shorter than the canvas at each end - height = allocation.height; - } else { - width = allocation.height; - height = allocation.width; - } + digit_height = PANGO_PIXELS (ink_rect.height) + 2; + digit_offset = ink_rect.y; + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + width = allocation.width; #if GTK_CHECK_VERSION(3,0,0) - gtk_render_frame(context, - cr, - 0, 0, - allocation.width, allocation.height); - - gtk_render_background(context, - cr, - 0, 0, - allocation.width, allocation.height); + height = allocation.height - (border.top + border.bottom); #else - gtk_paint_box(style, priv->backing_store, - GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, - orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler", - 0, 0, - allocation.width, allocation.height); + height = allocation.height - ythickness * 2; #endif - - cairo_set_line_width(cr, 1.0); + } + else + { + width = allocation.height; +#if GTK_CHECK_VERSION(3,0,0) + height = allocation.width - (border.top + border.bottom); +#else + height = allocation.width - ythickness * 2; +#endif + } + cr = cairo_create (priv->backing_store); + #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); + gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); + gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); + + gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), + &color); + gdk_cairo_set_source_rgba (cr, &color); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + border.left, + height + border.top, + allocation.width - (border.left + border.right), + 1); + } + else + { + cairo_rectangle (cr, + height + border.left, + border.top, + 1, + allocation.height - (border.top + border.bottom)); + } #else - gdk_cairo_set_source_color(cr, &style->fg[gtk_widget_get_state(widget)]); + gdk_cairo_set_source_color (cr, &style->bg[state]); + + cairo_paint (cr); + + gdk_cairo_set_source_color(cr, &style->fg[state]); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + xthickness, + height + ythickness, + allocation.width - 2 * xthickness, + 1); + } + else + { + cairo_rectangle (cr, + height + xthickness, + ythickness, + 1, + allocation.height - 2 * ythickness); + } #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; - /* "pixels_per_unit" should be "points_per_unit". This is the size of the unit - * in 1/72nd's of an inch and has nothing to do with screen pixels */ + sp_ruler_get_range (ruler, &lower, &upper, &max_size); if ((upper - lower) == 0) - return; + goto out; - double increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower); // screen pixels per ruler unit + increment = (gdouble) width / (upper - lower); /* determine the scale - * For vruler, use the maximum extents of the ruler to determine the largest - * possible number to be displayed. Calculate the height in pixels - * of this displayed text. Use this height to find a scale which - * leaves sufficient room for drawing the ruler. - * For hruler, we calculate the text size as for the vruler instead of using - * text_width = gdk_string_width(font, unit_str), so that the result - * for the scale looks consistent with an accompanying vruler + * Use the maximum extents of the ruler to determine the largest + * possible number to be displayed. Calculate the height in pixels + * of this displayed text. Use this height to find a scale which + * leaves sufficient room for drawing the ruler. + * + * We calculate the text size as for the vruler instead of + * actually measuring the text width, so that the result for the + * scale looks consistent with an accompanying vruler */ - gint scale = (int)(ceil(priv->max_size / priv->metric->pixels_per_unit)); + scale = ceil (priv->max_size); sprintf (unit_str, "%d", scale); - gint text_dimension = strlen (unit_str) * digit_height + 1; + text_size = strlen (unit_str) * digit_height + 1; + + /* Inkscape change to ruler: Use a 1,2,4,8... scale for inches + * or a 1,2,5,10... scale for everything else */ + if (sp_ruler_get_unit (ruler) == SP_IN) + ruler_metric = ruler_metric_inches; - for (scale = 0; scale < MAXIMUM_SCALES; scale++) - if (priv->metric->ruler_scale[scale] * fabs(increment) > 2 * text_dimension) + for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) + if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_size) break; - if (scale == MAXIMUM_SCALES) - scale = MAXIMUM_SCALES - 1; + if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) + scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; + + unit = sp_ruler_get_unit (ruler); /* drawing starts here */ - gint length = 0; - for (gint i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--) { - double subd_incr = priv->metric->ruler_scale[scale] / - priv->metric->subdivide[i]; - if (subd_incr * fabs(increment) <= MINIMUM_INCR) + length = 0; + for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--) + { + gdouble subd_incr; + + /* hack to get proper subdivisions at full pixels */ + if (unit == SP_PX && scale == 1 && i == 1) + subd_incr = 1.0; + else + subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / + (gdouble) ruler_metric.subdivide[i]); + + if (subd_incr * fabs (increment) <= MINIMUM_INCR) continue; /* Calculate the length of the tickmarks. Make sure that * this length increases for each set of ticks */ - gint ideal_length = height / (i + 1) - 1; + ideal_length = height / (i + 1) - 1; if (ideal_length > ++length) length = ideal_length; - gdouble start = 0; - gdouble end = 0; - if (lower < upper) { + if (lower < upper) + { start = floor (lower / subd_incr) * subd_incr; end = ceil (upper / subd_incr) * subd_incr; - } else { + } + else + { start = floor (upper / subd_incr) * subd_incr; end = ceil (lower / subd_incr) * subd_incr; - } + } gint tick_index = 0; - gdouble cur = start; // location (in ruler units) of the first invisible tick at the left side of the canvas - while (cur <= end) { + for (cur = start; cur <= end; cur += subd_incr) + { // due to the typical values for cur, lower and increment, pos will often end up to // be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h) // and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-)) - gint pos = int(Inkscape::round((cur - lower) * increment + 1e-12)) - UNUSED_PIXELS; + pos = gint(Inkscape::round((cur - lower) * increment + 1e-12)); - if (orientation == GTK_ORIENTATION_HORIZONTAL) { - cairo_move_to(cr, pos+0.5, height + ythickness); - cairo_line_to(cr, pos+0.5, height - length + ythickness); - } else { - cairo_move_to(cr, height + xthickness - length, pos+0.5); - cairo_line_to(cr, height + xthickness, pos+0.5); - } +#if GTK_CHECK_VERSION(3,0,0) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + pos, height + border.top - length, + 1, length); + } + else + { + cairo_rectangle (cr, + height + border.left - length, pos, + length, 1); + } +#else + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + pos, height + ythickness - length, + 1, length); + } + else + { + cairo_rectangle (cr, + height + xthickness - length, pos, + length, 1); + } +#endif /* draw label */ - double label_spacing_px = fabs((increment*(double)priv->metric->ruler_scale[scale])/priv->metric->subdivide[i]); + double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]); if (i == 0 && (label_spacing_px > 6*digit_height || tick_index%2 == 0 || cur == 0) && (label_spacing_px > 3*digit_height || tick_index%4 == 0 || cur == 0)) - { + { if (fabs((int)cur) >= 2000 && (((int) cur)/1000)*1000 == ((int) cur)) sprintf (unit_str, "%dk", ((int) cur)/1000); else sprintf (unit_str, "%d", (int) cur); - if (orientation == GTK_ORIENTATION_HORIZONTAL) { - pango_layout_set_text (pango_layout, unit_str, -1); - cairo_move_to(cr, pos+2, 0); - pango_cairo_show_layout(cr, pango_layout); - } else { - for (gint j = 0; j < (int) strlen (unit_str); j++) { + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + pango_layout_set_text (layout, unit_str, -1); + pango_layout_get_extents (layout, &logical_rect, NULL); + +#if GTK_CHECK_VERSION(3,0,0) + cairo_move_to (cr, + pos + 2, + border.top + PANGO_PIXELS (logical_rect.y - digit_offset)); +#else + cairo_move_to (cr, + pos + 2, + ythickness + PANGO_PIXELS (logical_rect.y - digit_offset)); +#endif + + pango_cairo_show_layout(cr, layout); + } + else + { + gint j; + + for (j = 0; j < (int) strlen (unit_str); j++) + { digit_str[0] = unit_str[j]; - pango_layout_set_text (pango_layout, digit_str, 1); - cairo_move_to(cr, xthickness + 1, pos + digit_height * (j) + 1); - pango_cairo_show_layout(cr, pango_layout); - } - } - - } - /* Calculate cur from start rather than incrementing by subd_incr - * in each iteration. This is to avoid propagation of floating point - * errors in subd_incr. - */ + pango_layout_set_text (layout, digit_str, 1); + pango_layout_get_extents (layout, NULL, &logical_rect); + +#if GTK_CHECK_VERSION(3,0,0) + cairo_move_to (cr, + border.left + 1, + pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); +#else + cairo_move_to (cr, + xthickness + 1, + pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); +#endif + pango_cairo_show_layout (cr, layout); + } + } + } + ++tick_index; - cur = start + tick_index * subd_incr; - cairo_stroke(cr); - } - } -} + } + } + cairo_fill (cr); -void sp_ruler_set_metric(SPRuler *ruler, SPMetric metric) +out: + cairo_destroy (cr); +} + +static PangoLayout* +sp_ruler_create_layout (GtkWidget *widget, + const gchar *text) { - g_return_if_fail(ruler != NULL); - g_return_if_fail(SP_IS_RULER (ruler)); - g_return_if_fail((unsigned) metric < G_N_ELEMENTS(sp_ruler_metrics)); - SPRulerPrivate *priv = ruler->priv; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + PangoLayout *layout; + PangoAttrList *attrs; + PangoAttribute *attr; - if (metric == 0) - return; + layout = gtk_widget_create_pango_layout (widget, text); - priv->metric = const_cast<SPRulerMetric *>(&sp_ruler_metrics[metric]); + attrs = pango_attr_list_new (); - g_object_notify(G_OBJECT(ruler), "metric"); + attr = pango_attr_scale_new (priv->font_scale); + attr->start_index = 0; + attr->end_index = -1; + pango_attr_list_insert (attrs, attr); - sp_ruler_invalidate_ticks(ruler); + pango_layout_set_attributes (layout, attrs); + pango_attr_list_unref (attrs); + + return layout; +} + +static PangoLayout * +sp_ruler_get_layout (GtkWidget *widget, + const gchar *text) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + + if (priv->layout) + { + pango_layout_set_text (priv->layout, text, -1); + return priv->layout; + } + + priv->layout = sp_ruler_create_layout (widget, text); + + return priv->layout; } + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h index d4e21b300..f0d866fff 100644 --- a/src/widgets/ruler.h +++ b/src/widgets/ruler.h @@ -18,6 +18,8 @@ #include <iostream> #include <glib.h> +G_BEGIN_DECLS + #define SP_TYPE_RULER (sp_ruler_get_type ()) #define SP_RULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_RULER, SPRuler)) #define SP_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_RULER, SPRulerClass)) @@ -25,59 +27,45 @@ #define SP_IS_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_RULER)) #define SP_RULER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SP_TYPE_RULER, SPRulerClass)) - typedef struct _SPRuler SPRuler; -typedef struct _SPRulerPrivate SPRulerPrivate; typedef struct _SPRulerClass SPRulerClass; -typedef struct _SPRulerMetric SPRulerMetric; -/* All distances below are in 1/72nd's of an inch. (According to - * Adobe that's a point, but points are really 1/72.27 in.) - */ struct _SPRuler { - GtkWidget widget; - - /*< private >*/ - SPRulerPrivate *priv; + GtkWidget parent_instance; }; struct _SPRulerClass { GtkWidgetClass parent_class; - - void (* draw_ticks) (SPRuler *ruler, - cairo_t *cr); - void (* draw_pos) (SPRuler *ruler, - cairo_t *cr); }; -struct _SPRulerMetric -{ - gchar const *metric_name; - gchar const *abbrev; - /* This should be points_per_unit. This is the size of the unit - * in 1/72nd's of an inch and has nothing to do with screen pixels */ - gdouble pixels_per_unit; - gdouble ruler_scale[10]; - gint subdivide[5]; /* five possible modes of subdivision */ -}; +GType sp_ruler_get_type (void) G_GNUC_CONST; + +GtkWidget* sp_ruler_new (GtkOrientation orientation); + +void sp_ruler_add_track_widget (SPRuler *ruler, + GtkWidget *widget); +void sp_ruler_remove_track_widget (SPRuler *ruler, + GtkWidget *widget); + +void sp_ruler_set_unit (SPRuler *ruler, + SPMetric unit); +SPMetric sp_ruler_get_unit (SPRuler *ruler); +void sp_ruler_set_position (SPRuler *ruler, + gdouble set_position); +gdouble sp_ruler_get_position (SPRuler *ruler); +void sp_ruler_set_range (SPRuler *ruler, + gdouble lower, + gdouble upper, + gdouble max_size); +void sp_ruler_get_range (SPRuler *ruler, + gdouble *lower, + gdouble *upper, + gdouble *max_size); -GType sp_ruler_get_type (void) G_GNUC_CONST; -GtkWidget* sp_ruler_new (GtkOrientation orientation); -void sp_ruler_set_range (SPRuler *ruler, - gdouble lower, - gdouble upper, - gdouble position, - gdouble max_size); -void sp_ruler_get_range (SPRuler *ruler, - gdouble *lower, - gdouble *upper, - gdouble *position, - gdouble *max_size); -void sp_ruler_set_metric(SPRuler *ruler, SPMetric metric); -SPMetric sp_ruler_get_metric(SPRuler *ruler); +G_END_DECLS #endif /* __SP_RULER_H__ */ diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 3ccfa9cf9..549581610 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -88,13 +88,13 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) if (unit.base == SP_UNIT_DIMENSIONLESS) { double const val = 1. / unit.unittobase; for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { - GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key); + GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, val); tracker->setFullVal( a, keyval[i].val ); } } else { for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { - GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key); + GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit)); } } diff --git a/src/widgets/sp-color-icc-selector.cpp b/src/widgets/sp-color-icc-selector.cpp index 80974c2e4..d89d35e9c 100644 --- a/src/widgets/sp-color-icc-selector.cpp +++ b/src/widgets/sp-color-icc-selector.cpp @@ -104,12 +104,9 @@ sp_color_icc_selector_get_type (void) static void sp_color_icc_selector_class_init(SPColorICCSelectorClass *klass) { static const gchar* nameset[] = {N_("CMS"), 0}; - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class; - SPColorSelectorClass *selector_class; - - widget_class = (GtkWidgetClass *) klass; - selector_class = SP_COLOR_SELECTOR_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + SPColorSelectorClass *selector_class = SP_COLOR_SELECTOR_CLASS (klass); parent_class = SP_COLOR_SELECTOR_CLASS (g_type_class_peek_parent (klass)); @@ -453,7 +450,7 @@ void ColorICCSelector::init() #endif /* Adjustment */ - _adj = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 10.0, 10.0); + _adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0)); /* Slider */ _slider = sp_color_slider_new (_adj); @@ -510,8 +507,8 @@ void ColorICCSelector::init() static void sp_color_icc_selector_dispose(GObject *object) { - if (((GObjectClass *) (parent_class))->dispose) - (* ((GObjectClass *) (parent_class))->dispose)(object); + if ((G_OBJECT_CLASS(parent_class))->dispose) + (* (G_OBJECT_CLASS(parent_class))->dispose)(object); } static void @@ -672,7 +669,7 @@ void ColorICCSelector::_profilesChanged( std::string const & name ) g_signal_handler_block( G_OBJECT(_profileSel), _profChangedID ); - GtkListStore *store = (GtkListStore *)gtk_combo_box_get_model (combo); + GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); gtk_list_store_clear(store); GtkTreeIter iter; @@ -1008,7 +1005,7 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC void ColorICCSelector::_sliderGrabbed( SPColorSlider */*slider*/, SPColorICCSelector */*cs*/ ) { -// ColorICCSelector* iccSelector = (ColorICCSelector*)(SP_COLOR_SELECTOR(cs)->base); +// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); // if (!iccSelector->_dragging) { // iccSelector->_dragging = TRUE; // iccSelector->_grabbed(); @@ -1018,7 +1015,7 @@ void ColorICCSelector::_sliderGrabbed( SPColorSlider */*slider*/, SPColorICCSele void ColorICCSelector::_sliderReleased( SPColorSlider */*slider*/, SPColorICCSelector */*cs*/ ) { -// ColorICCSelector* iccSelector = (ColorICCSelector*)(SP_COLOR_SELECTOR(cs)->base); +// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); // if (iccSelector->_dragging) { // iccSelector->_dragging = FALSE; // iccSelector->_released(); @@ -1035,7 +1032,7 @@ void ColorICCSelector::_sliderChanged( SPColorSlider */*slider*/, SPColorICCSele #ifdef DEBUG_LCMS g_message("Changed %p and %p", slider, cs ); #endif // DEBUG_LCMS -// ColorICCSelector* iccSelector = (ColorICCSelector*)(SP_COLOR_SELECTOR(cs)->base); +// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging ); } diff --git a/src/widgets/sp-color-scales.cpp b/src/widgets/sp-color-scales.cpp index 95c6d341d..c3f9d511c 100644 --- a/src/widgets/sp-color-scales.cpp +++ b/src/widgets/sp-color-scales.cpp @@ -78,12 +78,9 @@ static void sp_color_scales_class_init (SPColorScalesClass *klass) { static const gchar* nameset[] = {N_("RGB"), N_("HSL"), N_("CMYK"), 0}; - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class; - SPColorSelectorClass *selector_class; - - widget_class = (GtkWidgetClass *) klass; - selector_class = SP_COLOR_SELECTOR_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + SPColorSelectorClass *selector_class = SP_COLOR_SELECTOR_CLASS (klass); parent_class = SP_COLOR_SELECTOR_CLASS (g_type_class_peek_parent (klass)); @@ -164,7 +161,7 @@ void ColorScales::init() #endif /* Adjustment */ - _a[i] = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, _rangeLimit, 1.0, 10.0, 10.0); + _a[i] = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, _rangeLimit, 1.0, 10.0, 10.0)); /* Slider */ _s[i] = sp_color_slider_new (_a[i]); gtk_widget_show (_s[i]); @@ -217,8 +214,8 @@ void ColorScales::init() static void sp_color_scales_dispose(GObject *object) { - if (((GObjectClass *) (parent_class))->dispose) - (* ((GObjectClass *) (parent_class))->dispose) (object); + if ((G_OBJECT_CLASS(parent_class))->dispose) + (* (G_OBJECT_CLASS(parent_class))->dispose) (object); } static void @@ -466,7 +463,7 @@ void ColorScales::setMode(SPColorScalesMode mode) gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[3]), _("_A:")); gtk_widget_set_tooltip_text (_s[3], _("Alpha (opacity)")); gtk_widget_set_tooltip_text (_b[3], _("Alpha (opacity)")); - sp_color_slider_set_map (SP_COLOR_SLIDER (_s[0]), (guchar*)sp_color_scales_hue_map ()); + sp_color_slider_set_map (SP_COLOR_SLIDER (_s[0]), (guchar *)(sp_color_scales_hue_map())); gtk_widget_hide (_l[4]); gtk_widget_hide (_s[4]); gtk_widget_hide (_b[4]); diff --git a/src/widgets/sp-color-slider.cpp b/src/widgets/sp-color-slider.cpp index 3ba748f2b..37cccda9f 100644 --- a/src/widgets/sp-color-slider.cpp +++ b/src/widgets/sp-color-slider.cpp @@ -86,12 +86,10 @@ sp_color_slider_get_type (void) static void sp_color_slider_class_init(SPColorSliderClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class; + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - widget_class = (GtkWidgetClass *) klass; - - parent_class = (GtkWidgetClass*)g_type_class_peek_parent (klass); + parent_class = GTK_WIDGET_CLASS(g_type_class_peek_parent(klass)); slider_signals[GRABBED] = g_signal_new ("grabbed", G_TYPE_FROM_CLASS(object_class), @@ -185,8 +183,8 @@ static void sp_color_slider_dispose(GObject *object) slider->adjustment = NULL; } - if (((GObjectClass *) (parent_class))->dispose) - (* ((GObjectClass *) (parent_class))->dispose) (object); + if ((G_OBJECT_CLASS(parent_class))->dispose) + (* (G_OBJECT_CLASS(parent_class))->dispose) (object); } static void @@ -311,17 +309,16 @@ sp_color_slider_button_press (GtkWidget *widget, GdkEventButton *event) g_signal_emit (G_OBJECT (slider), slider_signals[DRAGGED], 0); #if GTK_CHECK_VERSION(3,0,0) - gdk_device_grab(gdk_event_get_device((GdkEvent*)event), + gdk_device_grab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)), gtk_widget_get_window(widget), GDK_OWNERSHIP_NONE, FALSE, - (GdkEventMask)(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), + static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, event->time); #else gdk_pointer_grab(gtk_widget_get_window(widget), FALSE, - (GdkEventMask)(GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK), + static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, NULL, event->time); #endif } @@ -339,8 +336,8 @@ sp_color_slider_button_release (GtkWidget *widget, GdkEventButton *event) if (event->button == 1) { #if GTK_CHECK_VERSION(3,0,0) - gdk_device_ungrab(gdk_event_get_device((GdkEvent *)event), - gdk_event_get_time((GdkEvent *)event)); + gdk_device_ungrab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)), + gdk_event_get_time(reinterpret_cast<GdkEvent *>(event))); #else gdk_pointer_ungrab (event->time); #endif @@ -388,7 +385,7 @@ void sp_color_slider_set_adjustment(SPColorSlider *slider, GtkAdjustment *adjust g_return_if_fail (SP_IS_COLOR_SLIDER (slider)); if (!adjustment) { - adjustment = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, 1.0, 0.01, 0.0, 0.0); + adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 1.0, 0.01, 0.0, 0.0)); } else { gtk_adjustment_set_page_increment(adjustment, 0.0); gtk_adjustment_set_page_size(adjustment, 0.0); @@ -448,7 +445,7 @@ sp_color_slider_set_map (SPColorSlider *slider, const guchar *map) g_return_if_fail (slider != NULL); g_return_if_fail (SP_IS_COLOR_SLIDER (slider)); - slider->map = (guchar *) map; + slider->map = const_cast<guchar *>(map); gtk_widget_queue_draw (GTK_WIDGET (slider)); } diff --git a/src/widgets/sp-color-wheel-selector.cpp b/src/widgets/sp-color-wheel-selector.cpp index a979a168a..3e91274d2 100644 --- a/src/widgets/sp-color-wheel-selector.cpp +++ b/src/widgets/sp-color-wheel-selector.cpp @@ -56,12 +56,9 @@ sp_color_wheel_selector_get_type (void) static void sp_color_wheel_selector_class_init(SPColorWheelSelectorClass *klass) { static const gchar* nameset[] = {N_("Wheel"), 0}; - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class; - SPColorSelectorClass *selector_class; - - widget_class = (GtkWidgetClass *) klass; - selector_class = SP_COLOR_SELECTOR_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + SPColorSelectorClass *selector_class = SP_COLOR_SELECTOR_CLASS (klass); parent_class = SP_COLOR_SELECTOR_CLASS (g_type_class_peek_parent (klass)); @@ -197,7 +194,7 @@ void ColorWheelSelector::init() #endif /* Adjustment */ - _adj = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 10.0, 10.0); + _adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0)); /* Slider */ _slider = sp_color_slider_new (_adj); @@ -266,8 +263,8 @@ void ColorWheelSelector::init() static void sp_color_wheel_selector_dispose(GObject *object) { - if (((GObjectClass *) (parent_class))->dispose) - (* ((GObjectClass *) (parent_class))->dispose) (object); + if ((G_OBJECT_CLASS(parent_class))->dispose) + (* (G_OBJECT_CLASS(parent_class))->dispose) (object); } static void diff --git a/src/widgets/sp-widget.cpp b/src/widgets/sp-widget.cpp index 8d840da25..7876f0454 100644 --- a/src/widgets/sp-widget.cpp +++ b/src/widgets/sp-widget.cpp @@ -306,7 +306,7 @@ GtkWidget *SPWidgetImpl::constructGlobal(SPWidget *spw, Inkscape::Application *i g_signal_emit(spw, signals[CONSTRUCT], 0); - return (GtkWidget *) spw; + return GTK_WIDGET(spw); } void SPWidgetImpl::modifySelectionCB(Application *inkscape, Selection *selection, guint flags, SPWidget *spw) diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp index 1fd120d17..47b0ebb9d 100644 --- a/src/widgets/sp-xmlview-attr-list.cpp +++ b/src/widgets/sp-xmlview-attr-list.cpp @@ -68,7 +68,7 @@ GtkWidget *sp_xmlview_attr_list_new (Inkscape::XML::Node * repr) sp_xmlview_attr_list_set_repr (attr_list, repr); - return (GtkWidget *) attr_list; + return GTK_WIDGET(attr_list); } void @@ -114,14 +114,14 @@ GType sp_xmlview_attr_list_get_type(void) void sp_xmlview_attr_list_class_init (SPXMLViewAttrListClass * klass) { #if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = (GtkWidgetClass *) klass; + GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_attr_list_destroy; #else - GtkObjectClass * object_class = (GtkObjectClass *) klass; + GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); object_class->destroy = sp_xmlview_attr_list_destroy; #endif - parent_class = (GtkTreeViewClass*)g_type_class_peek_parent (klass); + parent_class = GTK_TREE_VIEW_CLASS(g_type_class_peek_parent (klass)); g_signal_new("row-value-changed", G_TYPE_FROM_CLASS(klass), diff --git a/src/widgets/sp-xmlview-content.cpp b/src/widgets/sp-xmlview-content.cpp index d31e031c2..ac64dabdb 100644 --- a/src/widgets/sp-xmlview-content.cpp +++ b/src/widgets/sp-xmlview-content.cpp @@ -59,7 +59,7 @@ GtkWidget *sp_xmlview_content_new(Inkscape::XML::Node * repr) sp_xmlview_content_set_repr (text, repr); - return (GtkWidget *) text; + return GTK_WIDGET(text); } void @@ -107,14 +107,14 @@ GType sp_xmlview_content_get_type(void) void sp_xmlview_content_class_init(SPXMLViewContentClass * klass) { #if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = (GtkWidgetClass *) klass; + GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_content_destroy; #else - GtkObjectClass * object_class = (GtkObjectClass *) klass; + GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); object_class->destroy = sp_xmlview_content_destroy; #endif - parent_class = (GtkTextViewClass*)g_type_class_peek_parent (klass); + parent_class = GTK_TEXT_VIEW_CLASS(g_type_class_peek_parent (klass)); } void diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp index 258cea0b4..bc6031c1e 100644 --- a/src/widgets/sp-xmlview-tree.cpp +++ b/src/widgets/sp-xmlview-tree.cpp @@ -122,7 +122,7 @@ GtkWidget *sp_xmlview_tree_new(Inkscape::XML::Node * repr, void * /*factory*/, v g_signal_connect(GTK_TREE_VIEW(tree), "drag_data_received", G_CALLBACK(on_drag_data_received), tree); g_signal_connect(GTK_TREE_VIEW(tree), "drag-motion", G_CALLBACK(do_drag_motion), tree); - return (GtkWidget *) tree; + return GTK_WIDGET(tree); } GType @@ -151,14 +151,14 @@ sp_xmlview_tree_get_type (void) void sp_xmlview_tree_class_init(SPXMLViewTreeClass * klass) { #if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = (GtkWidgetClass *) klass; + GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_tree_destroy; #else - GtkObjectClass * object_class = (GtkObjectClass *) klass; + GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); object_class->destroy = sp_xmlview_tree_destroy; #endif - parent_class = (GtkTreeViewClass *) g_type_class_peek_parent (klass); + parent_class = GTK_TREE_VIEW_CLASS(g_type_class_peek_parent (klass)); // Signal for when a tree drag and drop has completed g_signal_new ( "tree_move", @@ -441,7 +441,7 @@ void on_row_changed(GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *it return; } - GtkTreeRowReference *old_parent_ref = (GtkTreeRowReference *)g_object_get_data (G_OBJECT (tree), "drag-src-path"); + GtkTreeRowReference *old_parent_ref = static_cast<GtkTreeRowReference *>(g_object_get_data (G_OBJECT (tree), "drag-src-path")); if (!old_parent_ref) { //No drag source location g_signal_emit_by_name(G_OBJECT (tree), "tree_move", GUINT_TO_POINTER(0) ); diff --git a/src/widgets/spinbutton-events.cpp b/src/widgets/spinbutton-events.cpp index 1d44b9190..96d746468 100644 --- a/src/widgets/spinbutton-events.cpp +++ b/src/widgets/spinbutton-events.cpp @@ -23,11 +23,9 @@ #include "spinbutton-events.h" gboolean -spinbutton_focus_in (GtkWidget *w, GdkEventKey */*event*/, gpointer /*data*/) +spinbutton_focus_in (GtkWidget *w, GdkEventKey * /*event*/, gpointer /*data*/) { - gdouble *ini; - - ini = (gdouble *) g_object_get_data(G_OBJECT (w), "ini"); + gdouble *ini = static_cast<gdouble *>(g_object_get_data(G_OBJECT(w), "ini")); if (ini) g_free (ini); // free the old value if any // retrieve the value @@ -43,7 +41,7 @@ spinbutton_focus_in (GtkWidget *w, GdkEventKey */*event*/, gpointer /*data*/) void spinbutton_undo (GtkWidget *w) { - gdouble *ini = (gdouble *) g_object_get_data(G_OBJECT (w), "ini"); + gdouble *ini = static_cast<gdouble *>(g_object_get_data(G_OBJECT (w), "ini")); if (ini) { gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), *ini); } @@ -57,7 +55,7 @@ spinbutton_defocus (GtkWidget *container) if (stay) { g_object_set_data (G_OBJECT (container), "stay", GINT_TO_POINTER (FALSE)); } else { - GtkWidget *canvas = (GtkWidget *) g_object_get_data(G_OBJECT (container), "dtw"); + GtkWidget *canvas = GTK_WIDGET(g_object_get_data(G_OBJECT (container), "dtw")); if (canvas) { gtk_widget_grab_focus (GTK_WIDGET(canvas)); } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index c51c8b6cf..b493ca5bf 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -147,15 +147,15 @@ static void sp_spl_tb_defaults(GtkWidget * /*widget*/, GObject *obj) gdouble exp = 1.0; gdouble t0 = 0.0; - adj = (GtkAdjustment*)g_object_get_data(obj, "revolution"); + adj = GTK_ADJUSTMENT(g_object_get_data(obj, "revolution")); gtk_adjustment_set_value(adj, rev); gtk_adjustment_value_changed(adj); - adj = (GtkAdjustment*)g_object_get_data(obj, "expansion"); + adj = GTK_ADJUSTMENT(g_object_get_data(obj, "expansion")); gtk_adjustment_set_value(adj, exp); gtk_adjustment_value_changed(adj); - adj = (GtkAdjustment*)g_object_get_data(obj, "t0"); + adj = GTK_ADJUSTMENT(g_object_get_data(obj, "t0")); gtk_adjustment_set_value(adj, t0); gtk_adjustment_value_changed(adj); @@ -181,17 +181,17 @@ static void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr, g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE)); GtkAdjustment *adj; - adj = (GtkAdjustment*)g_object_get_data(G_OBJECT(tbl), "revolution"); + adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "revolution")); double revolution = 3.0; sp_repr_get_double(repr, "sodipodi:revolution", &revolution); gtk_adjustment_set_value(adj, revolution); - adj = (GtkAdjustment*)g_object_get_data(G_OBJECT(tbl), "expansion"); + adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "expansion")); double expansion = 1.0; sp_repr_get_double(repr, "sodipodi:expansion", &expansion); gtk_adjustment_set_value(adj, expansion); - adj = (GtkAdjustment*)g_object_get_data(G_OBJECT(tbl), "t0"); + adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "t0")); double t0 = 0.0; sp_repr_get_double(repr, "sodipodi:t0", &t0); gtk_adjustment_set_value(adj, t0); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index d783e3336..f8c5714cb 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -337,7 +337,7 @@ static void star_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *n gtk_action_set_sensitive( prop_action, FALSE ); } } else if ((!strcmp(name, "sodipodi:r1") || !strcmp(name, "sodipodi:r2")) && (!isFlatSided) ) { - adj = (GtkAdjustment*)g_object_get_data(G_OBJECT(tbl), "proportion"); + adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "proportion")); gdouble r1 = 1.0; gdouble r2 = 1.0; sp_repr_get_double(repr, "sodipodi:r1", &r1); @@ -348,7 +348,7 @@ static void star_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *n gtk_adjustment_set_value(adj, r1/r2); } } else if (!strcmp(name, "sodipodi:sides")) { - adj = (GtkAdjustment*)g_object_get_data(G_OBJECT(tbl), "magnitude"); + adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "magnitude")); int sides = 0; sp_repr_get_int(repr, "sodipodi:sides", &sides); gtk_adjustment_set_value(adj, sides); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 9e0977d51..6c22c81e3 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -174,6 +174,9 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) Ink_ComboBoxEntry_Action* act = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); GtkTreeModel *model = ink_comboboxentry_action_get_model( act ); gchar *current_font = ink_comboboxentry_action_get_active_text( act ); + if (!current_font) { + return; + } // Get an iter to the selected font from the model data // We cant get it from the combo, cause it might not have been created yet @@ -183,11 +186,11 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) while ( valid ) { // Get text from list entry - gchar* text = 0; + gchar* text = NULL; gtk_tree_model_get( model, &iter, 0, &text, -1 ); // Column 0 // Check for match - if( strcmp( current_font, text ) == 0 ){ + if ( text && (strcmp( current_font, text ) == 0) ) { found = true; break; } @@ -199,7 +202,7 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) } // Get the list of styles from the selected font - GList *list=0; + GList *list = NULL; gtk_tree_model_get (model, &iter, 1, &list, -1); Ink_ComboBoxEntry_Action* fontStyleAction = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontStyleAction" ) ); diff --git a/src/widgets/widget-sizes.h b/src/widgets/widget-sizes.h index fe89d4574..87c7ca2e0 100644 --- a/src/widgets/widget-sizes.h +++ b/src/widgets/widget-sizes.h @@ -35,11 +35,6 @@ #define STATUS_LAYER_FONT_SIZE 7700 -#define RULER_WIDTH 12 -#define RULER_HEIGHT 12 -#define RULER_FONT_SIZE 6500 -#define RULER_FONT_VERTICAL_SPACING 1.2 - /* Local Variables: mode:c++ |
