diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-18 18:13:01 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-18 18:13:01 +0000 |
| commit | 0d3d7f676b29f9d9a9cd53f08ced76e6588b856a (patch) | |
| tree | 12a2646048750e49e7edee42046b8aa138207f2c /src | |
| parent | warping into a layer (diff) | |
| parent | Replace sp_style_xxx functions with SPStyle member functions. (diff) | |
| download | inkscape-0d3d7f676b29f9d9a9cd53f08ced76e6588b856a.tar.gz inkscape-0d3d7f676b29f9d9a9cd53f08ced76e6588b856a.zip | |
update to trunk
(bzr r13682.1.22)
Diffstat (limited to 'src')
267 files changed, 3590 insertions, 3597 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1f5fc3dd..617e9dce1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,7 +187,6 @@ set(inkscape_SRC console-output-undo-observer.cpp context-fns.cpp desktop-events.cpp - desktop-handles.cpp desktop-style.cpp desktop.cpp device-manager.cpp @@ -299,7 +298,6 @@ set(inkscape_SRC context-fns.h decimal-round.h desktop-events.h - desktop-handles.h desktop-style.h desktop.h device-manager.h @@ -336,7 +334,6 @@ set(inkscape_SRC icon-size.h id-clash.h # ige-mac-menu.h - inkscape-private.h inkscape-version.h inkscape.h interface.h @@ -518,10 +515,19 @@ set(inkscape_SRC # make executable for INKSCAPE add_executable(inkscape ${main_SRC} ${inkscape_SRC} ${sp_SRC}) +if(UNIX) +# message after building. +add_custom_command( + TARGET inkscape + POST_BUILD MAIN_DEPENDENCY inkscape + COMMAND ${CMAKE_COMMAND} -E echo 'now run: \"make install\" to copy runtime files & scripts to ${CMAKE_INSTALL_PREFIX}' +) +endif() + add_dependencies(inkscape inkscape_version) target_link_libraries(inkscape - # order from automake + # order from automake #sp_LIB nrtype_LIB diff --git a/src/Makefile_insert b/src/Makefile_insert index 107acdf31..b07541109 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -29,7 +29,6 @@ ink_common_sources += \ decimal-round.h \ desktop.cpp desktop.h \ desktop-events.cpp desktop-events.h \ - desktop-handles.cpp desktop-handles.h \ desktop-style.cpp desktop-style.h \ device-manager.cpp device-manager.h \ dir-util.cpp dir-util.h \ @@ -63,7 +62,7 @@ ink_common_sources += \ helper/pixbuf-ops.h \ icon-size.h \ id-clash.cpp id-clash.h \ - inkscape.cpp inkscape.h inkscape-private.h \ + inkscape.cpp inkscape.h \ isinf.h \ knot.cpp knot.h \ knot-enums.h \ diff --git a/src/attributes.cpp b/src/attributes.cpp index d142d1a06..2b04843a7 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -115,7 +115,7 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_SNAP_BBOX_CORNER, "inkscape:bbox-nodes"}, {SP_ATTR_INKSCAPE_SNAP_PAGE_BORDER, "inkscape:snap-page"}, {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"}, - {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"}, + {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"}, // This setting sets the Display units, *not* the units used in SVG {SP_ATTR_UNITS, "units"}, {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"}, /* SPColorProfile */ diff --git a/src/box3d.cpp b/src/box3d.cpp index 3c0cbb675..6412a299f 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -37,7 +37,7 @@ #include "preferences.h" #include "desktop.h" -#include "desktop-handles.h" + #include "macros.h" static void box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box); @@ -401,7 +401,7 @@ box3d_snap (SPBox3D *box, int id, Proj::Pt3 const &pt_proj, Proj::Pt3 const &sta snap_pts[3] = diag2.closest_to (pt); } - gdouble const zoom = inkscape_active_desktop()->current_zoom(); + gdouble const zoom = SP_ACTIVE_DESKTOP->current_zoom(); // determine the distances to all potential snapping points double snap_dists[MAX_POINT_COUNT]; diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index cb72f65dc..c13b9a5d3 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -32,7 +32,7 @@ #include "xml/node.h" #include "document.h" #include "desktop.h" -#include "desktop-handles.h" + #include "document-undo.h" #include "sp-namedview.h" #include "sp-item-group.h" @@ -87,11 +87,11 @@ void SPAvoidRef::setAvoid(char const *value) void SPAvoidRef::handleSettingChange(void) { - SPDesktop *desktop = inkscape_active_desktop(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop == NULL) { return; } - if (sp_desktop_document(desktop) != item->document) { + if (desktop->getDocument() != item->document) { // We don't want to go any further if the active desktop's document // isn't the same as the document that this item is part of. This // case can happen if a new document is loaded from the file chooser @@ -277,7 +277,7 @@ static std::vector<Geom::Point> approxItemWithPoints(SPItem const *item, const G } static Avoid::Polygon avoid_item_poly(SPItem const *item) { - SPDesktop *desktop = inkscape_active_desktop(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; g_assert(desktop != NULL); double spacing = desktop->namedview->connector_spacing; @@ -370,7 +370,7 @@ void init_avoided_shape_geometry(SPDesktop *desktop) { // Don't count this as changes to the document, // it is basically just late initialisation. - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); bool saved = DocumentUndo::getUndoSensitive(document); DocumentUndo::setUndoSensitive(document, false); diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 5d8ea8b9f..5dbe0f8dc 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -24,7 +24,7 @@ #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "ui/dialog-events.h" #include "display/canvas-axonomgrid.h" #include "display/canvas-grid.h" @@ -40,6 +40,7 @@ #include "display/sp-canvas.h" #include "sp-guide.h" #include "sp-namedview.h" +#include "sp-root.h" #include "ui/tools-switch.h" #include "verbs.h" #include "widgets/desktop-widget.h" @@ -217,11 +218,21 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge if ((horiz ? wy : wx) >= 0) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); + + // If root viewBox set, interpret guides in terms of viewBox (90/96) + double newx = event_dt.x(); + double newy = event_dt.y(); + + SPRoot *root = desktop->doc()->getRoot(); + if( root->viewBox_set ) { + newx = newx * root->viewBox.width() / root->width.computed; + newy = newy * root->viewBox.height() / root->height.computed; + } + sp_repr_set_point(repr, "position", Geom::Point( newx, newy )); sp_repr_set_point(repr, "orientation", normal); - sp_repr_set_point(repr, "position", event_dt); desktop->namedview->appendChild(repr); Inkscape::GC::release(repr); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE, _("Create guide")); } desktop->set_coordinate_status(event_dt); @@ -229,7 +240,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge if (!dragged) { // Ruler click (without drag) toggle the guide visibility on and off Inkscape::XML::Node *repr = desktop->namedview->getRepr(); - sp_namedview_toggle_guides(sp_desktop_document(desktop), repr); + sp_namedview_toggle_guides(desktop->getDocument(), repr); } @@ -477,14 +488,14 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) assert(false); break; } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE, _("Move guide")); } else { /* Undo movement of any attached shapes. */ guide->moveto(guide->getPoint(), false); guide->set_normal(guide->getNormal(), false); sp_guide_remove(guide); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE, _("Delete guide")); } moved = false; @@ -505,7 +516,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) if ((event->crossing.state & GDK_SHIFT_MASK) && (drag_type != SP_DRAG_MOVE_ORIGIN)) { GdkCursor *guide_cursor; guide_cursor = gdk_cursor_new (GDK_EXCHANGE); - gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); + gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(desktop->getCanvas())), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) g_object_unref(guide_cursor); #else @@ -514,7 +525,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } else { GdkCursor *guide_cursor; guide_cursor = gdk_cursor_new (GDK_HAND1); - gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); + gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(desktop->getCanvas())), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) g_object_unref(guide_cursor); #else @@ -531,7 +542,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) sp_guideline_set_color(SP_GUIDELINE(item), guide->getColor()); // restore event context's cursor - gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), desktop->event_context->cursor); + gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(desktop->getCanvas())), desktop->event_context->cursor); desktop->guidesMessageContext()->clear(); break; @@ -553,7 +564,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) if (drag_type != SP_DRAG_MOVE_ORIGIN) { GdkCursor *guide_cursor; guide_cursor = gdk_cursor_new (GDK_EXCHANGE); - gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); + gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(desktop->getCanvas())), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) g_object_unref(guide_cursor); #else @@ -574,7 +585,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) case GDK_KEY_Shift_R: GdkCursor *guide_cursor; guide_cursor = gdk_cursor_new (GDK_EXCHANGE); - gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor); + gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(desktop->getCanvas())), guide_cursor); #if GTK_CHECK_VERSION(3,0,0) g_object_unref(guide_cursor); #else diff --git a/src/desktop-handles.cpp b/src/desktop-handles.cpp deleted file mode 100644 index 8fa7ad986..000000000 --- a/src/desktop-handles.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Frontends - * - * Author: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * Copyright (C) 2001-2002 Lauris Kaplinski - * Copyright (C) 2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "display/sp-canvas.h" -#include "display/sp-canvas-item.h" -#include "desktop.h" -#include "desktop-handles.h" - -Inkscape::Selection * -sp_desktop_selection (SPDesktop const * desktop) -{ - g_assert(desktop != NULL); - - return desktop->selection; -} - -SPDocument * -sp_desktop_document (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->doc(); -} - -SPCanvas * -sp_desktop_canvas (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return (SP_CANVAS_ITEM(desktop->main))->canvas; -} - -SPCanvasItem * -sp_desktop_acetate (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->acetate; -} - -SPCanvasGroup * -sp_desktop_main (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->main; -} - -SPCanvasGroup * -sp_desktop_gridgroup (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->gridgroup; -} - -SPCanvasGroup * -sp_desktop_guides (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->guides; -} - -SPCanvasItem * -sp_desktop_drawing (SPDesktop const *desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->drawing; -} - -SPCanvasGroup * -sp_desktop_sketch (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->sketch; -} - -SPCanvasGroup * -sp_desktop_controls (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->controls; -} - -SPCanvasGroup * -sp_desktop_tempgroup (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->tempgroup; -} - -Inkscape::MessageStack * -sp_desktop_message_stack (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->messageStack(); -} - -SPNamedView * -sp_desktop_namedview (SPDesktop const * desktop) -{ - g_return_val_if_fail (desktop != NULL, NULL); - - return desktop->namedview; -} - - diff --git a/src/desktop-handles.h b/src/desktop-handles.h deleted file mode 100644 index 70a8c8b5f..000000000 --- a/src/desktop-handles.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef SEEN_SP_DESKTOP_HANDLES_H -#define SEEN_SP_DESKTOP_HANDLES_H - -/* - * Frontends - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * Copyright (C) 1999-2002 Lauris Kaplinski - * Copyright (C) 2000-2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -class SPDesktop; -class SPDocument; - -namespace Inkscape { -namespace UI { -namespace Tools { - -class ToolBase; - -} -} -} - -class SPNamedView; -struct SPCanvas; -struct SPCanvasGroup; -struct SPCanvasItem; - -namespace Inkscape { - class MessageStack; - class Selection; -} - -#define SP_DESKTOP_ZOOM_MAX 256.0 -#define SP_DESKTOP_ZOOM_MIN 0.01 - -#define SP_COORDINATES_UNDERLINE_NONE (0) -#define SP_COORDINATES_UNDERLINE_X (1 << Geom::X) -#define SP_COORDINATES_UNDERLINE_Y (1 << Geom::Y) - -//ToolBase * sp_desktop_event_context (SPDesktop const * desktop); -Inkscape::Selection * sp_desktop_selection (SPDesktop const * desktop); -SPDocument * sp_desktop_document (SPDesktop const * desktop); -SPCanvas * sp_desktop_canvas (SPDesktop const * desktop); -SPCanvasItem * sp_desktop_acetate (SPDesktop const * desktop); -SPCanvasGroup * sp_desktop_main (SPDesktop const * desktop); -SPCanvasGroup * sp_desktop_gridgroup (SPDesktop const * desktop); -SPCanvasGroup * sp_desktop_guides (SPDesktop const * desktop); -SPCanvasItem *sp_desktop_drawing (SPDesktop const *desktop); -SPCanvasGroup * sp_desktop_sketch (SPDesktop const * desktop); -SPCanvasGroup * sp_desktop_controls (SPDesktop const * desktop); -SPCanvasGroup * sp_desktop_tempgroup (SPDesktop const * desktop); -Inkscape::MessageStack * sp_desktop_message_stack (SPDesktop const * desktop); -SPNamedView * sp_desktop_namedview (SPDesktop const * desktop); - -#endif // SEEN_SP_DESKTOP_HANDLES_H - -/* - 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/desktop-style.cpp b/src/desktop-style.cpp index 30869d87d..ee9fa39ec 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -428,10 +428,9 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) double ret = 12; if (!style_str.empty()) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str.data()); - ret = style->font_size.computed; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str.data()); + ret = style.font_size.computed; } return ret; } @@ -626,7 +625,7 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill paintImpossible = false; paint_res->colorSet = paint->colorSet; - paint_res->currentcolor = paint->currentcolor; + paint_res->paintOrigin = paint->paintOrigin; if (paint_res->set && paint_effectively_set && paint->isPaintserver()) { // copy the server gchar const *string = NULL; // memory leak results if style->get* called inside sp_style_set_to_uri_string. if (isfill) { diff --git a/src/desktop.cpp b/src/desktop.cpp index 74dea3ca1..cdf8f276c 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -37,7 +37,7 @@ #include "color.h" #include "desktop-events.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "device-manager.h" #include "display/canvas-arena.h" @@ -56,7 +56,6 @@ #include "event-log.h" #include "helper/action-context.h" #include "ui/interface.h" -#include "inkscape-private.h" #include "layer-fns.h" #include "layer-manager.h" #include "layer-model.h" @@ -94,28 +93,28 @@ static void _reconstruction_finish(SPDesktop * desktop); static void _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop); SPDesktop::SPDesktop() : - _dlg_mgr( 0 ), - namedview( 0 ), - canvas( 0 ), - layers( 0 ), - selection( 0 ), - event_context( 0 ), - layer_manager( 0 ), - event_log( 0 ), - temporary_item_list( 0 ), - snapindicator( 0 ), - acetate( 0 ), - main( 0 ), - gridgroup( 0 ), - guides( 0 ), - drawing( 0 ), - sketch( 0 ), - controls( 0 ), - tempgroup ( 0 ), - table( 0 ), - page( 0 ), - page_border( 0 ), - current( 0 ), + _dlg_mgr( NULL ), + namedview( NULL ), + canvas( NULL ), + layers( NULL ), + selection( NULL ), + event_context( NULL ), + layer_manager( NULL ), + event_log( NULL ), + temporary_item_list( NULL ), + snapindicator( NULL ), + acetate( NULL ), + main( NULL ), + gridgroup( NULL ), + guides( NULL ), + drawing( NULL ), + sketch( NULL ), + controls( NULL ), + tempgroup ( NULL ), + table( NULL ), + page( NULL ), + page_border( NULL ), + current( NULL ), _focusMode(false), dkey( 0 ), number( 0 ), @@ -124,16 +123,15 @@ SPDesktop::SPDesktop() : waiting_cursor( false ), showing_dialogs ( false ), guides_active( false ), - gr_item( 0 ), + gr_item( NULL ), gr_point_type( POINT_LG_BEGIN ), gr_point_i( 0 ), gr_fill_or_stroke( Inkscape::FOR_FILL ), _reconstruction_old_layer_id(), // an id attribute is not allowed to be the empty string _display_mode(Inkscape::RENDERMODE_NORMAL), _display_color_mode(Inkscape::COLORMODE_NORMAL), - _widget( 0 ), - _inkscape( 0 ), - _guides_message_context( 0 ), + _widget( NULL ), + _guides_message_context( NULL ), _active( false ), _w2d(), _d2w(), @@ -299,7 +297,6 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid // ? // sp_active_desktop_set (desktop); - _inkscape = INKSCAPE; _activate_connection = _activate_signal.connect( sigc::bind( @@ -385,10 +382,6 @@ void SPDesktop::destroy() layer_manager = NULL; } - if (_inkscape) { - _inkscape = NULL; - } - if (drawing) { doc()->getRoot()->invoke_hide(dkey); g_object_unref(drawing); @@ -509,7 +502,7 @@ void SPDesktop::_setDisplayMode(Inkscape::RenderMode mode) { canvas->rendermode = mode; _display_mode = mode; redrawDesktop(); - _widget->setTitle( sp_desktop_document(this)->getName() ); + _widget->setTitle( this->getDocument()->getName() ); } void SPDesktop::_setDisplayColorMode(Inkscape::ColorMode mode) { // reload grayscale matrix from prefs @@ -530,7 +523,7 @@ void SPDesktop::_setDisplayColorMode(Inkscape::ColorMode mode) { canvas->colorrendermode = mode; _display_color_mode = mode; redrawDesktop(); - _widget->setTitle( sp_desktop_document(this)->getName() ); + _widget->setTitle( this->getDocument()->getName() ); } void SPDesktop::displayModeToggle() { @@ -1431,7 +1424,7 @@ void SPDesktop::emitToolSubselectionChanged(gpointer data) { _tool_subselection_changed.emit(data); - inkscape_subselection_changed (this); + INKSCAPE.subselection_changed (this); } void SPDesktop::updateNow() @@ -1453,7 +1446,7 @@ void SPDesktop::disableInteraction() void SPDesktop::setWaitingCursor() { GdkCursor *waiting = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(sp_desktop_canvas(this))), waiting); + gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(getCanvas())), waiting); #if GTK_CHECK_VERSION(3,0,0) g_object_unref(waiting); #else @@ -1488,7 +1481,7 @@ void SPDesktop::toggleGrids() } } else { //there is no grid present at the moment. add a rectangular grid and make it visible - namedview->writeNewGrid(sp_desktop_document(this), Inkscape::GRID_RECTANGULAR); + namedview->writeNewGrid(this->getDocument(), Inkscape::GRID_RECTANGULAR); showGrids(true); } } diff --git a/src/desktop.h b/src/desktop.h index 509f8a396..a0b9592d0 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -103,6 +103,9 @@ namespace Inkscape { } } +#define SP_DESKTOP_ZOOM_MAX 256.0 +#define SP_DESKTOP_ZOOM_MIN 0.01 + /** * SPDesktop is a subclass of View, implementing an editable document * canvas. It is extensively used by many UI controls that need certain @@ -424,7 +427,6 @@ public: private: Inkscape::UI::View::EditWidgetInterface *_widget; - InkscapeApplication *_inkscape; Inkscape::MessageContext *_guides_message_context; bool _active; Geom::Affine _w2d; diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 592c962a6..05ba71a49 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -36,7 +36,7 @@ #include "ui/widget/registered-widget.h" #include "desktop.h" -#include "desktop-handles.h" + #include "display/cairo-utils.h" #include "display/canvas-grid.h" #include "display/sp-canvas-util.h" @@ -46,6 +46,7 @@ #include "preferences.h" #include "sp-namedview.h" #include "sp-object.h" +#include "sp-root.h" #include "svg/svg-color.h" #include "2geom/line.h" #include "2geom/angle.h" @@ -213,22 +214,53 @@ static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) void CanvasAxonomGrid::readRepr() { + SPRoot *root = doc->getRoot(); + double scale_x = 1.0; + double scale_y = 1.0; + if( root->viewBox_set ) { + scale_x = root->width.computed / root->viewBox.width(); + scale_y = root->height.computed / root->viewBox.height(); + } + gchar const *value; + if ( (value = repr->attribute("originx")) ) { + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - origin[Geom::X] = q.value("px"); + + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + origin[Geom::X] = q.value("px"); + } else { + // Grid in 'user units' + origin[Geom::X] = q.quantity * scale_x; + } } + if ( (value = repr->attribute("originy")) ) { + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - origin[Geom::Y] = q.value("px"); + + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + origin[Geom::Y] = q.value("px"); + } else { + // Grid in 'user units' + origin[Geom::Y] = q.quantity * scale_y; + } } if ( (value = repr->attribute("spacingy")) ) { + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - lengthy = q.value("px"); + + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + lengthy = q.value("px"); + } else { + // Grid in 'user units' + lengthy = q.quantity * scale_y; // We do not handle scale_x != scale_y + } if (lengthy < 0.0500) lengthy = 0.0500; } @@ -281,6 +313,10 @@ CanvasAxonomGrid::readRepr() snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0); } + if ( (value = repr->attribute("units")) ) { + gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu + } + for (GSList *l = canvasitems; l != NULL; l = l->next) { sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); } @@ -316,11 +352,14 @@ _wr.setUpdating (true); Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu( _("Grid _units:"), "units", _wr, repr, doc) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) ); + _("_Origin X:"), _("X coordinate of grid origin"), "originx", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) ); + _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("Spacing _Y:"), _("Base length of z-axis"), "spacingy", *_rumg, _wr, repr, doc) ); + _("Spacing _Y:"), _("Base length of z-axis"), "spacingy", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) ); Inkscape::UI::Widget::RegisteredScalar *_rsu_ax = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( _("Angle X:"), _("Angle of x-axis"), "gridanglex", _wr, repr, doc ) ); Inkscape::UI::Widget::RegisteredScalar *_rsu_az = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 2eeaa7006..1a284b46e 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -36,7 +36,7 @@ #include "desktop.h" #include "sp-canvas-util.h" #include "util/mathfns.h" -#include "desktop-handles.h" + #include "display/cairo-utils.h" #include "display/canvas-axonomgrid.h" #include "display/canvas-grid.h" @@ -47,6 +47,7 @@ #include "preferences.h" #include "sp-namedview.h" #include "sp-object.h" +#include "sp-root.h" #include "svg/svg-color.h" #include "svg/stringstream.h" #include "util/mathfns.h" @@ -284,12 +285,12 @@ CanvasGrid::createCanvasItem(SPDesktop * desktop) // check if there is already a canvasitem on this desktop linking to this grid for (GSList *l = canvasitems; l != NULL; l = l->next) { - if ( sp_desktop_gridgroup(desktop) == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) { + if ( desktop->getGridGroup() == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) { return NULL; } } - GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(sp_desktop_gridgroup(desktop), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) ); + GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(desktop->getGridGroup(), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) ); item->grid = this; sp_canvas_item_show(SP_CANVAS_ITEM(item)); @@ -367,17 +368,21 @@ bool CanvasGrid::isEnabled() const return snapper->getEnabled(); } +// Used to shift origin when page size changed to fit drawing. void CanvasGrid::setOrigin(Geom::Point const &origin_px) { - Inkscape::SVGOStringStream os_x, os_y; - gdouble val; + SPRoot *root = doc->getRoot(); + double scale_x = 1.0; + double scale_y = 1.0; + if( root->viewBox_set ) { + scale_x = root->viewBox.width() / root->width.computed; + scale_y = root->viewBox.height() / root->height.computed; + } - val = origin_px[Geom::X]; - val = Inkscape::Util::Quantity::convert(val, "px", gridunit); - os_x << val << gridunit->abbr; - val = origin_px[Geom::Y]; - val = Inkscape::Util::Quantity::convert(val, "px", gridunit); - os_y << val << gridunit->abbr; + // Write out in 'user-units' + Inkscape::SVGOStringStream os_x, os_y; + os_x << origin_px[Geom::X] * scale_x; + os_y << origin_px[Geom::Y] * scale_y; repr->setAttribute("originx", os_x.str().c_str()); repr->setAttribute("originy", os_y.str().c_str()); } @@ -504,33 +509,6 @@ static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) return TRUE; } -/** If the passed scalar is invalid (<=0), then set the widget and the scalar - to use the given old value. - - @param oldVal Old value to use if the new one is invalid. - @param pTarget The scalar to validate. - @param widget Widget associated with the scalar. -*/ -static void validateScalar(double oldVal, - double* pTarget) -{ - // Avoid nullness. - if ( pTarget == NULL ) - return; - - // Invalid new value? - if ( *pTarget <= 0 ) { - // If the old value is somehow invalid as well, then default to 1. - if ( oldVal <= 0 ) - oldVal = 1; - - // Reset the scalar and associated widget to the old value. - *pTarget = oldVal; - } //if - -} //validateScalar - - /** If the passed int is invalid (<=0), then set the widget and the int to use the given old value. @@ -560,34 +538,78 @@ static void validateInt(gint oldVal, void CanvasXYGrid::readRepr() { + SPRoot *root = doc->getRoot(); + double scale_x = 1.0; + double scale_y = 1.0; + if( root->viewBox_set ) { + scale_x = root->width.computed / root->viewBox.width(); + scale_y = root->height.computed / root->viewBox.height(); + } + gchar const *value; + if ( (value = repr->attribute("originx")) ) { + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - origin[Geom::X] = q.value("px"); + + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + origin[Geom::X] = q.value("px"); + } else { + // Grid in 'user units' + origin[Geom::X] = q.quantity * scale_x; + } } if ( (value = repr->attribute("originy")) ) { + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - origin[Geom::Y] = q.value("px"); + + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + origin[Geom::Y] = q.value("px"); + } else { + // Grid in 'user units' + origin[Geom::Y] = q.quantity * scale_y; + } } if ( (value = repr->attribute("spacingx")) ) { - double oldVal = spacing[Geom::X]; + + // Ensure a valid default value + if( spacing[Geom::X] <= 0.0 ) + spacing[Geom::X] = 1.0; + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - spacing[Geom::X] = q.quantity; - validateScalar(oldVal, &spacing[Geom::X]); - spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, "px"); + // Ensure a valid new value + if( q.quantity > 0 ) { + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + spacing[Geom::X] = q.value("px"); + } else { + // Grid in 'user units' + spacing[Geom::X] = q.quantity * scale_x; + } + } } + if ( (value = repr->attribute("spacingy")) ) { - double oldVal = spacing[Geom::Y]; + + // Ensure a valid default value + if( spacing[Geom::Y] <= 0.0 ) + spacing[Geom::Y] = 1.0; + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); - gridunit = q.unit; - spacing[Geom::Y] = q.quantity; - validateScalar(oldVal, &spacing[Geom::Y]); - spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, "px"); + // Ensure a valid new value + if( q.quantity > 0 ) { + if( q.unit->type == UNIT_TYPE_LINEAR ) { + // Legacy grid not in 'user units' + spacing[Geom::Y] = q.value("px"); + } else { + // Grid in 'user units' + spacing[Geom::Y] = q.quantity * scale_y; + } + } } if ( (value = repr->attribute("color")) ) { @@ -629,6 +651,10 @@ CanvasXYGrid::readRepr() snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0); } + if ( (value = repr->attribute("units")) ) { + gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu + } + for (GSList *l = canvasitems; l != NULL; l = l->next) { sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); } @@ -666,13 +692,17 @@ CanvasXYGrid::newSpecificWidget() Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu( _("Grid _units:"), "units", _wr, repr, doc) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) ); + _("_Origin X:"), _("X coordinate of grid origin"), "originx", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) ); + _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx", *_rumg, _wr, repr, doc) ); + _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) ); Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( - _("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", *_rumg, _wr, repr, doc) ); + _("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", + *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) ); Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( diff --git a/src/display/drawing-group.cpp b/src/display/drawing-group.cpp index bce89d70e..1a9cbfdcc 100644 --- a/src/display/drawing-group.cpp +++ b/src/display/drawing-group.cpp @@ -21,14 +21,11 @@ namespace Inkscape { DrawingGroup::DrawingGroup(Drawing &drawing) : DrawingItem(drawing) - , _style(NULL) , _child_transform(NULL) {} DrawingGroup::~DrawingGroup() { - if (_style) - sp_style_unref(_style); delete _child_transform; // delete NULL; is safe } @@ -42,12 +39,6 @@ DrawingGroup::setPickChildren(bool p) _pick_children = p; } -void -DrawingGroup::setStyle(SPStyle *style) -{ - _setStyleCommon(_style, style); -} - /** * Set additional transform for the group. * This is applied after the normal transform and mainly useful for diff --git a/src/display/drawing-group.h b/src/display/drawing-group.h index ab1f9895d..0c985b43f 100644 --- a/src/display/drawing-group.h +++ b/src/display/drawing-group.h @@ -14,8 +14,6 @@ #include "display/drawing-item.h" -class SPStyle; - namespace Inkscape { class DrawingGroup @@ -28,7 +26,6 @@ public: bool pickChildren() { return _pick_children; } void setPickChildren(bool p); - void setStyle(SPStyle *style); void setChildTransform(Geom::Affine const &new_trans); protected: @@ -40,7 +37,6 @@ protected: virtual DrawingItem *_pickItem(Geom::Point const &p, double delta, unsigned flags); virtual bool _canClip(); - SPStyle *_style; Geom::Affine *_child_transform; }; diff --git a/src/display/drawing-image.cpp b/src/display/drawing-image.cpp index e56f3e58b..8fe337959 100644 --- a/src/display/drawing-image.cpp +++ b/src/display/drawing-image.cpp @@ -24,15 +24,10 @@ namespace Inkscape { DrawingImage::DrawingImage(Drawing &drawing) : DrawingItem(drawing) , _pixbuf(NULL) - , _style(NULL) {} DrawingImage::~DrawingImage() { - if (_style) { - sp_style_unref(_style); - } - // _pixbuf is owned by SPImage - do not delete it } @@ -45,12 +40,6 @@ DrawingImage::setPixbuf(Inkscape::Pixbuf *pb) } void -DrawingImage::setStyle(SPStyle *style) -{ - _setStyleCommon(_style, style); -} - -void DrawingImage::setScale(double sx, double sy) { _scale = Geom::Scale(sx, sy); diff --git a/src/display/drawing-image.h b/src/display/drawing-image.h index 64e4517b0..7511768c9 100644 --- a/src/display/drawing-image.h +++ b/src/display/drawing-image.h @@ -29,7 +29,6 @@ public: ~DrawingImage(); void setPixbuf(Inkscape::Pixbuf *pb); - void setStyle(SPStyle *style); void setScale(double sx, double sy); void setOrigin(Geom::Point const &o); void setClipbox(Geom::Rect const &box); @@ -43,7 +42,6 @@ protected: virtual DrawingItem *_pickItem(Geom::Point const &p, double delta, unsigned flags); Inkscape::Pixbuf *_pixbuf; - SPStyle *_style; // TODO: the following three should probably be merged into a new Geom::Viewbox object Geom::Rect _clipbox; ///< for preserveAspectRatio diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 8ed74b550..89ca66dc4 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -109,6 +109,8 @@ DrawingItem::DrawingItem(Drawing &drawing) : _drawing(drawing) , _parent(NULL) , _key(0) + , _style(NULL) + , _context_style(NULL) , _opacity(1.0) , _transform(NULL) , _clip(NULL) @@ -188,6 +190,8 @@ DrawingItem::~DrawingItem() delete _clip; delete _mask; delete _filter; + if(_style) + sp_style_unref(_style); } DrawingItem * @@ -351,6 +355,72 @@ DrawingItem::setCached(bool cached, bool persistent) } } +/** + * Process information related to the new style. + * + * Note: _style is not used by DrawingGlyphs which uses its parent style. + */ +void +DrawingItem::setStyle(SPStyle *style, SPStyle *context_style) +{ + // std::cout << "DrawingItem::setStyle: " << name() << " " << style + // << " " << context_style << std::endl; + + if( style != _style ) { + if (style) sp_style_ref(style); + if (_style) sp_style_unref(_style); + _style = style; + } + + if (style && style->filter.set && style->getFilter()) { + if (!_filter) { + int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter())); + _filter = new Inkscape::Filters::Filter(primitives); + } + sp_filter_build_renderer(SP_FILTER(style->getFilter()), _filter); + } else { + // no filter set for this group + delete _filter; + _filter = NULL; + } + + if (style && style->enable_background.set) { + if (style->enable_background.value == SP_CSS_BACKGROUND_NEW && !_background_new) { + _background_new = true; + _markForUpdate(STATE_BACKGROUND, true); + } else if (style->enable_background.value == SP_CSS_BACKGROUND_ACCUMULATE && _background_new) { + _background_new = false; + _markForUpdate(STATE_BACKGROUND, true); + } + } + + if (context_style != NULL) { + _context_style = context_style; + } else if (_parent != NULL) { + _context_style = _parent->_context_style; + } + + _markForUpdate(STATE_ALL, false); +} + + +/** + * Recursively update children style. + * The purpose of this call is to update fill and stroke for markers that have elements with + * fill/stroke property values of 'context-fill' or 'context-stroke'. Marker styling is not + * updated like other 'clones' as marker instances are not included the SP object tree. + * Note: this is a virtual function. + */ +void +DrawingItem::setChildrenStyle(SPStyle* context_style) +{ + _context_style = context_style; + for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { + i->setChildrenStyle( context_style ); + } +} + + void DrawingItem::setClip(DrawingItem *item) { @@ -908,6 +978,39 @@ DrawingItem::pick(Geom::Point const &p, double delta, unsigned flags) return NULL; } +// For debugging +Glib::ustring +DrawingItem::name() +{ + SPObject *object = static_cast<SPObject *>(_user_data); + if (object) { + if(object->getId()) + return object->getId(); + else + return "No object id"; + } else { + return "No associated object"; + } +} + +// For debugging: Print drawing tree structure. +void +DrawingItem::recursivePrintTree( unsigned level ) +{ + if (level == 0) { + std::cout << "Display Item Tree" << std::endl; + } + std::cout << "DI: "; + for (unsigned i = 0; i < level; ++i) { + std::cout << " "; + } + std::cout << name() << std::endl; + for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { + i->recursivePrintTree( level+1 ); + } +} + + /** * Marks the current visual bounding box of the item for redrawing. * This is called whenever the object changes its visible appearance. @@ -998,48 +1101,6 @@ DrawingItem::_markForUpdate(unsigned flags, bool propagate) } /** - * Process information related to the new style. - * - * This function is something of a hack to avoid creating an extra class in the hierarchy - * which would differ from DrawingItem only by having a _style member. - * This is mainly to the benefit of DrawingGlyphs, which use the style of their parent. - * This should probably be refactored some day, possibly by creating the relevant class - * or creating a more complex data model in DrawingText and removing DrawingGlyphs, - * which would cause every item to have a style. - */ -void -DrawingItem::_setStyleCommon(SPStyle *&_style, SPStyle *style) -{ - if (style) sp_style_ref(style); - if (_style) sp_style_unref(_style); - _style = style; - - if (style && style->filter.set && style->getFilter()) { - if (!_filter) { - int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter())); - _filter = new Inkscape::Filters::Filter(primitives); - } - sp_filter_build_renderer(SP_FILTER(style->getFilter()), _filter); - } else { - // no filter set for this group - delete _filter; - _filter = NULL; - } - - if (style && style->enable_background.set) { - if (style->enable_background.value == SP_CSS_BACKGROUND_NEW && !_background_new) { - _background_new = true; - _markForUpdate(STATE_BACKGROUND, true); - } else if (style->enable_background.value == SP_CSS_BACKGROUND_ACCUMULATE && _background_new) { - _background_new = false; - _markForUpdate(STATE_BACKGROUND, true); - } - } - - _markForUpdate(STATE_ALL, false); -} - -/** * Compute the caching score. * * Higher scores mean the item is more aggresively prioritized for automatic diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h index 9b399e6e3..3c593ceaa 100644 --- a/src/display/drawing-item.h +++ b/src/display/drawing-item.h @@ -20,6 +20,10 @@ #include <exception> #include <list> +namespace Glib { +class ustring; +} + class SPStyle; namespace Inkscape { @@ -108,6 +112,8 @@ public: bool cached() const { return _cached; } void setCached(bool c, bool persistent = false); + virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL); + virtual void setChildrenStyle(SPStyle *context_style); void setOpacity(float opacity); void setAntialiasing(bool a); void setIsolation(unsigned isolation); // CSS Compositing and Blending @@ -131,6 +137,9 @@ public: void clip(DrawingContext &dc, Geom::IntRect const &area); DrawingItem *pick(Geom::Point const &p, double delta, unsigned flags = 0); + virtual Glib::ustring name(); // For debugging + void recursivePrintTree(unsigned level = 0); // For debugging + protected: enum ChildType { CHILD_ORPHAN = 0, // no parent - implies _parent == NULL @@ -149,7 +158,6 @@ protected: void _markForUpdate(unsigned state, bool propagate); void _markForRendering(); void _invalidateFilterBackground(Geom::IntRect const &area); - void _setStyleCommon(SPStyle *&_style, SPStyle *style); double _cacheScore(); Geom::OptIntRect _cacheRect(); virtual unsigned _updateItem(Geom::IntRect const &/*area*/, UpdateContext const &/*ctx*/, @@ -176,6 +184,9 @@ protected: unsigned _key; ///< Some SPItems can have more than one DrawingItem; /// this value is a hack used to distinguish between them + SPStyle *_style; // Not used by DrawingGlyphs + SPStyle *_context_style; // Used for 'context-fill', 'context-stroke' + float _opacity; Geom::Affine *_transform; ///< Incremental transform from parent to this item's coords diff --git a/src/display/drawing-pattern.h b/src/display/drawing-pattern.h index 7483ba067..dc1f93ed1 100644 --- a/src/display/drawing-pattern.h +++ b/src/display/drawing-pattern.h @@ -15,7 +15,6 @@ #include "display/drawing-group.h" typedef struct _cairo_pattern cairo_pattern_t; -class SPStyle; namespace Inkscape { diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp index 66160638f..63efb3c0d 100644 --- a/src/display/drawing-shape.cpp +++ b/src/display/drawing-shape.cpp @@ -34,15 +34,12 @@ namespace Inkscape { DrawingShape::DrawingShape(Drawing &drawing) : DrawingItem(drawing) , _curve(NULL) - , _style(NULL) , _last_pick(NULL) , _repick_after(0) {} DrawingShape::~DrawingShape() { - if (_style) - sp_style_unref(_style); if (_curve) _curve->unref(); } @@ -65,10 +62,17 @@ DrawingShape::setPath(SPCurve *curve) } void -DrawingShape::setStyle(SPStyle *style) +DrawingShape::setStyle(SPStyle *style, SPStyle *context_style) { - _setStyleCommon(_style, style); - _nrstyle.set(style); + DrawingItem::setStyle(style, context_style); // Must be first + _nrstyle.set(_style, _context_style); +} + +void +DrawingShape::setChildrenStyle(SPStyle* context_style) +{ + DrawingItem::setChildrenStyle( context_style ); + _nrstyle.set(_style, _context_style); } unsigned @@ -145,7 +149,6 @@ DrawingShape::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, u _bbox.unionWith(i->geometricBounds()); } } - return STATE_ALL; } diff --git a/src/display/drawing-shape.h b/src/display/drawing-shape.h index 9d93a642f..1cdbc636e 100644 --- a/src/display/drawing-shape.h +++ b/src/display/drawing-shape.h @@ -28,7 +28,8 @@ public: ~DrawingShape(); void setPath(SPCurve *curve); - void setStyle(SPStyle *style); + virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL); + virtual void setChildrenStyle(SPStyle *context_style); protected: virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx, @@ -45,7 +46,6 @@ protected: DrawingItem *stop_at); SPCurve *_curve; - SPStyle *_style; NRStyle _nrstyle; DrawingItem *_last_pick; diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index afe661b2e..e20a7ff2a 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -55,6 +55,13 @@ DrawingGlyphs::setGlyph(font_instance *font, int glyph, Geom::Affine const &tran _markForUpdate(STATE_ALL, false); } +void +DrawingGlyphs::setStyle(SPStyle * /*style*/, SPStyle * /*context_style*/) +{ + std::cerr << "DrawingGlyphs: Use parent style" << std::endl; +} + + unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext const &ctx, unsigned /*flags*/, unsigned /*reset*/) { DrawingText *ggroup = dynamic_cast<DrawingText *>(_parent); @@ -216,10 +223,17 @@ DrawingText::addComponent(font_instance *font, int glyph, Geom::Affine const &tr } void -DrawingText::setStyle(SPStyle *style) +DrawingText::setStyle(SPStyle *style, SPStyle *context_style) +{ + DrawingGroup::setStyle(style, context_style); // Must be first + _nrstyle.set(_style, _context_style); +} + +void +DrawingText::setChildrenStyle(SPStyle* context_style) { - _nrstyle.set(style); - DrawingGroup::setStyle(style); + DrawingGroup::setChildrenStyle( context_style ); + _nrstyle.set(_style, _context_style); } unsigned diff --git a/src/display/drawing-text.h b/src/display/drawing-text.h index 4453a3db4..3d248df9b 100644 --- a/src/display/drawing-text.h +++ b/src/display/drawing-text.h @@ -28,6 +28,7 @@ public: ~DrawingGlyphs(); void setGlyph(font_instance *font, int glyph, Geom::Affine const &trans); + virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL); // Not to be used protected: unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx, @@ -56,8 +57,8 @@ public: void clear(); bool addComponent(font_instance *font, int glyph, Geom::Affine const &trans, float width, float ascent, float descent, float phase_length); - void setStyle(SPStyle *style); - + virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL); + virtual void setChildrenStyle(SPStyle *context_style); protected: virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx, diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp index b065ac445..c8b569036 100644 --- a/src/display/nr-filter-primitive.cpp +++ b/src/display/nr-filter-primitive.cpp @@ -17,7 +17,7 @@ #include "inkscape.h" #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "sp-root.h" #include "style.h" @@ -171,9 +171,11 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) void FilterPrimitive::setStyle(SPStyle *style) { - if (style) sp_style_ref(style); - if (_style) sp_style_unref(_style); - _style = style; + if( style != _style ) { + if (style) sp_style_ref(style); + if (_style) sp_style_unref(_style); + _style = style; + } } diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 96d16bf06..1740785e2 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -93,24 +93,47 @@ NRStyle::~NRStyle() text_decoration_stroke.clear(); } -void NRStyle::set(SPStyle *style) +void NRStyle::set(SPStyle *style, SPStyle *context_style) { - if ( style->fill.isPaintserver() ) { + // Handle 'context-fill' and 'context-stroke': Work in progress + const SPIPaint *style_fill = &(style->fill); + if( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + if( context_style != NULL ) { + style_fill = &(context_style->fill); + } else { + // A marker in the defs section will result in ending up here. + //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + } + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + if( context_style != NULL ) { + style_fill = &(context_style->stroke); + } else { + //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + } + } + + if ( style_fill->isPaintserver() ) { SPPaintServer* server = style->getFillPaintServer(); if ( server && server->isValid() ) { fill.set(server); - } else if ( style->fill.colorSet ) { - fill.set(style->fill.value.color); + } else if ( style_fill->colorSet ) { + fill.set(style_fill->value.color); } else { fill.clear(); } - } else if ( style->fill.isColor() ) { - fill.set(style->fill.value.color); - } else if ( style->fill.isNone() ) { + } else if ( style_fill->isColor() ) { + fill.set(style_fill->value.color); + } else if ( style_fill->isNone() ) { fill.clear(); + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + // A marker in the defs section will result in ending up here. + //std::cerr << "NRStyle::set: fill: context-fill: Double" << std::endl; + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + //std::cerr << "NRStyle::set: fill: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } + fill.opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); switch (style->fill_rule.computed) { @@ -124,22 +147,42 @@ void NRStyle::set(SPStyle *style) g_assert_not_reached(); } - if ( style->stroke.isPaintserver() ) { + const SPIPaint *style_stroke = &(style->stroke); + if( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + if( context_style != NULL ) { + style_stroke = &(context_style->fill); + } else { + //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + } + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + if( context_style != NULL ) { + style_stroke = &(context_style->stroke); + } else { + //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + } + } + + if ( style_stroke->isPaintserver() ) { SPPaintServer* server = style->getStrokePaintServer(); if ( server && server->isValid() ) { stroke.set(server); - } else if ( style->stroke.isColor() ) { - stroke.set(style->stroke.colorSet); + } else if ( style_stroke->isColor() ) { + stroke.set(style_stroke->colorSet); } else { stroke.clear(); } - } else if ( style->stroke.isColor() ) { - stroke.set(style->stroke.value.color); - } else if ( style->stroke.isNone() ) { + } else if ( style_stroke->isColor() ) { + stroke.set(style_stroke->value.color); + } else if ( style_stroke->isNone() ) { stroke.clear(); + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + //std::cerr << "NRStyle::set: stroke: context-fill: Double" << std::endl; + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + //std::cerr << "NRStyle::set: stroke: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } + stroke.opacity = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); stroke_width = style->stroke_width.computed; switch (style->stroke_linecap.computed) { @@ -266,7 +309,7 @@ void NRStyle::set(SPStyle *style) } else if ( style_td->fill.isNone() ) { text_decoration_fill.clear(); } else { - g_assert_not_reached(); + //g_assert_not_reached(); } if ( style_td->stroke.isPaintserver() ) { @@ -276,7 +319,7 @@ void NRStyle::set(SPStyle *style) } else if ( style_td->stroke.isNone() ) { text_decoration_stroke.clear(); } else { - g_assert_not_reached(); + //g_assert_not_reached(); } } @@ -310,13 +353,16 @@ bool NRStyle::prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &pai fill_pattern = pattern->renderPattern(fill.opacity); } else { fill_pattern = fill.server->pattern_new(dc.raw(), paintbox, fill.opacity); - } break; + } + break; case PAINT_COLOR: { SPColor const &c = fill.color; fill_pattern = cairo_pattern_create_rgba( c.v.c[0], c.v.c[1], c.v.c[2], fill.opacity); - } break; - default: break; + } + break; + default: + break; } } if (!fill_pattern) return false; diff --git a/src/display/nr-style.h b/src/display/nr-style.h index f324fdb56..5f78795d3 100644 --- a/src/display/nr-style.h +++ b/src/display/nr-style.h @@ -1,6 +1,7 @@ /** * @file * Style information for rendering. + * Only used by classes DrawingShape and DrawingText *//* * Authors: * Krzysztof KosiÅ„ski <tweenk.pl@gmail.com> @@ -28,7 +29,7 @@ struct NRStyle { NRStyle(); ~NRStyle(); - void set(SPStyle *); + void set(SPStyle *style, SPStyle *context_style = NULL); bool prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern); bool prepareStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern); bool prepareTextDecorationFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern); diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index 2632d69db..bcce81f0b 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -14,7 +14,7 @@ #include "display/snap-indicator.h" #include "desktop.h" -#include "desktop-handles.h" + #include "display/sodipodi-ctrl.h" #include "display/sodipodi-ctrlrect.h" #include "display/canvas-text.h" @@ -246,7 +246,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap // Display the snap indicator (i.e. the cross) SPCanvasItem * canvasitem = NULL; - canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop), + canvasitem = sp_canvas_item_new(_desktop->getTempGroup(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 10.0, @@ -280,7 +280,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap tooltip_pos += _desktop->w2d(Geom::Point(0, -2*fontsize)); } - SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, tooltip_pos, tooltip_str); + SPCanvasItem *canvas_tooltip = sp_canvastext_new(_desktop->getTempGroup(), _desktop, tooltip_pos, tooltip_str); sp_canvastext_set_fontsize(SP_CANVASTEXT(canvas_tooltip), fontsize); SP_CANVASTEXT(canvas_tooltip)->rgba = 0xffffffff; SP_CANVASTEXT(canvas_tooltip)->outline = false; @@ -299,7 +299,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap // Display the bounding box, if we snapped to one Geom::OptRect const bbox = p.getTargetBBox(); if (bbox) { - SPCanvasItem* box = sp_canvas_item_new(sp_desktop_tempgroup (_desktop), + SPCanvasItem* box = sp_canvas_item_new(_desktop->getTempGroup(), SP_TYPE_CTRLRECT, NULL); @@ -348,7 +348,7 @@ SnapIndicator::set_new_snapsource(Inkscape::SnapCandidatePoint const &p) bool value = prefs->getBool("/options/snapindicator/value", true); if (value) { - SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop), + SPCanvasItem * canvasitem = sp_canvas_item_new( _desktop->getTempGroup(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 6.0, @@ -367,7 +367,7 @@ void SnapIndicator::set_new_debugging_point(Geom::Point const &p) { g_assert(_desktop != NULL); - SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop), + SPCanvasItem * canvasitem = sp_canvas_item_new( _desktop->getTempGroup(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 10.0, diff --git a/src/document-private.h b/src/document-private.h index 8e28b288b..a5033b3c2 100644 --- a/src/document-private.h +++ b/src/document-private.h @@ -75,6 +75,8 @@ struct SPDocumentPrivate { Inkscape::ConsoleOutputUndoObserver console_output_undo_observer; bool seeking; + sigc::connection selChangeConnection; + sigc::connection desktopActivatedConnection; }; #endif // SEEN_SP_DOCUMENT_PRIVATE_H diff --git a/src/document-undo.cpp b/src/document-undo.cpp index 15d5d2c70..d4015bafb 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -99,9 +99,8 @@ void Inkscape::DocumentUndo::done(SPDocument *doc, const unsigned int event_type maybeDone(doc, NULL, event_type, event_description); } -void Inkscape::DocumentUndo::resetKey( InkscapeApplication * /*inkscape*/, SPDesktop * /*desktop*/, GObject *base ) +void Inkscape::DocumentUndo::resetKey( SPDocument *doc ) { - SPDocument *doc = reinterpret_cast<SPDocument *>(base); doc->actionkey.clear(); } @@ -259,7 +258,7 @@ gboolean Inkscape::DocumentUndo::undo(SPDocument *doc) doc->priv->seeking = false; if (ret) - inkscape_external_change(); + INKSCAPE.external_change(); return ret; } @@ -304,7 +303,7 @@ gboolean Inkscape::DocumentUndo::redo(SPDocument *doc) doc->priv->seeking = false; if (ret) - inkscape_external_change(); + INKSCAPE.external_change(); return ret; } diff --git a/src/document-undo.h b/src/document-undo.h index 17b3de252..85b44d562 100644 --- a/src/document-undo.h +++ b/src/document-undo.h @@ -41,7 +41,7 @@ public: static void maybeDone(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring const &event_description); - static void resetKey(InkscapeApplication *inkscape, SPDesktop *desktop, GObject *base); + static void resetKey(SPDocument *doc); static void cancel(SPDocument *document); diff --git a/src/document.cpp b/src/document.cpp index f5269eab3..c7d14727a 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -50,7 +50,7 @@ #include "document-private.h" #include "document-undo.h" #include "id-clash.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "inkscape-version.h" #include "libavoid/router.h" #include "persp3d.h" @@ -154,6 +154,14 @@ SPDocument::~SPDocument() { router = NULL; } + if (oldSignalsConnected) { + priv->selChangeConnection.disconnect(); + priv->desktopActivatedConnection.disconnect(); + } else { + _selection_changed_connection.disconnect(); + _desktop_activated_connection.disconnect(); + } + if (priv) { if (priv->partial) { sp_repr_free_log(priv->partial); @@ -208,17 +216,8 @@ SPDocument::~SPDocument() { rerouting_handler_id = 0; } - if (oldSignalsConnected) { - g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE), - reinterpret_cast<gpointer>(DocumentUndo::resetKey), - static_cast<gpointer>(this)); - } else { - _selection_changed_connection.disconnect(); - _desktop_activated_connection.disconnect(); - } - if (keepalive) { - inkscape_unref(); + inkscape_unref(INKSCAPE); keepalive = FALSE; } @@ -447,7 +446,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, rdf_set_defaults( document ); if (keepalive) { - inkscape_ref(); + inkscape_ref(INKSCAPE); } // Check if the document already has a perspective (e.g., when opening an existing @@ -462,10 +461,14 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced - g_signal_connect(G_OBJECT(INKSCAPE), "change_selection", - G_CALLBACK(DocumentUndo::resetKey), document); - g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", - G_CALLBACK(DocumentUndo::resetKey), document); + document->priv->selChangeConnection = INKSCAPE.signal_selection_changed.connect( + sigc::hide(sigc::bind( + sigc::ptr_fun(&DocumentUndo::resetKey), document) + )); + document->priv->desktopActivatedConnection = INKSCAPE.signal_activate_desktop.connect( + sigc::hide(sigc::bind( + sigc::ptr_fun(&DocumentUndo::resetKey), document) + )); document->oldSignalsConnected = true; return document; @@ -593,10 +596,18 @@ SPDocument *SPDocument::doUnref() } /// guaranteed not to return nullptr -Inkscape::Util::Unit const* SPDocument::getDefaultUnit() const +Inkscape::Util::Unit const* SPDocument::getDisplayUnit() const { SPNamedView const* nv = sp_document_namedview(this, NULL); - return nv ? nv->getDefaultUnit() : unit_table.getUnit("pt"); + return nv ? nv->getDisplayUnit() : unit_table.getUnit("px"); +} + +/// guaranteed not to return nullptr +// returns 'px' units as default, like legacy Inkscape +Inkscape::Util::Unit const& SPDocument::getSVGUnit() const +{ + SPNamedView const* nv = sp_document_namedview(this, NULL); + return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } Inkscape::Util::Quantity SPDocument::getWidth() const @@ -616,24 +627,18 @@ Inkscape::Util::Quantity SPDocument::getWidth() const return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } -void SPDocument::setWidth(const Inkscape::Util::Quantity &width) +void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); if (root->width.unit) old_units = unit_table.getUnit(root->width.unit); gdouble old_converted = Inkscape::Util::Quantity::convert(root->width.value, old_units, width.unit); + root->width.computed = width.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*width.unit == *unit_table.getUnit("m")) { - root->width.value = width.value("cm"); - root->width.unit = SVGLength::CM; - } else { - root->width.value = width.quantity; - root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); - } + root->width.value = width.quantity; + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); - if (root->viewBox_set) + if (root->viewBox_set && changeSize) root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); @@ -657,24 +662,18 @@ Inkscape::Util::Quantity SPDocument::getHeight() const return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } -void SPDocument::setHeight(const Inkscape::Util::Quantity &height) +void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); if (root->height.unit) old_units = unit_table.getUnit(root->height.unit); gdouble old_converted = Inkscape::Util::Quantity::convert(root->height.value, old_units, height.unit); + root->height.computed = height.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*height.unit == *unit_table.getUnit("m")) { - root->height.value = height.value("cm"); - root->height.unit = SVGLength::CM; - } else { - root->height.value = height.quantity; - root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - } + root->height.value = height.quantity; + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set) + if (root->viewBox_set && changeSize) root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); root->updateRepr(); diff --git a/src/document.h b/src/document.h index 4ace249ae..4a24ff502 100644 --- a/src/document.h +++ b/src/document.h @@ -38,7 +38,6 @@ class SPGroup; class SPRoot; namespace Inkscape { - struct Application; class Selection; class UndoStackObserver; class EventLog; @@ -241,13 +240,14 @@ public: SPDocument *doRef(); SPDocument *doUnref(); - Inkscape::Util::Unit const* getDefaultUnit() const; + Inkscape::Util::Unit const* getDisplayUnit() const; + Inkscape::Util::Unit const& getSVGUnit() const; Inkscape::Util::Quantity getWidth() const; Inkscape::Util::Quantity getHeight() const; Geom::Point getDimensions() const; Geom::OptRect preferredBounds() const; - void setWidth(const Inkscape::Util::Quantity &width); - void setHeight(const Inkscape::Util::Quantity &height); + void setWidth(const Inkscape::Util::Quantity &width, bool changeSize=true); + void setHeight(const Inkscape::Util::Quantity &height, bool changeSize=true); void setViewBox(const Geom::Rect &viewBox); void requestModified(); int ensureUpToDate(); diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp index c0bc19d90..afaf9aedf 100644 --- a/src/extension/dbus/application-interface.cpp +++ b/src/extension/dbus/application-interface.cpp @@ -49,7 +49,7 @@ application_interface_init (ApplicationInterface *app_interface) static bool ensure_desktop_valid(GError **error) { - if (!inkscape_use_gui()) { + if (!INKSCAPE.use_gui()) { g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires a GUI"); return false; } @@ -59,7 +59,7 @@ ensure_desktop_valid(GError **error) static bool ensure_desktop_not_present(GError **error) { - if (inkscape_use_gui()) { + if (INKSCAPE.use_gui()) { g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires non-GUI (command line) mode"); return false; } @@ -196,7 +196,7 @@ application_interface_document_close_all (ApplicationInterface *app_interface, SPDesktop *desktop = SP_ACTIVE_DESKTOP; g_assert(desktop != NULL); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); g_assert(doc != NULL); Inkscape::XML::Node *repr = doc->getReprRoot(); diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 19b48e10d..43830762c 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -153,23 +153,23 @@ gchar * init_document (void) { // This is for command-line use only - g_assert(!inkscape_use_gui()); + g_assert(!INKSCAPE.use_gui()); // Create a blank document and get its selection model etc in an ActionContext SPDocument *doc = SPDocument::createNewDoc(NULL, 1, TRUE); - inkscape_add_document(doc); - return dbus_register_document(inkscape_action_context_for_document(doc)); + INKSCAPE.add_document(doc); + return dbus_register_document(INKSCAPE.action_context_for_document(doc)); } gchar * init_active_document() { - SPDocument *doc = inkscape_active_document(); + SPDocument *doc = INKSCAPE.active_document(); if (!doc) { return NULL; } - return dbus_register_document(inkscape_active_action_context()); + return dbus_register_document(INKSCAPE.active_action_context()); } gchar * diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e3452f4ce..4fde6885f 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -21,7 +21,7 @@ #include <string.h> #include <dbus/dbus-glib.h> #include "desktop.h" -#include "desktop-handles.h" //sp_desktop_document() + //sp_desktop_document() #include "desktop-style.h" //sp_desktop_get_style #include "display/canvas-text.h" //text #include "display/sp-canvas.h" //text @@ -156,7 +156,7 @@ get_name_from_object (SPObject * obj) void desktop_ensure_active (SPDesktop* desk) { if (desk != SP_ACTIVE_DESKTOP) - inkscape_activate_desktop (desk); + INKSCAPE.activate_desktop (desk); return; } diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 3c8ee5844..e7299ba51 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -9,10 +9,10 @@ */ #include "prefdialog.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "helper/action.h" #include "ui/view/view.h" -#include "desktop-handles.h" + #include "selection.h" #include "sp-namedview.h" #include "desktop.h" @@ -89,11 +89,13 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * } // children of "inkscape-extension" } // if we have an XML file - if (INKSCAPE != NULL && inkscape_use_gui()) { + // \TODO this gets called from the Inkscape::Application constructor, where it initializes the menus. + // But in the constructor, our object isn't quite there yet! + if (Inkscape::Application::exists() && INKSCAPE.use_gui()) { if (_effects_list == NULL) - _effects_list = find_menu(inkscape_get_menus(INKSCAPE), EFFECTS_LIST); + _effects_list = find_menu(INKSCAPE.get_menus(), EFFECTS_LIST); if (_filters_list == NULL) - _filters_list = find_menu(inkscape_get_menus(INKSCAPE), FILTERS_LIST); + _filters_list = find_menu(INKSCAPE.get_menus(), FILTERS_LIST); } if ((_effects_list != NULL || _filters_list != NULL)) { diff --git a/src/extension/error-file.cpp b/src/extension/error-file.cpp index f60af870f..db354c0ce 100644 --- a/src/extension/error-file.cpp +++ b/src/extension/error-file.cpp @@ -48,9 +48,10 @@ ErrorFileNotice::ErrorFileNotice (void) : ) { + // \FIXME change this /* This is some filler text, needs to change before relase */ Glib::ustring dialog_text(_("<span weight=\"bold\" size=\"larger\">One or more extensions failed to load</span>\n\nThe failed extensions have been skipped. Inkscape will continue to run normally but those extensions will be unavailable. For details to troubleshoot this problem, please refer to the error log located at: ")); - gchar * ext_error_file = profile_path(EXTENSION_ERROR_LOG_FILENAME); + gchar * ext_error_file = Inkscape::Application::profile_path(EXTENSION_ERROR_LOG_FILENAME); dialog_text += ext_error_file; g_free(ext_error_file); set_message(dialog_text, true); diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index d4b5fd187..13b8d60c4 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -31,7 +31,7 @@ #include "desktop.h" #include "ui/view/view.h" #include "sp-namedview.h" -#include "desktop-handles.h" + #include "display/sp-canvas.h" #include "util/glib-list-iterators.h" @@ -65,7 +65,7 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp if (desktop != NULL) { Inkscape::Util::GSListConstIterator<SPItem *> selected = - sp_desktop_selection(desktop)->itemList(); + desktop->getSelection()->itemList(); while ( selected != NULL ) { Glib::ustring selected_id; selected_id = (*selected)->getId(); @@ -200,7 +200,7 @@ ExecutionEnv::reselect (void) { if (desktop == NULL) { return; } - Inkscape::Selection * selection = sp_desktop_selection(desktop); + Inkscape::Selection * selection = desktop->getSelection(); for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); ++i) { SPObject * obj = doc->getObjectById(i->c_str()); diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 6a22eb585..3d0f49a20 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -667,7 +667,7 @@ Extension::set_param_color (const gchar * name, guint32 color, SPDocument * doc, void Extension::error_file_open (void) { - gchar * ext_error_file = profile_path(EXTENSION_ERROR_LOG_FILENAME); + gchar * ext_error_file = Inkscape::Application::profile_path(EXTENSION_ERROR_LOG_FILENAME); gchar * filename = g_filename_from_utf8( ext_error_file, -1, NULL, NULL, NULL ); error_file.open(filename); if (!error_file.is_open()) { diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 6f6bddb93..52f63499a 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -21,7 +21,7 @@ #include "selection.h" #include "desktop.h" -#include "desktop-handles.h" + #include "ui/view/view.h" #include "util/glib-list-iterators.h" @@ -48,8 +48,8 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); using Inkscape::Util::GSListConstIterator; - GSListConstIterator<SPItem *> selected = - sp_desktop_selection((SPDesktop *)view)->itemList(); + // FIXME very unsafe cast + GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; if (selected != NULL) { const SPItem * item = *selected; diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 99c882a01..bbc567f75 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -24,7 +24,7 @@ #include <errno.h> #include <glib/gstdio.h> -#include "desktop-handles.h" + #include "desktop.h" #include "ui/dialog-events.h" #include "extension/effect.h" @@ -690,7 +690,7 @@ void Script::effect(Inkscape::Extension::Effect *module, } Inkscape::Util::GSListConstIterator<SPItem *> selected = - sp_desktop_selection(desktop)->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer + desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer while ( selected != NULL ) { Glib::ustring selected_id; selected_id += "--id="; @@ -1051,7 +1051,7 @@ int Script::execute (const std::list<std::string> &in_command, Glib::ustring stderr_data = fileerr.string(); if (stderr_data.length() != 0 && - inkscape_use_gui() + INKSCAPE.use_gui() ) { checkStderr(stderr_data, Gtk::MESSAGE_INFO, _("Inkscape has received additional data from the script executed. " diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 912d58a13..c16a5a899 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -243,7 +243,7 @@ init() /* Load search path for extensions */ if (Inkscape::Extension::Extension::search_path.size() == 0) { - Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions")); + Inkscape::Extension::Extension::search_path.push_back(Inkscape::Application::profile_path("extensions")); Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR)); diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 0d47240d4..76f35415e 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -25,7 +25,7 @@ #include <glib/gstdio.h> #include "desktop.h" -#include "desktop-handles.h" + #include "selection.h" #include "sp-object.h" #include "util/glib-list-iterators.h" @@ -242,7 +242,9 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie SPDocument * current_document = view->doc(); using Inkscape::Util::GSListConstIterator; - GSListConstIterator<SPItem *> selected = sp_desktop_selection((SPDesktop *)view)->itemList(); + + // FIXME very unsafe cast + GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (selected != NULL) { first_select = (*selected)->getRepr(); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 5a9a28ef9..1f48d2097 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -206,7 +206,7 @@ static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) { tr = Geom::Rotate::from_degrees( 180.0 ) * sp_shape_marker_get_transform_at_start(pathv.begin()->front()); } else { - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(pathv.begin()->front().pointAt(0)); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(pathv.begin()->front().pointAt(0)); } sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx); } @@ -224,7 +224,7 @@ static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_start(path_it->front()); } else { - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0)); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(path_it->front().pointAt(0)); } sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx); } @@ -241,7 +241,7 @@ static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2); } else { - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1)); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(curve_it1->pointAt(1)); } sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx); @@ -257,7 +257,7 @@ static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_end(lastcurve); } else { - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1)); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(lastcurve.pointAt(1)); } sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx); } @@ -281,7 +281,7 @@ static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_end(lastcurve); } else { - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1)); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(lastcurve.pointAt(1)); } sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx); diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index 3a3e2b58e..f4789a08f 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -263,7 +263,7 @@ SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u // If only one page is present, import that one without bothering user if (tmpSVGOutput.size() > 1) { CdrImportDialog *dlg = 0; - if (inkscape_use_gui()) { + if (INKSCAPE.use_gui()) { dlg = new CdrImportDialog(tmpSVGOutput); if (!dlg->showDialog()) { delete dlg; @@ -285,7 +285,7 @@ SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u // Set viewBox if it doesn't exist if (doc && !doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } return doc; } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 0f43fbca1..f7b6626c4 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -144,7 +144,7 @@ unsigned int PrintEmf::begin(Inkscape::Extension::Print *mod, SPDocument *doc) // width and height in px _width = doc->getWidth().value("px"); _height = doc->getHeight().value("px"); - _doc_unit_scale = Inkscape::Util::Quantity::convert(1, (doc->getDefaultUnit()), "px"); + _doc_unit_scale = Inkscape::Util::Quantity::convert(1, &doc->getSVGUnit(), "px"); // initialize a few global variables hbrush = hbrushOld = hpen = 0; diff --git a/src/extension/internal/filter/filter-file.cpp b/src/extension/internal/filter/filter-file.cpp index 48e64f089..b1993057d 100644 --- a/src/extension/internal/filter/filter-file.cpp +++ b/src/extension/internal/filter/filter-file.cpp @@ -29,7 +29,7 @@ namespace Filter { void Filter::filters_all_files(void) { - gchar *filtersProfilePath = profile_path("filters"); + gchar *filtersProfilePath = Inkscape::Application::profile_path("filters"); filters_load_dir(INKSCAPE_FILTERDIR, _("Bundled")); filters_load_dir(filtersProfilePath, _("Personal")); diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index 28e44c461..04a446d1c 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -136,7 +136,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { std::cout << "Viewbox not set, setting" << std::endl; - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } // restore undo, as now this document may be shown to the user if a bitmap was opened diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 0059bbec2..270edfe44 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -24,7 +24,7 @@ #include <gtkmm/spinbutton.h> #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "selection.h" #include "sp-object.h" @@ -113,7 +113,7 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc bounding_area = temprec; } - gdouble scale = Inkscape::Util::Quantity::convert(1, "px", (document->doc())->getDefaultUnit()); + gdouble scale = Inkscape::Util::Quantity::convert(1, "px", &document->doc()->getSVGUnit()); bounding_area *= Geom::Scale(scale); Geom::Point spacings( scale * module->get_param_float("xspacing"), scale * module->get_param_float("yspacing") ); @@ -191,7 +191,9 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View SPDocument * current_document = view->doc(); using Inkscape::Util::GSListConstIterator; - GSListConstIterator<SPItem *> selected = sp_desktop_selection((SPDesktop *)view)->itemList(); + + // FIXME very unsafe cast + GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (selected != NULL) { first_select = (*selected)->getRepr(); diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index c8a7feabf..148d2dcba 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -720,7 +720,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { } PdfImportDialog *dlg = NULL; - if (inkscape_use_gui()) { + if (INKSCAPE.use_gui()) { dlg = new PdfImportDialog(pdf_doc, uri); if (!dlg->showDialog()) { _cancelled = true; @@ -883,7 +883,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } // Restore undo diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 0b7dc7905..812fa373f 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -923,7 +923,9 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) GBool isolated = gFalse; GBool knockout = gFalse; if (!obj4.dictLookup(const_cast<char*>("CS"), &obj5)->isNull()) { -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + blendingColorSpace = GfxColorSpace::parse(NULL, &obj5, NULL, NULL); +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) blendingColorSpace = GfxColorSpace::parse(&obj5, NULL, NULL); #elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) blendingColorSpace = GfxColorSpace::parse(&obj5, NULL); @@ -1159,7 +1161,13 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/) res->lookupColorSpace(args[0].getName(), &obj); GfxColorSpace *colorSpace = 0; -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + if (obj.isNull()) { + colorSpace = GfxColorSpace::parse(NULL, &args[0], NULL, NULL); + } else { + colorSpace = GfxColorSpace::parse(NULL, &obj, NULL, NULL); + } +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) if (obj.isNull()) { colorSpace = GfxColorSpace::parse(&args[0], NULL, NULL); } else { @@ -1202,7 +1210,13 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/) state->setStrokePattern(NULL); res->lookupColorSpace(args[0].getName(), &obj); -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + if (obj.isNull()) { + colorSpace = GfxColorSpace::parse(NULL, &args[0], NULL, NULL); + } else { + colorSpace = GfxColorSpace::parse(NULL, &obj, NULL, NULL); + } +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) if (obj.isNull()) { colorSpace = GfxColorSpace::parse(&args[0], NULL, NULL); } else { @@ -2910,7 +2924,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } } if (!obj1.isNull()) { -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + colorSpace = GfxColorSpace::parse(NULL, &obj1, NULL, NULL); +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) colorSpace = GfxColorSpace::parse(&obj1, NULL, NULL); #elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) colorSpace = GfxColorSpace::parse(&obj1, NULL); @@ -3004,7 +3020,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) obj2.free(); } } -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + GfxColorSpace *maskColorSpace = GfxColorSpace::parse(NULL, &obj1, NULL, NULL); +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL, NULL); #elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL); @@ -3196,7 +3214,9 @@ void PdfParser::doForm(Object *str) { if (obj1.dictLookup(const_cast<char*>("S"), &obj2)->isName(const_cast<char*>("Transparency"))) { transpGroup = gTrue; if (!obj1.dictLookup(const_cast<char*>("CS"), &obj3)->isNull()) { -#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) +#if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) + blendingColorSpace = GfxColorSpace::parse(NULL, &obj3, NULL, NULL); +#elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) blendingColorSpace = GfxColorSpace::parse(&obj3, NULL, NULL); #elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) blendingColorSpace = GfxColorSpace::parse(&obj3, NULL); diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 9f9bf2651..7fd0d363b 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -263,7 +263,7 @@ SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u // If only one page is present, import that one without bothering user if (tmpSVGOutput.size() > 1) { VsdImportDialog *dlg = 0; - if (inkscape_use_gui()) { + if (INKSCAPE.use_gui()) { dlg = new VsdImportDialog(tmpSVGOutput); if (!dlg->showDialog()) { delete dlg; @@ -285,7 +285,7 @@ SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } return doc; diff --git a/src/extension/internal/wpg-input.cpp b/src/extension/internal/wpg-input.cpp index 12d86a99a..54a14fc72 100644 --- a/src/extension/internal/wpg-input.cpp +++ b/src/extension/internal/wpg-input.cpp @@ -129,7 +129,7 @@ SPDocument *WpgInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u // Set viewBox if it doesn't exist if (doc && !doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } delete input; diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 5225f11ee..6a95717f2 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -121,7 +121,7 @@ SPDocument *open(Extension *key, gchar const *filename) } if (last_chance_svg) { - if ( inkscape_use_gui() ) { + if ( INKSCAPE.use_gui() ) { sp_ui_error_dialog(_("Format autodetect failed. The file is being opened as SVG.")); } else { g_warning("%s", _("Format autodetect failed. The file is being opened as SVG.")); diff --git a/src/file.cpp b/src/file.cpp index 307944001..72516d776 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -32,7 +32,7 @@ #include "ui/dialog/ocaldialogs.h" #include "desktop.h" -#include "desktop-handles.h" + #include "dir-util.h" #include "document-private.h" #include "document-undo.h" @@ -144,7 +144,7 @@ SPDesktop *sp_file_new(const std::string &templ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { DocumentUndo::setUndoSensitive(doc, false); - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); DocumentUndo::setUndoSensitive(doc, true); } @@ -177,7 +177,7 @@ SPDesktop *sp_file_new(const std::string &templ) Glib::ustring sp_file_default_template_uri() { std::list<gchar *> sources; - sources.push_back( profile_path("templates") ); // first try user's local dir + sources.push_back( Inkscape::Application::profile_path("templates") ); // first try user's local dir sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir std::list<gchar const*> baseNames; gchar const* localized = _("default.svg"); @@ -289,7 +289,7 @@ bool sp_file_open(const Glib::ustring &uri, if (doc) { - SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL; + SPDocument *existing = desktop ? desktop->getDocument() : NULL; if (existing && existing->virgin && replace_empty) { // If the current desktop is empty, open the document there @@ -316,7 +316,7 @@ bool sp_file_open(const Glib::ustring &uri, sp_file_add_recent( doc->getURI() ); } - if ( inkscape_use_gui() ) { + if ( INKSCAPE.use_gui() ) { // Perform a fixup pass for hrefs. if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { Glib::ustring msg = _("Broken links have been changed to point to existing files."); @@ -348,7 +348,7 @@ void sp_file_revert_dialog() SPDesktop *desktop = SP_ACTIVE_DESKTOP; g_assert(desktop != NULL); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); g_assert(doc != NULL); Inkscape::XML::Node *repr = doc->getReprRoot(); @@ -1055,7 +1055,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) { //TODO: merge with file_import() - SPDocument *target_document = sp_desktop_document(desktop); + SPDocument *target_document = desktop->getDocument(); Inkscape::XML::Node *root = clipdoc->getReprRoot(); Inkscape::XML::Node *target_parent = desktop->currentLayer()->getRepr(); @@ -1086,7 +1086,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) } // Change the selection to the freshly pasted objects - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->setReprList(pasted_objects); // Apply inverse of parent transform @@ -1221,7 +1221,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, // select and move the imported item if (new_obj && SP_IS_ITEM(new_obj)) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->set(SP_ITEM(new_obj)); // preserve parent and viewBox transformations @@ -1232,7 +1232,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, // move to mouse pointer { - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); Geom::OptRect sel_bbox = selection->visualBounds(); if (sel_bbox) { Geom::Point m( desktop->point() - sel_bbox->midpoint() ); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 27f4d7a98..cf75f6cf0 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -31,7 +31,7 @@ #include "document-undo.h" #include "desktop.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "ui/tools/tool-base.h" #include "selection.h" #include "verbs.h" @@ -868,9 +868,8 @@ void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint gchar const* color_str = sp_repr_css_property( stop, "stop-color", NULL ); if( color_str ) { SPColor color( 0 ); - SPStyle* style = sp_style_new(0); SPIPaint paint; - paint.read( color_str, *style ); + paint.read( color_str ); if( paint.isColor() ) { color = paint.value.color; } @@ -1569,20 +1568,20 @@ SPGradient *sp_gradient_vector_for_object( SPDocument *const doc, SPDesktop *con void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTarget fill_or_stroke) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { sp_item_gradient_invert_vector_color(SP_ITEM(i->data), fill_or_stroke); } // we did an undoable action - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Invert gradient colors")); } void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::UI::Tools::ToolBase *ev = desktop->getEventContext(); if (!ev) { @@ -1602,7 +1601,7 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) } // we did an undoable action - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Reverse gradient")); } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index d945231fc..154b7339b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -22,11 +22,11 @@ #include <cstring> #include <string> -#include "desktop-handles.h" + #include "selection.h" #include "desktop.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "display/sp-ctrlline.h" @@ -563,7 +563,7 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler mg->array.built = false; mg->ensureArray(); // How do we do this? - DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Added patch row or column")); } // Mesh @@ -631,7 +631,7 @@ GrDrag::GrDrag(SPDesktop *desktop) : vert_levels(), draggers(0), lines(0), - selection(sp_desktop_selection(desktop)), + selection(desktop->getSelection()), sel_changed_connection(), sel_modified_connection(), style_set_connection(), @@ -796,7 +796,7 @@ static void gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, gui d_new->updateKnotShape (); d_new->updateTip (); d_new->updateDependencies(true); - DocumentUndo::done(sp_desktop_document (d_new->parent->desktop), SP_VERB_CONTEXT_GRADIENT, _("Merge gradient handles")); + DocumentUndo::done(d_new->parent->desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Merge gradient handles")); return; } } @@ -1102,8 +1102,7 @@ static void gr_knot_ungrabbed_handler(SPKnot *knot, unsigned int state, gpointer dragger->updateDependencies(true); // we did an undoable action - DocumentUndo::done(sp_desktop_document (dragger->parent->desktop), SP_VERB_CONTEXT_GRADIENT, - _("Move gradient handle")); + DocumentUndo::done(dragger->parent->desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Move gradient handle")); } /** @@ -1869,7 +1868,7 @@ void GrDrag::setDeselected(GrDragger *dragger) void GrDrag::addLine(SPItem *item, Geom::Point p1, Geom::Point p2, Inkscape::PaintTarget fill_or_stroke) { CtrlLineType type = (fill_or_stroke == Inkscape::FOR_FILL) ? CTLINE_PRIMARY : CTLINE_SECONDARY; - SPCtrlLine *line = ControlManager::getManager().createControlLine(sp_desktop_controls(this->desktop), p1, p2, type); + SPCtrlLine *line = ControlManager::getManager().createControlLine(this->desktop->getControls(), p1, p2, type); sp_canvas_item_move_to_z(line, 0); line->item = item; @@ -1885,7 +1884,7 @@ void GrDrag::addLine(SPItem *item, Geom::Point p1, Geom::Point p2, Inkscape::Pai void GrDrag::addCurve(SPItem *item, Geom::Point p0, Geom::Point p1, Geom::Point p2, Geom::Point p3, Inkscape::PaintTarget fill_or_stroke) { CtrlLineType type = (fill_or_stroke == Inkscape::FOR_FILL) ? CTLINE_PRIMARY : CTLINE_SECONDARY; - SPCtrlCurve *line = ControlManager::getManager().createControlCurve(sp_desktop_controls(this->desktop), p0, p1, p2, p3, type); + SPCtrlCurve *line = ControlManager::getManager().createControlCurve(this->desktop->getControls(), p0, p1, p2, p3, type); sp_canvas_item_move_to_z(line, 0); line->item = item; @@ -2375,7 +2374,7 @@ void GrDrag::selected_move(double x, double y, bool write_repr, bool scale_radia if (write_repr && did) { // we did an undoable action - DocumentUndo::maybeDone(sp_desktop_document (desktop), "grmoveh", SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::maybeDone(desktop->getDocument(), "grmoveh", SP_VERB_CONTEXT_GRADIENT, _("Move gradient handle(s)")); return; } @@ -2411,7 +2410,7 @@ void GrDrag::selected_move(double x, double y, bool write_repr, bool scale_radia if (write_repr && did) { // we did an undoable action - DocumentUndo::maybeDone(sp_desktop_document (desktop), "grmovem", SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::maybeDone(desktop->getDocument(), "grmovem", SP_VERB_CONTEXT_GRADIENT, _("Move gradient mid stop(s)")); } } diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 18159cb41..e5d61ab64 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -117,7 +117,7 @@ void graphlayout(GSList const *const items) { // add the connector spacing to the size of node bounding boxes // so that connectors can always be routed between shapes - SPDesktop* desktop = inkscape_active_desktop(); + SPDesktop* desktop = SP_ACTIVE_DESKTOP; double spacing = 0; if(desktop) spacing = desktop->namedview->connector_spacing+0.1; diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp index 582dcd2a8..5a56b89ff 100644 --- a/src/helper/stock-items.cpp +++ b/src/helper/stock-items.cpp @@ -29,7 +29,7 @@ #include "document-private.h" #include "sp-pattern.h" #include "sp-marker.h" -#include "desktop-handles.h" +#include "desktop.h" #include "inkscape.h" #include "io/sys.h" @@ -195,8 +195,8 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) gchar * base = g_strndup(e, a); - SPDesktop *desktop = inkscape_active_desktop(); - SPDocument *doc = sp_desktop_document(desktop); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); SPDefs *defs = doc->getDefs(); if (!defs) { g_free(base); @@ -265,8 +265,8 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) else { - SPDesktop *desktop = inkscape_active_desktop(); - SPDocument *doc = sp_desktop_document(desktop); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); SPObject *object = doc->getObjectById(urn); return object; diff --git a/src/inkscape-manifest-x64.xml b/src/inkscape-manifest-x64.xml index 38526cfe6..b5a6f11f2 100644 --- a/src/inkscape-manifest-x64.xml +++ b/src/inkscape-manifest-x64.xml @@ -1,5 +1,10 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> + <application xmlns="urn:schemas-microsoft-com:asm.v3"> + <windowsSettings> + <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware> + </windowsSettings> + </application> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" diff --git a/src/inkscape-private.h b/src/inkscape-private.h deleted file mode 100644 index d28ed223e..000000000 --- a/src/inkscape-private.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SEEN_INKSCAPE_PRIVATE_H -#define SEEN_INKSCAPE_PRIVATE_H - -/* - * Some forward declarations - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * Copyright (C) 1999-2002 Lauris Kaplinski - * Copyright (C) 2001-2002 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ -#include <glib-object.h> - -#define SP_TYPE_INKSCAPE (inkscape_get_type ()) -#define SP_INKSCAPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_INKSCAPE, Inkscape)) -#define SP_INKSCAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_INKSCAPE, InkscapeClass)) -#define SP_IS_INKSCAPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_INKSCAPE)) -#define SP_IS_INKSCAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_INKSCAPE)) - -#include "inkscape.h" - -struct SPColor; -namespace Inkscape { class Selection; } - -GType inkscape_get_type (void); - -void inkscape_ref (void); -void inkscape_unref (void); - -guint inkscape_mapalt(); -void inkscape_mapalt(guint); - -guint inkscape_trackalt(); -void inkscape_trackalt(guint); - -/* - * These are meant solely for desktop, document etc. implementations - */ - -void inkscape_selection_modified (Inkscape::Selection *selection, guint flags); -void inkscape_selection_changed (Inkscape::Selection * selection); -void inkscape_selection_set (Inkscape::Selection * selection); -void inkscape_eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext); -void inkscape_add_desktop (SPDesktop * desktop); -void inkscape_remove_desktop (SPDesktop * desktop); -void inkscape_activate_desktop (SPDesktop * desktop); -void inkscape_reactivate_desktop (SPDesktop * desktop); - -void inkscape_set_color (SPColor *color, float opacity); - -#endif // SEEN_INKSCAPE_PRIVATE_H - - - -/* - 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/inkscape.cpp b/src/inkscape.cpp index 36a802e5f..6a0e0f35a 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -1,13 +1,15 @@ /** * @file - * Legacy interface to main application. + * Interface to main application. */ /* Authors: * Lauris Kaplinski <lauris@kaplinski.com> * bulia byak <buliabyak@users.sf.net> + * Liam P. White <inkscapebrony@gmail.com> * - * Copyright (C) 1999-2005 authors - * g++ port Copyright (C) 2003 Nathan Hurst + * Copyright (C) 1999-2014 authors + * c++ port Copyright (C) 2003 Nathan Hurst + * c++ification Copyright (C) 2014 Liam P. White * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -50,240 +52,174 @@ #include <gtk/gtk.h> #include <signal.h> #include <string> + #include "desktop.h" -#include "desktop-handles.h" + #include "device-manager.h" #include "document.h" -#include "ui/tools/tool-base.h" #include "extension/db.h" #include "extension/init.h" #include "extension/output.h" #include "extension/system.h" -#include "inkscape-private.h" +#include "helper/action-context.h" +#include "helper/sp-marshal.h" +#include "inkscape.h" #include "io/sys.h" #include "layer-model.h" #include "message-stack.h" #include "preferences.h" #include "resource-manager.h" #include "selection.h" +#include "ui/tools/tool-base.h" #include "ui/dialog/debug.h" #include "xml/repr.h" -#include "helper/action-context.h" -#include "helper/sp-marshal.h" - -static InkscapeApplication *inkscape = NULL; /* Backbones of configuration xml data */ #include "menus-skeleton.h" -enum { - MODIFY_SELECTION, // global: one of selections modified - CHANGE_SELECTION, // global: one of selections changed - CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed - SET_SELECTION, // global: one of selections set - SET_EVENTCONTEXT, // tool switched - ACTIVATE_DESKTOP, // some desktop got focus - DEACTIVATE_DESKTOP, // some desktop lost focus - SHUTDOWN_SIGNAL, // inkscape is quitting - DIALOGS_HIDE, // user pressed F12 - DIALOGS_UNHIDE, // user pressed F12 - EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this - // may not be reflected by a selection change and thus needs a separate signal - LAST_SIGNAL -}; +// Inkscape::Application static members +Inkscape::Application * Inkscape::Application::_S_inst = NULL; +bool Inkscape::Application::_crashIsHappening = false; -#define DESKTOP_IS_ACTIVE(d) (inkscape->desktops && ((d) == inkscape->desktops->data)) +#define DESKTOP_IS_ACTIVE(d) (!INKSCAPE._desktops->empty() && ((d) == INKSCAPE._desktops->front())) +static void (* segv_handler) (int) = SIG_DFL; +static void (* abrt_handler) (int) = SIG_DFL; +static void (* fpe_handler) (int) = SIG_DFL; +static void (* ill_handler) (int) = SIG_DFL; +#ifndef WIN32 +static void (* bus_handler) (int) = SIG_DFL; +#endif -/*################################ -# FORWARD DECLARATIONS -################################*/ +#define INKSCAPE_PROFILE_DIR "inkscape" +#define INKSCAPE_PROFILE_DIR_047DEV "Inkscape" +#define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape" +#define MENUS_FILE "menus.xml" -static void inkscape_dispose (GObject *object); +#define SP_INDENT 8 -static void inkscape_activate_desktop_private (InkscapeApplication *inkscape, SPDesktop *desktop); -static void inkscape_deactivate_desktop_private (InkscapeApplication *inkscape, SPDesktop *desktop); +#ifdef WIN32 +typedef int uid_t; +#define getuid() 0 +#endif + +/** C++ification TODO list + * - _S_inst should NOT need to be assigned inside the constructor, but if it isn't the Filters+Extensions menus break. + * - Application::_deskops has to be a pointer because of a signal bug somewhere else. Basically, it will attempt to access a deleted object in sp_ui_close_all(), + * but if it's a pointer we can stop and return NULL in Application::active_desktop() + * - These functions are calling Application::create for no good reason I can determine: + * + * Inkscape::UI::Dialog::SVGPreview::SVGPreview() + * src/ui/dialog/filedialogimpl-gtkmm.cpp:542:9 + * void Inkscape::UI::Widget::ImageIcon::init() + * src/ui/widget/imageicon.cpp:93:9 + */ -class AppSelectionModel { - Inkscape::LayerModel _layer_model; - Inkscape::Selection *_selection; +class InkErrorHandler : public Inkscape::ErrorReporter { public: - AppSelectionModel(SPDocument *doc) { - _layer_model.setDocument(doc); - // TODO: is this really how we should manage the lifetime of the selection? - // I just copied this from the initialization of the Selection in SPDesktop. - // When and how is it actually released? - _selection = Inkscape::GC::release(new Inkscape::Selection(&_layer_model, NULL)); + InkErrorHandler(bool useGui) : Inkscape::ErrorReporter(), + _useGui(useGui) + {} + virtual ~InkErrorHandler() {} + + virtual void handleError( Glib::ustring const& primary, Glib::ustring const& secondary ) const + { + if (_useGui) { + Gtk::MessageDialog err(primary, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); + err.set_secondary_text(secondary); + err.run(); + } else { + g_message("%s", primary.data()); + g_message("%s", secondary.data()); + } } - Inkscape::Selection *getSelection() const { return _selection; } +private: + bool _useGui; }; -struct InkscapeApplication { - GObject object; - Inkscape::XML::Document *menus; - std::map<SPDocument *, int> document_set; - std::map<SPDocument *, AppSelectionModel *> selection_models; - GSList *desktops; - gchar *argv0; - gboolean dialogs_toggle; - gboolean use_gui; // may want to consider a virtual function - // for overriding things like the warning dlg's - guint mapalt; - guint trackalt; -}; +void inkscape_ref(Inkscape::Application & in) +{ + in.refCount++; +} -struct InkscapeApplicationClass { - GObjectClass object_class; - - /* Signals */ - void (* change_selection) (InkscapeApplication * inkscape, Inkscape::Selection * selection); - void (* change_subselection) (InkscapeApplication * inkscape, SPDesktop *desktop); - void (* modify_selection) (InkscapeApplication * inkscape, Inkscape::Selection * selection, guint flags); - void (* set_selection) (InkscapeApplication * inkscape, Inkscape::Selection * selection); - void (* set_eventcontext) (InkscapeApplication * inkscape, Inkscape::UI::Tools::ToolBase * eventcontext); - void (* activate_desktop) (InkscapeApplication * inkscape, SPDesktop * desktop); - void (* deactivate_desktop) (InkscapeApplication * inkscape, SPDesktop * desktop); - void (* destroy_document) (InkscapeApplication *inkscape, SPDocument *doc); - void (* color_set) (InkscapeApplication *inkscape, SPColor *color, double opacity); - void (* shut_down) (InkscapeApplication *inkscape); - void (* dialogs_hide) (InkscapeApplication *inkscape); - void (* dialogs_unhide) (InkscapeApplication *inkscape); - void (* external_change) (InkscapeApplication *inkscape); -}; +void inkscape_unref(Inkscape::Application & in) +{ + in.refCount--; + + if (&in == Inkscape::Application::_S_inst) { + if (in.refCount <= 0) { + delete Inkscape::Application::_S_inst; + } + } else { + g_error("Attempt to unref an Application (=%p) not the current instance (=%p) (maybe it's already been destroyed?)", + &in, Inkscape::Application::_S_inst); + } +} -static guint inkscape_signals[LAST_SIGNAL] = {0}; +// Callback passed to g_timeout_add_seconds() +// gets the current instance and calls autosave() +int inkscape_autosave(gpointer) { + g_assert(Inkscape::Application::exists()); + return INKSCAPE.autosave(); +} -static void (* segv_handler) (int) = SIG_DFL; -static void (* abrt_handler) (int) = SIG_DFL; -static void (* fpe_handler) (int) = SIG_DFL; -static void (* ill_handler) (int) = SIG_DFL; -#ifndef WIN32 -static void (* bus_handler) (int) = SIG_DFL; -#endif +namespace Inkscape { -#define INKSCAPE_PROFILE_DIR "inkscape" -#define INKSCAPE_PROFILE_DIR_047DEV "Inkscape" -#define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape" -#define MENUS_FILE "menus.xml" +/** + * Defined only for debugging purposes. If we are certain the bugs are gone we can remove this + * and the references in inkscape_ref and inkscape_unref. + */ +Application* +Application::operator &() const +{ + return const_cast<Application*>(this); +} +/** + * Creates a new Inkscape::Application global object. + */ +void +Application::create(const char *argv0, bool use_gui) +{ + if (!Application::exists()) { + new Application(argv0, use_gui); + } else { + g_assert_not_reached(); + } +} -G_DEFINE_TYPE(InkscapeApplication, inkscape, G_TYPE_OBJECT); /** - * Initializes the inkscape class, registering all of its signal handlers - * and virtual functions + * Checks whether the current Inkscape::Application global object exists. */ -static void -inkscape_class_init (InkscapeApplicationClass * klass) +bool +Application::exists() { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - - inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, modify_selection), - NULL, NULL, - sp_marshal_VOID__POINTER_UINT, - G_TYPE_NONE, 2, - G_TYPE_POINTER, G_TYPE_UINT); - inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, change_selection), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, change_subselection), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, set_selection), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, set_eventcontext), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, activate_desktop), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, deactivate_desktop), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, shut_down), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, dialogs_hide), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, dialogs_unhide), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (InkscapeApplicationClass, external_change), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - object_class->dispose = inkscape_dispose; - - klass->activate_desktop = inkscape_activate_desktop_private; - klass->deactivate_desktop = inkscape_deactivate_desktop_private; + return Application::_S_inst != NULL; } -#ifdef WIN32 -typedef int uid_t; -#define getuid() 0 -#endif +/** + * Returns the current Inkscape::Application global object. + * \pre Application::_S_inst != NULL + */ +Application& +Application::instance() +{ + if (!exists()) { + g_error("Inkscape::Application does not yet exist."); + } + return *Application::_S_inst; +} /** * static gint inkscape_autosave(gpointer); * - * Callback passed to g_timeout_add_seconds() * Responsible for autosaving all open documents */ -static gint inkscape_autosave(gpointer) +int Application::autosave() { - if (inkscape->document_set.empty()) { // nothing to autosave + if (_document_set.empty()) { // nothing to autosave return TRUE; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -302,7 +238,7 @@ static gint inkscape_autosave(gpointer) } GDir *autosave_dir_ptr = g_dir_open(autosave_dir.c_str(), 0, NULL); - if( !autosave_dir_ptr ){ + if (!autosave_dir_ptr) { // Try to create the autosave directory if it doesn't exist if (g_mkdir(autosave_dir.c_str(), 0755)) { // the creation failed @@ -333,8 +269,8 @@ static gint inkscape_autosave(gpointer) gint docnum = 0; SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Autosaving documents...")); - for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin(); - iter != inkscape->document_set.end(); + for (std::map<SPDocument*,int>::iterator iter = _document_set.begin(); + iter != _document_set.end(); ++iter) { SPDocument *doc = iter->first; @@ -342,7 +278,6 @@ static gint inkscape_autosave(gpointer) ++docnum; Inkscape::XML::Node *repr = doc->getReprRoot(); - // g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->getName() : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)"); if (doc->isModifiedSinceSave()) { gchar *oldest_autosave = 0; @@ -373,8 +308,6 @@ static gint inkscape_autosave(gpointer) } } - // g_debug("%d previous autosaves exists. Max = %d", count, autosave_max); - // Have we reached the limit for number of autosaves? if ( count >= autosave_max ){ // Remove the oldest file @@ -396,8 +329,6 @@ static gint inkscape_autosave(gpointer) g_free(baseName); baseName = 0; - // g_debug("Filename: %s", full_path); - // Try to save the file FILE *file = Inkscape::IO::fopen_utf8name(full_path, "w"); gchar *errortext = 0; @@ -435,7 +366,7 @@ static gint inkscape_autosave(gpointer) return TRUE; } -void inkscape_autosave_init() +void Application::autosave_init() { static guint32 autosave_timeout_id = 0; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -446,139 +377,149 @@ void inkscape_autosave_init() autosave_timeout_id = 0; } - // g_debug("options.autosave.enable = %d", prefs->getBool("/options/autosave/enable", true)); // Is autosave enabled? if (!prefs->getBool("/options/autosave/enable", true)){ autosave_timeout_id = 0; } else { // Turn on autosave guint32 timeout = prefs->getInt("/options/autosave/interval", 10) * 60; - // g_debug("options.autosave.interval = %d", prefs->getInt("/options/autosave/interval", 10)); autosave_timeout_id = g_timeout_add_seconds(timeout, inkscape_autosave, NULL); } } - -static void -inkscape_init (InkscapeApplication * object) +void Application::argv0(char const* argv) { - if (!inkscape) { - inkscape = (InkscapeApplication *) object; - } else { - g_assert_not_reached (); - } - - new (&inkscape->document_set) std::map<SPDocument *, int>(); - new (&inkscape->selection_models) std::map<SPDocument *, AppSelectionModel *>(); - - inkscape->menus = NULL; - inkscape->desktops = NULL; - inkscape->dialogs_toggle = TRUE; - inkscape->mapalt = GDK_MOD1_MASK; - inkscape->trackalt = FALSE; + _argv0 = g_strdup(argv); } -static void -inkscape_dispose (GObject *object) +/* \brief Constructor for the application. + * Creates a new Inkscape::Application. + * + * \pre Application::_S_inst == NULL + */ + +Application::Application(const char* argv, bool use_gui) : + _menus(NULL), + _desktops(NULL), + refCount(1), + _dialogs_toggle(TRUE), + _mapalt(GDK_MOD1_MASK), + _trackalt(FALSE), + _use_gui(use_gui) { - InkscapeApplication *inkscape = (InkscapeApplication *) object; + /* fixme: load application defaults */ - g_assert (!inkscape->desktops); + segv_handler = signal (SIGSEGV, Application::crash_handler); + abrt_handler = signal (SIGABRT, Application::crash_handler); + fpe_handler = signal (SIGFPE, Application::crash_handler); + ill_handler = signal (SIGILL, Application::crash_handler); +#ifndef WIN32 + bus_handler = signal (SIGBUS, Application::crash_handler); +#endif - Inkscape::Preferences::unload(); + _argv0 = g_strdup(argv); - if (inkscape->menus) { - /* fixme: This is not the best place */ - Inkscape::GC::release(inkscape->menus); - inkscape->menus = NULL; - } + // \TODO: this belongs to Application::init but if it isn't here + // then the Filters and Extensions menus don't work. + _S_inst = this; - inkscape->selection_models.~map(); - inkscape->document_set.~map(); + /* Load the preferences and menus */ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + InkErrorHandler* handler = new InkErrorHandler(use_gui); + prefs->setErrorHandler(handler); + { + Glib::ustring msg; + Glib::ustring secondary; + if (prefs->getLastError( msg, secondary )) { + handler->handleError(msg, secondary); + } + } - G_OBJECT_CLASS (inkscape_parent_class)->dispose (object); + if (use_gui) { + load_menus(); + Inkscape::DeviceManager::getManager().loadConfig(); + } + Inkscape::ResourceManager::getManager(); - gtk_main_quit (); -} + /* set language for user interface according setting in preferences */ + Glib::ustring ui_language = prefs->getString("/ui/language"); + if(!ui_language.empty()) + { + setenv("LANGUAGE", ui_language, 1); + } + /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON. + * Use only if use_gui is enabled + */ +#ifdef WIN32 +#define DEFAULT_LOG_REDIRECT true +#else +#define DEFAULT_LOG_REDIRECT false +#endif -void -inkscape_ref (void) -{ - if (inkscape) - g_object_ref (G_OBJECT (inkscape)); -} + if (use_gui == TRUE && prefs->getBool("/dialogs/debug/redirect", DEFAULT_LOG_REDIRECT)) + { + Inkscape::UI::Dialog::DebugDialog::getInstance()->captureLogMessages(); + } + /* Check for global remapping of Alt key */ + if (use_gui) + { + mapalt(guint(prefs->getInt("/options/mapalt/value", 0))); + trackalt(guint(prefs->getInt("/options/trackalt/value", 0))); + } -void -inkscape_unref (void) -{ - if (inkscape) - g_object_unref (G_OBJECT (inkscape)); -} + /* Initialize the extensions */ + Inkscape::Extension::init(); -/* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */ -/* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */ -guint -inkscape_mapalt() { - return inkscape->mapalt; + autosave_init(); } -/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */ -void inkscape_mapalt(guint maskvalue) +Application::~Application() { - if(maskvalue<2 || maskvalue> 5 ){ /* MOD5 is the highest defined in gdktypes.h */ - inkscape->mapalt=0; - }else{ - inkscape->mapalt=(GDK_MOD1_MASK << (maskvalue-1)); + if (_desktops) { + g_error("FATAL: desktops still in list on application destruction!"); } -} -guint -inkscape_trackalt() { - return inkscape->trackalt; -} - -void inkscape_trackalt(guint trackvalue) -{ - inkscape->trackalt = trackvalue; -} + Inkscape::Preferences::unload(); + if (_menus) { + Inkscape::GC::release(_menus); + _menus = NULL; + } -static void -inkscape_activate_desktop_private (InkscapeApplication */*inkscape*/, SPDesktop *desktop) -{ - desktop->set_active (true); -} + if (_argv0) { + g_free(_argv0); + _argv0 = NULL; + } + _S_inst = NULL; // this will probably break things -static void -inkscape_deactivate_desktop_private (InkscapeApplication */*inkscape*/, SPDesktop *desktop) -{ - desktop->set_active (false); + refCount = 0; + gtk_main_quit (); } - -/* fixme: This is EVIL, and belongs to main after all */ - -#define SP_INDENT 8 - - -static bool crashIsHappening = false; - -bool inkscapeIsCrashing() +/** Sets the keyboard modifer to map to Alt. + * + * Zero switches off mapping, as does '1', which is the default. + */ +void Application::mapalt(guint maskvalue) { - return crashIsHappening; + if ( maskvalue < 2 || maskvalue > 5 ) { // MOD5 is the highest defined in gdktypes.h + _mapalt = 0; + } else { + _mapalt = (GDK_MOD1_MASK << (maskvalue-1)); + } } -static void -inkscape_crash_handler (int /*signum*/) +void +Application::crash_handler (int /*signum*/) { using Inkscape::Debug::SimpleEvent; using Inkscape::Debug::EventTracker; using Inkscape::Debug::Logger; - static gint recursion = FALSE; + static bool recursion = false; /* * reset all signal handlers: any further crashes should just be allowed @@ -596,9 +537,9 @@ inkscape_crash_handler (int /*signum*/) if (recursion) { abort (); } - recursion = TRUE; + recursion = true; - crashIsHappening = true; + _crashIsHappening = true; EventTracker<SimpleEvent<Inkscape::Debug::Event::CORE> > tracker("crash"); tracker.set<SimpleEvent<> >("emergency-save"); @@ -612,11 +553,11 @@ inkscape_crash_handler (int /*signum*/) gint count = 0; gchar *curdir = g_get_current_dir(); // This one needs to be freed explicitly - gchar *inkscapedir = g_path_get_dirname(INKSCAPE->argv0); // Needs to be freed + gchar *inkscapedir = g_path_get_dirname(INKSCAPE._argv0); // Needs to be freed GSList *savednames = NULL; GSList *failednames = NULL; - for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin(); - iter != inkscape->document_set.end(); + for (std::map<SPDocument*,int>::iterator iter = INKSCAPE._document_set.begin(), e = INKSCAPE._document_set.end(); + iter != e; ++iter) { SPDocument *doc = iter->first; Inkscape::XML::Node *repr; @@ -757,7 +698,7 @@ inkscape_crash_handler (int /*signum*/) } *(b + pos) = '\0'; - if ( inkscape_get_instance() && inkscape_use_gui() ) { + if ( exists() && instance().use_gui() ) { GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b); gtk_dialog_run (GTK_DIALOG (msgbox)); gtk_widget_destroy (msgbox); @@ -774,132 +715,19 @@ inkscape_crash_handler (int /*signum*/) /* on exit, allow restored signal handler to take over and crash us */ } - -class InkErrorHandler : public Inkscape::ErrorReporter { -public: - InkErrorHandler(bool useGui) : Inkscape::ErrorReporter(), - _useGui(useGui) - {} - virtual ~InkErrorHandler() {} - - virtual void handleError( Glib::ustring const& primary, Glib::ustring const& secondary ) const - { - if (_useGui) { - Gtk::MessageDialog err(primary, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); - err.set_secondary_text(secondary); - err.run(); - } else { - g_message("%s", primary.data()); - g_message("%s", secondary.data()); - } - } - -private: - bool _useGui; -}; - -void -inkscape_application_init (const gchar *argv0, gboolean use_gui) -{ - inkscape = (InkscapeApplication *)g_object_new (SP_TYPE_INKSCAPE, NULL); - /* fixme: load application defaults */ - - segv_handler = signal (SIGSEGV, inkscape_crash_handler); - abrt_handler = signal (SIGABRT, inkscape_crash_handler); - fpe_handler = signal (SIGFPE, inkscape_crash_handler); - ill_handler = signal (SIGILL, inkscape_crash_handler); -#ifndef WIN32 - bus_handler = signal (SIGBUS, inkscape_crash_handler); -#endif - - inkscape->use_gui = use_gui; - inkscape->argv0 = g_strdup(argv0); - - /* Load the preferences and menus */ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - InkErrorHandler* handler = new InkErrorHandler(use_gui); - prefs->setErrorHandler(handler); - { - Glib::ustring msg; - Glib::ustring secondary; - if (prefs->getLastError( msg, secondary )) { - handler->handleError(msg, secondary); - } - } - - if (use_gui) { - inkscape_load_menus(inkscape); - Inkscape::DeviceManager::getManager().loadConfig(); - } - Inkscape::ResourceManager::getManager(); - - /* set language for user interface according setting in preferences */ - Glib::ustring ui_language = prefs->getString("/ui/language"); - if(!ui_language.empty()) - { - setenv("LANGUAGE", ui_language, 1); - } - - /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON. - * Use only if use_gui is enabled - */ -#ifdef WIN32 -#define DEFAULT_LOG_REDIRECT true -#else -#define DEFAULT_LOG_REDIRECT false -#endif - - if (use_gui == TRUE && prefs->getBool("/dialogs/debug/redirect", DEFAULT_LOG_REDIRECT)) - { - Inkscape::UI::Dialog::DebugDialog::getInstance()->captureLogMessages(); - } - - /* Check for global remapping of Alt key */ - if (use_gui) - { - inkscape_mapalt(guint(prefs->getInt("/options/mapalt/value", 0))); - inkscape_trackalt(guint(prefs->getInt("/options/trackalt/value", 0))); - } - - /* Initialize the extensions */ - Inkscape::Extension::init(); - - inkscape_autosave_init(); - - return; -} - -/** - * Returns the current InkscapeApplication global object - */ -InkscapeApplication * -inkscape_get_instance() -{ - return inkscape; -} - -gboolean inkscape_use_gui() -{ - return inkscape_get_instance()->use_gui; -} - /** * Menus management * */ -bool inkscape_load_menus( InkscapeApplication * inkscape ) +bool Application::load_menus() { gchar *fn = profile_path(MENUS_FILE); gchar *menus_xml = 0; gsize len = 0; - if ( inkscape != inkscape_get_instance() ) { - g_warning("BAD BAD BAD THINGS"); - } - if ( g_file_get_contents(fn, &menus_xml, &len, NULL) ) { // load the menus_xml file - inkscape->menus = sp_repr_read_mem(menus_xml, len, NULL); + _menus = sp_repr_read_mem(menus_xml, len, NULL); g_free(menus_xml); menus_xml = 0; @@ -907,146 +735,157 @@ bool inkscape_load_menus( InkscapeApplication * inkscape ) g_free(fn); fn = 0; - if ( !inkscape->menus ) { - inkscape->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL); + if ( !_menus ) { + _menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL); } - return (inkscape->menus != NULL); + return (_menus != 0); } void -inkscape_selection_modified (Inkscape::Selection *selection, guint flags) +Application::selection_modified (Inkscape::Selection *selection, guint flags) { g_return_if_fail (selection != NULL); if (DESKTOP_IS_ACTIVE (selection->desktop())) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags); + signal_selection_modified.emit(selection, flags); } } void -inkscape_selection_changed (Inkscape::Selection * selection) +Application::selection_changed (Inkscape::Selection * selection) { g_return_if_fail (selection != NULL); - + if (DESKTOP_IS_ACTIVE (selection->desktop())) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection); + signal_selection_changed.emit(selection); } } void -inkscape_subselection_changed (SPDesktop *desktop) +Application::subselection_changed (SPDesktop *desktop) { g_return_if_fail (desktop != NULL); if (DESKTOP_IS_ACTIVE (desktop)) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop); + signal_subselection_changed.emit(desktop); } } void -inkscape_selection_set (Inkscape::Selection * selection) +Application::selection_set (Inkscape::Selection * selection) { g_return_if_fail (selection != NULL); if (DESKTOP_IS_ACTIVE (selection->desktop())) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection); + signal_selection_set.emit(selection); + signal_selection_changed.emit(selection); } } void -inkscape_eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext) +Application::eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext) { g_return_if_fail (eventcontext != NULL); g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext)); if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext); + signal_eventcontext_set.emit(eventcontext); } } void -inkscape_add_desktop (SPDesktop * desktop) +Application::add_desktop (SPDesktop * desktop) { g_return_if_fail (desktop != NULL); - g_return_if_fail (inkscape != NULL); + if (_desktops == NULL) { + _desktops = new std::vector<SPDesktop*>; + } - g_assert (!g_slist_find (inkscape->desktops, desktop)); + if (std::find(_desktops->begin(), _desktops->end(), desktop) != _desktops->end()) { + g_error("Attempted to add desktop already in list."); + } - inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop); + _desktops->insert(_desktops->begin(), desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext()); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop)); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop)); + signal_activate_desktop.emit(desktop); + signal_eventcontext_set.emit(desktop->getEventContext()); + signal_selection_set.emit(desktop->getSelection()); + signal_selection_changed.emit(desktop->getSelection()); } void -inkscape_remove_desktop (SPDesktop * desktop) +Application::remove_desktop (SPDesktop * desktop) { g_return_if_fail (desktop != NULL); - g_return_if_fail (inkscape != NULL); - g_assert (g_slist_find (inkscape->desktops, desktop)); + if (std::find (_desktops->begin(), _desktops->end(), desktop) == _desktops->end() ) { + g_error("Attempted to remove desktop not in list."); + } if (DESKTOP_IS_ACTIVE (desktop)) { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop); - if (inkscape->desktops->next != NULL) { - SPDesktop * new_desktop = static_cast<SPDesktop *>(inkscape->desktops->next->data); - inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop); - inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, new_desktop->getEventContext()); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop)); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop)); + signal_deactivate_desktop.emit(desktop); + if (_desktops->size() > 1) { + SPDesktop * new_desktop = *(++_desktops->begin()); + _desktops->erase(std::find(_desktops->begin(), _desktops->end(), new_desktop)); + _desktops->insert(_desktops->begin(), new_desktop); + + signal_activate_desktop.emit(new_desktop); + signal_eventcontext_set.emit(new_desktop->getEventContext()); + signal_selection_set.emit(new_desktop->getSelection()); + signal_selection_changed.emit(new_desktop->getSelection()); } else { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL); - if (sp_desktop_selection(desktop)) - sp_desktop_selection(desktop)->clear(); + signal_eventcontext_set.emit(NULL); + if (desktop->getSelection()) + desktop->getSelection()->clear(); } } - inkscape->desktops = g_slist_remove (inkscape->desktops, desktop); + _desktops->erase(std::find(_desktops->begin(), _desktops->end(), desktop)); // if this was the last desktop, shut down the program - if (inkscape->desktops == NULL) { - inkscape_exit (inkscape); + if (_desktops->empty()) { + this->exit(); + delete _desktops; + _desktops = NULL; } } void -inkscape_activate_desktop (SPDesktop * desktop) +Application::activate_desktop (SPDesktop * desktop) { g_return_if_fail (desktop != NULL); - g_return_if_fail (inkscape != NULL); if (DESKTOP_IS_ACTIVE (desktop)) { return; } - g_assert (g_slist_find (inkscape->desktops, desktop)); + std::vector<SPDesktop*>::iterator i; + + if ((i = std::find (_desktops->begin(), _desktops->end(), desktop)) == _desktops->end()) { + g_error("Tried to activate desktop not added to list."); + } - SPDesktop *current = static_cast<SPDesktop *>(inkscape->desktops->data); + SPDesktop *current = _desktops->front(); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current); + signal_deactivate_desktop.emit(current); - inkscape->desktops = g_slist_remove (inkscape->desktops, desktop); - inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop); + _desktops->erase (i); + _desktops->insert (_desktops->begin(), desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext()); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop)); - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop)); + signal_activate_desktop.emit(desktop); + signal_eventcontext_set.emit(desktop->getEventContext()); + signal_selection_set(desktop->getSelection()); + signal_selection_changed(desktop->getSelection()); } @@ -1054,65 +893,62 @@ inkscape_activate_desktop (SPDesktop * desktop) * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to */ void -inkscape_reactivate_desktop (SPDesktop * desktop) +Application::reactivate_desktop (SPDesktop * desktop) { g_return_if_fail (desktop != NULL); - g_return_if_fail (inkscape != NULL); - if (DESKTOP_IS_ACTIVE (desktop)) - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop); + if (DESKTOP_IS_ACTIVE (desktop)) { + signal_activate_desktop.emit(desktop); + } } SPDesktop * -inkscape_find_desktop_by_dkey (unsigned int dkey) +Application::find_desktop_by_dkey (unsigned int dkey) { - for (GSList *r = inkscape->desktops; r; r = r->next) { - if ((static_cast<SPDesktop *>(r->data))->dkey == dkey){ - return (static_cast<SPDesktop *>(r->data)); + for (std::vector<SPDesktop*>::iterator r = _desktops->begin(), e = _desktops->end(); r != e; ++r) { + if ((*r)->dkey == dkey){ + return *r; } } return NULL; } - - -static unsigned int -inkscape_maximum_dkey() +unsigned int +Application::maximum_dkey() { unsigned int dkey = 0; - for (GSList *r = inkscape->desktops; r; r = r->next) { - if ((static_cast<SPDesktop *>(r->data))->dkey > dkey){ - dkey = (static_cast<SPDesktop *>(r->data))->dkey; + for (std::vector<SPDesktop*>::iterator r = _desktops->begin(), e = _desktops->end(); r != e; ++r) { + if ((*r)->dkey > dkey){ + dkey = (*r)->dkey; } } - return dkey; } -static SPDesktop * -inkscape_next_desktop () +SPDesktop * +Application::next_desktop () { SPDesktop *d = NULL; - unsigned int dkey_current = (static_cast<SPDesktop *>(inkscape->desktops->data))->dkey; + unsigned int dkey_current = (_desktops->front())->dkey; - if (dkey_current < inkscape_maximum_dkey()) { + if (dkey_current < maximum_dkey()) { // find next existing - for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) { - d = inkscape_find_desktop_by_dkey (i); + for (unsigned int i = dkey_current + 1; i <= maximum_dkey(); ++i) { + d = find_desktop_by_dkey (i); if (d) { break; } } } else { // find first existing - for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) { - d = inkscape_find_desktop_by_dkey (i); + for (unsigned int i = 0; i <= maximum_dkey(); ++i) { + d = find_desktop_by_dkey (i); if (d) { break; } @@ -1120,22 +956,21 @@ inkscape_next_desktop () } g_assert (d); - return d; } -static SPDesktop * -inkscape_prev_desktop () +SPDesktop * +Application::prev_desktop () { SPDesktop *d = NULL; - unsigned int dkey_current = (static_cast<SPDesktop *>(inkscape->desktops->data))->dkey; + unsigned int dkey_current = (_desktops->front())->dkey; if (dkey_current > 0) { // find prev existing - for (signed int i = dkey_current - 1; i >= 0; i--) { - d = inkscape_find_desktop_by_dkey (i); + for (signed int i = dkey_current - 1; i >= 0; --i) { + d = find_desktop_by_dkey (i); if (d) { break; } @@ -1143,81 +978,74 @@ inkscape_prev_desktop () } if (!d) { // find last existing - d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey()); + d = find_desktop_by_dkey (maximum_dkey()); } g_assert (d); - return d; } void -inkscape_switch_desktops_next () +Application::switch_desktops_next () { - inkscape_next_desktop()->presentWindow(); + next_desktop()->presentWindow(); } - - void -inkscape_switch_desktops_prev () +Application::switch_desktops_prev() { - inkscape_prev_desktop()->presentWindow(); + prev_desktop()->presentWindow(); } - - void -inkscape_dialogs_hide () +Application::dialogs_hide() { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0); - inkscape->dialogs_toggle = FALSE; + signal_dialogs_hide.emit(); + _dialogs_toggle = false; } void -inkscape_dialogs_unhide () +Application::dialogs_unhide() { - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0); - inkscape->dialogs_toggle = TRUE; + signal_dialogs_unhide.emit(); + _dialogs_toggle = true; } void -inkscape_dialogs_toggle () +Application::dialogs_toggle() { - if (inkscape->dialogs_toggle) { - inkscape_dialogs_hide (); + if (_dialogs_toggle) { + dialogs_hide(); } else { - inkscape_dialogs_unhide (); + dialogs_unhide(); } } void -inkscape_external_change () +Application::external_change() { - g_return_if_fail (inkscape != NULL); - - g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0); + signal_external_change.emit(); } /** * fixme: These need probably signals too */ void -inkscape_add_document (SPDocument *document) +Application::add_document (SPDocument *document) { g_return_if_fail (document != NULL); // try to insert the pair into the list - if (!(inkscape->document_set.insert(std::make_pair(document, 1)).second)) { + if (!(_document_set.insert(std::make_pair(document, 1)).second)) { //insert failed, this key (document) is already in the list - for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin(); - iter != inkscape->document_set.end(); + for (std::map<SPDocument*,int>::iterator iter = _document_set.begin(); + iter != _document_set.end(); ++iter) { if (iter->first == document) { // found this document in list, increase its count @@ -1227,10 +1055,10 @@ inkscape_add_document (SPDocument *document) } else { // insert succeeded, this document is new. Do we need to create a // selection model for it, i.e. are we running without a desktop? - if (!inkscape->use_gui) { + if (!_use_gui) { // Create layer model and selection model so we can run some verbs without a GUI - g_assert(inkscape->selection_models.find(document) == inkscape->selection_models.end()); - inkscape->selection_models[document] = new AppSelectionModel(document); + g_assert(_selection_models.find(document) == _selection_models.end()); + _selection_models[document] = new AppSelectionModel(document); } } } @@ -1238,24 +1066,24 @@ inkscape_add_document (SPDocument *document) // returns true if this was last reference to this document, so you can delete it bool -inkscape_remove_document (SPDocument *document) +Application::remove_document (SPDocument *document) { g_return_val_if_fail (document != NULL, false); - for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin(); - iter != inkscape->document_set.end(); + for (std::map<SPDocument *,int>::iterator iter = _document_set.begin(); + iter != _document_set.end(); ++iter) { if (iter->first == document) { // found this document in list, decrease its count iter->second --; if (iter->second < 1) { // this was the last one, remove the pair from list - inkscape->document_set.erase (iter); + _document_set.erase (iter); // also remove the selection model - std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = inkscape->selection_models.find(document); - if (sel_iter != inkscape->selection_models.end()) { - inkscape->selection_models.erase(sel_iter); + std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = _selection_models.find(document); + if (sel_iter != _selection_models.end()) { + _selection_models.erase(sel_iter); } return true; @@ -1269,37 +1097,38 @@ inkscape_remove_document (SPDocument *document) } SPDesktop * -inkscape_active_desktop (void) +Application::active_desktop() { - if (inkscape->desktops == NULL) { + if (!_desktops || _desktops->empty()) { return NULL; } - return static_cast<SPDesktop *>(inkscape->desktops->data); + return _desktops->front(); } SPDocument * -inkscape_active_document (void) +Application::active_document() { if (SP_ACTIVE_DESKTOP) { - return sp_desktop_document (SP_ACTIVE_DESKTOP); - } else if (!inkscape->document_set.empty()) { + return SP_ACTIVE_DESKTOP->getDocument(); + } else if (!_document_set.empty()) { // If called from the command line there will be no desktop // So 'fall back' to take the first listed document in the Inkscape instance - return inkscape->document_set.begin()->first; + return _document_set.begin()->first; } return NULL; } -bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) { +bool +Application::sole_desktop_for_document(SPDesktop const &desktop) { SPDocument const* document = desktop.doc(); if (!document) { return false; } - for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) { - SPDesktop *other_desktop=static_cast<SPDesktop *>(iter->data); - SPDocument *other_document=other_desktop->doc(); + for ( std::vector<SPDesktop*>::iterator iter = _desktops->begin(), e = _desktops->end() ; iter != e; ++iter ) { + SPDesktop *other_desktop = *iter; + SPDocument *other_document = other_desktop->doc(); if ( other_document == document && other_desktop != &desktop ) { return false; } @@ -1308,7 +1137,7 @@ bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) { } Inkscape::UI::Tools::ToolBase * -inkscape_active_event_context (void) +Application::active_event_context (void) { if (SP_ACTIVE_DESKTOP) { return SP_ACTIVE_DESKTOP->getEventContext(); @@ -1318,34 +1147,36 @@ inkscape_active_event_context (void) } Inkscape::ActionContext -inkscape_active_action_context() +Application::active_action_context() { if (SP_ACTIVE_DESKTOP) { return Inkscape::ActionContext(SP_ACTIVE_DESKTOP); } - SPDocument *doc = inkscape_active_document(); + SPDocument *doc = active_document(); if (!doc) { return Inkscape::ActionContext(); } - return inkscape_action_context_for_document(doc); + return action_context_for_document(doc); } Inkscape::ActionContext -inkscape_action_context_for_document(SPDocument *doc) +Application::action_context_for_document(SPDocument *doc) { // If there are desktops, check them first to see if the document is bound to one of them - for (GSList *iter = inkscape->desktops ; iter ; iter = iter->next) { - SPDesktop *desktop=static_cast<SPDesktop *>(iter->data); - if (desktop->doc() == doc) { - return Inkscape::ActionContext(desktop); + if (_desktops != NULL) { + for (std::vector<SPDesktop*>::iterator iter = _desktops->begin(), e = _desktops->end() ; iter != e ; ++iter) { + SPDesktop *desktop = *iter; + if (desktop->doc() == doc) { + return Inkscape::ActionContext(desktop); + } } } // Document is not associated with any desktops - maybe we're in command-line mode - std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = inkscape->selection_models.find(doc); - if (sel_iter == inkscape->selection_models.end()) { + std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = _selection_models.find(doc); + if (sel_iter == _selection_models.end()) { return Inkscape::ActionContext(); } return Inkscape::ActionContext(sel_iter->second->getSelection()); @@ -1357,10 +1188,10 @@ inkscape_action_context_for_document(SPDocument *doc) #####################*/ void -inkscape_refresh_display (InkscapeApplication *inkscape) +Application::refresh_display () { - for (GSList *l = inkscape->desktops; l != NULL; l = l->next) { - (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw(); + for (std::vector<SPDesktop*>::iterator l = _desktops->begin(), e = _desktops->end(); l != e; ++l) { + (*l)->requestRedraw(); } } @@ -1370,26 +1201,26 @@ inkscape_refresh_display (InkscapeApplication *inkscape) * saves the preferences if appropriate, and quits. */ void -inkscape_exit (InkscapeApplication */*inkscape*/) +Application::exit () { - g_assert (INKSCAPE); - //emit shutdown signal so that dialogs could remember layout - g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0); + signal_shut_down.emit(); Inkscape::Preferences::unload(); gtk_main_quit (); } char * -homedir_path(const char *filename) +Application::homedir_path(const char *filename) { static const gchar *homedir = NULL; if (!homedir) { homedir = g_get_home_dir(); } if (!homedir) { - homedir = g_path_get_dirname(INKSCAPE->argv0); + if (Application::exists()) { + homedir = g_path_get_dirname(Application::instance()._argv0); + } } return g_build_filename(homedir, filename, NULL); } @@ -1400,7 +1231,7 @@ homedir_path(const char *filename) * file should be located. */ gchar * -profile_path(const char *filename) +Application::profile_path(const char *filename) { static const gchar *prefdir = NULL; @@ -1512,21 +1343,21 @@ profile_path(const char *filename) } Inkscape::XML::Node * -inkscape_get_menus (InkscapeApplication * inkscape) +Application::get_menus() { - Inkscape::XML::Node *repr = inkscape->menus->root(); + Inkscape::XML::Node *repr = _menus->root(); g_assert (!(strcmp (repr->name(), "inkscape"))); return repr->firstChild(); } void -inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf) +Application::get_all_desktops(std::list< SPDesktop* >& listbuf) { - for(GSList* l = inkscape->desktops; l != NULL; l = l->next) { - listbuf.push_back(static_cast< SPDesktop* >(l->data)); - } + listbuf.insert(listbuf.end(), _desktops->begin(), _desktops->end()); } +} // namespace Inkscape + /* Local Variables: mode:c++ diff --git a/src/inkscape.h b/src/inkscape.h index 3a9b85fc9..fe424377c 100644 --- a/src/inkscape.h +++ b/src/inkscape.h @@ -6,116 +6,220 @@ * * Authors: * Lauris Kaplinski <lauris@kaplinski.com> + * Liam P. White <inkscapebrony@gmail.com> * - * Copyright (C) 1999-2003 Authors + * Copyright (C) 1999-2014 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <list> +#include <map> +#include <vector> #include <glib.h> +#include <glib-object.h> +#include <sigc++/signal.h> +#include "layer-model.h" +#include "selection.h" class SPDesktop; class SPDocument; +struct SPColor; namespace Inkscape { + +class Application; namespace UI { namespace Tools { class ToolBase; -} -} -} - -struct InkscapeApplication; - -namespace Inkscape { - class ActionContext; - namespace XML { - class Node; - struct Document; - } -} - -#define INKSCAPE inkscape_get_instance() - -void inkscape_autosave_init(); - -void inkscape_application_init (const gchar *argv0, gboolean use_gui); - -bool inkscape_load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton, unsigned int skel_size, const gchar *e_notreg, const gchar *e_notxml, const gchar *e_notsp, const gchar *warn); - -/* Menus */ -bool inkscape_load_menus (InkscapeApplication * inkscape); -bool inkscape_save_menus (InkscapeApplication * inkscape); -Inkscape::XML::Node *inkscape_get_menus (InkscapeApplication * inkscape); - -InkscapeApplication *inkscape_get_instance(); -gboolean inkscape_use_gui(); - -bool inkscapeIsCrashing(); +} // namespace Tools +} // namespace UI -SPDesktop * inkscape_find_desktop_by_dkey (unsigned int dkey); +class ActionContext; -#define SP_ACTIVE_EVENTCONTEXT inkscape_active_event_context () -Inkscape::UI::Tools::ToolBase * inkscape_active_event_context (void); +namespace XML { +class Node; +struct Document; +} // namespace XML -#define SP_ACTIVE_DOCUMENT inkscape_active_document () -SPDocument * inkscape_active_document (void); +} // namespace Inkscape -#define SP_ACTIVE_DESKTOP inkscape_active_desktop () -SPDesktop * inkscape_active_desktop (void); +void inkscape_ref (Inkscape::Application & in); +void inkscape_unref(Inkscape::Application & in); -// Use this function to get selection model etc for a document, if possible! -// The "active" alternative below has all the horrible static cling of a singleton. -Inkscape::ActionContext -inkscape_action_context_for_document(SPDocument *doc); +#define INKSCAPE (Inkscape::Application::instance()) +#define SP_ACTIVE_EVENTCONTEXT (INKSCAPE.active_event_context()) +#define SP_ACTIVE_DOCUMENT (INKSCAPE.active_document()) +#define SP_ACTIVE_DESKTOP (INKSCAPE.active_desktop()) -// More horrible static cling... sorry about this. Should really replace all of -// the static stuff with a single instance of some kind of engine class holding -// all the document / non-GUI stuff, and an optional GUI class that behaves a -// bit like SPDesktop does currently. Then it will be easier to write good code -// that doesn't just expect a GUI all the time (like lots of the app currently -// does). -// Also, while the "active" document / desktop concepts are convenient, they -// appear to have been abused somewhat, further increasing static cling. -Inkscape::ActionContext inkscape_active_action_context(); +class AppSelectionModel { + Inkscape::LayerModel _layer_model; + Inkscape::Selection *_selection; -bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop); +public: + AppSelectionModel(SPDocument *doc) { + _layer_model.setDocument(doc); + // TODO: is this really how we should manage the lifetime of the selection? + // I just copied this from the initialization of the Selection in SPDesktop. + // When and how is it actually released? + _selection = Inkscape::GC::release(new Inkscape::Selection(&_layer_model, NULL)); + } -gchar *homedir_path(const char *filename); -gchar *profile_path(const char *filename); + Inkscape::Selection *getSelection() const { return _selection; } +}; -/* Inkscape desktop stuff */ -void inkscape_activate_desktop (SPDesktop * desktop); -void inkscape_switch_desktops_next (); -void inkscape_switch_desktops_prev (); -void inkscape_get_all_desktops (std::list< SPDesktop* >& listbuf); - -void inkscape_dialogs_hide (); -void inkscape_dialogs_unhide (); -void inkscape_dialogs_toggle (); - -void inkscape_external_change (); -void inkscape_subselection_changed (SPDesktop *desktop); - -/* Moved document add/remove functions into public inkscape.h as they are used - (rightly or wrongly) by console-mode functions */ -void inkscape_add_document (SPDocument *document); -bool inkscape_remove_document (SPDocument *document); - -/* - * fixme: This has to be rethought - */ - -void inkscape_refresh_display (InkscapeApplication *inkscape); - -/* - * fixme: This also - */ +namespace Inkscape { -void inkscape_exit (InkscapeApplication *inkscape); +class Application { +public: + static Application& instance(); + static bool exists(); + static void create(const char* argv0, bool use_gui); + + // returns the mask of the keyboard modifier to map to Alt, zero if no mapping + // Needs to be a guint because gdktypes.h does not define a 'no-modifier' value + guint mapalt() const { return _mapalt; } + + // Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default + void mapalt(guint maskvalue); + + guint trackalt() const { return _trackalt; } + void trackalt(guint trackvalue) { _trackalt = trackvalue; } + + bool use_gui() const { return _use_gui; } + void use_gui(gboolean guival) { _use_gui = guival; } + + char const* argv0() const { return _argv0; } + void argv0(char const *); + + // no setter for this -- only we can control this variable + static bool isCrashing() { return _crashIsHappening; } + + // useful functions + void autosave_init(); + void application_init (const gchar *argv0, gboolean use_gui); + void load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton, + unsigned int skel_size, const gchar *e_notreg, const gchar *e_notxml, + const gchar *e_notsp, const gchar *warn); + + bool load_menus(); + bool save_menus(); + Inkscape::XML::Node * get_menus(); + + Inkscape::UI::Tools::ToolBase * active_event_context(); + SPDocument * active_document(); + SPDesktop * active_desktop(); + + // Use this function to get selection model etc for a document + Inkscape::ActionContext action_context_for_document(SPDocument *doc); + Inkscape::ActionContext active_action_context(); + + bool sole_desktop_for_document(SPDesktop const &desktop); + + // Inkscape desktop stuff + void add_desktop(SPDesktop * desktop); + void remove_desktop(SPDesktop* desktop); + void activate_desktop (SPDesktop * desktop); + void switch_desktops_next (); + void switch_desktops_prev (); + void get_all_desktops (std::list< SPDesktop* >& listbuf); + void reactivate_desktop (SPDesktop * desktop); + SPDesktop * find_desktop_by_dkey (unsigned int dkey); + unsigned int maximum_dkey(); + SPDesktop * next_desktop (); + SPDesktop * prev_desktop (); + + void dialogs_hide (); + void dialogs_unhide (); + void dialogs_toggle (); + + void external_change (); + void selection_modified (Inkscape::Selection *selection, guint flags); + void selection_changed (Inkscape::Selection * selection); + void subselection_changed (SPDesktop *desktop); + void selection_set (Inkscape::Selection * selection); + + void eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext); + + // Moved document add/remove functions into public inkscape.h as they are used + // (rightly or wrongly) by console-mode functions + void add_document (SPDocument *document); + bool remove_document (SPDocument *document); + + static char *homedir_path(const char *filename); + static char *profile_path(const char *filename); + + // fixme: This has to be rethought + void refresh_display (); + + // fixme: This also + void exit (); + + static void crash_handler(int signum); + + int autosave(); + + // nobody should be accessing our reference count, so it's made private. + friend void ::inkscape_ref (Application & in); + friend void ::inkscape_unref(Application & in); + + // signals + + // one of selections changed + sigc::signal<void, Inkscape::Selection *> signal_selection_changed; + // one of subselections (text selection, gradient handle, etc) changed + sigc::signal<void, SPDesktop *> signal_subselection_changed; + // one of selections modified + sigc::signal<void, Inkscape::Selection *, guint /*flags*/> signal_selection_modified; + // one of selections set + sigc::signal<void, Inkscape::Selection *> signal_selection_set; + // tool switched + sigc::signal<void, Inkscape::UI::Tools::ToolBase * /*eventcontext*/> signal_eventcontext_set; + // some desktop got focus + sigc::signal<void, SPDesktop *> signal_activate_desktop; + // some desktop lost focus + sigc::signal<void, SPDesktop *> signal_deactivate_desktop; + + // these are orphaned signals (nothing emits them and nothing connects to them) + sigc::signal<void, SPDocument *> signal_destroy_document; + sigc::signal<void, SPColor *, double /*opacity*/> signal_color_set; + + // inkscape is quitting + sigc::signal<void> signal_shut_down; + // user pressed F12 + sigc::signal<void> signal_dialogs_hide; + // user pressed F12 + sigc::signal<void> signal_dialogs_unhide; + // a document was changed by some external means (undo or XML editor); this + // may not be reflected by a selection change and thus needs a separate signal + sigc::signal<void> signal_external_change; + +private: + static Inkscape::Application * _S_inst; + + Application(const char* argv0, bool use_gui); + ~Application(); + + Application(Application const&); // no copy + Application& operator=(Application const&); // no assign + Application* operator&() const; // no pointer access + + Inkscape::XML::Document * _menus; + std::map<SPDocument *, int> _document_set; + std::map<SPDocument *, AppSelectionModel *> _selection_models; + std::vector<SPDesktop *> * _desktops; + + unsigned refCount; + bool _dialogs_toggle; + guint _mapalt; + guint _trackalt; + char * _argv0; + static bool _crashIsHappening; + bool _use_gui; +}; + +} // namespace Inkscape #endif diff --git a/src/inkview.cpp b/src/inkview.cpp index 2969bb140..0b7b4d35c 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -60,9 +60,7 @@ #include "io/inkjar.h" #endif -#include "inkscape-private.h" - -InkscapeApplication *inkscape; +#include "inkscape.h" #include <iostream> @@ -232,7 +230,8 @@ main (int argc, const char **argv) ss.view = NULL; ss.fullscreen = false; - inkscape = (InkscapeApplication *)g_object_new (SP_TYPE_INKSCAPE, NULL); + Inkscape::Application::create(argv[0], true); + //Inkscape::Application &inkscape = Inkscape::Application::instance(); // starting at where the commandline options stopped parsing because // we want all the files to be in the list diff --git a/src/io/resource.cpp b/src/io/resource.cpp index ac1c5f06b..501eab03b 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -73,7 +73,7 @@ Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) case TEMPLATES: name = "templates"; break; default: return get_path(SYSTEM, type, filename); } - path = profile_path(name); + path = Inkscape::Application::profile_path(name); } break; } diff --git a/src/knot.cpp b/src/knot.cpp index 4118873c1..b3813ab53 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -19,7 +19,7 @@ #include <glibmm/i18n.h> #include "display/sodipodi-ctrl.h" #include "desktop.h" -#include "desktop-handles.h" + #include "knot.h" #include "knot-ptr.h" #include "document.h" @@ -109,7 +109,7 @@ SPKnot::SPKnot(SPDesktop *desktop, gchar const *tip) this->tip = g_strdup (tip); } - this->item = sp_canvas_item_new(sp_desktop_controls (desktop), + this->item = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 8.0, @@ -342,7 +342,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot knot->ungrabbed_signal.emit(knot, event->button.state); - DocumentUndo::undo(sp_desktop_document(knot->desktop)); + DocumentUndo::undo(knot->desktop->getDocument()); knot->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Node or handle drag canceled.")); transform_escaped = true; consumed = TRUE; diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index c02d75d16..b1e365fe2 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -15,7 +15,7 @@ #include "gc-finalized.h" #include "document.h" #include "desktop.h" -#include "desktop-handles.h" + #include "layer-manager.h" #include "preferences.h" #include "ui/view/view.h" @@ -154,7 +154,7 @@ void LayerManager::setCurrentLayer( SPObject* obj ) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/selection/layerdeselect", true)) { - sp_desktop_selection( _desktop )->clear(); + _desktop->getSelection()->clear(); } } } diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp index fa1e8c11b..cd9179c5f 100644 --- a/src/libnrtype/Layout-TNG-Input.cpp +++ b/src/libnrtype/Layout-TNG-Input.cpp @@ -325,7 +325,7 @@ PangoFontDescription *Layout::InputStreamTextSource::styleGetFontDescription() c Layout::InputStreamTextSource::~InputStreamTextSource() { - sp_style_unref(style); + sp_style_unref(style); } }//namespace Text diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index fad06cd00..a6ab3b239 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -385,27 +385,27 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::selection_update() #endif // Get fontspec from a selection, preferences, or thin air. Glib::ustring fontspec; - SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); // Directly from stored font specification. int result = - sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); //std::cout << " Attempting selected style" << std::endl; - if (result != QUERY_STYLE_NOTHING && query->font_specification.set) { - fontspec = query->font_specification.value; + if (result != QUERY_STYLE_NOTHING && query.font_specification.set) { + fontspec = query.font_specification.value; //std::cout << " fontspec from query :" << fontspec << ":" << std::endl; } // From style if (fontspec.empty()) { //std::cout << " Attempting desktop style" << std::endl; - int rfamily = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - int rstyle = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int rfamily = sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int rstyle = sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE); // Must have text in selection if (rfamily != QUERY_STYLE_NOTHING && rstyle != QUERY_STYLE_NOTHING) { - fontspec = fontspec_from_style(query); + fontspec = fontspec_from_style(&query); } //std::cout << " fontspec from style :" << fontspec << ":" << std::endl; } @@ -413,11 +413,10 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::selection_update() // From preferences if (fontspec.empty()) { //std::cout << " Attempting preferences" << std::endl; - sp_style_read_from_prefs(query, "/tools/text"); - fontspec = fontspec_from_style(query); + query.readFromPrefs("/tools/text"); + fontspec = fontspec_from_style(&query); //std::cout << " fontspec from prefs :" << fontspec << ":" << std::endl; } - sp_style_unref(query); // From thin air if (fontspec.empty()) { diff --git a/src/line-geometry.cpp b/src/line-geometry.cpp index 566af8840..c5357e213 100644 --- a/src/line-geometry.cpp +++ b/src/line-geometry.cpp @@ -13,7 +13,7 @@ #include "inkscape.h" #include "desktop.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "display/sp-canvas.h" #include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" @@ -201,8 +201,8 @@ boost::optional<Geom::Point> Line::intersection_with_viewbox (SPDesktop *desktop void create_canvas_point(Geom::Point const &pos, double size, guint32 rgba) { - SPDesktop *desktop = inkscape_active_desktop(); - SPCanvasItem * canvas_pt = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRL, + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPCanvasItem * canvas_pt = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRL, "size", size, "filled", 1, "fill_color", rgba, @@ -214,8 +214,8 @@ void create_canvas_point(Geom::Point const &pos, double size, guint32 rgba) void create_canvas_line(Geom::Point const &p1, Geom::Point const &p2, guint32 rgba) { - SPDesktop *desktop = inkscape_active_desktop(); - SPCtrlLine *line = ControlManager::getManager().createControlLine(sp_desktop_controls(desktop), p1, p2); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPCtrlLine *line = ControlManager::getManager().createControlLine(desktop->getControls(), p1, p2); line->setRgba32(rgba); sp_canvas_item_show(line); } diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 391eccdd3..37fe77aed 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -451,7 +451,7 @@ void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - defaultUnit = &sp_lpe_item->document->getDefaultUnit()->abbr; + defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); @@ -460,7 +460,7 @@ void Effect::doOnApply_impl(SPLPEItem const* lpeitem) void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - defaultUnit = &sp_lpe_item->document->getDefaultUnit()->abbr; + defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; //printf("(SPLPEITEM*) %p\n", sp_lpe_item); sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector(); @@ -477,7 +477,7 @@ void Effect::doAcceptPathPreparations(SPLPEItem *lpeitem) { // switch to pen context - SPDesktop *desktop = inkscape_active_desktop(); // TODO: Is there a better method to find the item's desktop? + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // TODO: Is there a better method to find the item's desktop? if (!tools_isactive(desktop, TOOLS_FREEHAND_PEN)) { tools_switch(desktop, TOOLS_FREEHAND_PEN); } diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index c5390a0c9..2bed90139 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -367,6 +367,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) { using Geom::X; using Geom::Y; + if (curve->get_segment_count() < 1) return; // Make copy of old path as it is changed during processing diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 8df2eb176..f39b92e58 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -27,6 +27,7 @@ #include "knot-holder-entity.h" #include "knotholder.h" + namespace Inkscape { namespace LivePathEffect { @@ -55,47 +56,32 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), - reflectionFromPage(_("Use page as relecion base"), _("Use page as relecion base"), "reflectionFromPage", &wr, this, false), + fixedReflectionLine(_("Fixed reflection line"), _("Fixed reflection line"), "fixedReflectionLine", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") { show_orig_path = true; - registerParameter(&mode); registerParameter( &discard_orig_path); registerParameter( &fusionPaths); registerParameter( &reverseFusion); - registerParameter( &reflectionFromPage); + registerParameter( &distanceToX); + registerParameter( &distanceToY); registerParameter( &reflection_line); registerParameter( ¢er); - } LPEMirrorSymmetry::~LPEMirrorSymmetry() { } -void LPEMirrorSymmetry::doOnApply(SPLPEItem const* lpeitem) -{ - SPDocument *doc = lpeitem->document(); - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - sp_selection_group_impl(GSList *p, group, xml_doc, doc); - Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); - group->setAttribute("inkscape:groupmode", "layer"); - sp_selection_group_impl(p, group, xml_doc, doc); - gchar *href = g_strdup_printf("#%s", this->lpeobject_href); - SP_LPE_ITEM(group)->addPathEffect(href, true); - lpeitem->removeCurrentPathEffect(false) - g_free(href); - Inkscape::GC::release(group); -} - void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); + SPObject *subitem = static_cast<SPObject *>(item); Point A(boundingbox_X.max(), boundingbox_Y.min()); Point B(boundingbox_X.max(), boundingbox_Y.max()); Point C(boundingbox_X.max(), boundingbox_Y.middle()); @@ -107,7 +93,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) A = Geom::Point(center[X],boundingbox_Y.min()); B = Geom::Point(center[X],boundingbox_Y.max()); } - if( mode == MT_X || mode == MT_Y ){ + if( mode == MT_X || mode == MT_Y || mode == MT_FIXED_X || mode == MT_FIXED_Y ){ Geom::Path path; path.start( A ); path.appendNew<Geom::LineSegment>( B ); @@ -147,6 +133,27 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { using namespace Geom; + /* + SPDocument *doc = lpeitem->document; + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); + group->setAttribute("inkscape:groupmode", "layer"); + SPLPEItem* item = const_cast<SPLPEItem*>(lpeitem); + Inkscape::XML::Node *current = item->getRepr(); + gint topmost = current->position(); + Inkscape::XML::Node *top_current = current->parent(); + Inkscape::XML::Node *spnew = current->duplicate(xml_doc); + sp_repr_unparent(current); + group->appendChild(spnew); + Inkscape::GC::release(spnew); + top_current->appendChild(group); + group->setPosition(topmost + 1); + gchar *href = g_strdup_printf("#%s", item->getCurrentLPE()->getRepr()->attribute("id")); + SP_LPE_ITEM(group)->addPathEffect(href, true); + item->removeCurrentPathEffect(false); + g_free(href); + Inkscape::GC::release(group); + */ original_bbox(lpeitem); Point A(boundingbox_X.max(), boundingbox_Y.min()); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 6e9e7dd1a..c18fb265d 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -44,8 +44,6 @@ public: virtual void doOnApply (SPLPEItem const* lpeitem); - virtual void doOnApply(SPLPEItem const* lpeitem); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); @@ -64,7 +62,7 @@ private: BoolParam discard_orig_path; BoolParam fusionPaths; BoolParam reverseFusion; - BoolParam reflectionFromPage; + BoolParam fixedReflectionLine; PathParam reflection_line; Geom::Line lineSeparation; Geom::Point previousCenter; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 5183a455f..901519b4f 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -23,7 +23,7 @@ #include "knot-holder-entity.h" #include "knotholder.h" #include "desktop.h" - +#include <util/units.h> #include "inkscape.h" #include <2geom/path.h> @@ -97,7 +97,8 @@ LPEPerspectivePath::doBeforeEffect (SPLPEItem const* lpeitem) return; } Proj::TransfMat3x4 pmat = persp->perspective_impl->tmat; - pmat = pmat * SP_ACTIVE_DESKTOP->doc2dt(); + Geom::Affine doc2d = Geom::Scale(1, -1) * Geom::Translate(0, item->document->getHeight().value("px")); + pmat = pmat * doc2d; pmat.copy_tmat(tmat); item->apply_to_clippath(item); item->apply_to_mask(item); diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 07d9e63e8..8cef9a3a3 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -160,11 +160,11 @@ double LPERoughen::sign(double randNumber) Geom::Point LPERoughen::randomize() { - Inkscape::Util::Unit const *doc_units = SP_ACTIVE_DESKTOP->namedview->doc_units; + Inkscape::Util::Unit const *svg_units = SP_ACTIVE_DESKTOP->namedview->svg_units; double displaceXParsed = Inkscape::Util::Quantity::convert( - displaceX * globalRandomize, unit.get_abbreviation(), doc_units->abbr); + displaceX * globalRandomize, unit.get_abbreviation(), svg_units->abbr); double displaceYParsed = Inkscape::Util::Quantity::convert( - displaceY * globalRandomize, unit.get_abbreviation(), doc_units->abbr); + displaceY * globalRandomize, unit.get_abbreviation(), svg_units->abbr); Geom::Point output = Geom::Point(sign(displaceXParsed), sign(displaceYParsed)); return output; @@ -175,7 +175,7 @@ void LPERoughen::doEffect(SPCurve *curve) Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); curve->reset(); - Inkscape::Util::Unit const *doc_units = SP_ACTIVE_DESKTOP->namedview->doc_units; + Inkscape::Util::Unit const *svg_units = SP_ACTIVE_DESKTOP->namedview->svg_units; for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) @@ -221,7 +221,7 @@ void LPERoughen::doEffect(SPCurve *curve) nCurve->lineto(A3); } double length = Inkscape::Util::Quantity::convert( - curve_it1->length(0.001), doc_units->abbr, unit.get_abbreviation()); + curve_it1->length(0.001), svg_units->abbr, unit.get_abbreviation()); std::size_t splits = 0; if (method == DM_SEGMENTS) { splits = segments; diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 7b2b445b7..2d8148730 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -25,15 +25,20 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) nodes(_("Show nodes"), _("Show nodes"), "nodes", &wr, this, true), handles(_("Show handles"), _("Show handles"), "handles", &wr, this, true), originalPath(_("Show path"), _("Show path"), "originalPath", &wr, this, true), - scaleNodesAndHandles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scaleNodesAndHandles", &wr, this, 10) + scaleNodesAndHandles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scaleNodesAndHandles", &wr, this, 10), + rotateNodes(_("Rotate nodes"), _("Rotate nodes"), "rotateNodes", &wr, this, 0) { registerParameter(dynamic_cast<Parameter *>(&nodes)); registerParameter(dynamic_cast<Parameter *>(&handles)); registerParameter(dynamic_cast<Parameter *>(&originalPath)); registerParameter(dynamic_cast<Parameter *>(&scaleNodesAndHandles)); + registerParameter(dynamic_cast<Parameter *>(&rotateNodes)); scaleNodesAndHandles.param_set_range(0, 500.); scaleNodesAndHandles.param_set_increments(1, 1); scaleNodesAndHandles.param_set_digits(2); + rotateNodes.param_set_range(0, 365); + rotateNodes.param_set_increments(1, 1); + rotateNodes.param_set_digits(0); strokeWidth = 1.0; } @@ -158,10 +163,11 @@ LPEShowHandles::drawNode(Geom::Point p) if(strokeWidth * scaleNodesAndHandles > 0.0) { double diameter = strokeWidth * scaleNodesAndHandles; char const * svgd; - svgd = "M 0.55,0.5 A 0.05,0.05 0 0 1 0.5,0.55 0.05,0.05 0 0 1 0.45,0.5 0.05,0.05 0 0 1 0.5,0.45 0.05,0.05 0 0 1 0.55,0.5 Z M 0,0 1,0 1,1 0,1 Z"; + svgd = "M 0.05,0 A 0.05,0.05 0 0 1 0,0.05 0.05,0.05 0 0 1 -0.05,0 0.05,0.05 0 0 1 0,-0.05 0.05,0.05 0 0 1 0.05,0 Z M -0.5,-0.5 0.5,-0.5 0.5,0.5 -0.5,0.5 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Affine(diameter,0,0,diameter,0,0); - pathv += p - Geom::Point(diameter/2,diameter/2); + pathv *= Geom::Rotate::from_degrees(rotateNodes); + pathv *= Geom::Scale (diameter); + pathv += p; outlinepath.push_back(pathv[0]); outlinepath.push_back(pathv[1]); } @@ -175,8 +181,8 @@ LPEShowHandles::drawHandle(Geom::Point p) char const * svgd; svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Affine(diameter,0,0,diameter,0,0); - pathv += p - Geom::Point(diameter * 0.35,diameter * 0.35); + pathv *= Geom::Scale (diameter); + pathv += p-Geom::Point(diameter * 0.35,diameter * 0.35); outlinepath.push_back(pathv[0]); } } diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 278908bb5..a405c26ee 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -44,6 +44,7 @@ private: BoolParam handles; BoolParam originalPath; ScalarParam scaleNodesAndHandles; + ScalarParam rotateNodes; double strokeWidth; static bool alertsOff; diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 6c4f2a100..0884c4c9c 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -27,7 +27,7 @@ #include "live_effects/effect.h" #include "inkscape.h" -#include "desktop-handles.h" +#include "desktop.h" #include "selection.h" #include "ui/icon-names.h" @@ -128,7 +128,7 @@ OriginalPathParam::on_select_original_button_click() if (desktop == NULL || original == NULL) { return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->set(original); } diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 2a14d4208..ba95affd9 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -30,7 +30,7 @@ // needed for on-canvas editting: #include "ui/tools-switch.h" #include "ui/shape-editor.h" -#include "desktop-handles.h" + #include "selection.h" // clipboard support #include "ui/clipboard.h" @@ -414,7 +414,7 @@ PathParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) void PathParam::on_edit_button_click() { - SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); if (item != NULL) { param_editOncanvas(item, SP_ACTIVE_DESKTOP); } diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 956a001ad..234a6174d 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -19,6 +19,7 @@ #include "inkscape.h" #include "verbs.h" #include "display/canvas-text.h" + #include <2geom/sbasis-geometric.h> namespace Inkscape { @@ -32,8 +33,8 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, value(default_value), defvalue(default_value) { - SPDesktop *desktop = inkscape_active_desktop(); // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), ""); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); sp_canvastext_set_text (canvas_text, default_value.c_str()); sp_canvastext_set_coords (canvas_text, 0, 0); } diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index 6af616e34..ade83dfda 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -9,7 +9,6 @@ #include <ui/view/view.h> #include <desktop.h> -#include <desktop-handles.h> #include <helper/action.h> #include <helper/action-context.h> #include <selection.h> @@ -82,7 +81,7 @@ CmdLineAction::doList (ActionContext const & context) { bool CmdLineAction::idle (void) { std::list<SPDesktop *> desktops; - inkscape_get_all_desktops(desktops); + INKSCAPE.get_all_desktops(desktops); // We're going to assume one desktop per document, because no one // should have had time to make more at this point. diff --git a/src/main.cpp b/src/main.cpp index 12ddb76e6..06c0d4873 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,7 +74,7 @@ #include "svg/svg-color.h" #include "svg/stringstream.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "inkscape-version.h" #include "sp-namedview.h" @@ -933,9 +933,9 @@ guint get_group0_keyval(GdkEventKey const* event); static void snooper(GdkEvent *event, gpointer /*data*/) { - if (inkscape_mapalt()) /* returns the map of the keyboard modifier to map to Alt, zero if no mapping */ + if (INKSCAPE.mapalt()) /* returns the map of the keyboard modifier to map to Alt, zero if no mapping */ { - GdkModifierType mapping=(GdkModifierType)inkscape_mapalt(); + GdkModifierType mapping=(GdkModifierType)INKSCAPE.mapalt(); switch (event->type) { case GDK_MOTION_NOTIFY: if(event->motion.state & mapping) { @@ -957,7 +957,7 @@ snooper(GdkEvent *event, gpointer /*data*/) { } } - if (inkscape_trackalt()) { + if (INKSCAPE.trackalt()) { // MacOS X with X11 has some problem with the default // xmodmapping. A ~/.xmodmap solution does not work reliably due // to the way we package our executable in a .app that can launch @@ -1042,7 +1042,7 @@ sp_main_gui(int argc, char const **argv) } // Add our icon directory to the search path for icon theme lookups. - gchar *usericondir = profile_path("icons"); + gchar *usericondir = Inkscape::Application::profile_path("icons"); gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), usericondir); gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), INKSCAPE_PIXMAPDIR); g_free(usericondir); @@ -1059,7 +1059,7 @@ sp_main_gui(int argc, char const **argv) gboolean create_new = TRUE; /// \todo FIXME BROKEN - non-UTF-8 sneaks in here. - inkscape_application_init(argv[0], true); + Inkscape::Application::create(argv[0], true); while (fl) { if (sp_file_open((gchar *)fl->data,NULL)) { @@ -1125,14 +1125,14 @@ static int sp_process_file_list(GSList *fl) retVal++; } else { - inkscape_add_document(doc); + INKSCAPE.add_document(doc); if (sp_vacuum_defs) { doc->vacuumDocument(); } // Execute command-line actions (selections and verbs) using our local models - bool has_performed_actions = Inkscape::CmdLineAction::doList(inkscape_active_action_context()); + bool has_performed_actions = Inkscape::CmdLineAction::doList(INKSCAPE.active_action_context()); #ifdef WITH_DBUS // If we've been asked to listen for D-Bus messages, enter a main loop here @@ -1221,7 +1221,7 @@ static int sp_process_file_list(GSList *fl) do_query_dimension (doc, false, sp_query_x? Geom::X : Geom::Y, sp_query_id); } - inkscape_remove_document(doc); + INKSCAPE.remove_document(doc); delete doc; } @@ -1335,7 +1335,7 @@ int sp_main_console(int argc, char const **argv) exit(0); } - inkscape_application_init(argv[0], false); + Inkscape::Application::create(argv[0], false); if (sp_shell) { int retVal = sp_main_shell(argv[0]); // Run as interactive shell diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 0c3f9cde7..5f6e1495b 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -35,7 +35,7 @@ #include "document-undo.h" #include "message-stack.h" #include "selection.h" -#include "desktop-handles.h" + #include "box3d.h" #include <2geom/pathvector.h> #include "selection-chemistry.h" @@ -47,11 +47,11 @@ using Inkscape::DocumentUndo; void sp_selected_path_combine(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPDocument *doc = sp_desktop_document(desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *doc = desktop->getDocument(); if (g_slist_length((GSList *) selection->itemList()) < 1) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); return; } @@ -170,7 +170,7 @@ sp_selected_path_combine(SPDesktop *desktop) // move to the position of the topmost, reduced by the number of deleted items repr->setPosition(position > 0 ? position : 0); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_COMBINE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_COMBINE, _("Combine")); selection->set(repr); @@ -178,7 +178,7 @@ sp_selected_path_combine(SPDesktop *desktop) Inkscape::GC::release(repr); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to combine in the selection.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to combine in the selection.")); } desktop->clearWaitingCursor(); @@ -187,10 +187,10 @@ sp_selected_path_combine(SPDesktop *desktop) void sp_selected_path_break_apart(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart.")); return; } @@ -283,10 +283,10 @@ sp_selected_path_break_apart(SPDesktop *desktop) desktop->clearWaitingCursor(); if (did) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_BREAK_APART, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_BREAK_APART, _("Break apart")); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection.")); } } @@ -296,7 +296,7 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b { if (selection->isEmpty()) { if (interactive && desktop) - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path.")); return; } @@ -323,10 +323,10 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b if (interactive && desktop) { desktop->clearWaitingCursor(); if (did) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_TO_CURVE, _("Object to path")); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection.")); return; } } @@ -335,7 +335,7 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b /** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */ void sp_selected_to_lpeitems(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { return; @@ -500,11 +500,12 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Rotation center */ g_repr->setAttribute("inkscape:transform-center-x", item->getRepr()->attribute("inkscape:transform-center-x"), false); g_repr->setAttribute("inkscape:transform-center-y", item->getRepr()->attribute("inkscape:transform-center-y"), false); + /* Whole text's style */ - gchar *style_str = sp_style_write_difference(item->style, - item->parent ? item->parent->style : NULL); // TODO investigate posibility - g_repr->setAttribute("style", style_str); - g_free(style_str); + Glib::ustring style_str = + item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + g_repr->setAttribute("style", style_str.c_str()); + Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); do { Inkscape::Text::Layout::iterator iter_next = iter; @@ -522,19 +523,17 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) while (dynamic_cast<SPString const *>(pos_obj) && pos_obj->parent) { pos_obj = pos_obj->parent; // SPStrings don't have style } - gchar *style_str = sp_style_write_difference(pos_obj->style, - pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility + Glib::ustring style_str = + pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility // get path from iter to iter_next: SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); iter = iter_next; // shift to next glyph if (!curve) { // error converting this glyph - g_free (style_str); continue; } if (curve->is_empty()) { // whitespace glyph? curve->unref(); - g_free (style_str); continue; } @@ -545,8 +544,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) g_free(def_str); curve->unref(); - p_repr->setAttribute("style", style_str); - g_free(style_str); + p_repr->setAttribute("style", style_str.c_str()); g_repr->appendChild(p_repr); Inkscape::GC::release(p_repr); @@ -565,7 +563,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) if (shape) { curve = shape->getCurve(); } - } + } if (!curve) return NULL; @@ -581,11 +579,11 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); /* Transformation */ repr->setAttribute("transform", item->getRepr()->attribute("transform")); + /* Style */ - gchar *style_str = sp_style_write_difference(item->style, - item->parent ? item->parent->style : NULL); // TODO investigate posibility - repr->setAttribute("style", style_str); - g_free(style_str); + Glib::ustring style_str = + item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + repr->setAttribute("style", style_str.c_str()); /* Mask */ gchar *mask_str = (gchar *) item->getRepr()->attribute("mask"); @@ -613,11 +611,11 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) void sp_selected_path_reverse(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList *items = (GSList *) selection->itemList(); if (!items) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); return; } @@ -660,10 +658,10 @@ sp_selected_path_reverse(SPDesktop *desktop) desktop->clearWaitingCursor(); if (did) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_REVERSE, _("Reverse path")); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection.")); } } diff --git a/src/persp3d.cpp b/src/persp3d.cpp index b10e5f23b..c761947ad 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -19,9 +19,11 @@ #include "vanishing-point.h" #include "ui/tools/box3d-tool.h" #include "box3d.h" +#include "svg/stringstream.h" #include "xml/document.h" #include "xml/node-event-vector.h" -#include "desktop-handles.h" +#include "desktop.h" + #include <glibmm/i18n.h> #include "verbs.h" #include "util/units.h" @@ -30,9 +32,6 @@ using Inkscape::DocumentUndo; static void persp3d_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); -static void persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image); -static gchar * persp3d_pt_to_str (Persp3DImpl *persp_impl, Proj::Axis const axis); - static int global_counter = 0; #include "sp-factory.h" @@ -102,36 +101,48 @@ void Persp3D::release() { // FIXME: Currently we only read the finite positions of vanishing points; // should we move VPs into their own repr (as it's done for SPStop, e.g.)? void Persp3D::set(unsigned key, gchar const *value) { - Persp3DImpl *persp_impl = this->perspective_impl; + + // Read values are in 'user units'. + double scale_x = 1.0; + double scale_y = 1.0; + SPRoot *root = document->getRoot(); + if( root->viewBox_set ) { + scale_x = root->width.computed / root->viewBox.width(); + scale_y = root->height.computed / root->viewBox.height(); + } switch (key) { case SP_ATTR_INKSCAPE_PERSP3D_VP_X: { if (value) { - Proj::Pt2 new_image (value); - persp3d_update_with_point (persp_impl, Proj::X, new_image); + Proj::Pt2 pt (value); + Proj::Pt2 ptn ( pt[0]*scale_x, pt[1]*scale_y, pt[2] ); + perspective_impl->tmat.set_image_pt( Proj::X, ptn ); } break; } case SP_ATTR_INKSCAPE_PERSP3D_VP_Y: { if (value) { - Proj::Pt2 new_image (value); - persp3d_update_with_point (persp_impl, Proj::Y, new_image); - break; + Proj::Pt2 pt (value); + Proj::Pt2 ptn ( pt[0]*scale_x, pt[1]*scale_y, pt[2] ); + perspective_impl->tmat.set_image_pt( Proj::Y, ptn ); } + break; } case SP_ATTR_INKSCAPE_PERSP3D_VP_Z: { if (value) { - Proj::Pt2 new_image (value); - persp3d_update_with_point (persp_impl, Proj::Z, new_image); - break; + Proj::Pt2 pt (value); + Proj::Pt2 ptn ( pt[0]*scale_x, pt[1]*scale_y, pt[2] ); + perspective_impl->tmat.set_image_pt( Proj::Z, ptn ); } + break; } case SP_ATTR_INKSCAPE_PERSP3D_ORIGIN: { if (value) { - Proj::Pt2 new_image (value); - persp3d_update_with_point (persp_impl, Proj::W, new_image); - break; + Proj::Pt2 pt (value); + Proj::Pt2 ptn ( pt[0]*scale_x, pt[1]*scale_y, pt[2] ); + perspective_impl->tmat.set_image_pt( Proj::W, ptn ); } + break; } default: { SPObject::set(key, value); @@ -140,7 +151,7 @@ void Persp3D::set(unsigned key, gchar const *value) { } // FIXME: Is this the right place for resetting the draggers? - Inkscape::UI::Tools::ToolBase *ec = inkscape_active_event_context(); + Inkscape::UI::Tools::ToolBase *ec = INKSCAPE.active_event_context(); if (SP_IS_BOX3D_CONTEXT(ec)) { Inkscape::UI::Tools::Box3dTool *bc = SP_BOX3D_CONTEXT(ec); bc->_vpdrag->updateDraggers(); @@ -169,10 +180,19 @@ Persp3D *persp3d_create_xml_element(SPDocument *document, Persp3DImpl *dup) {// repr = xml_doc->createElement("inkscape:perspective"); repr->setAttribute("sodipodi:type", "inkscape:persp3d"); - Proj::Pt2 proj_vp_x = Proj::Pt2 (0.0, document->getHeight().value("px")/2, 1.0); - Proj::Pt2 proj_vp_y = Proj::Pt2 (0.0, 1000.0, 0.0); - Proj::Pt2 proj_vp_z = Proj::Pt2 (document->getWidth().value("px"), document->getHeight().value("px")/2, 1.0); - Proj::Pt2 proj_origin = Proj::Pt2 (document->getWidth().value("px")/2, document->getHeight().value("px")/3, 1.0); + // Use 'user-units' + double width = document->getWidth().value("px"); + double height = document->getHeight().value("px"); + if( document->getRoot()->viewBox_set ) { + Geom::Rect vb = document->getRoot()->viewBox; + width = vb.width(); + height = vb.height(); + } + + Proj::Pt2 proj_vp_x = Proj::Pt2 (0.0, height/2.0, 1.0); + Proj::Pt2 proj_vp_y = Proj::Pt2 (0.0, 1000.0, 0.0); + Proj::Pt2 proj_vp_z = Proj::Pt2 (width, height/2.0, 1.0); + Proj::Pt2 proj_origin = Proj::Pt2 (width/2.0, height/3.0, 1.0 ); if (dup) { proj_vp_x = dup->tmat.column (Proj::X); @@ -217,7 +237,6 @@ Persp3D *persp3d_document_first_persp(SPDocument *document) * Virtual write: write object attributes to repr. */ Inkscape::XML::Node* Persp3D::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - Persp3DImpl *persp_impl = this->perspective_impl; if ((flags & SP_OBJECT_WRITE_BUILD & SP_OBJECT_WRITE_EXT) && !repr) { // this is where we end up when saving as plain SVG (also in other circumstances?); @@ -226,18 +245,39 @@ Inkscape::XML::Node* Persp3D::write(Inkscape::XML::Document *xml_doc, Inkscape:: } if (flags & SP_OBJECT_WRITE_EXT) { - gchar *str = NULL; // FIXME: Should this be freed each time we set an attribute or only in the end or at all? - str = persp3d_pt_to_str (persp_impl, Proj::X); - repr->setAttribute("inkscape:vp_x", str); - - str = persp3d_pt_to_str (persp_impl, Proj::Y); - repr->setAttribute("inkscape:vp_y", str); - - str = persp3d_pt_to_str (persp_impl, Proj::Z); - repr->setAttribute("inkscape:vp_z", str); - str = persp3d_pt_to_str (persp_impl, Proj::W); - repr->setAttribute("inkscape:persp3d-origin", str); + // Written values are in 'user units'. + double scale_x = 1.0; + double scale_y = 1.0; + SPRoot *root = document->getRoot(); + if( root->viewBox_set ) { + scale_x = root->viewBox.width() / root->width.computed; + scale_y = root->viewBox.height() / root->height.computed; + } + { + Proj::Pt2 pt = perspective_impl->tmat.column( Proj::X ); + Inkscape::SVGOStringStream os; + os << pt[0] * scale_x << " : " << pt[1] * scale_y << " : " << pt[2]; + repr->setAttribute("inkscape:vp_x", os.str().c_str()); + } + { + Proj::Pt2 pt = perspective_impl->tmat.column( Proj::Y ); + Inkscape::SVGOStringStream os; + os << pt[0] * scale_x << " : " << pt[1] * scale_y << " : " << pt[2]; + repr->setAttribute("inkscape:vp_y", os.str().c_str()); + } + { + Proj::Pt2 pt = perspective_impl->tmat.column( Proj::Z ); + Inkscape::SVGOStringStream os; + os << pt[0] * scale_x << " : " << pt[1] * scale_y << " : " << pt[2]; + repr->setAttribute("inkscape:vp_z", os.str().c_str()); + } + { + Proj::Pt2 pt = perspective_impl->tmat.column( Proj::W ); + Inkscape::SVGOStringStream os; + os << pt[0] * scale_x << " : " << pt[1] * scale_y << " : " << pt[2]; + repr->setAttribute("inkscape:persp3d-origin", os.str().c_str()); + } } SPObject::write(xml_doc, repr, flags); @@ -289,7 +329,7 @@ persp3d_toggle_VP (Persp3D *persp, Proj::Axis axis, bool set_undo) { persp3d_update_box_reprs (persp); persp->updateRepr(SP_OBJECT_WRITE_EXT); if (set_undo) { - DocumentUndo::done(sp_desktop_document(inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, _("Toggle vanishing point")); } } @@ -300,7 +340,7 @@ persp3d_toggle_VPs (std::list<Persp3D *> p, Proj::Axis axis) { for (std::list<Persp3D *>::iterator i = p.begin(); i != p.end(); ++i) { persp3d_toggle_VP((*i), axis, false); } - DocumentUndo::done(sp_desktop_document(inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, _("Toggle multiple vanishing points")); } @@ -329,23 +369,12 @@ persp3d_rotate_VP (Persp3D *persp, Proj::Axis axis, double angle, bool alt_press } void -persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image) { - persp_impl->tmat.set_image_pt (axis, new_image); -} - -void persp3d_apply_affine_transformation (Persp3D *persp, Geom::Affine const &xform) { persp->perspective_impl->tmat *= xform; persp3d_update_box_reprs(persp); persp->updateRepr(SP_OBJECT_WRITE_EXT); } -gchar * -persp3d_pt_to_str (Persp3DImpl *persp_impl, Proj::Axis const axis) -{ - return persp_impl->tmat.pt_to_str(axis); -} - void persp3d_add_box (Persp3D *persp, SPBox3D *box) { Persp3DImpl *persp_impl = persp->perspective_impl; @@ -527,7 +556,7 @@ persp3d_print_all_selected() { g_print ("\n======================================\n"); g_print ("Selected perspectives and their boxes:\n"); - std::list<Persp3D *> sel_persps = sp_desktop_selection(inkscape_active_desktop())->perspList(); + std::list<Persp3D *> sel_persps = SP_ACTIVE_DESKTOP->getSelection()->perspList(); for (std::list<Persp3D *>::iterator j = sel_persps.begin(); j != sel_persps.end(); ++j) { Persp3D *persp = SP_PERSP3D(*j); diff --git a/src/preferences.cpp b/src/preferences.cpp index d0c3783b5..e5a5fe7f0 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -91,11 +91,13 @@ Preferences::Preferences() : _hasError(false) { // profile_path essentailly returns the argument prefixed by the profile directory. - gchar *path = profile_path(NULL); + // \TODO this is kinda hackish, but the alternative (strrchr) is worse + + gchar *path = Inkscape::Application::profile_path(NULL); _prefs_dir = path; g_free(path); - path = profile_path(_prefs_basename.c_str()); + path = Inkscape::Application::profile_path(_prefs_basename.c_str()); _prefs_filename = path; g_free(path); @@ -155,7 +157,7 @@ void Preferences::_load() // create some subdirectories for user stuff char const *user_dirs[] = {"keys", "templates", "icons", "extensions", "palettes", NULL}; for (int i=0; user_dirs[i]; ++i) { - char *dir = profile_path(user_dirs[i]); + char *dir = Inkscape::Application::profile_path(user_dirs[i]); g_mkdir(dir, 0755); g_free(dir); } diff --git a/src/rubberband.cpp b/src/rubberband.cpp index 6ec4b3e45..4a171f4a1 100644 --- a/src/rubberband.cpp +++ b/src/rubberband.cpp @@ -12,7 +12,7 @@ #include "display/sodipodi-ctrlrect.h" #include "desktop.h" -#include "desktop-handles.h" + #include "rubberband.h" #include "display/sp-canvas.h" #include "display/sp-canvas-item.h" @@ -98,7 +98,7 @@ void Inkscape::Rubberband::move(Geom::Point const &p) if (_mode == RUBBERBAND_MODE_RECT) { if (_rect == NULL) { - _rect = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL)); + _rect = static_cast<CtrlRect *>(sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRLRECT, NULL)); _rect->setShadow(1, 0xffffffff); } _rect->setRectangle(Geom::Rect(_start, _end)); @@ -109,7 +109,7 @@ void Inkscape::Rubberband::move(Geom::Point const &p) } else if (_mode == RUBBERBAND_MODE_TOUCHPATH) { if (_touchpath == NULL) { - _touchpath = sp_canvas_bpath_new(sp_desktop_sketch(_desktop), NULL); + _touchpath = sp_canvas_bpath_new(_desktop->getSketch(), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(_touchpath), 0xff0000ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(_touchpath), 0, SP_WIND_RULE_NONZERO); } diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp index 588c78ce0..028a22405 100644 --- a/src/satisfied-guide-cns.cpp +++ b/src/satisfied-guide-cns.cpp @@ -1,5 +1,5 @@ #include <2geom/coord.h> -#include "desktop-handles.h" +#include "desktop.h" #include "sp-guide.h" #include "sp-guide-constraint.h" #include "sp-namedview.h" @@ -9,7 +9,7 @@ void satisfied_guide_cns(SPDesktop const &desktop, std::vector<Inkscape::SnapCandidatePoint> const &snappoints, std::vector<SPGuideConstraint> &cns) { - SPNamedView const &nv = *sp_desktop_namedview(&desktop); + SPNamedView const &nv = *desktop.getNamedView(); for (GSList const *l = nv.guides; l != NULL; l = l->next) { SPGuide &g = *SP_GUIDE(l->data); for (unsigned int i = 0; i < snappoints.size(); ++i) { diff --git a/src/selcue.cpp b/src/selcue.cpp index 805629636..d2fa0970a 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -13,7 +13,8 @@ #include <string.h> -#include "desktop-handles.h" +#include "desktop.h" + #include "selection.h" #include "display/sp-canvas-util.h" #include "display/sodipodi-ctrl.h" @@ -40,7 +41,7 @@ Inkscape::SelCue::SelCue(SPDesktop *desktop) : _desktop(desktop), _bounding_box_prefs_observer(*this) { - _selection = sp_desktop_selection(_desktop); + _selection = _desktop->getSelection(); _sel_changed_connection = _selection->connectChanged( sigc::hide(sigc::mem_fun(*this, &Inkscape::SelCue::_newItemBboxes)) @@ -154,7 +155,7 @@ void Inkscape::SelCue::_newItemBboxes() if (b) { if (mode == MARK) { - box = sp_canvas_item_new(sp_desktop_controls(_desktop), + box = sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRL, "mode", SP_CTRL_MODE_XOR, "shape", SP_CTRL_SHAPE_DIAMOND, @@ -170,7 +171,7 @@ void Inkscape::SelCue::_newItemBboxes() sp_canvas_item_move_to_z(box, 0); // just low enough to not get in the way of other draggable knots } else if (mode == BBOX) { - box = sp_canvas_item_new(sp_desktop_controls(_desktop), + box = sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRLRECT, NULL); @@ -207,7 +208,7 @@ void Inkscape::SelCue::_newTextBaselines() if (layout != NULL && layout->outputExists()) { boost::optional<Geom::Point> pt = layout->baselineAnchorPoint(); if (pt) { - baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL, + baseline_point = sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRL, "mode", SP_CTRL_MODE_XOR, "size", 4.0, "filled", 0, diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index ffa149cee..c9837aabe 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -38,7 +38,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "layer-model.h" #include "selection.h" #include "ui/tools-switch.h" -#include "desktop-handles.h" + #include "message-stack.h" #include "sp-item-transform.h" #include "sp-marker.h" @@ -99,7 +99,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "display/curve.h" #include "display/canvas-bpath.h" #include "display/cairo-utils.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "path-chemistry.h" #include "ui/tool/control-point-selection.h" #include "ui/tool/multi-path-manipulator.h" @@ -177,8 +177,8 @@ void SelectionHelper::selectNone(SPDesktop *dt) if (nt && !nt->_selected_nodes->empty()) { nt->_selected_nodes->clear(); - } else if (!sp_desktop_selection(dt)->isEmpty()) { - sp_desktop_selection(dt)->clear(); + } else if (!dt->getSelection()->isEmpty()) { + dt->getSelection()->clear(); } else { // If nothing selected switch to selection tool tools_switch(dt, TOOLS_SELECT); @@ -277,7 +277,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) if(!dt) return; - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); GSList *items = NULL; @@ -402,12 +402,12 @@ void sp_selection_delete(SPDesktop *desktop) if (tools_isactive(desktop, TOOLS_TEXT)) if (Inkscape::UI::Tools::sp_text_delete_selection(desktop->event_context)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Delete text")); return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -429,7 +429,7 @@ void sp_selection_delete(SPDesktop *desktop) */ tools_switch( desktop, tools_active( desktop ) ); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_DELETE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_DELETE, _("Delete")); } @@ -454,7 +454,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) SPDocument *doc = desktop->doc(); Inkscape::XML::Document* xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -521,11 +521,9 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) if (!strcmp(orig->getId(), old_ids[j])) { // we have both orig and clone in selection, relink // std::cout << id << " old, its ori: " << orig->getId() << "; will relink:" << new_ids[i] << " to " << new_ids[j] << "\n"; - gchar *newref = g_strdup_printf("#%s", new_ids[j]); SPObject *new_clone = doc->getObjectById(new_ids[i]); - new_clone->getRepr()->setAttribute("xlink:href", newref); + new_clone->getRepr()->setAttribute("xlink:href", Glib::ustring("#") + new_ids[j]); new_clone->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - g_free(newref); } } } else { @@ -534,9 +532,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) for (guint j = 0; j < old_ids.size(); j++) { gchar *source_href = offset->sourceHref; if (source_href && source_href[0]=='#' && !strcmp(source_href+1, old_ids[j])) { - gchar *newref = g_strdup_printf("#%s", new_ids[j]); - doc->getObjectById(new_ids[i])->getRepr()->setAttribute("xlink:href", newref); - g_free(newref); + doc->getObjectById(new_ids[i])->getRepr()->setAttribute("xlink:href", Glib::ustring("#") + new_ids[j]); } } } @@ -546,7 +542,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) if ( !suppressDone ) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_DUPLICATE, _("Duplicate")); } @@ -613,7 +609,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i if (!dt) return; - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); g_return_if_fail(dynamic_cast<SPGroup *>(dt->currentLayer())); @@ -1146,7 +1142,7 @@ sp_undo(SPDesktop *desktop, SPDocument *) // No re/undo while dragging, too dangerous. if(desktop->getCanvas()->is_dragging) return; - if (!DocumentUndo::undo(sp_desktop_document(desktop))) { + if (!DocumentUndo::undo(desktop->getDocument())) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to undo.")); } } @@ -1157,7 +1153,7 @@ sp_redo(SPDesktop *desktop, SPDocument *) // No re/undo while dragging, too dangerous. if(desktop->getCanvas()->is_dragging) return; - if (!DocumentUndo::redo(sp_desktop_document(desktop))) { + if (!DocumentUndo::redo(desktop->getDocument())) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to redo.")); } } @@ -1230,7 +1226,7 @@ void sp_selection_paste(SPDesktop *desktop, bool in_place) { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if (cm->paste(desktop, in_place)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_PASTE, _("Paste")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_PASTE, _("Paste")); } } @@ -1238,7 +1234,7 @@ void sp_selection_paste_style(SPDesktop *desktop) { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if (cm->pasteStyle(desktop)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_PASTE_STYLE, _("Paste style")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_PASTE_STYLE, _("Paste style")); } } @@ -1247,7 +1243,7 @@ void sp_selection_paste_livepatheffect(SPDesktop *desktop) { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if (cm->pastePathEffect(desktop)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_PASTE_LIVEPATHEFFECT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_PASTE_LIVEPATHEFFECT, _("Paste live path effect")); } } @@ -1266,7 +1262,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) { if (desktop == NULL) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -1281,7 +1277,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_REMOVE_LIVEPATHEFFECT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_REMOVE_LIVEPATHEFFECT, _("Remove live path effect")); } @@ -1289,7 +1285,7 @@ void sp_selection_remove_filter(SPDesktop *desktop) { if (desktop == NULL) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -1302,7 +1298,7 @@ void sp_selection_remove_filter(SPDesktop *desktop) sp_desktop_set_style(desktop, css); sp_repr_css_attr_unref(css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_REMOVE_FILTER, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_REMOVE_FILTER, _("Remove filter")); } @@ -1311,7 +1307,7 @@ void sp_selection_paste_size(SPDesktop *desktop, bool apply_x, bool apply_y) { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if (cm->pasteSize(desktop, false, apply_x, apply_y)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_PASTE_SIZE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_PASTE_SIZE, _("Paste size")); } } @@ -1320,14 +1316,14 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if (cm->pasteSize(desktop, true, apply_x, apply_y)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_PASTE_SIZE_SEPARATELY, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_PASTE_SIZE_SEPARATELY, _("Paste size separately")); } } void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) { - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -1346,9 +1342,9 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers GSList *copied; if (next) { - copied = sp_selection_paste_impl(sp_desktop_document(dt), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); } else { - copied = sp_selection_paste_impl(sp_desktop_document(dt), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); no_more = true; } selection->setReprList((GSList const *) copied); @@ -1356,7 +1352,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) if (temp_clip) g_slist_free(temp_clip); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_MOVE_TO_NEXT, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT, _("Raise to next layer")); } } else { @@ -1372,7 +1368,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) { - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -1391,9 +1387,9 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers GSList *copied; if (next) { - copied = sp_selection_paste_impl(sp_desktop_document(dt), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); } else { - copied = sp_selection_paste_impl(sp_desktop_document(dt), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); no_more = true; } selection->setReprList((GSList const *) copied); @@ -1401,7 +1397,7 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) if (temp_clip) g_slist_free(temp_clip); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_MOVE_TO_PREV, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV, _("Lower to previous layer")); } } else { @@ -1417,7 +1413,7 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) { - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -1431,13 +1427,13 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) GSList *temp_clip = NULL; sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); - GSList *copied = sp_selection_paste_impl(sp_desktop_document(dt), moveto, &temp_clip); + GSList *copied = sp_selection_paste_impl(dt->getDocument(), moveto, &temp_clip); selection->setReprList((GSList const *) copied); g_slist_free(copied); if (temp_clip) g_slist_free(temp_clip); if (moveto) dt->setCurrentLayer(moveto); if ( !suppressDone ) { - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_MOVE_TO, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO, _("Move selection to layer")); } } @@ -1690,7 +1686,7 @@ void sp_selection_remove_transform(SPDesktop *desktop) if (desktop == NULL) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *l = const_cast<GSList *>(selection->reprList()); while (l != NULL) { @@ -1698,7 +1694,7 @@ void sp_selection_remove_transform(SPDesktop *desktop) l = l->next; } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_OBJECT_FLATTEN, + DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, _("Remove transform")); } @@ -1788,7 +1784,7 @@ void sp_selection_move_relative(Inkscape::Selection *selection, double dx, doubl */ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) return; @@ -1804,7 +1800,7 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) } } - DocumentUndo::done(sp_desktop_document(desktop), + DocumentUndo::done(desktop->getDocument(), ccw ? SP_VERB_OBJECT_ROTATE_90_CCW : SP_VERB_OBJECT_ROTATE_90_CW, ccw ? _("Rotate 90\xc2\xb0 CCW") : _("Rotate 90\xc2\xb0 CW")); } @@ -1822,7 +1818,7 @@ sp_selection_rotate(Inkscape::Selection *selection, gdouble const angle_degrees) sp_selection_rotate_relative(selection, *center, angle_degrees); - DocumentUndo::maybeDone(sp_desktop_document(selection->desktop()), + DocumentUndo::maybeDone(selection->desktop()->getDocument(), ( ( angle_degrees > 0 ) ? "selector:rotate:ccw" : "selector:rotate:cw" ), @@ -1856,7 +1852,7 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); GSList *all_matches = NULL; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); @@ -1909,7 +1905,7 @@ void sp_select_same_object_type(SPDesktop *desktop) GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); GSList *matches = all_list; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); @@ -1951,7 +1947,7 @@ void sp_select_same_stroke_style(SPDesktop *desktop) GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); GSList *matches = all_list; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); @@ -2114,7 +2110,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy SPStyle *sel_style_for_width = NULL; if (type == SP_STROKE_STYLE_WIDTH) { objects = g_slist_prepend(objects, sel); - sel_style_for_width = sp_style_new (SP_ACTIVE_DOCUMENT); + sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } @@ -2129,11 +2125,11 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy if (sel_style->stroke_width.set && iter_style->stroke_width.set) { GSList *objects = NULL; objects = g_slist_prepend(objects, iter); - SPStyle *iter_style_for_width = sp_style_new (SP_ACTIVE_DOCUMENT); - objects_query_strokewidth (objects, iter_style_for_width); + SPStyle tmp_style(SP_ACTIVE_DOCUMENT); + objects_query_strokewidth (objects, &tmp_style); if (sel_style_for_width) { - match = (sel_style_for_width->stroke_width.computed == iter_style_for_width->stroke_width.computed); + match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed); } g_slist_free(objects); } @@ -2165,6 +2161,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } } + if( sel_style_for_width != NULL ) delete sel_style_for_width; g_slist_free(objects); return matches; @@ -2209,7 +2206,7 @@ sp_selection_rotate_screen(Inkscape::Selection *selection, gdouble angle) sp_selection_rotate_relative(selection, *center, zangle); - DocumentUndo::maybeDone(sp_desktop_document(selection->desktop()), + DocumentUndo::maybeDone(selection->desktop()->getDocument(), ( (angle > 0) ? "selector:rotate:ccw" : "selector:rotate:cw" ), @@ -2239,7 +2236,7 @@ sp_selection_scale(Inkscape::Selection *selection, gdouble grow) double const times = 1.0 + grow / max_len; sp_selection_scale_relative(selection, center, Geom::Scale(times, times)); - DocumentUndo::maybeDone(sp_desktop_document(selection->desktop()), + DocumentUndo::maybeDone(selection->desktop()->getDocument(), ( (grow > 0) ? "selector:scale:larger" : "selector:scale:smaller" ), @@ -2268,7 +2265,7 @@ sp_selection_scale_times(Inkscape::Selection *selection, gdouble times) Geom::Point const center(sel_bbox->midpoint()); sp_selection_scale_relative(selection, center, Geom::Scale(times, times)); - DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(selection->desktop()->getDocument(), SP_VERB_CONTEXT_SELECT, _("Scale by whole factor")); } @@ -2380,7 +2377,7 @@ void sp_selection_item_next(SPDesktop *desktop) { g_return_if_fail(desktop != NULL); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs->getInt("/options/kbselection/inlayer", PREFS_SELECTION_LAYER); @@ -2407,10 +2404,10 @@ sp_selection_item_next(SPDesktop *desktop) void sp_selection_item_prev(SPDesktop *desktop) { - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); g_return_if_fail(document != NULL); g_return_if_fail(desktop != NULL); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); PrefsSelectionContext inlayer = (PrefsSelectionContext) prefs->getInt("/options/kbselection/inlayer", PREFS_SELECTION_LAYER); @@ -2438,7 +2435,7 @@ void sp_selection_next_patheffect_param(SPDesktop * dt) { if (!dt) return; - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); if ( selection && !selection->isEmpty() ) { SPItem *item = selection->singleItem(); if ( SPLPEItem *lpeitem = dynamic_cast<SPLPEItem*>(item) ) { @@ -2471,7 +2468,7 @@ void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/) /*if (!dt) return; using namespace Inkscape::UI; - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = dt->getSelection(); if (!selection || selection->isEmpty()) return; GSList const *items = selection->itemList(); @@ -2611,7 +2608,7 @@ void sp_selection_clone(SPDesktop *desktop) return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -2652,7 +2649,7 @@ void sp_selection_clone(SPDesktop *desktop) Inkscape::GC::release(clone); } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_CLONE, C_("Action", "Clone")); selection->setReprList(newsel); @@ -2666,7 +2663,7 @@ sp_selection_relink(SPDesktop *desktop) if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>clones</b> to relink.")); @@ -2701,7 +2698,7 @@ sp_selection_relink(SPDesktop *desktop) if (!relinked) { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to relink</b> in the selection.")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_UNLINK_CLONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_UNLINK_CLONE, _("Relink clone")); } } @@ -2713,7 +2710,7 @@ sp_selection_unlink(SPDesktop *desktop) if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>clones</b> to unlink.")); @@ -2775,7 +2772,7 @@ sp_selection_unlink(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to unlink</b> in the selection.")); } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_UNLINK_CLONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_UNLINK_CLONE, _("Unlink clone")); } @@ -2785,7 +2782,7 @@ sp_select_clone_original(SPDesktop *desktop) if (desktop == NULL) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); SPItem *item = selection->singleItem(); @@ -2860,7 +2857,7 @@ sp_select_clone_original(SPDesktop *desktop) curve->moveto(a->midpoint()); curve->lineto(b->midpoint()); - SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), curve); + SPCanvasItem * canvasitem = sp_canvas_bpath_new(desktop->getTempGroup(), curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), 0x0000ddff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT, 5, 3); sp_canvas_item_show(canvasitem); curve->unref(); @@ -2884,17 +2881,19 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) if (desktop == NULL) { return; } - + + Inkscape::Selection *selection = desktop->getSelection(); + Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; - for (const GSList * item = desktop->selection->itemList(); item != NULL; item = item->next) { + for (const GSList * item = selection->itemList(); item != NULL; item = item->next) { if (SP_IS_SHAPE(item->data) || SP_IS_TEXT(item->data)) { if (firstItem) { os << "|"; } else { firstItem = SP_ITEM(item->data); } - os << "#" << SP_ITEM(item->data)->getId() << ",0"; + os << '#' << SP_ITEM(item->data)->getId() << ",0"; } } if (firstItem) { @@ -2905,10 +2904,10 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); { lpe_repr->setAttribute("effect", "fill_between_many"); - lpe_repr->setAttribute("linkedpaths", os.str().c_str()); + lpe_repr->setAttribute("linkedpaths", os.str()); desktop->doc()->getDefs()->getRepr()->addChild(lpe_repr, NULL); // adds to <defs> and assigns the 'id' attribute } - const gchar * lpe_id = lpe_repr->attribute("id"); + std::string lpe_id_href = std::string("#") + lpe_repr->attribute("id"); Inkscape::GC::release(lpe_repr); // create the new path @@ -2920,13 +2919,15 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) SPObject *clone_obj = desktop->doc()->getObjectById(clone->attribute("id")); SPLPEItem *clone_lpeitem = dynamic_cast<SPLPEItem *>(clone_obj); if (clone_lpeitem) { - gchar *href = g_strdup_printf("#%s", lpe_id); - clone_lpeitem->addPathEffect(href, false); - g_free(href); + clone_lpeitem->addPathEffect(lpe_id_href, false); } } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, _("Fill between many")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, _("Fill between many")); + // select the new object: + selection->set(clone); + + Inkscape::GC::release(clone); } else { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select path(s) to fill.")); } @@ -2939,10 +2940,10 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -3040,8 +3041,8 @@ void sp_selection_to_guides(SPDesktop *desktop) if (desktop == NULL) return; - SPDocument *doc = sp_desktop_document(desktop); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPDocument *doc = desktop->getDocument(); + Inkscape::Selection *selection = desktop->getSelection(); // we need to copy the list because it gets reset when objects are deleted GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); @@ -3098,10 +3099,10 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // Check if something is selected. if (selection->isEmpty()) { @@ -3172,9 +3173,9 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) the_group->getAttribute("inkscape:transform-center-y")); the_group->setAttribute("style", NULL); - std::string id = symbol_repr->attribute("id"); + Glib::ustring id = symbol_repr->attribute("id"); id += "_transform"; - the_group->setAttribute("id", id.c_str()); + the_group->setAttribute("id", id); } @@ -3192,10 +3193,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) // Create <use> pointing to new symbol (to replace the moved objects). Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); - const gchar *symbol_id = symbol_repr->attribute("id"); - gchar *href_str = g_strdup_printf("#%s", symbol_id); - clone->setAttribute("xlink:href", href_str, false); - g_free(href_str); + clone->setAttribute("xlink:href", Glib::ustring("#")+symbol_repr->attribute("id"), false); the_parent_repr->appendChild(clone); @@ -3223,10 +3221,10 @@ void sp_selection_unsymbol(SPDesktop *desktop) return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // Check if something is selected. if (selection->isEmpty()) { @@ -3286,11 +3284,11 @@ void sp_selection_unsymbol(SPDesktop *desktop) // Need to delete <symbol>; all <use> elements that referenced <symbol> should // auto-magically reference <g> (if <symbol> deleted after setting <g> 'id'). Glib::ustring id = symbol->getAttribute("id"); - group->setAttribute("id",id.c_str()); + group->setAttribute("id", id); symbol->deleteObject(true); // Change selection to new <g> element. - SPItem *group_item = static_cast<SPItem *>(sp_desktop_document(desktop)->getObjectByRepr(group)); + SPItem *group_item = static_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(group)); selection->set(group_item); // Clean up @@ -3308,10 +3306,10 @@ sp_selection_tile(SPDesktop *desktop, bool apply) return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -3403,7 +3401,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) // restore parent and position parent->getRepr()->appendChild(rect); rect->setPosition(pos > 0 ? pos : 0); - SPItem *rectangle = static_cast<SPItem *>(sp_desktop_document(desktop)->getObjectByRepr(rect)); + SPItem *rectangle = static_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(rect)); Inkscape::GC::release(rect); @@ -3423,10 +3421,10 @@ void sp_selection_untile(SPDesktop *desktop) return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -3493,7 +3491,7 @@ void sp_selection_untile(SPDesktop *desktop) if (!did) { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No pattern fills</b> in the selection.")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_UNTILE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_UNTILE, _("Pattern to objects")); selection->setList(new_select); } @@ -3578,10 +3576,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) return; } - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); Inkscape::XML::Document *xml_doc = document->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -3628,7 +3626,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) directory = g_path_get_dirname( document->getURI() ); } if (directory == NULL) { - directory = homedir_path(NULL); + directory = INKSCAPE.homedir_path(NULL); } gchar *filepath = g_build_filename(directory, basename, NULL); g_free(directory); @@ -3796,10 +3794,10 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) if (desktop == NULL) { return; } - SPDocument* doc = sp_desktop_document(desktop); + SPDocument* doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create clippath or mask from.")); return; @@ -3912,10 +3910,10 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected bool is_empty = selection->isEmpty(); @@ -4084,9 +4082,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::GC::release(group); } - gchar *value_str = g_strdup_printf("url(#%s)", mask_id); - apply_mask_to->setAttribute(attributeName, value_str); - g_free(value_str); + apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')'); } @@ -4117,9 +4113,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { return; } - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { @@ -4210,7 +4206,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { parent->appendChild(repr); repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0); - SPItem *mask_item = static_cast<SPItem *>(sp_desktop_document(desktop)->getObjectByRepr(repr)); + SPItem *mask_item = static_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(repr)); items_to_select = g_slist_prepend(items_to_select, mask_item); // transform mask, so it is moved the same spot where mask was applied @@ -4258,7 +4254,7 @@ bool fit_canvas_to_selection(SPDesktop *desktop, bool with_margins) { g_return_val_if_fail(desktop != NULL, false); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); g_return_val_if_fail(doc != NULL, false); g_return_val_if_fail(desktop->selection != NULL, false); @@ -4283,7 +4279,7 @@ void verb_fit_canvas_to_selection(SPDesktop *const desktop) { if (fit_canvas_to_selection(desktop)) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION, + DocumentUndo::done(desktop->getDocument(), SP_VERB_FIT_CANVAS_TO_SELECTION, _("Fit Page to Selection")); } } @@ -4311,8 +4307,8 @@ fit_canvas_to_drawing(SPDocument *doc, bool with_margins) void verb_fit_canvas_to_drawing(SPDesktop *desktop) { - if (fit_canvas_to_drawing(sp_desktop_document(desktop))) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_DRAWING, + if (fit_canvas_to_drawing(desktop->getDocument())) { + DocumentUndo::done(desktop->getDocument(), SP_VERB_FIT_CANVAS_TO_DRAWING, _("Fit Page to Drawing")); } } @@ -4324,7 +4320,7 @@ verb_fit_canvas_to_drawing(SPDesktop *desktop) */ void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) { g_return_if_fail(desktop != NULL); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); g_return_if_fail(doc != NULL); g_return_if_fail(desktop->selection != NULL); @@ -4333,7 +4329,7 @@ void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) { ? fit_canvas_to_drawing(doc, true) : fit_canvas_to_selection(desktop, true) ); if (changed) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, + DocumentUndo::done(desktop->getDocument(), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, _("Fit Page to Selection or Drawing")); } }; diff --git a/src/selection.cpp b/src/selection.cpp index 17b7253f2..81139d044 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -20,7 +20,7 @@ # include <config.h> #endif #include "macros.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "document.h" #include "layer-model.h" #include "selection.h" @@ -89,7 +89,7 @@ Selection::_emit_modified(Selection *selection) } void Selection::_emitModified(guint flags) { - inkscape_selection_modified(this, flags); + INKSCAPE.selection_modified(this, flags); _modified_signal.emit(this, flags); } @@ -104,7 +104,7 @@ void Selection::_emitChanged(bool persist_selection_context/* = false */) { _releaseContext(_selection_context); } - inkscape_selection_changed(this); + INKSCAPE.selection_changed(this); _changed_signal.emit(this); } diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 96c7fb49b..5e4c0642e 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -26,7 +26,7 @@ #include "document-undo.h" #include "sp-namedview.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "knot.h" #include "message-stack.h" @@ -131,9 +131,9 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _makeHandles(); _updateHandles(); - _selection = sp_desktop_selection(desktop); + _selection = desktop->getSelection(); - _norm = sp_canvas_item_new(sp_desktop_controls(desktop), + _norm = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "mode", SP_CTRL_MODE_COLOR, @@ -146,7 +146,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : "pixbuf", handles[12], NULL); - _grip = sp_canvas_item_new(sp_desktop_controls(desktop), + _grip = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "mode", SP_CTRL_MODE_XOR, @@ -163,7 +163,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : sp_canvas_item_hide(_norm); for (int i = 0; i < 4; i++) { - _l[i] = ControlManager::getManager().createControlLine(sp_desktop_controls(desktop)); + _l[i] = ControlManager::getManager().createControlLine(desktop->getControls()); sp_canvas_item_hide(_l[i]); } @@ -252,7 +252,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s { // While dragging a handle, we will either scale, skew, or rotate and the "translating" parameter will be false // When dragging the selected item itself however, we will translate the selection and that parameter will be true - Inkscape::Selection *selection = sp_desktop_selection(_desktop); + Inkscape::Selection *selection = _desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); g_return_if_fail(!_grabbed); @@ -418,7 +418,7 @@ void Inkscape::SelTrans::ungrab() _desktop->snapindicator->remove_snapsource(); - Inkscape::Selection *selection = sp_desktop_selection(_desktop); + Inkscape::Selection *selection = _desktop->getSelection(); _updateVolatileState(); for (unsigned i = 0; i < _items.size(); i++) { @@ -473,16 +473,16 @@ void Inkscape::SelTrans::ungrab() // when trying to stretch a perfectly vertical line in horizontal direction, which will not be allowed // by the handles; this would be identified as a (zero) translation by isTranslation() if (_current_relative_affine.isTranslation()) { - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Move")); } else if (_current_relative_affine.withoutTranslation().isScale()) { - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Scale")); } else if (_current_relative_affine.withoutTranslation().isRotation()) { - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Rotate")); } else { - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Skew")); } } @@ -495,7 +495,7 @@ void Inkscape::SelTrans::ungrab() SPItem *it = SP_ITEM(l->data); it->updateRepr(); } - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Set center")); } @@ -512,7 +512,7 @@ void Inkscape::SelTrans::ungrab() void Inkscape::SelTrans::stamp() { - Inkscape::Selection *selection = sp_desktop_selection(_desktop); + Inkscape::Selection *selection = _desktop->getSelection(); bool fixup = !_grabbed; if ( fixup && _stamp_cache ) { @@ -549,7 +549,7 @@ void Inkscape::SelTrans::stamp() // move to the saved position copy_repr->setPosition(pos > 0 ? pos : 0); - SPItem *copy_item = (SPItem *) sp_desktop_document(_desktop)->getObjectByRepr(copy_repr); + SPItem *copy_item = (SPItem *) _desktop->getDocument()->getObjectByRepr(copy_repr); Geom::Affine const *new_affine; if (_show == SHOW_OUTLINE) { @@ -570,7 +570,7 @@ void Inkscape::SelTrans::stamp() Inkscape::GC::release(copy_repr); l = l->next; } - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Stamp")); } @@ -606,7 +606,7 @@ void Inkscape::SelTrans::_updateHandles() void Inkscape::SelTrans::_updateVolatileState() { - Inkscape::Selection *selection = sp_desktop_selection(_desktop); + Inkscape::Selection *selection = _desktop->getSelection(); _empty = selection->isEmpty(); if (_empty) { @@ -719,7 +719,7 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa _center_is_set = false; // center has changed _updateHandles(); } - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Reset center")); } break; @@ -1306,8 +1306,8 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // status text Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px"); - GString *xs = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str()); - GString *ys = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str()); + GString *xs = g_string_new(x_q.string(_desktop->namedview->display_units).c_str()); + GString *ys = g_string_new(y_q.string(_desktop->namedview->display_units).c_str()); _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str); g_string_free(xs, FALSE); g_string_free(ys, FALSE); @@ -1460,8 +1460,8 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) // status text Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px"); - GString *xs = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str()); - GString *ys = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str()); + GString *xs = g_string_new(x_q.string(_desktop->namedview->display_units).c_str()); + GString *ys = g_string_new(y_q.string(_desktop->namedview->display_units).c_str()); _message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str); g_string_free(xs, TRUE); g_string_free(ys, TRUE); diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp index 1e43c98c6..e72c16de0 100644 --- a/src/shortcuts.cpp +++ b/src/shortcuts.cpp @@ -211,7 +211,7 @@ Inkscape::XML::Document *sp_shortcut_create_template_file(char const *filename) void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<Glib::ustring> *paths) { std::list<gchar *> sources; - sources.push_back( profile_path("keys") ); + sources.push_back( Inkscape::Application::profile_path("keys") ); sources.push_back( g_strdup(INKSCAPE_KEYSDIR) ); // loop through possible keyboard shortcut file locations. @@ -229,7 +229,7 @@ void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<G gchar *filename = 0; while ((filename = (gchar *) g_dir_read_name(directory)) != NULL) { gchar* lower = g_ascii_strdown(filename, -1); - if (!strcmp(dirname, profile_path("keys")) && + if (!strcmp(dirname, Inkscape::Application::profile_path("keys")) && !strcmp(lower, "default.xml")) { // Dont add the users custom keys file continue; diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index 8e2e7d7a6..5065f25c3 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -103,7 +103,7 @@ void SPClipPath::set(unsigned int key, const gchar* value) { break; default: if (SP_ATTRIBUTE_IS_CSS(key)) { - sp_style_read_from_object(this->style, this); + this->style->readFromObject( this ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { SPObjectGroup::set(key, value); diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 766026980..6d2385aff 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -14,7 +14,7 @@ #include "inkscape.h" #include "document.h" #include "selection.h" -#include "desktop-handles.h" + #include "desktop.h" #include "xml/repr.h" @@ -525,10 +525,10 @@ Inkscape::XML::Node *SPFlowtext::getAsText() Glib::ustring::iterator span_text_start_iter; this->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter); SPObject *source_obj = reinterpret_cast<SPObject *>(rawptr); - gchar *style_text = sp_style_write_difference((dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style, this->style); - if (style_text && *style_text) { - span_tspan->setAttribute("style", style_text); - g_free(style_text); + + Glib::ustring style_text = (dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, this->style); + if (!style_text.empty()) { + span_tspan->setAttribute("style", style_text.c_str()); } SPString *str = dynamic_cast<SPString *>(source_obj); @@ -620,7 +620,7 @@ bool SPFlowtext::has_internal_frame() const SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, Geom::Point p0, Geom::Point p1) { - SPDocument *doc = sp_desktop_document (desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *root_repr = xml_doc->createElement("svg:flowRoot"); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 581c8a440..3eecb2783 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -22,7 +22,7 @@ #include <algorithm> #include <cstring> #include <string> -#include "desktop-handles.h" + #include "display/sp-canvas.h" #include "display/guideline.h" #include "svg/svg.h" @@ -37,6 +37,7 @@ #include <remove-last.h> #include "inkscape.h" #include "desktop.h" +#include "sp-root.h" #include "sp-namedview.h" #include <2geom/angle.h> #include "document.h" @@ -152,6 +153,12 @@ void SPGuide::set(unsigned int key, const gchar *value) { success += sp_svg_number_read_d(strarray[1], &newy); g_strfreev (strarray); if (success == 2) { + // If root viewBox set, interpret guides in terms of viewBox (90/96) + SPRoot *root = document->getRoot(); + if( root->viewBox_set ) { + newx = newx * root->width.computed / root->viewBox.width(); + newy = newy * root->height.computed / root->viewBox.height(); + } this->point_on_line = Geom::Point(newx, newy); } else if (success == 1) { // before 0.46 style guideline definition. @@ -185,7 +192,17 @@ SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::P Geom::Point n = Geom::rot90(pt2 - pt1); - sp_repr_set_point(repr, "position", pt1); + // If root viewBox set, interpret guides in terms of viewBox (90/96) + double newx = pt1.x(); + double newy = pt1.y(); + + SPRoot *root = doc->getRoot(); + if( root->viewBox_set ) { + newx = newx * root->viewBox.width() / root->width.computed; + newy = newy * root->viewBox.height() / root->height.computed; + } + + sp_repr_set_point(repr, "position", Geom::Point( newx, newy )); sp_repr_set_point(repr, "orientation", n); SPNamedView *namedview = sp_document_namedview(doc, NULL); @@ -207,7 +224,7 @@ void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Poin void sp_guide_create_guides_around_page(SPDesktop *dt) { - SPDocument *doc=sp_desktop_document(dt); + SPDocument *doc=dt->getDocument(); std::list<std::pair<Geom::Point, Geom::Point> > pts; Geom::Point A(0, 0); @@ -227,7 +244,7 @@ void sp_guide_create_guides_around_page(SPDesktop *dt) void sp_guide_delete_all_guides(SPDesktop *dt) { - SPDocument *doc=sp_desktop_document(dt); + SPDocument *doc=dt->getDocument(); const GSList *current; while ( (current = doc->getResourceList("guide")) ) { SPGuide* guide = SP_GUIDE(current->data); @@ -318,8 +335,18 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ if (commit) { + // If root viewBox set, interpret guides in terms of viewBox (90/96) + double newx = point_on_line.x(); + double newy = point_on_line.y(); + + SPRoot *root = document->getRoot(); + if( root->viewBox_set ) { + newx = newx * root->viewBox.width() / root->width.computed; + newy = newy * root->viewBox.height() / root->height.computed; + } + //XML Tree being used here directly while it shouldn't be. - sp_repr_set_point(getRepr(), "position", point_on_line); + sp_repr_set_point(getRepr(), "position", Geom::Point(newx, newy) ); } /* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) @@ -410,8 +437,8 @@ char* SPGuide::description(bool const verbose) const Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(this->point_on_line[X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(this->point_on_line[Y], "px"); - GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str()); - GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str()); + GString *position_string_x = g_string_new(x_q.string(namedview->display_units).c_str()); + GString *position_string_y = g_string_new(y_q.string(namedview->display_units).c_str()); gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete")); diff --git a/src/sp-hatch-path.cpp b/src/sp-hatch-path.cpp index 8558b67f2..bc95c246e 100644 --- a/src/sp-hatch-path.cpp +++ b/src/sp-hatch-path.cpp @@ -128,7 +128,7 @@ void SPHatchPath::set(unsigned int key, const gchar* value) default: if (SP_ATTRIBUTE_IS_CSS(key)) { - sp_style_read_from_object(style, this); + style->readFromObject( this ); requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { SPObject::set(key, value); diff --git a/src/sp-hatch.cpp b/src/sp-hatch.cpp index 4a8707e08..dfecb2250 100644 --- a/src/sp-hatch.cpp +++ b/src/sp-hatch.cpp @@ -238,7 +238,7 @@ void SPHatch::set(unsigned int key, const gchar* value) default: if (SP_ATTRIBUTE_IS_CSS(key)) { - sp_style_read_from_object(style, this); + style->readFromObject( this ); requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { SPPaintServer::set(key, value); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 992bca631..acf8b2012 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -40,7 +40,7 @@ #include "box3d.h" #include "persp3d.h" #include "inkscape.h" -#include "desktop-handles.h" + #include "selection.h" #include "live_effects/effect.h" #include "live_effects/lpeobject.h" @@ -159,6 +159,7 @@ void SPGroup::order_changed (Inkscape::XML::Node *child, Inkscape::XML::Node *ol } void SPGroup::update(SPCtx *ctx, unsigned int flags) { + // std::cout << "SPGroup::update(): " << (getId()?getId():"null") << std::endl; SPItemCtx *ictx, cctx; ictx = (SPItemCtx *) ctx; @@ -199,12 +200,16 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *group = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); - group->setStyle(this->style); + if( this->parent ) { + this->context_style = this->parent->context_style; + } + group->setStyle(this->style, this->context_style); } } } void SPGroup::modified(guint flags) { + // std::cout << "SPGroup::modified(): " << (getId()?getId():"null") << std::endl; SPLPEItem::modified(flags); SPObject *child; @@ -352,11 +357,15 @@ void SPGroup::set(unsigned int key, gchar const* value) { } Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + // std::cout << "SPGroup::show(): " << (getId()?getId():"null") << std::endl; Inkscape::DrawingGroup *ai; ai = new Inkscape::DrawingGroup(drawing); ai->setPickChildren(this->effectiveLayerMode(key) == SPGroup::LAYER); - ai->setStyle(this->style); + if( this->parent ) { + this->context_style = this->parent->context_style; + } + ai->setStyle(this->style, this->context_style); this->_showChildren(drawing, ai, key, flags); return ai; @@ -435,7 +444,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) // it here _before_ the new transform is set, so as to use the pre-transform bbox citem->adjust_paint_recursive (Geom::identity(), Geom::identity(), false); - sp_style_merge_from_dying_parent(child->style, group->style); + child->style->merge( group->style ); /* * fixme: We currently make no allowance for the case where child is cloned * and the group has any style settings. @@ -444,9 +453,8 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) * version of inkscape without using the XML editor: we usually apply group * style changes to children rather than to the group itself.) * - * If the group has no style settings, then - * sp_style_merge_from_dying_parent should be a no-op. Otherwise (i.e. if - * we change the child's style to compensate for its parent going away) + * If the group has no style settings, then style->merge() should be a no-op. Otherwise + * (i.e. if we change the child's style to compensate for its parent going away) * then those changes will typically be reflected in any clones of child, * whereas we'd prefer for Ungroup not to affect the visual appearance. * diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 73347fc4e..fbb76e971 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -25,7 +25,7 @@ #include "uri.h" #include "inkscape.h" #include "desktop.h" -#include "desktop-handles.h" + #include "style.h" #include <glibmm/i18n.h> @@ -555,7 +555,7 @@ void SPItem::set(unsigned int key, gchar const* value) { } default: if (SP_ATTRIBUTE_IS_CSS(key)) { - sp_style_read_from_object(object->style, object); + style->readFromObject( this ); object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { SPObject::set(key, value); @@ -1006,7 +1006,7 @@ void SPItem::getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscap clips_and_masks.push_back(clip_ref->getObject()); clips_and_masks.push_back(mask_ref->getObject()); - SPDesktop *desktop = inkscape_active_desktop(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); ++o) { if (*o) { // obj is a group object, the children are the actual clippers @@ -1607,7 +1607,7 @@ Geom::Affine SPItem::i2doc_affine() const Geom::Affine SPItem::i2dt_affine() const { Geom::Affine ret; - SPDesktop const *desktop = inkscape_active_desktop(); + SPDesktop const *desktop = SP_ACTIVE_DESKTOP; if ( desktop ) { ret = i2doc_affine() * desktop->doc2dt(); } else { @@ -1625,7 +1625,7 @@ void SPItem::set_i2d_affine(Geom::Affine const &i2dt) if (parent) { dt2p = static_cast<SPItem *>(parent)->i2dt_affine().inverse(); } else { - SPDesktop *dt = inkscape_active_desktop(); + SPDesktop *dt = SP_ACTIVE_DESKTOP; dt2p = dt->dt2doc(); } diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 019d15162..f059ab531 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -58,8 +58,8 @@ static void sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem); static void sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem); typedef std::list<std::string> HRefList; -static std::string patheffectlist_write_svg(PathEffectList const & list); -static std::string hreflist_write_svg(HRefList const & list); +static std::string patheffectlist_svg_string(PathEffectList const & list); +static std::string hreflist_svg_string(HRefList const & list); SPLPEItem::SPLPEItem() : SPItem() @@ -195,8 +195,7 @@ void SPLPEItem::modified(unsigned int flags) { Inkscape::XML::Node* SPLPEItem::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_EXT) { if ( hasPathEffect() ) { - std::string href = patheffectlist_write_svg(*this->path_effect_list); - repr->setAttribute("inkscape:path-effect", href.c_str()); + repr->setAttribute("inkscape:path-effect", patheffectlist_svg_string(*this->path_effect_list)); } else { repr->setAttribute("inkscape:path-effect", NULL); } @@ -418,9 +417,9 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) } } -void SPLPEItem::addPathEffect(gchar *value, bool reset) +void SPLPEItem::addPathEffect(std::string value, bool reset) { - if (value) { + if (!value.empty()) { // Apply the path effects here because in the casse of a group, lpe->resetDefaults // needs that all the subitems have their effects applied sp_lpe_item_update_patheffect(this, false, true); @@ -434,10 +433,9 @@ void SPLPEItem::addPathEffect(gchar *value, bool reset) { hreflist.push_back( std::string((*it)->lpeobject_href) ); } - hreflist.push_back( std::string(value) ); - std::string hrefs = hreflist_write_svg(hreflist); + hreflist.push_back(value); // C++11: should be emplace_back std::move'd (also the reason why passed by value to addPathEffect) - this->getRepr()->setAttribute("inkscape:path-effect", hrefs.c_str()); + this->getRepr()->setAttribute("inkscape:path-effect", hreflist_svg_string(hreflist)); // Make sure that ellipse is stored as <svg:path> if( SP_IS_GENERICELLIPSE(this)) { @@ -501,13 +499,7 @@ void SPLPEItem::removeCurrentPathEffect(bool keep_paths) } PathEffectList new_list = *this->path_effect_list; new_list.remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list - std::string r = patheffectlist_write_svg(new_list); - - if (!r.empty()) { - this->getRepr()->setAttribute("inkscape:path-effect", r.c_str()); - } else { - this->getRepr()->setAttribute("inkscape:path-effect", NULL); - } + this->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); if (!keep_paths) { // Make sure that ellipse is stored as <svg:circle> or <svg:ellipse> if possible. @@ -551,8 +543,8 @@ void SPLPEItem::downCurrentPathEffect() std::iter_swap(cur_it, down_it); } } - std::string r = patheffectlist_write_svg(new_list); - this->getRepr()->setAttribute("inkscape:path-effect", r.c_str()); + + this->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); sp_lpe_item_cleanup_original_path_recursive(this); } @@ -570,9 +562,8 @@ void SPLPEItem::upCurrentPathEffect() --up_it; std::iter_swap(cur_it, up_it); } - std::string r = patheffectlist_write_svg(new_list); - this->getRepr()->setAttribute("inkscape:path-effect", r.c_str()); + this->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); sp_lpe_item_cleanup_original_path_recursive(this); } @@ -862,16 +853,16 @@ void SPLPEItem::remove_child(Inkscape::XML::Node * child) { SPItem::remove_child(child); } -static std::string patheffectlist_write_svg(PathEffectList const & list) +static std::string patheffectlist_svg_string(PathEffectList const & list) { HRefList hreflist; for (PathEffectList::const_iterator it = list.begin(); it != list.end(); ++it) { - hreflist.push_back( std::string((*it)->lpeobject_href) ); + hreflist.push_back( std::string((*it)->lpeobject_href) ); // C++11: use emplace_back } - return hreflist_write_svg(hreflist); + return hreflist_svg_string(hreflist); } /** @@ -881,7 +872,7 @@ static std::string patheffectlist_write_svg(PathEffectList const & list) * - populate the templist with the effects from the old list that you want to have and their order * - call this function with temp list as param */ -static std::string hreflist_write_svg(HRefList const & list) +static std::string hreflist_svg_string(HRefList const & list) { std::string r; bool semicolon_first = false; @@ -968,8 +959,7 @@ void SPLPEItem::replacePathEffects( std::vector<LivePathEffectObject const *> co } } - std::string r = hreflist_write_svg(hreflist); - this->getRepr()->setAttribute("inkscape:path-effect", r.c_str()); + this->getRepr()->setAttribute("inkscape:path-effect", hreflist_svg_string(hreflist)); } /** diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index 9c052b7b1..902271430 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -15,6 +15,7 @@ */ #include <list> +#include <string> #include "sp-item.h" #define SP_LPE_ITEM(obj) (dynamic_cast<SPLPEItem*>((SPObject*)obj)) @@ -88,7 +89,7 @@ public: bool setCurrentPathEffect(Inkscape::LivePathEffect::LPEObjectReference* lperef); void removeCurrentPathEffect(bool keep_paths); void removeAllPathEffects(bool keep_paths); - void addPathEffect(char *value, bool reset); + void addPathEffect(std::string value, bool reset); void addPathEffect(LivePathEffectObject * new_lpeobj); void apply_to_mask(SPItem * item); void apply_to_clippath(SPItem * item); diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index e955594ab..371a6c35c 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -29,13 +29,19 @@ #include "document-private.h" #include "preferences.h" -struct SPMarkerView { - SPMarkerView *next; - unsigned int key; - std::vector<Inkscape::DrawingItem *> items; -}; +class SPMarkerView { -static void sp_marker_view_remove (SPMarker *marker, SPMarkerView *view, unsigned int destroyitems); +public: + + SPMarkerView() {}; + ~SPMarkerView() { + for (unsigned int i = 0; i < items.size(); ++i) { + delete items[i]; + } + items.clear(); + } + std::vector<Inkscape::DrawingItem *> items; +}; #include "sp-factory.h" @@ -55,8 +61,6 @@ SPMarker::SPMarker() : SPGroup(), SPViewBox() { this->orient_mode = MARKER_ORIENT_ANGLE; this->orient_set = 0; this->orient = 0; - - this->views = NULL; } /** @@ -90,20 +94,6 @@ void SPMarker::build(SPDocument *document, Inkscape::XML::Node *repr) { SPGroup::build(document, repr); } -void SPMarker::release() { - while (this->views) { - // Destroy all DrawingItems etc. - // Parent class ::hide method - //reinterpret_cast<SPItemClass *>(parent_class)->hide(marker, marker->views->key); - // CPPIFY: correct one? - SPGroup::hide(this->views->key); - - - sp_marker_view_remove (this, this->views, TRUE); - } - - SPGroup::release(); -} /** * Removes, releases and unrefs all children of object @@ -117,6 +107,17 @@ void SPMarker::release() { * * \see SPObject::release() */ +void SPMarker::release() { + + std::map<unsigned int, SPMarkerView>::iterator it; + for (it = views_map.begin(); it != views_map.end(); ++it) { + SPGroup::hide( it->first ); + } + views_map.clear(); + + SPGroup::release(); +} + void SPMarker::set(unsigned int key, const gchar* value) { switch (key) { @@ -168,9 +169,12 @@ void SPMarker::set(unsigned int key, const gchar* value) { } else if (!strcmp (value, "auto-start-reverse")) { this->orient_mode = MARKER_ORIENT_AUTO_START_REVERSE; this->orient_set = TRUE; - } else if (sp_svg_number_read_f (value, &this->orient)) { - this->orient_mode = MARKER_ORIENT_ANGLE; - this->orient_set = TRUE; + } else { + orient.readOrUnset(value); + if (orient._set) { + this->orient_mode = MARKER_ORIENT_ANGLE; + this->orient_set = orient._set; + } } } @@ -218,10 +222,11 @@ void SPMarker::update(SPCtx *ctx, guint flags) { SPGroup::update((SPCtx *) &rctx, flags); // As last step set additional transform of drawing group - for (SPMarkerView *v = this->views; v != NULL; v = v->next) { - for (unsigned i = 0 ; i < v->items.size() ; i++) { - if (v->items[i]) { - Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->items[i]); + std::map<unsigned int, SPMarkerView>::iterator it; + for (it = views_map.begin(); it != views_map.end(); ++it) { + for (unsigned i = 0 ; i < it->second.items.size() ; ++i) { + if (it->second.items[i]) { + Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(it->second.items[i]); g->setChildTransform(this->c2p); } } @@ -273,7 +278,7 @@ Inkscape::XML::Node* SPMarker::write(Inkscape::XML::Document *xml_doc, Inkscape: } else if (this->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) { repr->setAttribute("orient", "auto-start-reverse"); } else { - sp_repr_set_css_double(repr, "orient", this->orient); + sp_repr_set_css_double(repr, "orient", this->orient.computed); } } else { repr->setAttribute("orient", NULL); @@ -325,31 +330,26 @@ void SPMarker::print(SPPrintContext* /*ctx*/) { * \param key Key to give each SPMarkerView. * \param size Number of DrawingItems to put in the SPMarkerView. */ +// If marker views are always created in order, then this function could be eliminated +// by doing the push_back in sp_marker_show_instance. void sp_marker_show_dimension (SPMarker *marker, unsigned int key, unsigned int size) { - SPMarkerView *view; - - for (view = marker->views; view != NULL; view = view->next) { - if (view->key == key) break; - } - if (view && (view->items.size() != size)) { - /* Free old view and allocate new */ - /* Parent class ::hide method */ - marker->hide(key); - - sp_marker_view_remove (marker, view, TRUE); - view = NULL; - } - if (!view) { - view = new SPMarkerView(); - view->items.clear(); - for (unsigned int i = 0; i < size; i++) { - view->items.push_back(NULL); + std::map<unsigned int, SPMarkerView>::iterator it = marker->views_map.find(key); + if (it != marker->views_map.end()) { + if (it->second.items.size() != size ) { + // Need to change size of vector! (We should not really need to do this.) + marker->hide(key); + it->second.items.clear(); + for (unsigned int i = 0; i < size; ++i) { + it->second.items.push_back(NULL); + } + } + } else { + marker->views_map[key] = SPMarkerView(); + for (unsigned int i = 0; i < size; ++i) { + marker->views_map[key].items.push_back(NULL); } - view->next = marker->views; - marker->views = view; - view->key = key; } } @@ -362,51 +362,58 @@ sp_marker_show_instance ( SPMarker *marker, Inkscape::DrawingItem *parent, unsigned int key, unsigned int pos, Geom::Affine const &base, float linewidth) { - // do not show marker if linewidth == 0 and markerUnits == strokeWidth + // Do not show marker if linewidth == 0 and markerUnits == strokeWidth // otherwise Cairo will fail to render anything on the tile - // that contains the "degenerate" marker + // that contains the "degenerate" marker. if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH && linewidth == 0) { return NULL; } - for (SPMarkerView *v = marker->views; v != NULL; v = v->next) { - if (v->key == key) { - if (pos >= v->items.size()) { - return NULL; - } - if (!v->items[pos]) { - /* Parent class ::show method */ - v->items[pos] = marker->private_show(parent->drawing(), key, SP_ITEM_REFERENCE_FLAGS); - - if (v->items[pos]) { - /* fixme: Position (Lauris) */ - parent->prependChild(v->items[pos]); - Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->items[pos]); - if (g) g->setChildTransform(marker->c2p); - } - } - if (v->items[pos]) { - Geom::Affine m; - if (marker->orient_mode == MARKER_ORIENT_AUTO) { - m = base; - } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) { - m = Geom::Rotate::from_degrees( 180.0 ) * base; - m = base; - } else { - /* fixme: Orient units (Lauris) */ - m = Geom::Rotate::from_degrees(marker->orient); - m *= Geom::Translate(base.translation()); - } - if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { - m = Geom::Scale(linewidth) * m; - } - v->items[pos]->setTransform(m); - } - return v->items[pos]; + std::map<unsigned int, SPMarkerView>::iterator it = marker->views_map.find(key); + if (it == marker->views_map.end()) { + // Key not found + return NULL; + } + + SPMarkerView *view = &(it->second); + if (pos >= view->items.size() ) { + // Position index too large, doesn't exist. + return NULL; + } + + // If not already created + if (view->items[pos] == NULL) { + + /* Parent class ::show method */ + view->items[pos] = marker->private_show(parent->drawing(), key, SP_ITEM_REFERENCE_FLAGS); + + if (view->items[pos]) { + /* fixme: Position (Lauris) */ + parent->prependChild(view->items[pos]); + Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(view->items[pos]); + if (g) g->setChildTransform(marker->c2p); + } + } + + if (view->items[pos]) { + Geom::Affine m; + if (marker->orient_mode == MARKER_ORIENT_AUTO) { + m = base; + } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) { + m = Geom::Rotate::from_degrees( 180.0 ) * base; + m = base; + } else { + /* fixme: Orient units (Lauris) */ + m = Geom::Rotate::from_degrees(marker->orient.computed); + m *= Geom::Translate(base.translation()); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { + m = Geom::Scale(linewidth) * m; + } + view->items[pos]->setTransform(m); } - return NULL; + return view->items[pos]; } /** @@ -417,46 +424,10 @@ sp_marker_show_instance ( SPMarker *marker, Inkscape::DrawingItem *parent, void sp_marker_hide (SPMarker *marker, unsigned int key) { - SPMarkerView *v; - - v = marker->views; - while (v != NULL) { - SPMarkerView *next; - next = v->next; - if (v->key == key) { - /* Parent class ::hide method */ - marker->hide(key); - - sp_marker_view_remove (marker, v, TRUE); - return; - } - v = next; - } + marker->hide(key); + marker->views_map.erase(key); } -/** - * Removes a given view. Also will destroy sub-items in the view if destroyitems - * is set to a non-zero value. - */ -static void -sp_marker_view_remove (SPMarker *marker, SPMarkerView *view, unsigned int destroyitems) -{ - if (view == marker->views) { - marker->views = view->next; - } else { - SPMarkerView *v; - for (v = marker->views; v->next != view; v = v->next) if (!v->next) return; - v->next = view->next; - } - if (destroyitems) { - for (unsigned int i = 0; i < view->items.size(); i++) { - /* We have to walk through the whole array because there may be hidden items */ - delete view->items[i]; - } - } - view->items.clear(); - delete view; -} const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) { diff --git a/src/sp-marker.h b/src/sp-marker.h index b58523251..e804fd7dc 100644 --- a/src/sp-marker.h +++ b/src/sp-marker.h @@ -21,13 +21,16 @@ #define SP_MARKER(obj) (dynamic_cast<SPMarker*>((SPObject*)obj)) #define SP_IS_MARKER(obj) (dynamic_cast<const SPMarker*>((SPObject*)obj) != NULL) -struct SPMarkerView; +class SPMarkerView; + +#include <map> #include <2geom/rect.h> #include <2geom/affine.h> #include "enums.h" #include "svg/svg-length.h" +#include "svg/svg-angle.h" #include "sp-item-group.h" #include "uri-references.h" #include "viewbox.h" @@ -58,10 +61,15 @@ public: /* orient */ unsigned int orient_set : 1; markerOrient orient_mode : 2; - float orient; - - /* Private views */ - SPMarkerView *views; + SVGAngle orient; + + /* Private views indexed by key that corresponds to a + * particular marker type (start, mid, end) on a particular + * path. SPMarkerView is a wrapper for a vector of pointers to + * Inkscape::DrawingItem instances, one pointer for each + * rendered marker. + */ + std::map<unsigned int, SPMarkerView> views_map; virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index b68421dc6..dc36e68b9 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -29,7 +29,7 @@ #include "document.h" #include "document-undo.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "sp-guide.h" #include "sp-item-group.h" #include "sp-namedview.h" @@ -76,7 +76,9 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) { this->window_x = 0; this->cy = 0; this->window_y = 0; - this->doc_units = NULL; + this->svg_units = unit_table.getUnit("px"); // legacy behavior: if no viewbox present, default to 'px' units + this->display_units = NULL; + this->page_size_units = NULL; this->pagecolor = 0; this->cx = 0; this->pageshadow = 0; @@ -262,6 +264,14 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) { // backwards compatibility with grid settings (pre 0.46) sp_namedview_generate_old_grid(this, document, repr); + + // If viewbox defined: try to calculate the SVG unit from document width and viewbox + if (document->getRoot()->viewBox_set) { + Inkscape::Util::Quantity svgwidth = document->getWidth(); + Geom::Rect viewbox = document->getRoot()->viewBox; + double factor = svgwidth.value(unit_table.primary(Inkscape::Util::UNIT_TYPE_LINEAR)) / viewbox.width(); + svg_units = unit_table.findUnit(factor, Inkscape::Util::UNIT_TYPE_LINEAR); + } } void SPNamedView::release() { @@ -540,22 +550,13 @@ void SPNamedView::set(unsigned int key, const gchar* value) { this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_DOCUMENT_UNITS: { - /* The default unit if the document doesn't override this: e.g. for files saved as + /* The default display unit if the document doesn't override this: e.g. for files saved as * `plain SVG', or non-inkscape files, or files created by an inkscape 0.40 & * earlier. * - * Here we choose `px': useful for screen-destined SVGs, and fewer bug reports - * about "not the same numbers as what's in the SVG file" (at least for documents - * without a viewBox attribute on the root <svg> element). Similarly, it's also - * the most reliable unit (i.e. least likely to be wrong in different viewing - * conditions) for viewBox-less SVG files given that it's the unit that inkscape - * uses for all coordinates. + * Note that these units are not the same as the units used for the values in SVG! * - * For documents that do have a viewBox attribute on the root <svg> element, it - * might be better if we used either viewBox coordinates or if we used the unit of - * say the width attribute of the root <svg> element. However, these pose problems - * in that they aren't in general absolute units as currently required by - * doc_units. + * We default to `px'. */ static Inkscape::Util::Unit const *px = unit_table.getUnit("px"); Inkscape::Util::Unit const *new_unit = px; @@ -576,7 +577,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { /* fixme: Don't use g_log (see above). */ } } - this->doc_units = new_unit; + this->display_units = new_unit; this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } @@ -675,7 +676,7 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r g->SPGuide::showSPGuide(static_cast<SPDesktop*>(l->data)->guides, (GCallback) sp_dt_guide_event); if (static_cast<SPDesktop*>(l->data)->guides_active) { - g->sensitize(sp_desktop_canvas(static_cast<SPDesktop*> (l->data)), TRUE); + g->sensitize((static_cast<SPDesktop*> (l->data))->getCanvas(), TRUE); } sp_namedview_show_single_guide(SP_GUIDE(g), this->showguides); @@ -733,7 +734,7 @@ void SPNamedView::show(SPDesktop *desktop) for (GSList *l = guides; l != NULL; l = l->next) { SP_GUIDE(l->data)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event); if (desktop->guides_active) { - SP_GUIDE(l->data)->sensitize(sp_desktop_canvas(desktop), TRUE); + SP_GUIDE(l->data)->sensitize(desktop->getCanvas(), TRUE); } sp_namedview_show_single_guide(SP_GUIDE(l->data), showguides); } @@ -839,7 +840,7 @@ void sp_namedview_window_from_document(SPDesktop *desktop) && nv->cx != HUGE_VAL && !IS_NAN(nv->cx) && nv->cy != HUGE_VAL && !IS_NAN(nv->cy)) { desktop->zoom_absolute(nv->cx, nv->cy, nv->zoom); - } else if (sp_desktop_document(desktop)) { // document without saved zoom, zoom to its page + } else if (desktop->getDocument()) { // document without saved zoom, zoom to its page desktop->zoom_page(); } @@ -899,8 +900,8 @@ void sp_namedview_document_from_window(SPDesktop *desktop) Geom::Rect const r = desktop->get_display_area(); // saving window geometry is not undoable - bool saved = DocumentUndo::getUndoSensitive(sp_desktop_document(desktop)); - DocumentUndo::setUndoSensitive(sp_desktop_document(desktop), false); + bool saved = DocumentUndo::getUndoSensitive(desktop->getDocument()); + DocumentUndo::setUndoSensitive(desktop->getDocument(), false); if (save_viewport_in_file) { sp_repr_set_svg_double(view, "inkscape:zoom", desktop->current_zoom()); @@ -921,7 +922,7 @@ void sp_namedview_document_from_window(SPDesktop *desktop) view->setAttribute("inkscape:current-layer", desktop->currentLayer()->getId()); // restore undoability - DocumentUndo::setUndoSensitive(sp_desktop_document(desktop), saved); + DocumentUndo::setUndoSensitive(desktop->getDocument(), saved); } void SPNamedView::hide(SPDesktop const *desktop) @@ -930,7 +931,7 @@ void SPNamedView::hide(SPDesktop const *desktop) g_assert(g_slist_find(views, desktop)); for (GSList *l = guides; l != NULL; l = l->next) { - SP_GUIDE(l->data)->hideSPGuide(sp_desktop_canvas(desktop)); + SP_GUIDE(l->data)->hideSPGuide(desktop->getCanvas()); } views = g_slist_remove(views, desktop); @@ -944,7 +945,7 @@ void SPNamedView::activateGuides(void* desktop, bool active) SPDesktop *dt = static_cast<SPDesktop*>(desktop); for (GSList *l = guides; l != NULL; l = l->next) { - SP_GUIDE(l->data)->sensitize( sp_desktop_canvas(dt), active); + SP_GUIDE(l->data)->sensitize(dt->getCanvas(), active); } } @@ -1129,11 +1130,17 @@ double SPNamedView::getMarginLength(gchar const * const key, /** * Returns namedview's default unit. - * If no default unit is set, "pt" is returned + * If no default unit is set, "px" is returned */ -Inkscape::Util::Unit const * SPNamedView::getDefaultUnit() const +Inkscape::Util::Unit const * SPNamedView::getDisplayUnit() const +{ + return display_units ? display_units : unit_table.getUnit("px"); +} + +Inkscape::Util::Unit const & SPNamedView::getSVGUnit() const { - return doc_units ? doc_units : unit_table.getUnit("pt"); + assert(svg_units); + return *svg_units; } /** diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 4746b2962..f1ecc12d3 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -61,7 +61,8 @@ public: GSList * grids; bool grids_visible; - Inkscape::Util::Unit const *doc_units; + Inkscape::Util::Unit const *svg_units; // Units used for the values in SVG + Inkscape::Util::Unit const *display_units; // Units used for the UI (*not* the same as units of SVG coordinates) Inkscape::Util::Unit const *page_size_units; // Only used in "Custom size" part of Document Properties dialog GQuark default_layer_id; @@ -85,7 +86,8 @@ public: char const *getName() const; unsigned int getViewCount(); GSList const *getViewList() const; - Inkscape::Util::Unit const * getDefaultUnit() const; + Inkscape::Util::Unit const * getDisplayUnit() const; + Inkscape::Util::Unit const & getSVGUnit() const; void translateGuides(Geom::Translate const &translation); void translateGrids(Geom::Translate const &translation); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 024fce85a..059fa8093 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -130,7 +130,8 @@ SPObject::SPObject() // vg, g, defs, desc, title, symbol, use, image, switch, path, rect, circle, ellipse, line, polyline, // polygon, text, tspan, tref, textPath, altGlyph, glyphRef, marker, linearGradient, radialGradient, // stop, pattern, clipPath, mask, filter, feImage, a, font, glyph, missing-glyph, foreignObject - this->style = sp_style_new_from_object(this); + this->style = new SPStyle( NULL, this ); // Is it necessary to call with "this"? + this->context_style = NULL; } SPObject::~SPObject() { @@ -144,6 +145,19 @@ SPObject::~SPObject() { sp_object_unref(this->_successor, NULL); this->_successor = NULL; } + + if( style == NULL ) { + // style pointer could be NULL if unreffed too many times. + // Conjecture: style pointer is never NULL. + std::cerr << "SPObject::~SPObject(): style pointer is NULL" << std::endl; + } else if( style->refCount() > 1 ) { + // Several classes ref style. + // Conjecture: style pointer should be unreffed by other classes before reaching here. + std::cerr << "SPObject::~SPObject(): someone else still holding ref to style" << std::endl; + sp_style_unref( this->style ); + } else { + delete this->style; + } } // CPPIFY: make pure virtual @@ -795,9 +809,10 @@ void SPObject::releaseReferences() { g_assert(!this->id); } - if (this->style) { - this->style = sp_style_unref(this->style); - } + // style belongs to SPObject, we should not need to unref here. + // if (this->style) { + // this->style = sp_style_unref(this->style); + // } this->document = NULL; this->repr = NULL; @@ -914,7 +929,7 @@ void SPObject::set(unsigned int key, gchar const* value) { object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; case SP_ATTR_STYLE: - sp_style_read_from_object(object->style, object); + object->style->readFromObject( object ); object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; default: @@ -1006,9 +1021,8 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML repr->setAttribute("inkscape:collect", NULL); } - SPStyle const *const obj_style = this->style; - if (obj_style) { - gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET); + if (style) { + Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. @@ -1016,17 +1030,14 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML if( prefs->getBool("/options/svgoutput/check_on_editing") ) { unsigned int flags = sp_attribute_clean_get_prefs(); - Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s, flags ); - g_free( s ); - s = (s_cleaned.empty() ? NULL : g_strdup (s_cleaned.c_str())); + Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s.c_str(), flags ); } - if( s == NULL || strcmp(s,"") == 0 ) { + if( s.empty() ) { repr->setAttribute("style", NULL); } else { - repr->setAttribute("style", s); + repr->setAttribute("style", s.c_str()); } - g_free(s); } else { /** \todo I'm not sure what to do in this case. Bug #1165868 @@ -1148,7 +1159,7 @@ void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags) */ if ((flags & SP_OBJECT_STYLE_MODIFIED_FLAG) && (flags & SP_OBJECT_PARENT_MODIFIED_FLAG)) { if (this->style && this->parent) { - sp_style_merge_from_parent(this->style, this->parent->style); + style->cascade( this->parent->style ); } } @@ -1254,6 +1265,16 @@ void SPObject::setAttribute(gchar const *key, gchar const *value, SPException *e //XML Tree being used here. getRepr()->setAttribute(key, value, false); } +void SPObject::setAttribute(char const *key, Glib::ustring const &value, SPException *ex) +{ + setAttribute(key, value.empty() ? NULL : value.c_str(), ex); +} +void SPObject::setAttribute(Glib::ustring const &key, Glib::ustring const &value, SPException *ex) +{ + setAttribute( key.empty() ? NULL : key.c_str(), + value.empty() ? NULL : value.c_str(), ex); +} + void SPObject::removeAttribute(gchar const *key, SPException *ex) { @@ -1513,6 +1534,22 @@ char* SPObject::textualContent() const return g_string_free(text, FALSE); } +// For debugging: Print SP tree structure. +void SPObject::recursivePrintTree( unsigned level ) +{ + if (level == 0) { + std::cout << "SP Object Tree" << std::endl; + } + std::cout << "SP: "; + for (unsigned i = 0; i < level; ++i) { + std::cout << " "; + } + std::cout << (getId()?getId():"No object id") << std::endl; + for (SPObject *child = children; child; child = child->next) { + child->recursivePrintTree( level+1 ); + } +} + /* Local Variables: mode:c++ diff --git a/src/sp-object.h b/src/sp-object.h index 575198f36..ff80eaefc 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -67,6 +67,9 @@ struct Document; } } +namespace Glib { + class ustring; +} typedef enum { SP_NO_EXCEPTION, @@ -264,6 +267,11 @@ public: */ SPStyle *style; + /** + * Represents the style that should be used to resolve 'context-fill' and 'context-stroke' + */ + SPStyle *context_style; + /// Switch containing next() method. struct ParentIteratorStrategy { static SPObject const *next(SPObject const *object) { @@ -703,7 +711,9 @@ public: */ void setKeyValue(unsigned int key, char const *value); - void setAttribute(char const *key, char const *value, SPException *ex=NULL); + void setAttribute( char const *key, char const *value, SPException *ex=NULL); + void setAttribute( char const *key, Glib::ustring const &value, SPException *ex=NULL); + void setAttribute(Glib::ustring const &key, Glib::ustring const &value, SPException *ex=NULL); /** * Read value of key attribute from XML node into object. @@ -849,6 +859,8 @@ protected: public: virtual void read_content(); + + void recursivePrintTree(unsigned level = 0); // For debugging }; diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 5c076b7cb..0fef57698 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -41,7 +41,7 @@ #include "document.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "ui/tools/tool-base.h" #include "inkscape.h" diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 12570e03e..85582e209 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -375,6 +375,15 @@ Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key g->setChildTransform(this->c2p); } + // Uncomment to print out XML tree + // getRepr()->recursivePrintTree(0); + + // Uncomment to print out SP Object tree + // recursivePrintTree(0); + + // Uncomment to print out Display Item tree + // ai->recursivePrintTree(0); + return ai; } diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 8b7e735e0..16f9ec13b 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -126,6 +126,7 @@ Inkscape::XML::Node* SPShape::write(Inkscape::XML::Document *xml_doc, Inkscape:: } void SPShape::update(SPCtx* ctx, guint flags) { + // std::cout << "SPShape::update(): " << (getId()?getId():"null") << std::endl; SPLPEItem::update(ctx, flags); /* This stanza checks that an object's marker style agrees with @@ -145,7 +146,15 @@ void SPShape::update(SPCtx* ctx, guint flags) { for (SPItemView *v = ((SPItem *) (this))->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); - sh->setStyle(this->style); + if (hasMarkers()) { + this->context_style = this->style; + sh->setStyle(this->style, this->context_style); + // Done at end: + // sh->setChildrenStyle(this->context_style); //Resolve 'context-xxx' in children. + } else if (this->parent) { + this->context_style = this->parent->context_style; + sh->setStyle(this->style, this->context_style); + } } } } @@ -163,6 +172,7 @@ void SPShape::update(SPCtx* ctx, guint flags) { } if (this->hasMarkers ()) { + /* Dimension marker views */ for (SPItemView *v = this->display; v != NULL; v = v->next) { if (!v->arenaitem->key()) { @@ -182,6 +192,13 @@ void SPShape::update(SPCtx* ctx, guint flags) { for (SPItemView *v = this->display; v != NULL; v = v->next) { sp_shape_update_marker_view (this, v->arenaitem); } + + // Marker selector needs this here or marker previews are not rendered. + for (SPItemView *v = this->display; v != NULL; v = v->next) { + Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); + + sh->setChildrenStyle(this->context_style); // Resolve 'context-xxx' in children. + } } } @@ -382,12 +399,23 @@ sp_shape_update_marker_view(SPShape *shape, Inkscape::DrawingItem *ai) } void SPShape::modified(unsigned int flags) { + // std::cout << "SPShape::modified(): " << (getId()?getId():"null") << std::endl; SPLPEItem::modified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); - sh->setStyle(this->style); + if (hasMarkers()) { + this->context_style = this->style; + sh->setStyle(this->style, this->context_style); + // Note: marker selector preview does not trigger SP_OBJECT_STYLE_MODIFIED_FLAG so + // this is not called when marker previews are generated, however there is code in + // SPShape::update() that calls this routine so we don't worry about it here. + sh->setChildrenStyle(this->context_style); // Resolve 'context-xxx' in children. + } else if (this->parent) { + this->context_style = this->parent->context_style; + sh->setStyle(this->style, this->context_style); + } } } } @@ -434,7 +462,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox tr = Geom::Rotate::from_degrees( 180.0 ) * tr; } else if (_marker[i]->orient_mode == MARKER_ORIENT_ANGLE) { Geom::Point transl = tr.translation(); - tr = Geom::Rotate::from_degrees(_marker[i]->orient) * Geom::Translate(transl); + tr = Geom::Rotate::from_degrees(_marker[i]->orient.computed) * Geom::Translate(transl); } if (_marker[i]->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { @@ -472,7 +500,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox if (marker->orient_mode == MARKER_ORIENT_ANGLE) { Geom::Point transl = tr.translation(); - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(transl); } if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { @@ -502,7 +530,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox if (marker->orient_mode == MARKER_ORIENT_ANGLE) { Geom::Point transl = tr.translation(); - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(transl); } if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { @@ -525,7 +553,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox if (marker->orient_mode == MARKER_ORIENT_ANGLE) { Geom::Point transl = tr.translation(); - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(transl); } if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { @@ -560,7 +588,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox if (marker->orient_mode == MARKER_ORIENT_ANGLE) { Geom::Point transl = tr.translation(); - tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); + tr = Geom::Rotate::from_degrees(marker->orient.computed) * Geom::Translate(transl); } if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { @@ -718,8 +746,11 @@ void SPShape::print(SPPrintContext* ctx) { } Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/) { + // std::cout << "SPShape::show(): " << (getId()?getId():"null") << std::endl; Inkscape::DrawingShape *s = new Inkscape::DrawingShape(drawing); - s->setStyle(this->style); + + bool has_markers = this->hasMarkers(); + s->setPath(this->_curve); /* This stanza checks that an object's marker style agrees with @@ -731,7 +762,7 @@ Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int /* sp_shape_set_marker (this, i, this->style->marker_ptrs[i]->value); } - if (this->hasMarkers ()) { + if (has_markers) { /* provide key and dimension the marker views */ if (!s->key()) { s->setKey(SPItem::display_key_new (SP_MARKER_LOC_QTY)); @@ -747,8 +778,14 @@ Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int /* /* Update marker views */ sp_shape_update_marker_view (this, s); - } + this->context_style = this->style; + s->setStyle(this->style, this->context_style); + s->setChildrenStyle(this->context_style); // Resolve 'context-xxx' in children. + } else if (this->parent) { + this->context_style = this->parent->context_style; + s->setStyle(this->style, this->context_style); + } return s; } diff --git a/src/sp-solid-color.cpp b/src/sp-solid-color.cpp index 0d6b96b62..72569d8c0 100644 --- a/src/sp-solid-color.cpp +++ b/src/sp-solid-color.cpp @@ -53,7 +53,7 @@ void SPSolidColor::build(SPDocument* doc, Inkscape::XML::Node* repr) { void SPSolidColor::set(unsigned int key, const gchar* value) { if (SP_ATTRIBUTE_IS_CSS(key)) { - sp_style_read_from_object(this->style, this); + style->readFromObject( this ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { SPPaintServer::set(key, value); diff --git a/src/sp-stop.cpp b/src/sp-stop.cpp index d644a9b4b..3ee467322 100644 --- a/src/sp-stop.cpp +++ b/src/sp-stop.cpp @@ -210,16 +210,14 @@ SPStop* SPStop::getPrevStop() { SPColor SPStop::readStopColor(Glib::ustring const &styleStr, guint32 dfl) { SPColor color(dfl); - SPStyle* style = sp_style_new(0); SPIPaint paint; - paint.read( styleStr.c_str(), *style ); + + paint.read( styleStr.c_str() ); if ( paint.isColor() ) { color = paint.value.color; } - sp_style_unref(style); - return color; } diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index da17b08d9..668780272 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -319,13 +319,14 @@ void SPStyleElem::read_content() { //requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); // Style references via class= do not, and actually cannot, use autoupdating URIReferences. - // Therefore, if an object refers to a stylesheet which has not yet loaded when the object is being loaded - // (e.g. if the stylesheet is below or inside the object in XML), its class= has no effect (bug 1491639). - // Below is a partial hack that fixes this for a single case: when the <style> is a child of the object - // that uses a style from it. It just forces the parent of <style> to reread its style as soon as the stylesheet - // is fully loaded. Naturally, this won't work if the user of the stylesheet is its grandparent or precedent. + // Therefore, if an object refers to a stylesheet which has not yet loaded when the object is + // being loaded (e.g. if the stylesheet is below or inside the object in XML), its class= has + // no effect (bug 1491639). Below is a partial hack that fixes this for a single case: when + // the <style> is a child of the object that uses a style from it. It just forces the parent of + // <style> to reread its style as soon as the stylesheet is fully loaded. Naturally, this won't + // work if the user of the stylesheet is its grandparent or precedent. if ( parent ) { - sp_style_read_from_object(parent->style, parent); + parent->style->readFromObject( parent ); } } diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 93d81e47b..1cd690729 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -38,7 +38,7 @@ #include "attributes.h" #include "document.h" #include "preferences.h" -#include "desktop-handles.h" +#include "desktop.h" #include "sp-namedview.h" #include "style.h" #include "inkscape.h" @@ -195,7 +195,7 @@ void SPText::update(SPCtx *ctx, guint flags) { for (SPItemView* v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); this->_clearFlow(g); - g->setStyle(this->style); + g->setStyle(this->style, this->parent->style); // pass the bbox of the this this as paintbox (used for paintserver fills) this->layout.show(g, paintbox); } @@ -221,7 +221,7 @@ void SPText::modified(guint flags) { for (SPItemView* v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); this->_clearFlow(g); - g->setStyle(this->style); + g->setStyle(this->style, this->parent->style); this->layout.show(g, paintbox); } } @@ -333,7 +333,7 @@ Geom::OptRect SPText::bbox(Geom::Affine const &transform, SPItem::BBoxType type) Inkscape::DrawingItem* SPText::show(Inkscape::Drawing &drawing, unsigned /*key*/, unsigned /*flags*/) { Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(drawing); flowed->setPickChildren(false); - flowed->setStyle(this->style); + flowed->setStyle(this->style, this->parent->style); // pass the bbox of the text object as paintbox (used for paintserver fills) this->layout.show(flowed, this->geometricBounds()); @@ -362,7 +362,7 @@ gchar* SPText::description() const { char *n = xml_quote_strdup( style->font_family.value ); Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px"); - GString *xs = g_string_new(q.string(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str()); + GString *xs = g_string_new(q.string(SP_ACTIVE_DESKTOP->getNamedView()->display_units).c_str()); char const *trunc = ""; Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) this); diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp index 0f6eb106f..6a229e170 100644 --- a/src/sp-tref.cpp +++ b/src/sp-tref.cpp @@ -492,12 +492,8 @@ sp_tref_convert_to_tspan(SPObject *obj) //SPObject * new_string_child = document->getObjectByRepr(new_string_repr); // Merge style from the tref - SPStyle *new_tspan_sty = new_tspan->style; - SPStyle const *tref_sty = tref->style; - sp_style_merge_from_dying_parent(new_tspan_sty, tref_sty); - sp_style_merge_from_parent(new_tspan_sty, new_tspan->parent->style); - - + new_tspan->style->merge( tref->style ); + new_tspan->style->cascade( new_tspan->parent->style ); new_tspan->updateRepr(); // Hold onto our SPObject and repr for now. diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 2bd6757ff..9b38a91c5 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -94,7 +94,7 @@ void SPUse::build(SPDocument *document, Inkscape::XML::Node *repr) { // We don't need to create child here: // reading xlink:href will attach ref, and that will cause the changed signal to be emitted, - // which will call sp_use_href_changed, and that will take care of the child + // which will call SPUse::href_changed, and that will take care of the child } void SPUse::release() { @@ -145,7 +145,7 @@ void SPUse::set(unsigned int key, const gchar* value) { this->href = NULL; if (value) { - // First, set the href field, because sp_use_href_changed will need it. + // First, set the href field, because SPUse::href_changed will need it. this->href = g_strdup(value); // Now do the attaching, which emits the changed signal. @@ -280,10 +280,13 @@ gchar* SPUse::description() const { } Inkscape::DrawingItem* SPUse::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + + // std::cout << "SPUse::show: " << (getId()?getId():"null") << std::endl; Inkscape::DrawingGroup *ai = new Inkscape::DrawingGroup(drawing); ai->setPickChildren(false); - ai->setStyle(this->style); - + this->context_style = this->style; + ai->setStyle(this->style, this->context_style); + if (this->child) { Inkscape::DrawingItem *ac = this->child->invoke_show(drawing, key, flags); @@ -529,6 +532,7 @@ void SPUse::delete_self() { } void SPUse::update(SPCtx *ctx, unsigned flags) { + // std::cout << "SPUse::update: " << (getId()?getId():"null") << std::endl; SPItemCtx *ictx = (SPItemCtx *) ctx; SPItemCtx cctx = *ictx; @@ -579,7 +583,8 @@ void SPUse::update(SPCtx *ctx, unsigned flags) { if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); - g->setStyle(this->style); + this->context_style = this->style; + g->setStyle(this->style, this->context_style); } } @@ -592,6 +597,7 @@ void SPUse::update(SPCtx *ctx, unsigned flags) { } void SPUse::modified(unsigned int flags) { + // std::cout << "SPUse::modified: " << (getId()?getId():"null") << std::endl; if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } @@ -601,7 +607,8 @@ void SPUse::modified(unsigned int flags) { if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem); - g->setStyle(this->style); + this->context_style = this->style; + g->setStyle(this->style, this->context_style); } } @@ -657,11 +664,8 @@ SPItem *SPUse::unlink() { SPObject *unlinked = document->getObjectByRepr(copy); // Merge style from the use. - SPStyle *unli_sty = unlinked->style; - SPStyle const *use_sty = this->style; - sp_style_merge_from_dying_parent(unli_sty, use_sty); - sp_style_merge_from_parent(unli_sty, unlinked->parent->style); - + unlinked->style->merge( this->style ); + unlinked->style->cascade( unlinked->parent->style ); unlinked->updateRepr(); // Hold onto our SPObject and repr for now. diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 1a75a6f29..8bb3e9897 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -37,7 +37,7 @@ #include "layer-model.h" #include "message-stack.h" #include "selection.h" -#include "desktop-handles.h" + #include "desktop.h" #include "display/canvas-bpath.h" #include "display/curve.h" @@ -1151,7 +1151,7 @@ Geom::PathVector* item_outline(SPItem const *item, bool bbox_only) void sp_selected_path_outline(SPDesktop *desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>stroked path(s)</b> to convert stroke to path.")); @@ -1343,7 +1343,7 @@ sp_selected_path_outline(SPDesktop *desktop) if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether - SPDocument * doc = sp_desktop_document(desktop); + SPDocument * doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); @@ -1482,7 +1482,7 @@ sp_selected_path_outline(SPDesktop *desktop) // restore title, description, id, transform repr->setAttribute("id", id); - SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); + SPItem *newitem = (SPItem *) desktop->getDocument()->getObjectByRepr(repr); newitem->doWriteTransform(repr, transform); if (title) { newitem->setTitle(title); @@ -1512,7 +1512,7 @@ sp_selected_path_outline(SPDesktop *desktop) } if (did) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_OUTLINE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_OUTLINE, _("Convert stroke to path")); } else { // TRANSLATORS: "to outline" means "to convert stroke to path" @@ -1583,7 +1583,7 @@ void sp_selected_path_create_updating_inset(SPDesktop *desktop) void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating) { SPCurve *curve = NULL; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); SPItem *item = selection->singleItem(); if (item == NULL || ( !SP_IS_SHAPE(item) && !SP_IS_TEXT(item) ) ) { @@ -1675,7 +1675,7 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool { // pas vraiment de points sur le resultat // donc il ne reste rien - DocumentUndo::done(sp_desktop_document(desktop), + DocumentUndo::done(desktop->getDocument(), (updating ? SP_VERB_SELECTION_LINKED_OFFSET : SP_VERB_SELECTION_DYNAMIC_OFFSET), (updating ? _("Create linked offset") @@ -1723,7 +1723,7 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool // move to the saved position repr->setPosition(pos > 0 ? pos : 0); - SPItem *nitem = reinterpret_cast<SPItem *>(sp_desktop_document(desktop)->getObjectByRepr(repr)); + SPItem *nitem = reinterpret_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(repr)); if ( !updating ) { // delete original, apply the transform to the offset @@ -1740,7 +1740,7 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool selection->set(nitem); } - DocumentUndo::done(sp_desktop_document(desktop), + DocumentUndo::done(desktop->getDocument(), (updating ? SP_VERB_SELECTION_LINKED_OFFSET : SP_VERB_SELECTION_DYNAMIC_OFFSET), (updating ? _("Create linked offset") @@ -1766,7 +1766,7 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to inset/outset.")); @@ -1946,7 +1946,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) // move to the saved position repr->setPosition(pos > 0 ? pos : 0); - SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); + SPItem *newitem = (SPItem *) desktop->getDocument()->getObjectByRepr(repr); // reapply the transform newitem->doWriteTransform(repr, transform); @@ -1963,7 +1963,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) } if (did) { - DocumentUndo::done(sp_desktop_document(desktop), + DocumentUndo::done(desktop->getDocument(), (expand ? SP_VERB_SELECTION_OFFSET : SP_VERB_SELECTION_INSET), (expand ? _("Outset path") : _("Inset path"))); } else { @@ -2089,7 +2089,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, // move to the saved position repr->setPosition(pos > 0 ? pos : 0); - SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); + SPItem *newitem = (SPItem *) desktop->getDocument()->getObjectByRepr(repr); // reapply the transform newitem->doWriteTransform(repr, transform); @@ -2191,7 +2191,7 @@ static void sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, @@ -2208,7 +2208,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju breakableAngles, true); if (didSomething) - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_SIMPLIFY, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_SIMPLIFY, _("Simplify")); else desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to simplify in the selection.")); diff --git a/src/style-internal.cpp b/src/style-internal.cpp index b858e5cb6..915282301 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -984,7 +984,7 @@ SPIPaint::read( gchar const *str ) { if (streq(str, "currentColor")) { set = true; - currentcolor = true; + paintOrigin = SP_CSS_PAINT_ORIGIN_CURRENT_COLOR; if (style) { setColor( style->color.value.color ); } else { @@ -995,6 +995,12 @@ SPIPaint::read( gchar const *str ) { std::cerr << "SPIPaint::read(): value is 'currentColor' but 'color' not available." << std::endl; setColor( 0 ); } + } else if (streq(str, "context-fill")) { + set = true; + paintOrigin = SP_CSS_PAINT_ORIGIN_CONTEXT_FILL; + } else if (streq(str, "context-stroke")) { + set = true; + paintOrigin = SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE; } else if (streq(str, "none")) { set = true; noneSet = true; @@ -1058,14 +1064,28 @@ SPIPaint::write( guint const flags, SPIBase const *const base) const { css << "none"; } - if ( this->currentcolor ) { + if ( this->paintOrigin == SP_CSS_PAINT_ORIGIN_CURRENT_COLOR ) { if ( !css.str().empty() ) { css << " "; } css << "currentColor"; } - if ( this->colorSet && !this->currentcolor ) { + if ( this->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + if ( !css.str().empty() ) { + css << " "; + } + css << "context-fill"; + } + + if ( this->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + if ( !css.str().empty() ) { + css << " "; + } + css << "context-stroke"; + } + + if ( this->colorSet && this->paintOrigin == SP_CSS_PAINT_ORIGIN_NORMAL ) { if ( !css.str().empty() ) { css << " "; } @@ -1074,7 +1094,7 @@ SPIPaint::write( guint const flags, SPIBase const *const base) const { css << color_buf; } - if (this->value.color.icc && !this->currentcolor) { + if ( this->value.color.icc && this->paintOrigin == SP_CSS_PAINT_ORIGIN_NORMAL ) { if ( !css.str().empty() ) { css << " "; } @@ -1107,7 +1127,7 @@ SPIPaint::reset( bool init ) { // std::cout << "SPIPaint::reset(): " << name << " " << init << std::endl; SPIBase::clear(); - currentcolor = false; + paintOrigin = SP_CSS_PAINT_ORIGIN_NORMAL; colorSet = false; noneSet = false; value.color.set( false ); @@ -1147,8 +1167,8 @@ SPIPaint::cascade( const SPIBase* const parent ) { setColor( p->value.color ); } else if( p->isNoneSet() ) { noneSet = true; - } else if( p->currentcolor ) { - currentcolor = true; + } else if( p->paintOrigin == SP_CSS_PAINT_ORIGIN_CURRENT_COLOR ) { + paintOrigin = SP_CSS_PAINT_ORIGIN_CURRENT_COLOR; setColor( style->color.value.color ); } else if( isNone() ) { // @@ -1156,7 +1176,7 @@ SPIPaint::cascade( const SPIBase* const parent ) { g_assert_not_reached(); } } else { - if( currentcolor ) { + if( paintOrigin == SP_CSS_PAINT_ORIGIN_CURRENT_COLOR ) { // Update in case color value changed. setColor( style->color.value.color ); } @@ -1187,7 +1207,7 @@ SPIPaint::operator==(const SPIBase& rhs) { if ( (this->isColor() != r->isColor() ) || (this->isPaintserver() != r->isPaintserver() ) || - (this->currentcolor != r->currentcolor ) ) { + (this->paintOrigin != r->paintOrigin ) ) { return false; } diff --git a/src/style-internal.h b/src/style-internal.h index faae76ac5..a8f0c5096 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -628,6 +628,15 @@ public: #define SP_STYLE_FILL_SERVER(s) ((const_cast<SPStyle *> (s))->getFillPaintServer()) #define SP_STYLE_STROKE_SERVER(s) ((const_cast<SPStyle *> (s))->getStrokePaintServer()) +// SVG 2 +enum SPPaintOrigin { + SP_CSS_PAINT_ORIGIN_NORMAL, + SP_CSS_PAINT_ORIGIN_CURRENT_COLOR, + SP_CSS_PAINT_ORIGIN_CONTEXT_FILL, + SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE +}; + + /// Paint type internal to SPStyle. class SPIPaint : public SPIBase { @@ -635,7 +644,7 @@ class SPIPaint : public SPIBase public: SPIPaint() : SPIBase( "anonymous_paint" ), - currentcolor(false), + paintOrigin( SP_CSS_PAINT_ORIGIN_NORMAL ), colorSet(false), noneSet(false) { value.href = NULL; @@ -644,7 +653,6 @@ public: SPIPaint( Glib::ustring const &name ) : SPIBase( name ), - currentcolor(false), colorSet(false), noneSet(false) { value.href = NULL; @@ -663,7 +671,7 @@ public: SPIPaint& operator=(const SPIPaint& rhs) { SPIBase::operator=(rhs); - currentcolor = rhs.currentcolor; + paintOrigin = rhs.paintOrigin; colorSet = rhs.colorSet; noneSet = rhs.noneSet; value.color = rhs.value.color; @@ -677,7 +685,7 @@ public: } bool isSameType( SPIPaint const & other ) const { - return (isPaintserver() == other.isPaintserver()) && (colorSet == other.colorSet) && (currentcolor == other.currentcolor); + return (isPaintserver() == other.isPaintserver()) && (colorSet == other.colorSet) && (paintOrigin == other.paintOrigin); } bool isNoneSet() const { @@ -685,7 +693,7 @@ public: } bool isNone() const { - return !currentcolor && !colorSet && !isPaintserver(); + return (paintOrigin == SP_CSS_PAINT_ORIGIN_NORMAL) && !colorSet && !isPaintserver(); } // TODO refine bool isColor() const { @@ -712,7 +720,7 @@ public: // To do: make private public: - bool currentcolor : 1; + SPPaintOrigin paintOrigin : 2; bool colorSet : 1; bool noneSet : 1; struct { diff --git a/src/style-test.h b/src/style-test.h index e14ed4db7..cd6769b24 100644 --- a/src/style-test.h +++ b/src/style-test.h @@ -214,32 +214,25 @@ public: for ( gint i = 0; cases[i].src; i++ ) { // std::cout << "Test one: " << i << std::endl; - SPStyle *style = sp_style_new(_doc); - TS_ASSERT(style); - if ( style ) { - sp_style_merge_from_style_string( style, cases[i].src ); - - if ( cases[i].uri ) { - TSM_ASSERT( cases[i].src, style->fill.value.href ); - if ( style->fill.value.href ) { - TS_ASSERT_EQUALS( style->fill.value.href->getURI()->toString(), std::string(cases[i].uri) ); - } - } else { - TS_ASSERT( !style->fill.value.href || !style->fill.value.href->getObject() ); + SPStyle style(_doc); + style.mergeString( cases[i].src ); + if ( cases[i].uri ) { + TSM_ASSERT( cases[i].src, style.fill.value.href ); + if ( style.fill.value.href ) { + TS_ASSERT_EQUALS( style.fill.value.href->getURI()->toString(), std::string(cases[i].uri) ); } + } else { + TS_ASSERT( !style.fill.value.href || !style.fill.value.href->getObject() ); + } - gchar *str0_set = sp_style_write_string( style, SP_STYLE_FLAG_IFSET ); - //printf("<<%s>>\n", str0_set); - if ( cases[i].dst ) { - // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].dst) << std::endl; - TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].dst) ); - } else { - // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].src) << std::endl; - TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].src) ); - } + std::string str0_set = style.write(SP_STYLE_FLAG_IFSET ); - g_free(str0_set); - sp_style_unref(style); + if ( cases[i].dst ) { + // std::cout << " " << str0_set << " " << std::string(cases[i].dst) << std::endl; + TS_ASSERT_EQUALS( str0_set, std::string(cases[i].dst) ); + } else { + // std::cout << " " << str0_set << " " << std::string(cases[i].src) << std::endl; + TS_ASSERT_EQUALS( str0_set, std::string(cases[i].src) ); } } } @@ -366,26 +359,22 @@ public: }; for ( gint i = 0; cases[i].src; i++ ) { // std::cout << "Test two: " << i << std::endl; - SPStyle *style_src = sp_style_new(_doc); - TS_ASSERT(style_src); - SPStyle *style_dst = sp_style_new(_doc); - TS_ASSERT(style_dst); - - if ( style_src && style_dst ) { - sp_style_merge_from_style_string( style_src, cases[i].src ); - sp_style_merge_from_style_string( style_dst, cases[i].dst ); - // std::cout << "Test:" << std::endl; - // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl; - // std::cout << " S: |" << style_src->write( SP_STYLE_FLAG_IFSET, NULL ) << "| |" - // << style_dst->write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl; - TS_ASSERT( (*style_src == *style_dst) == cases[i].match ); - sp_style_unref(style_src); - sp_style_unref(style_dst); - // std::cout << "End Test\n" << std::endl; - } + SPStyle style_src(_doc); + SPStyle style_dst(_doc); + + style_src.mergeString( cases[i].src ); + style_dst.mergeString( cases[i].dst ); + + // std::cout << "Test:" << std::endl; + // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl; + // std::cout << " S: |" << style_src.write( SP_STYLE_FLAG_IFSET, NULL ) << "| |" + // << style_dst.write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl; + TS_ASSERT( (style_src == style_dst) == cases[i].match ); + // std::cout << "End Test\n" << std::endl; } } + // Test of cascade void testThree() { @@ -477,37 +466,29 @@ public: }; for ( gint i = 0; cases[i].parent; i++ ) { // std::cout << "Test three: " << i << std::endl; - SPStyle *style_parent = sp_style_new(_doc); - TS_ASSERT(style_parent); - SPStyle *style_child = sp_style_new(_doc); - TS_ASSERT(style_child); - SPStyle *style_result = sp_style_new(_doc); - TS_ASSERT(style_result); - - if ( style_parent && style_child && style_result ) { - sp_style_merge_from_style_string( style_parent, cases[i].parent ); - sp_style_merge_from_style_string( style_child, cases[i].child ); - sp_style_merge_from_style_string( style_result, cases[i].result ); - // std::cout << "Test:" << std::endl; - // std::cout << " Input: "; - // std::cout << " Parent: " << cases[i].parent - // << " Child: " << cases[i].child - // << " Result: " << cases[i].result << std::endl; - // std::cout << " Write: "; - // std::cout << " Parent: " << style_parent->write( SP_STYLE_FLAG_IFSET ) - // << " Child: " << style_child->write( SP_STYLE_FLAG_IFSET ) - // << " Result: " << style_result->write( SP_STYLE_FLAG_IFSET ) << std::endl; - - //sp_style_merge_from_parent( style_child, style_parent ); - style_child->cascade( style_parent ); - - TS_ASSERT(*style_child == *style_result ); - - sp_style_unref(style_child); - sp_style_unref(style_parent); - sp_style_unref(style_result); - // std::cout << "End Test: *************\n" << std::endl; - } + SPStyle style_parent(_doc); + SPStyle style_child( _doc); + SPStyle style_result(_doc); + + style_parent.mergeString( cases[i].parent ); + style_child.mergeString( cases[i].child ); + style_result.mergeString( cases[i].result ); + + // std::cout << "Test:" << std::endl; + // std::cout << " Input: "; + // std::cout << " Parent: " << cases[i].parent + // << " Child: " << cases[i].child + // << " Result: " << cases[i].result << std::endl; + // std::cout << " Write: "; + // std::cout << " Parent: " << style_parent.write( SP_STYLE_FLAG_IFSET ) + // << " Child: " << style_child.write( SP_STYLE_FLAG_IFSET ) + // << " Result: " << style_result.write( SP_STYLE_FLAG_IFSET ) << std::endl; + + style_child.cascade( &style_parent ); + + TS_ASSERT(style_child == style_result ); + + // std::cout << "End Test: *************\n" << std::endl; } } diff --git a/src/style.cpp b/src/style.cpp index a7e50b17a..0772a4bce 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -458,7 +458,14 @@ SPStyle::~SPStyle() { _properties.clear(); - // std::cout << "SPStyle::~SPstyle(): Exit\n" << std::endl; + // Conjecture: all this SPStyle ref counting is not needed. SPObject creates an instance of + // SPStyle when it is constructed and deletes it when it is destructed. The refcount is + // incremented and decremented only in the files: display/drawing-item.cpp, + // display/nr-filter-primitive.cpp, and libnrtype/Layout-TNG-Input.cpp. + if( _refcount > 1 ) { + std::cerr << "SPStyle::~SPStyle: ref count greater than 1! " << _refcount << std::endl; + } + // std::cout << "SPStyle::~SPStyle(): Exit\n" << std::endl; } // Used in SPStyle::clear() @@ -476,7 +483,7 @@ SPStyle::clear() { // (this->*(i->second)).clear(); // } - // Release connection to object, created in sp_style_new_from_object() + // Release connection to object, created in constructor. release_connection.disconnect(); // href->detach() called in fill->clear()... @@ -576,7 +583,13 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { } } -// Matches void sp_style_read_from_object(SPStyle *style, SPObject *object); +/** + * Read style properties from object's repr. + * + * 1. Reset existing object style + * 2. Load current effective object style + * 3. Load i attributes from immediate parent (which has to be up-to-date) + */ void SPStyle::readFromObject( SPObject *object ) { @@ -591,6 +604,34 @@ SPStyle::readFromObject( SPObject *object ) { read( object, repr ); } +/** + * Read style properties from preferences. + * @param path Preferences directory from which the style should be read + */ +void +SPStyle::readFromPrefs(Glib::ustring const &path) { + + g_return_if_fail(!path.empty()); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + // not optimal: we reconstruct the node based on the prefs, then pass it to + // sp_style_read for actual processing. + Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; + Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs"); + + std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path); + for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) { + tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); + } + + read( NULL, tempnode ); + + Inkscape::GC::release(tempnode); + Inkscape::GC::release(tempdoc); + delete tempdoc; +} + // Matches sp_style_merge_property(SPStyle *style, gint id, gchar const *val) void SPStyle::readIfUnset( gint id, gchar const *val ) { @@ -868,6 +909,19 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { } } +/** + * Outputs the style to a CSS string. + * + * Use with SP_STYLE_FLAG_ALWAYS for copying an object's complete cascaded style to + * style_clipboard. + * + * Use with SP_STYLE_FLAG_IFDIFF and a pointer to the parent class when you need a CSS string for + * an object in the document tree. + * + * \pre flags in {IFSET, ALWAYS, IFDIFF}. + * \pre base. + * \post ret != NULL. + */ Glib::ustring SPStyle::write( guint const flags, SPStyle const *const base ) const { @@ -897,9 +951,20 @@ SPStyle::write( guint const flags, SPStyle const *const base ) const { } // Corresponds to sp_style_merge_from_parent() +/** + * Sets computed values in \a style, which may involve inheriting from (or in some other way + * calculating from) corresponding computed values of \a parent. + * + * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. + * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to + * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise + * about what the computed value is (not obvious for lengths). + * + * \pre \a parent's computed values are already up-to-date. + */ void SPStyle::cascade( SPStyle const *const parent ) { - // std::cout << "SPStyle::cascade" << std::endl; + // std::cout << "SPStyle::cascade: " << (object->getId()?object->getId():"null") << std::endl; for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { _properties[i]->cascade( parent->_properties[i] ); } @@ -909,6 +974,23 @@ SPStyle::cascade( SPStyle const *const parent ) { } // Corresponds to sp_style_merge_from_dying_parent() +/** + * Combine \a style and \a parent style specifications into a single style specification that + * preserves (as much as possible) the effect of the existing \a style being a child of \a parent. + * + * Called when the parent repr is to be removed (e.g. the parent is a \<use\> element that is being + * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent, + * trying to retain the same visual appearance once the parent is removed. Interesting cases are + * when there is unusual interaction with the parent's value (opacity, display) or when the value + * can be specified as relative to the parent computed value (font-size, font-weight etc.). + * + * Doesn't update computed values of \a style. For correctness, you should subsequently call + * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a + * style was previously up-to-date wrt \a parent. + * + * \pre \a parent's computed values are already up-to-date. + * (\a style's computed values needn't be up-to-date.) + */ void SPStyle::merge( SPStyle const *const parent ) { // std::cout << "SPStyle::merge" << std::endl; @@ -920,6 +1002,14 @@ SPStyle::merge( SPStyle const *const parent ) { // } } +/** + * Parses a style="..." string and merges it with an existing SPStyle. + */ +void +SPStyle::mergeString( gchar const *const p ) { + _mergeString( p ); +} + // Mostly for unit testing bool SPStyle::operator==(const SPStyle& rhs) { @@ -1142,35 +1232,6 @@ sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPSty sp_style_paint_server_ref_modified(ref, 0, style); } -// Called in: desktop-style.cpp, gradient-chemistry.cpp, sp-object.cpp, sp-stop.cpp, style.cpp -// text-editing.cpp, libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/fill-style.cpp, -// widgets/stroke-style.cpp, widgets/text-toolbar.cpp, ui/dialog/glyphs.cpp, ui/dialog/swatches.cpp, -// ui/dialog/swatches.cpp, ui/dialog/text-edit.cpp. ui/tools/freehand-base.cpp, -// ui/widget/object-composite-settings.cpp, ui/widget/selected-style.cpp, ui/widget/style-swatch.cpp -/** - * Returns a new SPStyle object with default settings. - */ -SPStyle * -sp_style_new(SPDocument *document) -{ - SPStyle *const style = new SPStyle( document ); - return style; -} - -// Called in: sp-object.cpp -/** - * Creates a new SPStyle object, and attaches it to the specified SPObject. - */ -SPStyle * -sp_style_new_from_object(SPObject *object) -{ - g_return_val_if_fail(object != NULL, NULL); - g_return_val_if_fail(SP_IS_OBJECT(object), NULL); - - SPStyle *const style = new SPStyle( NULL, object ); - return style; -} - // Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp /** * Increase refcount of style. @@ -1180,13 +1241,12 @@ sp_style_ref(SPStyle *style) { g_return_val_if_fail(style != NULL, NULL); - style->ref(); // Increase ref count + style->style_ref(); // Increase ref count return style; } -// Called in style.cpp, desktop-style.cpp, sp-object.cpp, sp-stop.cpp, text-editing.cpp -// display/drawing-group.cpp, ... +// Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp /** * Decrease refcount of style with possible destruction. */ @@ -1194,71 +1254,13 @@ SPStyle * sp_style_unref(SPStyle *style) { g_return_val_if_fail(style != NULL, NULL); - if (style->unref() < 1) { + if (style->style_unref() < 1) { delete style; return NULL; } return style; } - - -// Called in: sp-clippath.cpp, sp-item.cpp (suspicious), sp-object.cpp, sp-style-elem.cpp -/** - * Read style properties from object's repr. - * - * 1. Reset existing object style - * 2. Load current effective object style - * 3. Load i attributes from immediate parent (which has to be up-to-date) - */ -void -sp_style_read_from_object(SPStyle *style, SPObject *object) -{ - // std::cout << "sp_style_read_from_object: " << (object->getId()?object->getId():"null") << std::endl; - g_return_if_fail(style != NULL); - g_return_if_fail(object != NULL); - g_return_if_fail(SP_IS_OBJECT(object)); - - Inkscape::XML::Node *repr = object->getRepr(); - g_return_if_fail(repr != NULL); - - style->read( object, repr ); -} - -// Called in: libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/text-toolbar.cpp, -// ui/dialog/text-edit.cpp -// Why is this called when draging a gradient handle? -/** - * Read style properties from preferences. - * @param style The style to write to - * @param path Preferences directory from which the style should be read - */ -void -sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path) -{ - g_return_if_fail(style != NULL); - g_return_if_fail(path != ""); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - // not optimal: we reconstruct the node based on the prefs, then pass it to - // sp_style_read for actual processing. - Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; - Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs"); - - std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path); - for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) { - tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); - } - - style->read( NULL, tempnode ); - - Inkscape::GC::release(tempnode); - Inkscape::GC::release(tempdoc); - delete tempdoc; -} - - static CRSelEng * sp_repr_sel_eng() { @@ -1282,81 +1284,9 @@ sp_repr_sel_eng() return ret; } - -// Called in text-editting.cpp, ui/tools/frehand-base.cpp, ui/widget/style-swatch.cpp -/** - * Parses a style="..." string and merges it with an existing SPStyle. - */ -void -sp_style_merge_from_style_string(SPStyle *const style, gchar const *const p) -{ - // std::cout << "sp_style_merge_from_style_string: " << (p?p:"null") <<std::endl; - /* - * Reference: http://www.w3.org/TR/SVG11/styling.html#StyleAttribute: - * ``When CSS styling is used, CSS inline style is specified by including - * semicolon-separated property declarations of the form "name : value" - * within the style attribute''. - * - * That's fairly ambiguous. Is a `value' allowed to contain semicolons? - * Why does it say "including", what else is allowed in the style - * attribute value? - */ - style->_mergeString( p ); -} - /** Indexed by SP_CSS_FONT_SIZE_blah. These seem a bit small */ static float const font_size_table[] = {6.0, 8.0, 10.0, 12.0, 14.0, 18.0, 24.0}; -// Called in sp-object.cpp, sp-tref.cpp, sp-use.cpp -/** - * Sets computed values in \a style, which may involve inheriting from (or in some other way - * calculating from) corresponding computed values of \a parent. - * - * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. - * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to - * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise - * about what the computed value is (not obvious for lengths). - * - * \pre \a parent's computed values are already up-to-date. - */ -void -sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent) -{ - // std::cout << "sp_style_merge_from_parent" << std::endl; - g_return_if_fail(style != NULL); - - if (!parent) - return; - - style->cascade( parent ); - return; -} - -// Called in: sp-use.cpp, sp-tref.cpp, sp-item.cpp -/** - * Combine \a style and \a parent style specifications into a single style specification that - * preserves (as much as possible) the effect of the existing \a style being a child of \a parent. - * - * Called when the parent repr is to be removed (e.g. the parent is a \<use\> element that is being - * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent, - * trying to retain the same visual appearance once the parent is removed. Interesting cases are - * when there is unusual interaction with the parent's value (opacity, display) or when the value - * can be specified as relative to the parent computed value (font-size, font-weight etc.). - * - * Doesn't update computed values of \a style. For correctness, you should subsequently call - * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a - * style was previously up-to-date wrt \a parent. - * - * \pre \a parent's computed values are already up-to-date. - * (\a style's computed values needn't be up-to-date.) - */ -void -sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const parent) -{ - // std::cout << "sp_style_merge_from_dying_parent" << std::endl; - style->merge( parent ); -} - // The following functions should be incorporated into SPIPaint. FIXME // Called in: style.cpp, style-internal.cpp void @@ -1473,50 +1403,6 @@ sp_style_css_size_units_to_px(double size, int unit) return size * (size / sp_style_css_size_px_to_units(size, unit));; } -// Called in style.cpp, text-editing.cpp -/** - * Dumps the style to a CSS string, with either SP_STYLE_FLAG_IFSET or - * SP_STYLE_FLAG_ALWAYS flags. Used with Always for copying an object's - * complete cascaded style to style_clipboard. When you need a CSS string - * for an object in the document tree, you normally call - * sp_style_write_difference instead to take into account the object's parent. - * - * \pre style != NULL. - * \pre flags in {IFSET, ALWAYS}. - * \post ret != NULL. - */ -gchar * -sp_style_write_string(SPStyle const *const style, guint const flags) -{ - /** \todo - * Merge with write_difference, much duplicate code! - */ - g_return_val_if_fail(style != NULL, NULL); - g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) || - (flags == SP_STYLE_FLAG_ALWAYS) ), - NULL); - - return g_strdup( style->write( flags ).c_str() ); -} - - -// Called in style.cpp, path-chemistry, NOT in text-editting.cpp (because of bug) -/** - * Dumps style to CSS string, see sp_style_write_string() - * - * \pre from != NULL. - * \pre to != NULL. - * \post ret != NULL. - */ -gchar * -sp_style_write_difference(SPStyle const *const from, SPStyle const *const to) -{ - g_return_val_if_fail(from != NULL, NULL); - g_return_val_if_fail(to != NULL, NULL); - - return g_strdup( from->write( SP_STYLE_FLAG_IFDIFF, to ).c_str() ); -} - // FIXME: Everything below this line belongs in a different file - css-chemistry? @@ -1677,10 +1563,9 @@ sp_css_attr_from_style(SPStyle const *const style, guint const flags) g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) || (flags == SP_STYLE_FLAG_ALWAYS) ), NULL); - gchar *style_str = sp_style_write_string(style, flags); + Glib::ustring style_str = style->write(flags); SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, style_str); - g_free(style_str); + sp_repr_css_attr_add_from_string(css, style_str.c_str()); return css; } diff --git a/src/style.h b/src/style.h index 1b1596458..3f21f37db 100644 --- a/src/style.h +++ b/src/style.h @@ -51,18 +51,19 @@ public: void readFromObject(SPObject *object); void readFromPrefs(Glib::ustring const &path); void readIfUnset( int id, char const *val ); - Glib::ustring write( unsigned int const flags, SPStyle const *const base = NULL ) const; + Glib::ustring write( unsigned int const flags = SP_STYLE_FLAG_IFSET, + SPStyle const *const base = NULL ) const; void cascade( SPStyle const *const parent ); void merge( SPStyle const *const parent ); + void mergeString( char const *const p ); bool operator==(const SPStyle& rhs); - int ref() { ++_refcount; return _refcount; } - int unref() { --_refcount; return _refcount; } + int style_ref() { ++_refcount; return _refcount; } + int style_unref() { --_refcount; return _refcount; } + int refCount() { return _refcount; } -//FIXME: Make private -public: - void _mergeString( char const *const p ); // Rename to readFromString? private: + void _mergeString( char const *const p ); void _mergeDeclList( CRDeclaration const *const decl_list ); void _mergeDecl( CRDeclaration const *const decl ); void _mergeProps( CRPropList *const props ); @@ -282,28 +283,10 @@ public: char const *getStrokeURI() const { return (stroke.value.href) ? stroke.value.href->getURI()->toString() : NULL; } }; -SPStyle *sp_style_new(SPDocument *document); // SPStyle::SPStyle( SPDocument *document = NULL ); - -SPStyle *sp_style_new_from_object(SPObject *object); // SPStyle::SPStyle( SPObject *object ); - SPStyle *sp_style_ref(SPStyle *style); // SPStyle::ref(); SPStyle *sp_style_unref(SPStyle *style); // SPStyle::unref(); -void sp_style_read_from_object(SPStyle *style, SPObject *object); //SPStyle::read( SPObject * object); - -void sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path); // SPStyle::read( ... ); - -void sp_style_merge_from_style_string(SPStyle *style, char const *p); // SPStyle::merge( ... );? - -void sp_style_merge_from_parent(SPStyle *style, SPStyle const *parent); // SPStyle::cascade( ... ); - -void sp_style_merge_from_dying_parent(SPStyle *style, SPStyle const *parent); // SPStyle::merge( ... ) - -char *sp_style_write_string(SPStyle const *style, unsigned int flags = SP_STYLE_FLAG_IFSET);//SPStyle::write - -char *sp_style_write_difference(SPStyle const *from, SPStyle const *to); // SPStyle::write - void sp_style_set_to_uri_string (SPStyle *style, bool isfill, const char *uri); // ? char const *sp_style_get_css_unit_string(int unit); // No change? diff --git a/src/svg/svg-color.cpp b/src/svg/svg-color.cpp index c9f22f8a4..693094048 100644 --- a/src/svg/svg-color.cpp +++ b/src/svg/svg-color.cpp @@ -32,8 +32,8 @@ #include "svg-color.h" #include "svg-icc-color.h" -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #include "color.h" +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #include "color-profile.h" #include "document.h" #include "inkscape.h" diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index b9b475f4b..ea235b2e4 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -520,7 +520,8 @@ gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit) case SVGLength::MM: return "mm"; case SVGLength::CM: return "cm"; case SVGLength::INCH: return "in"; - case SVGLength::FOOT: return ""; // Does not have a "foot" unit string in the SVG spec + case SVGLength::FOOT: return ""; // Not in SVG/CSS specification. + case SVGLength::MITRE: return ""; // Not in SVG/CSS specification. case SVGLength::EM: return "em"; case SVGLength::EX: return "ex"; case SVGLength::PERCENT: return "%"; @@ -539,6 +540,8 @@ std::string sp_svg_length_write_with_units(SVGLength const &length) os << 100*length.value << sp_svg_length_get_css_units(length.unit); } else if (length.unit == SVGLength::FOOT) { os << 12*length.value << sp_svg_length_get_css_units(SVGLength::INCH); + } else if (length.unit == SVGLength::MITRE) { + os << 100*length.value << sp_svg_length_get_css_units(SVGLength::CM); } else { os << length.value << sp_svg_length_get_css_units(length.unit); } diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h index c34905d07..1e6b4c96c 100644 --- a/src/svg/svg-length.h +++ b/src/svg/svg-length.h @@ -28,6 +28,7 @@ public: CM, INCH, FOOT, + MITRE, EM, EX, PERCENT, diff --git a/src/test-helpers.h b/src/test-helpers.h index 001356e65..d30449ebb 100644 --- a/src/test-helpers.h +++ b/src/test-helpers.h @@ -5,7 +5,7 @@ #include <cxxtest/TestSuite.h> #include "document.h" -#include "inkscape-private.h" +#include "inkscape.h" // Dummy functions to keep linker happy @@ -28,10 +28,10 @@ T* createSuiteAndDocument( void (*fun)(T*&) ) #endif Inkscape::GC::init(); - if ( !inkscape_get_instance() ) + if ( !Inkscape::Application::exists() ) { // Create the global inkscape object. - static_cast<void>(g_object_new(inkscape_get_type(), NULL)); + Inkscape::Application::create("", false); } SPDocument* tmp = SPDocument::createNewDoc( NULL, TRUE, true ); diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index aa2d81427..65b59f2ad 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -29,7 +29,7 @@ #include "message-stack.h" #include "selection.h" #include "style.h" -#include "desktop-handles.h" + #include "text-editing.h" #include "text-chemistry.h" #include "sp-flowtext.h" @@ -83,7 +83,7 @@ text_put_on_path() if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); @@ -91,18 +91,18 @@ text_put_on_path() Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text and a path</b> to put text on path.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text and a path</b> to put text on path.")); return; } if (SP_IS_TEXT_TEXTPATH(text)) { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("This text object is <b>already put on a path</b>. Remove it from the path first. Use <b>Shift+D</b> to look up its path.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("This text object is <b>already put on a path</b>. Remove it from the path first. Use <b>Shift+D</b> to look up its path.")); return; } if (SP_IS_RECT(shape)) { // rect is the only SPShape which is not <path> yet, and thus SVG forbids us from putting text on it - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("You cannot put text on a rectangle in this version. Convert rectangle to path first.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot put text on a rectangle in this version. Convert rectangle to path first.")); return; } @@ -110,7 +110,7 @@ text_put_on_path() if (SP_IS_FLOWTEXT(text)) { if (!SP_FLOWTEXT(text)->layout.outputExists()) { - sp_desktop_message_stack(desktop)-> + desktop->getMessageStack()-> flash(Inkscape::WARNING_MESSAGE, _("The flowed text(s) must be <b>visible</b> in order to be put on a path.")); } @@ -122,14 +122,14 @@ text_put_on_path() Inkscape::XML::Node *parent = text->getRepr()->parent(); parent->appendChild(repr); - SPItem *new_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); + SPItem *new_item = (SPItem *) desktop->getDocument()->getObjectByRepr(repr); new_item->doWriteTransform(repr, text->transform); new_item->updateRepr(); Inkscape::GC::release(repr); text->deleteObject(); // delete the orignal flowtext - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); selection->clear(); @@ -181,7 +181,7 @@ text_put_on_path() text->getRepr()->setAttribute("x", NULL); text->getRepr()->setAttribute("y", NULL); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Put text on path")); g_slist_free(text_reprs); } @@ -191,10 +191,10 @@ text_remove_from_path() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text on path</b> to remove it from path.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text on path</b> to remove it from path.")); return; } @@ -215,9 +215,9 @@ text_remove_from_path() } if (!did) { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No texts-on-paths</b> in the selection.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No texts-on-paths</b> in the selection.")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove text from path")); selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description } @@ -256,10 +256,10 @@ text_remove_all_kerns() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>text(s)</b> to remove kerns from.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>text(s)</b> to remove kerns from.")); return; } @@ -280,9 +280,9 @@ text_remove_all_kerns() } if (!did) { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("Select <b>text(s)</b> to remove kerns from.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("Select <b>text(s)</b> to remove kerns from.")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove manual kerns")); } } @@ -294,16 +294,16 @@ text_flow_into_shape() if (!desktop) return; - SPDocument *doc = sp_desktop_document (desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); if (!text || !shape || g_slist_length((GSList *) selection->itemList()) < 2) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text</b> and one or more <b>paths or shapes</b> to flow text into frame.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text</b> and one or more <b>paths or shapes</b> to flow text into frame.")); return; } @@ -375,7 +375,7 @@ text_flow_into_shape() DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, _("Flow text into shape")); - sp_desktop_selection(desktop)->set(SP_ITEM(root_object)); + desktop->getSelection()->set(SP_ITEM(root_object)); Inkscape::GC::release(root_repr); Inkscape::GC::release(region_repr); @@ -388,14 +388,14 @@ text_unflow () if (!desktop) return; - SPDocument *doc = sp_desktop_document (desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!flowtext_in_selection(selection) || g_slist_length((GSList *) selection->itemList()) < 1) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a flowed text</b> to unflow it.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a flowed text</b> to unflow it.")); return; } @@ -477,10 +477,10 @@ flowtext_to_text() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>flowed text(s)</b> to convert.")); return; } @@ -497,7 +497,7 @@ flowtext_to_text() continue; if (!SP_FLOWTEXT(item)->layout.outputExists()) { - sp_desktop_message_stack(desktop)-> + desktop->getMessageStack()-> flash(Inkscape::WARNING_MESSAGE, _("The flowed text(s) must be <b>visible</b> in order to be converted.")); return; @@ -512,7 +512,7 @@ flowtext_to_text() Inkscape::XML::Node *parent = item->getRepr()->parent(); parent->addChild(repr, item->getRepr()); - SPItem *new_item = reinterpret_cast<SPItem *>(sp_desktop_document(desktop)->getObjectByRepr(repr)); + SPItem *new_item = reinterpret_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(repr)); new_item->doWriteTransform(repr, item->transform); new_item->updateRepr(); @@ -525,12 +525,12 @@ flowtext_to_text() g_slist_free(items); if (did) { - DocumentUndo::done(sp_desktop_document(desktop), + DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLOWTEXT_TO_TEXT, _("Convert flowed text to text")); selection->setReprList(reprs); } else { - sp_desktop_message_stack(desktop)-> + desktop->getMessageStack()-> flash(Inkscape::ERROR_MESSAGE, _("<b>No flowed text(s)</b> to convert in the selection.")); } diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 47964880c..4a962ab4c 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -1321,23 +1321,23 @@ static unsigned char_index_of_iterator(Glib::ustring const &string, Glib::ustrin return n; } +// Move to style.h? /** applies the given style string on top of the existing styles for \a item, as opposed to sp_style_merge_from_style_string which merges its parameter underneath the existing styles (ie ignoring already set properties). */ static void overwrite_style_with_string(SPObject *item, gchar const *style_string) { - SPStyle *new_style = sp_style_new(item->document); - sp_style_merge_from_style_string(new_style, style_string); + SPStyle style(item->document); + style.mergeString(style_string); gchar const *item_style_string = item->getRepr()->attribute("style"); if (item_style_string && *item_style_string) { - sp_style_merge_from_style_string(new_style, item_style_string); + style.mergeString(item_style_string); } - gchar *new_style_string = sp_style_write_string(new_style); - sp_style_unref(new_style); - item->getRepr()->setAttribute("style", new_style_string && *new_style_string ? new_style_string : NULL); - g_free(new_style_string); + Glib::ustring new_style_string = style.write(); + item->getRepr()->setAttribute("style", new_style_string.empty() ? NULL : new_style_string.c_str()); } +// Move to style.h? /** Returns true if the style of \a parent and the style of \a child are equivalent (and hence the children of both will appear the same). It is a limitation of the current implementation that \a parent must be a (not @@ -1349,14 +1349,14 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi // implications too large for me to feel safe fixing, but mainly because the css spec // requires that the computed value is inherited, not the specified value. g_assert(parent->isAncestorOf(child)); - gchar *parent_style = sp_style_write_string(parent->style, SP_STYLE_FLAG_ALWAYS); + + Glib::ustring parent_style = parent->style->write( SP_STYLE_FLAG_ALWAYS ); + // we have to write parent_style then read it again, because some properties format their values // differently depending on whether they're set or not (*cough*dash-offset*cough*) - SPStyle *parent_spstyle = sp_style_new(parent->document); - sp_style_merge_from_style_string(parent_spstyle, parent_style); - g_free(parent_style); - parent_style = sp_style_write_string(parent_spstyle, SP_STYLE_FLAG_ALWAYS); - sp_style_unref(parent_spstyle); + SPStyle parent_spstyle(parent->document); + parent_spstyle.mergeString(parent_style.c_str()); + parent_style = parent_spstyle.write(SP_STYLE_FLAG_ALWAYS); Glib::ustring child_style_construction; while (child != parent) { @@ -1369,13 +1369,12 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi child = child->parent; } child_style_construction.insert(0, parent_style); - SPStyle *child_spstyle = sp_style_new(parent->document); - sp_style_merge_from_style_string(child_spstyle, child_style_construction.c_str()); - gchar *child_style = sp_style_write_string(child_spstyle, SP_STYLE_FLAG_ALWAYS); - sp_style_unref(child_spstyle); - bool equal = !strcmp(child_style, parent_style); - g_free(child_style); - g_free(parent_style); + + SPStyle child_spstyle(parent->document); + child_spstyle.mergeString(child_style_construction.c_str()); + Glib::ustring child_style = child_spstyle.write(SP_STYLE_FLAG_ALWAYS); + + bool equal = (child_style == parent_style); // Glib::ustring overloads == operator return equal; } diff --git a/src/trace/potrace/inkscape-potrace.cpp b/src/trace/potrace/inkscape-potrace.cpp index 59dd6f254..69138463d 100644 --- a/src/trace/potrace/inkscape-potrace.cpp +++ b/src/trace/potrace/inkscape-potrace.cpp @@ -25,7 +25,7 @@ #include "trace/imagemap-gdk.h" #include <inkscape.h> -#include <desktop-handles.h> +#include "desktop.h" #include "message-stack.h" #include <sp-path.h> #include <svg/path-string.h> @@ -510,7 +510,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceBrightnessMulti(GdkP SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { ustring msg = ustring::compose(_("Trace: %1. %2 nodes"), traceCount++, nodeCount); - sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg); + desktop->getMessageStack()->flash(Inkscape::NORMAL_MESSAGE, msg); } } } @@ -573,7 +573,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceQuant(GdkPixbuf * th SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { ustring msg = ustring::compose(_("Trace: %1. %2 nodes"), colorIndex, nodeCount); - sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg); + desktop->getMessageStack()->flash(Inkscape::NORMAL_MESSAGE, msg); } } }// for colorIndex diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index cb83541e3..cc3d000a3 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -16,7 +16,7 @@ #include "inkscape.h" #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "message-stack.h" @@ -51,9 +51,9 @@ SPImage *Tracer::getSelectedSPImage() return NULL; } - Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); + Inkscape::MessageStack *msgStack = desktop->getMessageStack(); - Inkscape::Selection *sel = sp_desktop_selection(desktop); + Inkscape::Selection *sel = desktop->getSelection(); if (!sel) { char *msg = _("Select an <b>image</b> to trace"); @@ -217,9 +217,9 @@ Glib::RefPtr<Gdk::Pixbuf> Tracer::sioxProcessImage(SPImage *img, Glib::RefPtr<Gd return Glib::RefPtr<Gdk::Pixbuf>(NULL); } - Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); + Inkscape::MessageStack *msgStack = desktop->getMessageStack(); - Inkscape::Selection *sel = sp_desktop_selection(desktop); + Inkscape::Selection *sel = desktop->getSelection(); if (!sel) { char *msg = _("Select an <b>image</b> to trace"); @@ -397,9 +397,9 @@ void Tracer::traceThread() return; } - Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); + Inkscape::MessageStack *msgStack = desktop->getMessageStack(); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!SP_ACTIVE_DOCUMENT) { diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index e5c605889..98a5a224c 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -4,8 +4,8 @@ set(ui_SRC control-manager.cpp dialog-events.cpp draw-anchor.cpp - interface.cpp - object-edit.cpp + interface.cpp + object-edit.cpp previewholder.cpp shape-editor.cpp tools-switch.cpp diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 153ed9830..c2465932b 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -37,7 +37,7 @@ #include "inkscape.h" #include "io/stringstream.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" // for sp_desktop_set_style, used in _pasteStyle #include "document.h" #include "document-private.h" @@ -201,7 +201,7 @@ void ClipboardManagerImpl::copy(SPDesktop *desktop) if ( desktop == NULL ) { return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // Special case for when the gradient dragger is active - copies gradient color if (desktop->event_context->get_drag()) { @@ -330,13 +330,13 @@ void ClipboardManagerImpl::copySymbol(Inkscape::XML::Node* symbol, gchar const* use->setAttribute("xlink:href", id.c_str() ); // Set a default style in <use> rather than <symbol> so it can be changed. use->setAttribute("style", style ); - - Inkscape::XML::Node *nv_repr = sp_desktop_namedview(inkscape_active_desktop())->getRepr(); +/* disable rev 13709 in rev 13806, following Bug 1365451, comments 13-16 + Inkscape::XML::Node *nv_repr = SP_ACTIVE_DESKTOP->getNamedView()->getRepr(); gdouble scale_units = Inkscape::Util::Quantity::convert(1, nv_repr->attribute("inkscape:document-units"), "px"); gchar *transform_str = sp_svg_transform_write(Geom::Scale(scale_units, scale_units)); use->setAttribute("transform", transform_str); g_free(transform_str); - +*/ _root->appendChild(use); // This min and max sets offsets, we don't have any so set to zero. @@ -435,7 +435,7 @@ bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop) } // check whether something is selected - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { _userWarn(desktop, _("Select <b>object(s)</b> to paste style to.")); return false; @@ -488,7 +488,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a if ( desktop == NULL ) { return false; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { _userWarn(desktop, _("Select <b>object(s)</b> to paste size to.")); return false; @@ -551,7 +551,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) return false; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection && selection->isEmpty()) { _userWarn(desktop, _("Select <b>object(s)</b> to paste live path effect to.")); return false; diff --git a/src/ui/dialog-events.cpp b/src/ui/dialog-events.cpp index 6bd93bbc3..5bc8088a1 100644 --- a/src/ui/dialog-events.cpp +++ b/src/ui/dialog-events.cpp @@ -6,7 +6,7 @@ * bulia byak <bulia@dr.com> * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> * - * Copyright (C) 2003-2007 Authors + * Copyright (C) 2003-2014 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -25,7 +25,7 @@ #include "macros.h" #include <gtk/gtk.h> #include "desktop.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "preferences.h" #include "ui/tools/tool-base.h" @@ -183,12 +183,11 @@ void sp_transientize(GtkWidget *dialog) void on_transientize (SPDesktop *desktop, win_data *wd ) { - sp_transientize_callback (0, desktop, wd); + sp_transientize_callback (desktop, wd); } void -sp_transientize_callback ( InkscapeApplication * /*inkscape*/, - SPDesktop *desktop, win_data *wd ) +sp_transientize_callback ( SPDesktop *desktop, win_data *wd ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint transient_policy = prefs->getIntLimited( "/options/transientpolicy/value", 1, 0, 2); diff --git a/src/ui/dialog-events.h b/src/ui/dialog-events.h index b33eb3f38..b4a5d7c35 100644 --- a/src/ui/dialog-events.h +++ b/src/ui/dialog-events.h @@ -4,7 +4,7 @@ /* Authors: * bulia byak <bulia@dr.com> * - * Copyright (C) 2003 authors + * Copyright (C) 2003-2014 authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -28,8 +28,6 @@ class Entry; } class SPDesktop; - -struct InkscapeApplication; typedef struct { GtkWidget *win; @@ -53,14 +51,14 @@ void sp_transientize ( GtkWidget *win ); void on_transientize ( SPDesktop *desktop, win_data *wd ); -void sp_transientize_callback ( InkscapeApplication *inkscape, - SPDesktop *desktop, +void sp_transientize_callback ( SPDesktop *desktop, win_data *wd ); void on_dialog_hide (GtkWidget *w); void on_dialog_unhide (GtkWidget *w); -gboolean sp_dialog_hide (GObject *object, gpointer data); -gboolean sp_dialog_unhide (GObject *object, gpointer data); + +//gboolean sp_dialog_hide (GObject *object, gpointer data); +//gboolean sp_dialog_unhide (GObject *object, gpointer data); #endif diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 431da7ad1..65bc94011 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -24,7 +24,7 @@ #include "align-and-distribute.h" #include <2geom/transforms.h> #include "ui/widget/spinbutton.h" -#include "desktop-handles.h" + #include "unclump.h" #include "document.h" #include "enums.h" @@ -91,7 +91,7 @@ Action::Action(const Glib::ustring &id, void ActionAlign::do_action(SPDesktop *desktop, int index) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -123,10 +123,10 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) focus = selection->smallestItem(horiz); break; case PAGE: - b = sp_desktop_document(desktop)->preferredBounds(); + b = desktop->getDocument()->preferredBounds(); break; case DRAWING: - b = sp_desktop_document(desktop)->getRoot()->desktopPreferredBounds(); + b = desktop->getDocument()->getRoot()->desktopPreferredBounds(); break; case SELECTION: b = selection->preferredBounds(); @@ -152,7 +152,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) for (std::list<SPItem *>::iterator it(selected.begin()); it != selected.end(); ++it) { - sp_desktop_document (desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); if (!sel_as_group) b = (*it)->desktopPreferredBounds(); if (b && (!focus || (*it) != focus)) { @@ -167,7 +167,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) } if (changed) { - DocumentUndo::done( sp_desktop_document(desktop) , SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done( desktop->getDocument() , SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Align")); } } @@ -247,7 +247,7 @@ private : SPDesktop *desktop = _dialog.getDesktop(); if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; using Inkscape::Util::GSListConstIterator; @@ -337,7 +337,7 @@ private : prefs->setInt("/options/clonecompensation/value", saved_compensation); if (changed) { - DocumentUndo::done( sp_desktop_document(desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done( desktop->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Distribute")); } } @@ -458,13 +458,12 @@ private : // xGap and yGap are the minimum space required between bounding rectangles. double const xGap = removeOverlapXGap.get_value(); double const yGap = removeOverlapYGap.get_value(); - removeoverlap(sp_desktop_selection(_dialog.getDesktop())->itemList(), - xGap, yGap); + removeoverlap(_dialog.getDesktop()->getSelection()->itemList(), xGap, yGap); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(_dialog.getDesktop()->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Remove overlaps")); } }; @@ -490,12 +489,12 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(sp_desktop_selection(_dialog.getDesktop())->itemList()); + graphlayout(_dialog.getDesktop()->getSelection()->itemList()); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(_dialog.getDesktop()->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network")); } }; @@ -547,7 +546,7 @@ private : SPDesktop *desktop = _dialog.getDesktop(); if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; using Inkscape::Util::GSListConstIterator; @@ -588,7 +587,7 @@ private : // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(_dialog.getDesktop()->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Exchange Positions")); } }; @@ -617,12 +616,12 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - unclump ((GSList *) sp_desktop_selection(_dialog.getDesktop())->itemList()); + unclump ((GSList *) _dialog.getDesktop()->getSelection()->itemList()); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(_dialog.getDesktop()->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Unclump")); } }; @@ -644,7 +643,7 @@ private : SPDesktop *desktop = _dialog.getDesktop(); if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; using Inkscape::Util::GSListConstIterator; @@ -677,7 +676,7 @@ private : it != selected.end(); ++it) { - sp_desktop_document (desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); Geom::OptRect item_box = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); if (item_box) { // find new center, staying within bbox @@ -694,7 +693,7 @@ private : // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Randomize positions")); } }; @@ -743,7 +742,7 @@ private : SPDesktop *desktop = _dialog.getDesktop(); if (!desktop) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; using Inkscape::Util::GSListConstIterator; @@ -797,7 +796,7 @@ private : } if (changed) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Distribute text baselines")); } @@ -820,7 +819,7 @@ private : } if (changed) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Align text baselines")); } } @@ -829,14 +828,14 @@ private : -static void on_tool_changed(InkscapeApplication */*inkscape*/, Inkscape::UI::Tools::ToolBase */*context*/, AlignAndDistribute *daad) +static void on_tool_changed(AlignAndDistribute *daad) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop && desktop->getEventContext()) daad->setMode(tools_active(desktop) == TOOLS_NODES); } -static void on_selection_changed(InkscapeApplication */*inkscape*/, Inkscape::Selection */*selection*/, AlignAndDistribute *daad) +static void on_selection_changed(AlignAndDistribute *daad) { daad->randomize_bbox = Geom::OptRect(); } @@ -1044,10 +1043,10 @@ AlignAndDistribute::AlignAndDistribute() contents->pack_start(_nodesFrame, true, true); //Connect to the global tool change signal - g_signal_connect (G_OBJECT (INKSCAPE), "set_eventcontext", G_CALLBACK (on_tool_changed), this); + _toolChangeConn = INKSCAPE.signal_eventcontext_set.connect(sigc::hide<0>(sigc::bind(sigc::ptr_fun(&on_tool_changed), this))); // Connect to the global selection change, to invalidate cached randomize_bbox - g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this); + _selChangeConn = INKSCAPE.signal_selection_changed.connect(sigc::hide<0>(sigc::bind(sigc::ptr_fun(&on_selection_changed), this))); randomize_bbox = Geom::OptRect(); _desktopChangeConn = _deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &AlignAndDistribute::setDesktop) ); @@ -1055,18 +1054,18 @@ AlignAndDistribute::AlignAndDistribute() show_all_children(); - on_tool_changed (NULL, NULL, this); // set current mode + on_tool_changed (this); // set current mode } AlignAndDistribute::~AlignAndDistribute() { - sp_signal_disconnect_by_data (G_OBJECT (INKSCAPE), this); - for (std::list<Action *>::iterator it = _actionList.begin(); it != _actionList.end(); ++it) { delete *it; } + _toolChangeConn.disconnect(); + _selChangeConn.disconnect(); _desktopChangeConn.disconnect(); _deskTrack.disconnect(); } @@ -1075,7 +1074,7 @@ void AlignAndDistribute::setTargetDesktop(SPDesktop *desktop) { if (_desktop != desktop) { _desktop = desktop; - on_tool_changed (NULL, NULL, this); + on_tool_changed (this); } } diff --git a/src/ui/dialog/align-and-distribute.h b/src/ui/dialog/align-and-distribute.h index dfd84535b..eecc30ff8 100644 --- a/src/ui/dialog/align-and-distribute.h +++ b/src/ui/dialog/align-and-distribute.h @@ -127,7 +127,8 @@ protected: SPDesktop *_desktop; DesktopTracker _deskTrack; sigc::connection _desktopChangeConn; - + sigc::connection _toolChangeConn; + sigc::connection _selChangeConn; private: AlignAndDistribute(AlignAndDistribute const &d); AlignAndDistribute& operator=(AlignAndDistribute const &d); diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index d1a675735..fede30b26 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -27,7 +27,7 @@ #include <gtkmm/adjustment.h> #include "desktop.h" -#include "desktop-handles.h" + #include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-context.h" @@ -76,15 +76,12 @@ static gdouble trace_zoom; static SPDocument *trace_doc = NULL; -CloneTiler::CloneTiler (void) : +CloneTiler::CloneTiler () : UI::Widget::Panel ("", "/dialogs/clonetiler/", SP_VERB_DIALOG_CLONETILER), dlg(NULL), desktop(NULL), deskTrack(), - table_row_labels(NULL), - selectChangedConn(), - subselChangedConn(), - selectModifiedConn() + table_row_labels(NULL) { Gtk::Box *contents = _getContents(); contents->set_spacing(0); @@ -1096,7 +1093,7 @@ CloneTiler::CloneTiler (void) : // unitmenu unit_menu = new Inkscape::UI::Widget::UnitMenu(); unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); - unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); + unit_menu->setUnit(SP_ACTIVE_DESKTOP->getNamedView()->display_units->abbr); unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed)); { @@ -1273,12 +1270,13 @@ CloneTiler::CloneTiler (void) : // connect to global selection changed signal (so we can change desktops) and // external_change (so we're not fooled by undo) - g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (clonetiler_change_selection), dlg); - g_signal_connect (G_OBJECT (INKSCAPE), "external_change", G_CALLBACK (clonetiler_external_change), dlg); - g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), G_OBJECT (INKSCAPE)); + selectChangedConn = INKSCAPE.signal_selection_changed.connect(sigc::bind(sigc::ptr_fun(&CloneTiler::clonetiler_change_selection), dlg)); + externChangedConn = INKSCAPE.signal_external_change.connect (sigc::bind(sigc::ptr_fun(&CloneTiler::clonetiler_external_change), dlg)); + + g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(clonetiler_disconnect_gsignal), this); // update now - clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg); + clonetiler_change_selection (SP_ACTIVE_DESKTOP->getSelection(), dlg); } { @@ -1350,7 +1348,7 @@ void CloneTiler::on_picker_color_changed(guint rgba) is_updating = false; } -void CloneTiler::clonetiler_change_selection(InkscapeApplication * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg) +void CloneTiler::clonetiler_change_selection(Inkscape::Selection *selection, GtkWidget *dlg) { GtkWidget *buttons = GTK_WIDGET(g_object_get_data (G_OBJECT(dlg), "buttons_on_tiles")); GtkWidget *status = GTK_WIDGET(g_object_get_data (G_OBJECT(dlg), "status")); @@ -1379,16 +1377,18 @@ void CloneTiler::clonetiler_change_selection(InkscapeApplication * /*inkscape*/, } } -void CloneTiler::clonetiler_external_change(InkscapeApplication * /*inkscape*/, GtkWidget *dlg) +void CloneTiler::clonetiler_external_change(GtkWidget *dlg) { - clonetiler_change_selection (NULL, sp_desktop_selection(SP_ACTIVE_DESKTOP), dlg); + clonetiler_change_selection (SP_ACTIVE_DESKTOP->getSelection(), dlg); } -void CloneTiler::clonetiler_disconnect_gsignal(GObject *widget, gpointer source) +void CloneTiler::clonetiler_disconnect_gsignal(GObject *, gpointer source) { - if (source && G_IS_OBJECT(source)) { - sp_signal_disconnect_by_data (source, widget); - } + g_return_if_fail(source != NULL); + + CloneTiler* dlg = reinterpret_cast<CloneTiler*>(source); + dlg->selectChangedConn.disconnect(); + dlg->externChangedConn.disconnect(); } Geom::Affine CloneTiler::clonetiler_get_transform( @@ -2093,11 +2093,11 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump.")); return; } @@ -2112,13 +2112,13 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) } } - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); unclump (to_unclump); g_slist_free (to_unclump); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_CLONETILER, _("Unclump tiled clones")); } @@ -2144,11 +2144,11 @@ void CloneTiler::clonetiler_remove(GtkWidget */*widget*/, GtkWidget *dlg, bool d return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove.")); return; } @@ -2169,10 +2169,10 @@ void CloneTiler::clonetiler_remove(GtkWidget */*widget*/, GtkWidget *dlg, bool d } g_slist_free (to_delete); - clonetiler_change_selection (NULL, selection, dlg); + clonetiler_change_selection (selection, dlg); if (do_undo) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_CLONETILER, _("Delete tiled clones")); } } @@ -2216,17 +2216,17 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) return; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone.")); return; } // Check if more than one object is selected. if (g_slist_length((GSList *) selection->itemList()) > 1) { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>.")); + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>.")); return; } @@ -2251,7 +2251,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) clonetiler_remove (NULL, dlg, false); - double scale_units = Inkscape::Util::Quantity::convert(1, "px", sp_desktop_document(desktop)->getDefaultUnit()); + double scale_units = Inkscape::Util::Quantity::convert(1, "px", &desktop->getDocument()->getSVGUnit()); double shiftx_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shiftx_per_i", 0, -10000, 10000); double shifty_per_i = 0.01 * prefs->getDoubleLimited(prefs_path + "shifty_per_i", 0, -10000, 10000); @@ -2337,7 +2337,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) SPItem *item = dynamic_cast<SPItem *>(obj); if (dotrace) { - clonetiler_trace_setup (sp_desktop_document(desktop), 1.0, item); + clonetiler_trace_setup (desktop->getDocument(), 1.0, item); } Geom::Point center; @@ -2611,21 +2611,21 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) parent->getRepr()->appendChild(clone); if (blur > 0.0) { - SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone); + SPObject *clone_object = desktop->getDocument()->getObjectByRepr(clone); double perimeter = perimeter_original * t.descrim(); double radius = blur * perimeter; // this is necessary for all newly added clones to have correct bboxes, // otherwise filters won't work: - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); // it's hard to figure out exact width/height of the tile without having an object // that we can take bbox of; however here we only need a lower bound so that blur // margins are not too small, and the perimeter should work - SPFilter *constructed = new_filter_gaussian_blur(sp_desktop_document(desktop), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter); + SPFilter *constructed = new_filter_gaussian_blur(desktop->getDocument(), radius, t.descrim(), t.expansionX(), t.expansionY(), perimeter, perimeter); sp_style_set_property_url (clone_object, "filter", constructed, false); } if (center_set) { - SPObject *clone_object = sp_desktop_document(desktop)->getObjectByRepr(clone); + SPObject *clone_object = desktop->getDocument()->getObjectByRepr(clone); SPItem *item = dynamic_cast<SPItem *>(clone_object); if (clone_object && item) { clone_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -2643,11 +2643,11 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) clonetiler_trace_finish (); } - clonetiler_change_selection (NULL, selection, dlg); + clonetiler_change_selection (selection, dlg); desktop->clearWaitingCursor(); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_DIALOG_CLONETILER, + DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_CLONETILER, _("Create tiled clones")); } diff --git a/src/ui/dialog/clonetiler.h b/src/ui/dialog/clonetiler.h index 70da86338..e5f5638b2 100644 --- a/src/ui/dialog/clonetiler.h +++ b/src/ui/dialog/clonetiler.h @@ -57,8 +57,8 @@ protected: static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/); static void clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg); static void clonetiler_unclump(GtkWidget */*widget*/, void *); - static void clonetiler_change_selection(InkscapeApplication * /*inkscape*/, Inkscape::Selection *selection, GtkWidget *dlg); - static void clonetiler_external_change(InkscapeApplication * /*inkscape*/, GtkWidget *dlg); + static void clonetiler_change_selection(Inkscape::Selection *selection, GtkWidget *dlg); + static void clonetiler_external_change(GtkWidget *dlg); static void clonetiler_disconnect_gsignal(GObject *widget, gpointer source); static void clonetiler_reset(GtkWidget */*widget*/, GtkWidget *dlg); static guint clonetiler_number_of_clones(SPObject *obj); @@ -129,6 +129,7 @@ private: sigc::connection desktopChangeConn; sigc::connection selectChangedConn; + sigc::connection externChangedConn; sigc::connection subselChangedConn; sigc::connection selectModifiedConn; sigc::connection color_changed_connection; diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp index bab7e18e1..a49a47d5c 100644 --- a/src/ui/dialog/color-item.cpp +++ b/src/ui/dialog/color-item.cpp @@ -29,7 +29,7 @@ #include "color-item.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "display/cairo-utils.h" #include "document.h" @@ -476,7 +476,7 @@ void ColorItem::_updatePreviews() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; if ( desktop ) { - SPDocument* document = sp_desktop_document( desktop ); + SPDocument* document = desktop->getDocument(); Inkscape::XML::Node *rroot = document->getReprRoot(); if ( rroot ) { @@ -706,7 +706,7 @@ void ColorItem::buttonClicked(bool secondary) sp_desktop_set_style(desktop, css); sp_repr_css_attr_unref(css); - DocumentUndo::done( sp_desktop_document(desktop), SP_VERB_DIALOG_SWATCHES, descr.c_str() ); + DocumentUndo::done( desktop->getDocument(), SP_VERB_DIALOG_SWATCHES, descr.c_str() ); } } diff --git a/src/ui/dialog/desktop-tracker.cpp b/src/ui/dialog/desktop-tracker.cpp index 3ed998252..0659de67b 100644 --- a/src/ui/dialog/desktop-tracker.cpp +++ b/src/ui/dialog/desktop-tracker.cpp @@ -22,7 +22,6 @@ DesktopTracker::DesktopTracker() : desktop(0), widget(0), hierID(0), - inkID(0), trackActive(false), desktopChangedSig() { @@ -41,7 +40,10 @@ void DesktopTracker::connect(GtkWidget *widget) // Use C/gobject callbacks to avoid gtkmm rewrap-during-destruct issues: hierID = g_signal_connect( G_OBJECT(widget), "hierarchy-changed", G_CALLBACK(hierarchyChangeCB), this ); - inkID = g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(activateDesktopCB), this ); + inkID = INKSCAPE.signal_activate_desktop.connect( + sigc::bind( + sigc::ptr_fun(&DesktopTracker::activateDesktopCB), this) + ); GtkWidget *wdgt = gtk_widget_get_ancestor(widget, SP_TYPE_DESKTOP_WIDGET); if (wdgt && !base) { @@ -60,11 +62,8 @@ void DesktopTracker::disconnect() } hierID = 0; } - if (inkID) { - if (INKSCAPE) { - g_signal_handler_disconnect(G_OBJECT(INKSCAPE), inkID); - } - inkID = 0; + if (inkID.connected()) { + inkID.disconnect(); } } @@ -94,12 +93,12 @@ sigc::connection DesktopTracker::connectDesktopChanged( const sigc::slot<void, S return desktopChangedSig.connect(slot); } -gboolean DesktopTracker::activateDesktopCB(InkscapeApplication */*inkscape*/, SPDesktop *desktop, DesktopTracker *self ) +void DesktopTracker::activateDesktopCB(SPDesktop *desktop, DesktopTracker *self ) { if (self && self->trackActive) { self->setDesktop(desktop); } - return FALSE; + //return FALSE; } bool DesktopTracker::hierarchyChangeCB(GtkWidget * /*widget*/, GtkWidget* /*prev*/, DesktopTracker *self) diff --git a/src/ui/dialog/desktop-tracker.h b/src/ui/dialog/desktop-tracker.h index 7b944ddfa..8cb205a35 100644 --- a/src/ui/dialog/desktop-tracker.h +++ b/src/ui/dialog/desktop-tracker.h @@ -36,7 +36,7 @@ public: sigc::connection connectDesktopChanged( const sigc::slot<void, SPDesktop*> & slot ); private: - static gboolean activateDesktopCB(InkscapeApplication *inkscape, SPDesktop *desktop, DesktopTracker *self ); + static void activateDesktopCB(SPDesktop *desktop, DesktopTracker *self ); static bool hierarchyChangeCB(GtkWidget *widget, GtkWidget* prev, DesktopTracker *self); void handleHierarchyChange(); @@ -46,7 +46,7 @@ private: SPDesktop *desktop; GtkWidget *widget; gulong hierID; - gulong inkID; + sigc::connection inkID; bool trackActive; sigc::signal<void, SPDesktop*> desktopChangedSig; }; diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp index 213965a18..27d88bae7 100644 --- a/src/ui/dialog/dialog.cpp +++ b/src/ui/dialog/dialog.cpp @@ -25,7 +25,7 @@ #include "inkscape.h" #include "ui/tools/tool-base.h" #include "desktop.h" -#include "desktop-handles.h" + #include "shortcuts.h" #include "preferences.h" #include "ui/interface.h" @@ -41,12 +41,6 @@ namespace Inkscape { namespace UI { namespace Dialog { -void sp_retransientize(InkscapeApplication */*inkscape*/, SPDesktop *desktop, gpointer dlgPtr) -{ - Dialog *dlg = static_cast<Dialog *>(dlgPtr); - dlg->onDesktopActivated (desktop); -} - gboolean sp_retransientize_again(gpointer dlgPtr) { Dialog *dlg = static_cast<Dialog *>(dlgPtr); @@ -54,30 +48,6 @@ gboolean sp_retransientize_again(gpointer dlgPtr) return FALSE; // so that it is only called once } -void sp_dialog_shutdown(GObject * /*object*/, gpointer dlgPtr) -{ - Dialog *dlg = static_cast<Dialog *>(dlgPtr); - dlg->onShutdown(); -} - - -static void hideCallback(GObject * /*object*/, gpointer dlgPtr) -{ - g_return_if_fail( dlgPtr != NULL ); - - Dialog *dlg = static_cast<Dialog *>(dlgPtr); - dlg->onHideF12(); -} - -static void unhideCallback(GObject * /*object*/, gpointer dlgPtr) -{ - g_return_if_fail( dlgPtr != NULL ); - - Dialog *dlg = static_cast<Dialog *>(dlgPtr); - dlg->onShowF12(); -} - - //===================================================================== Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_path, int verb_num, @@ -103,10 +73,10 @@ Dialog::Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_pat _behavior = behavior_factory(*this); _desktop = SP_ACTIVE_DESKTOP; - g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(sp_retransientize), (void *)this); - g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(hideCallback), (void *)this); - g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(unhideCallback), (void *)this); - g_signal_connect(G_OBJECT(INKSCAPE), "shut_down", G_CALLBACK(sp_dialog_shutdown), (void *)this); + INKSCAPE.signal_activate_desktop.connect(sigc::mem_fun(*this, &Dialog::onDesktopActivated)); + INKSCAPE.signal_dialogs_hide.connect(sigc::mem_fun(*this, &Dialog::onHideF12)); + INKSCAPE.signal_dialogs_unhide.connect(sigc::mem_fun(*this, &Dialog::onShowF12)); + INKSCAPE.signal_shut_down.connect(sigc::mem_fun(*this, &Dialog::onShutdown)); Glib::wrap(gobj())->signal_event().connect(sigc::mem_fun(*this, &Dialog::_onEvent)); Glib::wrap(gobj())->signal_key_press_event().connect(sigc::mem_fun(*this, &Dialog::_onKeyPress)); @@ -340,7 +310,7 @@ void Dialog::_defocus() Inkscape::Selection* Dialog::_getSelection() { - return sp_desktop_selection(SP_ACTIVE_DESKTOP); + return SP_ACTIVE_DESKTOP->getSelection(); } } // namespace Dialog diff --git a/src/ui/dialog/dialog.h b/src/ui/dialog/dialog.h index ccff43a56..9c7efd47b 100644 --- a/src/ui/dialog/dialog.h +++ b/src/ui/dialog/dialog.h @@ -30,7 +30,6 @@ namespace Dialog { enum BehaviorType { FLOATING, DOCK }; -void sp_retransientize(InkscapeApplication *inkscape, SPDesktop *desktop, gpointer dlgPtr); gboolean sp_retransientize_again(gpointer dlgPtr); void sp_dialog_shutdown(GObject *object, gpointer dlgPtr); diff --git a/src/ui/dialog/document-metadata.cpp b/src/ui/dialog/document-metadata.cpp index 77ea175d9..da1facc08 100644 --- a/src/ui/dialog/document-metadata.cpp +++ b/src/ui/dialog/document-metadata.cpp @@ -20,7 +20,7 @@ #include "document-metadata.h" #include "desktop.h" -#include "desktop-handles.h" + #include "inkscape.h" #include "rdf.h" #include "sp-namedview.h" @@ -100,7 +100,7 @@ DocumentMetadata::init() { update(); - Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); + Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); repr->addListener (&_repr_events, this); show_all_children(); @@ -108,7 +108,7 @@ DocumentMetadata::init() DocumentMetadata::~DocumentMetadata() { - Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); + Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); repr->removeListenerByData (this); for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it) @@ -217,23 +217,23 @@ void DocumentMetadata::update() void DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->addListener (&_repr_events, this); update(); } void -DocumentMetadata::_handleActivateDesktop(InkscapeApplication *, SPDesktop *desktop) +DocumentMetadata::_handleActivateDesktop(SPDesktop *desktop) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->addListener(&_repr_events, this); update(); } void -DocumentMetadata::_handleDeactivateDesktop(InkscapeApplication *, SPDesktop *desktop) +DocumentMetadata::_handleDeactivateDesktop(SPDesktop *desktop) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->removeListenerByData(this); } diff --git a/src/ui/dialog/document-metadata.h b/src/ui/dialog/document-metadata.h index 77084bc3d..cde5d92fd 100644 --- a/src/ui/dialog/document-metadata.h +++ b/src/ui/dialog/document-metadata.h @@ -28,6 +28,7 @@ # include <gtkmm/table.h> #endif +#include "inkscape.h" #include "ui/widget/licensor.h" #include "ui/widget/registry.h" @@ -56,8 +57,8 @@ protected: void init(); void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); - void _handleActivateDesktop(InkscapeApplication *application, SPDesktop *desktop); - void _handleDeactivateDesktop(InkscapeApplication *application, SPDesktop *desktop); + void _handleActivateDesktop(SPDesktop *desktop); + void _handleDeactivateDesktop(SPDesktop *desktop); Gtk::Notebook _notebook; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 6064c2a5e..af7ca678a 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -26,7 +26,7 @@ #include "document-properties.h" #include "display/canvas-grid.h" #include "document.h" -#include "desktop-handles.h" + #include "desktop.h" #include "inkscape.h" #include "io/sys.h" @@ -114,7 +114,7 @@ DocumentProperties::DocumentProperties() _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 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), + _rum_deflt(_("Display _units:"), "inkscape:document-units", _wr), _page_sizer(_wr), //--------------------------------------------------------------- //General snap options @@ -186,9 +186,9 @@ void DocumentProperties::init() { update(); - Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); + Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); repr->addListener (&_repr_events, this); - Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr(); + Inkscape::XML::Node *root = getDesktop()->getDocument()->getRoot()->getRepr(); root->addListener (&_repr_events, this); show_all_children(); @@ -197,9 +197,9 @@ void DocumentProperties::init() DocumentProperties::~DocumentProperties() { - Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); + Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); repr->removeListenerByData (this); - Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr(); + Inkscape::XML::Node *root = getDesktop()->getDocument()->getRoot()->getRepr(); root->removeListenerByData (this); for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it) @@ -1384,7 +1384,7 @@ void DocumentProperties::populate_script_lists(){ void DocumentProperties::update_gridspage() { SPDesktop *dt = getDesktop(); - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); //remove all tabs while (_grids_notebook.get_n_pages() != 0) { @@ -1428,7 +1428,7 @@ void DocumentProperties::build_gridspage() /// Dissenting view: you want snapping without grid. SPDesktop *dt = getDesktop(); - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); (void)nv; _grids_label_crea.set_markup(_("<b>Creation</b>")); @@ -1464,7 +1464,7 @@ void DocumentProperties::update() if (_wr.isUpdating()) return; SPDesktop *dt = getDesktop(); - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); _wr.setUpdating (true); set_sensitive (true); @@ -1480,25 +1480,25 @@ void DocumentProperties::update() _rcb_antialias.set_xml_target(root->getRepr(), dt->getDocument()); _rcb_antialias.setActive(root->style->shape_rendering.computed != SP_CSS_SHAPE_RENDERING_CRISPEDGES); - if (nv->doc_units) { - _rum_deflt.setUnit (nv->doc_units->abbr); + if (nv->display_units) { + _rum_deflt.setUnit (nv->display_units->abbr); } - double doc_w = sp_desktop_document(dt)->getRoot()->width.value; - Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit)->abbr; + double doc_w = dt->getDocument()->getRoot()->width.value; + Glib::ustring doc_w_unit = unit_table.getUnit(dt->getDocument()->getRoot()->width.unit)->abbr; if (doc_w_unit == "") { doc_w_unit = "px"; - } else if (doc_w_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + } else if (doc_w_unit == "%" && dt->getDocument()->getRoot()->viewBox_set) { doc_w_unit = "px"; - doc_w = sp_desktop_document(dt)->getRoot()->viewBox.width(); + doc_w = dt->getDocument()->getRoot()->viewBox.width(); } - double doc_h = sp_desktop_document(dt)->getRoot()->height.value; - Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit)->abbr; + double doc_h = dt->getDocument()->getRoot()->height.value; + Glib::ustring doc_h_unit = unit_table.getUnit(dt->getDocument()->getRoot()->height.unit)->abbr; if (doc_h_unit == "") { doc_h_unit = "px"; - } else if (doc_h_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + } else if (doc_h_unit == "%" && dt->getDocument()->getRoot()->viewBox_set) { doc_h_unit = "px"; - doc_h = sp_desktop_document(dt)->getRoot()->viewBox.height(); + doc_h = dt->getDocument()->getRoot()->viewBox.height(); } _page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit)); _page_sizer.updateFitMarginsUI(nv->getRepr()); @@ -1592,27 +1592,27 @@ void DocumentProperties::save_default_metadata() void DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->addListener(&_repr_events, this); Inkscape::XML::Node *root = document->getRoot()->getRepr(); root->addListener(&_repr_events, this); update(); } -void DocumentProperties::_handleActivateDesktop(InkscapeApplication *, SPDesktop *desktop) +void DocumentProperties::_handleActivateDesktop(SPDesktop *desktop) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->addListener(&_repr_events, this); - Inkscape::XML::Node *root = sp_desktop_document(desktop)->getRoot()->getRepr(); + Inkscape::XML::Node *root = desktop->getDocument()->getRoot()->getRepr(); root->addListener(&_repr_events, this); update(); } -void DocumentProperties::_handleDeactivateDesktop(InkscapeApplication *, SPDesktop *desktop) +void DocumentProperties::_handleDeactivateDesktop(SPDesktop *desktop) { - Inkscape::XML::Node *repr = sp_desktop_namedview(desktop)->getRepr(); + Inkscape::XML::Node *repr = desktop->getNamedView()->getRepr(); repr->removeListenerByData(this); - Inkscape::XML::Node *root = sp_desktop_document(desktop)->getRoot()->getRepr(); + Inkscape::XML::Node *root = desktop->getDocument()->getRoot()->getRepr(); root->removeListenerByData(this); } @@ -1647,8 +1647,8 @@ static void on_repr_attr_changed(Inkscape::XML::Node *, gchar const *, gchar con void DocumentProperties::onNewGrid() { SPDesktop *dt = getDesktop(); - Inkscape::XML::Node *repr = sp_desktop_namedview(dt)->getRepr(); - SPDocument *doc = sp_desktop_document(dt); + Inkscape::XML::Node *repr = dt->getNamedView()->getRepr(); + SPDocument *doc = dt->getDocument(); Glib::ustring typestring = _grids_combo_gridtype.get_active_text(); CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str())); @@ -1665,7 +1665,7 @@ void DocumentProperties::onRemoveGrid() return; SPDesktop *dt = getDesktop(); - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); Inkscape::CanvasGrid * found_grid = NULL; int i = 0; for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works. @@ -1679,7 +1679,7 @@ void DocumentProperties::onRemoveGrid() // delete the grid that corresponds with the selected tab // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer! found_grid->repr->parent()->removeChild(found_grid->repr); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid")); + DocumentUndo::done(dt->getDocument(), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid")); } } @@ -1697,7 +1697,7 @@ void DocumentProperties::onDocUnitChange() } - Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); + Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); Inkscape::Util::Unit const *old_doc_unit = unit_table.getUnit("px"); if(repr->attribute("inkscape:document-units")) { old_doc_unit = unit_table.getUnit(repr->attribute("inkscape:document-units")); @@ -1708,7 +1708,10 @@ void DocumentProperties::onDocUnitChange() Inkscape::SVGOStringStream os; os << doc_unit->abbr; repr->setAttribute("inkscape:document-units", os.str().c_str()); - + + // Disable changing of SVG Units. The intent here is to change the units in the UI, not the units in SVG. + // This code should be moved (and fixed) once we have an "SVG Units" setting that sets what units are used in SVG data. +#if 0 // Set viewBox if (doc->getRoot()->viewBox_set) { gdouble scale = Inkscape::Util::Quantity::convert(1, old_doc_unit, doc_unit); @@ -1760,10 +1763,11 @@ void DocumentProperties::onDocUnitChange() prefs->setBool("/options/transform/rectcorners", transform_rectcorners); prefs->setBool("/options/transform/pattern", transform_pattern); prefs->setBool("/options/transform/gradient", transform_gradient); +#endif doc->setModifiedSinceSave(); - DocumentUndo::done(doc, SP_VERB_NONE, _("Changed document unit")); + DocumentUndo::done(doc, SP_VERB_NONE, _("Changed default display unit")); } } // namespace Dialog diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index ee7e88b18..b1f90b4b7 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -94,8 +94,8 @@ protected: void save_default_metadata(); void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); - void _handleActivateDesktop(InkscapeApplication *application, SPDesktop *desktop); - void _handleDeactivateDesktop(InkscapeApplication *application, SPDesktop *desktop); + void _handleActivateDesktop(SPDesktop *desktop); + void _handleDeactivateDesktop(SPDesktop *desktop); Inkscape::XML::SignalObserver _emb_profiles_observer, _scripts_observer; Gtk::Notebook _notebook; diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index b044a6e2c..6d90c792e 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -51,10 +51,10 @@ #include "ui/widget/unit-menu.h" #include "util/units.h" #include "helper/window.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "document.h" #include "document-undo.h" -#include "desktop-handles.h" + #include "sp-item.h" #include "selection.h" #include "file.h" @@ -101,7 +101,6 @@ #define EXPORT_COORD_PRECISION 3 -#include "../../desktop-handles.h" #include "../../document.h" #include "../../document-undo.h" #include "verbs.h" @@ -206,7 +205,7 @@ Export::Export (void) : SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { - unit_selector.setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); + unit_selector.setUnit(desktop->getNamedView()->display_units->abbr); } unitChangedConn = unit_selector.signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged)); unitbox.pack_end(unit_selector, false, false, 0); @@ -588,7 +587,7 @@ Glib::ustring Export::create_filepath_from_id (Glib::ustring id, const Glib::ust } if (directory.empty()) { - directory = homedir_path(NULL); + directory = INKSCAPE.homedir_path(NULL); } Glib::ustring filename = Glib::build_filename(directory, id+".png"); @@ -606,7 +605,7 @@ void Export::onBatchClicked () void Export::updateCheckbuttons () { - gint num = g_slist_length((GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); + gint num = g_slist_length((GSList *) SP_ACTIVE_DESKTOP->getSelection()->itemList()); if (num >= 2) { batch_export.set_sensitive(true); batch_export.set_label(g_strdup_printf (ngettext("B_atch export %d selected object","B_atch export %d selected objects",num), num)); @@ -622,7 +621,7 @@ inline void Export::findDefaultSelection() { selection_type key = SELECTION_NUMBER_OF; - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { + if ((SP_ACTIVE_DESKTOP->getSelection())->isEmpty() == false) { key = SELECTION_SELECTION; } @@ -660,15 +659,15 @@ inline void Export::findDefaultSelection() */ void Export::onSelectionChanged() { - Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); if ((current_key == SELECTION_DRAWING || current_key == SELECTION_PAGE) && - (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false && + (SP_ACTIVE_DESKTOP->getSelection())->isEmpty() == false && was_empty) { current_key = SELECTION_SELECTION; selectiontype_buttons[current_key]->set_active(true); } - was_empty = (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty(); + was_empty = (SP_ACTIVE_DESKTOP->getSelection())->isEmpty(); if ( selection && SELECTION_CUSTOM != current_key) { @@ -685,7 +684,7 @@ void Export::onSelectionModified ( guint /*flags*/ ) case SELECTION_DRAWING: if ( SP_ACTIVE_DESKTOP ) { SPDocument *doc; - doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); if (bbox) { setArea ( bbox->left(), @@ -696,7 +695,7 @@ void Export::onSelectionModified ( guint /*flags*/ ) } break; case SELECTION_SELECTION: - Sel = sp_desktop_selection(SP_ACTIVE_DESKTOP); + Sel = SP_ACTIVE_DESKTOP->getSelection(); if (Sel->isEmpty() == false) { Geom::OptRect bbox = Sel->visualBounds(); if (bbox) @@ -736,16 +735,16 @@ void Export::onAreaToggled () SPDocument *doc; Geom::OptRect bbox; bbox = Geom::Rect(Geom::Point(0.0, 0.0),Geom::Point(0.0, 0.0)); - doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + doc = SP_ACTIVE_DESKTOP->getDocument(); /* Notice how the switch is used to 'fall through' here to get various backups. If you modify this without noticing you'll probabaly screw something up. */ switch (key) { case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) + if ((SP_ACTIVE_DESKTOP->getSelection())->isEmpty() == false) { - bbox = sp_desktop_selection (SP_ACTIVE_DESKTOP)->visualBounds(); + bbox = SP_ACTIVE_DESKTOP->getSelection()->visualBounds(); /* Only if there is a selection that we can set do we break, otherwise we fall through to the drawing */ @@ -810,15 +809,15 @@ void Export::onAreaToggled () break; } case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { + if ((SP_ACTIVE_DESKTOP->getSelection())->isEmpty() == false) { - sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), filename, &xdpi, &ydpi); + sp_selection_get_export_hints (SP_ACTIVE_DESKTOP->getSelection(), filename, &xdpi, &ydpi); /* If we still don't have a filename -- let's build one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList(); + const GSList * reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); for(; reprlst != NULL; reprlst = reprlst->next) { Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data; if (repr->attribute("id")) { @@ -1002,8 +1001,8 @@ void Export::onExport () SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) return; - SPNamedView *nv = sp_desktop_namedview(desktop); - SPDocument *doc = sp_desktop_document (desktop); + SPNamedView *nv = desktop->getNamedView(); + SPDocument *doc = desktop->getDocument(); bool exportSuccessful = false; @@ -1011,7 +1010,7 @@ void Export::onExport () if (batch_export.get_active ()) { // Batch export of selected objects - gint num = g_slist_length(const_cast<GSList *>(sp_desktop_selection(desktop)->itemList())); + gint num = g_slist_length(const_cast<GSList *>(desktop->getSelection()->itemList())); gint n = 0; if (num < 1) { @@ -1025,7 +1024,7 @@ void Export::onExport () gint export_count = 0; - for (GSList *i = const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()); i && !interrupted; i = i->next) { + for (GSList *i = const_cast<GSList *>(desktop->getSelection()->itemList()); i && !interrupted; i = i->next) { SPItem *item = reinterpret_cast<SPItem *>(i->data); prog_dlg->set_data("current", GINT_TO_POINTER(n)); @@ -1070,7 +1069,7 @@ void Export::onExport () nv->pagecolor, onProgressCallback, (void*)prog_dlg, TRUE, // overwrite without asking - hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL + hide ? const_cast<GSList *>(desktop->getSelection()->itemList()) : NULL )) { gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); @@ -1154,12 +1153,12 @@ void Export::onExport () prog_dlg->set_data("total", GINT_TO_POINTER(0)); /* Do export */ - ExportResult status = sp_export_png_file(sp_desktop_document(desktop), path.c_str(), + ExportResult status = sp_export_png_file(desktop->getDocument(), path.c_str(), Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, nv->pagecolor, onProgressCallback, (void*)prog_dlg, FALSE, - hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL + hide ? const_cast<GSList *>(desktop->getSelection()->itemList()) : NULL ); if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); @@ -1231,7 +1230,7 @@ void Export::onExport () bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); - reprlst = sp_desktop_selection(desktop)->reprList(); + reprlst = desktop->getSelection()->reprList(); for(; reprlst != NULL; reprlst = reprlst->next) { Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data); @@ -1463,8 +1462,8 @@ void Export::detectSize() { i++) { switch (this_test[i]) { case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { - Geom::OptRect bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds(SPItem::VISUAL_BBOX); + if ((SP_ACTIVE_DESKTOP->getSelection())->isEmpty() == false) { + Geom::OptRect bbox = (SP_ACTIVE_DESKTOP->getSelection())->bounds(SPItem::VISUAL_BBOX); if ( bbox && bbox_equal(*bbox,current_bbox)) { key = SELECTION_SELECTION; @@ -1472,7 +1471,7 @@ void Export::detectSize() { } break; case SELECTION_DRAWING: { - SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + SPDocument *doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); @@ -1485,7 +1484,7 @@ void Export::detectSize() { case SELECTION_PAGE: { SPDocument *doc; - doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::Point x(0.0, 0.0); Geom::Point y(doc->getWidth().value("px"), diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 5d330f7f0..17cf835cd 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -577,8 +577,9 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) SVGPreview::SVGPreview() { - if (!INKSCAPE) - inkscape_application_init("", false); + // \FIXME Why?!!?? + if (!Inkscape::Application::exists()) + Inkscape::Application::create("", false); document = NULL; viewerGtk = NULL; set_size_request(150, 150); @@ -1083,7 +1084,7 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow, const Gl } // allow easy access to the user's own templates folder - gchar *templates = profile_path("templates"); + gchar *templates = Inkscape::Application::profile_path("templates"); if (Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) && Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) && g_path_is_absolute(templates)) { add_shortcut_folder(templates); diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index c55d55cda..8141f7696 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -16,7 +16,7 @@ */ #include "ui/widget/notebook-page.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "document.h" #include "fill-and-stroke.h" diff --git a/src/ui/dialog/fill-and-stroke.h b/src/ui/dialog/fill-and-stroke.h index 35c98ef9c..f2a6bf39d 100644 --- a/src/ui/dialog/fill-and-stroke.h +++ b/src/ui/dialog/fill-and-stroke.h @@ -41,8 +41,7 @@ public: virtual void setDesktop(SPDesktop *desktop); - void selectionChanged(InkscapeApplication *inkscape, - Inkscape::Selection *selection); + //void selectionChanged(Inkscape::Selection *selection); void showPageFill(); void showPageStrokePaint(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index bd44846a3..3da0e0043 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -33,7 +33,7 @@ #include <glibmm/stringutils.h> #include "desktop.h" -#include "desktop-handles.h" + #include "dir-util.h" #include "document.h" #include "document-undo.h" @@ -688,7 +688,7 @@ public: private: void select_svg_element(){ - Inkscape::Selection* sel = sp_desktop_selection(_desktop); + Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); if (!node || !node->matchAttributeName("id")) return; @@ -1416,7 +1416,7 @@ void FilterEffectsDialog::FilterModifier::setTargetDesktop(SPDesktop *desktop) _selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &FilterModifier::on_modified_selection))); } _doc_replaced = desktop->connectDocumentReplaced( sigc::mem_fun(*this, &FilterModifier::on_document_replaced)); - _resource_changed = sp_desktop_document(desktop)->connectResourcesChanged("filter",sigc::mem_fun(*this, &FilterModifier::update_filters)); + _resource_changed = desktop->getDocument()->connectResourcesChanged("filter",sigc::mem_fun(*this, &FilterModifier::update_filters)); _dialog.setDesktop(desktop); update_filters(); @@ -1441,7 +1441,7 @@ void FilterEffectsDialog::FilterModifier::on_document_replaced(SPDesktop * /*des // When the selection changes, show the active filter(s) in the dialog void FilterEffectsDialog::FilterModifier::on_change_selection() { - Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); update_selection(selection); } @@ -1537,9 +1537,9 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri if(iter) { SPDesktop *desktop = _dialog.getDesktop(); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); SPFilter* filter = (*iter)[_columns.filter]; - Inkscape::Selection *sel = sp_desktop_selection(desktop); + Inkscape::Selection *sel = desktop->getSelection(); /* If this filter is the only one used in the selection, unset it */ if((*iter)[_columns.sel] == 1) @@ -1571,7 +1571,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri void FilterEffectsDialog::FilterModifier::update_filters() { SPDesktop* desktop = _dialog.getDesktop(); - SPDocument* document = sp_desktop_document(desktop); + SPDocument* document = desktop->getDocument(); const GSList* filters = document->getResourceList("filter"); _model->clear(); @@ -1627,7 +1627,7 @@ void FilterEffectsDialog::FilterModifier::filter_list_button_release(GdkEventBut void FilterEffectsDialog::FilterModifier::add_filter() { - SPDocument* doc = sp_desktop_document(_dialog.getDesktop()); + SPDocument* doc = _dialog.getDesktop()->getDocument(); SPFilter* filter = new_filter(doc); const int count = _model->children().size(); @@ -1937,7 +1937,7 @@ void FilterEffectsDialog::PrimitiveList::remove_selected() //XML Tree being used directly here while it shouldn't be. sp_repr_unparent(prim->getRepr()); - DocumentUndo::done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_FILTER_EFFECTS, + DocumentUndo::done(_dialog.getDesktop()->getDocument(), SP_VERB_DIALOG_FILTER_EFFECTS, _("Remove filter primitive")); update(); diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 1a7832688..6d8d64607 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -29,7 +29,7 @@ #include "document.h" #include "document-undo.h" #include "selection.h" -#include "desktop-handles.h" + #include "ui/dialog-events.h" #include "verbs.h" @@ -238,7 +238,7 @@ Find::Find() show_all_children(); - Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); SPItem *item = selection->singleItem(); if (item) { if (dynamic_cast<SPText *>(item) || dynamic_cast<SPFlowtext *>(item)) { @@ -824,7 +824,7 @@ void Find::onAction() if (check_scope_layer.get_active()) { l = all_items (desktop->currentLayer(), l, hidden, locked); } else { - l = all_items(sp_desktop_document(desktop)->getRoot(), l, hidden, locked); + l = all_items(desktop->getDocument()->getRoot(), l, hidden, locked); } } guint all = g_slist_length (l); @@ -850,7 +850,7 @@ void Find::onAction() button_replace.set_sensitive(attributenameyok); } - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(n); SPObject *obj = reinterpret_cast<SPObject *>(n->data); @@ -859,13 +859,13 @@ void Find::onAction() scroll_to_show_item(desktop, item); if (_action_replace) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Replace text or property")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Replace text or property")); } } else { status.set_text(_("Nothing found")); if (!check_scope_selection.get_active()) { - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); } desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No objects found")); diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index db7bdf222..ae03bdf0e 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -28,7 +28,7 @@ #include "selection.h" #include "ui/dialog-events.h" -#include "desktop-handles.h" + #include "selection-chemistry.h" #include "preferences.h" @@ -134,7 +134,7 @@ FontSubstitution::show(Glib::ustring out, GSList *l) if (cbSelect->get_active()) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(l); } diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 9bad90e7c..2b9053da9 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -709,13 +709,12 @@ void GlyphsPanel::readSelection( bool updateStyle, bool /*updateContent*/ ) calcCanInsert(); if (targetDesktop && updateStyle) { - //SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + //SPStyle query(SP_ACTIVE_DOCUMENT); - //int result_family = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - //int result_style = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - //int result_numbers = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + //int result_family = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTFAMILY); + //int result_style = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTSTYLE); + //int result_numbers = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - //sp_style_unref(query); } } diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 1417b39fa..d3ccb9bde 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -31,7 +31,7 @@ #include "verbs.h" #include "preferences.h" #include "inkscape.h" -#include "desktop-handles.h" + #include "selection.h" #include "document.h" #include "document-undo.h" @@ -165,9 +165,9 @@ void GridArrangeTab::arrange() grid_top = 99999; SPDesktop *desktop = Parent->getDesktop(); - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); const GSList *items = selection ? selection->itemList() : 0; cnt=0; for (; items != NULL; items = items->next) { @@ -347,7 +347,7 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h g_slist_free (current_row); } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_ARRANGE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_ARRANGE, _("Arrange in a grid")); } @@ -567,17 +567,6 @@ void GridArrangeTab::updateSelection() } - -/*########################## -## Experimental -##########################*/ - -static void updateSelectionCallback(InkscapeApplication */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) -{ - dlg->updateSelection(); -} - - //######################################################################### //## C O N S T R U C T O R / D E S T R U C T O R //######################################################################### @@ -605,7 +594,7 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) { // Selection Change signal - g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); + INKSCAPE.signal_selection_changed.connect(sigc::hide<0>(sigc::mem_fun(*this, &GridArrangeTab::updateSelection))); } Gtk::Box *contents = this; diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 4519a905f..af8e2cc31 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -24,7 +24,7 @@ #include "document-undo.h" #include "sp-guide.h" #include "sp-namedview.h" -#include "desktop-handles.h" + #include "ui/tools/tool-base.h" #include "widgets/desktop-widget.h" #include <glibmm/i18n.h> @@ -216,8 +216,8 @@ void GuidelinePropertiesDialog::_setup() { /* fixme: We should allow percents here too, as percents of the canvas size */ _unit_menu.setUnitType(UNIT_TYPE_LINEAR); _unit_menu.setUnit("px"); - if (_desktop->namedview->doc_units) { - _unit_menu.setUnit( _desktop->namedview->doc_units->abbr ); + if (_desktop->namedview->display_units) { + _unit_menu.setUnit( _desktop->namedview->display_units->abbr ); } _spin_angle.setUnit(_angle_unit_status); diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 468e85d36..b908a90cb 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -35,7 +35,7 @@ #include "ui/widget/frame.h" #include "desktop.h" -#include "desktop-handles.h" + #include "display/drawing.h" #include "document.h" #include "inkscape.h" @@ -362,7 +362,7 @@ void IconPreviewPanel::refreshPreview() target = (hold && !targetId.empty()) ? desktop->doc()->getObjectById( targetId.c_str() ) : 0; if ( !target ) { targetId.clear(); - Inkscape::Selection * sel = sp_desktop_selection(desktop); + Inkscape::Selection * sel = desktop->getSelection(); if ( sel ) { //g_message("found a selection to play with"); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 75cfe5bfe..8d507d037 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -32,7 +32,7 @@ #include "util/units.h" #include <iostream> #include "enums.h" -#include "desktop-handles.h" + #include "extension/internal/gdkpixbuf-input.h" #include "message-stack.h" #include "style.h" @@ -213,10 +213,10 @@ static void StyleFromSelectionToTool(Glib::ustring const &prefs_path, StyleSwatc if (desktop == NULL) return; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects selected</b> to take the style from.")); return; } @@ -225,7 +225,7 @@ static void StyleFromSelectionToTool(Glib::ustring const &prefs_path, StyleSwatc /* TODO: If each item in the selection has the same style then don't consider it an error. * Maybe we should try to handle multiple selections anyway, e.g. the intersection of the * style attributes for the selected items. */ - sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, + desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>More than one object selected.</b> Cannot take style from multiple objects.")); return; } @@ -279,10 +279,14 @@ void InkscapePreferences::AddNewObjectsStyle(DialogPage &p, Glib::ustring const p.add_line( true, "", *hb, "", ""); // style swatch - Gtk::Button* button = Gtk::manage( new Gtk::Button(_("Take from selection"),true)); + Gtk::Button* button = Gtk::manage( new Gtk::Button(_("Take from selection"), true)); StyleSwatch *swatch = 0; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getInt(prefs_path + "/usecurrent")) { + button->set_sensitive(false); + } + SPCSSAttr *css = prefs->getStyle(prefs_path + "/style"); swatch = new StyleSwatch(css, _("This tool's style of new objects")); hb->add(*swatch); @@ -461,7 +465,7 @@ void InkscapePreferences::initPageTools() _page_text.add_line( false, _("Text size unit type:"), _font_unit_type, "", _("Set the type of unit used in the text toolbar and text dialogs"), false); _font_output_px.init ( _("Always output text size in pixels (px)"), "/options/font/textOutputPx", true); - _page_text.add_line( false, "", _font_output_px, "", _("Always convert the text size units above into pixels (px) before saving to file")); +// _page_text.add_line( false, "", _font_output_px, "", _("Always convert the text size units above into pixels (px) before saving to file")); this->AddNewObjectsStyle(_page_text, "/tools/text"); @@ -1913,7 +1917,7 @@ void InkscapePreferences::initPageSystem() _page_system.add_group_header( _("System info")); - _sys_user_config.set_text((char const *)profile_path("")); + _sys_user_config.set_text((char const *)Inkscape::Application::profile_path("")); _sys_user_config.set_editable(false); _page_system.add_line(true, _("User config: "), _sys_user_config, "", _("Location of users configuration"), true); diff --git a/src/ui/dialog/layer-properties.cpp b/src/ui/dialog/layer-properties.cpp index d5540b88a..1b8fbb3f7 100644 --- a/src/ui/dialog/layer-properties.cpp +++ b/src/ui/dialog/layer-properties.cpp @@ -23,7 +23,7 @@ #include "document-undo.h" #include "layer-manager.h" #include "message-stack.h" -#include "desktop-handles.h" + #include "sp-object.h" #include "sp-item.h" #include "verbs.h" @@ -132,7 +132,7 @@ LayerPropertiesDialog::_apply() g_assert(_strategy != NULL); _strategy->perform(*this); - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_NONE, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_NONE, _("Add layer")); _close(); @@ -364,7 +364,7 @@ void LayerPropertiesDialog::Rename::perform(LayerPropertiesDialog &dialog) { (gchar *)name.c_str(), FALSE ); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, + DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE, _("Rename layer")); // TRANSLATORS: This means "The layer has been renamed" desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Renamed layer")); @@ -399,7 +399,7 @@ void LayerPropertiesDialog::Create::perform(LayerPropertiesDialog &dialog) { if (!name.empty()) { desktop->layer_manager->renameLayer( new_layer, (gchar *)name.c_str(), TRUE ); } - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); desktop->setCurrentLayer(new_layer); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("New layer created.")); } diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index eb3857ee7..3b87597c8 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -23,7 +23,7 @@ #include <vector> #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "gtkmm/widget.h" @@ -398,7 +398,7 @@ LivePathEffectEditor::setDesktop(SPDesktop *desktop) lpe_list_locked = false; current_desktop = desktop; if (desktop) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection_changed_connection = selection->connectChanged( sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) ); selection_modified_connection = selection->connectModified( @@ -475,9 +475,13 @@ LivePathEffectEditor::onAdd() // run sp_selection_clone_original_path_lpe sp_selection_clone_original_path_lpe(current_desktop); + SPItem *new_item = sel->singleItem(); - new_item->getRepr()->setAttribute("id", id); - new_item->getRepr()->setAttribute("transform", transform); + // Check that the cloning was successful. We don't want to change the ID of the original referenced path! + if (new_item && (new_item != orig)) { + new_item->getRepr()->setAttribute("id", id); + new_item->getRepr()->setAttribute("transform", transform); + } g_free(id); g_free(transform); @@ -506,7 +510,7 @@ LivePathEffectEditor::onRemove() if ( lpeitem ) { lpeitem->removeCurrentPathEffect(false); - DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Remove path effect") ); effect_list_reload(lpeitem); @@ -524,7 +528,7 @@ void LivePathEffectEditor::onUp() if ( lpeitem ) { lpeitem->upCurrentPathEffect(); - DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Move path effect up") ); effect_list_reload(lpeitem); @@ -541,7 +545,7 @@ void LivePathEffectEditor::onDown() if ( lpeitem ) { lpeitem->downCurrentPathEffect(); - DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Move path effect down") ); effect_list_reload(lpeitem); @@ -580,7 +584,7 @@ void LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str ) /* FIXME: this explicit writing to SVG is wrong. The lpe_item should have a method to disable/enable an effect within its stack. * So one can call: lpe_item->setActive(lpeobjref->lpeobject); */ lpeobjref->lpeobject->get_lpe()->getRepr()->setAttribute("is_visible", newValue ? "true" : "false"); - DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, newValue ? _("Activate path effect") : _("Deactivate path effect")); } } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 55a19fc51..1ca84e6b3 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -23,7 +23,7 @@ #include "document-undo.h" #include "layer-manager.h" #include "message-stack.h" -#include "desktop-handles.h" + #include "sp-object.h" #include "sp-item.h" #include "verbs.h" diff --git a/src/ui/dialog/lpe-powerstroke-properties.cpp b/src/ui/dialog/lpe-powerstroke-properties.cpp index 55f938a48..a9e57970d 100644 --- a/src/ui/dialog/lpe-powerstroke-properties.cpp +++ b/src/ui/dialog/lpe-powerstroke-properties.cpp @@ -32,7 +32,7 @@ #include "document-undo.h" #include "layer-manager.h" #include "message-stack.h" -#include "desktop-handles.h" + #include "sp-object.h" #include "sp-item.h" #include "verbs.h" diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp index cfa5c6182..f43a15225 100644 --- a/src/ui/dialog/object-attributes.cpp +++ b/src/ui/dialog/object-attributes.cpp @@ -22,7 +22,7 @@ #include "ui/dialog/dialog-manager.h" #include "desktop.h" -#include "desktop-handles.h" + #include "macros.h" #include "sp-anchor.h" #include "sp-image.h" @@ -113,7 +113,7 @@ void ObjectAttributes::widget_setup (void) return; } - Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); SPItem *item = selection->singleItem(); if (!item) { diff --git a/src/ui/dialog/object-properties.cpp b/src/ui/dialog/object-properties.cpp index 28e9b360b..dfe211e94 100644 --- a/src/ui/dialog/object-properties.cpp +++ b/src/ui/dialog/object-properties.cpp @@ -28,7 +28,7 @@ #include "object-properties.h" #include "widgets/sp-attribute-widget.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "verbs.h" @@ -353,7 +353,7 @@ void ObjectProperties::update() return; } - Inkscape::Selection *selection = sp_desktop_selection(SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); Gtk::Box *contents = _getContents(); if (!selection->singleItem()) { @@ -458,7 +458,7 @@ void ObjectProperties::_labelChanged() return; } - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); g_return_if_fail (item != NULL); _blocked = true; @@ -518,7 +518,7 @@ void ObjectProperties::_imageRenderingChanged() return; } - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); g_return_if_fail (item != NULL); _blocked = true; @@ -543,7 +543,7 @@ void ObjectProperties::_sensitivityToggled() return; } - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); g_return_if_fail(item != NULL); _blocked = true; @@ -559,7 +559,7 @@ void ObjectProperties::_hiddenToggled() return; } - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); g_return_if_fail(item != NULL); _blocked = true; diff --git a/src/ui/dialog/panel-dialog.h b/src/ui/dialog/panel-dialog.h index b4a355083..39110f47a 100644 --- a/src/ui/dialog/panel-dialog.h +++ b/src/ui/dialog/panel-dialog.h @@ -49,19 +49,10 @@ public: virtual UI::Widget::Panel &getPanel() { return _panel; } protected: - static void handle_deactivate_desktop(InkscapeApplication *application, SPDesktop *desktop, void *data) { - g_return_if_fail(data != NULL); - static_cast<PanelDialogBase *>(data)->_propagateDesktopDeactivated(application, desktop); - } - - static void _handle_activate_desktop(InkscapeApplication *application, SPDesktop *desktop, void *data) { - g_return_if_fail(data != NULL); - static_cast<PanelDialogBase *>(data)->_propagateDesktopActivated(application, desktop); - } inline virtual void _propagateDocumentReplaced(SPDesktop* desktop, SPDocument *document); - inline virtual void _propagateDesktopActivated(InkscapeApplication *, SPDesktop *); - inline virtual void _propagateDesktopDeactivated(InkscapeApplication *, SPDesktop *); + inline virtual void _propagateDesktopActivated(SPDesktop *); + inline virtual void _propagateDesktopDeactivated(SPDesktop *); UI::Widget::Panel &_panel; sigc::connection _document_replaced_connection; @@ -134,17 +125,17 @@ void PanelDialogBase::_propagateDocumentReplaced(SPDesktop *desktop, SPDocument _panel.signalDocumentReplaced().emit(desktop, document); } -void PanelDialogBase::_propagateDesktopActivated(InkscapeApplication *application, SPDesktop *desktop) +void PanelDialogBase::_propagateDesktopActivated(SPDesktop *desktop) { _document_replaced_connection = desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialogBase::_propagateDocumentReplaced)); - _panel.signalActivateDesktop().emit(application, desktop); + _panel.signalActivateDesktop().emit(desktop); } -void PanelDialogBase::_propagateDesktopDeactivated(InkscapeApplication *application, SPDesktop *desktop) +void PanelDialogBase::_propagateDesktopDeactivated(SPDesktop *desktop) { _document_replaced_connection.disconnect(); - _panel.signalDeactiveDesktop().emit(application, desktop); + _panel.signalDeactiveDesktop().emit(desktop); } @@ -162,7 +153,7 @@ PanelDialog<B>::PanelDialog(Widget::Panel &panel, char const *prefs_path, int co SPDesktop *desktop = SP_ACTIVE_DESKTOP; - _propagateDesktopActivated(INKSCAPE, desktop); + _propagateDesktopActivated(desktop); _document_replaced_connection = desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialog::_propagateDocumentReplaced)); @@ -211,7 +202,7 @@ PanelDialog<Behavior::FloatingBehavior>::PanelDialog(UI::Widget::Panel &panel, c SPDesktop *desktop = SP_ACTIVE_DESKTOP; - _propagateDesktopActivated(INKSCAPE, desktop); + _propagateDesktopActivated(desktop); _document_replaced_connection = desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialog::_propagateDocumentReplaced)); @@ -247,8 +238,12 @@ PanelDialog<Behavior::FloatingBehavior> *PanelDialog<Behavior::FloatingBehavior> new PanelDialog<Behavior::FloatingBehavior>(panel, panel.getPrefsPath(), panel.getVerb(), panel.getApplyLabel()); - g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(_handle_activate_desktop), instance); - g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK(handle_deactivate_desktop), instance); + INKSCAPE.signal_activate_desktop.connect( + sigc::mem_fun(*instance, &PanelDialog<Behavior::FloatingBehavior>::_propagateDesktopActivated) + ); + INKSCAPE.signal_deactivate_desktop.connect( + sigc::mem_fun(*instance, &PanelDialog<Behavior::FloatingBehavior>::_propagateDesktopDeactivated) + ); return instance; } diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 80579c9d3..cc5decfd7 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -16,7 +16,7 @@ #include "verbs.h" #include "preferences.h" #include "inkscape.h" -#include "desktop-handles.h" + #include "selection.h" #include "document.h" #include "document-undo.h" @@ -296,7 +296,7 @@ static void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { - Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); + Inkscape::Selection *selection = parent->getDesktop()->getSelection(); const GSList *items, *tmp; tmp = items = selection->itemList(); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection @@ -399,7 +399,7 @@ void PolarArrangeTab::arrange() tmp = tmp->next; } - DocumentUndo::done(sp_desktop_document(parent->getDesktop()), SP_VERB_SELECTION_ARRANGE, + DocumentUndo::done(parent->getDesktop()->getDocument(), SP_VERB_SELECTION_ARRANGE, _("Arrange on ellipse")); } diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 9faa8a2cb..6da8acb20 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -22,7 +22,7 @@ #include "document.h" #include "selection.h" #include "desktop.h" -#include "desktop-handles.h" + #include "ui/tools-switch.h" #include "ui/tools/text-tool.h" #include "ui/interface.h" @@ -407,7 +407,7 @@ SpellCheck::init(SPDesktop *d) } #endif /* HAVE_ASPELL */ - _root = sp_desktop_document(desktop)->getRoot(); + _root = desktop->getDocument()->getRoot(); // empty the list of objects we've checked g_slist_free (_seen_objects); @@ -612,7 +612,7 @@ SpellCheck::nextWord() area.expandBy(MAX(0.05 * mindim, 1)); // create canvas path rectangle, red stroke - SPCanvasItem *rect = sp_canvas_bpath_new(sp_desktop_sketch(desktop), NULL); + SPCanvasItem *rect = sp_canvas_bpath_new(desktop->getSketch(), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(rect), 0, SP_WIND_RULE_NONZERO); SPCurve *curve = new SPCurve(); @@ -792,7 +792,7 @@ void SpellCheck::onAccept () // find the end of the word anew _end_w = _begin_w; _end_w.nextEndOfWord(); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Fix spelling")); } } diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 56ecfdecc..bc228633d 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -29,7 +29,8 @@ #include "xml/node.h" #include "xml/repr.h" #include "sp-font-face.h" -#include "desktop-handles.h" +#include "desktop.h" + #include "display/nr-svgfonts.h" #include "verbs.h" #include "sp-glyph.h" @@ -181,7 +182,7 @@ void SvgFontsDialog::on_kerning_value_changed(){ return; } - SPDocument* document = sp_desktop_document(this->getDesktop()); + SPDocument* document = this->getDesktop()->getDocument(); //TODO: I am unsure whether this is the correct way of calling SPDocumentUndo::maybe_done Glib::ustring undokey = "svgfonts:hkern:k:"; @@ -264,7 +265,7 @@ void SvgFontsDialog::update_sensitiveness(){ void SvgFontsDialog::update_fonts() { SPDesktop* desktop = this->getDesktop(); - SPDocument* document = sp_desktop_document(desktop); + SPDocument* document = desktop->getDocument(); const GSList* fonts = document->getResourceList("font"); _model->clear(); @@ -481,7 +482,7 @@ void SvgFontsDialog::update_glyphs(){ void SvgFontsDialog::add_glyph(){ const int count = _GlyphsListStore->children().size(); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); /* SPGlyph* glyph =*/ new_glyph(doc, get_selected_spfont(), count+1); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Add glyph")); @@ -514,9 +515,9 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); - SPDocument* doc = sp_desktop_document(desktop); - Inkscape::Selection* sel = sp_desktop_selection(desktop); + Inkscape::MessageStack *msgStack = desktop->getMessageStack(); + SPDocument* doc = desktop->getDocument(); + Inkscape::Selection* sel = desktop->getSelection(); if (sel->isEmpty()){ char *msg = _("Select a <b>path</b> to define the curves of a glyph"); msgStack->flash(Inkscape::ERROR_MESSAGE, msg); @@ -556,9 +557,9 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::MessageStack *msgStack = sp_desktop_message_stack(desktop); - SPDocument* doc = sp_desktop_document(desktop); - Inkscape::Selection* sel = sp_desktop_selection(desktop); + Inkscape::MessageStack *msgStack = desktop->getMessageStack(); + SPDocument* doc = desktop->getDocument(); + Inkscape::Selection* sel = desktop->getSelection(); if (sel->isEmpty()){ char *msg = _("Select a <b>path</b> to define the curves of a glyph"); msgStack->flash(Inkscape::ERROR_MESSAGE, msg); @@ -597,7 +598,7 @@ void SvgFontsDialog::reset_missing_glyph_description(){ return; } - SPDocument* doc = sp_desktop_document(desktop); + SPDocument* doc = desktop->getDocument(); SPObject* obj; for (obj = get_selected_spfont()->children; obj; obj=obj->next){ if (SP_IS_MISSING_GLYPH(obj)){ @@ -618,7 +619,7 @@ void SvgFontsDialog::glyph_name_edit(const Glib::ustring&, const Glib::ustring& //XML Tree being directly used here while it shouldn't be. glyph->getRepr()->setAttribute("glyph-name", str.c_str()); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Edit glyph name")); update_glyphs(); @@ -632,7 +633,7 @@ void SvgFontsDialog::glyph_unicode_edit(const Glib::ustring&, const Glib::ustrin //XML Tree being directly used here while it shouldn't be. glyph->getRepr()->setAttribute("unicode", str.c_str()); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Set glyph unicode")); update_glyphs(); @@ -644,7 +645,7 @@ void SvgFontsDialog::remove_selected_font(){ //XML Tree being directly used here while it shouldn't be. sp_repr_unparent(font->getRepr()); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Remove font")); update_fonts(); @@ -661,7 +662,7 @@ void SvgFontsDialog::remove_selected_glyph(){ //XML Tree being directly used here while it shouldn't be. sp_repr_unparent(glyph->getRepr()); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Remove glyph")); update_glyphs(); @@ -678,7 +679,7 @@ void SvgFontsDialog::remove_selected_kerning_pair(){ //XML Tree being directly used here while it shouldn't be. sp_repr_unparent(pair->getRepr()); - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Remove kerning pair")); update_glyphs(); @@ -749,7 +750,7 @@ void SvgFontsDialog::add_kerning_pair(){ if (this->kerning_pair) return; //We already have this kerning pair - SPDocument* document = sp_desktop_document(this->getDesktop()); + SPDocument* document = this->getDesktop()->getDocument(); Inkscape::XML::Document *xml_doc = document->getReprDoc(); // create a new hkern node @@ -863,7 +864,7 @@ void set_font_family(SPFont* font, char* str){ } void SvgFontsDialog::add_font(){ - SPDocument* doc = sp_desktop_document(this->getDesktop()); + SPDocument* doc = this->getDesktop()->getDocument(); SPFont* font = new_font(doc); const int count = _model->children().size(); @@ -937,7 +938,7 @@ SvgFontsDialog::SvgFontsDialog() _FontsList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &SvgFontsDialog::fonts_list_button_release)); create_fonts_popup_menu(_FontsList, sigc::mem_fun(*this, &SvgFontsDialog::remove_selected_font)); - _defs_observer.set(sp_desktop_document(this->getDesktop())->getDefs()); + _defs_observer.set(this->getDesktop()->getDocument()->getDefs()); _defs_observer.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::update_fonts)); _getContents()->show_all(); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index a3cfeeba8..8759039c3 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -28,7 +28,7 @@ #include "color-item.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "document.h" #include "document-private.h" @@ -122,15 +122,15 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) if ( gr ) { bool shown = false; if ( desktop && desktop->doc() ) { - Inkscape::Selection *selection = sp_desktop_selection( desktop ); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); if (items) { - SPStyle *query = sp_style_new( desktop->doc() ); - int result = objects_query_fillstroke(const_cast<GSList *>(items), query, true); + SPStyle query( desktop->doc() ); + int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, true); if ( (result == QUERY_STYLE_MULTIPLE_SAME) || (result == QUERY_STYLE_SINGLE) ) { // could be pertinent - if (query->fill.isPaintserver()) { - SPPaintServer* server = query->getFillPaintServer(); + if (query.fill.isPaintserver()) { + SPPaintServer* server = query.getFillPaintServer(); if ( SP_IS_GRADIENT(server) ) { SPGradient* grad = SP_GRADIENT(server); if ( grad->isSwatch() && grad->getId() == gr->getId()) { @@ -140,7 +140,6 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) } } } - sp_style_unref(query); } } @@ -527,7 +526,7 @@ static void loadEmUp() beenHere = true; std::list<gchar *> sources; - sources.push_back( profile_path("palettes") ); + sources.push_back( Inkscape::Application::profile_path("palettes") ); sources.push_back( g_strdup(INKSCAPE_PALETTESDIR) ); sources.push_back( g_strdup(CREATE_PALETTESDIR) ); @@ -1061,15 +1060,15 @@ void SwatchesPanel::_updateFromSelection() Glib::ustring fillId; Glib::ustring strokeId; - SPStyle *tmpStyle = sp_style_new( sp_desktop_document(_currentDesktop) ); - int result = sp_desktop_query_style( _currentDesktop, tmpStyle, QUERY_STYLE_PROPERTY_FILL ); + SPStyle tmpStyle(_currentDesktop->getDocument()); + int result = sp_desktop_query_style( _currentDesktop, &tmpStyle, QUERY_STYLE_PROPERTY_FILL ); switch (result) { case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_AVERAGED: case QUERY_STYLE_MULTIPLE_SAME: { - if (tmpStyle->fill.set && tmpStyle->fill.isPaintserver()) { - SPPaintServer* server = tmpStyle->getFillPaintServer(); + if (tmpStyle.fill.set && tmpStyle.fill.isPaintserver()) { + SPPaintServer* server = tmpStyle.getFillPaintServer(); if ( SP_IS_GRADIENT(server) ) { SPGradient* target = 0; SPGradient* grad = SP_GRADIENT(server); @@ -1095,14 +1094,14 @@ void SwatchesPanel::_updateFromSelection() } } - result = sp_desktop_query_style( _currentDesktop, tmpStyle, QUERY_STYLE_PROPERTY_STROKE ); + result = sp_desktop_query_style( _currentDesktop, &tmpStyle, QUERY_STYLE_PROPERTY_STROKE ); switch (result) { case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_AVERAGED: case QUERY_STYLE_MULTIPLE_SAME: { - if (tmpStyle->stroke.set && tmpStyle->stroke.isPaintserver()) { - SPPaintServer* server = tmpStyle->getStrokePaintServer(); + if (tmpStyle.stroke.set && tmpStyle.stroke.isPaintserver()) { + SPPaintServer* server = tmpStyle.getStrokePaintServer(); if ( SP_IS_GRADIENT(server) ) { SPGradient* target = 0; SPGradient* grad = SP_GRADIENT(server); @@ -1126,7 +1125,6 @@ void SwatchesPanel::_updateFromSelection() break; } } - sp_style_unref(tmpStyle); for ( boost::ptr_vector<ColorItem>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) { ColorItem* item = &*it; diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index a17a03861..bdba3e154 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -52,7 +52,7 @@ #include "selection.h" #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "inkscape.h" #include "sp-root.h" @@ -287,8 +287,8 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; /**********************************************************/ - currentDesktop = inkscape_active_desktop(); - currentDocument = sp_desktop_document(currentDesktop); + currentDesktop = SP_ACTIVE_DESKTOP; + currentDocument = currentDesktop->getDocument(); previewDocument = symbols_preview_doc(); /* Template to render symbols in */ previewDocument->ensureUpToDate(); /* Necessary? */ @@ -585,13 +585,15 @@ void SymbolsDialog::get_symbols() { std::list<Glib::ustring> directories; +// \TODO optimize this + if( Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) { directories.push_back( INKSCAPE_SYMBOLSDIR ); } - if( Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_EXISTS ) && - Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) { - directories.push_back( profile_path("symbols") ); + if( Inkscape::IO::file_test( Inkscape::Application::profile_path("symbols"), G_FILE_TEST_EXISTS ) && + Inkscape::IO::file_test( Inkscape::Application::profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) { + directories.push_back( Inkscape::Application::profile_path("symbols") ); } std::list<Glib::ustring>::iterator it; diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 13cb01eef..fca1f7b30 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -194,7 +194,7 @@ void TemplateLoadTab::_refreshTemplatesList() void TemplateLoadTab::_loadTemplates() { // user's local dir - _getTemplatesFromDir(profile_path("templates") + _loading_path); + _getTemplatesFromDir(Inkscape::Application::profile_path("templates") + _loading_path); // system templates dir _getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path); diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp index f79d166f2..eff75b311 100644 --- a/src/ui/dialog/template-widget.cpp +++ b/src/ui/dialog/template-widget.cpp @@ -20,7 +20,7 @@ #include "template-load-tab.h" #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "file.h" @@ -68,8 +68,8 @@ void TemplateWidget::create() SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDesktop *desc = sp_file_new_default(); _current_template.tpl_effect->effect(desc); - DocumentUndo::clearUndo(sp_desktop_document(desc)); - sp_desktop_document(desc)->setModifiedSinceSave(false); + DocumentUndo::clearUndo(desc->getDocument()); + desc->getDocument()->setModifiedSinceSave(false); // Apply cx,cy etc. from document sp_namedview_window_from_document( desc ); diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 0f4a6f7f1..a8be8b543 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -41,7 +41,7 @@ extern "C" { #include "document.h" #include "desktop.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "document-undo.h" #include "selection.h" #include "style.h" @@ -325,18 +325,18 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) if (dostyle) { // create temporary style - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); - int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); // If querying returned nothing, read the style from the text tool prefs (default style for new texts) // (Ok to not get a font specification - must just rely on the family and style in that case) if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) { - sp_style_read_from_prefs(query, "/tools/text"); + query.readFromPrefs("/tools/text"); } // FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists @@ -344,47 +344,46 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ ) Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); // This is normally done for us by text-toolbar but only when we are in text editing context - fontlister->update_font_list(sp_desktop_document(this->desktop)); + fontlister->update_font_list(this->desktop->getDocument()); fontlister->selection_update(); Glib::ustring fontspec = fontlister->get_fontspec(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); - double size = sp_style_css_size_px_to_units(query->font_size.computed, unit); + double size = sp_style_css_size_px_to_units(query.font_size.computed, unit); sp_font_selector_set_fontspec(fsel, fontspec, size ); setPreviewText (fontspec, phrase); - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) { - if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) { + if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) { + if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) { align_justify.set_active(); } else { align_left.set_active(); } - } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { + } else if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { align_center.set_active(); } else { align_right.set_active(); } - if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { + if (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { text_horizontal.set_active(); } else { text_vertical.set_active(); } double height; - if (query->line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; - else if (query->line_height.unit == SP_CSS_UNIT_PERCENT) - height = query->line_height.value; - else height = query->line_height.computed; + if (query.line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; + else if (query.line_height.unit == SP_CSS_UNIT_PERCENT) + height = query.line_height.value; + else height = query.line_height.computed; gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5)); gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) spacing_combo), sstr); g_free(sstr); - sp_style_unref(query); } blocked = false; } @@ -419,7 +418,7 @@ SPItem *TextEdit::getSelectedTextItem (void) if (!SP_ACTIVE_DESKTOP) return NULL; - for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); item != NULL; item = item->next) { @@ -438,7 +437,7 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; - for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); item != NULL; item = item->next) { @@ -543,7 +542,7 @@ void TextEdit::onApply() SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const GSList *item_list = sp_desktop_selection(desktop)->itemList(); + const GSList *item_list = desktop->getSelection()->itemList(); SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); @@ -569,7 +568,7 @@ void TextEdit::onApply() } else if (items == 1) { // exactly one text object; now set its text, too - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) { updateObjectText (item); } @@ -583,7 +582,7 @@ void TextEdit::onApply() } // complete the transaction - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_TEXT, _("Set text style")); apply_button.set_sensitive ( false ); @@ -658,7 +657,7 @@ void TextEdit::onStartOffsetChange(GtkTextBuffer * /*text_buffer*/, TextEdit *se const gchar *sstr = gtk_combo_box_text_get_active_text(reinterpret_cast<GtkComboBoxText *>(self->startOffset)); tp->setAttribute("startOffset", sstr); - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "startOffset", SP_VERB_CONTEXT_TEXT, _("Set text style")); + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "startOffset", SP_VERB_CONTEXT_TEXT, _("Set text style")); } } diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 3e135b9b2..233d99750 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -25,7 +25,8 @@ #include "document.h" #include "document-undo.h" -#include "desktop-handles.h" +#include "desktop.h" + #include "transformation.h" #include "align-and-distribute.h" #include "inkscape.h" @@ -47,16 +48,13 @@ namespace Inkscape { namespace UI { namespace Dialog { -static void on_selection_changed(InkscapeApplication */*inkscape*/, Inkscape::Selection *selection, Transformation *daad) +static void on_selection_changed(Inkscape::Selection *selection, Transformation *daad) { int page = daad->getCurrentPage(); daad->updateSelection((Inkscape::UI::Dialog::Transformation::PageType)page, selection); } -static void on_selection_modified( InkscapeApplication */*inkscape*/, - Inkscape::Selection *selection, - guint /*flags*/, - Transformation *daad ) +static void on_selection_modified(Inkscape::Selection *selection, Transformation *daad) { int page = daad->getCurrentPage(); daad->updateSelection((Inkscape::UI::Dialog::Transformation::PageType)page, selection); @@ -159,8 +157,8 @@ Transformation::Transformation() } // Connect to the global selection changed & modified signals - g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this); - g_signal_connect (G_OBJECT (INKSCAPE), "modify_selection", G_CALLBACK (on_selection_modified), this); + _selChangeConn = INKSCAPE.signal_selection_changed.connect(sigc::bind(sigc::ptr_fun(&on_selection_changed), this)); + _selModifyConn = INKSCAPE.signal_selection_modified.connect(sigc::hide<1>(sigc::bind(sigc::ptr_fun(&on_selection_modified), this))); _desktopChangeConn = _deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &Transformation::setDesktop) ); _deskTrack.connect(GTK_WIDGET(gobj())); @@ -170,7 +168,8 @@ Transformation::Transformation() Transformation::~Transformation() { - sp_signal_disconnect_by_data (G_OBJECT (INKSCAPE), this); + _selModifyConn.disconnect(); + _selChangeConn.disconnect(); _desktopChangeConn.disconnect(); _deskTrack.disconnect(); } @@ -207,9 +206,9 @@ void Transformation::layoutPageMove() // Setting default unit to document unit SPDesktop *dt = getDesktop(); - SPNamedView *nv = sp_desktop_namedview(dt); - if (nv->doc_units) { - _units_move.setUnit(nv->doc_units->abbr); + SPNamedView *nv = dt->getNamedView(); + if (nv->display_units) { + _units_move.setUnit(nv->display_units->abbr); } _scalar_move_horizontal.initScalar(-1e6, 1e6); @@ -580,7 +579,7 @@ void Transformation::onSwitchPage(Gtk::Widget * /*page*/, guint pagenum) void Transformation::onSwitchPage(GtkNotebookPage * /*page*/, guint pagenum) #endif { - updateSelection((PageType)pagenum, sp_desktop_selection(getDesktop())); + updateSelection((PageType)pagenum, getDesktop()->getSelection()); } @@ -803,7 +802,7 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) } } - DocumentUndo::done( sp_desktop_document(selection->desktop()) , SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done( selection->desktop()->getDocument() , SP_VERB_DIALOG_TRANSFORM, _("Move")); } @@ -865,7 +864,7 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) } } - DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done(selection->desktop()->getDocument(), SP_VERB_DIALOG_TRANSFORM, _("Scale")); } @@ -890,7 +889,7 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) } } - DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done(selection->desktop()->getDocument(), SP_VERB_DIALOG_TRANSFORM, _("Rotate")); } @@ -905,7 +904,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) double skewX = _scalar_skew_horizontal.getValue("%"); double skewY = _scalar_skew_vertical.getValue("%"); if (fabs(0.01*skewX*0.01*skewY - 1.0) < Geom::EPSILON) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } sp_item_skew_rel (item, 0.01*skewX, 0.01*skewY); @@ -916,7 +915,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) || (fabs(angleX - angleY - M_PI/2) < Geom::EPSILON) || (fabs((angleX - angleY)/3 + M_PI/2) < Geom::EPSILON) || (fabs((angleX - angleY)/3 - M_PI/2) < Geom::EPSILON)) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } double skewX = tan(-angleX); @@ -930,7 +929,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) double width = bbox->dimensions()[Geom::X]; double height = bbox->dimensions()[Geom::Y]; if (fabs(skewX*skewY - width*height) < Geom::EPSILON) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } sp_item_skew_rel (item, skewX/height, skewY/width); @@ -949,7 +948,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) double skewX = _scalar_skew_horizontal.getValue("%"); double skewY = _scalar_skew_vertical.getValue("%"); if (fabs(0.01*skewX*0.01*skewY - 1.0) < Geom::EPSILON) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } sp_selection_skew_relative(selection, *center, 0.01*skewX, 0.01*skewY); @@ -960,7 +959,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) || (fabs(angleX - angleY - M_PI/2) < Geom::EPSILON) || (fabs((angleX - angleY)/3 + M_PI/2) < Geom::EPSILON) || (fabs((angleX - angleY)/3 - M_PI/2) < Geom::EPSILON)) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } double skewX = tan(-angleX); @@ -970,7 +969,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) double skewX = _scalar_skew_horizontal.getValue("px"); double skewY = _scalar_skew_vertical.getValue("px"); if (fabs(skewX*skewY - width*height) < Geom::EPSILON) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } sp_selection_skew_relative(selection, *center, skewX/height, skewY/width); @@ -978,7 +977,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) } } - DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done(selection->desktop()->getDocument(), SP_VERB_DIALOG_TRANSFORM, _("Skew")); } @@ -994,7 +993,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) Geom::Affine displayed(a, b, c, d, e, f); if (displayed.isSingular()) { - sp_desktop_message_stack(getDesktop())->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); + getDesktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Transform matrix is singular, <b>not used</b>.")); return; } @@ -1008,7 +1007,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform } - DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done(selection->desktop()->getDocument(), SP_VERB_DIALOG_TRANSFORM, _("Edit transformation matrix")); } diff --git a/src/ui/dialog/transformation.h b/src/ui/dialog/transformation.h index 1d24a0c94..89aa95d90 100644 --- a/src/ui/dialog/transformation.h +++ b/src/ui/dialog/transformation.h @@ -232,6 +232,9 @@ private: Gtk::Button *applyButton; Gtk::Button *resetButton; Gtk::Button *cancelButton; + + sigc::connection _selChangeConn; + sigc::connection _selModifyConn; }; diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index 53691cd37..a50a169eb 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -24,7 +24,7 @@ #include "document-undo.h" #include "inkscape.h" #include "verbs.h" -#include "desktop-handles.h" + #include "util/signal-blocker.h" #include "desktop.h" diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index 7ab6c78ba..c02520218 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -23,7 +23,7 @@ #include <gtkmm/stock.h> #include "desktop.h" -#include "desktop-handles.h" + #include "ui/dialog-events.h" #include "document.h" #include "document-undo.h" @@ -360,10 +360,10 @@ void XmlTree::set_tree_desktop(SPDesktop *desktop) } current_desktop = desktop; if (desktop) { - sel_changed_connection = sp_desktop_selection(desktop)->connectChanged(sigc::hide(sigc::mem_fun(this, &XmlTree::on_desktop_selection_changed))); + sel_changed_connection = desktop->getSelection()->connectChanged(sigc::hide(sigc::mem_fun(this, &XmlTree::on_desktop_selection_changed))); document_replaced_connection = desktop->connectDocumentReplaced(sigc::mem_fun(this, &XmlTree::on_document_replaced)); - set_tree_document(sp_desktop_document(desktop)); + set_tree_document(desktop->getDocument()); } else { set_tree_document(NULL); } @@ -472,7 +472,7 @@ Inkscape::XML::Node *XmlTree::get_dt_select() if (!current_desktop) { return NULL; } - return sp_desktop_selection(current_desktop)->singleRepr(); + return current_desktop->getSelection()->singleRepr(); } @@ -483,7 +483,7 @@ void XmlTree::set_dt_select(Inkscape::XML::Node *repr) return; } - Inkscape::Selection *selection = sp_desktop_selection(current_desktop); + Inkscape::Selection *selection = current_desktop->getSelection(); SPObject *object; if (repr) { @@ -493,7 +493,7 @@ void XmlTree::set_dt_select(Inkscape::XML::Node *repr) repr = repr->parent(); } // end of while loop - object = sp_desktop_document(current_desktop)->getObjectByRepr(repr); + object = current_desktop->getDocument()->getObjectByRepr(repr); } else { object = NULL; } @@ -827,7 +827,7 @@ void XmlTree::on_document_replaced(SPDesktop *dt, SPDocument *doc) if (current_desktop) sel_changed_connection.disconnect(); - sel_changed_connection = sp_desktop_selection(dt)->connectChanged(sigc::hide(sigc::mem_fun(this, &XmlTree::on_desktop_selection_changed))); + sel_changed_connection = dt->getSelection()->connectChanged(sigc::hide(sigc::mem_fun(this, &XmlTree::on_desktop_selection_changed))); set_tree_document(doc); } diff --git a/src/ui/draw-anchor.cpp b/src/ui/draw-anchor.cpp index 84c919018..6b9a88ed7 100644 --- a/src/ui/draw-anchor.cpp +++ b/src/ui/draw-anchor.cpp @@ -15,7 +15,6 @@ #include "ui/draw-anchor.h" #include "desktop.h" -#include "desktop-handles.h" #include "ui/tools/tool-base.h" #include "ui/tools/lpe-tool.h" #include "display/sodipodi-ctrl.h" @@ -45,7 +44,7 @@ SPDrawAnchor *sp_draw_anchor_new(Inkscape::UI::Tools::FreehandBase *dc, SPCurve a->start = start; a->active = FALSE; a->dp = delta; - a->ctrl = ControlManager::getManager().createControl(sp_desktop_controls(&dc->getDesktop()), Inkscape::CTRL_TYPE_ANCHOR); + a->ctrl = ControlManager::getManager().createControl(dc->getDesktop().getControls(), Inkscape::CTRL_TYPE_ANCHOR); SP_CTRL(a->ctrl)->moveto(delta); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 7830a8de1..28a65e0b4 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -29,7 +29,7 @@ #include <gtkmm/imagemenuitem.h> #include <gtkmm/separatormenuitem.h> -#include "inkscape-private.h" +#include "inkscape.h" #include "extension/db.h" #include "extension/effect.h" #include "extension/input.h" @@ -38,7 +38,7 @@ #include "path-prefix.h" #include "shortcuts.h" #include "document.h" -#include "desktop-handles.h" + #include "ui/interface.h" #include "desktop.h" #include "selection.h" @@ -270,7 +270,7 @@ sp_create_window(SPViewWidget *vw, bool editable) // needed because the first ACTIVATE_DESKTOP was sent when there was no window yet if ( SP_IS_DESKTOP_WIDGET(vw) ) { - inkscape_reactivate_desktop(SP_DESKTOP_WIDGET(vw)->desktop); + INKSCAPE.reactivate_desktop(SP_DESKTOP_WIDGET(vw)->desktop); } } @@ -318,13 +318,13 @@ sp_ui_close_view(GtkWidget */*widget*/) // If closing the last document, open a new document so Inkscape doesn't quit. std::list<SPDesktop *> desktops; - inkscape_get_all_desktops(desktops); + INKSCAPE.get_all_desktops(desktops); if (desktops.size() == 1) { Glib::ustring templateUri = sp_file_default_template_uri(); SPDocument *doc = SPDocument::createNewDoc( templateUri.c_str() , TRUE, true ); // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } dt->change_document(doc); sp_namedview_window_from_document(dt); @@ -921,7 +921,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I GtkWidget *sp_ui_main_menubar(Inkscape::UI::View::View *view) { GtkWidget *mbar = gtk_menu_bar_new(); - sp_ui_build_dyn_menus(inkscape_get_menus(INKSCAPE), mbar, view); + sp_ui_build_dyn_menus(INKSCAPE.get_menus(), mbar, view); return mbar; } @@ -1232,12 +1232,12 @@ sp_ui_drag_data_received(GtkWidget *widget, SPObject *new_obj = NULL; new_obj = desktop->currentLayer()->appendChildRepr(newgroup); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection->set(SP_ITEM(new_obj)); // move to mouse pointer { - sp_desktop_document(desktop)->ensureUpToDate(); + desktop->getDocument()->ensureUpToDate(); Geom::OptRect sel_bbox = selection->visualBounds(); if (sel_bbox) { Geom::Point m( desktop->point() - sel_bbox->midpoint() ); @@ -2117,13 +2117,13 @@ void ContextMenu::ImageEdit(void) void ContextMenu::ImageTraceBitmap(void) { - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); _desktop->_dlg_mgr->showDialog("Trace"); } void ContextMenu::ImageTracePixelArt(void) { - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); _desktop->_dlg_mgr->showDialog("PixelArt"); } diff --git a/src/ui/object-edit.cpp b/src/ui/object-edit.cpp index ca550502d..fb99dfd59 100644 --- a/src/ui/object-edit.cpp +++ b/src/ui/object-edit.cpp @@ -28,7 +28,7 @@ #include "preferences.h" #include "style.h" #include "desktop.h" -#include "desktop-handles.h" + #include "sp-namedview.h" #include "live_effects/effect.h" #include "sp-pattern.h" diff --git a/src/ui/shape-editor.cpp b/src/ui/shape-editor.cpp index 0b9fc24c5..aec5cde27 100644 --- a/src/ui/shape-editor.cpp +++ b/src/ui/shape-editor.cpp @@ -14,7 +14,7 @@ #include <string.h> #include <glibmm/i18n.h> -#include "desktop-handles.h" +#include "desktop.h" #include "document.h" #include "gc-anchored.h" #include "knotholder.h" @@ -146,7 +146,7 @@ void ShapeEditor::set_item(SPItem *item, bool keep_knotholder) { void ShapeEditor::reset_item(bool keep_knotholder) { if (knotholder) { - SPObject *obj = sp_desktop_document(desktop)->getObjectByRepr(knotholder_listener_attached_for); /// note that it is not certain that this is an SPItem; it could be a LivePathEffectObject. + SPObject *obj = desktop->getDocument()->getObjectByRepr(knotholder_listener_attached_for); /// note that it is not certain that this is an SPItem; it could be a LivePathEffectObject. set_item(SP_ITEM(obj), keep_knotholder); } } diff --git a/src/ui/tool/control-point.cpp b/src/ui/tool/control-point.cpp index e98c7b2a2..bcf5c9fce 100644 --- a/src/ui/tool/control-point.cpp +++ b/src/ui/tool/control-point.cpp @@ -11,7 +11,7 @@ #include <gdkmm.h> #include <2geom/point.h> #include "desktop.h" -#include "desktop-handles.h" + #include "display/sp-canvas.h" #include "display/snap-indicator.h" #include "ui/tools/tool-base.h" @@ -74,7 +74,7 @@ ControlPoint::ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAncho _lurking(false) { _canvas_item = sp_canvas_item_new( - group ? group : sp_desktop_controls(_desktop), SP_TYPE_CTRL, + group ? group : _desktop->getControls(), SP_TYPE_CTRL, "anchor", (SPAnchorType) anchor, "size", (gdouble) pixbuf->get_width(), "shape", SP_CTRL_SHAPE_BITMAP, "pixbuf", pixbuf->gobj(), "filled", TRUE, "fill_color", _cset.normal.fill, @@ -93,7 +93,7 @@ ControlPoint::ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAncho _position(initial_pos), _lurking(false) { - _canvas_item = ControlManager::getManager().createControl(group ? group : sp_desktop_controls(_desktop), type); + _canvas_item = ControlManager::getManager().createControl(group ? group : _desktop->getControls(), type); g_object_set(_canvas_item, "anchor", anchor, "filled", TRUE, "fill_color", _cset.normal.fill, diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index d7b35c974..f53cef5f4 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -14,7 +14,7 @@ #include "node.h" #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "live_effects/lpeobject.h" @@ -820,9 +820,9 @@ void MultiPathManipulator::_commit(CommitEvent cps) _selection.signal_update.emit(); invokeForAll(&PathManipulator::writeXML); if (key) { - DocumentUndo::maybeDone(sp_desktop_document(_desktop), key, SP_VERB_CONTEXT_NODE, reason); + DocumentUndo::maybeDone(_desktop->getDocument(), key, SP_VERB_CONTEXT_NODE, reason); } else { - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason); + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_NODE, reason); } signal_coords_changed.emit(); } @@ -831,7 +831,7 @@ void MultiPathManipulator::_commit(CommitEvent cps) void MultiPathManipulator::_done(gchar const *reason, bool alert_LPE) { invokeForAll(&PathManipulator::update, alert_LPE); invokeForAll(&PathManipulator::writeXML); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason); + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_NODE, reason); signal_coords_changed.emit(); } diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 8a1ca0b90..eeea47e4d 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -17,7 +17,7 @@ #include "display/sp-canvas.h" #include "display/sp-canvas-util.h" #include "desktop.h" -#include "desktop-handles.h" + #include "preferences.h" #include "snap.h" #include "snap-preferences.h" @@ -566,9 +566,9 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion */*event*/) const Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px"); - GString *x = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str()); - GString *y = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str()); - GString *len = g_string_new(len_q.string(_desktop->namedview->doc_units).c_str()); + GString *x = g_string_new(x_q.string(_desktop->namedview->display_units).c_str()); + GString *y = g_string_new(y_q.string(_desktop->namedview->display_units).c_str()); + GString *len = g_string_new(len_q.string(_desktop->namedview->display_units).c_str()); Glib::ustring ret = format_tip(C_("Path handle tip", "Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str); g_string_free(x, TRUE); @@ -1490,8 +1490,8 @@ Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); - GString *x = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str()); - GString *y = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str()); + GString *x = g_string_new(x_q.string(_desktop->namedview->display_units).c_str()); + GString *y = g_string_new(y_q.string(_desktop->namedview->display_units).c_str()); Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"), x->str, y->str); g_string_free(x, TRUE); g_string_free(y, TRUE); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 8b99c33b8..c8b986824 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -23,7 +23,7 @@ #include <glibmm/i18n.h> #include "ui/tool/path-manipulator.h" #include "desktop.h" -#include "desktop-handles.h" + #include "display/sp-canvas.h" #include "display/sp-canvas-util.h" #include "display/curve.h" @@ -972,6 +972,10 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d NodeList &list = NodeList::get(first); NodeList::iterator second = first.next(); if (!second) throw std::invalid_argument("Subdivide after last node in open path"); + if (first->type() == NODE_SYMMETRIC) + first->setType(NODE_SMOOTH, false); + if (second->type() == NODE_SYMMETRIC) + second->setType(NODE_SMOOTH, false); // We need to insert the segment after 'first'. We can't simply use 'second' // as the point of insertion, because when 'first' is the last node of closed path, @@ -1617,13 +1621,13 @@ void PathManipulator::_removeNodesFromSelection() void PathManipulator::_commit(Glib::ustring const &annotation) { writeXML(); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, annotation.data()); + DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_NODE, annotation.data()); } void PathManipulator::_commit(Glib::ustring const &annotation, gchar const *key) { writeXML(); - DocumentUndo::maybeDone(sp_desktop_document(_desktop), key, SP_VERB_CONTEXT_NODE, + DocumentUndo::maybeDone(_desktop->getDocument(), key, SP_VERB_CONTEXT_NODE, annotation.data()); } diff --git a/src/ui/tool/selector.cpp b/src/ui/tool/selector.cpp index bdeacadc9..e4e701785 100644 --- a/src/ui/tool/selector.cpp +++ b/src/ui/tool/selector.cpp @@ -11,7 +11,7 @@ #include "control-point.h" #include "desktop.h" -#include "desktop-handles.h" + #include "display/sodipodi-ctrlrect.h" #include "ui/tools/tool-base.h" #include "preferences.h" @@ -37,7 +37,7 @@ public: _cancel(false) { setVisible(false); - _rubber = static_cast<CtrlRect*>(sp_canvas_item_new(sp_desktop_controls(_desktop), + _rubber = static_cast<CtrlRect*>(sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRLRECT, NULL)); sp_canvas_item_hide(_rubber); } @@ -100,7 +100,7 @@ private: Selector::Selector(SPDesktop *d) : Manipulator(d) - , _dragger(new SelectorPoint(d, sp_desktop_controls(d), this)) + , _dragger(new SelectorPoint(d, d->getControls(), this)) { _dragger->setVisible(false); } diff --git a/src/ui/tool/transform-handle-set.cpp b/src/ui/tool/transform-handle-set.cpp index 7d5c9bf0c..da2a54989 100644 --- a/src/ui/tool/transform-handle-set.cpp +++ b/src/ui/tool/transform-handle-set.cpp @@ -15,7 +15,7 @@ #include <glib/gi18n.h> #include <2geom/transforms.h> #include "desktop.h" -#include "desktop-handles.h" + #include "display/sodipodi-ctrlrect.h" #include "preferences.h" #include "snap.h" @@ -686,7 +686,7 @@ TransformHandleSet::TransformHandleSet(SPDesktop *d, SPCanvasGroup *th_group) , _in_transform(false) , _visible(true) { - _trans_outline = static_cast<CtrlRect*>(sp_canvas_item_new(sp_desktop_controls(_desktop), + _trans_outline = static_cast<CtrlRect*>(sp_canvas_item_new(_desktop->getControls(), SP_TYPE_CTRLRECT, NULL)); sp_canvas_item_hide(_trans_outline); _trans_outline->setDashed(true); diff --git a/src/ui/tools-switch.cpp b/src/ui/tools-switch.cpp index 47b9d2832..11313f550 100644 --- a/src/ui/tools-switch.cpp +++ b/src/ui/tools-switch.cpp @@ -16,9 +16,9 @@ #include <cstring> #include <string> -#include "inkscape-private.h" +#include "inkscape.h" #include "desktop.h" -#include "desktop-handles.h" + #include <glibmm/i18n.h> #include <xml/repr.h> @@ -159,7 +159,7 @@ tools_switch(SPDesktop *dt, int num) /* fixme: This is really ugly hack. We should bind and unbind class methods */ /* First 4 tools use guides, first is undefined but we don't care */ dt->activate_guides(num < 5); - inkscape_eventcontext_set(dt->getEventContext()); + INKSCAPE.eventcontext_set(dt->getEventContext()); } void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p) diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index 4f64ade25..b9206407a 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -29,7 +29,7 @@ #include "document-undo.h" #include "sp-namedview.h" #include "selection.h" -#include "desktop-handles.h" + #include "snap.h" #include "pixmaps/cursor-ellipse.xpm" #include "xml/repr.h" @@ -109,11 +109,11 @@ void ArcTool::selection_changed(Inkscape::Selection* selection) { void ArcTool::setup() { ToolBase::setup(); - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } @@ -151,7 +151,7 @@ bool ArcTool::item_handler(SPItem* item, GdkEvent* event) { bool ArcTool::root_handler(GdkEvent* event) { static bool dragging; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -405,8 +405,8 @@ void ArcTool::drag(Geom::Point pt, guint state) { Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); - GString *xs = g_string_new(rdimx_q.string(desktop->namedview->doc_units).c_str()); - GString *ys = g_string_new(rdimy_q.string(desktop->namedview->doc_units).c_str()); + GString *xs = g_string_new(rdimx_q.string(desktop->namedview->display_units).c_str()); + GString *ys = g_string_new(rdimy_q.string(desktop->namedview->display_units).c_str()); if (state & GDK_CONTROL_MASK) { int ratio_x, ratio_y; @@ -442,16 +442,16 @@ void ArcTool::finishItem() { desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(this->arc); + desktop->getSelection()->set(this->arc); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC, _("Create ellipse")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ARC, _("Create ellipse")); this->arc = NULL; } } void ArcTool::cancel() { - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); if (this->arc != NULL) { @@ -466,7 +466,7 @@ void ArcTool::cancel() { desktop->canvas->endForcedFullRedraws(); - DocumentUndo::cancel(sp_desktop_document(desktop)); + DocumentUndo::cancel(desktop->getDocument()); } } diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index 0a20a0842..f8ae685c4 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -26,7 +26,7 @@ #include "sp-namedview.h" #include "selection.h" #include "selection-chemistry.h" -#include "desktop-handles.h" + #include "snap.h" #include "display/curve.h" #include "display/sp-canvas-item.h" @@ -145,17 +145,17 @@ void Box3dTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); - this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged( + this->sel_changed_connection = this->desktop->getSelection()->connectChanged( sigc::mem_fun(this, &Box3dTool::selection_changed) ); - this->_vpdrag = new Box3D::VPDrag(sp_desktop_document(this->desktop)); + this->_vpdrag = new Box3D::VPDrag(this->desktop->getDocument()); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -195,8 +195,8 @@ bool Box3dTool::item_handler(SPItem* item, GdkEvent* event) { bool Box3dTool::root_handler(GdkEvent* event) { static bool dragging; - SPDocument *document = sp_desktop_document (desktop); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + SPDocument *document = desktop->getDocument(); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); @@ -466,7 +466,7 @@ bool Box3dTool::root_handler(GdkEvent* event) { break; case GDK_KEY_Escape: - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); //TODO: make dragging escapable by Esc break; @@ -589,7 +589,7 @@ void Box3dTool::finishItem() { this->extruded = false; if (this->box3d != NULL) { - SPDocument *doc = sp_desktop_document(this->desktop); + SPDocument *doc = this->desktop->getDocument(); if (!doc || !doc->getCurrentPersp3D()) { return; @@ -604,8 +604,8 @@ void Box3dTool::finishItem() { desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(this->box3d); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX, + desktop->getSelection()->set(this->box3d); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_3DBOX, _("Create 3D box")); this->box3d = NULL; diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index d297fe5e1..151ab5f89 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -47,7 +47,7 @@ #include "selection.h" #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "message-context.h" #include "preferences.h" @@ -141,7 +141,7 @@ void CalligraphicTool::setup() { this->cal1 = new SPCurve(); this->cal2 = new SPCurve(); - this->currentshape = sp_canvas_item_new(sp_desktop_sketch(this->desktop), SP_TYPE_CANVAS_BPATH, NULL); + this->currentshape = sp_canvas_item_new(this->desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->currentshape), DDC_RED_RGBA, SP_WIND_RULE_EVENODD); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); @@ -155,7 +155,7 @@ void CalligraphicTool::setup() { SPCurve *c = new SPCurve(path); - this->hatch_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); + this->hatch_area = sp_canvas_bpath_new(this->desktop->getControls(), c); c->unref(); @@ -373,7 +373,7 @@ void CalligraphicTool::brush() { double R, G, B, A; Geom::IntRect area = Geom::IntRect::from_xywh(brush_w.floor(), Geom::IntPoint(1, 1)); cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); - sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(SP_EVENT_CONTEXT(this)->desktop)), s, area); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(this->desktop->getDrawing()), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); double max = MAX (MAX (R, G), B); @@ -506,7 +506,7 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { if (event->motion.state & GDK_CONTROL_MASK) { // hatching - sense the item - SPItem *selected = sp_desktop_selection(desktop)->singleItem(); + SPItem *selected = desktop->getSelection()->singleItem(); if (selected && (SP_IS_SHAPE(selected) || SP_IS_TEXT(selected))) { // One item selected, and it's a path; // let's try to track it as a guide @@ -940,14 +940,14 @@ void CalligraphicTool::set_to_accumulated(bool unionize, bool subtract) { g_free(str); if (unionize) { - sp_desktop_selection(desktop)->add(this->repr); - sp_selected_path_union_skip_undo(sp_desktop_selection(desktop), desktop); + desktop->getSelection()->add(this->repr); + sp_selected_path_union_skip_undo(desktop->getSelection(), desktop); } else if (subtract) { - sp_desktop_selection(desktop)->add(this->repr); - sp_selected_path_diff_skip_undo(sp_desktop_selection(desktop), desktop); + desktop->getSelection()->add(this->repr); + sp_selected_path_diff_skip_undo(desktop->getSelection(), desktop); } else { if (this->keep_selected) { - sp_desktop_selection(desktop)->set(this->repr); + desktop->getSelection()->set(this->repr); } } @@ -973,7 +973,7 @@ void CalligraphicTool::set_to_accumulated(bool unionize, bool subtract) { this->repr = NULL; } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_CALLIGRAPHIC, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_CALLIGRAPHIC, _("Draw calligraphic stroke")); } @@ -1142,7 +1142,7 @@ void CalligraphicTool::fit_and_split(bool release) { if (!release) { g_assert(!this->currentcurve->is_empty()); - SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), + SPCanvasItem *cbp = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL); SPCurve *curve = this->currentcurve->copy(); diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 7b5c84c16..26a4eadd5 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -79,7 +79,7 @@ #include "svg/svg.h" #include "desktop.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "message-context.h" @@ -223,7 +223,7 @@ ConnectorTool::~ConnectorTool() { void ConnectorTool::setup() { ToolBase::setup(); - this->selection = sp_desktop_selection(this->desktop); + this->selection = this->desktop->getSelection(); this->sel_changed_connection.disconnect(); this->sel_changed_connection = this->selection->connectChanged( @@ -231,7 +231,7 @@ void ConnectorTool::setup() { ); /* Create red bpath */ - this->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), NULL); + this->red_bpath = sp_canvas_bpath_new(this->desktop->getSketch(), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->red_bpath), 0x00000000, @@ -659,7 +659,7 @@ bool ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; if ( revent.button == 1 && !this->space_panning ) { - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); SnapManager &m = desktop->namedview->snap_manager; Geom::Point const event_w(revent.x, revent.y); @@ -729,7 +729,7 @@ bool ConnectorTool::_handleKeyPress(guint const keyval) { break; case GDK_KEY_Escape: if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); this->_reroutingFinish(NULL); @@ -754,7 +754,7 @@ bool ConnectorTool::_handleKeyPress(guint const keyval) { } void ConnectorTool::_reroutingFinish(Geom::Point *const p) { - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); // Clear the temporary path: this->red_curve->reset(); @@ -812,7 +812,7 @@ void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { Avoid::Point dst(d[Geom::X], d[Geom::Y]); if (!this->newConnRef) { - Avoid::Router *router = sp_desktop_document(desktop)->router; + Avoid::Router *router = desktop->getDocument()->router; this->newConnRef = new Avoid::ConnRef(router); this->newConnRef->setEndpoint(Avoid::VertID::src, src); if (this->isOrthogonal) @@ -876,7 +876,7 @@ void ConnectorTool::_flushWhite(SPCurve *gc) { /* Now we have to go back to item coordinates at last */ c->transform(this->desktop->dt2doc()); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); if ( c && !c->is_empty() ) { @@ -1304,14 +1304,14 @@ bool cc_item_is_connector(SPItem *item) void cc_selection_set_avoid(bool const set_avoid) { - SPDesktop *desktop = inkscape_active_desktop(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop == NULL) { return; } - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList *l = const_cast<GSList *>(selection->itemList()); diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 6c55f7484..178e6636e 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -34,7 +34,7 @@ #include "sp-namedview.h" #include "sp-cursor.h" #include "desktop.h" -#include "desktop-handles.h" + #include "selection.h" #include "document.h" #include "document-undo.h" @@ -99,7 +99,7 @@ void DropperTool::setup() { SPCurve *c = new SPCurve(path); - this->area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); + this->area = sp_canvas_bpath_new(this->desktop->getControls(), c); c->unref(); @@ -200,7 +200,7 @@ bool DropperTool::root_handler(GdkEvent* event) { // If one time pick with stroke set the pixmap if (prefs->getBool("/tools/dropper/onetimepick", false) && prefs->getInt("/dialogs/fillstroke/page", 0) == 1) { //TODO Only set when not set already - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); gdk_window_set_cursor(window, cursor_dropper_stroke); } @@ -230,7 +230,7 @@ bool DropperTool::root_handler(GdkEvent* event) { if (!r.hasZeroArea()) { Geom::IntRect area = r.roundOutwards(); cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, area.width(), area.height()); - sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), s, area); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); } @@ -238,14 +238,14 @@ bool DropperTool::root_handler(GdkEvent* event) { // pick single pixel Geom::IntRect area = Geom::IntRect::from_xywh(floor(event->button.x), floor(event->button.y), 1, 1); cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); - sp_canvas_arena_render_surface(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), s, area); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); ink_cairo_surface_average_color_premul(s, R, G, B, A); cairo_surface_destroy(s); } if (pick == SP_DROPPER_PICK_VISIBLE) { // compose with page color - guint32 bg = sp_desktop_namedview(desktop)->pagecolor; + guint32 bg = desktop->getNamedView()->pagecolor; R = R + (SP_RGBA32_R_F(bg)) * (1 - A); G = G + (SP_RGBA32_G_F(bg)) * (1 - A); B = B + (SP_RGBA32_B_F(bg)) * (1 - A); @@ -324,12 +324,12 @@ bool DropperTool::root_handler(GdkEvent* event) { // REJON: set aux. toolbar input to hex color! if (event->button.state & GDK_SHIFT_MASK) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); gdk_window_set_cursor(window, cursor_dropper_stroke); } - if (!(sp_desktop_selection(desktop)->isEmpty())) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER, + if (!(desktop->getSelection()->isEmpty())) { + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_DROPPER, _("Set picked color")); } @@ -359,11 +359,11 @@ bool DropperTool::root_handler(GdkEvent* event) { break; case GDK_KEY_Escape: - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: if (!desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); gdk_window_set_cursor(window, cursor_dropper_stroke); } @@ -378,7 +378,7 @@ bool DropperTool::root_handler(GdkEvent* event) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: if (!desktop->isWaitingCursor() && !prefs->getBool("/tools/dropper/onetimepick", false)) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(desktop->getCanvas())); gdk_window_set_cursor(window, cursor_dropper_fill); } break; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index bf4015b4c..1b4dcfe25 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -44,7 +44,7 @@ #include "selection.h" #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "message-context.h" #include "preferences.h" @@ -121,7 +121,7 @@ void EraserTool::setup() { this->cal1 = new SPCurve(); this->cal2 = new SPCurve(); - this->currentshape = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); + this->currentshape = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->currentshape), ERC_RED_RGBA, SP_WIND_RULE_EVENODD); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); @@ -666,7 +666,7 @@ void EraserTool::set_to_accumulated() { if ( this->repr ) { bool wasSelection = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; @@ -680,10 +680,10 @@ void EraserTool::set_to_accumulated() { if (selection->isEmpty()) { if ( eraserMode ) { - toWorkOn = sp_desktop_document(desktop)->getItemsPartiallyInBox(desktop->dkey, bounds); + toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, bounds); } else { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); - toWorkOn = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, r->getPoints()); + toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } toWorkOn = g_slist_remove( toWorkOn, acid ); @@ -767,9 +767,9 @@ void EraserTool::set_to_accumulated() { if ( workDone ) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { - DocumentUndo::cancel(sp_desktop_document(desktop)); + DocumentUndo::cancel(desktop->getDocument()); } } @@ -949,7 +949,7 @@ void EraserTool::fit_and_split(bool release) { gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; g_assert(!this->currentcurve->is_empty()); - SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); + SPCanvasItem *cbp = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL); SPCurve *curve = this->currentcurve->copy(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve); curve->unref(); diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index 5745fc9cc..82057f483 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -31,7 +31,7 @@ #include "color.h" #include "context-fns.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "display/cairo-utils.h" #include "display/drawing-context.h" @@ -128,13 +128,13 @@ void FloodTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); - this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged( + this->sel_changed_connection = this->desktop->getSelection()->connectChanged( sigc::mem_fun(this, &FloodTool::selection_changed) ); @@ -360,7 +360,7 @@ inline static bool check_if_pixel_is_paintable(guchar *px, unsigned char *trace_ * @param union_with_selection If true, merge the final SVG path with the current selection. */ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *desktop, Geom::Affine transform, unsigned int min_x, unsigned int max_x, unsigned int min_y, unsigned int max_y, bool union_with_selection) { - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); unsigned char *trace_t; @@ -467,7 +467,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto g_free(affinestr); } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); pathRepr->setPosition(-1); @@ -476,7 +476,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto ngettext("Area filled, path with <b>%d</b> node created and unioned with selection.","Area filled, path with <b>%d</b> nodes created and unioned with selection.", SP_PATH(reprobj)->nodesInPath()), SP_PATH(reprobj)->nodesInPath() ); selection->add(reprobj); - sp_selected_path_union_skip_undo(sp_desktop_selection(desktop), desktop); + sp_selected_path_union_skip_undo(desktop->getSelection(), desktop); } else { desktop->messageStack()->flashF( Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with <b>%d</b> node created.","Area filled, path with <b>%d</b> nodes created.", @@ -740,7 +740,7 @@ static bool sort_fill_queue_horizontal(Geom::Point a, Geom::Point b) { */ static void sp_flood_do_flood_fill(ToolBase *event_context, GdkEvent *event, bool union_with_selection, bool is_point_fill, bool is_touch_fill) { SPDesktop *desktop = event_context->desktop; - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); document->ensureUpToDate(); @@ -792,7 +792,7 @@ static void sp_flood_do_flood_fill(ToolBase *event_context, GdkEvent *event, boo Inkscape::DrawingContext dc(s, Geom::Point(0,0)); // cairo_translate not necessary here - surface origin is at 0,0 - SPNamedView *nv = sp_desktop_namedview(desktop); + SPNamedView *nv = desktop->getNamedView(); bgcolor = nv->pagecolor; // bgcolor is 0xrrggbbaa, we need 0xaarrggbb dtc = (bgcolor >> 8) | (bgcolor << 24); @@ -1096,7 +1096,7 @@ bool FloodTool::item_handler(SPItem* item, GdkEvent* event) { // Set style desktop->applyCurrentOrToolStyle(item, "/tools/paintbucket", false); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object")); ret = TRUE; } @@ -1229,9 +1229,9 @@ void FloodTool::finishItem() { desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(this->item); + desktop->getSelection()->set(this->item); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area")); this->item = NULL; } diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index bd84e0efb..0f14d7534 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -27,7 +27,7 @@ #include <glibmm/i18n.h> #include "display/curve.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "document.h" #include "ui/draw-anchor.h" @@ -117,7 +117,7 @@ FreehandBase::~FreehandBase() { void FreehandBase::setup() { ToolBase::setup(); - this->selection = sp_desktop_selection(desktop); + this->selection = desktop->getSelection(); // Connect signals to track selection changes this->sel_changed_connection = this->selection->connectChanged( @@ -128,14 +128,14 @@ void FreehandBase::setup() { ); // Create red bpath - this->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), NULL); + this->red_bpath = sp_canvas_bpath_new(this->desktop->getSketch(), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); // Create red curve this->red_curve = new SPCurve(); // Create blue bpath - this->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), NULL); + this->blue_bpath = sp_canvas_bpath_new(this->desktop->getSketch(), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); // Create blue curve @@ -247,16 +247,14 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points char const *style_str = NULL; style_str = repr->attribute("style"); if (style_str) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str); - stroke_width = style->stroke_width.computed; - style->stroke_width.computed = 0; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str); + stroke_width = style.stroke_width.computed; } std::ostringstream s; s.imbue(std::locale::classic()); - s << "0," << stroke_width / 2.; + s << points[0][Geom::X] << "," << stroke_width / 2.; // write powerstroke parameters: lpe->getRepr()->setAttribute("start_linecap_type", "zerowidth"); @@ -500,7 +498,7 @@ void spdc_endpoint_snap_free(ToolBase const * const ec, Geom::Point& p, boost::o { SPDesktop *dt = ec->desktop; SnapManager &m = dt->namedview->snap_manager; - Inkscape::Selection *selection = sp_desktop_selection (dt); + Inkscape::Selection *selection = dt->getSelection(); // selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping) // TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment @@ -667,7 +665,7 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) : dc->desktop->dt2doc() ); SPDesktop *desktop = dc->desktop; - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); if ( c && !c->is_empty() ) { @@ -715,7 +713,7 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) // results in the tool losing all of the selected path's curve except that last subpath. To // fix this, we force the selection_modified callback now, to make sure the tool's curve is // in sync immediately. - spdc_selection_modified(sp_desktop_selection(desktop), 0, dc); + spdc_selection_modified(desktop->getSelection(), 0, dc); } c->unref(); @@ -821,14 +819,11 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too // find out stroke width (TODO: is there an easier way??) double stroke_width = 3.0; - gchar const *style_str = NULL; - style_str = repr->attribute("style"); + gchar const *style_str = repr->attribute("style"); if (style_str) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str); - stroke_width = style->stroke_width.computed; - style->stroke_width.computed = 0; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str); + stroke_width = style.stroke_width.computed; } // unset stroke and set fill color to former stroke color @@ -862,10 +857,10 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too sp_repr_set_svg_double (repr, "sodipodi:ry", rad * stroke_width); item->updateRepr(); - sp_desktop_selection(desktop)->set(item); + desktop->getSelection()->set(item); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating single dot")); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE, _("Create single dot")); } } diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 9c853917e..5da30da7b 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -23,7 +23,7 @@ #include "document.h" #include "selection.h" #include "desktop.h" -#include "desktop-handles.h" + #include "message-context.h" #include "message-stack.h" #include "pixmaps/cursor-gradient.xpm" @@ -112,7 +112,7 @@ void GradientTool::selection_changed(Inkscape::Selection*) { GradientTool *rc = (GradientTool *) this; GrDrag *drag = rc->_grdrag; - Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); if (selection == NULL) { return; } @@ -167,7 +167,7 @@ void GradientTool::setup() { } this->enableGrDrag(); - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->selcon = new sigc::connection(selection->connectChanged( sigc::mem_fun(this, &GradientTool::selection_changed) @@ -464,7 +464,7 @@ sp_gradient_context_add_stop_near_point (GradientTool *rc, SPItem *item, Geom:: SPStop *newstop = ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom()); - DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); ec->get_drag()->updateDraggers(); @@ -475,7 +475,7 @@ sp_gradient_context_add_stop_near_point (GradientTool *rc, SPItem *item, Geom:: bool GradientTool::root_handler(GdkEvent* event) { static bool dragging; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -509,13 +509,13 @@ bool GradientTool::root_handler(GdkEvent* event) { SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; - SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, fsmode); + SPGradient *vector = sp_gradient_vector_for_object(desktop->getDocument(), desktop, item, fsmode); SPGradient *priv = sp_item_set_gradient(item, vector, new_type, fsmode); sp_gradient_reset_to_userspace(priv, item); } - DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Create default gradient")); } ret = TRUE; @@ -892,8 +892,8 @@ bool GradientTool::root_handler(GdkEvent* event) { static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*state*/, guint32 etime) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPDocument *document = sp_desktop_document(desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *document = desktop->getDocument(); ToolBase *ec = SP_EVENT_CONTEXT(&rc); if (!selection->isEmpty()) { @@ -957,7 +957,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta "<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects), n_objects); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient.")); } } diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 1fd1ebf8c..c9b656397 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -30,7 +30,7 @@ #include "preferences.h" #include "ui/shape-editor.h" #include "selection.h" -#include "desktop-handles.h" + #include "document.h" #include "display/curve.h" #include "display/canvas-bpath.h" @@ -110,7 +110,7 @@ LpeTool::~LpeTool() { void LpeTool::setup() { PenTool::setup(); - Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); SPItem *item = selection->singleItem(); this->sel_changed_connection.disconnect(); @@ -164,7 +164,7 @@ bool LpeTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_BUTTON_PRESS: { // select the clicked item but do nothing else - Inkscape::Selection * const selection = sp_desktop_selection(this->desktop); + Inkscape::Selection * const selection = this->desktop->getSelection(); selection->clear(); selection->add(item); ret = TRUE; @@ -186,7 +186,7 @@ bool LpeTool::item_handler(SPItem* item, GdkEvent* event) { } bool LpeTool::root_handler(GdkEvent* event) { - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); bool ret = false; @@ -305,12 +305,12 @@ int lpetool_item_has_construction(LpeTool */*lc*/, SPItem *item) bool lpetool_try_construction(LpeTool *lc, Inkscape::LivePathEffect::EffectType const type) { - Inkscape::Selection *selection = sp_desktop_selection(lc->desktop); + Inkscape::Selection *selection = lc->desktop->getSelection(); SPItem *item = selection->singleItem(); // TODO: should we check whether type represents a valid geometric construction? if (item && SP_IS_LPE_ITEM(item) && Inkscape::LivePathEffect::Effect::acceptsNumClicks(type) == 0) { - Inkscape::LivePathEffect::Effect::createAndApply(type, sp_desktop_document(lc->desktop), item); + Inkscape::LivePathEffect::Effect::createAndApply(type, lc->desktop->getDocument(), item); return true; } return false; @@ -360,7 +360,7 @@ lpetool_context_reset_limiting_bbox(LpeTool *lc) if (!prefs->getBool("/tools/lpetool/show_bbox", true)) return; - SPDocument *document = sp_desktop_document(lc->desktop); + SPDocument *document = lc->desktop->getDocument(); Geom::Point A, B; lpetool_get_limiting_bbox_corners(document, A, B); @@ -371,7 +371,7 @@ lpetool_context_reset_limiting_bbox(LpeTool *lc) Geom::Rect rect(A, B); SPCurve *curve = SPCurve::new_from_rect(rect); - lc->canvas_bbox = sp_canvas_bpath_new (sp_desktop_controls(lc->desktop), curve); + lc->canvas_bbox = sp_canvas_bpath_new (lc->desktop->getControls(), curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(lc->canvas_bbox), 0x0000ffff, 0.8, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT, 5, 5); } @@ -396,7 +396,7 @@ void lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) { if (!selection) { - selection = sp_desktop_selection(lc->desktop); + selection = lc->desktop->getSelection(); } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool show = prefs->getBool("/tools/lpetool/show_measuring_info", true); @@ -404,7 +404,7 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) SPPath *path; SPCurve *curve; SPCanvasText *canvas_text; - SPCanvasGroup *tmpgrp = sp_desktop_tempgroup(lc->desktop); + SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup(); gchar *arc_length; double lengthval; diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 6b5cbeccd..b7e54b9c8 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -29,7 +29,7 @@ #include "pixmaps/cursor-measure.xpm" #include "preferences.h" #include "inkscape.h" -#include "desktop-handles.h" + #include "ui/tools/measure-tool.h" #include "ui/tools/freehand-base.h" #include "display/canvas-text.h" @@ -228,7 +228,7 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom yc + ay + (k2 * ax)); Geom::Point p3(xc + bx + (k2 * by), yc + by - (k2 * bx)); - SPCtrlCurve *curve = ControlManager::getManager().createControlCurve(sp_desktop_tempgroup(desktop), p1, p2, p3, p4, CTLINE_SECONDARY); + SPCtrlCurve *curve = ControlManager::getManager().createControlCurve(desktop->getTempGroup(), p1, p2, p3, p4, CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(SP_CANVAS_ITEM(curve), 0, true)); } @@ -291,7 +291,7 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: //TODO: consider only visible intersections Geom::Point intersection = lineseg[0].pointAt((*m).ta); double eps = 0.0001; - SPDocument* doc = sp_desktop_document(desktop); + SPDocument* doc = desktop->getDocument(); if (((*m).ta > eps && item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta - eps), false, NULL)) || ((*m).ta + eps < 1 && @@ -441,7 +441,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO switch to a different variable name. The single letter 'l' is easy to misread. //select elements crossed by line segment: - GSList *items = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, points); + GSList *items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); std::vector<double> intersection_times; for (GSList *l = items; l != NULL; l = l->next) { SPItem *item = static_cast<SPItem*>(l->data); @@ -525,7 +525,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO cleanup memory, Glib::ustring, etc.: gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, place.end, measure_str); @@ -548,7 +548,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO cleanup memory, Glib::ustring, etc.: gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); - SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, angleDisplayPt, angle_str); @@ -569,7 +569,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO cleanup memory, Glib::ustring, etc.: gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), totallength_str); @@ -590,7 +590,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO cleanup memory, Glib::ustring, etc.: gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), desktop, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, total_str); @@ -609,7 +609,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { for (size_t idx = 0; idx < intersections.size(); ++idx) { // Display the intersection indicator (i.e. the cross) - SPCanvasItem * canvasitem = sp_canvas_item_new(sp_desktop_tempgroup(desktop), + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 8.0, @@ -627,7 +627,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // draw main control line { - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(sp_desktop_tempgroup(desktop), + SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), start_point, end_point); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); @@ -642,7 +642,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { * Geom::Affine(Geom::Translate(start_point))); } - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(sp_desktop_tempgroup(desktop), + SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), start_point, anchorEnd, CTLINE_SECONDARY); @@ -655,17 +655,17 @@ bool MeasureTool::root_handler(GdkEvent* event) { if (intersections.size() > 2) { ControlManager &mgr = ControlManager::getManager(); SPCtrlLine *control_line = 0; - control_line = mgr.createControlLine(sp_desktop_tempgroup(desktop), + control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]) + normal * 60, desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - control_line = mgr.createControlLine(sp_desktop_tempgroup(desktop), + control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[0]), desktop->doc2dt(intersections[0]) + normal * 65); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - control_line = mgr.createControlLine(sp_desktop_tempgroup(desktop), + control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(intersections[intersections.size() - 1]), desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 65); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); @@ -677,7 +677,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { LabelPlacement &place = *it; ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(sp_desktop_tempgroup(desktop), + SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), place.start, place.end, CTLINE_SECONDARY); @@ -689,7 +689,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { Geom::Point measure_text_pos = (intersections[idx - 1] + intersections[idx]) / 2; ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(sp_desktop_tempgroup(desktop), + SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), desktop->doc2dt(measure_text_pos), desktop->doc2dt(measure_text_pos) - (normal * DIMENSION_OFFSET), CTLINE_SECONDARY); @@ -699,7 +699,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { // Initial point { - SPCanvasItem * canvasitem = sp_canvas_item_new(sp_desktop_tempgroup(desktop), + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), SP_TYPE_CTRL, "anchor", SP_ANCHOR_CENTER, "size", 8.0, diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 8a1fb7c72..d333b932e 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -27,7 +27,7 @@ // General #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "macros.h" @@ -107,7 +107,7 @@ const gchar *ms_handle_descr [] = { void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { GrDrag *drag = this->_grdrag; - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); if (selection == NULL) { return; @@ -234,7 +234,7 @@ void MeshTool::setup() { } this->enableGrDrag(); - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->selcon = new sigc::connection(selection->connectChanged( sigc::mem_fun(this, &MeshTool::selection_changed) @@ -317,7 +317,7 @@ static void sp_mesh_context_split_near_point(MeshTool *rc, SPItem *item, Geom:: ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom()); - DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Split mesh row/column")); ec->get_drag()->updateDraggers(); @@ -440,7 +440,7 @@ Handles all keyboard and mouse input for meshs. bool MeshTool::root_handler(GdkEvent* event) { static bool dragging; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -488,13 +488,13 @@ bool MeshTool::root_handler(GdkEvent* event) { #ifdef DEBUG_MESH std::cout << "sp_mesh_context_root_handler: creating new mesh on: " << (fsmode == Inkscape::FOR_FILL ? "Fill" : "Stroke") << std::endl; #endif - SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, fsmode); + SPGradient *vector = sp_gradient_vector_for_object(desktop->getDocument(), desktop, item, fsmode); SPGradient *priv = sp_item_set_gradient(item, vector, new_type, fsmode); sp_gradient_reset_to_userspace(priv, item); } - DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Create default mesh")); } @@ -933,8 +933,8 @@ bool MeshTool::root_handler(GdkEvent* event) { static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPDocument *document = sp_desktop_document(desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *document = desktop->getDocument(); ToolBase *ec = SP_EVENT_CONTEXT(&rc); if (!selection->isEmpty()) { @@ -994,7 +994,7 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ "<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects), n_objects); } else { - sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient.")); + desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient.")); } } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 838c2a884..caec901a6 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -13,7 +13,7 @@ #include "ui/tool/curve-drag-point.h" #include <glib/gi18n.h> #include "desktop.h" -#include "desktop-handles.h" + #include "display/sp-canvas-group.h" #include "display/canvas-bpath.h" #include "display/curve.h" @@ -155,7 +155,7 @@ NodeTool::NodeTool() SPCanvasGroup *create_control_group(SPDesktop *d) { return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new( - sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL)); + d->getControls(), SP_TYPE_CANVAS_GROUP, NULL)); } void destroy_group(SPCanvasGroup *g) @@ -215,7 +215,7 @@ void NodeTool::setup() { data.node_data.node_group = create_control_group(this->desktop); data.node_data.handle_group = create_control_group(this->desktop); - Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->_selection_changed_connection.disconnect(); this->_selection_changed_connection = @@ -295,7 +295,7 @@ void NodeTool::setup() { // show helper paths of the applied LPE, if any void NodeTool::update_helperpath () { - Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); if (this->helperpath_tmpitem) { this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem); @@ -324,7 +324,7 @@ void NodeTool::update_helperpath () { cc->reset(); } if (!c->is_empty()) { - SPCanvasItem *helperpath = sp_canvas_bpath_new(sp_desktop_tempgroup(this->desktop), c); + SPCanvasItem *helperpath = sp_canvas_bpath_new(this->desktop->getTempGroup(), c); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath), 0x0000ff9A, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO); sp_canvas_item_affine_absolute(helperpath, selection->singleItem()->i2dt_affine()); @@ -527,7 +527,7 @@ bool NodeTool::root_handler(GdkEvent* event) { } c->transform(over_item->i2dt_affine()); - SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c); + SPCanvasItem *flash = sp_canvas_bpath_new(desktop->getTempGroup(), c); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash), //prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0, @@ -668,7 +668,7 @@ void NodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { if (this->_multipath->empty()) { // if multipath is empty, select rubberbanded items rather than nodes Inkscape::Selection *selection = this->desktop->selection; - GSList *items = sp_desktop_document(this->desktop)->getItemsInBox(this->desktop->dkey, sel); + GSList *items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); selection->setList(items); g_slist_free(items); } else { diff --git a/src/ui/tools/node-tool.h b/src/ui/tools/node-tool.h index ab72f3632..20375e869 100644 --- a/src/ui/tools/node-tool.h +++ b/src/ui/tools/node-tool.h @@ -33,6 +33,8 @@ namespace Inkscape { } } +struct SPCanvasGroup; + #define INK_NODE_TOOL(obj) (dynamic_cast<Inkscape::UI::Tools::NodeTool*>((Inkscape::UI::Tools::ToolBase*)obj)) #define INK_IS_NODE_TOOL(obj) (dynamic_cast<const Inkscape::UI::Tools::NodeTool*>((const Inkscape::UI::Tools::ToolBase*)obj)) diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 92937a135..4587e88c8 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -23,7 +23,7 @@ #include "ui/tools/pen-tool.h" #include "sp-namedview.h" #include "desktop.h" -#include "desktop-handles.h" + #include "selection.h" #include "selection-chemistry.h" #include "ui/draw-anchor.h" @@ -192,14 +192,14 @@ void PenTool::setup() { ControlManager &mgr = ControlManager::getManager(); // Pen indicators - this->c0 = mgr.createControl(sp_desktop_controls(this->desktop), Inkscape::CTRL_TYPE_ADJ_HANDLE); + this->c0 = mgr.createControl(this->desktop->getControls(), Inkscape::CTRL_TYPE_ADJ_HANDLE); mgr.track(this->c0); - this->c1 = mgr.createControl(sp_desktop_controls(this->desktop), Inkscape::CTRL_TYPE_ADJ_HANDLE); + this->c1 = mgr.createControl(this->desktop->getControls(), Inkscape::CTRL_TYPE_ADJ_HANDLE); mgr.track(this->c1); - this->cl0 = mgr.createControlLine(sp_desktop_controls(this->desktop)); - this->cl1 = mgr.createControlLine(sp_desktop_controls(this->desktop)); + this->cl0 = mgr.createControlLine(this->desktop->getControls()); + this->cl1 = mgr.createControlLine(this->desktop->getControls()); sp_canvas_item_hide(this->c0); sp_canvas_item_hide(this->c1); @@ -468,7 +468,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) { // This is the first click of a new curve; deselect item so that // this curve is not combined with it (unless it is drawn from its // anchor, which is handled by the sibling branch above) - Inkscape::Selection * const selection = sp_desktop_selection(desktop); + Inkscape::Selection * const selection = desktop->getSelection(); if (!(bevent.state & GDK_SHIFT_MASK) || this->hasWaitingLPE()) { // if we have a waiting LPE, we need a fresh path to be created // so don't append to an existing one @@ -614,7 +614,12 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { ret = true; break; case PenTool::STOP: - // This is perfectly valid + if (!this->sp_event_context_knot_mouseover()) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); + m.unSetup(); + } break; default: break; @@ -685,8 +690,7 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { ret = true; break; case PenTool::STOP: - // This is perfectly valid - break; + // Don't break; fall through to default to do preSnapping default: if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; @@ -846,7 +850,7 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { this->setPolylineMode(); - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); if (this->waiting_LPE) { // we have an already created LPE waiting for a path @@ -881,7 +885,7 @@ void PenTool::_redrawAll() { this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } // one canvas bpath for all of green_curve - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO); @@ -1366,7 +1370,7 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t Geom::Point rel = p - this->p[pc_point_to_compare]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); - GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); + GString *dist = g_string_new(q.string(desktop->namedview->display_units).c_str()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { @@ -1415,7 +1419,7 @@ void PenTool::_bspline_spiro_color() this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } // one canvas bpath for all of green_curve - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO); this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); @@ -2161,7 +2165,7 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) { SPCurve *curve = this->red_curve->copy(); /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), curve); curve->unref(); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); @@ -2277,7 +2281,7 @@ void PenTool::_setToNearestHorizVert(Geom::Point &pt, guint const state, bool sn // Snap along the constraint line; if we didn't snap then still the constraint will be applied SnapManager &m = this->desktop->namedview->snap_manager; - Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); // selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping) // TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 3ea2ae843..28fed3a8f 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -20,7 +20,7 @@ #include "ui/tools/pencil-tool.h" #include "desktop.h" -#include "desktop-handles.h" + #include "selection.h" #include "selection-chemistry.h" #include "ui/draw-anchor.h" @@ -153,7 +153,7 @@ bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) { bool ret = false; if ( bevent.button == 1 && !this->space_panning) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return true; @@ -853,7 +853,7 @@ void PencilTool::_fitAndSplit() { SPCurve *curve = this->red_curve->copy(); /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), curve); curve->unref(); this->highlight_color = SP_ITEM(this->desktop->currentLayer())->highlight_color(); diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index de91dcff4..9476ff624 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -28,7 +28,7 @@ #include "sp-namedview.h" #include "selection.h" #include "selection-chemistry.h" -#include "desktop-handles.h" + #include "snap.h" #include "desktop.h" #include "desktop-style.h" @@ -111,13 +111,13 @@ void RectTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); - this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged( + this->sel_changed_connection = this->desktop->getSelection()->connectChanged( sigc::mem_fun(this, &RectTool::selection_changed) ); @@ -170,7 +170,7 @@ bool RectTool::root_handler(GdkEvent* event) { static bool dragging; SPDesktop *desktop = this->desktop; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -422,8 +422,8 @@ void RectTool::drag(Geom::Point const pt, guint state) { Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); - GString *xs = g_string_new(rdimx_q.string(desktop->namedview->doc_units).c_str()); - GString *ys = g_string_new(rdimy_q.string(desktop->namedview->doc_units).c_str()); + GString *xs = g_string_new(rdimx_q.string(desktop->namedview->display_units).c_str()); + GString *ys = g_string_new(rdimy_q.string(desktop->namedview->display_units).c_str()); if (state & GDK_CONTROL_MASK) { int ratio_x, ratio_y; @@ -476,16 +476,16 @@ void RectTool::finishItem() { this->desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(this->desktop)->set(this->rect); + this->desktop->getSelection()->set(this->rect); - DocumentUndo::done(sp_desktop_document(this->desktop), SP_VERB_CONTEXT_RECT, _("Create rectangle")); + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_RECT, _("Create rectangle")); this->rect = NULL; } } void RectTool::cancel(){ - sp_desktop_selection(this->desktop)->clear(); + this->desktop->getSelection()->clear(); sp_canvas_item_ungrab(SP_CANVAS_ITEM(this->desktop->acetate), 0); if (this->rect != NULL) { @@ -500,7 +500,7 @@ void RectTool::cancel(){ this->desktop->canvas->endForcedFullRedraws(); - DocumentUndo::cancel(sp_desktop_document(this->desktop)); + DocumentUndo::cancel(this->desktop->getDocument()); } } diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index a8267ea1d..939b1a0b3 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -38,7 +38,7 @@ #include "extension/dbus/document-interface.h" #endif #include "desktop.h" -#include "desktop-handles.h" + #include "sp-root.h" #include "preferences.h" #include "ui/tools-switch.h" @@ -208,7 +208,7 @@ bool SelectTool::sp_select_context_abort() { if (this->item) { // only undo if the item is still valid if (this->item->document) { - DocumentUndo::undo(sp_desktop_document(desktop)); + DocumentUndo::undo(desktop->getDocument()); } sp_object_unref( this->item, NULL); @@ -216,7 +216,7 @@ bool SelectTool::sp_select_context_abort() { // NOTE: This is a workaround to a bug. // When the ctrl key is held, sc->item is not defined // so in this case (only), we skip the object doc check - DocumentUndo::undo(sp_desktop_document(desktop)); + DocumentUndo::undo(desktop->getDocument()); } this->item = NULL; @@ -272,7 +272,7 @@ sp_select_context_up_one_layer(SPDesktop *desktop) { desktop->setCurrentLayer(parent); if (current_group && (SPGroup::LAYER != current_group->layerMode())) { - sp_desktop_selection(desktop)->set(current_layer); + desktop->getSelection()->set(current_layer); } } } @@ -308,7 +308,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { // if shift or ctrl was pressed, do not move objects; // pass the event to root handler which will perform rubberband, shift-click, ctrl-click, ctrl-drag } else { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); this->dragging = TRUE; this->moved = FALSE; @@ -353,7 +353,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_ENTER_NOTIFY: { if (!desktop->isWaitingCursor() && !this->dragging) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectMouseover); } @@ -361,7 +361,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } case GDK_LEAVE_NOTIFY: if (!desktop->isWaitingCursor() && !this->dragging) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, this->cursor); } @@ -469,7 +469,7 @@ bool SelectTool::root_handler(GdkEvent* event) { SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL; gint ret = FALSE; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // make sure we still have valid objects to move around @@ -485,7 +485,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(clicked_item); - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); this->dragging = false; sp_event_context_discard_delayed_snap_event(this); @@ -573,7 +573,7 @@ bool SelectTool::root_handler(GdkEvent* event) { // but not with shift) we want to drag rather than rubberband this->dragging = TRUE; - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectDragging); @@ -702,7 +702,7 @@ bool SelectTool::root_handler(GdkEvent* event) { } this->dragging = FALSE; - window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectMouseover); sp_event_context_discard_delayed_snap_event(this); @@ -722,9 +722,9 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); - items = sp_desktop_document(desktop)->getItemsInBox(desktop->dkey, *b); + items = desktop->getDocument()->getItemsInBox(desktop->dkey, *b); } else if (r->getMode() == RUBBERBAND_MODE_TOUCHPATH) { - items = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, r->getPoints()); + items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } _seltrans->resetState(); @@ -953,7 +953,7 @@ bool SelectTool::root_handler(GdkEvent* event) { // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectDragging); } @@ -974,15 +974,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(sp_desktop_selection(desktop), mul*-10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift } else { - sp_selection_move_screen(sp_desktop_selection(desktop), mul*-1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(sp_desktop_selection(desktop), mul*-10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift } else { - sp_selection_move(sp_desktop_selection(desktop), mul*-nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift } } @@ -997,15 +997,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(sp_desktop_selection(desktop), 0, mul*10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift } else { - sp_selection_move_screen(sp_desktop_selection(desktop), 0, mul*1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(sp_desktop_selection(desktop), 0, mul*10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift } else { - sp_selection_move(sp_desktop_selection(desktop), 0, mul*nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift } } @@ -1020,15 +1020,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(sp_desktop_selection(desktop), mul*10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift } else { - sp_selection_move_screen(sp_desktop_selection(desktop), mul*1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(sp_desktop_selection(desktop), mul*10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift } else { - sp_selection_move(sp_desktop_selection(desktop), mul*nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift } } @@ -1043,15 +1043,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(sp_desktop_selection(desktop), 0, mul*-10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift } else { - sp_selection_move_screen(sp_desktop_selection(desktop), 0, mul*-1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(sp_desktop_selection(desktop), 0, mul*-10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift } else { - sp_selection_move(sp_desktop_selection(desktop), 0, mul*-nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift } } @@ -1155,7 +1155,7 @@ bool SelectTool::root_handler(GdkEvent* event) { SPGroup *clickedGroup = dynamic_cast<SPGroup *>(clicked_item); if ( (clickedGroup && (clickedGroup->layerMode() != SPGroup::LAYER)) || dynamic_cast<SPBox3D *>(clicked_item)) { // enter group or a 3D box desktop->setCurrentLayer(clicked_item); - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); } else { this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter.")); } @@ -1226,7 +1226,7 @@ bool SelectTool::root_handler(GdkEvent* event) { // set cursor to default. if (!desktop->isWaitingCursor()) { // Do we need to reset the cursor here on key release ? - //GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + //GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); //gdk_window_set_cursor(window, event_context->cursor); } break; diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index 18c3e4e2d..f208e1c43 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -27,7 +27,7 @@ #include "document-undo.h" #include "sp-namedview.h" #include "selection.h" -#include "desktop-handles.h" + #include "snap.h" #include "desktop.h" #include "desktop-style.h" @@ -117,12 +117,12 @@ void SpiralTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->sel_changed_connection.disconnect(); this->sel_changed_connection = selection->connectChanged(sigc::mem_fun(this, &SpiralTool::selection_changed)); @@ -154,7 +154,7 @@ bool SpiralTool::root_handler(GdkEvent* event) { static gboolean dragging; SPDesktop *desktop = this->desktop; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -395,7 +395,7 @@ void SpiralTool::drag(Geom::Point const &p, guint state) { /* status text */ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px"); - GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str()); + GString *rads = g_string_new(q.string(desktop->namedview->display_units).c_str()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Spiral</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle"), rads->str, sp_round((arg + 2.0*M_PI*this->spiral->revo)*180/M_PI, 0.0001)); @@ -417,15 +417,15 @@ void SpiralTool::finishItem() { this->desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(this->desktop)->set(this->spiral); - DocumentUndo::done(sp_desktop_document(this->desktop), SP_VERB_CONTEXT_SPIRAL, _("Create spiral")); + this->desktop->getSelection()->set(this->spiral); + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_SPIRAL, _("Create spiral")); this->spiral = NULL; } } void SpiralTool::cancel() { - sp_desktop_selection(this->desktop)->clear(); + this->desktop->getSelection()->clear(); sp_canvas_item_ungrab(SP_CANVAS_ITEM(this->desktop->acetate), 0); if (this->spiral != NULL) { @@ -440,7 +440,7 @@ void SpiralTool::cancel() { this->desktop->canvas->endForcedFullRedraws(); - DocumentUndo::cancel(sp_desktop_document(this->desktop)); + DocumentUndo::cancel(this->desktop->getDocument()); } } diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index cdc608558..a01c5c55b 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -33,7 +33,7 @@ #include "selection.h" #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "message-context.h" #include "pixmaps/cursor-spray.xpm" #include <boost/optional.hpp> @@ -222,7 +222,7 @@ void SprayTool::setup() { SPCurve *c = new SPCurve(path); - this->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); + this->dilate_area = sp_canvas_bpath_new(this->desktop->getControls(), c); c->unref(); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->dilate_area), 0x00000000,(SPWindRule)0); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); @@ -527,7 +527,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse) { SPDesktop *desktop = tc->desktop; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection->isEmpty()) { return false; @@ -735,15 +735,15 @@ bool SprayTool::root_handler(GdkEvent* event) { this->has_dilated = false; switch (this->mode) { case SPRAY_MODE_COPY: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_SPRAY, _("Spray with copies")); break; case SPRAY_MODE_CLONE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_SPRAY, _("Spray with clones")); break; case SPRAY_MODE_SINGLE_PATH: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_SPRAY, _("Spray in single path")); break; } diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index 7604ba04e..df311f2d8 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -30,7 +30,7 @@ #include "document-undo.h" #include "sp-namedview.h" #include "selection.h" -#include "desktop-handles.h" + #include "snap.h" #include "desktop.h" #include "desktop-style.h" @@ -127,12 +127,12 @@ void StarTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item) { this->shape_editor->set_item(item); } - Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + Inkscape::Selection *selection = this->desktop->getSelection(); this->sel_changed_connection.disconnect(); @@ -168,7 +168,7 @@ bool StarTool::root_handler(GdkEvent* event) { static bool dragging; SPDesktop *desktop = this->desktop; - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -411,7 +411,7 @@ void StarTool::drag(Geom::Point p, guint state) /* status text */ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px"); - GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str()); + GString *rads = g_string_new(q.string(desktop->namedview->display_units).c_str()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, ( this->isflatsided? _("<b>Polygon</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") @@ -441,8 +441,8 @@ void StarTool::finishItem() { desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(this->star); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + desktop->getSelection()->set(this->star); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, _("Create star")); this->star = NULL; @@ -450,7 +450,7 @@ void StarTool::finishItem() { } void StarTool::cancel() { - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); if (this->star != NULL) { @@ -465,7 +465,7 @@ void StarTool::cancel() { desktop->canvas->endForcedFullRedraws(); - DocumentUndo::cancel(sp_desktop_document(desktop)); + DocumentUndo::cancel(desktop->getDocument()); } } diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index a72748733..df0583d67 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -26,7 +26,7 @@ #include <sstream> #include "context-fns.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "desktop.h" #include "document.h" @@ -131,17 +131,17 @@ void TextTool::setup() { timeout /= 2; } - this->cursor = ControlManager::getManager().createControlLine(sp_desktop_controls(desktop), Geom::Point(100, 0), Geom::Point(100, 100)); + this->cursor = ControlManager::getManager().createControlLine(desktop->getControls(), Geom::Point(100, 0), Geom::Point(100, 100)); this->cursor->setRgba32(0x000000ff); sp_canvas_item_hide(this->cursor); - this->indicator = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL); + this->indicator = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRLRECT, NULL); SP_CTRLRECT(this->indicator)->setRectangle(Geom::Rect(Geom::Point(0, 0), Geom::Point(100, 100))); SP_CTRLRECT(this->indicator)->setColor(0x0000ff7f, false, 0); SP_CTRLRECT(this->indicator)->setShadow(1, 0xffffff7f); sp_canvas_item_hide(this->indicator); - this->frame = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL); + this->frame = sp_canvas_item_new(desktop->getControls(), SP_TYPE_CTRLRECT, NULL); SP_CTRLRECT(this->frame)->setRectangle(Geom::Rect(Geom::Point(0, 0), Geom::Point(100, 100))); SP_CTRLRECT(this->frame)->setColor(0x0000ff7f, false, 0); sp_canvas_item_hide(this->frame); @@ -150,7 +150,7 @@ void TextTool::setup() { this->imc = gtk_im_multicontext_new(); if (this->imc) { - GtkWidget *canvas = GTK_WIDGET(sp_desktop_canvas(desktop)); + GtkWidget *canvas = GTK_WIDGET(desktop->getCanvas()); /* im preedit handling is very broken in inkscape for * multi-byte characters. See bug 1086769. @@ -175,15 +175,15 @@ void TextTool::setup() { this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); + SPItem *item = this->desktop->getSelection()->singleItem(); if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { this->shape_editor->set_item(item); } - this->sel_changed_connection = sp_desktop_selection(desktop)->connectChangedFirst( + this->sel_changed_connection = desktop->getSelection()->connectChangedFirst( sigc::mem_fun(*this, &TextTool::_selectionChanged) ); - this->sel_modified_connection = sp_desktop_selection(desktop)->connectModifiedFirst( + this->sel_modified_connection = desktop->getSelection()->connectModifiedFirst( sigc::mem_fun(*this, &TextTool::_selectionModified) ); this->style_set_connection = desktop->connectSetStyle( @@ -193,7 +193,7 @@ void TextTool::setup() { sigc::mem_fun(*this, &TextTool::_styleQueried) ); - _selectionChanged(sp_desktop_selection(desktop)); + _selectionChanged(desktop->getSelection()); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/text/selcue")) { @@ -206,7 +206,7 @@ void TextTool::setup() { void TextTool::finish() { if (this->desktop) { - sp_signal_disconnect_by_data(sp_desktop_canvas(this->desktop), this); + sp_signal_disconnect_by_data(this->desktop->getCanvas(), this); } this->enableGrDrag(false); @@ -268,7 +268,7 @@ bool TextTool::item_handler(SPItem* item, GdkEvent* event) { // find out clicked item, disregarding groups item_ungrouped = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE); if (SP_IS_TEXT(item_ungrouped) || SP_IS_FLOWTEXT(item_ungrouped)) { - sp_desktop_selection(desktop)->set(item_ungrouped); + desktop->getSelection()->set(item_ungrouped); if (this->text) { // find out click point in document coordinates Geom::Point p = desktop->w2d(Geom::Point(event->button.x, event->button.y)); @@ -425,13 +425,13 @@ static void sp_text_context_setup_text(TextTool *tc) SPItem *text_item = SP_ITEM(ec->desktop->currentLayer()->appendChildRepr(rtext)); /* fixme: Is selection::changed really immediate? */ /* yes, it's immediate .. why does it matter? */ - sp_desktop_selection(ec->desktop)->set(text_item); + ec->desktop->getSelection()->set(text_item); Inkscape::GC::release(rtext); text_item->transform = SP_ITEM(ec->desktop->currentLayer())->i2doc_affine().inverse(); text_item->updateRepr(); text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); - DocumentUndo::done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(ec->desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Create text")); } @@ -471,7 +471,7 @@ static void insert_uni_char(TextTool *const tc) tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, u); sp_text_context_update_cursor(tc); sp_text_context_update_text_selection(tc); - DocumentUndo::done(sp_desktop_document(tc->desktop), SP_VERB_DIALOG_TRANSFORM, + DocumentUndo::done(tc->desktop->getDocument(), SP_VERB_DIALOG_TRANSFORM, _("Insert Unicode character")); } } @@ -590,8 +590,8 @@ bool TextTool::root_handler(GdkEvent* event) { // status text Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - this->p0)[Geom::X]), "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - this->p0)[Geom::Y]), "px"); - GString *xs = g_string_new(x_q.string(desktop->namedview->doc_units).c_str()); - GString *ys = g_string_new(y_q.string(desktop->namedview->doc_units).c_str()); + GString *xs = g_string_new(x_q.string(desktop->namedview->display_units).c_str()); + GString *ys = g_string_new(y_q.string(desktop->namedview->display_units).c_str()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s × %s"), xs->str, ys->str); g_string_free(xs, FALSE); @@ -627,7 +627,7 @@ bool TextTool::root_handler(GdkEvent* event) { if (this->creating && this->within_tolerance) { /* Button 1, set X & Y & new item */ - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); this->pdoc = desktop->dt2doc(p1); this->show = TRUE; this->phase = 1; @@ -660,9 +660,9 @@ bool TextTool::root_handler(GdkEvent* event) { SPItem *ft = create_flowtext_with_internal_frame (desktop, this->p0, p1); /* Set style */ sp_desktop_apply_style_tool(desktop, ft->getRepr(), "/tools/text", true); - sp_desktop_selection(desktop)->set(ft); + desktop->getSelection()->set(ft); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Flowed text is created.")); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Create flowed text")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Create flowed text")); } else { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The frame is <b>too small</b> for the current font size. Flowed text not created.")); } @@ -801,7 +801,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("No-break space")); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Insert no-break space")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Insert no-break space")); return TRUE; } break; @@ -837,7 +837,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_repr_css_set_property(css, "font-weight", "normal"); sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); sp_repr_css_attr_unref(css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Make bold")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Make bold")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -854,7 +854,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_repr_css_set_property(css, "font-style", "italic"); sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); sp_repr_css_attr_unref(css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Make italic")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Make italic")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -892,7 +892,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("New line")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("New line")); return TRUE; } case GDK_KEY_BackSpace: @@ -933,7 +933,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Backspace")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Backspace")); } return TRUE; case GDK_KEY_Delete: @@ -971,7 +971,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Delete")); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Delete")); } return TRUE; case GDK_KEY_Left: @@ -987,7 +987,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(mul*-1, 0)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:left", SP_VERB_CONTEXT_TEXT, _("Kern to the left")); + DocumentUndo::maybeDone(desktop->getDocument(), "kern:left", SP_VERB_CONTEXT_TEXT, _("Kern to the left")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorLeftWithControl(); @@ -1011,7 +1011,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(mul*1, 0)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:right", SP_VERB_CONTEXT_TEXT, _("Kern to the right")); + DocumentUndo::maybeDone(desktop->getDocument(), "kern:right", SP_VERB_CONTEXT_TEXT, _("Kern to the right")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorRightWithControl(); @@ -1035,7 +1035,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(0, mul*-1)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:up", SP_VERB_CONTEXT_TEXT, _("Kern up")); + DocumentUndo::maybeDone(desktop->getDocument(), "kern:up", SP_VERB_CONTEXT_TEXT, _("Kern up")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorUpWithControl(); @@ -1059,7 +1059,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(0, mul*1)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:down", SP_VERB_CONTEXT_TEXT, _("Kern down")); + DocumentUndo::maybeDone(desktop->getDocument(), "kern:down", SP_VERB_CONTEXT_TEXT, _("Kern down")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorDownWithControl(); @@ -1117,7 +1117,7 @@ bool TextTool::root_handler(GdkEvent* event) { } Inkscape::Rubberband::get(desktop)->stop(); } else { - sp_desktop_selection(desktop)->clear(); + desktop->getSelection()->clear(); } this->nascent_object = FALSE; return TRUE; @@ -1134,7 +1134,7 @@ bool TextTool::root_handler(GdkEvent* event) { } else { sp_te_adjust_rotation(this->text, this->text_sel_start, this->text_sel_end, desktop, -90); } - DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:ccw", SP_VERB_CONTEXT_TEXT, _("Rotate counterclockwise")); + DocumentUndo::maybeDone(desktop->getDocument(), "textrot:ccw", SP_VERB_CONTEXT_TEXT, _("Rotate counterclockwise")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -1154,7 +1154,7 @@ bool TextTool::root_handler(GdkEvent* event) { } else { sp_te_adjust_rotation(this->text, this->text_sel_start, this->text_sel_end, desktop, 90); } - DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:cw", SP_VERB_CONTEXT_TEXT, _("Rotate clockwise")); + DocumentUndo::maybeDone(desktop->getDocument(), "textrot:cw", SP_VERB_CONTEXT_TEXT, _("Rotate clockwise")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -1170,13 +1170,13 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -10); else sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract line spacing")); + DocumentUndo::maybeDone(desktop->getDocument(), "linespacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract line spacing")); } else { if (MOD__SHIFT(event)) sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -10); else sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract letter spacing")); + DocumentUndo::maybeDone(desktop->getDocument(), "letterspacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract letter spacing")); } sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); @@ -1193,13 +1193,13 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 10); else sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand line spacing")); + DocumentUndo::maybeDone(desktop->getDocument(), "linespacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand line spacing")); } else { if (MOD__SHIFT(event)) sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 10); else sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand letter spacing"));\ + DocumentUndo::maybeDone(desktop->getDocument(), "letterspacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand letter spacing"));\ } sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); @@ -1328,7 +1328,7 @@ bool sp_text_paste_inline(ToolBase *ec) tc->text_sel_start = tc->text_sel_end = sp_te_insert_line(tc->text, tc->text_sel_start); begin = end + 1; } - DocumentUndo::done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(ec->desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Paste text")); return true; @@ -1451,7 +1451,7 @@ bool TextTool::_styleSet(SPCSSAttr const *css) return false; // will get picked up by the parent and applied to the whole text object sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); - DocumentUndo::done(sp_desktop_document(this->desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Set text style")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); @@ -1614,7 +1614,7 @@ static void sp_text_context_update_text_selection(TextTool *tc) quads = sp_te_create_selection_quads(tc->text, tc->text_sel_start, tc->text_sel_end, (tc->text)->i2dt_affine()); for (unsigned i = 0 ; i < quads.size() ; i += 4) { SPCanvasItem *quad_canvasitem; - quad_canvasitem = sp_canvas_item_new(sp_desktop_controls(tc->desktop), SP_TYPE_CTRLQUADR, NULL); + quad_canvasitem = sp_canvas_item_new(tc->desktop->getControls(), SP_TYPE_CTRLQUADR, NULL); // FIXME: make the color settable in prefs // for now, use semitrasparent blue, as cairo cannot do inversion :( sp_ctrlquadr_set_rgba32(SP_CTRLQUADR(quad_canvasitem), 0x00777777); @@ -1661,7 +1661,7 @@ static void sp_text_context_forget_text(TextTool *tc) // the XML editor if ( text_repr && text_repr->parent() ) { sp_repr_unparent(text_repr); - SPDocumentUndo::done(sp_desktop_document(tc->desktop), SP_VERB_CONTEXT_TEXT, + SPDocumentUndo::done(tc->desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove empty text")); } } diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 37ca5eeea..a07f2fb86 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -39,7 +39,7 @@ #include "xml/node-event-vector.h" #include "sp-cursor.h" #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-events.h" #include "desktop-style.h" #include "sp-namedview.h" @@ -149,7 +149,7 @@ ToolBase::~ToolBase() { */ void ToolBase::sp_event_context_set_cursor(GdkCursorType cursor_type) { - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + GtkWidget *w = GTK_WIDGET(this->desktop->getCanvas()); GdkDisplay *display = gdk_display_get_default(); GdkCursor *cursor = gdk_cursor_new_for_display(display, cursor_type); @@ -169,7 +169,7 @@ void ToolBase::sp_event_context_set_cursor(GdkCursorType cursor_type) { * Recreates and draws cursor on desktop related to ToolBase. */ void ToolBase::sp_event_context_update_cursor() { - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + GtkWidget *w = GTK_WIDGET(this->desktop->getCanvas()); if (gtk_widget_get_window (w)) { GtkStyle *style = gtk_widget_get_style(w); @@ -530,7 +530,7 @@ bool ToolBase::root_handler(GdkEvent* event) { if (panning_cursor == 1) { panning_cursor = 0; - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + GtkWidget *w = GTK_WIDGET(this->desktop->getCanvas()); gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); } @@ -641,7 +641,7 @@ bool ToolBase::root_handler(GdkEvent* event) { case GDK_KEY_KP_4: if (MOD__CTRL_ONLY(event)) { int i = (int) floor(key_scroll * accelerate_scroll(event, - acceleration, sp_desktop_canvas(desktop))); + acceleration, desktop->getCanvas())); gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); this->desktop->scroll_world(i, 0); @@ -654,7 +654,7 @@ bool ToolBase::root_handler(GdkEvent* event) { case GDK_KEY_KP_8: if (MOD__CTRL_ONLY(event)) { int i = (int) floor(key_scroll * accelerate_scroll(event, - acceleration, sp_desktop_canvas(desktop))); + acceleration, desktop->getCanvas())); gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); this->desktop->scroll_world(0, i); @@ -667,7 +667,7 @@ bool ToolBase::root_handler(GdkEvent* event) { case GDK_KEY_KP_6: if (MOD__CTRL_ONLY(event)) { int i = (int) floor(key_scroll * accelerate_scroll(event, - acceleration, sp_desktop_canvas(desktop))); + acceleration, desktop->getCanvas())); gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); this->desktop->scroll_world(-i, 0); @@ -680,7 +680,7 @@ bool ToolBase::root_handler(GdkEvent* event) { case GDK_KEY_KP_2: if (MOD__CTRL_ONLY(event)) { int i = (int) floor(key_scroll * accelerate_scroll(event, - acceleration, sp_desktop_canvas(desktop))); + acceleration, desktop->getCanvas())); gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); this->desktop->scroll_world(0, -i); @@ -740,7 +740,7 @@ bool ToolBase::root_handler(GdkEvent* event) { if (panning_cursor == 1) { panning_cursor = 0; - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + GtkWidget *w = GTK_WIDGET(this->desktop->getCanvas()); gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); } @@ -1083,7 +1083,7 @@ void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event) /* fixme: This is not what I want but works for now (Lauris) */ if (event->type == GDK_KEY_PRESS) { - item = sp_desktop_selection(desktop)->singleItem(); + item = desktop->getSelection()->singleItem(); } ContextMenu* CM = new ContextMenu(desktop, item); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index f56975de2..5e53fdb93 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -28,7 +28,7 @@ #include "selection.h" #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "message-context.h" #include "pixmaps/cursor-tweak-move.xpm" @@ -274,7 +274,7 @@ void TweakTool::setup() { SPCurve *c = new SPCurve(path); - this->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); + this->dilate_area = sp_canvas_bpath_new(this->desktop->getControls(), c); c->unref(); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->dilate_area), 0x00000000,(SPWindRule)0); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); @@ -1032,7 +1032,7 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point, static bool sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point vector, bool reverse) { - Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop); + Inkscape::Selection *selection = tc->desktop->getSelection(); SPDesktop *desktop = SP_EVENT_CONTEXT(tc)->desktop; if (selection->isEmpty()) { @@ -1235,55 +1235,55 @@ bool TweakTool::root_handler(GdkEvent* event) { this->has_dilated = false; switch (this->mode) { case TWEAK_MODE_MOVE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Move tweak")); break; case TWEAK_MODE_MOVE_IN_OUT: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Move in/out tweak")); break; case TWEAK_MODE_MOVE_JITTER: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Move jitter tweak")); break; case TWEAK_MODE_SCALE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Scale tweak")); break; case TWEAK_MODE_ROTATE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Rotate tweak")); break; case TWEAK_MODE_MORELESS: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Duplicate/delete tweak")); break; case TWEAK_MODE_PUSH: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Push path tweak")); break; case TWEAK_MODE_SHRINK_GROW: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Shrink/grow path tweak")); break; case TWEAK_MODE_ATTRACT_REPEL: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Attract/repel path tweak")); break; case TWEAK_MODE_ROUGHEN: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Roughen path tweak")); break; case TWEAK_MODE_COLORPAINT: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Color paint tweak")); break; case TWEAK_MODE_COLORJITTER: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Color jitter tweak")); break; case TWEAK_MODE_BLUR: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), + DocumentUndo::done(this->desktop->getDocument(), SP_VERB_CONTEXT_TWEAK, _("Blur tweak")); break; } diff --git a/src/ui/view/view.cpp b/src/ui/view/view.cpp index 72548e213..47e2a1e0d 100644 --- a/src/ui/view/view.cpp +++ b/src/ui/view/view.cpp @@ -20,7 +20,7 @@ #include "message-stack.h" #include "message-context.h" #include "verbs.h" -#include "inkscape-private.h" +#include "inkscape.h" namespace Inkscape { namespace UI { @@ -85,7 +85,7 @@ void View::_close() { if (_doc) { _document_uri_set_connection.disconnect(); _document_resized_connection.disconnect(); - if (inkscape_remove_document(_doc)) { + if (INKSCAPE.remove_document(_doc)) { // this was the last view of this document, so delete it delete _doc; } @@ -111,13 +111,13 @@ void View::setDocument(SPDocument *doc) { if (_doc) { _document_uri_set_connection.disconnect(); _document_resized_connection.disconnect(); - if (inkscape_remove_document(_doc)) { + if (INKSCAPE.remove_document(_doc)) { // this was the last view of this document, so delete it delete _doc; } } - inkscape_add_document(doc); + INKSCAPE.add_document(doc); _doc = doc; _document_uri_set_connection = diff --git a/src/ui/widget/color-picker.cpp b/src/ui/widget/color-picker.cpp index 6b5a351f6..d4c4d394e 100644 --- a/src/ui/widget/color-picker.cpp +++ b/src/ui/widget/color-picker.cpp @@ -12,7 +12,7 @@ #include "color-picker.h" #include "inkscape.h" -#include "desktop-handles.h" +#include "desktop.h" #include "document.h" #include "document-undo.h" #include "ui/dialog-events.h" @@ -128,7 +128,7 @@ void sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp) (ptr->_preview).setRgba32 (rgba); if (ptr->_undo && SP_ACTIVE_DESKTOP) - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_NONE, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_NONE, /* TODO: annotate */ "color-picker.cpp:130"); ptr->on_changed (rgba); diff --git a/src/ui/widget/dock.cpp b/src/ui/widget/dock.cpp index 52e9ea605..c5e14d4f0 100644 --- a/src/ui/widget/dock.cpp +++ b/src/ui/widget/dock.cpp @@ -119,8 +119,9 @@ Dock::Dock(Gtk::Orientation orientation) gdl_dock_bar_set_style(_gdl_dock_bar, gdl_dock_bar_style); - g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(hideCallback), (void *)this); - g_signal_connect(G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(unhideCallback), (void *)this); + + INKSCAPE.signal_dialogs_hide.connect(sigc::mem_fun(*this, &Dock::hide)); + INKSCAPE.signal_dialogs_unhide.connect(sigc::mem_fun(*this, &Dock::show)); g_signal_connect(_paned->gobj(), "button-press-event", G_CALLBACK(_on_paned_button_event), (void *)this); g_signal_connect(_paned->gobj(), "button-release-event", G_CALLBACK(_on_paned_button_event), (void *)this); diff --git a/src/ui/widget/filter-effect-chooser.cpp b/src/ui/widget/filter-effect-chooser.cpp index 4754b9c23..242a99073 100644 --- a/src/ui/widget/filter-effect-chooser.cpp +++ b/src/ui/widget/filter-effect-chooser.cpp @@ -13,7 +13,7 @@ #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "inkscape.h" diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index 22abd04ba..df261b69a 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -88,8 +88,9 @@ ImageIcon::~ImageIcon() */ void ImageIcon::init() { - if (!INKSCAPE) - inkscape_application_init("",false); + // \FIXME Why? + if (!Inkscape::Application::exists()) + Inkscape::Application::create("", false); document = NULL; viewerGtkmm = NULL; //set_size_request(150,150); diff --git a/src/ui/widget/layer-selector.cpp b/src/ui/widget/layer-selector.cpp index 7b1a8dbfb..dc89d233f 100644 --- a/src/ui/widget/layer-selector.cpp +++ b/src/ui/widget/layer-selector.cpp @@ -21,7 +21,7 @@ #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-handles.h" + #include "document.h" #include "document-undo.h" #include "layer-manager.h" @@ -601,7 +601,7 @@ void LayerSelector::_prepareLabelRenderer( void LayerSelector::_lockLayer(bool lock) { if ( _layer && SP_IS_ITEM(_layer) ) { SP_ITEM(_layer)->setLocked(lock); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_NONE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_NONE, lock? _("Lock layer") : _("Unlock layer")); } } @@ -609,7 +609,7 @@ void LayerSelector::_lockLayer(bool lock) { void LayerSelector::_hideLayer(bool hide) { if ( _layer && SP_IS_ITEM(_layer) ) { SP_ITEM(_layer)->setHidden(hide); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_NONE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_NONE, hide? _("Hide layer") : _("Unhide layer")); } } diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index e4cd76345..00a74c4fe 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -17,7 +17,7 @@ #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "document.h" #include "document-undo.h" @@ -39,26 +39,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/*void ObjectCompositeSettings::_on_desktop_activate( - InkscapeApplication *application, - SPDesktop *desktop, - ObjectCompositeSettings *w -) { - if (w->_subject) { - w->_subject->setDesktop(desktop); - } -} - -void ObjectCompositeSettings::_on_desktop_deactivate( - InkscapeApplication *application, - SPDesktop *desktop, - ObjectCompositeSettings *w -) { - if (w->_subject) { - w->_subject->setDesktop(NULL); - } -}*/ - ObjectCompositeSettings::ObjectCompositeSettings(unsigned int verb_code, char const *history_prefix, int flags) : _verb_code(verb_code), _blur_tag(Glib::ustring(history_prefix) + ":blur"), @@ -102,7 +82,6 @@ ObjectCompositeSettings::ObjectCompositeSettings(unsigned int verb_code, char co ObjectCompositeSettings::~ObjectCompositeSettings() { setSubject(NULL); - g_signal_handler_disconnect(G_OBJECT(INKSCAPE), _desktop_activated); } void ObjectCompositeSettings::setSubject(StyleSubject *subject) { @@ -125,14 +104,14 @@ ObjectCompositeSettings::_blendBlurValueChanged() if (!desktop) { return; } - SPDocument *document = sp_desktop_document (desktop); + SPDocument *document = desktop->getDocument(); if (_blocked) return; _blocked = true; // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in crash 1580903 - //sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); + //sp_canvas_force_full_redraw_after_interruptions(desktop->getCanvas(), 0); Geom::OptRect bbox = _subject->getBounds(SPItem::GEOMETRIC_BBOX); double radius; @@ -180,7 +159,7 @@ ObjectCompositeSettings::_blendBlurValueChanged() _("Change blur")); // resume interruptibility - //sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop)); + //sp_canvas_end_forced_full_redraws(desktop->getCanvas()); _blocked = false; } @@ -204,7 +183,7 @@ ObjectCompositeSettings::_opacityValueChanged() // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in crash 1580903 // UPDATE: crash fixed in GTK+ 2.10.7 (bug 374378), remove this as soon as it's reasonably common // (though this only fixes the crash, not the multiple change events) - //sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); + //sp_canvas_force_full_redraw_after_interruptions(desktop->getCanvas(), 0); SPCSSAttr *css = sp_repr_css_attr_new (); @@ -216,11 +195,11 @@ ObjectCompositeSettings::_opacityValueChanged() sp_repr_css_attr_unref (css); - DocumentUndo::maybeDone(sp_desktop_document (desktop), _opacity_tag.c_str(), _verb_code, + DocumentUndo::maybeDone(desktop->getDocument(), _opacity_tag.c_str(), _verb_code, _("Change opacity")); // resume interruptibility - //sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop)); + //sp_canvas_end_forced_full_redraws(desktop->getCanvas()); _blocked = false; } @@ -240,8 +219,8 @@ ObjectCompositeSettings::_subjectChanged() { return; _blocked = true; - SPStyle *query = sp_style_new (sp_desktop_document(desktop)); - int result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_MASTEROPACITY); + SPStyle query(desktop->getDocument()); + int result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_MASTEROPACITY); switch (result) { case QUERY_STYLE_NOTHING: @@ -252,19 +231,19 @@ ObjectCompositeSettings::_subjectChanged() { case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently case QUERY_STYLE_MULTIPLE_SAME: _opacity_vbox.set_sensitive(true); - _opacity_scale.get_adjustment()->set_value(100 * SP_SCALE24_TO_FLOAT(query->opacity.value)); + _opacity_scale.get_adjustment()->set_value(100 * SP_SCALE24_TO_FLOAT(query.opacity.value)); break; } //query now for current filter mode and average blurring of selection - const int blend_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLEND); + const int blend_result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_BLEND); switch(blend_result) { case QUERY_STYLE_NOTHING: _fe_cb.set_sensitive(false); break; case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_SAME: - _fe_cb.set_blend_mode(query->filter_blend_mode.value); + _fe_cb.set_blend_mode(query.filter_blend_mode.value); _fe_cb.set_sensitive(true); break; case QUERY_STYLE_MULTIPLE_DIFFERENT: @@ -274,7 +253,7 @@ ObjectCompositeSettings::_subjectChanged() { } if(blend_result == QUERY_STYLE_SINGLE || blend_result == QUERY_STYLE_MULTIPLE_SAME) { - int blur_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLUR); + int blur_result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_BLUR); switch (blur_result) { case QUERY_STYLE_NOTHING: //no blurring _fe_cb.set_blur_sensitive(false); @@ -287,7 +266,7 @@ ObjectCompositeSettings::_subjectChanged() { double perimeter = bbox->dimensions()[Geom::X] + bbox->dimensions()[Geom::Y]; // fixme: this is only half the perimeter, is that correct? _fe_cb.set_blur_sensitive(true); //update blur widget value - float radius = query->filter_gaussianBlur_deviation.value; + float radius = query.filter_gaussianBlur_deviation.value; float percent = radius * 400 / perimeter; // so that for a square, 100% == half side _fe_cb.set_blur_value(percent); } @@ -295,8 +274,6 @@ ObjectCompositeSettings::_subjectChanged() { } } - sp_style_unref(query); - _blocked = false; } diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h index e375bf24a..5a723a2fd 100644 --- a/src/ui/widget/object-composite-settings.h +++ b/src/ui/widget/object-composite-settings.h @@ -66,8 +66,8 @@ private: gulong _desktop_activated; sigc::connection _subject_changed; - static void _on_desktop_activate(InkscapeApplication *application, SPDesktop *desktop, ObjectCompositeSettings *w); - static void _on_desktop_deactivate(InkscapeApplication *application, SPDesktop *desktop, ObjectCompositeSettings *w); + static void _on_desktop_activate(SPDesktop *desktop, ObjectCompositeSettings *w); + static void _on_desktop_deactivate(SPDesktop *desktop, ObjectCompositeSettings *w); void _subjectChanged(); void _blendBlurValueChanged(); void _opacityValueChanged(); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 32e357c57..d36c11ace 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -32,7 +32,7 @@ #include <2geom/transforms.h> -#include "desktop-handles.h" + #include "document.h" #include "desktop.h" #include "helper/action.h" @@ -309,12 +309,12 @@ PageSizer::PageSizer(Registry & _wr) // Setting default custom unit to document unit SPDesktop *dt = SP_ACTIVE_DESKTOP; - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); _wr.setUpdating (true); if (nv->page_size_units) { _dimensionUnits.setUnit(nv->page_size_units->abbr); - } else if (nv->doc_units) { - _dimensionUnits.setUnit(nv->doc_units->abbr); + } else if (nv->display_units) { + _dimensionUnits.setUnit(nv->display_units->abbr); } _wr.setUpdating (false); @@ -459,7 +459,7 @@ PageSizer::init () * \param changeList whether to modify the paper size list */ void -PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList) +PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList, bool changeSize) { static bool _called = false; if (_called) { @@ -477,14 +477,16 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool _unit = w.unit->abbr; if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) { - SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP); + SPDocument *doc = SP_ACTIVE_DESKTOP->getDocument(); Inkscape::Util::Quantity const old_height = doc->getHeight(); - doc->setWidth (w); - doc->setHeight (h); + doc->setWidth (w, changeSize); + doc->setHeight (h, changeSize); // The origin for the user is in the lower left corner; this point should remain stationary when // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this - Geom::Translate const vert_offset(Geom::Point(0, (old_height.value("px") - h.value("px")))); - doc->getRoot()->translateChildItems(vert_offset); + if (changeSize) { + Geom::Translate const vert_offset(Geom::Point(0, (old_height.value("px") - h.value("px")))); + doc->getRoot()->translateChildItems(vert_offset); + } DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size")); } @@ -606,7 +608,7 @@ PageSizer::fire_fit_canvas_to_selection_or_drawing() SPNamedView *nv; Inkscape::XML::Node *nv_repr; - if ((doc = sp_desktop_document(SP_ACTIVE_DESKTOP)) + if ((doc = SP_ACTIVE_DESKTOP->getDocument()) && (nv = sp_document_namedview(doc, 0)) && (nv_repr = nv->getRepr())) { _lockMarginUpdate = true; @@ -717,7 +719,8 @@ PageSizer::on_units_changed() if (_widgetRegistry->isUpdating()) return; _unit = _dimensionUnits.getUnit()->abbr; setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), - Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); + Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()), + true, false); } } // namespace Widget diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index f4bcae4b6..bed117e5a 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -161,7 +161,7 @@ public: * Set the page size to the given dimensions. If 'changeList' is * true, then reset the paper size list to the closest match */ - void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true); + void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true, bool changeSize=true); /** * Updates the scalar widgets for the fit margins. (Just changes the value diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index 0abd81b16..0cff25d88 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -33,7 +33,8 @@ #include "panel.h" #include "icon-size.h" #include "preferences.h" -#include "desktop-handles.h" +#include "desktop.h" + #include "inkscape.h" #include "widgets/eek-preview.h" #include "ui/previewfillable.h" @@ -293,7 +294,7 @@ void Panel::_init() signalResponse().connect(sigc::mem_fun(*this, &Panel::_handleResponse)); - signalActivateDesktop().connect(sigc::hide<0>(sigc::mem_fun(*this, &Panel::setDesktop))); + signalActivateDesktop().connect(sigc::mem_fun(*this, &Panel::setDesktop)); show_all_children(); @@ -643,13 +644,13 @@ Panel::signalDocumentReplaced() return _signal_document_replaced; } -sigc::signal<void, InkscapeApplication *, SPDesktop *> & +sigc::signal<void, SPDesktop *> & Panel::signalActivateDesktop() { return _signal_activate_desktop; } -sigc::signal<void, InkscapeApplication *, SPDesktop *> & +sigc::signal<void, SPDesktop *> & Panel::signalDeactiveDesktop() { return _signal_deactive_desktop; @@ -667,7 +668,7 @@ void Panel::_handleResponse(int response_id) Inkscape::Selection *Panel::_getSelection() { - return sp_desktop_selection(_desktop); + return _desktop->getSelection(); } } // namespace Widget diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index 177314797..5680cac30 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -48,6 +48,7 @@ namespace Gtk { struct InkscapeApplication; namespace Inkscape { + class Selection; namespace UI { @@ -116,8 +117,8 @@ public: void setResponseSensitive(int response_id, bool setting); virtual sigc::signal<void, SPDesktop *, SPDocument *> &signalDocumentReplaced(); - virtual sigc::signal<void, InkscapeApplication *, SPDesktop *> &signalActivateDesktop(); - virtual sigc::signal<void, InkscapeApplication *, SPDesktop *> &signalDeactiveDesktop(); + virtual sigc::signal<void, SPDesktop *> &signalActivateDesktop(); + virtual sigc::signal<void, SPDesktop *> &signalDeactiveDesktop(); protected: /** @@ -147,8 +148,8 @@ protected: sigc::signal<void, int> _signal_response; sigc::signal<void> _signal_present; sigc::signal<void, SPDesktop *, SPDocument *> _signal_document_replaced; - sigc::signal<void, InkscapeApplication *, SPDesktop *> _signal_activate_desktop; - sigc::signal<void, InkscapeApplication *, SPDesktop *> _signal_deactive_desktop; + sigc::signal<void, SPDesktop *> _signal_activate_desktop; + sigc::signal<void, SPDesktop *> _signal_deactive_desktop; private: void _init(); diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 7f3e6cd47..98028ed78 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -34,7 +34,7 @@ #include "desktop.h" #include "enums.h" #include "inkscape.h" -#include "desktop-handles.h" + #include "message-stack.h" #include "style.h" #include "selection.h" diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index e97285de4..bbf542987 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -36,6 +36,11 @@ // for interruptability bug: #include "display/sp-canvas.h" +#include "desktop.h" + + +#include "sp-root.h" + namespace Inkscape { namespace UI { namespace Widget { @@ -203,7 +208,7 @@ RegisteredScalarUnit::~RegisteredScalarUnit() _value_changed_connection.disconnect(); } -RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) +RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in, RSU_UserUnits user_units) : RegisteredWidget<ScalarUnit>(label, tip, UNIT_TYPE_LINEAR, "", "", rum.getUnitMenu()), _um(0) { @@ -215,6 +220,7 @@ RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Gl setUnit (rum.getUnitMenu()->getUnitAbbr()); setDigits (2); _um = rum.getUnitMenu(); + _user_units = user_units; _value_changed_connection = signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed)); } @@ -233,12 +239,28 @@ RegisteredScalarUnit::on_value_changed() _wr->setUpdating (true); Inkscape::SVGOStringStream os; - os << getValue(""); - if (_um) - os << _um->getUnitAbbr(); + if (_user_units != RSU_none) { + // Output length in 'user units', taking into account scale in 'x' or 'y'. + double scale = 1.0; + if (doc) { + SPRoot *root = doc->getRoot(); + if (root->viewBox_set) { + if (_user_units == RSU_x) { + scale = root->viewBox.width() / root->width.computed; + } else { + scale = root->viewBox.height() / root->height.computed; + } + } + } + os << getValue("px") * scale; + } else { + // Output using unit identifiers. + os << getValue(""); + if (_um) + os << _um->getUnitAbbr(); + } write_to_xml(os.str().c_str()); - _wr->setUpdating (false); } @@ -397,8 +419,8 @@ RegisteredColorPicker::on_changed (guint32 rgba) SPDesktop *dt = SP_ACTIVE_DESKTOP; if (!dt) return; - local_repr = sp_desktop_namedview(dt)->getRepr(); - local_doc = sp_desktop_document(dt); + local_repr = dt->getNamedView()->getRepr(); + local_doc = dt->getDocument(); } gchar c[32]; diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 1f505a3cd..9d2489712 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -27,7 +27,7 @@ #include "document.h" #include "document-undo.h" -#include "desktop-handles.h" +#include "desktop.h" #include "sp-namedview.h" #include <gtkmm/checkbutton.h> @@ -99,8 +99,8 @@ protected: if (!local_repr) { // no repr specified, use active desktop's namedview's repr SPDesktop* dt = SP_ACTIVE_DESKTOP; - local_repr = reinterpret_cast<SPObject *>(sp_desktop_namedview(dt))->getRepr(); - local_doc = sp_desktop_document(dt); + local_repr = reinterpret_cast<SPObject *>(dt->getNamedView())->getRepr(); + local_doc = dt->getDocument(); } bool saved = DocumentUndo::getUndoSensitive(local_doc); @@ -206,6 +206,14 @@ protected: void on_changed(); }; +// Allow RegisteredScalarUnit to output lengths in 'user units' (which may have direction dependent +// scale factors). +enum RSU_UserUnits { + RSU_none, + RSU_x, + RSU_y +}; + class RegisteredScalarUnit : public RegisteredWidget<ScalarUnit> { public: ~RegisteredScalarUnit(); @@ -215,12 +223,14 @@ public: const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in = NULL, - SPDocument *doc_in = NULL ); + SPDocument *doc_in = NULL, + RSU_UserUnits _user_units = RSU_none ); protected: sigc::connection _value_changed_connection; UnitMenu *_um; void on_value_changed(); + RSU_UserUnits _user_units; }; class RegisteredScalar : public RegisteredWidget<Scalar> { diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index d22c59aa4..1fc67dcef 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -20,7 +20,7 @@ #include "ui/widget/color-preview.h" #include "selection.h" -#include "desktop-handles.h" + #include "style.h" #include "desktop-style.h" #include "sp-namedview.h" @@ -480,7 +480,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) _desktop = desktop; g_object_set_data (G_OBJECT(_opacity_sb.gobj()), "dtw", _desktop->canvas); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Selection *selection = desktop->getSelection(); selection_changed_connection = new sigc::connection (selection->connectChanged( sigc::bind ( @@ -498,7 +498,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) this ) )); - _sw_unit = sp_desktop_namedview(desktop)->doc_units; + _sw_unit = desktop->getNamedView()->display_units; // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); @@ -541,8 +541,7 @@ void SelectedStyle::dragDataReceived( GtkWidget */*widget*/, sp_repr_css_set_property( css, (tracker->item == SS_FILL) ? "fill":"stroke", c ); sp_desktop_set_style( tracker->parent->_desktop, css ); sp_repr_css_attr_unref( css ); - DocumentUndo::done( sp_desktop_document(tracker->parent->_desktop) , SP_VERB_NONE, - _("Drop color")); + DocumentUndo::done( tracker->parent->_desktop->getDocument(), SP_VERB_NONE, _("Drop color")); } } break; @@ -554,7 +553,7 @@ void SelectedStyle::on_fill_remove() { sp_repr_css_set_property (css, "fill", "none"); sp_desktop_set_style (_desktop, css, true, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Remove fill")); } @@ -563,7 +562,7 @@ void SelectedStyle::on_stroke_remove() { sp_repr_css_set_property (css, "stroke", "none"); sp_desktop_set_style (_desktop, css, true, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Remove stroke")); } @@ -572,7 +571,7 @@ void SelectedStyle::on_fill_unset() { sp_repr_css_unset_property (css, "fill"); sp_desktop_set_style (_desktop, css, true, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Unset fill")); } @@ -588,7 +587,7 @@ void SelectedStyle::on_stroke_unset() { sp_repr_css_unset_property (css, "stroke-dasharray"); sp_desktop_set_style (_desktop, css, true, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Unset stroke")); } @@ -597,7 +596,7 @@ void SelectedStyle::on_fill_opaque() { sp_repr_css_set_property (css, "fill-opacity", "1"); sp_desktop_set_style (_desktop, css, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Make fill opaque")); } @@ -606,7 +605,7 @@ void SelectedStyle::on_stroke_opaque() { sp_repr_css_set_property (css, "stroke-opacity", "1"); sp_desktop_set_style (_desktop, css, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Make fill opaque")); } @@ -618,7 +617,7 @@ void SelectedStyle::on_fill_lastused() { sp_repr_css_set_property (css, "fill", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Apply last set color to fill")); } @@ -630,7 +629,7 @@ void SelectedStyle::on_stroke_lastused() { sp_repr_css_set_property (css, "stroke", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Apply last set color to stroke")); } @@ -641,7 +640,7 @@ void SelectedStyle::on_fill_lastselected() { sp_repr_css_set_property (css, "fill", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Apply last selected color to fill")); } @@ -652,7 +651,7 @@ void SelectedStyle::on_stroke_lastselected() { sp_repr_css_set_property (css, "stroke", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Apply last selected color to stroke")); } @@ -678,7 +677,7 @@ void SelectedStyle::on_fill_invert() { sp_repr_css_set_property (css, "fill", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Invert fill")); } @@ -702,7 +701,7 @@ void SelectedStyle::on_stroke_invert() { sp_repr_css_set_property (css, "stroke", c); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Invert stroke")); } @@ -714,7 +713,7 @@ void SelectedStyle::on_fill_white() { sp_repr_css_set_property (css, "fill-opacity", "1"); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("White fill")); } @@ -726,7 +725,7 @@ void SelectedStyle::on_stroke_white() { sp_repr_css_set_property (css, "stroke-opacity", "1"); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("White stroke")); } @@ -738,7 +737,7 @@ void SelectedStyle::on_fill_black() { sp_repr_css_set_property (css, "fill-opacity", "1.0"); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Black fill")); } @@ -750,7 +749,7 @@ void SelectedStyle::on_stroke_black() { sp_repr_css_set_property (css, "stroke-opacity", "1.0"); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Black stroke")); } @@ -793,7 +792,7 @@ void SelectedStyle::on_fill_paste() { sp_repr_css_set_property (css, "fill", text.c_str()); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Paste fill")); } } @@ -811,7 +810,7 @@ void SelectedStyle::on_stroke_paste() { sp_repr_css_set_property (css, "stroke", text.c_str()); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Paste stroke")); } } @@ -865,7 +864,7 @@ void SelectedStyle::on_fillstroke_swap() { sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Swap fill and stroke")); } @@ -940,7 +939,7 @@ SelectedStyle::on_opacity_click(GdkEventButton *event) sp_repr_css_set_property (css, "opacity", opacity); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Change opacity")); return true; } @@ -967,7 +966,7 @@ void SelectedStyle::on_popup_preset(int i) { // FIXME: update dash patterns! sp_desktop_set_style (_desktop, css, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_DIALOG_SWATCHES, + DocumentUndo::done(_desktop->getDocument(), SP_VERB_DIALOG_SWATCHES, _("Change stroke width")); } @@ -978,7 +977,7 @@ SelectedStyle::update() return; // create temporary style - SPStyle *query = sp_style_new (sp_desktop_document(_desktop)); + SPStyle query(_desktop->getDocument()); for (int i = SS_FILL; i <= SS_STROKE; i++) { Gtk::EventBox *place = (i == SS_FILL)? &_fill_place : &_stroke_place; @@ -996,7 +995,7 @@ SelectedStyle::update() _popup_copy[i].set_sensitive(false); // query style from desktop. This returns a result flag and fills query with the style of subselection, if any, or selection - int result = sp_desktop_query_style (_desktop, query, + int result = sp_desktop_query_style (_desktop, &query, (i == SS_FILL)? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); switch (result) { case QUERY_STYLE_NOTHING: @@ -1021,12 +1020,12 @@ SelectedStyle::update() } SPIPaint *paint; if (i == SS_FILL) { - paint = &(query->fill); + paint = &(query.fill); } else { - paint = &(query->stroke); + paint = &(query.stroke); } if (paint->set && paint->isPaintserver()) { - SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query); + SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (&query) : SP_STYLE_STROKE_SERVER (&query); if ( server ) { Inkscape::XML::Node *srepr = server->getRepr(); _paintserver_id[i] += "url(#"; @@ -1063,7 +1062,7 @@ SelectedStyle::update() } } else if (paint->set && paint->isColor()) { guint32 color = paint->value.color.toRGBA32( - SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value)); + SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query.fill_opacity.value : query.stroke_opacity.value)); _lastselected[i] = _thisselected[i]; _thisselected[i] = color; // include opacity ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color); @@ -1106,7 +1105,7 @@ SelectedStyle::update() clearTooltip(_opacity_place); clearTooltip(_opacity_sb); - int result = sp_desktop_query_style (_desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY); + int result = sp_desktop_query_style (_desktop, &query, QUERY_STYLE_PROPERTY_MASTEROPACITY); switch (result) { case QUERY_STYLE_NOTHING: @@ -1123,16 +1122,16 @@ SelectedStyle::update() _opacity_blocked = true; _opacity_sb.set_sensitive(true); #if WITH_GTKMM_3_0 - _opacity_adjustment->set_value(SP_SCALE24_TO_FLOAT(query->opacity.value) * 100); + _opacity_adjustment->set_value(SP_SCALE24_TO_FLOAT(query.opacity.value) * 100); #else - _opacity_adjustment.set_value(SP_SCALE24_TO_FLOAT(query->opacity.value) * 100); + _opacity_adjustment.set_value(SP_SCALE24_TO_FLOAT(query.opacity.value) * 100); #endif _opacity_blocked = false; break; } // Now query stroke_width - int result_sw = sp_desktop_query_style (_desktop, query, QUERY_STYLE_PROPERTY_STROKEWIDTH); + int result_sw = sp_desktop_query_style (_desktop, &query, QUERY_STYLE_PROPERTY_STROKEWIDTH); switch (result_sw) { case QUERY_STYLE_NOTHING: _stroke_width.set_markup(""); @@ -1144,9 +1143,9 @@ SelectedStyle::update() { double w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit); + w = Inkscape::Util::Quantity::convert(query.stroke_width.computed, "px", _sw_unit); } else { - w = query->stroke_width.computed; + w = query.stroke_width.computed; } current_stroke_width = w; @@ -1169,8 +1168,6 @@ SelectedStyle::update() default: break; } - - sp_style_unref(query); } void SelectedStyle::opacity_0(void) {_opacity_sb.set_value(0);} @@ -1241,13 +1238,13 @@ void SelectedStyle::on_opacity_changed () // me. As a result, scrolling the spinbutton once results in runaway change until it hits 1.0 // or 0.0. (And no, this is not a race with ::update, I checked that.) // Sigh. So we disable interruptibility while we're setting the new value. - sp_desktop_canvas(_desktop)->forceFullRedrawAfterInterruptions(0); + _desktop->getCanvas()->forceFullRedrawAfterInterruptions(0); sp_desktop_set_style (_desktop, css); sp_repr_css_attr_unref (css); - DocumentUndo::maybeDone(sp_desktop_document(_desktop), "fillstroke:opacity", SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::maybeDone(_desktop->getDocument(), "fillstroke:opacity", SP_VERB_DIALOG_FILL_STROKE, _("Change opacity")); // resume interruptibility - sp_desktop_canvas(_desktop)->endForcedFullRedraws(); + _desktop->getCanvas()->endForcedFullRedraws(); spinbutton_defocus(GTK_WIDGET(_opacity_sb.gobj())); _opacity_blocked = false; } @@ -1385,25 +1382,25 @@ RotateableSwatch::do_motion(double by, guint modifier) { diff = color_adjust(hsla, by, cc, modifier); if (modifier == 3) { // alpha - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust alpha"))); double ch = hsla[3]; parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>alpha</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Shift</b> to adjust saturation, without modifiers to adjust hue"), ch - diff, ch, diff); } else if (modifier == 2) { // saturation - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust saturation"))); double ch = hsla[1]; parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>saturation</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Ctrl</b> to adjust lightness, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff); } else if (modifier == 1) { // lightness - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust lightness"))); double ch = hsla[2]; parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>lightness</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, without modifiers to adjust hue"), ch - diff, ch, diff); } else { // hue - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust hue"))); double ch = hsla[0]; parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>hue</b>: was %.3g, now <b>%.3g</b> (diff %.3g); with <b>Shift</b> to adjust saturation, with <b>Alt</b> to adjust alpha, with <b>Ctrl</b> to adjust lightness"), ch - diff, ch, diff); @@ -1440,18 +1437,18 @@ RotateableSwatch::do_release(double by, guint modifier) { } if (modifier == 3) { // alpha - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, ("Adjust alpha")); } else if (modifier == 2) { // saturation - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, ("Adjust saturation")); } else if (modifier == 1) { // lightness - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, ("Adjust lightness")); } else { // hue - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, ("Adjust hue")); } @@ -1523,7 +1520,7 @@ RotateableStrokeWidth::do_motion(double by, guint modifier) { if (modifier == 3) { // Alt, do nothing } else { double diff = value_adjust(startvalue, by, modifier, false); - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width"))); parent->getDesktop()->event_context->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>stroke width</b>: was %.3g, now <b>%.3g</b> (diff %.3g)"), startvalue, startvalue + diff, diff); } @@ -1537,7 +1534,7 @@ RotateableStrokeWidth::do_release(double by, guint modifier) { } else { value_adjust(startvalue, by, modifier, true); startvalue_set = false; - DocumentUndo::maybeDone(sp_desktop_document(parent->getDesktop()), undokey, + DocumentUndo::maybeDone(parent->getDesktop()->getDocument(), undokey, SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width"))); } diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index d9bf7e2aa..a48370d9b 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -11,7 +11,7 @@ #include "sp-object.h" #include "xml/sp-css-attr.h" #include "desktop-style.h" -#include "desktop-handles.h" + #include "selection.h" #include "style.h" @@ -49,7 +49,7 @@ StyleSubject::Selection::~Selection() { Inkscape::Selection *StyleSubject::Selection::_getSelection() const { SPDesktop *desktop = getDesktop(); if (desktop) { - return sp_desktop_selection(desktop); + return desktop->getSelection(); } else { return NULL; } @@ -88,7 +88,7 @@ void StyleSubject::Selection::_afterDesktopSwitch(SPDesktop *desktop) { _sel_modified.disconnect(); if (desktop) { _subsel_changed = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &Selection::_emitChanged))); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (selection) { _sel_changed = selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &Selection::_emitChanged))); _sel_modified = selection->connectModified(sigc::hide(sigc::hide(sigc::mem_fun(*this, &Selection::_emitChanged)))); diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 157fd2ad9..fa8543c46 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -260,13 +260,12 @@ void StyleSwatch::setStyle(SPCSSAttr *css) Glib::ustring css_string; sp_repr_css_write_string (_css, css_string); - SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT); + + SPStyle style(SP_ACTIVE_DOCUMENT); if (!css_string.empty()) { - sp_style_merge_from_style_string (temp_spstyle, css_string.c_str()); + style.mergeString(css_string.c_str()); } - - setStyle (temp_spstyle); - sp_style_unref (temp_spstyle); + setStyle (&style); } void StyleSwatch::setStyle(SPStyle *query) diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index aac7451f4..ff525c679 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -28,7 +28,8 @@ #include "inkscape.h" #include "document.h" #include "document-undo.h" -#include "desktop-handles.h" +#include "desktop.h" + #include "sp-namedview.h" #include "registry.h" @@ -195,10 +196,10 @@ void ToleranceSlider::update (double val) _wr->setUpdating (true); - SPDocument *doc = sp_desktop_document(dt); + SPDocument *doc = dt->getDocument(); bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); - Inkscape::XML::Node *repr = sp_desktop_namedview(dt)->getRepr(); + Inkscape::XML::Node *repr = dt->getNamedView()->getRepr(); repr->setAttribute(_key.c_str(), os.str().c_str()); DocumentUndo::setUndoSensitive(doc, saved); diff --git a/src/util/units.cpp b/src/util/units.cpp index 3d635e2d2..2c72ec3ae 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -16,11 +16,14 @@ #include <cmath> #include <cerrno> #include <iomanip> +#include <iostream> #include <glib.h> #include <glibmm/regex.h> #include <glibmm/fileutils.h> #include <glibmm/markup.h> +#include <2geom/coord.h> + #include "util/units.h" #include "path-prefix.h" #include "streq.h" @@ -44,6 +47,7 @@ enum UnitCode { UNIT_CODE_CM = MAKE_UNIT_CODE('c','m'), UNIT_CODE_IN = MAKE_UNIT_CODE('i','n'), UNIT_CODE_FT = MAKE_UNIT_CODE('f','t'), + UNIT_CODE_MT = MAKE_UNIT_CODE('m',' '), UNIT_CODE_EM = MAKE_UNIT_CODE('e','m'), UNIT_CODE_EX = MAKE_UNIT_CODE('e','x'), UNIT_CODE_PERCENT = MAKE_UNIT_CODE('%',0) @@ -71,6 +75,7 @@ unsigned const svg_length_lookup[] = { UNIT_CODE_CM, UNIT_CODE_IN, UNIT_CODE_FT, + UNIT_CODE_MT, UNIT_CODE_EM, UNIT_CODE_EX, UNIT_CODE_PERCENT @@ -279,6 +284,28 @@ Unit const *UnitTable::getUnit(SVGLength::Unit u) const return &_empty_unit; } +Unit const *UnitTable::findUnit(double factor, UnitType type) const +{ + const double eps = factor * 0.01; // allow for 1% deviation + + UnitCodeMap::const_iterator cit = _unit_map.begin(); + while (cit != _unit_map.end()) { + if (cit->second->type == type) { + if (Geom::are_near(cit->second->factor, factor, eps)) { + // unit found! + break; + } + } + ++cit; + } + + if (cit != _unit_map.end()) { + return cit->second; + } else { + return getUnit(_primary_unit[type]); + } +} + Quantity UnitTable::parseQuantity(Glib::ustring const &q) const { Glib::MatchInfo match_info; diff --git a/src/util/units.h b/src/util/units.h index efe1dbec7..13777fd1b 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -141,6 +141,9 @@ public: /** Retrieve a given unit based on its string identifier */ Unit const *getUnit(Glib::ustring const &name) const; Unit const *getUnit(char const *name) const; + + /** Try to find a unit based on its conversion factor to the primary */ + Unit const *findUnit(double factor, UnitType type) const; /** Retrieve a given unit based on its SVGLength unit */ Unit const *getUnit(SVGLength::Unit u) const; diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 13dd03ee3..b62aacbc5 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -16,7 +16,7 @@ #include <glibmm/i18n.h> #include "vanishing-point.h" -#include "desktop-handles.h" + #include "desktop.h" #include "display/sp-canvas-item.h" #include "display/sp-ctrlline.h" @@ -94,7 +94,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g Geom::Point p = ppointer; // FIXME: take from prefs - double snap_dist = SNAP_DIST / inkscape_active_desktop()->current_zoom(); + double snap_dist = SNAP_DIST / SP_ACTIVE_DESKTOP->current_zoom(); /* * We use dragging_started to indicate if we have already checked for the need to split Draggers up. @@ -110,7 +110,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g for (std::set<VanishingPoint*, less_ptr>::iterator vp = sel_vps.begin(); vp != sel_vps.end(); ++vp) { // for each VP that has selected boxes: Persp3D *old_persp = (*vp)->get_perspective(); - sel_boxes = (*vp)->selectedBoxes(sp_desktop_selection(inkscape_active_desktop())); + sel_boxes = (*vp)->selectedBoxes(SP_ACTIVE_DESKTOP->getSelection()); // we create a new perspective ... Persp3D *new_persp = persp3d_create_xml_element (dragger->parent->document, old_persp->perspective_impl); @@ -129,7 +129,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g } // FIXME: Do we need to create a new dragger as well? dragger->updateZOrders (); - DocumentUndo::done(sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, _("Split vanishing points")); return; } @@ -174,7 +174,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g // deleted according to changes in the svg representation, not based on any user input // as is currently the case. - DocumentUndo::done(sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, _("Merge vanishing points")); return; @@ -182,7 +182,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g } // We didn't snap to another dragger, so we'll try a regular snap - SPDesktop *desktop = inkscape_active_desktop(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); @@ -277,7 +277,7 @@ VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) if (vp.is_finite()) { // create the knot - this->knot = new SPKnot(inkscape_active_desktop(), NULL); + this->knot = new SPKnot(SP_ACTIVE_DESKTOP, NULL); this->knot->setMode(SP_KNOT_MODE_XOR); this->knot->setFill(VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL); this->knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); @@ -394,7 +394,7 @@ VPDragger::VPsOfSelectedBoxes() { std::set<VanishingPoint*, less_ptr> sel_vps; VanishingPoint *vp; // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. - Inkscape::Selection *sel = sp_desktop_selection(inkscape_active_desktop()); + Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); for (GSList const* i = sel->itemList(); i != NULL; i = i->next) { SPItem *item = static_cast<SPItem *>(i->data); SPBox3D *box = dynamic_cast<SPBox3D *>(item); @@ -488,7 +488,7 @@ VPDragger::printVPs() { VPDrag::VPDrag (SPDocument *document) { this->document = document; - this->selection = sp_desktop_selection(inkscape_active_desktop()); + this->selection = SP_ACTIVE_DESKTOP->getSelection(); this->draggers = NULL; this->lines = NULL; @@ -635,7 +635,7 @@ VPDrag::updateBoxHandles () return; } - Inkscape::UI::Tools::ToolBase *ec = inkscape_active_event_context(); + Inkscape::UI::Tools::ToolBase *ec = INKSCAPE.active_event_context(); g_assert (ec != NULL); if (ec->shape_editor != NULL) { ec->shape_editor->update_knotholder(); @@ -708,7 +708,7 @@ void VPDrag::drawLinesForFace(const SPBox3D *box, Proj::Axis axis) //, guint cor // draw perspective lines for infinite VPs boost::optional<Geom::Point> pt1, pt2, pt3, pt4; Persp3D *persp = box3d_get_perspective(box); - SPDesktop *desktop = inkscape_active_desktop (); // FIXME: Store the desktop in VPDrag + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: Store the desktop in VPDrag Box3D::PerspectiveLine pl (corner1, axis, persp); pt1 = pl.intersection_with_viewbox(desktop); @@ -782,7 +782,7 @@ VPDrag::swap_perspectives_of_VPs(Persp3D *persp2, Persp3D *persp1) void VPDrag::addLine(Geom::Point const &p1, Geom::Point const &p2, Inkscape::CtrlLineType type) { - SPCtrlLine *line = ControlManager::getManager().createControlLine(sp_desktop_controls(inkscape_active_desktop()), p1, p2, type); + SPCtrlLine *line = ControlManager::getManager().createControlLine(SP_ACTIVE_DESKTOP->getControls(), p1, p2, type); sp_canvas_item_show(line); this->lines = g_slist_append(this->lines, line); } diff --git a/src/verbs.cpp b/src/verbs.cpp index b4743751e..231e258d6 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -41,7 +41,7 @@ #include <gtkmm/stock.h> #include "desktop.h" -#include "desktop-handles.h" + #include "display/curve.h" #include "document.h" #include "ui/tools/freehand-base.h" @@ -52,7 +52,7 @@ #include "helper/action.h" #include "helper/action-context.h" #include "help.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "ui/interface.h" #include "layer-fns.h" #include "layer-manager.h" @@ -906,10 +906,10 @@ void FileVerb::perform(SPAction *action, void *data) // sp_file_export_to_ocal(*parent); // break; case SP_VERB_FILE_NEXT_DESKTOP: - inkscape_switch_desktops_next(); + INKSCAPE.switch_desktops_next(); break; case SP_VERB_FILE_PREV_DESKTOP: - inkscape_switch_desktops_prev(); + INKSCAPE.switch_desktops_prev(); break; case SP_VERB_FILE_CLOSE_VIEW: sp_ui_close_view(NULL); @@ -948,10 +948,10 @@ void EditVerb::perform(SPAction *action, void *data) switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_EDIT_UNDO: - sp_undo(dt, sp_desktop_document(dt)); + sp_undo(dt, dt->getDocument()); break; case SP_VERB_EDIT_REDO: - sp_redo(dt, sp_desktop_document(dt)); + sp_redo(dt, dt->getDocument()); break; case SP_VERB_EDIT_CUT: sp_selection_cut(dt); @@ -1203,11 +1203,11 @@ void SelectionVerb::perform(SPAction *action, void *data) SelectionHelper::reverse(dt); break; case SP_VERB_SELECTION_TRACE: - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); dt->_dlg_mgr->showDialog("Trace"); break; case SP_VERB_SELECTION_PIXEL_ART: - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); dt->_dlg_mgr->showDialog("PixelArt"); break; case SP_VERB_SELECTION_CREATE_BITMAP: @@ -1221,7 +1221,7 @@ void SelectionVerb::perform(SPAction *action, void *data) sp_selected_path_break_apart(dt); break; case SP_VERB_SELECTION_ARRANGE: - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); dt->_dlg_mgr->showDialog("TileDialog"); //FIXME: denis: What's this string (to be changed) break; default: @@ -1256,7 +1256,7 @@ void LayerVerb::perform(SPAction *action, void *data) SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { dt->setCurrentLayer(next); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_NEXT, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_NEXT, _("Switch to next layer")); dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Switched to next layer.")); } else { @@ -1268,7 +1268,7 @@ void LayerVerb::perform(SPAction *action, void *data) SPObject *prev=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (prev) { dt->setCurrentLayer(prev); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_PREV, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_PREV, _("Switch to previous layer")); dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Switched to previous layer.")); } else { @@ -1338,7 +1338,7 @@ void LayerVerb::perform(SPAction *action, void *data) description = _("Lower layer"); break; }; - DocumentUndo::done(sp_desktop_document(dt), verb, description); + DocumentUndo::done(dt->getDocument(), verb, description); if (message) { dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message); g_free((void *) message); @@ -1384,7 +1384,7 @@ void LayerVerb::perform(SPAction *action, void *data) dt->setCurrentLayer(new_layer); } #endif - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DUPLICATE, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_DUPLICATE, _("Duplicate layer")); // TRANSLATORS: this means "The layer has been duplicated." @@ -1396,7 +1396,7 @@ void LayerVerb::perform(SPAction *action, void *data) } case SP_VERB_LAYER_DELETE: { if ( dt->currentLayer() != dt->currentRoot() ) { - sp_desktop_selection(dt)->clear(); + dt->getSelection()->clear(); SPObject *old_layer=dt->currentLayer(); sp_object_ref(old_layer, NULL); @@ -1420,7 +1420,7 @@ void LayerVerb::perform(SPAction *action, void *data) dt->setCurrentLayer(survivor); } - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_DELETE, + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_DELETE, _("Delete layer")); // TRANSLATORS: this means "The layer has been deleted." @@ -1435,23 +1435,23 @@ void LayerVerb::perform(SPAction *action, void *data) dt->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No current layer.")); } else { dt->toggleLayerSolo( dt->currentLayer() ); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_SOLO, _("Toggle layer solo")); + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_SOLO, _("Toggle layer solo")); } break; } case SP_VERB_LAYER_SHOW_ALL: { dt->toggleHideAllLayers( false ); - DocumentUndo::maybeDone(sp_desktop_document(dt), "layer:showall", SP_VERB_LAYER_SHOW_ALL, _("Show all layers")); + DocumentUndo::maybeDone(dt->getDocument(), "layer:showall", SP_VERB_LAYER_SHOW_ALL, _("Show all layers")); break; } case SP_VERB_LAYER_HIDE_ALL: { dt->toggleHideAllLayers( true ); - DocumentUndo::maybeDone(sp_desktop_document(dt), "layer:hideall", SP_VERB_LAYER_HIDE_ALL, _("Hide all layers")); + DocumentUndo::maybeDone(dt->getDocument(), "layer:hideall", SP_VERB_LAYER_HIDE_ALL, _("Hide all layers")); break; } case SP_VERB_LAYER_LOCK_ALL: { dt->toggleLockAllLayers( true ); - DocumentUndo::maybeDone(sp_desktop_document(dt), "layer:lockall", SP_VERB_LAYER_LOCK_ALL, _("Lock all layers")); + DocumentUndo::maybeDone(dt->getDocument(), "layer:lockall", SP_VERB_LAYER_LOCK_ALL, _("Lock all layers")); break; } case SP_VERB_LAYER_LOCK_OTHERS: { @@ -1459,13 +1459,13 @@ void LayerVerb::perform(SPAction *action, void *data) dt->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No current layer.")); } else { dt->toggleLockOtherLayers( dt->currentLayer() ); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_LOCK_OTHERS, _("Lock other layers")); + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_LOCK_OTHERS, _("Lock other layers")); } break; } case SP_VERB_LAYER_UNLOCK_ALL: { dt->toggleLockAllLayers( false ); - DocumentUndo::maybeDone(sp_desktop_document(dt), "layer:unlockall", SP_VERB_LAYER_UNLOCK_ALL, _("Unlock all layers")); + DocumentUndo::maybeDone(dt->getDocument(), "layer:unlockall", SP_VERB_LAYER_UNLOCK_ALL, _("Unlock all layers")); break; } case SP_VERB_LAYER_TOGGLE_LOCK: @@ -1548,12 +1548,12 @@ void ObjectVerb::perform( SPAction *action, void *data) break; case SP_VERB_OBJECT_FLIP_HORIZONTAL: sp_selection_scale_relative(sel, center, Geom::Scale(-1.0, 1.0)); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_HORIZONTAL, + DocumentUndo::done(dt->getDocument(), SP_VERB_OBJECT_FLIP_HORIZONTAL, _("Flip horizontally")); break; case SP_VERB_OBJECT_FLIP_VERTICAL: sp_selection_scale_relative(sel, center, Geom::Scale(1.0, -1.0)); - DocumentUndo::done(sp_desktop_document(dt), SP_VERB_OBJECT_FLIP_VERTICAL, + DocumentUndo::done(dt->getDocument(), SP_VERB_OBJECT_FLIP_VERTICAL, _("Flip vertically")); break; case SP_VERB_OBJECT_SET_MASK: @@ -1592,10 +1592,6 @@ void TagVerb::perform( SPAction *action, void *data) if (!dt) return; - //Inkscape::UI::Tools::ToolBase *ec = dt->event_context; - - Inkscape::Selection *sel = sp_desktop_selection(dt); - Inkscape::XML::Document * doc; Inkscape::XML::Node * repr; gchar *id; @@ -1835,7 +1831,7 @@ void TextVerb::perform(SPAction *action, void */*data*/) g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - SPDocument *doc = sp_desktop_document(dt); + SPDocument *doc = dt->getDocument(); (void)doc; Inkscape::XML::Node *repr = dt->namedview->getRepr(); (void)repr; @@ -1850,7 +1846,7 @@ void ZoomVerb::perform(SPAction *action, void *data) SPDesktop *dt = sp_action_get_desktop(action); Inkscape::UI::Tools::ToolBase *ec = dt->event_context; - SPDocument *doc = sp_desktop_document(dt); + SPDocument *doc = dt->getDocument(); Inkscape::XML::Node *repr = dt->namedview->getRepr(); @@ -1860,7 +1856,7 @@ void ZoomVerb::perform(SPAction *action, void *data) double zcorr = 1.0; Glib::ustring abbr = prefs->getString("/options/zoomcorrection/unit"); - if (dt->namedview->doc_units && dt->namedview->doc_units->abbr == abbr) + if (dt->namedview->display_units && (dt->namedview->display_units->abbr == abbr)) zcorr = prefs->getDouble("/options/zoomcorrection/value", 1.0); Geom::Rect const d = dt->get_display_area(); @@ -2006,7 +2002,7 @@ void ZoomVerb::perform(SPAction *action, void *data) dt->toggleColorProfAdjust(); break; case SP_VERB_VIEW_ICON_PREVIEW: - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); dt->_dlg_mgr->showDialog("IconPreviewPanel"); break; @@ -2025,7 +2021,7 @@ void DialogVerb::perform(SPAction *action, void *data) { if (reinterpret_cast<std::size_t>(data) != SP_VERB_DIALOG_TOGGLE) { // unhide all when opening a new dialog - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); } g_return_if_fail(ensure_desktop_valid(action)); @@ -2088,7 +2084,7 @@ void DialogVerb::perform(SPAction *action, void *data) dt->_dlg_mgr->showDialog("UndoHistory"); break; case SP_VERB_DIALOG_TOGGLE: - inkscape_dialogs_toggle(); + INKSCAPE.dialogs_toggle(); break; case SP_VERB_DIALOG_CLONETILER: //clonetiler_dialog(); @@ -2166,7 +2162,7 @@ void HelpVerb::perform(SPAction *action, void *data) */ case SP_VERB_HELP_MEMORY: - inkscape_dialogs_unhide(); + INKSCAPE.dialogs_unhide(); dt->_dlg_mgr->showDialog("Memory"); break; default: @@ -2330,7 +2326,7 @@ void FitCanvasVerb::perform(SPAction *action, void *data) { g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - SPDocument *doc = sp_desktop_document(dt); + SPDocument *doc = dt->getDocument(); if (!doc) return; switch (reinterpret_cast<std::size_t>(data)) { @@ -2396,7 +2392,7 @@ void LockAndHideVerb::perform(SPAction *action, void *data) { g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - SPDocument *doc = sp_desktop_document(dt); + SPDocument *doc = dt->getDocument(); if (!doc) return; switch (reinterpret_cast<std::size_t>(data)) { diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index ca582924b..8a64854be 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -31,7 +31,7 @@ #include <glibmm/i18n.h> #include "arc-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -81,7 +81,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/shapes/arc/") + value_name, gtk_adjustment_get_value(adj)); } @@ -97,7 +97,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - for (GSList const *items = sp_desktop_selection(desktop)->itemList(); + for (GSList const *items = desktop->getSelection()->itemList(); items != NULL; items = items->next) { @@ -128,7 +128,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v sp_arctb_sensitivize( tbl, gtk_adjustment_get_value(adj), gtk_adjustment_get_value(other) ); if (modmade) { - DocumentUndo::maybeDone(sp_desktop_document(desktop), value_name, SP_VERB_CONTEXT_ARC, + DocumentUndo::maybeDone(desktop->getDocument(), value_name, SP_VERB_CONTEXT_ARC, _("Arc: Change start/end")); } @@ -150,7 +150,7 @@ static void sp_arctb_end_value_changed(GtkAdjustment *adj, GObject *tbl) static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/shapes/arc/open", ege_select_one_action_get_active(act) != 0); } @@ -166,7 +166,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - for (GSList const *items = sp_desktop_selection(desktop)->itemList(); + for (GSList const *items = desktop->getSelection()->itemList(); items != NULL; items = items->next) { @@ -179,7 +179,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - for (GSList const *items = sp_desktop_selection(desktop)->itemList(); + for (GSList const *items = desktop->getSelection()->itemList(); items != NULL; items = items->next) { @@ -194,7 +194,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ARC, _("Arc: Change open/closed")); } @@ -413,8 +413,8 @@ static void arc_toolbox_check_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBa static sigc::connection changed; if (SP_IS_ARC_CONTEXT(ec)) { - changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_arc_toolbox_selection_changed), holder)); - sp_arc_toolbox_selection_changed(sp_desktop_selection(desktop), holder); + changed = desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_arc_toolbox_selection_changed), holder)); + sp_arc_toolbox_selection_changed(desktop->getSelection(), holder); } else { if (changed) changed.disconnect(); diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index 02d102a11..26e914070 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -32,7 +32,7 @@ #include "box3d-toolbar.h" #include "box3d.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "document.h" @@ -195,7 +195,7 @@ static void box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObj sp_repr_synthesize_events(persp_repr, &box3d_persp_tb_repr_events, tbl); } - inkscape_active_document()->setCurrentPersp3D(persp3d_get_from_repr(persp_repr)); + SP_ACTIVE_DOCUMENT->setCurrentPersp3D(persp3d_get_from_repr(persp_repr)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setString("/tools/shapes/3dbox/persp", persp_repr->attribute("id")); @@ -208,7 +208,7 @@ static void box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObj static void box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, Proj::Axis axis) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); // quit if run by the attr_changed or selection changed listener if (g_object_get_data( dataKludge, "freeze" )) { @@ -218,7 +218,7 @@ static void box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, P // in turn, prevent listener from responding g_object_set_data(dataKludge, "freeze", GINT_TO_POINTER(TRUE)); - std::list<Persp3D *> sel_persps = sp_desktop_selection(desktop)->perspList(); + std::list<Persp3D *> sel_persps = desktop->getSelection()->perspList(); if (sel_persps.empty()) { // this can happen when the document is created; we silently ignore it return; @@ -255,7 +255,7 @@ static void box3d_angle_z_value_changed(GtkAdjustment *adj, GObject *dataKludge) static void box3d_vp_state_changed( GtkToggleAction *act, GtkAction * /*box3d_angle*/, Proj::Axis axis ) { // TODO: Take all selected perspectives into account - std::list<Persp3D *> sel_persps = sp_desktop_selection(inkscape_active_desktop())->perspList(); + std::list<Persp3D *> sel_persps = SP_ACTIVE_DESKTOP->getSelection()->perspList(); if (sel_persps.empty()) { // this can happen when the document is created; we silently ignore it return; @@ -287,7 +287,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); EgeAdjustmentAction* eact = 0; - SPDocument *document = sp_desktop_document (desktop); + SPDocument *document = desktop->getDocument(); Persp3DImpl *persp_impl = document->getCurrentPersp3DImpl(); EgeAdjustmentAction* box3d_angle_x = 0; @@ -420,8 +420,8 @@ static void box3d_toolbox_check_ec(SPDesktop* desktop, Inkscape::UI::Tools::Tool { static sigc::connection changed; if (SP_IS_BOX3D_CONTEXT(ec)) { - changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(box3d_toolbox_selection_changed), holder)); - box3d_toolbox_selection_changed(sp_desktop_selection(desktop), holder); + changed = desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(box3d_toolbox_selection_changed), holder)); + box3d_toolbox_selection_changed(desktop->getSelection(), holder); } else { if (changed) changed.disconnect(); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 6ce926dc1..c906f7de4 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -32,7 +32,7 @@ #include "connector-toolbar.h" #include "conn-avoid-ref.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -76,8 +76,8 @@ static void sp_connector_path_set_ignore(void) static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl ) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = sp_desktop_selection(desktop); - SPDocument *doc = sp_desktop_document(desktop); + Inkscape::Selection * selection = desktop->getSelection(); + SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { return; @@ -126,8 +126,8 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = sp_desktop_selection(desktop); - SPDocument *doc = sp_desktop_document(desktop); + Inkscape::Selection * selection = desktop->getSelection(); + SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { return; @@ -176,7 +176,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { return; @@ -233,11 +233,11 @@ static void sp_connector_graph_layout(void) int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); + graphlayout(SP_ACTIVE_DESKTOP->getSelection()->itemList()); prefs->setInt("/options/clonecompensation/value", saved_compensation); - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network")); + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network")); } static void sp_directed_graph_layout_toggled( GtkToggleAction* act, GObject * /*tbl*/ ) @@ -402,7 +402,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), ( tbuttonstate ? TRUE : FALSE )); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_directed_graph_layout_toggled), holder ); - sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_connector_toolbox_selection_changed), holder)); + desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_connector_toolbox_selection_changed), holder)); } // Avoid overlaps toggle button diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp index 479895022..9d591d33d 100644 --- a/src/widgets/dash-selector.cpp +++ b/src/widgets/dash-selector.cpp @@ -118,18 +118,18 @@ void SPDashSelector::init_dashes() { int pos = 0; if (!dash_prefs.empty()) { - SPStyle *style = sp_style_new (NULL); + SPStyle style; dashes = g_new (double *, dash_prefs.size() + 2); // +1 for custom slot, +1 for terminator slot for (std::vector<Glib::ustring>::iterator i = dash_prefs.begin(); i != dash_prefs.end(); ++i) { - sp_style_read_from_prefs(style, *i); + style.readFromPrefs( *i ); - if (!style->stroke_dasharray.values.empty()) { - dashes[pos] = g_new (double, style->stroke_dasharray.values.size() + 1); + if (!style.stroke_dasharray.values.empty()) { + dashes[pos] = g_new (double, style.stroke_dasharray.values.size() + 1); double *d = dashes[pos]; unsigned i = 0; - for (; i < style->stroke_dasharray.values.size(); i++) { - d[i] = style->stroke_dasharray.values[i]; + for (; i < style.stroke_dasharray.values.size(); i++) { + d[i] = style.stroke_dasharray.values[i]; } d[i] = -1; } else { diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 9c8dac7dc..fd3756220 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -32,7 +32,7 @@ #include "conn-avoid-ref.h" #include "desktop.h" #include "desktop-events.h" -#include "desktop-handles.h" + #include "desktop-widget.h" #include "display/sp-canvas.h" #include "display/canvas-arena.h" @@ -45,7 +45,7 @@ #include "helper/action-context.h" #include "util/units.h" #include "ui/widget/unit-tracker.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "ui/interface.h" #include "macros.h" #include "preferences.h" @@ -795,7 +795,7 @@ static void sp_desktop_widget_dispose(GObject *object) dtw->layer_selector->setDesktop(NULL); dtw->layer_selector->unreference(); - inkscape_remove_desktop (dtw->desktop); // clears selection too + INKSCAPE.remove_desktop (dtw->desktop); // clears selection too dtw->modified_connection.disconnect(); dtw->desktop->destroy(); Inkscape::GC::release (dtw->desktop); @@ -1091,7 +1091,7 @@ SPDesktopWidget::shutdown() { g_assert(desktop != NULL); - if (inkscape_is_sole_desktop_for_document(*desktop)) { + if (INKSCAPE.sole_desktop_for_document(*desktop)) { SPDocument *doc = desktop->doc(); if (doc->isModifiedSinceSave()) { GtkWidget *dialog; @@ -1665,14 +1665,14 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast<SPDesktopWidget*>(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = 1. / namedview->doc_units->factor; + dtw->dt2r = 1. / namedview->display_units->factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? dtw->desktop = new SPDesktop(); dtw->stub = new SPDesktopWidget::WidgetStub (dtw); dtw->desktop->init (namedview, dtw->canvas, dtw->stub); - inkscape_add_desktop (dtw->desktop); + INKSCAPE.add_desktop (dtw->desktop); // Add the shape geometry to libavoid for autorouting connectors. // This needs desktop set for its spacing preferences. @@ -1737,11 +1737,11 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = 1. / nv->doc_units->factor; + this->dt2r = 1. / nv->display_units->factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? - sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultUnit()); - sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultUnit()); + sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDisplayUnit()); + sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDisplayUnit()); /* This loops through all the grandchildren of aux toolbox, * and for each that it finds, it performs an sp_search_by_data_recursive(), @@ -1771,14 +1771,14 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) if (tracker == NULL) // it's null when inkscape is first opened continue; - tracker->setActiveUnit( nv->doc_units ); + tracker->setActiveUnit( nv->display_units ); } // grandchildren } // if child is a container } // children } // if aux_toolbox is a container - gtk_widget_set_tooltip_text(this->hruler_box, gettext(nv->doc_units->name_plural.c_str())); - gtk_widget_set_tooltip_text(this->vruler_box, gettext(nv->doc_units->name_plural.c_str())); + gtk_widget_set_tooltip_text(this->hruler_box, gettext(nv->display_units->name_plural.c_str())); + gtk_widget_set_tooltip_text(this->vruler_box, gettext(nv->display_units->name_plural.c_str())); sp_desktop_widget_update_rulers(this); ToolboxFactory::updateSnapToolbox(this->desktop, 0, this->snap_toolbox); @@ -1818,7 +1818,7 @@ bool SPDesktopWidget::onFocusInEvent(GdkEventFocus*) } } - inkscape_activate_desktop (desktop); + INKSCAPE.activate_desktop (desktop); return false; } diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index f547cbd8b..1f79b50f2 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -32,7 +32,7 @@ #include "eraser-toolbar.h" #include "calligraphy-toolbar.h" // TODO: needed for update_presets_list -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -61,7 +61,7 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); bool eraserMode = ege_select_one_action_get_active( act ) != 0; - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool( "/tools/eraser/mode", eraserMode ); } diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index d1d318abe..d60a92b8b 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -35,7 +35,7 @@ #include "desktop.h" #include "selection.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "display/sp-canvas.h" #include "document-private.h" @@ -252,13 +252,13 @@ void FillNStroke::performUpdate() update = true; // create temporary style - SPStyle *query = sp_style_new(desktop->doc()); + SPStyle query(desktop->doc()); // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - int result = sp_desktop_query_style(desktop, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); + int result = sp_desktop_query_style(desktop, &query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); - SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; - SPIScale24 &targOpacity = (kind == FILL) ? query->fill_opacity : query->stroke_opacity; + SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; + SPIScale24 &targOpacity = (kind == FILL) ? query.fill_opacity : query.stroke_opacity; switch (result) { case QUERY_STYLE_NOTHING: @@ -272,11 +272,11 @@ void FillNStroke::performUpdate() case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector case QUERY_STYLE_MULTIPLE_SAME: { - SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(query, kind); psel->setMode(pselmode); if (kind == FILL) { - psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? + psel->setFillrule(query.fill_rule.computed == ART_WIND_RULE_NONZERO? SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD); } @@ -284,7 +284,7 @@ void FillNStroke::performUpdate() psel->setColorAlpha(targPaint.value.color, SP_SCALE24_TO_FLOAT(targOpacity.value)); } else if (targPaint.set && targPaint.isPaintserver()) { - SPPaintServer *server = (kind == FILL) ? query->getFillPaintServer() : query->getStrokePaintServer(); + SPPaintServer *server = (kind == FILL) ? query.getFillPaintServer() : query.getStrokePaintServer(); if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { SPGradient *vector = SP_GRADIENT(server)->getVector(); @@ -318,8 +318,6 @@ void FillNStroke::performUpdate() } } - sp_style_unref(query); - update = false; } @@ -480,8 +478,8 @@ void FillNStroke::updateFromPaint() } update = true; - SPDocument *document = sp_desktop_document(desktop); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPDocument *document = desktop->getDocument(); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); @@ -516,18 +514,18 @@ void FillNStroke::updateFromPaint() { if (kind == FILL) { // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in losing release events - sp_desktop_canvas(desktop)->forceFullRedrawAfterInterruptions(0); + desktop->getCanvas()->forceFullRedrawAfterInterruptions(0); } psel->setFlatColor( desktop, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); - DocumentUndo::maybeDone(sp_desktop_document(desktop), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, + DocumentUndo::maybeDone(desktop->getDocument(), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, (kind == FILL) ? _("Set fill color") : _("Set stroke color")); if (kind == FILL) { // resume interruptibility - sp_desktop_canvas(desktop)->endForcedFullRedraws(); + desktop->getCanvas()->endForcedFullRedraws(); } // on release, toggle undo_label so that the next drag will not be lumped with this one @@ -562,10 +560,10 @@ void FillNStroke::updateFromPaint() if (!vector) { /* No vector in paint selector should mean that we just changed mode */ - SPStyle *query = sp_style_new(desktop->doc()); - int result = objects_query_fillstroke(const_cast<GSList *>(items), query, kind == FILL); + SPStyle query(desktop->doc()); + int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, kind == FILL); if (result == QUERY_STYLE_MULTIPLE_SAME) { - SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; + SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; SPColor common; if (!targPaint.isColor()) { common = sp_desktop_get_color(desktop, kind == FILL); @@ -577,7 +575,6 @@ void FillNStroke::updateFromPaint() vector->setSwatch(); } } - sp_style_unref(query); for (GSList const *i = items; i != NULL; i = i->next) { //FIXME: see above diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index b6378b251..ea009c048 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -18,7 +18,7 @@ #include "ui/widget/color-preview.h" #include <glibmm/i18n.h> -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "document.h" @@ -128,7 +128,7 @@ gboolean gr_vector_list(GtkWidget *combo_box, SPDesktop *desktop, bool selection return sensitive; } - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); GtkTreeIter iter; GtkListStore *store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)); @@ -356,7 +356,7 @@ static void gr_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointe return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); // take from desktop, not from args + Inkscape::Selection *selection = desktop->getSelection(); // take from desktop, not from args if (selection) { ToolBase *ev = desktop->getEventContext(); GrDrag *drag = NULL; @@ -560,7 +560,7 @@ static void gr_add_stop(GtkWidget * /*button*/, GtkWidget *vb) return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); if (!selection) { return; } @@ -582,7 +582,7 @@ static void gr_remove_stop(GtkWidget * /*button*/, GtkWidget *vb) return; } - Inkscape::Selection *selection = sp_desktop_selection(desktop); // take from desktop, not from args + Inkscape::Selection *selection = desktop->getSelection(); // take from desktop, not from args if (!selection) { return; } @@ -918,12 +918,12 @@ static void gr_gradient_combo_changed(EgeSelectOneAction *act, gpointer data) gr = sp_gradient_ensure_vector_normalized(gr); SPDesktop *desktop = static_cast<SPDesktop *>(data); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); ToolBase *ev = desktop->getEventContext(); gr_apply_gradient(selection, ev? ev->get_drag() : NULL, gr); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Assign gradient to object")); } @@ -936,7 +936,7 @@ static void gr_spread_change(EgeSelectOneAction *act, GtkWidget *widget) } SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(G_OBJECT(widget), "desktop")); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); SPGradient *gradient = 0; gr_get_dt_selected_gradient(selection, gradient); @@ -945,7 +945,7 @@ static void gr_spread_change(EgeSelectOneAction *act, GtkWidget *widget) gradient->setSpread(spread); gradient->updateRepr(); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, _("Set gradient repeat")); } } @@ -1246,8 +1246,8 @@ static void gradient_toolbox_check_ec(SPDesktop* desktop, Inkscape::UI::Tools::T static sigc::connection connDefsModified; if (SP_IS_GRADIENT_CONTEXT(ec)) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPDocument *document = sp_desktop_document(desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *document = desktop->getDocument(); // connect to selection modified and changed signals connChanged = selection->connectChanged(sigc::bind(sigc::ptr_fun(&gr_tb_selection_changed), holder)); diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 6607c90d2..d2c46ffec 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -1012,13 +1012,28 @@ GtkWidget * sp_gradient_vector_editor_new(SPGradient *gradient, SPStop *stop) sp_transientize(dlg); wd.win = dlg; wd.stop = 0; - g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(sp_transientize_callback), &wd); - g_signal_connect(G_OBJECT(dlg), "event", G_CALLBACK(sp_dialog_event_handler), dlg); - g_signal_connect(G_OBJECT(dlg), "destroy", G_CALLBACK(sp_gradient_vector_dialog_destroy), dlg); - g_signal_connect(G_OBJECT(dlg), "delete_event", G_CALLBACK(sp_gradient_vector_dialog_delete), dlg); - g_signal_connect(G_OBJECT(INKSCAPE), "shut_down", G_CALLBACK(sp_gradient_vector_dialog_delete), dlg); - g_signal_connect( G_OBJECT(INKSCAPE), "dialogs_hide", G_CALLBACK(sp_dialog_hide), dlg ); - g_signal_connect( G_OBJECT(INKSCAPE), "dialogs_unhide", G_CALLBACK(sp_dialog_unhide), dlg ); + + GObject *obj = G_OBJECT(dlg); + sigc::connection *conn = NULL; + + conn = new sigc::connection(INKSCAPE.signal_activate_desktop.connect(sigc::bind(sigc::ptr_fun(&sp_transientize_callback), &wd))); + g_object_set_data(obj, "desktop-activate-connection", conn); + + g_signal_connect(obj, "event", G_CALLBACK(sp_dialog_event_handler), dlg); + g_signal_connect(obj, "destroy", G_CALLBACK(sp_gradient_vector_dialog_destroy), dlg); + g_signal_connect(obj, "delete_event", G_CALLBACK(sp_gradient_vector_dialog_delete), dlg); + + conn = new sigc::connection(INKSCAPE.signal_shut_down.connect( + sigc::hide_return( + sigc::bind(sigc::ptr_fun(&sp_gradient_vector_dialog_delete), (GtkWidget *) NULL, (GdkEvent *) NULL, (GtkWidget *) NULL) + ))); + g_object_set_data(obj, "shutdown-connection", conn); + + conn = new sigc::connection(INKSCAPE.signal_dialogs_hide.connect(sigc::bind(sigc::ptr_fun(>k_widget_hide), dlg))); + g_object_set_data(obj, "dialog-hide-connection", conn); + + conn = new sigc::connection(INKSCAPE.signal_dialogs_unhide.connect(sigc::bind(sigc::ptr_fun(>k_widget_show), dlg))); + g_object_set_data(obj, "dialog-unhide-connection", conn); gtk_container_set_border_width(GTK_CONTAINER(dlg), PAD); @@ -1141,7 +1156,29 @@ static void sp_gradient_vector_dialog_destroy(GtkWidget * /*object*/, gpointer / static void sp_gradient_vector_dialog_destroy(GtkObject * /*object*/, gpointer /*data*/) #endif { - sp_signal_disconnect_by_data(INKSCAPE, dlg); + GObject *obj = G_OBJECT(dlg); + assert(obj != NULL); + + sigc::connection *conn = static_cast<sigc::connection *>(g_object_get_data(obj, "desktop-activate-connection")); + assert(conn != NULL); + conn->disconnect(); + delete conn; + + conn = static_cast<sigc::connection *>(g_object_get_data(obj, "shutdown-connection")); + assert(conn != NULL); + conn->disconnect(); + delete conn; + + conn = static_cast<sigc::connection *>(g_object_get_data(obj, "dialog-hide-connection")); + assert(conn != NULL); + conn->disconnect(); + delete conn; + + conn = static_cast<sigc::connection *>(g_object_get_data(obj, "dialog-unhide-connection")); + assert(conn != NULL); + conn->disconnect(); + delete conn; + wd.win = dlg = NULL; wd.stop = 0; } diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index a6e53d638..afc4fcfb0 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -1261,7 +1261,7 @@ std::list<gchar*> &IconImpl::icons_svg_paths() static bool initialized = false; if (!initialized) { // Fall back from user prefs dir into system locations. - gchar *userdir = profile_path("icons"); + gchar *userdir = Inkscape::Application::profile_path("icons"); sources.push_back(g_build_filename(userdir,"icons.svg", NULL)); sources.push_back(g_build_filename(INKSCAPE_PIXMAPDIR, "icons.svg", NULL)); g_free(userdir); @@ -1572,7 +1572,7 @@ void IconImpl::addPreRender( GtkIconSize lsize, gchar const *name ) } gboolean IconImpl::prerenderTask(gpointer /*data*/) { - if ( inkscapeIsCrashing() ) { + if ( Inkscape::Application::isCrashing() ) { // stop } else if (!pendingRenders.empty()) { bool workDone = false; @@ -1584,7 +1584,7 @@ gboolean IconImpl::prerenderTask(gpointer /*data*/) { } while (!pendingRenders.empty() && !workDone); } - if (!inkscapeIsCrashing() && !pendingRenders.empty()) { + if (!Inkscape::Application::isCrashing() && !pendingRenders.empty()) { return TRUE; } else { callbackHooked = false; diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index a85f3ae78..387bf6dee 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -30,7 +30,7 @@ #include "live_effects/lpe-line_segment.h" #include "lpe-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-select-one-action.h" @@ -91,7 +91,7 @@ static void sp_lpetool_mode_changed(EgeSelectOneAction *act, GObject *tbl) SP_LPETOOL_CONTEXT(desktop->event_context)->mode = type; } - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt( "/tools/lpetool/mode", mode ); } @@ -280,7 +280,7 @@ static void lpetool_toolbox_watch_ec(SPDesktop* dt, Inkscape::UI::Tools::ToolBas void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); - tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); + tracker->setActiveUnit(desktop->getNamedView()->display_units); g_object_set_data(holder, "tracker", tracker); Unit const *unit = tracker->getActiveUnit(); g_return_if_fail(unit != NULL); @@ -413,9 +413,9 @@ static void lpetool_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::To if (SP_IS_LPETOOL_CONTEXT(ec)) { // Watch selection - c_selection_modified = sp_desktop_selection(desktop)->connectModified(sigc::bind(sigc::ptr_fun(sp_lpetool_toolbox_sel_modified), holder)); - c_selection_changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_lpetool_toolbox_sel_changed), holder)); - sp_lpetool_toolbox_sel_changed(sp_desktop_selection(desktop), holder); + c_selection_modified = desktop->getSelection()->connectModified(sigc::bind(sigc::ptr_fun(sp_lpetool_toolbox_sel_modified), holder)); + c_selection_changed = desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_lpetool_toolbox_sel_changed), holder)); + sp_lpetool_toolbox_sel_changed(desktop->getSelection(), holder); } else { if (c_selection_modified) c_selection_modified.disconnect(); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 1a4678332..5a4785b1f 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -31,7 +31,7 @@ #include <glibmm/i18n.h> #include "measure-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -55,7 +55,7 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt(Glib::ustring("/tools/measure/fontsize"), gtk_adjustment_get_value(adj)); diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 897d84278..e9e9fa344 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -38,7 +38,7 @@ #include "document-private.h" #include "document-undo.h" #include "desktop.h" -#include "desktop-handles.h" + #include <glibmm/i18n.h> #include "ui/tools/gradient-tool.h" @@ -92,7 +92,7 @@ static void ms_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointe // return; // } - // Inkscape::Selection *selection = sp_desktop_selection(desktop); // take from desktop, not from args + // Inkscape::Selection *selection = desktop->getSelection(); // take from desktop, not from args // if (selection) { // ToolBase *ev = sp_desktop_event_context(desktop); // GrDrag *drag = NULL; @@ -334,8 +334,8 @@ static void mesh_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolB if (SP_IS_MESH_CONTEXT(ec)) { // connect to selection modified and changed signals - Inkscape::Selection *selection = sp_desktop_selection (desktop); - SPDocument *document = sp_desktop_document (desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *document = desktop->getDocument(); c_selection_changed = selection->connectChanged(sigc::bind(sigc::ptr_fun(&ms_tb_selection_changed), holder)); c_selection_modified = selection->connectModified(sigc::bind(sigc::ptr_fun(&ms_tb_selection_modified), holder)); diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 467325d08..113061519 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -31,7 +31,7 @@ #include "ui/tool/multi-path-manipulator.h" #include <glibmm/i18n.h> #include "node-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -264,7 +264,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D } Unit const *unit = tracker->getActiveUnit(); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } @@ -330,7 +330,7 @@ static void node_toolbox_watch_ec(SPDesktop* dt, Inkscape::UI::Tools::ToolBase* void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); - Unit doc_units = *sp_desktop_namedview(desktop)->doc_units; + Unit doc_units = *desktop->getNamedView()->display_units; tracker->setActiveUnit(&doc_units); g_object_set_data( holder, "tracker", tracker ); @@ -614,7 +614,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje gtk_action_group_add_action( mainActions, act ); } - sp_node_toolbox_sel_changed(sp_desktop_selection(desktop), holder); + sp_node_toolbox_sel_changed(desktop->getSelection(), holder); desktop->connectEventContextChanged(sigc::bind(sigc::ptr_fun(node_toolbox_watch_ec), holder)); } // end of sp_node_toolbox_prep() @@ -627,11 +627,11 @@ static void node_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolB if (INK_IS_NODE_TOOL(ec)) { // watch selection - c_selection_changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_node_toolbox_sel_changed), holder)); - c_selection_modified = sp_desktop_selection(desktop)->connectModified(sigc::bind(sigc::ptr_fun(sp_node_toolbox_sel_modified), holder)); + c_selection_changed = desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_node_toolbox_sel_changed), holder)); + c_selection_modified = desktop->getSelection()->connectModified(sigc::bind(sigc::ptr_fun(sp_node_toolbox_sel_modified), holder)); c_subselection_changed = desktop->connectToolSubselectionChanged(sigc::bind(sigc::ptr_fun(sp_node_toolbox_coord_changed), holder)); - sp_node_toolbox_sel_changed(sp_desktop_selection(desktop), holder); + sp_node_toolbox_sel_changed(desktop->getSelection(), holder); } else { if (c_selection_changed) c_selection_changed.disconnect(); diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index b6b7e435d..016aa4987 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -31,7 +31,7 @@ #include <glibmm/i18n.h> #include "rect-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -90,7 +90,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * Unit const *unit = tracker->getActiveUnit(); g_return_if_fail(unit != NULL); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name, Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); @@ -105,11 +105,11 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE)); bool modmade = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, sp_desktop_namedview(desktop)->doc_units)); + (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -120,7 +120,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * sp_rtb_sensitivize( tbl ); if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_RECT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_RECT, _("Change rectangle")); } @@ -181,7 +181,7 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) ); Unit const *unit = tracker->getActiveUnit(); - Unit const *doc_unit = sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units; + Unit const *svg_unit = SP_ACTIVE_DESKTOP->getNamedView()->svg_units; g_return_if_fail(unit != NULL); gpointer item = g_object_get_data( tbl, "item" ); @@ -190,28 +190,28 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) ); gdouble rx = SP_RECT(item)->getVisibleRx(); - gtk_adjustment_set_value(adj, Quantity::convert(rx, doc_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(rx, svg_unit, unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) ); gdouble ry = SP_RECT(item)->getVisibleRy(); - gtk_adjustment_set_value(adj, Quantity::convert(ry, doc_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(ry, svg_unit, unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) ); gdouble width = SP_RECT(item)->getVisibleWidth(); - gtk_adjustment_set_value(adj, Quantity::convert(width, doc_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(width, svg_unit, unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) ); gdouble height = SP_RECT(item)->getVisibleHeight(); - gtk_adjustment_set_value(adj, Quantity::convert(height, doc_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(height, svg_unit, unit)); } } @@ -307,7 +307,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); //tracker->addUnit( SP_UNIT_PERCENT, 0 ); // fixme: add % meaning per cent of the width/height - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + tracker->setActiveUnit( desktop->getNamedView()->display_units ); g_object_set_data( holder, "tracker", tracker ); /* W */ @@ -404,12 +404,20 @@ static void rect_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolB { static sigc::connection changed; - // TODO fixme: use of dynamic_cast<> seems wrong here. + // use of dynamic_cast<> seems wrong here -- we just need to check the current tool + if (dynamic_cast<Inkscape::UI::Tools::RectTool *>(ec)) { - changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_rect_toolbox_selection_changed), holder)); + Inkscape::Selection *sel = desktop->getSelection(); + + changed = sel->connectChanged(sigc::bind(sigc::ptr_fun(sp_rect_toolbox_selection_changed), holder)); + + // Synthesize an emission to trigger the update + sp_rect_toolbox_selection_changed(sel, holder); } else { - if (changed) + if (changed) { changed.disconnect(); + purge_repr_listener(NULL, holder); + } } } diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 08a46354e..e49c4c00a 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -21,7 +21,7 @@ #include "ui/widget/spinbutton.h" #include <glibmm/i18n.h> #include "select-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "display/sp-canvas.h" #include "document-undo.h" @@ -106,7 +106,7 @@ static void sp_selection_layout_widget_modify_selection(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data) { SPDesktop *desktop = static_cast<SPDesktop *>(data); - if ((sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop + if ((desktop->getSelection() == selection) // only respond to changes in our desktop && (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG ))) @@ -119,7 +119,7 @@ static void sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *selection, gpointer data) { SPDesktop *desktop = static_cast<SPDesktop *>(data); - if (sp_desktop_selection(desktop) == selection) { // only respond to changes in our desktop + if (desktop->getSelection() == selection) { // only respond to changes in our desktop gboolean setActive = (selection && !selection->isEmpty()); std::vector<GtkAction*> *contextActions = reinterpret_cast<std::vector<GtkAction*> *>(g_object_get_data(G_OBJECT(spw), "contextActions")); if ( contextActions ) { @@ -153,8 +153,8 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPDocument *document = sp_desktop_document(desktop); + Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *document = desktop->getDocument(); document->ensureUpToDate (); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -241,7 +241,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) if (actionkey != NULL) { // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed - sp_desktop_canvas(desktop)->forceFullRedrawAfterInterruptions(0); + desktop->getCanvas()->forceFullRedrawAfterInterruptions(0); bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool preserve = prefs->getBool("/options/preservetransform/value", false); @@ -262,7 +262,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) _("Transform by toolbar")); // resume interruptibility - sp_desktop_canvas(desktop)->endForcedFullRedraws(); + desktop->getCanvas()->endForcedFullRedraws(); } g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); @@ -470,10 +470,10 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb contextActions->push_back( act ); // Create the parent widget for x y w h tracker. - GtkWidget *spw = sp_widget_new_global(INKSCAPE); + GtkWidget *spw = sp_widget_new_global(); // Remember the desktop's canvas widget, to be used for defocusing. - g_object_set_data(G_OBJECT(spw), "dtw", sp_desktop_canvas(desktop)); + g_object_set_data(G_OBJECT(spw), "dtw", desktop->getCanvas()); // The vb frame holds all other widgets and is used to set sensitivity depending on selection state. #if GTK_CHECK_VERSION(3,0,0) @@ -488,7 +488,7 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb // Create the units menu. UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); tracker->addUnit(unit_table.getUnit("%")); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + tracker->setActiveUnit( desktop->getNamedView()->display_units ); g_object_set_data( G_OBJECT(spw), "tracker", tracker ); g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw ); @@ -546,7 +546,7 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_signal_connect(G_OBJECT(spw), "change_selection", G_CALLBACK(sp_selection_layout_widget_change_selection), desktop); // Update now. - sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? sp_desktop_selection(SP_ACTIVE_DESKTOP) : NULL); + sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? SP_ACTIVE_DESKTOP->getSelection() : NULL); for ( std::vector<GtkAction*>::iterator iter = contextActions->begin(); iter != contextActions->end(); ++iter) { diff --git a/src/widgets/sp-widget.cpp b/src/widgets/sp-widget.cpp index fdf5ec500..5ab6b1bb5 100644 --- a/src/widgets/sp-widget.cpp +++ b/src/widgets/sp-widget.cpp @@ -15,6 +15,7 @@ #include "macros.h" #include "document.h" +#include "inkscape.h" #include "sp-widget.h" #include "helper/sp-marshal.h" @@ -55,15 +56,15 @@ public: #endif static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation); - static void modifySelectionCB(Application *inkscape, Selection *selection, guint flags, SPWidget *spw); - static void changeSelectionCB(Application *inkscape, Selection *selection, SPWidget *spw); - static void setSelectionCB(Application *inkscape, Selection *selection, SPWidget *spw); + static void modifySelectionCB(Selection *selection, guint flags, SPWidget *spw); + static void changeSelectionCB(Selection *selection, SPWidget *spw); + static void setSelectionCB(Selection *selection, SPWidget *spw); - static GtkWidget *constructGlobal(SPWidget *spw, InkscapeApplication *inkscape); + static GtkWidget *constructGlobal(SPWidget *spw); - void modifySelection(Application *inkscape, Selection *selection, guint flags); - void changeSelection(Application *inkscape, Selection *selection); - void setSelection(Application *inkscape, Selection *selection); + void modifySelection(Selection *selection, guint flags); + void changeSelection(Selection *selection); + void setSelection(Selection *selection); private: SPWidget &_target; @@ -132,7 +133,6 @@ sp_widget_class_init(SPWidgetClass *klass) static void sp_widget_init(SPWidget *spw) { - spw->inkscape = NULL; spw->_impl = new SPWidgetImpl(*spw); // ctor invoked after all other init } @@ -151,16 +151,12 @@ void SPWidgetImpl::dispose(GObject *object) { SPWidget *spw = reinterpret_cast<SPWidget *>(object); - if (spw->inkscape) { - // Disconnect signals - - // the checks are necessary because when destroy is caused by the program shutting down, - // the inkscape object may already be (partly?) invalid --bb - if (G_IS_OBJECT(spw->inkscape) && G_OBJECT_GET_CLASS(spw->inkscape)) { - sp_signal_disconnect_by_data(spw->inkscape, spw); - } - spw->inkscape = NULL; - } + // Disconnect signals + if (Application::exists()) { + spw->selModified.disconnect(); + spw->selChanged.disconnect(); + spw->selSet.disconnect(); + } delete spw->_impl; spw->_impl = 0; @@ -174,11 +170,20 @@ void SPWidgetImpl::show(GtkWidget *widget) { SPWidget *spw = SP_WIDGET(widget); - if (spw->inkscape) { + if (Application::exists()) { // Connect signals - g_signal_connect(spw->inkscape, "modify_selection", G_CALLBACK(SPWidgetImpl::modifySelectionCB), spw); - g_signal_connect(spw->inkscape, "change_selection", G_CALLBACK(SPWidgetImpl::changeSelectionCB), spw); - g_signal_connect(spw->inkscape, "set_selection", G_CALLBACK(SPWidgetImpl::setSelectionCB), spw); + spw->selModified = INKSCAPE.signal_selection_modified.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::modifySelectionCB), spw) + ); + spw->selChanged = INKSCAPE.signal_selection_changed.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::changeSelectionCB), spw) + ); + spw->selSet = INKSCAPE.signal_selection_set.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::setSelectionCB), spw) + ); } if (GTK_WIDGET_CLASS(sp_widget_parent_class)->show) { @@ -190,9 +195,11 @@ void SPWidgetImpl::hide(GtkWidget *widget) { SPWidget *spw = SP_WIDGET (widget); - if (spw->inkscape) { + if (Application::exists()) { // Disconnect signals - sp_signal_disconnect_by_data(spw->inkscape, spw); + spw->selModified.disconnect(); + spw->selChanged.disconnect(); + spw->selSet.disconnect(); } if (GTK_WIDGET_CLASS(sp_widget_parent_class)->hide) { @@ -264,15 +271,21 @@ void SPWidgetImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation) } } -GtkWidget *SPWidgetImpl::constructGlobal(SPWidget *spw, InkscapeApplication *inkscape) +GtkWidget *SPWidgetImpl::constructGlobal(SPWidget *spw) { - g_return_val_if_fail(!spw->inkscape, NULL); - - spw->inkscape = inkscape; if (gtk_widget_get_visible(GTK_WIDGET(spw))) { - g_signal_connect(inkscape, "modify_selection", G_CALLBACK(SPWidgetImpl::modifySelectionCB), spw); - g_signal_connect(inkscape, "change_selection", G_CALLBACK(SPWidgetImpl::changeSelectionCB), spw); - g_signal_connect(inkscape, "set_selection", G_CALLBACK(SPWidgetImpl::setSelectionCB), spw); + spw->selModified = INKSCAPE.signal_selection_modified.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::modifySelectionCB), spw) + ); + spw->selChanged = INKSCAPE.signal_selection_changed.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::changeSelectionCB), spw) + ); + spw->selSet = INKSCAPE.signal_selection_set.connect( + sigc::bind( + sigc::ptr_fun(SPWidgetImpl::setSelectionCB), spw) + ); } g_signal_emit(spw, signals[CONSTRUCT], 0); @@ -280,32 +293,32 @@ GtkWidget *SPWidgetImpl::constructGlobal(SPWidget *spw, InkscapeApplication *ink return GTK_WIDGET(spw); } -void SPWidgetImpl::modifySelectionCB(Application *inkscape, Selection *selection, guint flags, SPWidget *spw) +void SPWidgetImpl::modifySelectionCB(Selection *selection, guint flags, SPWidget *spw) { - spw->_impl->modifySelection(inkscape, selection, flags); + spw->_impl->modifySelection(selection, flags); } -void SPWidgetImpl::changeSelectionCB(Application *inkscape, Selection *selection, SPWidget *spw) +void SPWidgetImpl::changeSelectionCB(Selection *selection, SPWidget *spw) { - spw->_impl->changeSelection(inkscape, selection); + spw->_impl->changeSelection(selection); } -void SPWidgetImpl::setSelectionCB(Application *inkscape, Selection *selection, SPWidget *spw) +void SPWidgetImpl::setSelectionCB(Selection *selection, SPWidget *spw) { - spw->_impl->setSelection(inkscape, selection); + spw->_impl->setSelection(selection); } -void SPWidgetImpl::modifySelection(Application * /*inkscape*/, Selection *selection, guint flags) +void SPWidgetImpl::modifySelection(Selection *selection, guint flags) { g_signal_emit(&_target, signals[MODIFY_SELECTION], 0, selection, flags); } -void SPWidgetImpl::changeSelection(Application * /*inkscape*/, Selection *selection) +void SPWidgetImpl::changeSelection(Selection *selection) { g_signal_emit(&_target, signals[CHANGE_SELECTION], 0, selection); } -void SPWidgetImpl::setSelection(Application * /*inkscape*/, Selection *selection) +void SPWidgetImpl::setSelection(Selection *selection) { // Emit "set_selection" signal g_signal_emit(&_target, signals[SET_SELECTION], 0, selection); @@ -316,11 +329,11 @@ void SPWidgetImpl::setSelection(Application * /*inkscape*/, Selection *selection // Methods -GtkWidget *sp_widget_new_global(InkscapeApplication *inkscape) +GtkWidget *sp_widget_new_global() { SPWidget *spw = reinterpret_cast<SPWidget*>(g_object_new(SP_TYPE_WIDGET, NULL)); - if (!SPWidgetImpl::constructGlobal(spw, inkscape)) { + if (!SPWidgetImpl::constructGlobal(spw)) { g_object_unref(spw); spw = 0; } diff --git a/src/widgets/sp-widget.h b/src/widgets/sp-widget.h index 6227c3a72..a53062cf4 100644 --- a/src/widgets/sp-widget.h +++ b/src/widgets/sp-widget.h @@ -16,6 +16,7 @@ */ #include <gtk/gtk.h> +#include "inkscape.h" #define SP_TYPE_WIDGET (sp_widget_get_type()) #define SP_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_WIDGET, SPWidget)) @@ -23,9 +24,8 @@ #define SP_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_WIDGET)) #define SP_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_WIDGET)) -struct InkscapeApplication; - namespace Inkscape { + class Selection; class SPWidgetImpl; } @@ -33,10 +33,15 @@ class SPWidgetImpl; struct SPWidget { friend class Inkscape::SPWidgetImpl; + static GType getType(); + GtkBin bin; - InkscapeApplication *inkscape; Inkscape::SPWidgetImpl *_impl; +private: + sigc::connection selModified; + sigc::connection selChanged; + sigc::connection selSet; }; struct SPWidgetClass { @@ -53,7 +58,7 @@ struct SPWidgetClass { GType sp_widget_get_type(); /** Generic constructor for global widget. */ -GtkWidget *sp_widget_new_global(InkscapeApplication *inkscape); +GtkWidget *sp_widget_new_global(); #endif // SEEN_SP_WIDGET_H /* diff --git a/src/widgets/sp-xmlview-content.cpp b/src/widgets/sp-xmlview-content.cpp index 9243760bd..a1d8475ba 100644 --- a/src/widgets/sp-xmlview-content.cpp +++ b/src/widgets/sp-xmlview-content.cpp @@ -15,7 +15,7 @@ #include "xml/node-event-vector.h" #include "sp-xmlview-content.h" -#include "desktop-handles.h" +#include "desktop.h" #include "document-private.h" #include "document-undo.h" #include "inkscape.h" @@ -147,7 +147,7 @@ sp_xmlview_content_changed (GtkTextBuffer *tb, SPXMLViewContent *text) text->repr->setContent(data); g_free (data); text->blocked = FALSE; - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_XML_EDITOR, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_DIALOG_XML_EDITOR, _("Type text in a text node")); } } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index e85b024ed..3fb0015c1 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -31,7 +31,7 @@ #include <glibmm/i18n.h> #include "spiral-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -62,7 +62,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/tools/shapes/spiral/" + value_name, gtk_adjustment_get_value(adj)); @@ -79,7 +79,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - for (GSList const *items = sp_desktop_selection(desktop)->itemList(); + for (GSList const *items = desktop->getSelection()->itemList(); items != NULL; items = items->next) { @@ -96,7 +96,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr g_free(namespaced_name); if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SPIRAL, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_SPIRAL, _("Change spiral")); } @@ -296,7 +296,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb sigc::connection *connection = new sigc::connection( - sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_spiral_toolbox_selection_changed), holder)) + desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_spiral_toolbox_selection_changed), holder)) ); g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection ); g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder ); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 6213263fc..cf12391c1 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -31,7 +31,7 @@ #include <glibmm/i18n.h> #include "star-toolbar.h" -#include "desktop-handles.h" + #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -64,7 +64,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { // do not remember prefs if this call is initiated by an undo change, because undoing object // creation sets bogus values to its attributes before it is deleted Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -82,7 +82,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); for (; items != NULL; items = items->next) { SPItem *item = reinterpret_cast<SPItem*>(items->data); @@ -99,7 +99,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu } } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, _("Star: Change number of corners")); } @@ -110,7 +110,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { if (!IS_NAN(gtk_adjustment_get_value(adj))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/tools/shapes/star/proportion", @@ -127,7 +127,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) ); bool modmade = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); for (; items != NULL; items = items->next) { SPItem *item = reinterpret_cast<SPItem *>(items->data); @@ -152,7 +152,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, _("Star: Change spoke ratio")); } @@ -164,7 +164,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); bool flat = ege_select_one_action_get_active( act ) == 0; - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool( "/tools/shapes/star/isflatsided", flat); } @@ -177,7 +177,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d // in turn, prevent listener from responding g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) ); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); GtkAction* prop_action = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) ); bool modmade = false; @@ -197,7 +197,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, flat ? _("Make polygon") : _("Make star")); } @@ -208,7 +208,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/tools/shapes/star/rounded", (gdouble) gtk_adjustment_get_value(adj)); } @@ -223,7 +223,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); for (; items != NULL; items = items->next) { SPItem *item = reinterpret_cast<SPItem*>(items->data); @@ -236,7 +236,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg } } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, _("Star: Change rounding")); } @@ -247,7 +247,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( dataKludge, "desktop" )); - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/tools/shapes/star/randomized", (gdouble) gtk_adjustment_get_value(adj)); @@ -263,7 +263,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); for (; items != NULL; items = items->next) { SPItem *item = reinterpret_cast<SPItem *>(items->data); @@ -276,7 +276,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl } } if (modmade) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_STAR, _("Star: Change randomization")); } @@ -582,8 +582,8 @@ static void star_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolB static sigc::connection changed; if (dynamic_cast<Inkscape::UI::Tools::StarTool const*>(ec) != NULL) { - changed = sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_star_toolbox_selection_changed), holder)); - sp_star_toolbox_selection_changed(sp_desktop_selection(desktop), holder); + changed = desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_star_toolbox_selection_changed), holder)); + sp_star_toolbox_selection_changed(desktop->getSelection(), holder); } else { if (changed) changed.disconnect(); diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index 23da54e94..e273faad7 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -26,7 +26,7 @@ #include "style.h" #include "ui/dialog-events.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "preferences.h" #include "path-prefix.h" @@ -64,8 +64,8 @@ MarkerComboBox::MarkerComboBox(gchar const *id, int l) : sp_pixbuf_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("no-marker") ) ) ); sandbox = ink_markers_preview_doc (); - desktop = inkscape_active_desktop(); - doc = sp_desktop_document(desktop); + desktop = SP_ACTIVE_DESKTOP; + doc = desktop->getDocument(); modified_connection = doc->getDefs()->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&MarkerComboBox::handleDefsModified), this))) ); @@ -92,7 +92,7 @@ void MarkerComboBox::setDesktop(SPDesktop *desktop) } this->desktop = desktop; - doc = sp_desktop_document(desktop); + doc = desktop->getDocument(); if (doc) { modified_connection = doc->getDefs()->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&MarkerComboBox::handleDefsModified), this))) ); @@ -578,25 +578,25 @@ gboolean MarkerComboBox::separator_cb (GtkTreeModel *model, GtkTreeIter *iter, g */ SPDocument *MarkerComboBox::ink_markers_preview_doc () { -gchar const *buffer = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" +gchar const *buffer = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" id=\"MarkerSample\">" " <defs id=\"defs\" />" " <g id=\"marker-start\">" -" <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:url(#sample);marker-mid:none;marker-end:none\"" +" <path style=\"fill:gray;stroke:darkgray;stroke-width:1.7;marker-start:url(#sample);marker-mid:none;marker-end:none\"" " d=\"M 12.5,13 L 25,13\" id=\"path1\" />" " <rect style=\"fill:none;stroke:none\" id=\"rect2\"" " width=\"25\" height=\"25\" x=\"0\" y=\"0\" />" " </g>" " <g id=\"marker-mid\">" -" <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:url(#sample);marker-end:none\"" +" <path style=\"fill:gray;stroke:darkgray;stroke-width:1.7;marker-start:none;marker-mid:url(#sample);marker-end:none\"" " d=\"M 0,113 L 12.5,113 L 25,113\" id=\"path11\" />" " <rect style=\"fill:none;stroke:none\" id=\"rect22\"" " width=\"25\" height=\"25\" x=\"0\" y=\"100\" />" " </g>" " <g id=\"marker-end\">" -" <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:none;marker-end:url(#sample)\"" +" <path style=\"fill:gray;stroke:darkgray;stroke-width:1.7;marker-start:none;marker-mid:none;marker-end:url(#sample)\"" " d=\"M 0,213 L 12.5,213\" id=\"path111\" />" " <rect style=\"fill:none;stroke:none\" id=\"rect222\"" " width=\"25\" height=\"25\" x=\"0\" y=\"200\" />" diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 02dd5df6e..5ca06a795 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -204,8 +204,8 @@ StrokeStyle::StrokeStyle() : unitSelector->addUnit(*unit_table.getUnit("%")); _old_unit = unitSelector->getUnit(); if (desktop) { - unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); - _old_unit = sp_desktop_namedview(desktop)->doc_units; + unitSelector->setUnit(desktop->getNamedView()->display_units->abbr); + _old_unit = desktop->getNamedView()->display_units; } widthSpin->setUnitMenu(unitSelector); unitChangedConn = unitSelector->signal_changed().connect(sigc::mem_fun(*this, &StrokeStyle::unitChangedCB)); @@ -456,7 +456,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, spw->update = true; - SPDocument *document = sp_desktop_document(spw->desktop); + SPDocument *document = spw->desktop->getDocument(); if (!document) { return; } @@ -471,10 +471,10 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, // Also update the marker combobox, so the document's markers // show up at the top of the combobox -// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL); +// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? desktop->getSelection() : NULL); //spw->updateMarkerHist(which); - Inkscape::Selection *selection = sp_desktop_selection(spw->desktop); + Inkscape::Selection *selection = spw->desktop->getSelection(); GSList const *items = selection->itemList(); for (; items != NULL; items = items->next) { SPItem *item = reinterpret_cast<SPItem *>(items->data); @@ -810,18 +810,18 @@ StrokeStyle::updateLine() update = true; - Inkscape::Selection *sel = desktop ? sp_desktop_selection(desktop) : NULL; + Inkscape::Selection *sel = desktop ? desktop->getSelection() : NULL; FillOrStroke kind = GPOINTER_TO_INT(get_data("kind")) ? FILL : STROKE; // create temporary style - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); // query into it - int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEWIDTH); - int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT); - int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP); - int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN); - SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; + int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEWIDTH); + int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT); + int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKECAP); + int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEJOIN); + SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; if (!sel || sel->isEmpty()) { // Nothing selected, grey-out all controls in the stroke-style dialog @@ -839,14 +839,14 @@ StrokeStyle::updateLine() // same width, or only one object; no sense to keep percent, switch to absolute Inkscape::Util::Unit const *tempunit = unitSelector->getUnit(); if (tempunit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { - unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); + unitSelector->setUnit(SP_ACTIVE_DESKTOP->getNamedView()->display_units->abbr); } } Inkscape::Util::Unit const *unit = unitSelector->getUnit(); if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", unit); + double avgwidth = Inkscape::Util::Quantity::convert(query.stroke_width.computed, "px", unit); #if WITH_GTKMM_3_0 (*widthAdj)->set_value(avgwidth); #else @@ -879,27 +879,25 @@ StrokeStyle::updateLine() if (result_ml != QUERY_STYLE_NOTHING) #if WITH_GTKMM_3_0 - (*miterLimitAdj)->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness? + (*miterLimitAdj)->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness? #else - miterLimitAdj->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness? + miterLimitAdj->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness? #endif if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT && result_join != QUERY_STYLE_NOTHING ) { - setJoinType(query->stroke_linejoin.value); + setJoinType(query.stroke_linejoin.value); } else { setJoinButtons(NULL); } if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT && result_cap != QUERY_STYLE_NOTHING ) { - setCapType (query->stroke_linecap.value); + setCapType (query.stroke_linecap.value); } else { setCapButtons(NULL); } - sp_style_unref(query); - if (!sel || sel->isEmpty()) return; @@ -957,8 +955,8 @@ StrokeStyle::scaleLine() update = true; - SPDocument *document = sp_desktop_document (desktop); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + SPDocument *document = desktop->getDocument(); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); @@ -1113,8 +1111,7 @@ void StrokeStyle::buttonToggledCB(StrokeStyleButton *tb, StrokeStyle *spw) sp_repr_css_attr_unref(css); css = 0; - DocumentUndo::done(sp_desktop_document(spw->desktop), SP_VERB_DIALOG_FILL_STROKE, - _("Set stroke style")); + DocumentUndo::done(spw->desktop->getDocument(), SP_VERB_DIALOG_FILL_STROKE, _("Set stroke style")); } } @@ -1200,7 +1197,7 @@ StrokeStyle::updateAllMarkers(GSList const *objects) if (update) { setMarkerColor(marker, combo->get_loc(), SP_ITEM(object)); - SPDocument *document = sp_desktop_document(desktop); + SPDocument *document = desktop->getDocument(); DocumentUndo::done(document, SP_VERB_DIALOG_FILL_STROKE, _("Set marker color")); } diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 15e394097..83048cb76 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -33,7 +33,6 @@ #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-handles.h" #include "desktop-style.h" #include "ui/dialog-events.h" #include "display/canvas-bpath.h" // for SP_STROKE_LINEJOIN_* diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index d62bb8027..3d2e6eef8 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -31,7 +31,7 @@ #include "libnrtype/font-lister.h" #include <glibmm/i18n.h> #include "text-toolbar.h" -#include "desktop-handles.h" + #include "desktop-style.h" #include "desktop.h" #include "document-undo.h" @@ -165,7 +165,7 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb sp_desktop_set_style (desktop, css, true, true); // Results in selection change called twice. sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Text: Change font family")); } @@ -220,21 +220,19 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje sp_desktop_set_style (desktop, css, true, true); // If no selected objects, set default. - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); } else { // Save for undo - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:size", SP_VERB_NONE, _("Text: Change font size")); } - sp_style_unref(query); - sp_repr_css_attr_unref (css); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); @@ -267,7 +265,7 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj sp_desktop_set_style (desktop, css, true, true); sp_repr_css_attr_unref (css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Text: Change font style")); } @@ -292,8 +290,8 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl ) #endif // Query baseline - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BASELINES); + SPStyle query(SP_ACTIVE_DOCUMENT); + int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_BASELINES); bool setSuper = false; bool setSub = false; @@ -307,14 +305,14 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl ) } } else { // Superscript - gboolean superscriptSet = (query->baseline_shift.set && - query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && - query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER ); + gboolean superscriptSet = (query.baseline_shift.set && + query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && + query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER ); // Subscript - gboolean subscriptSet = (query->baseline_shift.set && - query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && - query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB ); + gboolean subscriptSet = (query.baseline_shift.set && + query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && + query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB ); setSuper = !superscriptSet && prop == 0; setSub = !subscriptSet && prop == 1; @@ -345,7 +343,7 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl ) // Save for undo if(result_baseline != QUERY_STYLE_NOTHING) { - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:script", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:script", SP_VERB_NONE, _("Text: Change superscript or subscript")); } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); @@ -367,7 +365,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) SPDesktop *desktop = SP_ACTIVE_DESKTOP; // move the x of all texts to preserve the same bbox - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { if (SP_IS_TEXT(SP_ITEM(items->data))) { SPItem *item = SP_ITEM(items->data); @@ -473,10 +471,9 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) } } - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); // If querying returned nothing, update default style. if (result_numbers == QUERY_STYLE_NOTHING) @@ -485,12 +482,10 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) prefs->mergeStyle("/tools/text/style", css); } - sp_style_unref(query); - sp_desktop_set_style (desktop, css, true, true); if (result_numbers != QUERY_STYLE_NOTHING) { - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_TEXT, _("Text: Change alignment")); } sp_repr_css_attr_unref (css); @@ -521,7 +516,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Until deprecated sodipodi:linespacing purged: - Inkscape::Selection *selection = sp_desktop_selection(desktop); + Inkscape::Selection *selection = desktop->getSelection(); GSList const *items = selection->itemList(); bool modmade = false; for (; items != NULL; items = items->next) { @@ -533,20 +528,19 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Save for undo if(modmade) { - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:line-height", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:line-height", SP_VERB_NONE, _("Text: Change line-height")); } // If no selected objects, set default. - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); } - sp_style_unref(query); sp_repr_css_attr_unref (css); @@ -573,19 +567,18 @@ static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl sp_desktop_set_style (desktop, css, true, false); // If no selected objects, set default. - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); } else { // Save for undo - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:word-spacing", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:word-spacing", SP_VERB_NONE, _("Text: Change word-spacing")); } - sp_style_unref(query); sp_repr_css_attr_unref (css); @@ -612,9 +605,9 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb sp_desktop_set_style (desktop, css, true, false); // If no selected objects, set default. - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -623,12 +616,10 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb else { // Save for undo - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:letter-spacing", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:letter-spacing", SP_VERB_NONE, _("Text: Change letter-spacing")); } - sp_style_unref(query); - sp_repr_css_attr_unref (css); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); @@ -663,7 +654,7 @@ static void sp_text_dx_value_changed( GtkAdjustment *adj, GObject *tbl ) if(modmade) { // Save for undo - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:dx", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:dx", SP_VERB_NONE, _("Text: Change dx (kern)")); } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); @@ -697,7 +688,7 @@ static void sp_text_dy_value_changed( GtkAdjustment *adj, GObject *tbl ) if(modmade) { // Save for undo - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:dy", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:dy", SP_VERB_NONE, _("Text: Change dy")); } @@ -732,7 +723,7 @@ static void sp_text_rotation_value_changed( GtkAdjustment *adj, GObject *tbl ) // Save for undo if(modmade) { - DocumentUndo::maybeDone(sp_desktop_document(SP_ACTIVE_DESKTOP), "ttb:rotate", SP_VERB_NONE, + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:rotate", SP_VERB_NONE, _("Text: Change rotate")); } @@ -765,10 +756,9 @@ static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject * } } - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle query(SP_ACTIVE_DOCUMENT); int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); // If querying returned nothing, update default style. if (result_numbers == QUERY_STYLE_NOTHING) @@ -780,7 +770,7 @@ static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject * sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true); if(result_numbers != QUERY_STYLE_NOTHING) { - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, + DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_TEXT, _("Text: Change orientation")); } sp_repr_css_attr_unref (css); @@ -829,7 +819,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ std::cout << "sp_text_toolbox_selection_changed: start " << count << std::endl; std::cout << " Selected items:" << std::endl; - for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + for (GSList const *items = SP_ACTIVE_DESKTOP->getSelection()->itemList(); items != NULL; items = items->next) { @@ -860,7 +850,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); if (!subselection) { - fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP )); + fontlister->update_font_list( SP_ACTIVE_DESKTOP->getDocument()); } fontlister->selection_update(); @@ -873,7 +863,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + for (GSList const *items = SP_ACTIVE_DESKTOP->getSelection()->itemList(); items != NULL; items = items->next) { // const gchar* id = reinterpret_cast<SPItem *>(items->data)->getId(); @@ -892,11 +882,11 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ * Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode) * Font specification (Inkscape private attribute) */ - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BASELINES); + SPStyle query(SP_ACTIVE_DOCUMENT); + int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_BASELINES); /* * If no text in selection (querying returned nothing), read the style from @@ -905,14 +895,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ */ if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) { // There are no texts in selection, read from preferences. - sp_style_read_from_prefs(query, "/tools/text"); + query.readFromPrefs("/tools/text"); #ifdef DEBUG_TEXT std::cout << " read style from prefs:" << std::endl; - sp_print_font( query ); + sp_print_font( &query ); #endif if (g_object_get_data(tbl, "text_style_from_prefs")) { // Do not reset the toolbar style from prefs if we already did it last time - sp_style_unref(query); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); #ifdef DEBUG_TEXT std::cout << " text_style_from_prefs: toolbar already set" << std:: endl; @@ -937,7 +926,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Size (average of text selected) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); - double size = sp_style_css_size_px_to_units(query->font_size.computed, unit); + double size = sp_style_css_size_px_to_units(query.font_size.computed, unit); //gchar size_text[G_ASCII_DTOSTR_BUF_SIZE]; //g_ascii_dtostr (size_text, sizeof (size_text), size); @@ -961,9 +950,9 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Superscript gboolean superscriptSet = ((result_baseline == QUERY_STYLE_SINGLE || result_baseline == QUERY_STYLE_MULTIPLE_SAME ) && - query->baseline_shift.set && - query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && - query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER ); + query.baseline_shift.set && + query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && + query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER ); InkToggleAction* textSuperscriptAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextSuperscriptAction" ) ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textSuperscriptAction), superscriptSet ); @@ -972,9 +961,9 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Subscript gboolean subscriptSet = ((result_baseline == QUERY_STYLE_SINGLE || result_baseline == QUERY_STYLE_MULTIPLE_SAME ) && - query->baseline_shift.set && - query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && - query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB ); + query.baseline_shift.set && + query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL && + query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB ); InkToggleAction* textSubscriptAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextSubscriptAction" ) ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textSubscriptAction), subscriptSet ); @@ -1001,26 +990,26 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // ege_select_one_action_set_sensitive( textAlignAction, 3, isFlow ); int activeButton = 0; - if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) + if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) { activeButton = 3; } else { - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0; - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1; - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2; + if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0; + if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1; + if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2; } ege_select_one_action_set_active( textAlignAction, activeButton ); // Line height (spacing) double height; - if (query->line_height.normal) { + if (query.line_height.normal) { height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; } else { - if (query->line_height.unit == SP_CSS_UNIT_PERCENT) { - height = query->line_height.value; + if (query.line_height.unit == SP_CSS_UNIT_PERCENT) { + height = query.line_height.value; } else { - height = query->line_height.computed; + height = query.line_height.computed; } } @@ -1032,8 +1021,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Word spacing double wordSpacing; - if (query->word_spacing.normal) wordSpacing = 0.0; - else wordSpacing = query->word_spacing.computed; // Assume no units (change in desktop-style.cpp) + if (query.word_spacing.normal) wordSpacing = 0.0; + else wordSpacing = query.word_spacing.computed; // Assume no units (change in desktop-style.cpp) GtkAction* wordSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextWordSpacingAction" ) ); GtkAdjustment *wordSpacingAdjustment = @@ -1043,8 +1032,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Letter spacing double letterSpacing; - if (query->letter_spacing.normal) letterSpacing = 0.0; - else letterSpacing = query->letter_spacing.computed; // Assume no units (change in desktop-style.cpp) + if (query.letter_spacing.normal) letterSpacing = 0.0; + else letterSpacing = query.letter_spacing.computed; // Assume no units (change in desktop-style.cpp) GtkAction* letterSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextLetterSpacingAction" ) ); GtkAdjustment *letterSpacingAdjustment = @@ -1053,7 +1042,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Orientation - int activeButton2 = (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1); + int activeButton2 = (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1); EgeSelectOneAction* textOrientationAction = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextOrientationAction" ) ); @@ -1064,27 +1053,25 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ #ifdef DEBUG_TEXT std::cout << " GUI: fontfamily.value: " - << (query->font_family.value ? query->font_family.value : "No value") + << (query.font_family.value ? query.font_family.value : "No value") << std::endl; - std::cout << " GUI: font_size.computed: " << query->font_size.computed << std::endl; - std::cout << " GUI: font_weight.computed: " << query->font_weight.computed << std::endl; - std::cout << " GUI: font_style.computed: " << query->font_style.computed << std::endl; - std::cout << " GUI: text_anchor.computed: " << query->text_anchor.computed << std::endl; - std::cout << " GUI: text_align.computed: " << query->text_align.computed << std::endl; - std::cout << " GUI: line_height.computed: " << query->line_height.computed - << " line_height.value: " << query->line_height.value - << " line_height.unit: " << query->line_height.unit << std::endl; - std::cout << " GUI: word_spacing.computed: " << query->word_spacing.computed - << " word_spacing.value: " << query->word_spacing.value - << " word_spacing.unit: " << query->word_spacing.unit << std::endl; - std::cout << " GUI: letter_spacing.computed: " << query->letter_spacing.computed - << " letter_spacing.value: " << query->letter_spacing.value - << " letter_spacing.unit: " << query->letter_spacing.unit << std::endl; - std::cout << " GUI: writing_mode.computed: " << query->writing_mode.computed << std::endl; + std::cout << " GUI: font_size.computed: " << query.font_size.computed << std::endl; + std::cout << " GUI: font_weight.computed: " << query.font_weight.computed << std::endl; + std::cout << " GUI: font_style.computed: " << query.font_style.computed << std::endl; + std::cout << " GUI: text_anchor.computed: " << query.text_anchor.computed << std::endl; + std::cout << " GUI: text_align.computed: " << query.text_align.computed << std::endl; + std::cout << " GUI: line_height.computed: " << query.line_height.computed + << " line_height.value: " << query.line_height.value + << " line_height.unit: " << query.line_height.unit << std::endl; + std::cout << " GUI: word_spacing.computed: " << query.word_spacing.computed + << " word_spacing.value: " << query.word_spacing.value + << " word_spacing.unit: " << query.word_spacing.unit << std::endl; + std::cout << " GUI: letter_spacing.computed: " << query.letter_spacing.computed + << " letter_spacing.value: " << query.letter_spacing.value + << " letter_spacing.unit: " << query.letter_spacing.unit << std::endl; + std::cout << " GUI: writing_mode.computed: " << query.writing_mode.computed << std::endl; #endif - sp_style_unref(query); - // Kerning (xshift), yshift, rotation. NB: These are not CSS attributes. if( SP_IS_TEXT_CONTEXT((SP_ACTIVE_DESKTOP)->event_context) ) { Inkscape::UI::Tools::TextTool *const tc = SP_TEXT_CONTEXT((SP_ACTIVE_DESKTOP)->event_context); @@ -1169,7 +1156,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p GSList *selectList = NULL; SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPDocument *document = sp_desktop_document( desktop ); + SPDocument *document = desktop->getDocument(); GSList *allList = get_all_items(NULL, document->getRoot(), desktop, false, false, true, NULL); for (GSList *i = allList; i != NULL; i = i->next) { @@ -1196,7 +1183,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p } // Update selection - Inkscape::Selection *selection = sp_desktop_selection (desktop ); + Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); //std::cout << " list length: " << g_slist_length ( selectList ) << std::endl; selection->setList(selectList); @@ -1214,7 +1201,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje { // Font list Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); - fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP )); + fontlister->update_font_list( SP_ACTIVE_DESKTOP->getDocument()); Glib::RefPtr<Gtk::ListStore> store = fontlister->get_font_list(); GtkListStore* model = store->gobj(); @@ -1623,7 +1610,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje } // Is this necessary to call? Shouldn't hurt. - sp_text_toolbox_selection_changed(sp_desktop_selection(desktop), holder); + sp_text_toolbox_selection_changed(desktop->getSelection(), holder); desktop->connectEventContextChanged(sigc::bind(sigc::ptr_fun(text_toolbox_watch_ec), holder)); @@ -1642,8 +1629,8 @@ static void text_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolB if (SP_IS_TEXT_CONTEXT(ec)) { // Watch selection - c_selection_changed = sp_desktop_selection(desktop)->connectChanged(bind(ptr_fun(sp_text_toolbox_selection_changed), holder, false)); - c_selection_modified = sp_desktop_selection (desktop)->connectModified(bind(ptr_fun(sp_text_toolbox_selection_modified), holder)); + c_selection_changed = desktop->getSelection()->connectChanged(bind(ptr_fun(sp_text_toolbox_selection_changed), holder, false)); + c_selection_modified = desktop->getSelection()->connectModified(bind(ptr_fun(sp_text_toolbox_selection_modified), holder)); c_subselection_changed = desktop->connectToolSubselectionChanged(bind(ptr_fun(sp_text_toolbox_subselection_changed), holder)); } else { if (c_selection_changed) diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 9e55d1cf6..4f5682f7a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -40,7 +40,6 @@ #include <glibmm/i18n.h> #include "../desktop.h" -#include "../desktop-handles.h" #include "../desktop-style.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" @@ -1511,7 +1510,7 @@ static void toggle_snap_callback(GtkToggleAction *act, gpointer data) //data poi g_assert(ptr != NULL); SPDesktop *dt = reinterpret_cast<SPDesktop*>(ptr); - SPNamedView *nv = sp_desktop_namedview(dt); + SPNamedView *nv = dt->getNamedView(); SPDocument *doc = nv->document; if (dt == NULL || nv == NULL) { @@ -1871,7 +1870,7 @@ void ToolboxFactory::updateSnapToolbox(SPDesktop *desktop, ToolBase * /*eventcon g_assert(desktop != NULL); g_assert(toolbox != NULL); - SPNamedView *nv = sp_desktop_namedview(desktop); + SPNamedView *nv = desktop->getNamedView(); if (nv == NULL) { g_warning("Namedview cannot be retrieved (in updateSnapToolbox)!"); return; diff --git a/src/xml/node.h b/src/xml/node.h index 8bb70acc0..29cfdab46 100644 --- a/src/xml/node.h +++ b/src/xml/node.h @@ -469,6 +469,8 @@ public: * @deprecated Use synthesizeEvents(NodeObserver &) instead */ virtual void synthesizeEvents(NodeEventVector const *vector, void *data)=0; + + virtual void recursivePrintTree(unsigned level)=0; /*@}*/ diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index 4965f81c8..3cbedc80b 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -606,6 +606,26 @@ void SimpleNode::synthesizeEvents(NodeObserver &observer) { synthesizeEvents(&OBSERVER_EVENT_VECTOR, &observer); } +void SimpleNode::recursivePrintTree(unsigned level) { + + if (level == 0) { + std::cout << "XML Node Tree" << std::endl; + } + std::cout << "XML: "; + for (unsigned i = 0; i < level; ++i) { + std::cout << " "; + } + char const *id=attribute("id"); + if (id) { + std::cout << id << std::endl; + } else { + std::cout << name() << std::endl; + } + for (SimpleNode *child = _first_child; child != NULL; child = child->_next) { + child->recursivePrintTree( level+1 ); + } +} + Node *SimpleNode::root() { Node *parent=this; while (parent->parent()) { diff --git a/src/xml/simple-node.h b/src/xml/simple-node.h index 1fcb9193b..d09392249 100644 --- a/src/xml/simple-node.h +++ b/src/xml/simple-node.h @@ -19,6 +19,7 @@ #define SEEN_INKSCAPE_XML_SIMPLE_NODE_H #include <cassert> +#include <iostream> #include "xml/node.h" #include "xml/attribute-record.h" @@ -120,6 +121,8 @@ public: _subtree_observers.remove(observer); } + void recursivePrintTree(unsigned level = 0); + protected: SimpleNode(int code, Document *document); SimpleNode(SimpleNode const &repr, Document *document); |
