Merge lp:~inkscape.dev/inkscape/guides-improvements into lp:~inkscape.dev/inkscape/trunk

Proposed by hermes ramirez
Status: Work in progress
Proposed branch: lp:~inkscape.dev/inkscape/guides-improvements
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 5623 lines (+2147/-1318)
48 files modified
build.xml (+0/-8)
doc/HACKING.txt (+1/-1)
doc/architecture.txt (+1/-1)
share/icons/icons.svg (+2/-2)
src/Makefile_insert (+1/-1)
src/attributes.cpp (+2/-0)
src/attributes.h (+2/-0)
src/box3d.cpp (+1/-1)
src/desktop-events.cpp (+138/-54)
src/desktop.cpp (+27/-7)
src/desktop.h (+4/-0)
src/display/Makefile_insert (+2/-0)
src/display/canvas-axonomgrid.cpp (+15/-13)
src/display/canvas-axonomgrid.h (+10/-0)
src/display/canvas-grid.cpp (+14/-10)
src/display/canvas-guide.cpp (+549/-0)
src/display/canvas-guide.h (+92/-0)
src/display/guideline.cpp (+38/-6)
src/display/guideline.h (+4/-0)
src/document-undo.cpp (+24/-20)
src/document.cpp (+4/-4)
src/file.cpp (+117/-1)
src/guide-manager.cpp (+154/-0)
src/guide-manager.h (+65/-0)
src/guide-snapper.cpp (+5/-4)
src/helper/geom.cpp (+15/-1)
src/helper/geom.h (+3/-0)
src/line-snapper.cpp (+1/-1)
src/main.cpp (+2/-1)
src/satisfied-guide-cns.cpp (+1/-1)
src/snap.cpp (+11/-10)
src/sp-guide.cpp (+0/-540)
src/sp-guide.h (+0/-88)
src/sp-item-notify-moveto.cpp (+1/-1)
src/sp-item-rm-unsatisfied-cns.cpp (+1/-1)
src/sp-item-update-cns.cpp (+2/-3)
src/sp-item.cpp (+2/-2)
src/sp-line.cpp (+6/-5)
src/sp-namedview.cpp (+30/-6)
src/sp-namedview.h (+7/-2)
src/sp-path.cpp (+3/-3)
src/sp-rect.cpp (+6/-6)
src/ui/dialog/document-properties.cpp (+687/-450)
src/ui/dialog/document-properties.h (+92/-57)
src/ui/dialog/guides.cpp (+2/-3)
src/ui/dialog/layers.cpp (+1/-2)
src/ui/tools/tool-base.cpp (+1/-1)
src/verbs.cpp (+1/-1)
To merge this branch: bzr merge lp:~inkscape.dev/inkscape/guides-improvements
Reviewer Review Type Date Requested Status
Inkscape Developers Pending
Review via email: mp+116144@code.launchpad.net
To post a comment you must log in.
Revision history for this message
ScislaC (scislac) wrote :

This is currently an ongoing GSOC project and is not ready for merging. This is an outside branch and has not been merged yet.

11501. By Samuel Chase

debugging info

11502. By Samuel Chase

merged with trunk r:11573

11503. By Samuel Chase

debugging information with line numbers

11504. By Samuel Chase

commented out debugging information

11505. By Samuel Chase

removed debugging information. partially working labels.

11506. By Samuel Chase

Fix for Bug #1029033

11507. By Samuel Chase

memory leak fix.

11508. By Samuel Chase

merged with trunk

11509. By Samuel Chase

added two buttons. experimental prototyping. needs a lot of fixing.

11510. By Samuel Chase

removed unnecessary file

11511. By Samuel Chase

added guide-manager.cpp, guide-manager.h. Got inkscape to build.

11512. By Samuel Chase

made guide_manager a pointer.

11513. By Samuel Chase

removed inclusion of header

11514. By Samuel Chase

I can see!

11515. By Samuel Chase

basic guide information displayed in TreeView

11516. By Samuel Chase

added some checking macros.

11517. By Samuel Chase

NULL checks. eye and lock ImageTogglers

11518. By Samuel Chase

cosmetic changes

11519. By Samuel Chase

removed the header-row, and the Guide-no. column

11520. By Samuel Chase

Fixed bug in which guides without labels caused Inkscape to crash.

11521. By Samuel Chase

NULL check for getAttribute

11522. By Samuel Chase

merged with trunk

11523. By Samuel Chase

trying to get the "Delete" button to work

11524. By Samuel Chase

rearrangement of code

11525. By Samuel Chase

The "Delete" button works.

11526. By Samuel Chase

attempt to make the guide-lable editable in-place

11527. By Samuel Chase

revert to r:11525. New approach needed.

11528. By Samuel Chase

basic class design for GuideManager

11529. By Samuel Chase

empty constructor

11530. By Samuel Chase

it buids.

11531. By Samuel Chase

duplicated the code in layer-manager.cpp in guide-manager.cpp and commented it all out

11532. By Samuel Chase

Well, it builds.

11533. By Samuel Chase

implemented destructor, removed some unnecessary commented code

11534. By Samuel Chase

removed more unecessary commented code

11535. By Samuel Chase

merged with trunk

11536. By Samuel Chase

as SPNamedView::connectModified is being used, names changed appropriately

11537. By Samuel Chase

cosmetic changes. The Delete button doesn't work any more

11538. By Samuel Chase

The "Delete" button works again. Also removed some unncessary commented out code

11539. By Samuel Chase

fixed the SP_IS_GUIDE check

11540. By Samuel Chase

implementing _rebuild. Initial stages

11541. By Samuel Chase

still _rebuilding

11542. By Samuel Chase

merged with trunk

11543. By Samuel Chase

rudimentary _rebuild()

11544. By Samuel Chase

merged with trunk

11545. By Samuel Chase

All new guides will be created as "inkscape:guide".

11546. By Samuel Chase

first broken attempt to transform old-style guides to new style guides

11547. By Samuel Chase

more broken things.

11548. By Samuel Chase

Horrible attempt #1.

11549. By Samuel Chase

position and orientation attribute reading code same as that of canvas-guide.cpp. and a few other cleanups

11550. By Samuel Chase

Reading from SVG using streams works

11551. By Samuel Chase

reverted

11552. By Samuel Chase

added comment

11553. By Samuel Chase

merge with trunk

11554. By Samuel Chase

height is read from the document instead of using getHeight(). using sp_repr_set_double makes things a little less ugly.

11555. By Samuel Chase

merge with trunk

11556. By Samuel Chase

added the enable attribute. GC'd the node

11557. By Samuel Chase

sp_namedview_convert_old_guides now has the same arguments as sp_namedview_generate_old_grid, kinda.

11558. By Johan Engelen

enable console output for windows builds

11559. By Johan Engelen

backwards compatibility: convert old-style guides to new-style

11560. By Johan Engelen

guides default enabled

11561. By Samuel Chase

merged with trunk

11562. By Samuel Chase

merged with trunk

11563. By Samuel Chase

merged with trunk

11564. By Johan Engelen

work on changing coord system for grids too. display is good now. snapping is still in old coordsystem

11565. By Johan Engelen

fix grid snapping. i think grids are now in same coord system as everything else. the UI is now awkward, as the origin location does not correspond to what is put on the rulers... (similar to guide dialog (double-click on guide))

11566. By Johan Engelen

1. fix axonomgrid snapping
2. fix alt-drag grid-multiple snapping

11567. By Johan Engelen

merge trunnk.......

11568. By Johan Engelen

correctly move guides and grids when resizing page to drawing/selection

11569. By Samuel Chase

Merge with trunk.

11570. By Samuel Chase

Attempt to merge canvas-guide.cpp with a newer sp-guide.cpp from trunk

11571. By Samuel Chase

Merge with trunk.

11572. By Samuel Chase

Add <glibmm/threads.h> include to make Inkscape build again.

11573. By Samuel Chase

Change sodipodi:guide to inkscape:guide

11574. By Samuel Chase

Merge with trunk.

11575. By Samuel Chase

Merge with trunk

11576. By Samuel Chase

Merge with trunk

11577. By Samuel Chase

Remove warning. Stylistic changes

* Change from sodipodi:guide to inkscape:guide.
  Earlier there was a warning on console "unknown type: sodipodi:guide" when
  the icons.svg file was read. This warning was from factory.h

* Trivial stylistic changes in document-properties.cpp

11578. By Samuel Chase

Update documentation

11579. By Samuel Chase

Fix build error in document-properties.cc

- Change GTK+ code to use GTKMM instead
- Minor stylistic changes

11580. By Samuel Chase

Modularise method by creating helper method

11581. By Samuel Chase

Stylistic Changes

Break long lines
Spaces around infix aritmetic operators

11582. By Samuel Chase

clang-formatt document-properties.cpp

11583. By Samuel Chase

Fix formatting of widget_array[]

11584. By Samuel Chase

Merge with trunk.

11585. By Samuel Chase

Merge with trunk

11586. By Samuel Chase

Refactor populate_guides_list()

- Remove unnecessary checks.
- Remove C-style cast.
- Use more descriptive variable names.
- Fix unrelated documentation formatting.

11587. By Samuel Chase

Implement multiple guide selection and deletion

- Some unrelated stylistic refactoring
- Made some functions private

11588. By Samuel Chase

Fix Undo for guide-multi-delete

- Some unrelated stylistic change.

11589. By Samuel Chase

Remove unnecessary headers

11590. By Samuel Chase

Intermediate GTK3 migration attempt commit

11591. By Samuel Chase

Merge with trunk

11592. By Samuel Chase

Merge with trunk

Unmerged revisions

11592. By Samuel Chase

Merge with trunk

11591. By Samuel Chase

Merge with trunk

11590. By Samuel Chase

Intermediate GTK3 migration attempt commit

11589. By Samuel Chase

Remove unnecessary headers

11588. By Samuel Chase

Fix Undo for guide-multi-delete

- Some unrelated stylistic change.

11587. By Samuel Chase

Implement multiple guide selection and deletion

- Some unrelated stylistic refactoring
- Made some functions private

11586. By Samuel Chase

Refactor populate_guides_list()

- Remove unnecessary checks.
- Remove C-style cast.
- Use more descriptive variable names.
- Fix unrelated documentation formatting.

11585. By Samuel Chase

Merge with trunk

11584. By Samuel Chase

Merge with trunk.

11583. By Samuel Chase

Fix formatting of widget_array[]

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'build.xml'
--- build.xml 2014-09-02 23:51:04 +0000
+++ build.xml 2014-09-23 18:22:24 +0000
@@ -354,13 +354,6 @@
354 <flags>354 <flags>
355 -Wall -Wformat -Werror=format-security -Wextra -Wpointer-arith -Wcast-align -Wsign-compare -Wswitch355 -Wall -Wformat -Werror=format-security -Wextra -Wpointer-arith -Wcast-align -Wsign-compare -Wswitch
356 -Werror=return-type356 -Werror=return-type
357 <!-- - -> -Werror <!-- -->
358 <!-- A list of warnings that should not error *yet*, any help is welcome in fixing the code generating these warnings! -->
359 <!-- libcroco is using guchar where it should use gchar, so we need: --> -Wno-error=pointer-sign
360 -Wno-error=unused-parameter -Wno-error=unused-but-set-variable -Wno-error=strict-overflow -Wno-error=write-strings
361 <!-- Format warnings are obviously bad errors, but with the current old compiler on Windows (gcc 4.6.) we run into a problem with long long ints...
362 The errors can be restored by removing these flags after updating to a newer compiler (soon after 0.91 release hopefully) -->
363 -Wno-error=format -Wno-error=format-extra-args
364 -O2357 -O2
365 -mms-bitfields358 -mms-bitfields
366 -fopenmp359 -fopenmp
@@ -530,7 +523,6 @@
530 stripcommand="${archutil}strip"523 stripcommand="${archutil}strip"
531 objcopycommand="${archutil}objcopy">524 objcopycommand="${archutil}objcopy">
532 <flags>525 <flags>
533 -mwindows
534 -mthreads526 -mthreads
535 </flags>527 </flags>
536 <fileset dir="${build}/obj">528 <fileset dir="${build}/obj">
537529
=== modified file 'doc/HACKING.txt'
--- doc/HACKING.txt 2010-03-20 11:18:53 +0000
+++ doc/HACKING.txt 2014-09-23 18:22:24 +0000
@@ -30,7 +30,7 @@
30of something you'd like to work on. If not, here are just a few ways you30of something you'd like to work on. If not, here are just a few ways you
31can help: 31can help:
3232
33 * Pick a bug, fix it, and send in a patch ("diff -uNrp" or "cvs diff -up")33 * Pick a bug, fix it, and send in a patch ("diff -uNrp" or "bzr diff")
34 * Choose a feature you want to see developed, and make it34 * Choose a feature you want to see developed, and make it
35 * If you speak a language in addition to English, work on your35 * If you speak a language in addition to English, work on your
36 language's i18n file in the po/ directory36 language's i18n file in the po/ directory
3737
=== modified file 'doc/architecture.txt'
--- doc/architecture.txt 2006-01-16 02:36:01 +0000
+++ doc/architecture.txt 2014-09-23 18:22:24 +0000
@@ -159,7 +159,7 @@
159 SPObjectGroup ABSTRACT159 SPObjectGroup ABSTRACT
160 SPNamedView <sodipodi:namedview>160 SPNamedView <sodipodi:namedview>
161 SPClipPath <clipPath>161 SPClipPath <clipPath>
162 SPGuide <sodipodi:guide>162 SPGuide <inkscape:guide>
163 SPPaintServer ABSTRACT163 SPPaintServer ABSTRACT
164 SPGradient ABSTRACT164 SPGradient ABSTRACT
165 SPLinearGradient <linearGradient>165 SPLinearGradient <linearGradient>
166166
=== modified file 'share/icons/icons.svg'
--- share/icons/icons.svg 2014-06-13 16:06:01 +0000
+++ share/icons/icons.svg 2014-09-23 18:22:24 +0000
@@ -866,8 +866,8 @@
866</defs>866</defs>
867<sodipodi:namedview inkscape:guide-bbox="true" inkscape:current-layer="svg1" inkscape:grid-bbox="true" inkscape:pageopacity="1.0000000" pagecolor="#e8e8e4" snaptoguides="true" showguides="true" inkscape:window-y="0" inkscape:window-x="40" inkscape:window-height="745" inkscape:window-width="1326" inkscape:cy="417.9499" inkscape:cx="364.8285" inkscape:zoom="3.343024" gridtolerance="6" snaptogrid="false" showgrid="false" id="base" inkscape:document-units="px" inkscape:grid-points="true" guidetolerance="8" fill="#8ab3de" stroke="#646464" inkscape:object-nodes="false" objecttolerance="11" inkscape:snap-bbox="false" inkscape:snap-nodes="true" inkscape:bbox-nodes="false" inkscape:bbox-paths="false" inkscape:snap-global="false" inkscape:snap-center="false" inkscape:snap-midpoints="false" inkscape:snap-intersection-paths="true" inkscape:object-paths="false" inkscape:snap-object-midpoints="true" inkscape:window-maximized="1" inkscape:snap-grids="true" inkscape:snap-smooth-nodes="false" inkscape:snap-text-baseline="false" inkscape:snap-page="true" inkscape:snap-bbox-midpoints="false" inkscape:snap-bbox-edge-midpoints="false">867<sodipodi:namedview inkscape:guide-bbox="true" inkscape:current-layer="svg1" inkscape:grid-bbox="true" inkscape:pageopacity="1.0000000" pagecolor="#e8e8e4" snaptoguides="true" showguides="true" inkscape:window-y="0" inkscape:window-x="40" inkscape:window-height="745" inkscape:window-width="1326" inkscape:cy="417.9499" inkscape:cx="364.8285" inkscape:zoom="3.343024" gridtolerance="6" snaptogrid="false" showgrid="false" id="base" inkscape:document-units="px" inkscape:grid-points="true" guidetolerance="8" fill="#8ab3de" stroke="#646464" inkscape:object-nodes="false" objecttolerance="11" inkscape:snap-bbox="false" inkscape:snap-nodes="true" inkscape:bbox-nodes="false" inkscape:bbox-paths="false" inkscape:snap-global="false" inkscape:snap-center="false" inkscape:snap-midpoints="false" inkscape:snap-intersection-paths="true" inkscape:object-paths="false" inkscape:snap-object-midpoints="true" inkscape:window-maximized="1" inkscape:snap-grids="true" inkscape:snap-smooth-nodes="false" inkscape:snap-text-baseline="false" inkscape:snap-page="true" inkscape:snap-bbox-midpoints="false" inkscape:snap-bbox-edge-midpoints="false">
868<inkscape:grid type="xygrid" id="grid9252" originx="0px" originy="0px" spacingx="0.5px" spacingy="0.5px" empspacing="2" visible="true" enabled="true" snapvisiblegridlinesonly="true" />868<inkscape:grid type="xygrid" id="grid9252" originx="0px" originy="0px" spacingx="0.5px" spacingy="0.5px" empspacing="2" visible="true" enabled="true" snapvisiblegridlinesonly="true" />
869<sodipodi:guide orientation="0,1" position="630.08101,968.02815" id="guide4946" />869<inkscape:guide orientation="0,1" position="630.08101,968.02815" id="guide4946" />
870<sodipodi:guide orientation="0,1" position="618.47896,943.93157" id="guide4948" />870<inkscape:guide orientation="0,1" position="618.47896,943.93157" id="guide4948" />
871</sodipodi:namedview>871</sodipodi:namedview>
872<metadata id="metadata1810">872<metadata id="metadata1810">
873<rdf:RDF>873<rdf:RDF>
874874
=== modified file 'src/Makefile_insert'
--- src/Makefile_insert 2014-07-31 14:31:01 +0000
+++ src/Makefile_insert 2014-09-23 18:22:24 +0000
@@ -61,6 +61,7 @@
61 gradient-chemistry.cpp gradient-chemistry.h \61 gradient-chemistry.cpp gradient-chemistry.h \
62 gradient-drag.cpp gradient-drag.h \62 gradient-drag.cpp gradient-drag.h \
63 graphlayout.cpp graphlayout.h \63 graphlayout.cpp graphlayout.h \
64 guide-manager.cpp guide-manager.h \
64 guide-snapper.cpp guide-snapper.h \65 guide-snapper.cpp guide-snapper.h \
65 help.cpp help.h \66 help.cpp help.h \
66 helper-fns.h \67 helper-fns.h \
@@ -157,7 +158,6 @@
157 sp-gradient-vector.h \158 sp-gradient-vector.h \
158 sp-guide-attachment.h \159 sp-guide-attachment.h \
159 sp-guide-constraint.h \160 sp-guide-constraint.h \
160 sp-guide.cpp sp-guide.h \
161 sp-image.cpp sp-image.h \161 sp-image.cpp sp-image.h \
162 sp-item.cpp sp-item.h \162 sp-item.cpp sp-item.h \
163 sp-item-group.cpp sp-item-group.h \163 sp-item-group.cpp sp-item-group.h \
164164
=== modified file 'src/attributes.cpp'
--- src/attributes.cpp 2014-08-01 09:04:51 +0000
+++ src/attributes.cpp 2014-09-23 18:22:24 +0000
@@ -124,6 +124,8 @@
124 /* SPGuide */124 /* SPGuide */
125 {SP_ATTR_ORIENTATION, "orientation"},125 {SP_ATTR_ORIENTATION, "orientation"},
126 {SP_ATTR_POSITION, "position"},126 {SP_ATTR_POSITION, "position"},
127 {SP_ATTR_ENABLE, "enable"},
128 {SP_ATTR_GROUP, "group"},
127 /* SPImage */129 /* SPImage */
128 {SP_ATTR_X, "x"},130 {SP_ATTR_X, "x"},
129 {SP_ATTR_Y, "y"},131 {SP_ATTR_Y, "y"},
130132
=== modified file 'src/attributes.h'
--- src/attributes.h 2014-08-01 09:04:51 +0000
+++ src/attributes.h 2014-09-23 18:22:24 +0000
@@ -125,6 +125,8 @@
125 /* SPGuide */125 /* SPGuide */
126 SP_ATTR_ORIENTATION,126 SP_ATTR_ORIENTATION,
127 SP_ATTR_POSITION,127 SP_ATTR_POSITION,
128 SP_ATTR_ENABLE,
129 SP_ATTR_GROUP,
128 /* SPImage */130 /* SPImage */
129 SP_ATTR_X,131 SP_ATTR_X,
130 SP_ATTR_Y,132 SP_ATTR_Y,
131133
=== modified file 'src/box3d.cpp'
--- src/box3d.cpp 2014-07-22 19:15:15 +0000
+++ src/box3d.cpp 2014-09-23 18:22:24 +0000
@@ -31,7 +31,7 @@
31#include "persp3d-reference.h"31#include "persp3d-reference.h"
32#include "uri.h"32#include "uri.h"
33#include <2geom/line.h>33#include <2geom/line.h>
34#include "sp-guide.h"34#include "display/canvas-guide.h"
35#include "sp-namedview.h"35#include "sp-namedview.h"
36#include "preferences.h"36#include "preferences.h"
3737
3838
=== modified file 'src/desktop-events.cpp'
--- src/desktop-events.cpp 2014-07-22 19:16:13 +0000
+++ src/desktop-events.cpp 2014-09-23 18:22:24 +0000
@@ -34,11 +34,15 @@
34#include "document-undo.h"34#include "document-undo.h"
35#include "ui/tools/tool-base.h"35#include "ui/tools/tool-base.h"
36#include "helper/action.h"36#include "helper/action.h"
37// #include "helper/unit-menu.h"
38// #include "helper/units.h"
39#include "helper/geom.h"
37#include "message-context.h"40#include "message-context.h"
38#include "preferences.h"41#include "preferences.h"
39#include "snap.h"42#include "snap.h"
40#include "display/sp-canvas.h"43#include "display/sp-canvas.h"
41#include "sp-guide.h"44#include "display/canvas-guide.h"
45// #include "sp-metrics.h"
42#include "sp-namedview.h"46#include "sp-namedview.h"
43#include "tools-switch.h"47#include "tools-switch.h"
44#include "verbs.h"48#include "verbs.h"
@@ -49,7 +53,7 @@
4953
50static void snoop_extended(GdkEvent* event, SPDesktop *desktop);54static void snoop_extended(GdkEvent* event, SPDesktop *desktop);
51static void init_extended();55static void init_extended();
52void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem *guide, Geom::Point &event_dt, Geom::Point &normal);56void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem *guide, Geom::Point &event_dt, Geom::Point &normal_dt);
5357
54/* Root item handler */58/* Root item handler */
5559
@@ -74,7 +78,7 @@
74 return sp_event_context_root_handler(desktop->event_context, event);78 return sp_event_context_root_handler(desktop->event_context, event);
75}79}
7680
77static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw, bool horiz)81static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw, bool horiz_ruler)
78{82{
79 static bool clicked = false;83 static bool clicked = false;
80 static bool dragged = false;84 static bool dragged = false;
@@ -84,7 +88,7 @@
84 static gint xp = 0, yp = 0; // where drag started88 static gint xp = 0, yp = 0; // where drag started
8589
86 SPDesktop *desktop = dtw->desktop;90 SPDesktop *desktop = dtw->desktop;
87 GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(dtw->canvas));91 GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(dtw->canvas));
8892
89 gint width, height;93 gint width, height;
9094
@@ -94,7 +98,7 @@
94 gdk_window_get_geometry(window, NULL /*x*/, NULL /*y*/, &width, &height);98 gdk_window_get_geometry(window, NULL /*x*/, NULL /*y*/, &width, &height);
95#else99#else
96 gdk_window_get_pointer(window, &wx, &wy, NULL);100 gdk_window_get_pointer(window, &wx, &wy, NULL);
97 gdk_window_get_geometry(window, NULL /*x*/, NULL /*y*/, &width, &height, NULL/*depth*/);101 gdk_window_get_geometry(window, NULL /*x*/, NULL /*y*/, &width, &height, NULL /*depth*/);
98#endif102#endif
99 103
100 Geom::Point const event_win(wx, wy);104 Geom::Point const event_win(wx, wy);
@@ -110,14 +114,16 @@
110114
111 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));115 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
112 Geom::Point const event_dt(desktop->w2d(event_w));116 Geom::Point const event_dt(desktop->w2d(event_w));
117 Geom::Point const event_doc(desktop->w2doc(event_w));
113118
114 // calculate the normal of the guidelines when dragged from the edges of rulers.119 // calculate the normal of the guidelines when dragged from the edges of rulers.
115 Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright120 Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright
116 Geom::Point normal_tr_to_bl(1.,1.); //topright to bottomleft121 Geom::Point normal_tr_to_bl(1.,1.); //topright to bottomleft
117 normal_bl_to_tr.normalize();122 normal_bl_to_tr.normalize();
118 normal_tr_to_bl.normalize();123 normal_tr_to_bl.normalize();
124
119 Inkscape::CanvasGrid * grid = sp_namedview_get_first_enabled_grid(desktop->namedview);125 Inkscape::CanvasGrid * grid = sp_namedview_get_first_enabled_grid(desktop->namedview);
120 if (grid){126 if (grid) {
121 if (grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) {127 if (grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) {
122 Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast<Inkscape::CanvasAxonomGrid *>(grid);128 Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast<Inkscape::CanvasAxonomGrid *>(grid);
123 if (event->button.state & GDK_CONTROL_MASK) {129 if (event->button.state & GDK_CONTROL_MASK) {
@@ -130,25 +136,48 @@
130 }136 }
131 }137 }
132 }138 }
133 if (horiz) {139
140 /*
141
142 The following if-else block determines whether the guides created are horizontal,
143 vertical or angled.
144
145 Horizontal guides are created by clicked and dragging from the ruler on the left,
146 vertical guides from the ruler on top and diagonal guides by clicking and
147 dragging within 50 px of all the ends of the guides.
148
149 horiz_ruler: true when the mouse click occurs at the ruler at the top, and false
150 for the ruler at the left.
151
152 Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright (desktop co-ords)
153 The vector (-1, 1) is a normal for a topleft->bottomright guide in document
154 co-ordinates.
155
156 Geom::Point normal_tr_to_bl(1.,1.); //topright to bottomleft (desktop co-ords)
157 The vector (1, 1) is a normal for a bottomleft->topright guide in document
158 co-ordinates.
159
160 */
161
162 if (horiz_ruler) {
134 if (wx < 50) {163 if (wx < 50) {
135 normal = normal_bl_to_tr;164 normal = normal_tr_to_bl;
136 } else if (wx > width - 50) {165 } else if (wx > width - 50) {
137 normal = normal_tr_to_bl;166 normal = normal_bl_to_tr;
138 } else {167 } else {
139 normal = Geom::Point(0.,1.);168 normal = Geom::Point(0.,1.);
140 }169 }
141 } else {170 } else {
142 if (wy < 50) {171 if (wy < 50) {
143 normal = normal_bl_to_tr;172 normal = normal_tr_to_bl;
144 } else if (wy > height - 50) {173 } else if (wy > height - 50) {
145 normal = normal_tr_to_bl;174 normal = normal_bl_to_tr;
146 } else {175 } else {
147 normal = Geom::Point(1.,0.);176 normal = Geom::Point(1.,0.);
148 }177 }
149 }178 }
150179
151 guide = sp_guideline_new(desktop->guides, NULL, event_dt, normal);180 guide = sp_guideline_new(desktop->guides, NULL, event_doc, normal);
152 sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor);181 sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor);
153182
154#if GTK_CHECK_VERSION(3,0,0)183#if GTK_CHECK_VERSION(3,0,0)
@@ -156,12 +185,12 @@
156 gtk_widget_get_window(widget), 185 gtk_widget_get_window(widget),
157 GDK_OWNERSHIP_NONE,186 GDK_OWNERSHIP_NONE,
158 FALSE,187 FALSE,
159 (GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),188 (GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),
160 NULL,189 NULL,
161 event->button.time);190 event->button.time);
162#else191#else
163 gdk_pointer_grab(gtk_widget_get_window (widget), FALSE,192 gdk_pointer_grab(gtk_widget_get_window (widget), FALSE,
164 (GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),193 (GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),
165 NULL, NULL,194 NULL, NULL,
166 event->button.time);195 event->button.time);
167#endif196#endif
@@ -171,7 +200,8 @@
171 if (clicked) {200 if (clicked) {
172 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));201 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
173 Geom::Point event_dt(desktop->w2d(event_w));202 Geom::Point event_dt(desktop->w2d(event_w));
174203 Geom::Point event_doc(desktop->w2doc(event_w));
204
175 Inkscape::Preferences *prefs = Inkscape::Preferences::get();205 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
176 gint tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);206 gint tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
177 if ( ( abs( (gint) event->motion.x - xp ) < tolerance )207 if ( ( abs( (gint) event->motion.x - xp ) < tolerance )
@@ -182,15 +212,23 @@
182 dragged = true;212 dragged = true;
183213
184 // explicitly show guidelines; if I draw a guide, I want them on214 // explicitly show guidelines; if I draw a guide, I want them on
185 if ((horiz ? wy : wx) >= 0) {215 if ((horiz_ruler ? wy : wx) >= 0) {
186 desktop->namedview->setGuides(true);216 desktop->namedview->setGuides(true);
187 }217 }
188218
189 if (!(event->motion.state & GDK_SHIFT_MASK)) {219 if (!(event->motion.state & GDK_SHIFT_MASK)) {
190 sp_dt_ruler_snap_new_guide(desktop, guide, event_dt, normal);220 // FIXME: snapping will need to be fixed later.
221 Geom::Point normal_dt = transform_normal(normal, desktop->doc2dt());
222 sp_dt_ruler_snap_new_guide(desktop, guide, event_dt, normal_dt);
223 // sp_dt_ruler_snap_new_guide calls a function that changes the values of
224 // normal and event_dt. This is why the variables holding the document
225 // co-ordinate values need to be updated.
226 event_doc = desktop->dt2doc(event_dt);
227 normal = transform_normal(normal_dt, desktop->dt2doc());
191 }228 }
229
192 sp_guideline_set_normal(SP_GUIDELINE(guide), normal);230 sp_guideline_set_normal(SP_GUIDELINE(guide), normal);
193 sp_guideline_set_position(SP_GUIDELINE(guide), event_dt);231 sp_guideline_set_position(SP_GUIDELINE(guide), event_doc);
194232
195 desktop->set_coordinate_status(event_dt);233 desktop->set_coordinate_status(event_dt);
196 }234 }
@@ -206,28 +244,41 @@
206#endif244#endif
207245
208 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));246 Geom::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
247
209 Geom::Point event_dt(desktop->w2d(event_w));248 Geom::Point event_dt(desktop->w2d(event_w));
249 Geom::Point event_doc(desktop->w2doc(event_w));
210250
211 if (!(event->button.state & GDK_SHIFT_MASK)) {251 if (!(event->button.state & GDK_SHIFT_MASK)) {
212 sp_dt_ruler_snap_new_guide(desktop, guide, event_dt, normal);252 Geom::Point normal_dt = transform_normal(normal, desktop->doc2dt());
253 sp_dt_ruler_snap_new_guide(desktop, guide, event_dt, normal_dt);
254 // sp_dt_ruler_snap_new_guide calls a function that changes the values of
255 // normal and event_dt. This is why the variables holding the document
256 // co-ordinate values need to be updated.
257 event_doc = desktop->dt2doc(event_dt);
258 normal = transform_normal(normal_dt, desktop->dt2doc());
213 }259 }
214260
215 sp_canvas_item_destroy(guide);261 sp_canvas_item_destroy(guide);
216 guide = NULL;262 guide = NULL;
217 if ((horiz ? wy : wx) >= 0) {263 if ((horiz_ruler ? wy : wx) >= 0) {
218 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();264 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
219 Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");265 Inkscape::XML::Node *repr = NULL;
266
267 repr = xml_doc->createElement("inkscape:guide");
268
220 sp_repr_set_point(repr, "orientation", normal);269 sp_repr_set_point(repr, "orientation", normal);
221 sp_repr_set_point(repr, "position", event_dt);270 sp_repr_set_point(repr, "position", event_doc);
271 sp_repr_set_boolean(repr, "enable", true);
272 repr->setAttribute("group", "default");
222 desktop->namedview->appendChild(repr);273 desktop->namedview->appendChild(repr);
223 Inkscape::GC::release(repr);274 Inkscape::GC::release(repr);
224 DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE,275 DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE,
225 _("Create guide"));276 _("Create guide"));
226 }277 }
227 desktop->set_coordinate_status(event_dt);278 desktop->set_coordinate_status(event_dt);
228279
229 if (!dragged) {280 if (!dragged) {
230 // Ruler click (without drag) toggle the guide visibility on and off281 // Clicking on the ruler (without dragging) toggles the guide visibility on and off
231 Inkscape::XML::Node *repr = desktop->namedview->getRepr();282 Inkscape::XML::Node *repr = desktop->namedview->getRepr();
232 sp_namedview_toggle_guides(sp_desktop_document(desktop), repr);283 sp_namedview_toggle_guides(sp_desktop_document(desktop), repr);
233 284
@@ -246,7 +297,9 @@
246int sp_dt_hruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)297int sp_dt_hruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
247{298{
248 if (event->type == GDK_MOTION_NOTIFY) {299 if (event->type == GDK_MOTION_NOTIFY) {
249 sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HRULER);300 sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget,
301 (gpointer) dtw, (GdkEventMotion *) event,
302 Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HRULER);
250 }303 }
251 return sp_dt_ruler_event(widget, event, dtw, true);304 return sp_dt_ruler_event(widget, event, dtw, true);
252}305}
@@ -254,16 +307,18 @@
254int sp_dt_vruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)307int sp_dt_vruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
255{308{
256 if (event->type == GDK_MOTION_NOTIFY) {309 if (event->type == GDK_MOTION_NOTIFY) {
257 sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_VRULER);310 sp_event_context_snap_delay_handler(dtw->desktop->event_context,
311 (gpointer) widget, (gpointer) dtw, (GdkEventMotion *) event,
312 Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_VRULER);
258 }313 }
259 return sp_dt_ruler_event(widget, event, dtw, false);314 return sp_dt_ruler_event(widget, event, dtw, false);
260}315}
261316
262static Geom::Point drag_origin;317static Geom::Point drag_origin;
263static SPGuideDragType drag_type = SP_DRAG_NONE;318static SPGuideDragType drag_type = SP_DRAG_NONE;
264//static bool reset_drag_origin = false; // when Ctrl is pressed while dragging, this is used to trigger resetting of the319//static bool reset_drag_origin = false;
265// // drag origin to that location so that constrained movement is more intuitive320// when Ctrl is pressed while dragging, this is used to trigger resetting of the
266321// drag origin to that location so that constrained movement is more intuitive
267// Min distance from anchor to initiate rotation, measured in screenpixels322// Min distance from anchor to initiate rotation, measured in screenpixels
268#define tol 40.0323#define tol 40.0
269324
@@ -274,7 +329,7 @@
274329
275 SPGuide *guide = SP_GUIDE(data);330 SPGuide *guide = SP_GUIDE(data);
276 SPDesktop *desktop = static_cast<SPDesktop*>(g_object_get_data(G_OBJECT(item->canvas), "SPDesktop"));331 SPDesktop *desktop = static_cast<SPDesktop*>(g_object_get_data(G_OBJECT(item->canvas), "SPDesktop"));
277332
278 switch (event->type) {333 switch (event->type) {
279 case GDK_2BUTTON_PRESS:334 case GDK_2BUTTON_PRESS:
280 if (event->button.button == 1) {335 if (event->button.button == 1) {
@@ -289,7 +344,7 @@
289 if (event->button.button == 1) {344 if (event->button.button == 1) {
290 Geom::Point const event_w(event->button.x, event->button.y);345 Geom::Point const event_w(event->button.x, event->button.y);
291 Geom::Point const event_dt(desktop->w2d(event_w));346 Geom::Point const event_dt(desktop->w2d(event_w));
292347
293 // Due to the tolerance allowed when grabbing a guide, event_dt will generally348 // Due to the tolerance allowed when grabbing a guide, event_dt will generally
294 // be close to the guide but not just exactly on it. The drag origin calculated349 // be close to the guide but not just exactly on it. The drag origin calculated
295 // here must be exactly on the guide line though, otherwise350 // here must be exactly on the guide line though, otherwise
@@ -321,9 +376,9 @@
321 break;376 break;
322 case GDK_MOTION_NOTIFY:377 case GDK_MOTION_NOTIFY:
323 if (drag_type != SP_DRAG_NONE) {378 if (drag_type != SP_DRAG_NONE) {
324 Geom::Point const motion_w(event->motion.x,379 Geom::Point const motion_w(event->motion.x, event->motion.y);
325 event->motion.y);
326 Geom::Point motion_dt(desktop->w2d(motion_w));380 Geom::Point motion_dt(desktop->w2d(motion_w));
381 Geom::Point motion_doc(desktop->w2doc(motion_w));
327382
328 sp_event_context_snap_delay_handler(desktop->event_context, (gpointer) item, data, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HANDLER);383 sp_event_context_snap_delay_handler(desktop->event_context, (gpointer) item, data, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HANDLER);
329384
@@ -336,31 +391,46 @@
336 // be forced to be on the guide. If we don't snap however, then391 // be forced to be on the guide. If we don't snap however, then
337 // the origin should still be constrained to the guide. So let's do392 // the origin should still be constrained to the guide. So let's do
338 // that explicitly first:393 // that explicitly first:
394
395 // guideConstrainedSnap modifies it's arguments. Points in document
396 // co-ordinates have to be passed to the guide-snapping functions because they
397 // operate on points in desktop co-ordinates.
398
339 Geom::Line line(guide->point_on_line, guide->angle());399 Geom::Line line(guide->point_on_line, guide->angle());
340 Geom::Coord t = line.nearestPoint(motion_dt);400 Geom::Coord t = line.nearestPoint(motion_doc);
341 motion_dt = line.pointAt(t);401 motion_doc = line.pointAt(t);
342 if (!(event->motion.state & GDK_SHIFT_MASK)) {402 if (!(event->motion.state & GDK_SHIFT_MASK)) {
343 m.guideConstrainedSnap(motion_dt, *guide);403 m.guideConstrainedSnap(motion_dt, *guide);
344 }404 }
345 } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {405 } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {
346 // cannot use shift here to disable snapping, because we already use it for rotating the guide406 // cannot use shift here to disable snapping, because we already use it for rotating the guide
407
408 Geom::Point point_on_line_dt = desktop->doc2dt(guide->point_on_line);
409 Geom::Point normal_to_line_dt = transform_normal(guide->normal_to_line, desktop->doc2dt());
410
347 if (drag_type == SP_DRAG_ROTATE) {411 if (drag_type == SP_DRAG_ROTATE) {
348 m.guideFreeSnap(motion_dt, guide->point_on_line, true, false);412 m.guideFreeSnap(motion_dt, point_on_line_dt, true, false);
349 } else {413 } else {
350 m.guideFreeSnap(motion_dt, guide->normal_to_line, false, true);414 m.guideFreeSnap(motion_dt, normal_to_line_dt, false, true);
351 }415 }
416
417 guide->point_on_line = desktop->dt2doc(point_on_line_dt);
418 guide->normal_to_line = transform_normal(normal_to_line_dt, desktop->dt2doc());
419
352 }420 }
353 m.unSetup();421 m.unSetup();
354422
423 motion_doc = desktop->dt2doc(motion_dt);
424
355 switch (drag_type) {425 switch (drag_type) {
356 case SP_DRAG_TRANSLATE:426 case SP_DRAG_TRANSLATE:
357 {427 {
358 sp_guide_moveto(*guide, motion_dt, false);428 sp_guide_moveto(*guide, motion_doc, false);
359 break;429 break;
360 }430 }
361 case SP_DRAG_ROTATE:431 case SP_DRAG_ROTATE:
362 {432 {
363 Geom::Point pt = motion_dt - guide->point_on_line;433 Geom::Point pt = motion_doc - guide->point_on_line;
364 Geom::Angle angle(pt);434 Geom::Angle angle(pt);
365 if (event->motion.state & GDK_CONTROL_MASK) {435 if (event->motion.state & GDK_CONTROL_MASK) {
366 Inkscape::Preferences *prefs = Inkscape::Preferences::get();436 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -383,7 +453,7 @@
383 }453 }
384 case SP_DRAG_MOVE_ORIGIN:454 case SP_DRAG_MOVE_ORIGIN:
385 {455 {
386 sp_guide_moveto(*guide, motion_dt, false);456 sp_guide_moveto(*guide, motion_doc, false);
387 break;457 break;
388 }458 }
389 case SP_DRAG_NONE:459 case SP_DRAG_NONE:
@@ -404,6 +474,7 @@
404 Geom::Point const event_w(event->button.x,474 Geom::Point const event_w(event->button.x,
405 event->button.y);475 event->button.y);
406 Geom::Point event_dt(desktop->w2d(event_w));476 Geom::Point event_dt(desktop->w2d(event_w));
477 Geom::Point event_doc(desktop->w2doc(event_w));
407478
408 SnapManager &m = desktop->namedview->snap_manager;479 SnapManager &m = desktop->namedview->snap_manager;
409 m.setup(desktop, true, NULL, NULL, guide);480 m.setup(desktop, true, NULL, NULL, guide);
@@ -412,32 +483,43 @@
412 // be forced to be on the guide. If we don't snap however, then483 // be forced to be on the guide. If we don't snap however, then
413 // the origin should still be constrained to the guide. So let's484 // the origin should still be constrained to the guide. So let's
414 // do that explicitly first:485 // do that explicitly first:
415 Geom::Line line(guide->point_on_line, guide->angle());486 Geom::Line line(desktop->doc2dt(guide->point_on_line), guide->angle());
416 Geom::Coord t = line.nearestPoint(event_dt);487 Geom::Coord t = line.nearestPoint(event_dt);
417 event_dt = line.pointAt(t);488 event_dt = line.pointAt(t);
489
418 if (!(event->button.state & GDK_SHIFT_MASK)) {490 if (!(event->button.state & GDK_SHIFT_MASK)) {
419 m.guideConstrainedSnap(event_dt, *guide);491 m.guideConstrainedSnap(event_dt, *guide);
420 }492 }
421 } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {493 } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) {
422 // cannot use shift here to disable snapping, because we already use it for rotating the guide494 // cannot use shift here to disable snapping, because we already use it for rotating the guide
495
496 Geom::Point point_on_line_dt = desktop->doc2dt(guide->point_on_line);
497 Geom::Point normal_to_line_dt = transform_normal(guide->normal_to_line, desktop->doc2dt());
498
423 if (drag_type == SP_DRAG_ROTATE) {499 if (drag_type == SP_DRAG_ROTATE) {
424 m.guideFreeSnap(event_dt, guide->point_on_line, true, false);500 m.guideFreeSnap(event_dt, point_on_line_dt, true, false);
425 } else {501 } else {
426 m.guideFreeSnap(event_dt, guide->normal_to_line, false, true);502 m.guideFreeSnap(event_dt, normal_to_line_dt, false, true);
427 }503 }
504
505 guide->point_on_line = desktop->dt2doc(point_on_line_dt);
506 guide->normal_to_line = transform_normal(normal_to_line_dt, desktop->dt2doc());
428 }507 }
508
429 m.unSetup();509 m.unSetup();
430510
511 event_doc = desktop->dt2doc(event_dt);
512
431 if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {513 if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
432 switch (drag_type) {514 switch (drag_type) {
433 case SP_DRAG_TRANSLATE:515 case SP_DRAG_TRANSLATE:
434 {516 {
435 sp_guide_moveto(*guide, event_dt, true);517 sp_guide_moveto(*guide, event_doc, true);
436 break;518 break;
437 }519 }
438 case SP_DRAG_ROTATE:520 case SP_DRAG_ROTATE:
439 {521 {
440 Geom::Point pt = event_dt - guide->point_on_line;522 Geom::Point pt = event_doc - guide->point_on_line;
441 Geom::Angle angle(pt);523 Geom::Angle angle(pt);
442 if (event->motion.state & GDK_CONTROL_MASK) {524 if (event->motion.state & GDK_CONTROL_MASK) {
443 Inkscape::Preferences *prefs = Inkscape::Preferences::get();525 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -455,12 +537,13 @@
455 }537 }
456 }538 }
457 }539 }
540
458 sp_guide_set_normal(*guide, Geom::Point::polar(angle).cw(), true);541 sp_guide_set_normal(*guide, Geom::Point::polar(angle).cw(), true);
459 break;542 break;
460 }543 }
461 case SP_DRAG_MOVE_ORIGIN:544 case SP_DRAG_MOVE_ORIGIN:
462 {545 {
463 sp_guide_moveto(*guide, event_dt, true);546 sp_guide_moveto(*guide, event_doc, true);
464 break;547 break;
465 }548 }
466 case SP_DRAG_NONE:549 case SP_DRAG_NONE:
@@ -609,7 +692,7 @@
609 if ( devName692 if ( devName
610 && (avoidName != devName)693 && (avoidName != devName)
611 && (devSrc != GDK_SOURCE_MOUSE) ) {694 && (devSrc != GDK_SOURCE_MOUSE) ) {
612// g_message("Adding '%s' as [%d]", devName, devSrc);695 // g_message("Adding '%s' as [%d]", devName, devSrc);
613696
614 // Set the initial tool for the device697 // Set the initial tool for the device
615 switch ( devSrc ) {698 switch ( devSrc ) {
@@ -714,10 +797,11 @@
714}797}
715798
716799
717void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem * /*guide*/, Geom::Point &event_dt, Geom::Point &normal)800void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem * /*guide*/, Geom::Point &event_dt, Geom::Point &normal_dt)
718{801{
719 SnapManager &m = desktop->namedview->snap_manager;802 SnapManager &m = desktop->namedview->snap_manager;
720 m.setup(desktop);803 m.setup(desktop);
804
721 // We're dragging a brand new guide, just pulled of the rulers seconds ago. When snapping to a805 // We're dragging a brand new guide, just pulled of the rulers seconds ago. When snapping to a
722 // path this guide will change it slope to become either tangential or perpendicular to that path. It's806 // path this guide will change it slope to become either tangential or perpendicular to that path. It's
723 // therefore not useful to try tangential or perpendicular snapping, so this will be disabled temporarily807 // therefore not useful to try tangential or perpendicular snapping, so this will be disabled temporarily
@@ -728,17 +812,17 @@
728 // We only have a temporary guide which is not stored in our document yet.812 // We only have a temporary guide which is not stored in our document yet.
729 // Because the guide snapper only looks in the document for guides to snap to,813 // Because the guide snapper only looks in the document for guides to snap to,
730 // we don't have to worry about a guide snapping to itself here814 // we don't have to worry about a guide snapping to itself here
731 Geom::Point normal_orig = normal;815 Geom::Point normal_orig = normal_dt;
732 m.guideFreeSnap(event_dt, normal, false, false);816 m.guideFreeSnap(event_dt, normal_dt, false, false);
733 // After snapping, both event_dt and normal have been modified accordingly; we'll take the normal (of the817 // After snapping, both event_dt and normal have been modified accordingly; we'll take the normal (of the
734 // curve we snapped to) to set the normal the guide. And rotate it by 90 deg. if needed818 // curve we snapped to) to set the normal the guide. And rotate it by 90 deg. if needed
735 if (pref_perp) { // Perpendicular snapping to paths is requested by the user, so let's do that819 if (pref_perp) { // Perpendicular snapping to paths is requested by the user, so let's do that
736 if (normal != normal_orig) {820 if (normal_dt != normal_orig) {
737 normal = Geom::rot90(normal);821 normal_dt = Geom::rot90(normal_dt);
738 }822 }
739 }823 }
740 if (!(pref_tang || pref_perp)) { // if we don't want to snap either perpendicularly or tangentially, then824 if (!(pref_tang || pref_perp)) { // if we don't want to snap either perpendicularly or tangentially, then
741 normal = normal_orig; // we must restore the normal to it's original state825 normal_dt = normal_orig; // we must restore the normal to it's original state
742 }826 }
743 // Restore the preferences827 // Restore the preferences
744 m.snapprefs.setSnapPerp(pref_perp);828 m.snapprefs.setSnapPerp(pref_perp);
745829
=== modified file 'src/desktop.cpp'
--- src/desktop.cpp 2014-04-20 00:36:33 +0000
+++ src/desktop.cpp 2014-09-23 18:22:24 +0000
@@ -60,6 +60,7 @@
60#include "layer-fns.h"60#include "layer-fns.h"
61#include "layer-manager.h"61#include "layer-manager.h"
62#include "layer-model.h"62#include "layer-model.h"
63#include "guide-manager.h"
63#include "macros.h"64#include "macros.h"
64#include "message-context.h"65#include "message-context.h"
65#include "message-stack.h"66#include "message-stack.h"
@@ -101,6 +102,7 @@
101 selection( 0 ),102 selection( 0 ),
102 event_context( 0 ),103 event_context( 0 ),
103 layer_manager( 0 ),104 layer_manager( 0 ),
105 guide_manager( 0 ),
104 event_log( 0 ),106 event_log( 0 ),
105 temporary_item_list( 0 ),107 temporary_item_list( 0 ),
106 snapindicator( 0 ),108 snapindicator( 0 ),
@@ -241,11 +243,12 @@
241 // will not work (the snap indicator is on top of the node handler; is the snapindicator243 // will not work (the snap indicator is on top of the node handler; is the snapindicator
242 // being selected? or does it intercept some of the events that should have gone to the244 // being selected? or does it intercept some of the events that should have gone to the
243 // node handler? see bug https://bugs.launchpad.net/inkscape/+bug/414142)245 // node handler? see bug https://bugs.launchpad.net/inkscape/+bug/414142)
246
244 gridgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);247 gridgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
245 guides = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);248 guides = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
246 sketch = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);249 sketch = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
247 tempgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);250 tempgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
248 controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);251 controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
249252
250 // Set the select tool as the active tool.253 // Set the select tool as the active tool.
251 set_event_context2("/tools/select");254 set_event_context2("/tools/select");
@@ -272,6 +275,8 @@
272 /* Connect event for page resize */275 /* Connect event for page resize */
273 _doc2dt[5] = document->getHeight().value("px");276 _doc2dt[5] = document->getHeight().value("px");
274 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);277 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);
278 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (gridgroup), _doc2dt);
279 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (guides), _doc2dt);
275280
276 _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));281 _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));
277282
@@ -284,8 +289,10 @@
284 }289 }
285290
286 namedview->show(this);291 namedview->show(this);
287 /* Ugly hack */292 /* Ugly hack */
293
288 activate_guides (true);294 activate_guides (true);
295
289 /* Ugly hack */296 /* Ugly hack */
290 _namedview_modified (namedview, SP_OBJECT_MODIFIED_FLAG, this);297 _namedview_modified (namedview, SP_OBJECT_MODIFIED_FLAG, this);
291298
@@ -331,6 +338,7 @@
331 /* setup LayerManager */338 /* setup LayerManager */
332 // (Setting up after the connections are all in place, as it may use some of them)339 // (Setting up after the connections are all in place, as it may use some of them)
333 layer_manager = new Inkscape::LayerManager( this );340 layer_manager = new Inkscape::LayerManager( this );
341 guide_manager = new Inkscape::GuideManager( this );
334342
335 showGrids(namedview->grids_visible, false);343 showGrids(namedview->grids_visible, false);
336344
@@ -822,8 +830,8 @@
822 int clear = FALSE;830 int clear = FALSE;
823 if (!Geom::are_near(newscale, scale, Geom::EPSILON * scale)) {831 if (!Geom::are_near(newscale, scale, Geom::EPSILON * scale)) {
824 // zoom changed - set new zoom factors832 // zoom changed - set new zoom factors
825 _d2w = Geom::Scale(newscale, -newscale);833 _d2w = Geom::Scale(newscale, -newscale);
826 _w2d = Geom::Scale(1/newscale, 1/-newscale);834 _w2d = Geom::Scale(1/newscale, 1/-newscale);
827 redrawDesktop();835 redrawDesktop();
828 clear = TRUE;836 clear = TRUE;
829 zoomChanged = true;837 zoomChanged = true;
@@ -1618,6 +1626,8 @@
1618{1626{
1619 _doc2dt[5] = height;1627 _doc2dt[5] = height;
1620 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);1628 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);
1629 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (gridgroup), _doc2dt);
1630 sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (guides), _doc2dt);
1621 Geom::Rect const a(Geom::Point(0, 0), Geom::Point(width, height));1631 Geom::Rect const a(Geom::Point(0, 0), Geom::Point(width, height));
1622 SP_CTRLRECT(page)->setRectangle(a);1632 SP_CTRLRECT(page)->setRectangle(a);
1623 SP_CTRLRECT(page_border)->setRectangle(a);1633 SP_CTRLRECT(page_border)->setRectangle(a);
@@ -1803,12 +1813,22 @@
1803 return p * _w2d;1813 return p * _w2d;
1804}1814}
18051815
1816Geom::Affine SPDesktop::w2doc() const
1817{
1818 return w2d() * dt2doc();
1819}
1820
1821Geom::Point SPDesktop::w2doc(Geom::Point const &p) const
1822{
1823 return p * w2d() * dt2doc();
1824}
1825
1806Geom::Point SPDesktop::d2w(Geom::Point const &p) const1826Geom::Point SPDesktop::d2w(Geom::Point const &p) const
1807{1827{
1808 return p * _d2w;1828 return p * _d2w;
1809}1829}
18101830
1811Geom::Affine SPDesktop::doc2dt() const1831Geom::Affine SPDesktop::doc2dt () const
1812{1832{
1813 return _doc2dt;1833 return _doc2dt;
1814}1834}
18151835
=== modified file 'src/desktop.h'
--- src/desktop.h 2014-05-15 21:51:32 +0000
+++ src/desktop.h 2014-09-23 18:22:24 +0000
@@ -78,6 +78,7 @@
78 class MessageContext;78 class MessageContext;
79 class Selection;79 class Selection;
80 class LayerManager;80 class LayerManager;
81 class GuideManager;
81 class EventLog;82 class EventLog;
82 namespace UI {83 namespace UI {
83 namespace Dialog {84 namespace Dialog {
@@ -142,6 +143,7 @@
142 Inkscape::Selection *selection;143 Inkscape::Selection *selection;
143 Inkscape::UI::Tools::ToolBase *event_context;144 Inkscape::UI::Tools::ToolBase *event_context;
144 Inkscape::LayerManager *layer_manager;145 Inkscape::LayerManager *layer_manager;
146 Inkscape::GuideManager *guide_manager;
145 Inkscape::EventLog *event_log;147 Inkscape::EventLog *event_log;
146 DocumentInterface *dbus_document_interface;148 DocumentInterface *dbus_document_interface;
147 Inkscape::Display::TemporaryItemList *temporary_item_list;149 Inkscape::Display::TemporaryItemList *temporary_item_list;
@@ -404,6 +406,8 @@
404406
405 Geom::Affine w2d() const; //transformation from window to desktop coordinates (used for zooming)407 Geom::Affine w2d() const; //transformation from window to desktop coordinates (used for zooming)
406 Geom::Point w2d(Geom::Point const &p) const;408 Geom::Point w2d(Geom::Point const &p) const;
409 Geom::Affine w2doc() const;
410 Geom::Point w2doc(Geom::Point const &p) const;
407 Geom::Point d2w(Geom::Point const &p) const;411 Geom::Point d2w(Geom::Point const &p) const;
408 Geom::Affine doc2dt() const;412 Geom::Affine doc2dt() const;
409 Geom::Affine dt2doc() const;413 Geom::Affine dt2doc() const;
410414
=== modified file 'src/display/Makefile_insert'
--- src/display/Makefile_insert 2014-03-27 01:33:44 +0000
+++ src/display/Makefile_insert 2014-09-23 18:22:24 +0000
@@ -15,6 +15,8 @@
15 display/canvas-bpath.h \15 display/canvas-bpath.h \
16 display/canvas-grid.cpp \16 display/canvas-grid.cpp \
17 display/canvas-grid.h \17 display/canvas-grid.h \
18 display/canvas-guide.cpp \
19 display/canvas-guide.h \
18 display/canvas-temporary-item.cpp \20 display/canvas-temporary-item.cpp \
19 display/canvas-temporary-item.h \21 display/canvas-temporary-item.h \
20 display/canvas-temporary-item-list.cpp \22 display/canvas-temporary-item-list.cpp \
2123
=== modified file 'src/display/canvas-axonomgrid.cpp'
--- src/display/canvas-axonomgrid.cpp 2014-08-17 00:23:01 +0000
+++ src/display/canvas-axonomgrid.cpp 2014-09-23 18:22:24 +0000
@@ -634,6 +634,8 @@
634 return s;634 return s;
635 }635 }
636636
637// Geom::Point spacing_dt = _snapmanager->getDesktop()->doc2dt(grid->spacing);
638 Geom::Point origin_dt = _snapmanager->getDesktop()->doc2dt(grid->origin);
637 double spacing_h;639 double spacing_h;
638 double spacing_v;640 double spacing_v;
639641
@@ -661,16 +663,16 @@
661 // - 2 angled x grid lines, one above and one below the point663 // - 2 angled x grid lines, one above and one below the point
662664
663 // Calculate the x coordinate of the vertical grid lines665 // Calculate the x coordinate of the vertical grid lines
664 Geom::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[Geom::X], spacing_h, grid->origin[Geom::X]);666 Geom::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[Geom::X], spacing_h, origin_dt[Geom::X]);
665 Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], spacing_h, grid->origin[Geom::X]);667 Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], spacing_h, origin_dt[Geom::X]);
666668
667 // Calculate the y coordinate of the intersection of the angled grid lines with the y-axis669 // Calculate the y coordinate of the intersection of the angled grid lines with the y-axis
668 double y_proj_along_z = p[Geom::Y] - grid->tan_angle[Z]*(p[Geom::X] - grid->origin[Geom::X]);670 double y_proj_along_z = p[Geom::Y] - grid->tan_angle[Z]*(p[Geom::X] - origin_dt[Geom::X]);
669 double y_proj_along_x = p[Geom::Y] + grid->tan_angle[X]*(p[Geom::X] - grid->origin[Geom::X]);671 double y_proj_along_x = p[Geom::Y] + grid->tan_angle[X]*(p[Geom::X] - origin_dt[Geom::X]);
670 double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, spacing_v, grid->origin[Geom::Y]);672 double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, spacing_v, origin_dt[Geom::Y]);
671 double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, spacing_v, grid->origin[Geom::Y]);673 double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, spacing_v, origin_dt[Geom::Y]);
672 double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, spacing_v, grid->origin[Geom::Y]);674 double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, spacing_v, origin_dt[Geom::Y]);
673 double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, spacing_v, grid->origin[Geom::Y]);675 double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, spacing_v, origin_dt[Geom::Y]);
674676
675 // Calculate the versor for the angled grid lines677 // Calculate the versor for the angled grid lines
676 Geom::Point vers_x = Geom::Point(1, -grid->tan_angle[X]);678 Geom::Point vers_x = Geom::Point(1, -grid->tan_angle[X]);
@@ -709,21 +711,21 @@
709711
710 if (inters) {712 if (inters) {
711 Geom::Point inters_pt = line_x.pointAt((*inters).ta);713 Geom::Point inters_pt = line_x.pointAt((*inters).ta);
712 use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < inters_pt[Geom::X];714 use_left_half = (p[Geom::X] - origin_dt[Geom::X]) < inters_pt[Geom::X];
713 use_right_half = !use_left_half;715 use_right_half = !use_left_half;
714 }716 }
715717
716 // Return the three grid lines which define the triangle that encloses our point718 // Return the three grid lines which define the triangle that encloses our point
717 // If we didn't find an intersection above, all 6 grid lines will be returned719 // If we didn't find an intersection above, all 6 grid lines will be returned
718 if (use_left_half) {720 if (use_left_half) {
719 s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_max)));721 s.push_back(std::make_pair(norm_z, Geom::Point(origin_dt[Geom::X], y_proj_along_z_max)));
720 s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_min)));722 s.push_back(std::make_pair(norm_x, Geom::Point(origin_dt[Geom::X], y_proj_along_x_min)));
721 s.push_back(std::make_pair(Geom::Point(1, 0), Geom::Point(x_max, 0)));723 s.push_back(std::make_pair(Geom::Point(1, 0), Geom::Point(x_max, 0)));
722 }724 }
723725
724 if (use_right_half) {726 if (use_right_half) {
725 s.push_back(std::make_pair(norm_z, Geom::Point(grid->origin[Geom::X], y_proj_along_z_min)));727 s.push_back(std::make_pair(norm_z, Geom::Point(origin_dt[Geom::X], y_proj_along_z_min)));
726 s.push_back(std::make_pair(norm_x, Geom::Point(grid->origin[Geom::X], y_proj_along_x_max)));728 s.push_back(std::make_pair(norm_x, Geom::Point(origin_dt[Geom::X], y_proj_along_x_max)));
727 s.push_back(std::make_pair(Geom::Point(1, 0), Geom::Point(x_min, 0)));729 s.push_back(std::make_pair(Geom::Point(1, 0), Geom::Point(x_min, 0)));
728 }730 }
729731
730732
=== modified file 'src/display/canvas-axonomgrid.h'
--- src/display/canvas-axonomgrid.h 2014-03-27 01:33:44 +0000
+++ src/display/canvas-axonomgrid.h 2014-09-23 18:22:24 +0000
@@ -85,5 +85,15 @@
8585
8686
87#endif87#endif
88/*
89 Local Variables:
90 mode:c++
91 c-file-style:"stroustrup"
92 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93 indent-tabs-mode:nil
94 fill-column:99
95 End:
96*/
97// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
8898
8999
90100
=== modified file 'src/display/canvas-grid.cpp'
--- src/display/canvas-grid.cpp 2014-03-30 21:43:02 +0000
+++ src/display/canvas-grid.cpp 2014-09-23 18:22:24 +0000
@@ -996,6 +996,9 @@
996 return s;996 return s;
997 }997 }
998998
999 Geom::Point spacing_dt = _snapmanager->getDesktop()->doc2dt(grid->spacing);
1000 Geom::Point origin_dt = _snapmanager->getDesktop()->doc2dt(grid->origin);
1001
999 for (unsigned int i = 0; i < 2; ++i) {1002 for (unsigned int i = 0; i < 2; ++i) {
10001003
1001 double spacing;1004 double spacing;
@@ -1011,21 +1014,22 @@
1011 }1014 }
1012 } else {1015 } else {
1013 // Snapping to any grid line, whether it's visible or not1016 // Snapping to any grid line, whether it's visible or not
1014 spacing = grid->spacing[i];1017 spacing = spacing_dt[i];
1015 }1018 }
10161019
1017 Geom::Coord rounded;
1018 Geom::Point point_on_line;
1019 Geom::Point cvec(0.,0.);1020 Geom::Point cvec(0.,0.);
1020 cvec[i] = 1.;1021 cvec[i] = 1.;
10211022
1022 rounded = Inkscape::Util::round_to_upper_multiple_plus(p[i], spacing, grid->origin[i]);1023 { // upper
1023 point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0);1024 Geom::Coord rounded = Inkscape::Util::round_to_upper_multiple_plus(p[i], spacing, origin_dt[i]);
1024 s.push_back(std::make_pair(cvec, point_on_line));1025 Geom::Point point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0);
10251026 s.push_back(std::make_pair(cvec, point_on_line));
1026 rounded = Inkscape::Util::round_to_lower_multiple_plus(p[i], spacing, grid->origin[i]);1027 }
1027 point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0);1028 { // lower
1028 s.push_back(std::make_pair(cvec, point_on_line));1029 Geom::Coord rounded = Inkscape::Util::round_to_lower_multiple_plus(p[i], spacing, origin_dt[i]);
1030 Geom::Point point_on_line = i ? Geom::Point(0, rounded) : Geom::Point(rounded, 0);
1031 s.push_back(std::make_pair(cvec, point_on_line));
1032 }
1029 }1033 }
10301034
1031 return s;1035 return s;
10321036
=== added file 'src/display/canvas-guide.cpp'
--- src/display/canvas-guide.cpp 1970-01-01 00:00:00 +0000
+++ src/display/canvas-guide.cpp 2014-09-23 18:22:24 +0000
@@ -0,0 +1,549 @@
1/*
2 * Inkscape guideline implementation
3 *
4 * Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * Peter Moulder <pmoulder@mail.csse.monash.edu.au>
7 * Johan Engelen
8 * Jon A. Cruz <jon@joncruz.org>
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2000-2002 authors
12 * Copyright (C) 2004 Monash University
13 * Copyright (C) 2007 Johan Engelen
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include <algorithm>
23#include <cstring>
24#include <string>
25#include "desktop-handles.h"
26#include "display/sp-canvas.h"
27#include "display/guideline.h"
28#include "svg/svg.h"
29#include "svg/stringstream.h"
30#include "attributes.h"
31#include "canvas-guide.h"
32#include <sp-item-notify-moveto.h>
33#include <sp-item.h>
34#include <sp-guide-constraint.h>
35#include <glibmm/i18n.h>
36#include <xml/repr.h>
37#include <remove-last.h>
38// #include "sp-metrics.h"
39#include "inkscape.h"
40#include "desktop.h"
41#include "sp-namedview.h"
42#include <2geom/angle.h>
43#include "document.h"
44#include "document-undo.h"
45#include "verbs.h"
46
47using Inkscape::DocumentUndo;
48using std::vector;
49
50//enum {
51// PROP_0,
52// PROP_COLOR,
53// PROP_HICOLOR
54//};
55//
56//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
57//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
58
59#include "sp-factory.h"
60
61namespace {
62 SPObject* createGuide() {
63 return new SPGuide();
64 }
65
66 bool guideRegistered = SPFactory::instance().registerObject("inkscape:guide", createGuide);
67}
68
69SPGuide::SPGuide() : SPObject() {
70 this->label = NULL;
71 this->views = NULL;
72
73 this->normal_to_line = Geom::Point(0.,1.);
74 this->point_on_line = Geom::Point(0.,0.);
75 this->color = 0x0000ff7f;
76 this->hicolor = 0xff00007f;
77 // this->enable = true;
78 // this->group = g_strdup("default");
79}
80
81SPGuide::~SPGuide() {
82}
83
84guint32 SPGuide::getColor() const {
85 return color;
86}
87
88guint32 SPGuide::getHiColor() const {
89 return hicolor;
90}
91
92void SPGuide::setColor(guint32 c) {
93 color = c;
94
95 for (GSList *l = this->views; l != NULL; l = l->next) {
96 sp_guideline_set_color(SP_GUIDELINE(l->data), this->color);
97 }
98}
99
100void SPGuide::setHiColor(guint32 h) {
101 this->hicolor = h;
102}
103
104//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec */*pspec*/)
105//{
106// SPGuide &guide = *SP_GUIDE(object);
107//
108// switch (prop_id) {
109// case PROP_COLOR:
110// guide.color = g_value_get_uint(value);
111// for (GSList *l = guide.views; l != NULL; l = l->next) {
112// sp_guideline_set_color(SP_GUIDELINE(l->data), guide.color);
113// }
114// break;
115//
116// case PROP_HICOLOR:
117// guide.hicolor = g_value_get_uint(value);
118// break;
119// }
120//}
121//
122//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec */*pspec*/)
123//{
124// SPGuide const &guide = *SP_GUIDE(object);
125//
126// switch (prop_id) {
127// case PROP_COLOR:
128// g_value_set_uint(value, guide.color);
129// break;
130// case PROP_HICOLOR:
131// g_value_set_uint(value, guide.hicolor);
132// break;
133// }
134//}
135
136void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr) {
137 SPObject::build(document, repr);
138
139 this->readAttr( "inkscape:label" );
140 this->readAttr( "orientation" );
141 this->readAttr( "position" );
142 // FIXME: Samuel Chase
143 // this->readAttr( "enable" );
144 // this->readAttr( "group" );
145
146 /* Register */
147 document->addResource("guide", this);
148}
149
150void SPGuide::release() {
151 while (this->views) {
152 sp_guideline_delete(SP_GUIDELINE(this->views->data));
153 this->views = g_slist_remove(this->views, this->views->data);
154 }
155
156 if (this->document) {
157 // Unregister ourselves
158 this->document->removeResource("guide", this);
159 }
160
161 SPObject::release();
162}
163
164void SPGuide::set(unsigned int key, const gchar *value) {
165 switch (key) {
166 case SP_ATTR_INKSCAPE_LABEL:
167 if (value) {
168 this->label = g_strdup(value);
169 } else {
170 this->label = NULL;
171 }
172
173 sp_guide_set_label(*this, this->label, false);
174 break;
175 case SP_ATTR_ORIENTATION:
176 {
177 if (value && !strcmp(value, "horizontal")) {
178 /* Visual representation of a horizontal line, constrain vertically (y coordinate). */
179 this->normal_to_line = Geom::Point(0., 1.);
180 } else if (value && !strcmp(value, "vertical")) {
181 this->normal_to_line = Geom::Point(1., 0.);
182 } else if (value) {
183 gchar ** strarray = g_strsplit(value, ",", 2);
184 double newx, newy;
185 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
186 success += sp_svg_number_read_d(strarray[1], &newy);
187 g_strfreev (strarray);
188 if (success == 2 && (fabs(newx) > 1e-6 || fabs(newy) > 1e-6)) {
189 Geom::Point direction(newx, newy);
190 direction.normalize();
191 this->normal_to_line = direction;
192 } else {
193 // default to vertical line for bad arguments
194 this->normal_to_line = Geom::Point(1., 0.);
195 }
196 } else {
197 // default to vertical line for bad arguments
198 this->normal_to_line = Geom::Point(1., 0.);
199 }
200 sp_guide_set_normal(*this, this->normal_to_line, false);
201 }
202 break;
203 case SP_ATTR_POSITION:
204 {
205 if (value) {
206 gchar ** strarray = g_strsplit(value, ",", 2);
207 double newx, newy;
208 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
209 success += sp_svg_number_read_d(strarray[1], &newy);
210 g_strfreev (strarray);
211 if (success == 2) {
212 this->point_on_line = Geom::Point(newx, newy);
213 } else if (success == 1) {
214 // before 0.46 style guideline definition.
215 const gchar *attr = this->getRepr()->attribute("orientation");
216 if (attr && !strcmp(attr, "horizontal")) {
217 this->point_on_line = Geom::Point(0, newx);
218 } else {
219 this->point_on_line = Geom::Point(newx, 0);
220 }
221 }
222 } else {
223 // default to (0,0) for bad arguments
224 this->point_on_line = Geom::Point(0,0);
225 }
226 // update position in non-committing way
227 // fixme: perhaps we need to add an update method instead, and request_update here
228 sp_guide_moveto(*this, this->point_on_line, false);
229 }
230 break;
231
232 case SP_ATTR_ENABLE:
233 {
234
235 // if (value) {
236 // const gchar *attr = object->getRepr()->attribute("enable");
237 // if (attr && !strcmp(attr, "true")) {
238 // guide->enable = true;
239 // } else if (attr && !strcmp(attr, "false")) {
240 // guide->enable = false;
241 // }
242 // }
243 }
244 break;
245
246 case SP_ATTR_GROUP:
247 {
248
249 }
250 break;
251
252 default:
253 SPObject::set(key, value);
254 break;
255 }
256}
257
258SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2)
259{
260 Inkscape::XML::Document *xml_doc = doc->getReprDoc();
261
262 Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:guide");
263
264 Geom::Point n = Geom::rot90(pt2 - pt1);
265
266 sp_repr_set_point(repr, "position", pt1);
267 sp_repr_set_point(repr, "orientation", n);
268 sp_repr_set_boolean(repr, "enable", false);
269
270 SPNamedView *namedview = sp_document_namedview(doc, NULL);
271 if (namedview) {
272 namedview->appendChild(repr);
273 }
274 Inkscape::GC::release(repr);
275
276 SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr));
277 return guide;
278}
279
280void
281sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts) {
282 for (std::list<std::pair<Geom::Point, Geom::Point> >::iterator i = pts.begin(); i != pts.end(); ++i) {
283 SPGuide::createSPGuide(doc, (*i).first, (*i).second);
284 }
285}
286
287void
288sp_guide_create_guides_around_page(SPDesktop *dt) {
289 SPDocument *doc=sp_desktop_document(dt);
290 std::list<std::pair<Geom::Point, Geom::Point> > pts;
291
292 Geom::Point A(0, 0);
293 Geom::Point C(doc->getWidth().value("px"), doc->getHeight().value("px"));
294 Geom::Point B(C[Geom::X], 0);
295 Geom::Point D(0, C[Geom::Y]);
296
297 pts.push_back(std::make_pair<Geom::Point, Geom::Point>(A, B));
298 pts.push_back(std::make_pair<Geom::Point, Geom::Point>(B, C));
299 pts.push_back(std::make_pair<Geom::Point, Geom::Point>(C, D));
300 pts.push_back(std::make_pair<Geom::Point, Geom::Point>(D, A));
301
302 sp_guide_pt_pairs_to_guides(doc, pts);
303
304 DocumentUndo::done(doc, SP_VERB_NONE, _("Create Guides Around the Page"));
305}
306
307void
308sp_guide_delete_all_guides(SPDesktop *dt) {
309 SPDocument *doc=sp_desktop_document(dt);
310 const GSList *current;
311 while ( (current = doc->getResourceList("guide")) ) {
312 SPGuide* guide = SP_GUIDE(current->data);
313 sp_guide_remove(guide);
314 }
315
316 DocumentUndo::done(doc, SP_VERB_NONE, _("Delete All Guides"));
317}
318
319void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler)
320{
321 SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line);
322 sp_guideline_set_color(SP_GUIDELINE(item), color);
323
324 // FIXME: sp_guideline_set_enable(SP_GUIDELINE(item), enable);
325
326 // for (GSList *l = views; l != NULL; l = l->next) {
327 // g_message("showSPGuide: Enable: %d", enable);
328 // sp_guideline_set_enable(SP_GUIDELINE(l->data), enable);
329 // }
330
331 g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this);
332
333 views = g_slist_prepend(views, item);
334}
335
336void SPGuide::hideSPGuide(SPCanvas *canvas)
337{
338 g_assert(canvas != NULL);
339 g_assert(SP_IS_CANVAS(canvas));
340
341 for (GSList *l = views; l != NULL; l = l->next) {
342 if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
343 sp_guideline_delete(SP_GUIDELINE(l->data));
344 views = g_slist_remove(views, l->data);
345 return;
346 }
347 }
348
349 g_assert_not_reached();
350}
351
352void SPGuide::sensitize(SPCanvas *canvas, gboolean sensitive)
353{
354 g_assert(canvas != NULL);
355 g_assert(SP_IS_CANVAS(canvas));
356
357 for (GSList *l = views; l != NULL; l = l->next) {
358 if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
359 sp_guideline_set_sensitive(SP_GUIDELINE(l->data), sensitive);
360 return;
361 }
362 }
363
364 g_assert_not_reached();
365}
366
367Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const
368{
369 return -(pt - point_on_line);
370}
371
372double SPGuide::getDistanceFrom(Geom::Point const &pt) const
373{
374 return Geom::dot(pt - point_on_line, normal_to_line);
375}
376
377/**
378 * \arg commit False indicates temporary moveto in response to motion event while dragging,
379 * true indicates a "committing" version: in response to button release event after
380 * dragging a guideline, or clicking OK in guide editing dialog.
381 */
382void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit)
383{
384 g_assert(SP_IS_GUIDE(&guide));
385
386 for (GSList *l = guide.views; l != NULL; l = l->next) {
387 sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
388 }
389
390 /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
391 case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
392 if (commit) {
393 //XML Tree being used here directly while it shouldn't be.
394 sp_repr_set_point(guide.getRepr(), "position", point_on_line);
395 }
396
397/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
398 for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
399 iEnd(guide.attached_items.end());
400 i != iEnd; ++i)
401 {
402 SPGuideAttachment const &att = *i;
403 sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
404 }
405*/
406}
407
408/**
409 * \arg commit False indicates temporary moveto in response to motion event while dragging,
410 * true indicates a "committing" version: in response to button release event after
411 * dragging a guideline, or clicking OK in guide editing dialog.
412 */
413void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit)
414{
415 g_assert(SP_IS_GUIDE(&guide));
416
417 for (GSList *l = guide.views; l != NULL; l = l->next) {
418 sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line);
419 }
420
421 /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
422 case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
423 if (commit) {
424 //XML Tree being used directly while it shouldn't be
425 sp_repr_set_point(guide.getRepr(), "orientation", normal_to_line);
426 }
427
428/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
429 for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
430 iEnd(guide.attached_items.end());
431 i != iEnd; ++i)
432 {
433 SPGuideAttachment const &att = *i;
434 sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
435 }
436*/
437}
438
439void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit)
440{
441 g_assert(SP_IS_GUIDE(&guide));
442 guide.color = (r << 24) | (g << 16) | (b << 8) | 0x7f;
443
444 if (guide.views) {
445 sp_guideline_set_color(SP_GUIDELINE(guide.views->data), guide.color);
446 }
447
448 if (commit) {
449 std::ostringstream os;
450 os << "rgb(" << r << "," << g << "," << b << ")";
451 //XML Tree being used directly while it shouldn't be
452 guide.getRepr()->setAttribute("inkscape:color", os.str().c_str());
453 }
454}
455
456void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit)
457{
458 g_assert(SP_IS_GUIDE(&guide));
459
460 if (guide.views) {
461 sp_guideline_set_label(SP_GUIDELINE(guide.views->data), label);
462 }
463
464 if (commit) {
465 //XML Tree being used directly while it shouldn't be
466 guide.getRepr()->setAttribute("inkscape:label", label);
467 }
468}
469
470/**
471 * Returns a human-readable description of the guideline for use in dialog boxes and status bar.
472 * If verbose is false, only positioning information is included (useful for dialogs).
473 *
474 * The caller is responsible for freeing the string.
475 */
476char *sp_guide_description(SPGuide const *guide, const bool verbose)
477{
478 using Geom::X;
479 using Geom::Y;
480
481 char *descr = 0;
482 if ( !guide->document ) {
483 // Guide has probably been deleted and no longer has an attached namedview.
484 descr = g_strdup_printf("%s", _("Deleted"));
485 } else {
486 SPNamedView *namedview = sp_document_namedview(guide->document, NULL);
487
488 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px");
489 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px");
490 GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str());
491 GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str());
492
493 gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));
494
495 if ( are_near(guide->normal_to_line, Geom::Point(1., 0.)) ||
496 are_near(guide->normal_to_line, -Geom::Point(1., 0.)) ) {
497 descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str);
498 } else if ( are_near(guide->normal_to_line, Geom::Point(0., 1.)) ||
499 are_near(guide->normal_to_line, -Geom::Point(0., 1.)) ) {
500 descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str);
501 } else {
502 double const radians = guide->angle();
503 double const degrees = Geom::rad_to_deg(radians);
504 int const degrees_int = (int) round(degrees);
505 descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"),
506 degrees_int, position_string_x->str, position_string_y->str);
507 }
508
509 g_string_free(position_string_x, TRUE);
510 g_string_free(position_string_y, TRUE);
511
512 if (verbose) {
513 gchar *oldDescr = descr;
514 descr = g_strconcat(oldDescr, shortcuts, NULL);
515 g_free(oldDescr);
516 }
517 g_free(shortcuts);
518 }
519
520 return descr;
521}
522
523void sp_guide_remove(SPGuide *guide)
524{
525 g_assert(SP_IS_GUIDE(guide));
526
527 for (vector<SPGuideAttachment>::const_iterator i(guide->attached_items.begin()),
528 iEnd(guide->attached_items.end());
529 i != iEnd; ++i)
530 {
531 SPGuideAttachment const &att = *i;
532 remove_last(att.item->constraints, SPGuideConstraint(guide, att.snappoint_ix));
533 }
534 guide->attached_items.clear();
535
536 //XML Tree being used directly while it shouldn't be.
537 sp_repr_unparent(guide->getRepr());
538}
539
540/*
541 Local Variables:
542 mode:c++
543 c-file-style:"stroustrup"
544 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
545 indent-tabs-mode:nil
546 fill-column:99
547 End:
548*/
549// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
0550
=== added file 'src/display/canvas-guide.h'
--- src/display/canvas-guide.h 1970-01-01 00:00:00 +0000
+++ src/display/canvas-guide.h 2014-09-23 18:22:24 +0000
@@ -0,0 +1,92 @@
1#ifndef SEEN_SP_GUIDE_H
2#define SEEN_SP_GUIDE_H
3
4/*
5 * SPGuide
6 *
7 * A guideline
8 *
9 * Copyright (C) Lauris Kaplinski 2000
10 * Copyright (C) Johan Engelen 2007
11 * Abhishek Sharma
12 * Jon A. Cruz <jon@joncruz.org>
13 *
14 */
15
16#include <vector>
17
18#include <2geom/point.h>
19#include "sp-object.h"
20#include "sp-guide-attachment.h"
21
22struct SPCanvas;
23struct SPCanvasGroup;
24class SPDesktop;
25
26#define SP_GUIDE(obj) (dynamic_cast<SPGuide*>((SPObject*)obj))
27#define SP_IS_GUIDE(obj) (dynamic_cast<const SPGuide*>((SPObject*)obj) != NULL)
28
29/* Represents the constraint on p that dot(g.direction, p) == g.position. */
30class SPGuide : public SPObject {
31public:
32 SPGuide();
33 virtual ~SPGuide();
34
35 char* label;
36 char* group;
37 bool enable;
38
39 Geom::Point normal_to_line;
40 Geom::Point point_on_line;
41
42 guint32 color;
43 guint32 hicolor;
44 GSList *views;
45 std::vector<SPGuideAttachment> attached_items;
46
47 guint32 getColor() const;
48 guint32 getHiColor() const;
49 void setColor(guint32 c);
50 void setHiColor(guint32 h);
51 inline bool isHorizontal() const { return (normal_to_line[Geom::X] == 0.); };
52 inline bool isVertical() const { return (normal_to_line[Geom::Y] == 0.); };
53 inline double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); };
54 static SPGuide *createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2);
55 void showSPGuide(SPCanvasGroup *group, GCallback handler);
56 void hideSPGuide(SPCanvas *canvas);
57 void sensitize(SPCanvas *canvas, gboolean sensitive);
58 Geom::Point getPositionFrom(Geom::Point const &pt) const;
59 double getDistanceFrom(Geom::Point const &pt) const;
60
61protected:
62 virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
63 virtual void release();
64 virtual void set(unsigned int key, const gchar* value);
65};
66
67void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts);
68void sp_guide_create_guides_around_page(SPDesktop *dt);
69void sp_guide_delete_all_guides(SPDesktop *dt);
70
71void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit);
72void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit);
73void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit);
74void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit);
75void sp_guide_set_enable(SPGuide &guide, bool const enable_flag, bool const commit);
76
77void sp_guide_remove(SPGuide *guide);
78
79char *sp_guide_description(SPGuide const *guide, const bool verbose = true);
80
81#endif // SEEN_SP_GUIDE_H
82
83/*
84 Local Variables:
85 mode:c++
86 c-file-style:"stroustrup"
87 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
88 indent-tabs-mode:nil
89 fill-column:99
90 End:
91*/
92// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
093
=== modified file 'src/display/guideline.cpp'
--- src/display/guideline.cpp 2014-03-27 01:33:44 +0000
+++ src/display/guideline.cpp 2014-09-23 18:22:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Horizontal/vertical but can also be angled line2 * Guides can be horizontal, vertical or angled.
3 *3 *
4 * Authors:4 * Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>5 * Lauris Kaplinski <lauris@kaplinski.com>
@@ -16,6 +16,7 @@
1616
17#include <2geom/coord.h>17#include <2geom/coord.h>
18#include <2geom/transforms.h>18#include <2geom/transforms.h>
19#include <helper/geom.h>
19#include "sp-canvas-util.h"20#include "sp-canvas-util.h"
20#include "sp-ctrlpoint.h"21#include "sp-ctrlpoint.h"
21#include "guideline.h"22#include "guideline.h"
@@ -84,6 +85,9 @@
84 gl->point_on_line = Geom::Point(0,0);85 gl->point_on_line = Geom::Point(0,0);
85 gl->sensitive = 0;86 gl->sensitive = 0;
8687
88 gl->group = g_strdup("default");
89 gl->enable = true;
90
87 gl->origin = NULL;91 gl->origin = NULL;
88 gl->label = NULL;92 gl->label = NULL;
89}93}
@@ -113,10 +117,13 @@
113117
114static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)118static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
115{119{
116 //TODO: the routine that renders the label of a specific guideline sometimes120 // TODO: the routine that renders the label of a specific guideline sometimes
117 // ends up erasing the labels of the other guidelines.121 // ends up erasing the labels of the other guidelines.
118 // Maybe we should render all labels everytime.122 // Maybe we should render all labels everytime.
119123
124 static const double dash[] = {4.0, 4.0};
125 static int len = sizeof(dash) / sizeof(dash[0]);
126
120 SPGuideLine const *gl = SP_GUIDELINE (item);127 SPGuideLine const *gl = SP_GUIDELINE (item);
121128
122 cairo_save(buf->ct);129 cairo_save(buf->ct);
@@ -126,7 +133,13 @@
126 cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE);133 cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE);
127 cairo_set_font_size(buf->ct, 10);134 cairo_set_font_size(buf->ct, 10);
128135
129 Geom::Point normal_dt = /*unit_vector*/(gl->normal_to_line * gl->affine.withoutTranslation()); // note that normal_dt does not have unit length136 //g_message("Enable: %d", gl->enable);
137
138 if (!gl->enable) {
139 cairo_set_dash(buf->ct, dash, len, 1);
140 }
141
142 Geom::Point normal_dt = transform_normal(gl->normal_to_line, gl->affine); // note that normal_dt does not have unit length
130 Geom::Point point_on_line_dt = gl->point_on_line * gl->affine;143 Geom::Point point_on_line_dt = gl->point_on_line * gl->affine;
131144
132 if (gl->label) {145 if (gl->label) {
@@ -228,7 +241,7 @@
228241
229 *actual_item = item;242 *actual_item = item;
230243
231 Geom::Point vec = gl->normal_to_line * gl->affine.withoutTranslation();244 Geom::Point vec = transform_normal(gl->normal_to_line, gl->affine);
232 double distance = Geom::dot((p - gl->point_on_line * gl->affine), unit_vector(vec));245 double distance = Geom::dot((p - gl->point_on_line * gl->affine), unit_vector(vec));
233 return MAX(fabs(distance)-1, 0);246 return MAX(fabs(distance)-1, 0);
234}247}
@@ -238,7 +251,7 @@
238 SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL);251 SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL);
239 SPCanvasItem *origin = ControlManager::getManager().createControl(parent, Inkscape::CTRL_TYPE_ORIGIN);252 SPCanvasItem *origin = ControlManager::getManager().createControl(parent, Inkscape::CTRL_TYPE_ORIGIN);
240 ControlManager::getManager().track(origin);253 ControlManager::getManager().track(origin);
241254
242 SPGuideLine *gl = SP_GUIDELINE(item);255 SPGuideLine *gl = SP_GUIDELINE(item);
243 SPCtrlPoint *cp = SP_CTRLPOINT(origin);256 SPCtrlPoint *cp = SP_CTRLPOINT(origin);
244 gl->origin = cp;257 gl->origin = cp;
@@ -247,6 +260,8 @@
247 gl->label = label;260 gl->label = label;
248 gl->normal_to_line = normal;261 gl->normal_to_line = normal;
249 gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]);262 gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]);
263 gl->group = g_strdup("default");
264 //gl->enable = true;
250 sp_guideline_set_position(gl, point_on_line);265 sp_guideline_set_position(gl, point_on_line);
251266
252 sp_ctrlpoint_set_coords(cp, point_on_line);267 sp_ctrlpoint_set_coords(cp, point_on_line);
@@ -254,13 +269,30 @@
254 return item;269 return item;
255}270}
256271
272void sp_guideline_set_group(SPGuideLine *gl, const char* group)
273{
274 if (gl->group) {
275 g_free(gl->group);
276 }
277 gl->group = g_strdup(group);
278
279 sp_canvas_item_request_update(SP_CANVAS_ITEM (gl));
280}
281
282void sp_guideline_set_enable(SPGuideLine *gl, bool enable_flag)
283{
284 gl->enable = enable_flag;
285 sp_canvas_item_request_update(SP_CANVAS_ITEM (gl));
286}
287
257void sp_guideline_set_label(SPGuideLine *gl, const char* label)288void sp_guideline_set_label(SPGuideLine *gl, const char* label)
258{289{
290
259 if (gl->label) {291 if (gl->label) {
260 g_free(gl->label);292 g_free(gl->label);
261 }293 }
294
262 gl->label = g_strdup(label);295 gl->label = g_strdup(label);
263
264 sp_canvas_item_request_update(SP_CANVAS_ITEM (gl));296 sp_canvas_item_request_update(SP_CANVAS_ITEM (gl));
265}297}
266298
267299
=== modified file 'src/display/guideline.h'
--- src/display/guideline.h 2014-03-27 01:33:44 +0000
+++ src/display/guideline.h 2014-09-23 18:22:24 +0000
@@ -32,9 +32,11 @@
32 guint32 rgba;32 guint32 rgba;
3333
34 char* label;34 char* label;
35 char* group;
35 Geom::Point normal_to_line;36 Geom::Point normal_to_line;
36 Geom::Point point_on_line;37 Geom::Point point_on_line;
37 double angle;38 double angle;
39 bool enable;
3840
39 unsigned int sensitive : 1;41 unsigned int sensitive : 1;
4042
@@ -55,6 +57,8 @@
55void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line);57void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line);
56void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba);58void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba);
57void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive);59void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive);
60void sp_guideline_set_group(SPGuideLine *gl, char* group);
61void sp_guideline_set_enable(SPGuideLine *gl, bool enable_flag);
58void sp_guideline_delete(SPGuideLine *gl);62void sp_guideline_delete(SPGuideLine *gl);
5963
60#endif // SEEN_SP_GUIDELINE_H64#endif // SEEN_SP_GUIDELINE_H
6165
=== modified file 'src/document-undo.cpp'
--- src/document-undo.cpp 2014-08-06 17:56:59 +0000
+++ src/document-undo.cpp 2014-09-23 18:22:24 +0000
@@ -22,8 +22,8 @@
22 * stack. Two methods exist to indicate that the given action is completed:22 * stack. Two methods exist to indicate that the given action is completed:
23 *23 *
24 * \verbatim24 * \verbatim
25 void sp_document_done( SPDocument *document );25 * void sp_document_done( SPDocument *document );
26 void sp_document_maybe_done( SPDocument *document, const unsigned char *key ) \endverbatim26 * void sp_document_maybe_done( SPDocument *document, const unsigned char *key ) \endverbatim
27 *27 *
28 * Both move the recent action list into the undo stack and clear the28 * Both move the recent action list into the undo stack and clear the
29 * list afterwards. While the first method does an unconditional push,29 * list afterwards. While the first method does an unconditional push,
@@ -150,17 +150,19 @@
150150
151}151}
152152
153void Inkscape::DocumentUndo::maybeDone(SPDocument *doc, const gchar *key, const unsigned int event_type,153void Inkscape::DocumentUndo::maybeDone(SPDocument *doc, const gchar *key,
154 const unsigned int event_type,
154 Glib::ustring const &event_description)155 Glib::ustring const &event_description)
155{156{
156 g_assert (doc != NULL);157 g_assert (doc != NULL);
157 g_assert (doc->priv != NULL);158 g_assert (doc->priv != NULL);
158 g_assert (doc->priv->sensitive);159 g_assert (doc->priv->sensitive);
159 if ( key && !*key ) {160
160 g_warning("Blank undo key specified.");161 if ( key && !*key ) {
161 }162 g_warning("Blank undo key specified.");
162163 }
163 Inkscape::Debug::EventTracker<CommitEvent> tracker(doc, key, event_type);164
165 Inkscape::Debug::EventTracker<CommitEvent> tracker(doc, key, event_type);
164166
165 doc->collectOrphans();167 doc->collectOrphans();
166168
@@ -168,11 +170,12 @@
168170
169 DocumentUndo::clearRedo(doc);171 DocumentUndo::clearRedo(doc);
170172
171 Inkscape::XML::Event *log = sp_repr_coalesce_log (doc->priv->partial, sp_repr_commit_undoable (doc->rdoc));173 Inkscape::XML::Event *log = sp_repr_coalesce_log(doc->priv->partial,
174 sp_repr_commit_undoable(doc->rdoc));
172 doc->priv->partial = NULL;175 doc->priv->partial = NULL;
173176
174 if (!log) {177 if (!log) {
175 sp_repr_begin_transaction (doc->rdoc);178 sp_repr_begin_transaction(doc->rdoc);
176 return;179 return;
177 }180 }
178181
@@ -180,24 +183,25 @@
180 ((Inkscape::Event *)doc->priv->undo->data)->event =183 ((Inkscape::Event *)doc->priv->undo->data)->event =
181 sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log);184 sp_repr_coalesce_log (((Inkscape::Event *)doc->priv->undo->data)->event, log);
182 } else {185 } else {
183 Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description);186 Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description);
184 doc->priv->undo = g_slist_prepend (doc->priv->undo, event);187 doc->priv->undo = g_slist_prepend(doc->priv->undo, event);
185 doc->priv->history_size++;188 doc->priv->history_size++;
186 doc->priv->undoStackObservers.notifyUndoCommitEvent(event);189 doc->priv->undoStackObservers.notifyUndoCommitEvent(event);
187 }190 }
188191
189 if ( key ) {192 if (key) {
190 doc->actionkey = key;193 doc->actionkey = key;
191 } else {194 }
192 doc->actionkey.clear();195 else {
193 }196 doc->actionkey.clear();
197 }
194198
195 doc->virgin = FALSE;199 doc->virgin = FALSE;
196 doc->setModifiedSinceSave();200 doc->setModifiedSinceSave();
197201
198 sp_repr_begin_transaction (doc->rdoc);202 sp_repr_begin_transaction (doc->rdoc);
199203
200 doc->priv->commit_signal.emit();204 doc->priv->commit_signal.emit();
201}205}
202206
203void Inkscape::DocumentUndo::cancel(SPDocument *doc)207void Inkscape::DocumentUndo::cancel(SPDocument *doc)
204208
=== modified file 'src/document.cpp'
--- src/document.cpp 2014-09-02 23:51:04 +0000
+++ src/document.cpp 2014-09-23 18:22:24 +0000
@@ -747,11 +747,11 @@
747 root->translateChildItems(tr);747 root->translateChildItems(tr);
748748
749 if(nv) {749 if(nv) {
750 nv->translateGuides(Geom::Translate(tr[0],-tr[1]));
751 nv->translateGrids (Geom::Translate(tr[0],-tr[1]));
752
753 // update the viewport so the drawing appears to stay where it was
750 Geom::Translate tr2(-rect_with_margins.min());754 Geom::Translate tr2(-rect_with_margins.min());
751 nv->translateGuides(tr2);
752 nv->translateGrids(tr2);
753
754 // update the viewport so the drawing appears to stay where it was
755 nv->scrollAllDesktops(-tr2[0], tr2[1], false);755 nv->scrollAllDesktops(-tr2[0], tr2[1], false);
756 }756 }
757}757}
758758
=== modified file 'src/file.cpp'
--- src/file.cpp 2014-08-19 21:24:08 +0000
+++ src/file.cpp 2014-09-23 18:22:24 +0000
@@ -59,6 +59,7 @@
59#include "selection.h"59#include "selection.h"
60#include "sp-namedview.h"60#include "sp-namedview.h"
61#include "style.h"61#include "style.h"
62#include "2geom/transforms.h"
62#include "ui/view/view-widget.h"63#include "ui/view/view-widget.h"
63#include "uri.h"64#include "uri.h"
64#include "xml/rebase-hrefs.h"65#include "xml/rebase-hrefs.h"
@@ -67,6 +68,9 @@
67#include "event-log.h"68#include "event-log.h"
68#include "ui/dialog/font-substitution.h"69#include "ui/dialog/font-substitution.h"
6970
71#include "svg/stringstream.h"
72#include "svg/svg.h"
73
70#include <gtk/gtk.h>74#include <gtk/gtk.h>
71#include <gtkmm/main.h>75#include <gtkmm/main.h>
7276
@@ -249,12 +253,106 @@
249 }253 }
250}254}
251255
252
253/*######################256/*######################
254## O P E N257## O P E N
255######################*/258######################*/
256259
257/**260/**
261 * Convert old-style guides (pre-0.50, "sodipodi:guide") to new-style (0.50, "inkscape-guide")
262 * \return true if there was anything changed
263 */
264static
265bool sp_file_backwcompat_guides(SPDocument *doc)
266{
267 SPNamedView *namedview = sp_document_namedview(doc, NULL);
268 if (!namedview) return false;
269 Inkscape::XML::Document *document = doc->getReprDoc();
270 if (!document) return false;
271 Inkscape::XML::Node *nv_root = namedview->getRepr();
272 if (!nv_root) return false;
273 Inkscape::XML::Node *node = nv_root->firstChild();
274 std::vector<Inkscape::XML::Node * > nodes_to_be_removed;
275
276 while (node) {
277 if (!strcmp(node->name(), "sodipodi:guide")) {
278 gchar const *position = node->attribute("position");
279 gchar const *orientation = node->attribute("orientation");
280
281 Geom::Point normal = Geom::Point(1.,0.); // default value if reading from SVG fails
282 Geom::Point point_on_line = Geom::Point(0.,0.); // default value if reading from SVG fails
283
284 // the value string of "position" is of the form:
285 // <x-coord double>,<y-coord double>. e.g. 123.243434,355.438534
286
287 if (position) {
288 double pos_x, pos_y;
289 gchar **attr_val = g_strsplit(position, ",", 2);
290 unsigned int success = sp_svg_number_read_d(attr_val[0], &pos_x);
291 success += sp_svg_number_read_d(attr_val[1], &pos_y);
292 g_strfreev(attr_val);
293 if (success == 2) {
294 point_on_line = Geom::Point(pos_x, pos_y);
295 }
296 else if (success == 1) {
297 if (orientation && !strcmp(orientation, "horizontal")) {
298 point_on_line = Geom::Point(0, pos_x);
299 } else {
300 point_on_line = Geom::Point(pos_x, 0);
301 }
302 }
303 }
304
305 if (orientation) {
306 if ( !strcmp(orientation, "horizontal") ) {
307 normal = Geom::Point(0., 1.);
308 }
309 else if ( !strcmp(orientation, "vertical") ) {
310 normal = Geom::Point(1., 0.);
311 } else {
312 double ort_x, ort_y;
313 gchar **attr_val = g_strsplit(orientation, ",", 2);
314 unsigned int success = sp_svg_number_read_d(attr_val[0], &ort_x);
315 success += sp_svg_number_read_d(attr_val[1], &ort_y);
316 g_strfreev(attr_val);
317 if (success == 2 && (fabs(ort_x) > 1e-6 || fabs(ort_y) > 1e-6)) {
318 normal = Geom::Point(ort_x, ort_y);
319 normal.normalize();
320 }
321 }
322 }
323
324 double height = doc->getHeight().value("px");
325
326 Geom::Point point_on_line_doc = Geom::Point(point_on_line[0], -point_on_line[1] + height);
327 Geom::Point normal_doc = Geom::Point(normal[0], -normal[1]);
328
329 Inkscape::SVGOStringStream pos, ort;
330 pos << point_on_line_doc;
331 ort << normal_doc;
332
333 Inkscape::XML::Node *new_node = document->createElement("inkscape:guide");
334 new_node->setAttribute("id", node->attribute("id"));
335 new_node->setAttribute("label", node->attribute("label"));
336 new_node->setAttribute("color", node->attribute("color"));
337 new_node->setAttribute("position", pos.str().c_str());
338 new_node->setAttribute("orientation", ort.str().c_str());
339
340 nv_root->appendChild(new_node);
341 Inkscape::GC::release(new_node);
342
343 nodes_to_be_removed.push_back(node);
344 }
345 node = node->next();
346 } // end while
347
348 for (std::vector<Inkscape::XML::Node * >::iterator itr = nodes_to_be_removed.begin(); itr != nodes_to_be_removed.end(); ++itr) {
349 nv_root->removeChild(*itr);
350 }
351
352 return ( !nodes_to_be_removed.empty() );
353}
354
355/**
258 * Open a file, add the document to the desktop356 * Open a file, add the document to the desktop
259 *357 *
260 * \param replace_empty if true, and the current desktop is empty, this document358 * \param replace_empty if true, and the current desktop is empty, this document
@@ -291,6 +389,10 @@
291389
292 SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;390 SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
293391
392 // backwards compatibility: updating old-style files to new-style files
393 bool changed = sp_file_backwcompat_guides(doc);
394 /// \todo report the change to the user, and perhaps find better place to do such things
395
294 if (existing && existing->virgin && replace_empty) {396 if (existing && existing->virgin && replace_empty) {
295 // If the current desktop is empty, open the document there397 // If the current desktop is empty, open the document there
296 doc->ensureUpToDate(); // TODO this will trigger broken link warnings, etc.398 doc->ensureUpToDate(); // TODO this will trigger broken link warnings, etc.
@@ -298,7 +400,21 @@
298 doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px"));400 doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px"));
299 } else {401 } else {
300 // create a whole new desktop and window402 // create a whole new desktop and window
403
404 // Ipnkscape::XML::Document *xml_doc = doc->getReprDoc();
405 // SPViewWidget *dtw;
406 // // find if old-style guides are being used.
407 // if (sp_repr_lookup_name(xml_doc->root(), "sodipodi:guide")) {
408 // SPNamedView *nv = sp_document_namedview(doc, NULL);
409 // g_message("hi");
410 // Geom::Affine dt2doc = desktop->dt2doc();
411 // //nv->transformGuides(dt2doc);
412 // //dtw = sp_desktop_widget_new(nv);
413 // }
414 // else {
301 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.415 SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
416 // }
417
302 sp_create_window(dtw, TRUE);418 sp_create_window(dtw, TRUE);
303 desktop = static_cast<SPDesktop*>(dtw->view);419 desktop = static_cast<SPDesktop*>(dtw->view);
304 }420 }
305421
=== added file 'src/guide-manager.cpp'
--- src/guide-manager.cpp 1970-01-01 00:00:00 +0000
+++ src/guide-manager.cpp 2014-09-23 18:22:24 +0000
@@ -0,0 +1,154 @@
1/*
2
3 #include "guide-manager.h"
4
5 namespace Inkscape {
6
7 class GuideManager::GuideWatcher {
8 public:
9 };
10
11 GuideManager::GuideManager(SPDesktop *desktop) : _desktop(desktop)
12 {
13
14 }
15
16
17
18 } // end of namespace Inkscape
19
20*/
21
22/*
23 * Inkscape::GuideManager
24 * Released under GNU GPL, read the file 'COPYING' for more information
25 */
26
27#include <set>
28#include <sigc++/functors/mem_fun.h>
29#include <sigc++/adaptors/hide.h>
30#include "gc-managed.h"
31#include "gc-finalized.h"
32#include "document.h"
33#include "desktop.h"
34#include "desktop-handles.h"
35#include "guide-manager.h"
36#include "preferences.h"
37#include "ui/view/view.h"
38#include "selection.h"
39#include "sp-object.h"
40#include "sp-namedview.h"
41#include "sp-item-group.h"
42#include "xml/node.h"
43#include "xml/node-observer.h"
44#include "util/format.h"
45// #include "debug/event-tracker.h"
46// #include "debug/simple-event.h"
47
48namespace Inkscape {
49
50// class GuideManager::GuideWatcher {
51// public:
52// };
53
54GuideManager::GuideManager(SPDesktop *desktop) : _desktop(desktop)
55{
56 _namedview_connection = desktop->namedview->connectModified(sigc::mem_fun(*this, &GuideManager::_namedview_changed));
57}
58
59using Inkscape::XML::Node;
60
61class GuideManager::GuideWatcher : public Inkscape::XML::NodeObserver {
62public:
63 GuideWatcher(GuideManager* mgr, SPObject* obj, sigc::connection c) :
64 _mgr(mgr),
65 _obj(obj),
66 _connection(c)
67 {}
68
69 virtual void notifyChildAdded( Node &/*node*/, Node &/*child*/, Node */*prev*/ ) {}
70 virtual void notifyChildRemoved( Node &/*node*/, Node &/*child*/, Node */*prev*/ ) {}
71 virtual void notifyChildOrderChanged( Node &/*node*/, Node &/*child*/, Node */*old_prev*/, Node */*new_prev*/ ) {}
72 virtual void notifyContentChanged( Node &/*node*/, Util::ptr_shared<char> /*old_content*/, Util::ptr_shared<char> /*new_content*/ ) {}
73
74 virtual void notifyAttributeChanged( Node &/*node*/, GQuark name, Util::ptr_shared<char> /*old_value*/, Util::ptr_shared<char> /*new_value*/ ) {
75 if ( _mgr && _obj ) {
76 _mgr->_objectModified( _obj, 0 );
77 }
78 }
79
80 GuideManager* _mgr;
81 SPObject* _obj;
82 sigc::connection _connection;
83};
84
85GuideManager::~GuideManager()
86{
87 _namedview_connection.disconnect();
88 _resource_connection.disconnect();
89 //_document = 0;
90}
91
92// void LayerManager::_setDocument(SPDocument *document) {
93// if (_document) {
94// _resource_connection.disconnect();
95// }
96// _document = document;
97// if (document) {
98// _resource_connection = document->connectResourcesChanged("layer", sigc::mem_fun(*this, &LayerManager::_rebuild));
99// }
100// _rebuild();
101// }
102
103void GuideManager::_objectModified(SPObject* obj, guint /*flags*/ )
104{
105 _details_changed_signal.emit(obj);
106}
107
108void GuideManager::_rebuild() {
109
110 while ( !_watchers.empty() ) {
111 GuideWatcher* one = _watchers.back();
112 _watchers.pop_back();
113 if ( one->_obj ) {
114 Node* node = one->_obj->getRepr();
115 if ( node ) {
116 node->removeObserver(*one);
117 }
118 one->_connection.disconnect();
119 }
120 }
121
122 _clear();
123
124 GSList const *guides = _desktop->namedview->guides;
125
126 for (GSList const *iter = guides; iter; iter = iter->next) {
127
128 SPObject *guide = SP_OBJECT(iter);
129 sigc::connection connection = guide->connectModified(sigc::mem_fun(*this, &GuideManager::_objectModified));
130 GuideWatcher *eye = new GuideWatcher(this, guide, connection);
131
132 _watchers.push_back(eye);
133 guide->getRepr()->addObserver(*eye);
134 _addOne(guide);
135 }
136}
137
138void GuideManager::_namedview_changed(SPObject *guide, guint /*flags*/)
139{
140 _namedview_changed_signal.emit(guide);
141}
142
143} //namespace
144
145/*
146 Local Variables:
147 mode:c++
148 c-file-style:"stroustrup"
149 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150 indent-tabs-mode:nil
151 fill-column:99
152 End:
153*/
154// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
0155
=== added file 'src/guide-manager.h'
--- src/guide-manager.h 1970-01-01 00:00:00 +0000
+++ src/guide-manager.h 2014-09-23 18:22:24 +0000
@@ -0,0 +1,65 @@
1/*
2 * Inkscape::GuideManager
3 *
4 * Released under GNU GPL, read the file 'COPYING' for more information
5 *
6 */
7
8#ifndef SEEN_INKSCAPE_GUIDE_MANAGER_H
9#define SEEN_INKSCAPE_GUIDE_MANAGER_H
10
11#include "document-subset.h"
12#include "gc-finalized.h"
13#include "gc-soft-ptr.h"
14#include <vector>
15#include <map>
16
17class SPDesktop;
18class SPDocument;
19
20namespace Inkscape {
21
22class GuideManager : public DocumentSubset,
23 public GC::Finalized
24
25{
26
27public:
28 GuideManager(SPDesktop *desktop);
29 ~GuideManager();
30
31private:
32 friend class GuideWatcher;
33 class GuideWatcher;
34
35 void _objectModified(SPObject* obj, guint flags);
36 void _setDocument(SPDocument *document);
37 void _rebuild();
38 void _namedview_changed(SPObject *guide, guint);
39
40 sigc::connection _namedview_connection;
41 sigc::connection _resource_connection;
42
43 GC::soft_ptr<SPDesktop> _desktop;
44
45 std::vector<GuideWatcher*> _watchers;
46
47 sigc::signal<void, SPObject *> _namedview_changed_signal;
48 sigc::signal<void, SPObject *> _details_changed_signal;
49
50};
51
52} // namespace
53
54#endif
55
56/*
57 Local Variables:
58 mode:c++
59 c-file-style:"stroustrup"
60 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
61 indent-tabs-mode:nil
62 fill-column:99
63 End:
64*/
65// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
066
=== modified file 'src/guide-snapper.cpp'
--- src/guide-snapper.cpp 2014-03-27 01:33:44 +0000
+++ src/guide-snapper.cpp 2014-09-23 18:22:24 +0000
@@ -13,7 +13,8 @@
1313
14#include "sp-namedview.h"14#include "sp-namedview.h"
15#include "desktop.h"15#include "desktop.h"
16#include "sp-guide.h"16#include "display/canvas-guide.h"
17#include "helper/geom.h"
1718
18Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)19Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)
19{20{
@@ -47,8 +48,8 @@
4748
48 for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) {49 for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) {
49 SPGuide const *g = SP_GUIDE(l->data);50 SPGuide const *g = SP_GUIDE(l->data);
50 if (g != guide_to_ignore) {51 if (g != guide_to_ignore && g->enable == true) {
51 s.push_back(std::make_pair(g->normal_to_line, g->point_on_line));52 s.push_back(std::make_pair(transform_normal(g->normal_to_line, _snapmanager->getDesktop()->doc2dt()), _snapmanager->getDesktop()->doc2dt(g->point_on_line)));
52 }53 }
53 }54 }
5455
@@ -70,7 +71,7 @@
70void Inkscape::GuideSnapper::_addSnappedLine(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const &normal_to_line, Geom::Point const &point_on_line) const71void Inkscape::GuideSnapper::_addSnappedLine(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const &normal_to_line, Geom::Point const &point_on_line) const
71{72{
72 SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GUIDE, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);73 SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GUIDE, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
73 isr.guide_lines.push_back(dummy);74 isr.guide_lines.push_back(dummy);
74}75}
7576
76void Inkscape::GuideSnapper::_addSnappedLinesOrigin(IntermSnapResults &isr, Geom::Point const &origin, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const77void Inkscape::GuideSnapper::_addSnappedLinesOrigin(IntermSnapResults &isr, Geom::Point const &origin, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
7778
=== modified file 'src/helper/geom.cpp'
--- src/helper/geom.cpp 2014-03-27 01:33:44 +0000
+++ src/helper/geom.cpp 2014-09-23 18:22:24 +0000
@@ -812,7 +812,21 @@
812 rect = Geom::Rect(ints[0], ints[1]);812 rect = Geom::Rect(ints[0], ints[1]);
813}813}
814814
815815Geom::Point transform_normal(Geom::Point normal, Geom::Affine affine) {
816
817/* Function that transforms normals. Ensures that the normal still has a magnitude of 1 */
818
819 normal = normal.ccw(); // normal is now parallel to the line.
820 normal = normal * affine.withoutTranslation(); // apply the transform
821 normal = normal.ccw(); // rotate in the opposite direction to make it perpendicular again.
822
823 if (!normal.isNormalized()) {
824 normal.normalize();
825 }
826
827 return normal;
828}
829
816namespace Geom {830namespace Geom {
817831
818bool transform_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon) {832bool transform_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon) {
819833
=== modified file 'src/helper/geom.h'
--- src/helper/geom.h 2014-03-27 01:33:44 +0000
+++ src/helper/geom.h 2014-09-23 18:22:24 +0000
@@ -34,6 +34,9 @@
3434
35void round_rectangle_outwards(Geom::Rect & rect);35void round_rectangle_outwards(Geom::Rect & rect);
3636
37Geom::Point transform_normal(Geom::Point normal, Geom::Affine affine);
38
39
37namespace Geom{40namespace Geom{
38bool transform_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon);41bool transform_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon);
39bool translate_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon);42bool translate_equalp(Geom::Affine const &m0, Geom::Affine const &m1, Geom::Coord const epsilon);
4043
=== modified file 'src/line-snapper.cpp'
--- src/line-snapper.cpp 2014-03-27 01:33:44 +0000
+++ src/line-snapper.cpp 2014-09-23 18:22:24 +0000
@@ -32,7 +32,7 @@
3232
33 /* Get the lines that we will try to snap to */33 /* Get the lines that we will try to snap to */
34 const LineList lines = _getSnapLines(p.getPoint());34 const LineList lines = _getSnapLines(p.getPoint());
3535
36 for (LineList::const_iterator i = lines.begin(); i != lines.end(); ++i) {36 for (LineList::const_iterator i = lines.begin(); i != lines.end(); ++i) {
37 Geom::Point const p1 = i->second; // point at guide/grid line37 Geom::Point const p1 = i->second; // point at guide/grid line
38 Geom::Point const p2 = p1 + Geom::rot90(i->first); // 2nd point at guide/grid line38 Geom::Point const p2 = p1 + Geom::rot90(i->first); // 2nd point at guide/grid line
3939
=== modified file 'src/main.cpp'
--- src/main.cpp 2014-06-03 17:50:49 +0000
+++ src/main.cpp 2014-09-23 18:22:24 +0000
@@ -78,7 +78,8 @@
78#include "inkscape-version.h"78#include "inkscape-version.h"
7979
80#include "sp-namedview.h"80#include "sp-namedview.h"
81#include "sp-guide.h"81#include "display/canvas-guide.h"
82// #include "sp-object-repr.h"
82#include "xml/repr.h"83#include "xml/repr.h"
8384
84#include "io/sys.h"85#include "io/sys.h"
8586
=== modified file 'src/satisfied-guide-cns.cpp'
--- src/satisfied-guide-cns.cpp 2014-03-27 01:33:44 +0000
+++ src/satisfied-guide-cns.cpp 2014-09-23 18:22:24 +0000
@@ -1,6 +1,6 @@
1#include <2geom/coord.h>1#include <2geom/coord.h>
2#include "desktop-handles.h"2#include "desktop-handles.h"
3#include "sp-guide.h"3#include "display/canvas-guide.h"
4#include "sp-guide-constraint.h"4#include "sp-guide-constraint.h"
5#include "sp-namedview.h"5#include "sp-namedview.h"
6#include "satisfied-guide-cns.h"6#include "satisfied-guide-cns.h"
77
=== modified file 'src/snap.cpp'
--- src/snap.cpp 2014-08-17 18:31:38 +0000
+++ src/snap.cpp 2014-09-23 18:22:24 +0000
@@ -30,7 +30,7 @@
30#include "inkscape.h"30#include "inkscape.h"
31#include "desktop.h"31#include "desktop.h"
32#include "selection.h"32#include "selection.h"
33#include "sp-guide.h"33#include "display/canvas-guide.h"
34#include "preferences.h"34#include "preferences.h"
35#include "ui/tools/tool-base.h"35#include "ui/tools/tool-base.h"
36#include "util/mathfns.h"36#include "util/mathfns.h"
@@ -179,7 +179,8 @@
179 // will use the grid snapper. Simply snapping the value t to the grid will do, but179 // will use the grid snapper. Simply snapping the value t to the grid will do, but
180 // only if the origin of the grid is at (0,0). If it's not then compensate for this180 // only if the origin of the grid is at (0,0). If it's not then compensate for this
181 // in the translation t181 // in the translation t
182 Geom::Point const t_offset = t + grid->origin;182 Geom::Point origin_dt = getDesktop()->doc2dt(grid->origin); // remember snapping is done in desktop-coords
183 Geom::Point const t_offset = t + origin_dt;
183 IntermSnapResults isr;184 IntermSnapResults isr;
184 // Only the first three parameters are being used for grid snappers185 // Only the first three parameters are being used for grid snappers
185 snapper->freeSnap(isr, Inkscape::SnapCandidatePoint(t_offset, Inkscape::SNAPSOURCE_GRID_PITCH),Geom::OptRect(), NULL, NULL);186 snapper->freeSnap(isr, Inkscape::SnapCandidatePoint(t_offset, Inkscape::SNAPSOURCE_GRID_PITCH),Geom::OptRect(), NULL, NULL);
@@ -192,7 +193,7 @@
192 // use getSnapDistance() instead of getWeightedDistance() here because the pointer's position193 // use getSnapDistance() instead of getWeightedDistance() here because the pointer's position
193 // doesn't tell us anything about which node to snap194 // doesn't tell us anything about which node to snap
194 success = true;195 success = true;
195 nearest_multiple = s.getPoint() - grid->origin;196 nearest_multiple = s.getPoint() - origin_dt;
196 nearest_distance = s.getSnapDistance();197 nearest_distance = s.getSnapDistance();
197 bestSnappedPoint = s;198 bestSnappedPoint = s;
198 }199 }
@@ -384,7 +385,7 @@
384 return sp;385 return sp;
385}386}
386387
387void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point &origin_or_vector, bool origin, bool freeze_angle) const388void SnapManager::guideFreeSnap(Geom::Point &point_dt, Geom::Point &origin_or_vector, bool origin, bool freeze_angle) const
388{389{
389 if (freeze_angle && origin) {390 if (freeze_angle && origin) {
390 g_warning("Dear developer, when snapping guides you shouldn't ask me to freeze the guide's vector when you haven't specified one");391 g_warning("Dear developer, when snapping guides you shouldn't ask me to freeze the guide's vector when you haven't specified one");
@@ -395,11 +396,11 @@
395 return;396 return;
396 }397 }
397398
398 Inkscape::SnapCandidatePoint candidate(p, Inkscape::SNAPSOURCE_GUIDE);399 Inkscape::SnapCandidatePoint candidate(point_dt, Inkscape::SNAPSOURCE_GUIDE);
399 if (origin) {400 if (origin) {
400 candidate.addOrigin(origin_or_vector);401 candidate.addOrigin(origin_or_vector);
401 } else {402 } else {
402 candidate = Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_GUIDE_ORIGIN);403 candidate = Inkscape::SnapCandidatePoint(point_dt, Inkscape::SNAPSOURCE_GUIDE_ORIGIN);
403 candidate.addVector(Geom::rot90(origin_or_vector));404 candidate.addVector(Geom::rot90(origin_or_vector));
404 }405 }
405406
@@ -411,7 +412,7 @@
411412
412 Inkscape::SnappedPoint const s = findBestSnap(candidate, isr, false);413 Inkscape::SnappedPoint const s = findBestSnap(candidate, isr, false);
413414
414 s.getPointIfSnapped(p);415 s.getPointIfSnapped(point_dt);
415416
416 if (!freeze_angle && s.getSnapped()) {417 if (!freeze_angle && s.getSnapped()) {
417 if (!Geom::are_near(s.getTangent(), Geom::Point(0,0))) { // If the tangent has been set ...418 if (!Geom::are_near(s.getTangent(), Geom::Point(0,0))) { // If the tangent has been set ...
@@ -421,13 +422,13 @@
421 }422 }
422}423}
423424
424void SnapManager::guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const425void SnapManager::guideConstrainedSnap(Geom::Point &point_dt, SPGuide const &guideline) const
425{426{
426 if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally() || !snapprefs.isTargetSnappable(Inkscape::SNAPTARGET_GUIDE)) {427 if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally() || !snapprefs.isTargetSnappable(Inkscape::SNAPTARGET_GUIDE)) {
427 return;428 return;
428 }429 }
429430
430 Inkscape::SnapCandidatePoint candidate(p, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, Inkscape::SNAPTARGET_UNDEFINED);431 Inkscape::SnapCandidatePoint candidate(point_dt, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, Inkscape::SNAPTARGET_UNDEFINED);
431432
432 IntermSnapResults isr;433 IntermSnapResults isr;
433 Inkscape::Snapper::SnapConstraint cl(guideline.point_on_line, Geom::rot90(guideline.normal_to_line));434 Inkscape::Snapper::SnapConstraint cl(guideline.point_on_line, Geom::rot90(guideline.normal_to_line));
@@ -438,7 +439,7 @@
438 }439 }
439440
440 Inkscape::SnappedPoint const s = findBestSnap(candidate, isr, false);441 Inkscape::SnappedPoint const s = findBestSnap(candidate, isr, false);
441 s.getPointIfSnapped(p);442 s.getPointIfSnapped(point_dt);
442}443}
443444
444Inkscape::SnappedPoint SnapManager::_snapTransformed(445Inkscape::SnappedPoint SnapManager::_snapTransformed(
445446
=== removed file 'src/sp-guide.cpp'
--- src/sp-guide.cpp 2014-03-28 21:16:35 +0000
+++ src/sp-guide.cpp 1970-01-01 00:00:00 +0000
@@ -1,540 +0,0 @@
1/*
2 * Inkscape guideline implementation
3 *
4 * Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * Peter Moulder <pmoulder@mail.csse.monash.edu.au>
7 * Johan Engelen
8 * Jon A. Cruz <jon@joncruz.org>
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2000-2002 authors
12 * Copyright (C) 2004 Monash University
13 * Copyright (C) 2007 Johan Engelen
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include <algorithm>
23#include <cstring>
24#include <string>
25#include "desktop-handles.h"
26#include "display/sp-canvas.h"
27#include "display/guideline.h"
28#include "svg/svg.h"
29#include "svg/stringstream.h"
30#include "attributes.h"
31#include "sp-guide.h"
32#include <sp-item-notify-moveto.h>
33#include <sp-item.h>
34#include <sp-guide-constraint.h>
35#include <glibmm/i18n.h>
36#include <xml/repr.h>
37#include <remove-last.h>
38#include "inkscape.h"
39#include "desktop.h"
40#include "sp-namedview.h"
41#include <2geom/angle.h>
42#include "document.h"
43#include "document-undo.h"
44#include "verbs.h"
45
46using Inkscape::DocumentUndo;
47using std::vector;
48
49//enum {
50// PROP_0,
51// PROP_COLOR,
52// PROP_HICOLOR
53//};
54//
55//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
56//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
57
58#include "sp-factory.h"
59
60namespace {
61 SPObject* createGuide() {
62 return new SPGuide();
63 }
64
65 bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide);
66}
67
68//static void sp_guide_class_init(SPGuideClass *gc)
69//{
70// GObjectClass *gobject_class = (GObjectClass *) gc;
71//
72// gobject_class->set_property = sp_guide_set_property;
73// gobject_class->get_property = sp_guide_get_property;
74//
75// g_object_class_install_property(gobject_class,
76// PROP_COLOR,
77// g_param_spec_uint("color", "Color", "Color",
78// 0,
79// 0xffffffff,
80// 0xff000000,
81// (GParamFlags) G_PARAM_READWRITE));
82//
83// g_object_class_install_property(gobject_class,
84// PROP_HICOLOR,
85// g_param_spec_uint("hicolor", "HiColor", "HiColor",
86// 0,
87// 0xffffffff,
88// 0xff000000,
89// (GParamFlags) G_PARAM_READWRITE));
90//}
91// CPPIFY: properties!
92
93SPGuide::SPGuide() : SPObject() {
94 this->label = NULL;
95 this->views = NULL;
96
97 this->normal_to_line = Geom::Point(0.,1.);
98 this->point_on_line = Geom::Point(0.,0.);
99 this->color = 0x0000ff7f;
100 this->hicolor = 0xff00007f;
101}
102
103SPGuide::~SPGuide() {
104}
105
106guint32 SPGuide::getColor() const {
107 return color;
108}
109
110guint32 SPGuide::getHiColor() const {
111 return hicolor;
112}
113
114void SPGuide::setColor(guint32 c) {
115 color = c;
116
117 for (GSList *l = this->views; l != NULL; l = l->next) {
118 sp_guideline_set_color(SP_GUIDELINE(l->data), this->color);
119 }
120}
121
122void SPGuide::setHiColor(guint32 h) {
123 this->hicolor = h;
124}
125
126//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec */*pspec*/)
127//{
128// SPGuide &guide = *SP_GUIDE(object);
129//
130// switch (prop_id) {
131// case PROP_COLOR:
132// guide.color = g_value_get_uint(value);
133// for (GSList *l = guide.views; l != NULL; l = l->next) {
134// sp_guideline_set_color(SP_GUIDELINE(l->data), guide.color);
135// }
136// break;
137//
138// case PROP_HICOLOR:
139// guide.hicolor = g_value_get_uint(value);
140// break;
141// }
142//}
143//
144//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec */*pspec*/)
145//{
146// SPGuide const &guide = *SP_GUIDE(object);
147//
148// switch (prop_id) {
149// case PROP_COLOR:
150// g_value_set_uint(value, guide.color);
151// break;
152// case PROP_HICOLOR:
153// g_value_set_uint(value, guide.hicolor);
154// break;
155// }
156//}
157
158void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr) {
159 SPObject::build(document, repr);
160
161 this->readAttr( "inkscape:label" );
162 this->readAttr( "orientation" );
163 this->readAttr( "position" );
164
165 /* Register */
166 document->addResource("guide", this);
167}
168
169void SPGuide::release() {
170 while (this->views) {
171 sp_guideline_delete(SP_GUIDELINE(this->views->data));
172 this->views = g_slist_remove(this->views, this->views->data);
173 }
174
175 if (this->document) {
176 // Unregister ourselves
177 this->document->removeResource("guide", this);
178 }
179
180 SPObject::release();
181}
182
183void SPGuide::set(unsigned int key, const gchar *value) {
184 switch (key) {
185 case SP_ATTR_INKSCAPE_LABEL:
186 if (this->label) g_free(this->label);
187
188 if (value) {
189 this->label = g_strdup(value);
190 } else {
191 this->label = NULL;
192 }
193
194 sp_guide_set_label(*this, this->label, false);
195 break;
196 case SP_ATTR_ORIENTATION:
197 {
198 if (value && !strcmp(value, "horizontal")) {
199 /* Visual representation of a horizontal line, constrain vertically (y coordinate). */
200 this->normal_to_line = Geom::Point(0., 1.);
201 } else if (value && !strcmp(value, "vertical")) {
202 this->normal_to_line = Geom::Point(1., 0.);
203 } else if (value) {
204 gchar ** strarray = g_strsplit(value, ",", 2);
205 double newx, newy;
206 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
207 success += sp_svg_number_read_d(strarray[1], &newy);
208 g_strfreev (strarray);
209 if (success == 2 && (fabs(newx) > 1e-6 || fabs(newy) > 1e-6)) {
210 Geom::Point direction(newx, newy);
211 direction.normalize();
212 this->normal_to_line = direction;
213 } else {
214 // default to vertical line for bad arguments
215 this->normal_to_line = Geom::Point(1., 0.);
216 }
217 } else {
218 // default to vertical line for bad arguments
219 this->normal_to_line = Geom::Point(1., 0.);
220 }
221 sp_guide_set_normal(*this, this->normal_to_line, false);
222 }
223 break;
224 case SP_ATTR_POSITION:
225 {
226 if (value) {
227 gchar ** strarray = g_strsplit(value, ",", 2);
228 double newx, newy;
229 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
230 success += sp_svg_number_read_d(strarray[1], &newy);
231 g_strfreev (strarray);
232 if (success == 2) {
233 this->point_on_line = Geom::Point(newx, newy);
234 } else if (success == 1) {
235 // before 0.46 style guideline definition.
236 const gchar *attr = this->getRepr()->attribute("orientation");
237 if (attr && !strcmp(attr, "horizontal")) {
238 this->point_on_line = Geom::Point(0, newx);
239 } else {
240 this->point_on_line = Geom::Point(newx, 0);
241 }
242 }
243 } else {
244 // default to (0,0) for bad arguments
245 this->point_on_line = Geom::Point(0,0);
246 }
247 // update position in non-committing way
248 // fixme: perhaps we need to add an update method instead, and request_update here
249 sp_guide_moveto(*this, this->point_on_line, false);
250 }
251 break;
252 default:
253 SPObject::set(key, value);
254 break;
255 }
256}
257
258SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2)
259{
260 Inkscape::XML::Document *xml_doc = doc->getReprDoc();
261
262 Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");
263
264 Geom::Point n = Geom::rot90(pt2 - pt1);
265
266 sp_repr_set_point(repr, "position", pt1);
267 sp_repr_set_point(repr, "orientation", n);
268
269 SPNamedView *namedview = sp_document_namedview(doc, NULL);
270 if (namedview) {
271 namedview->appendChild(repr);
272 }
273 Inkscape::GC::release(repr);
274
275 SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr));
276 return guide;
277}
278
279void
280sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts) {
281 for (std::list<std::pair<Geom::Point, Geom::Point> >::iterator i = pts.begin(); i != pts.end(); ++i) {
282 SPGuide::createSPGuide(doc, (*i).first, (*i).second);
283 }
284}
285
286void
287sp_guide_create_guides_around_page(SPDesktop *dt) {
288 SPDocument *doc=sp_desktop_document(dt);
289 std::list<std::pair<Geom::Point, Geom::Point> > pts;
290
291 Geom::Point A(0, 0);
292 Geom::Point C(doc->getWidth().value("px"), doc->getHeight().value("px"));
293 Geom::Point B(C[Geom::X], 0);
294 Geom::Point D(0, C[Geom::Y]);
295
296 pts.push_back(std::pair<Geom::Point, Geom::Point>(A, B));
297 pts.push_back(std::pair<Geom::Point, Geom::Point>(B, C));
298 pts.push_back(std::pair<Geom::Point, Geom::Point>(C, D));
299 pts.push_back(std::pair<Geom::Point, Geom::Point>(D, A));
300
301 sp_guide_pt_pairs_to_guides(doc, pts);
302
303 DocumentUndo::done(doc, SP_VERB_NONE, _("Create Guides Around the Page"));
304}
305
306void
307sp_guide_delete_all_guides(SPDesktop *dt) {
308 SPDocument *doc=sp_desktop_document(dt);
309 const GSList *current;
310 while ( (current = doc->getResourceList("guide")) ) {
311 SPGuide* guide = SP_GUIDE(current->data);
312 sp_guide_remove(guide);
313 }
314
315 DocumentUndo::done(doc, SP_VERB_NONE, _("Delete All Guides"));
316}
317
318void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler)
319{
320 SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line);
321 sp_guideline_set_color(SP_GUIDELINE(item), color);
322
323 g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this);
324
325 views = g_slist_prepend(views, item);
326}
327
328void SPGuide::hideSPGuide(SPCanvas *canvas)
329{
330 g_assert(canvas != NULL);
331 g_assert(SP_IS_CANVAS(canvas));
332
333 for (GSList *l = views; l != NULL; l = l->next) {
334 if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
335 sp_guideline_delete(SP_GUIDELINE(l->data));
336 views = g_slist_remove(views, l->data);
337 return;
338 }
339 }
340
341 g_assert_not_reached();
342}
343
344void SPGuide::sensitize(SPCanvas *canvas, gboolean sensitive)
345{
346 g_assert(canvas != NULL);
347 g_assert(SP_IS_CANVAS(canvas));
348
349 for (GSList *l = views; l != NULL; l = l->next) {
350 if (canvas == SP_CANVAS_ITEM(l->data)->canvas) {
351 sp_guideline_set_sensitive(SP_GUIDELINE(l->data), sensitive);
352 return;
353 }
354 }
355
356 g_assert_not_reached();
357}
358
359Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const
360{
361 return -(pt - point_on_line);
362}
363
364double SPGuide::getDistanceFrom(Geom::Point const &pt) const
365{
366 return Geom::dot(pt - point_on_line, normal_to_line);
367}
368
369/**
370 * \arg commit False indicates temporary moveto in response to motion event while dragging,
371 * true indicates a "committing" version: in response to button release event after
372 * dragging a guideline, or clicking OK in guide editing dialog.
373 */
374void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit)
375{
376 g_assert(SP_IS_GUIDE(&guide));
377
378 for (GSList *l = guide.views; l != NULL; l = l->next) {
379 sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
380 }
381
382 /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
383 case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
384 if (commit) {
385 //XML Tree being used here directly while it shouldn't be.
386 sp_repr_set_point(guide.getRepr(), "position", point_on_line);
387 }
388
389/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
390 for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
391 iEnd(guide.attached_items.end());
392 i != iEnd; ++i)
393 {
394 SPGuideAttachment const &att = *i;
395 sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
396 }
397*/
398}
399
400/**
401 * \arg commit False indicates temporary moveto in response to motion event while dragging,
402 * true indicates a "committing" version: in response to button release event after
403 * dragging a guideline, or clicking OK in guide editing dialog.
404 */
405void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit)
406{
407 g_assert(SP_IS_GUIDE(&guide));
408
409 for (GSList *l = guide.views; l != NULL; l = l->next) {
410 sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line);
411 }
412
413 /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
414 case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
415 if (commit) {
416 //XML Tree being used directly while it shouldn't be
417 sp_repr_set_point(guide.getRepr(), "orientation", normal_to_line);
418 }
419
420/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
421 for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
422 iEnd(guide.attached_items.end());
423 i != iEnd; ++i)
424 {
425 SPGuideAttachment const &att = *i;
426 sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
427 }
428*/
429}
430
431void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit)
432{
433 g_assert(SP_IS_GUIDE(&guide));
434 guide.color = (r << 24) | (g << 16) | (b << 8) | 0x7f;
435
436 if (guide.views){
437 sp_guideline_set_color(SP_GUIDELINE(guide.views->data), guide.color);
438 }
439
440 if (commit){
441 std::ostringstream os;
442 os << "rgb(" << r << "," << g << "," << b << ")";
443 //XML Tree being used directly while it shouldn't be
444 guide.getRepr()->setAttribute("inkscape:color", os.str().c_str());
445 }
446}
447
448void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit)
449{
450 g_assert(SP_IS_GUIDE(&guide));
451 if (guide.views){
452 sp_guideline_set_label(SP_GUIDELINE(guide.views->data), label);
453 }
454
455 if (commit){
456 //XML Tree being used directly while it shouldn't be
457 guide.getRepr()->setAttribute("inkscape:label", label);
458 }
459}
460
461/**
462 * Returns a human-readable description of the guideline for use in dialog boxes and status bar.
463 * If verbose is false, only positioning information is included (useful for dialogs).
464 *
465 * The caller is responsible for freeing the string.
466 */
467char *sp_guide_description(SPGuide const *guide, const bool verbose)
468{
469 using Geom::X;
470 using Geom::Y;
471
472 char *descr = 0;
473 if ( !guide->document ) {
474 // Guide has probably been deleted and no longer has an attached namedview.
475 descr = g_strdup_printf("%s", _("Deleted"));
476 } else {
477 SPNamedView *namedview = sp_document_namedview(guide->document, NULL);
478
479 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px");
480 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px");
481 GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str());
482 GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str());
483
484 gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));
485
486 if ( are_near(guide->normal_to_line, Geom::Point(1., 0.)) ||
487 are_near(guide->normal_to_line, -Geom::Point(1., 0.)) ) {
488 descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str);
489 } else if ( are_near(guide->normal_to_line, Geom::Point(0., 1.)) ||
490 are_near(guide->normal_to_line, -Geom::Point(0., 1.)) ) {
491 descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str);
492 } else {
493 double const radians = guide->angle();
494 double const degrees = Geom::rad_to_deg(radians);
495 int const degrees_int = (int) round(degrees);
496 descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"),
497 degrees_int, position_string_x->str, position_string_y->str);
498 }
499
500 g_string_free(position_string_x, TRUE);
501 g_string_free(position_string_y, TRUE);
502
503 if (verbose) {
504 gchar *oldDescr = descr;
505 descr = g_strconcat(oldDescr, shortcuts, NULL);
506 g_free(oldDescr);
507 }
508 g_free(shortcuts);
509 }
510
511 return descr;
512}
513
514void sp_guide_remove(SPGuide *guide)
515{
516 g_assert(SP_IS_GUIDE(guide));
517
518 for (vector<SPGuideAttachment>::const_iterator i(guide->attached_items.begin()),
519 iEnd(guide->attached_items.end());
520 i != iEnd; ++i)
521 {
522 SPGuideAttachment const &att = *i;
523 remove_last(att.item->constraints, SPGuideConstraint(guide, att.snappoint_ix));
524 }
525 guide->attached_items.clear();
526
527 //XML Tree being used directly while it shouldn't be.
528 sp_repr_unparent(guide->getRepr());
529}
530
531/*
532 Local Variables:
533 mode:c++
534 c-file-style:"stroustrup"
535 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
536 indent-tabs-mode:nil
537 fill-column:99
538 End:
539*/
540// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
5410
=== removed file 'src/sp-guide.h'
--- src/sp-guide.h 2014-03-27 01:33:44 +0000
+++ src/sp-guide.h 1970-01-01 00:00:00 +0000
@@ -1,88 +0,0 @@
1#ifndef SEEN_SP_GUIDE_H
2#define SEEN_SP_GUIDE_H
3
4/*
5 * SPGuide
6 *
7 * A guideline
8 *
9 * Copyright (C) Lauris Kaplinski 2000
10 * Copyright (C) Johan Engelen 2007
11 * Abhishek Sharma
12 * Jon A. Cruz <jon@joncruz.org>
13 *
14 */
15
16#include <vector>
17
18#include <2geom/point.h>
19#include "sp-object.h"
20#include "sp-guide-attachment.h"
21
22struct SPCanvas;
23struct SPCanvasGroup;
24class SPDesktop;
25
26#define SP_GUIDE(obj) (dynamic_cast<SPGuide*>((SPObject*)obj))
27#define SP_IS_GUIDE(obj) (dynamic_cast<const SPGuide*>((SPObject*)obj) != NULL)
28
29/* Represents the constraint on p that dot(g.direction, p) == g.position. */
30class SPGuide : public SPObject {
31public:
32 SPGuide();
33 virtual ~SPGuide();
34
35 char* label;
36 Geom::Point normal_to_line;
37 Geom::Point point_on_line;
38
39 guint32 color;
40 guint32 hicolor;
41 GSList *views;
42 std::vector<SPGuideAttachment> attached_items;
43
44 guint32 getColor() const;
45 guint32 getHiColor() const;
46 void setColor(guint32 c);
47 void setHiColor(guint32 h);
48
49 inline bool isHorizontal() const { return (normal_to_line[Geom::X] == 0.); };
50 inline bool isVertical() const { return (normal_to_line[Geom::Y] == 0.); };
51 inline double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); };
52 static SPGuide *createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2);
53 void showSPGuide(SPCanvasGroup *group, GCallback handler);
54 void hideSPGuide(SPCanvas *canvas);
55 void sensitize(SPCanvas *canvas, gboolean sensitive);
56 Geom::Point getPositionFrom(Geom::Point const &pt) const;
57 double getDistanceFrom(Geom::Point const &pt) const;
58
59protected:
60 virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
61 virtual void release();
62 virtual void set(unsigned int key, const gchar* value);
63};
64
65void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts);
66void sp_guide_create_guides_around_page(SPDesktop *dt);
67void sp_guide_delete_all_guides(SPDesktop *dt);
68
69void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit);
70void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit);
71void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit);
72void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit);
73void sp_guide_remove(SPGuide *guide);
74
75char *sp_guide_description(SPGuide const *guide, const bool verbose = true);
76
77#endif // SEEN_SP_GUIDE_H
78
79/*
80 Local Variables:
81 mode:c++
82 c-file-style:"stroustrup"
83 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
84 indent-tabs-mode:nil
85 fill-column:99
86 End:
87*/
88// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
890
=== modified file 'src/sp-item-notify-moveto.cpp'
--- src/sp-item-notify-moveto.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-item-notify-moveto.cpp 2014-09-23 18:22:24 +0000
@@ -4,7 +4,7 @@
44
5#include <sp-item.h>5#include <sp-item.h>
6#include <2geom/transforms.h>6#include <2geom/transforms.h>
7#include <sp-guide.h>7#include <display/canvas-guide.h>
8#include <sp-item-rm-unsatisfied-cns.h>8#include <sp-item-rm-unsatisfied-cns.h>
9#include <sp-item-notify-moveto.h>9#include <sp-item-notify-moveto.h>
10using std::vector;10using std::vector;
1111
=== modified file 'src/sp-item-rm-unsatisfied-cns.cpp'
--- src/sp-item-rm-unsatisfied-cns.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-item-rm-unsatisfied-cns.cpp 2014-09-23 18:22:24 +0000
@@ -3,7 +3,7 @@
3#include <2geom/coord.h>3#include <2geom/coord.h>
44
5#include "remove-last.h"5#include "remove-last.h"
6#include "sp-guide.h"6#include "display/canvas-guide.h"
7#include "sp-guide-constraint.h"7#include "sp-guide-constraint.h"
8#include "sp-item.h"8#include "sp-item.h"
9#include "sp-item-rm-unsatisfied-cns.h"9#include "sp-item-rm-unsatisfied-cns.h"
1010
=== modified file 'src/sp-item-update-cns.cpp'
--- src/sp-item-update-cns.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-item-update-cns.cpp 2014-09-23 18:22:24 +0000
@@ -1,9 +1,8 @@
1
2#include "satisfied-guide-cns.h"1#include "satisfied-guide-cns.h"
3#include "sp-guide-constraint.h"2#include "sp-guide-constraint.h"
3#include "display/canvas-guide.h"
4#include "sp-item.h"
4#include "sp-item-update-cns.h"5#include "sp-item-update-cns.h"
5#include "sp-guide.h"
6#include "sp-item.h"
7#include <algorithm>6#include <algorithm>
8using std::find;7using std::find;
9using std::vector;8using std::vector;
109
=== modified file 'src/sp-item.cpp'
--- src/sp-item.cpp 2014-08-26 20:38:14 +0000
+++ src/sp-item.cpp 2014-09-23 18:22:24 +0000
@@ -55,7 +55,7 @@
55#include "conditions.h"55#include "conditions.h"
56#include "sp-filter-reference.h"56#include "sp-filter-reference.h"
57#include "filter-chemistry.h"57#include "filter-chemistry.h"
58#include "sp-guide.h"58#include "display/canvas-guide.h"
59#include "sp-title.h"59#include "sp-title.h"
60#include "sp-desc.h"60#include "sp-desc.h"
6161
@@ -1638,7 +1638,7 @@
1638 Inkscape::Preferences *prefs = Inkscape::Preferences::get();1638 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1639 int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);1639 int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);
16401640
1641 Geom::OptRect bbox = (prefs_bbox == 0) ? desktopVisualBounds() : desktopGeometricBounds();1641 Geom::OptRect bbox = (prefs_bbox == 0) ? documentVisualBounds() : documentGeometricBounds();
1642 if (!bbox) {1642 if (!bbox) {
1643 g_warning ("Cannot determine item's bounding box during conversion to guides.\n");1643 g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
1644 return;1644 return;
16451645
=== modified file 'src/sp-line.cpp'
--- src/sp-line.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-line.cpp 2014-09-23 18:22:24 +0000
@@ -17,7 +17,7 @@
17#include "attributes.h"17#include "attributes.h"
18#include "style.h"18#include "style.h"
19#include "sp-line.h"19#include "sp-line.h"
20#include "sp-guide.h"20#include "display/canvas-guide.h"
21#include "display/curve.h"21#include "display/curve.h"
22#include <glibmm/i18n.h>22#include <glibmm/i18n.h>
23#include "xml/repr.h"23#include "xml/repr.h"
@@ -128,10 +128,11 @@
128128
129void SPLine::convert_to_guides() const {129void SPLine::convert_to_guides() const {
130 Geom::Point points[2];130 Geom::Point points[2];
131 Geom::Affine const i2dt(this->i2dt_affine());131
132132 Geom::Affine const i2doc(this->i2doc_affine());
133 points[0] = Geom::Point(this->x1.computed, this->y1.computed)*i2dt;133
134 points[1] = Geom::Point(this->x2.computed, this->y2.computed)*i2dt;134 points[0] = Geom::Point(this->x1.computed, this->y1.computed)*i2doc;
135 points[1] = Geom::Point(this->x2.computed, this->y2.computed)*i2doc;
135136
136 SPGuide::createSPGuide(this->document, points[0], points[1]);137 SPGuide::createSPGuide(this->document, points[0], points[1]);
137}138}
138139
=== modified file 'src/sp-namedview.cpp'
--- src/sp-namedview.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-namedview.cpp 2014-09-23 18:22:24 +0000
@@ -14,14 +14,19 @@
14 * Released under GNU GPL, read the file 'COPYING' for more information14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */15 */
1616
17#ifdef HAVE_CONFIG_H
17#include "config.h"18#include "config.h"
19#endif
20
18#include <cstring>21#include <cstring>
19#include <string>22#include <string>
20#include "event-log.h"23#include "event-log.h"
21#include <2geom/transforms.h>24#include <2geom/transforms.h>
2225
26#include "display/guideline.h"
23#include "display/canvas-grid.h"27#include "display/canvas-grid.h"
24#include "display/guideline.h"28#include "display/canvas-guide.h"
29
25#include "util/units.h"30#include "util/units.h"
26#include "svg/svg-color.h"31#include "svg/svg-color.h"
27#include "xml/repr.h"32#include "xml/repr.h"
@@ -30,7 +35,6 @@
30#include "document-undo.h"35#include "document-undo.h"
31#include "desktop-events.h"36#include "desktop-events.h"
32#include "desktop-handles.h"37#include "desktop-handles.h"
33#include "sp-guide.h"
34#include "sp-item-group.h"38#include "sp-item-group.h"
35#include "sp-namedview.h"39#include "sp-namedview.h"
36#include "preferences.h"40#include "preferences.h"
@@ -38,6 +42,8 @@
38#include "conn-avoid-ref.h" // for defaultConnSpacing.42#include "conn-avoid-ref.h" // for defaultConnSpacing.
39#include "sp-root.h"43#include "sp-root.h"
40#include <gtkmm/window.h>44#include <gtkmm/window.h>
45#include "guide-manager.h"
46
4147
42using Inkscape::DocumentUndo;48using Inkscape::DocumentUndo;
43using Inkscape::Util::unit_table;49using Inkscape::Util::unit_table;
@@ -1162,6 +1168,24 @@
1162 }1168 }
1163}1169}
11641170
1171// void SPNamedView::transformGuides(Geom::Affine const affine) {
1172
1173// for (GSList *l = guides; l != NULL; l = l->next) {
1174// SPGuide &guide = *SP_GUIDE(l->data);
1175
1176// Geom::Point point_on_line = guide.point_on_line;
1177// Geom::Point normal = guide.normal_to_line;
1178
1179// point_on_line *= affine;
1180// normal = transform_normal(normal, affine);
1181
1182// sp_guide_moveto(guide, point_on_line, true);
1183// sp_guide_set_normal(guide, normal, true);
1184
1185// // TODO attribute names should be changed as well.
1186// }
1187// }
1188
1165void SPNamedView::translateGrids(Geom::Translate const &tr) {1189void SPNamedView::translateGrids(Geom::Translate const &tr) {
1166 for (GSList *l = grids; l != NULL; l = l->next) {1190 for (GSList *l = grids; l != NULL; l = l->next) {
1167 Inkscape::CanvasGrid* g = reinterpret_cast<Inkscape::CanvasGrid*>(l->data);1191 Inkscape::CanvasGrid* g = reinterpret_cast<Inkscape::CanvasGrid*>(l->data);
@@ -1172,10 +1196,10 @@
1172}1196}
11731197
1174void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) {1198void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) {
1175 for(GSList *l = views; l; l = l->next) {1199 for (GSList *l = views; l; l = l->next) {
1176 SPDesktop *desktop = static_cast<SPDesktop *>(l->data);1200 SPDesktop *desktop = static_cast<SPDesktop *>(l->data);
1177 desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling);1201 desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling);
1178 }1202 }
1179}1203}
11801204
11811205
11821206
=== modified file 'src/sp-namedview.h'
--- src/sp-namedview.h 2014-03-27 01:33:44 +0000
+++ src/sp-namedview.h 2014-09-23 18:22:24 +0000
@@ -22,11 +22,13 @@
22#include "document.h"22#include "document.h"
23#include "util/units.h"23#include "util/units.h"
2424
25
25namespace Inkscape {26namespace Inkscape {
26 class CanvasGrid;27class CanvasGrid;
27 namespace Util {28 namespace Util {
28 class Unit;29 class Unit;
29 }30 }
31 class GuideManager;
30}32}
3133
32enum {34enum {
@@ -55,6 +57,7 @@
55 gint window_maximized;57 gint window_maximized;
5658
57 SnapManager snap_manager;59 SnapManager snap_manager;
60 Inkscape::GuideManager *guide_manager;
58 GSList * grids;61 GSList * grids;
59 bool grids_visible;62 bool grids_visible;
6063
@@ -86,6 +89,7 @@
8689
87 void translateGuides(Geom::Translate const &translation);90 void translateGuides(Geom::Translate const &translation);
88 void translateGrids(Geom::Translate const &translation);91 void translateGrids(Geom::Translate const &translation);
92 // void transformGuides(Geom::Affine const affine);
89 void scrollAllDesktops(double dx, double dy, bool is_scrolling);93 void scrollAllDesktops(double dx, double dy, bool is_scrolling);
90 void writeNewGrid(SPDocument *document,int gridtype);94 void writeNewGrid(SPDocument *document,int gridtype);
91 bool getSnapGlobal() const;95 bool getSnapGlobal() const;
@@ -116,8 +120,9 @@
116void sp_namedview_document_from_window(SPDesktop *desktop);120void sp_namedview_document_from_window(SPDesktop *desktop);
117void sp_namedview_update_layers_from_document (SPDesktop *desktop);121void sp_namedview_update_layers_from_document (SPDesktop *desktop);
118122
123void sp_namedview_show_grids(SPNamedView *namedview, bool show, bool dirty_document);
119void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr);124void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr);
120void sp_namedview_show_grids(SPNamedView *namedview, bool show, bool dirty_document);125void sp_namedview_convert_old_guides(SPNamedView * /*nv*/, SPDocument *document, Inkscape::XML::Node *repr);
121Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview);126Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview);
122127
123128
124129
=== modified file 'src/sp-path.cpp'
--- src/sp-path.cpp 2014-07-28 21:44:54 +0000
+++ src/sp-path.cpp 2014-09-23 18:22:24 +0000
@@ -37,7 +37,7 @@
37#include "attributes.h"37#include "attributes.h"
3838
39#include "sp-path.h"39#include "sp-path.h"
40#include "sp-guide.h"40#include "display/canvas-guide.h"
4141
42#include "document.h"42#include "document.h"
43#include "desktop.h"43#include "desktop.h"
@@ -107,7 +107,7 @@
107107
108 std::list<std::pair<Geom::Point, Geom::Point> > pts;108 std::list<std::pair<Geom::Point, Geom::Point> > pts;
109109
110 Geom::Affine const i2dt(this->i2dt_affine());110 Geom::Affine const i2doc(this->i2doc_affine());
111 Geom::PathVector const & pv = this->_curve->get_pathvector();111 Geom::PathVector const & pv = this->_curve->get_pathvector();
112 112
113 for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) {113 for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) {
@@ -115,7 +115,7 @@
115 // only add curves for straight line segments115 // only add curves for straight line segments
116 if( is_straight_curve(*cit) )116 if( is_straight_curve(*cit) )
117 {117 {
118 pts.push_back(std::make_pair(cit->initialPoint() * i2dt, cit->finalPoint() * i2dt));118 pts.push_back(std::make_pair(cit->initialPoint() * i2doc, cit->finalPoint() * i2doc));
119 }119 }
120 }120 }
121 }121 }
122122
=== modified file 'src/sp-rect.cpp'
--- src/sp-rect.cpp 2014-03-27 01:33:44 +0000
+++ src/sp-rect.cpp 2014-09-23 18:22:24 +0000
@@ -26,7 +26,7 @@
26#include "sp-rect.h"26#include "sp-rect.h"
27#include <glibmm/i18n.h>27#include <glibmm/i18n.h>
28#include "xml/repr.h"28#include "xml/repr.h"
29#include "sp-guide.h"29#include "display/canvas-guide.h"
30#include "preferences.h"30#include "preferences.h"
3131
32#define noRECT_VERBOSE32#define noRECT_VERBOSE
@@ -529,12 +529,12 @@
529529
530 std::list<std::pair<Geom::Point, Geom::Point> > pts;530 std::list<std::pair<Geom::Point, Geom::Point> > pts;
531531
532 Geom::Affine const i2dt(this->i2dt_affine());532 Geom::Affine const i2doc(this->i2doc_affine());
533533
534 Geom::Point A1(Geom::Point(this->x.computed, this->y.computed) * i2dt);534 Geom::Point A1(Geom::Point(this->x.computed, this->y.computed) * i2doc);
535 Geom::Point A2(Geom::Point(this->x.computed, this->y.computed + this->height.computed) * i2dt);535 Geom::Point A2(Geom::Point(this->x.computed, this->y.computed + this->height.computed) * i2doc);
536 Geom::Point A3(Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed) * i2dt);536 Geom::Point A3(Geom::Point(this->x.computed + this->width.computed, this->y.computed + this->height.computed) * i2doc);
537 Geom::Point A4(Geom::Point(this->x.computed + this->width.computed, this->y.computed) * i2dt);537 Geom::Point A4(Geom::Point(this->x.computed + this->width.computed, this->y.computed) * i2doc);
538538
539 pts.push_back(std::make_pair(A1, A2));539 pts.push_back(std::make_pair(A1, A2));
540 pts.push_back(std::make_pair(A2, A3));540 pts.push_back(std::make_pair(A2, A3));
541541
=== modified file 'src/ui/dialog/document-properties.cpp'
--- src/ui/dialog/document-properties.cpp 2014-09-08 17:13:03 +0000
+++ src/ui/dialog/document-properties.cpp 2014-09-23 18:22:24 +0000
@@ -19,13 +19,15 @@
19 */19 */
2020
21#ifdef HAVE_CONFIG_H21#ifdef HAVE_CONFIG_H
22# include <config.h>22#include <config.h>
23#endif23#endif
2424
25#include "ui/widget/notebook-page.h"25#include "ui/widget/notebook-page.h"
26#include "document-properties.h"26#include "document-properties.h"
27#include "display/canvas-grid.h"27#include "display/canvas-grid.h"
28#include "display/canvas-guide.h"
28#include "document.h"29#include "document.h"
30#include "document-undo.h"
29#include "desktop-handles.h"31#include "desktop-handles.h"
30#include "desktop.h"32#include "desktop.h"
31#include "inkscape.h"33#include "inkscape.h"
@@ -43,8 +45,10 @@
43#include "ui/dialog/filedialog.h"45#include "ui/dialog/filedialog.h"
44#include "verbs.h"46#include "verbs.h"
45#include "widgets/icon.h"47#include "widgets/icon.h"
48#include "ui/icon-names.h"
46#include "xml/node-event-vector.h"49#include "xml/node-event-vector.h"
47#include "xml/repr.h"50#include "xml/repr.h"
51#include "ui/widget/imagetoggler.h"
48#include <algorithm> // std::min52#include <algorithm> // std::min
4953
50#include "rdf.h"54#include "rdf.h"
@@ -75,20 +79,20 @@
7579
76//---------------------------------------------------80//---------------------------------------------------
7781
78static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);82static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void *data);
79static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);83
80static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);84static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref,
8185 void *data);
82static Inkscape::XML::NodeEventVector const _repr_events = {86
83 on_child_added, // child_added87static void on_repr_attr_changed(Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
84 on_child_removed, // child_removed88
85 on_repr_attr_changed,89static Inkscape::XML::NodeEventVector const _repr_events = { on_child_added, // child_added
86 NULL, // content_changed90 on_child_removed, // child_removed
87 NULL // order_changed91 on_repr_attr_changed, NULL, // content_changed
92 NULL // order_changed
88};93};
8994
9095DocumentProperties &DocumentProperties::getInstance()
91DocumentProperties& DocumentProperties::getInstance()
92{96{
93 DocumentProperties &instance = *new DocumentProperties();97 DocumentProperties &instance = *new DocumentProperties();
94 instance.init();98 instance.init();
@@ -96,70 +100,112 @@
96 return instance;100 return instance;
97}101}
98102
99DocumentProperties::DocumentProperties()103DocumentProperties::DocumentProperties() :
100 : UI::Widget::Panel ("", "/dialogs/documentoptions", SP_VERB_DIALOG_NAMEDVIEW),104 UI::Widget::Panel ("", "/dialogs/documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
101 _page_page(Gtk::manage(new UI::Widget::NotebookPage(1, 1, true, true))),105 _page_page (Gtk::manage(new UI::Widget::NotebookPage(1, 1, true, true))),
102 _page_guides(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),106 _page_guides (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
103 _page_snap(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),107 _page_snap (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
104 _page_cms(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),108 _page_cms (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
105 _page_scripting(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),109 _page_scripting (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
106 _page_external_scripts(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),110 _page_external_scripts (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
107 _page_embedded_scripts(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),111 _page_embedded_scripts (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
108 _page_metadata1(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),112 _page_metadata1 (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
109 _page_metadata2(Gtk::manage(new UI::Widget::NotebookPage(1, 1))),113 _page_metadata2 (Gtk::manage(new UI::Widget::NotebookPage(1, 1))),
110 //---------------------------------------------------------------114//---------------------------------------------------------------
111 _rcb_antialias(_("Use antialiasing"), _("If unset, no antialiasing will be done on the drawing"), "shape-rendering", _wr, false, NULL, NULL, NULL, "crispEdges"),115 _rcb_antialias(_("Use antialiasing"),
112 _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false),116 _("If unset, no antialiasing will be done on the drawing"),
113 _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false),117 "shape-rendering", _wr, false, NULL, NULL, NULL, "crispEdges"),
114 _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false),118
115 _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),119 _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"),
116 _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr),120 "showborder", _wr, false),
117 _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr),121
118 _page_sizer(_wr),122 _rcb_bord(_("Border on _top of drawing"),
119 //---------------------------------------------------------------123 _("If set, border is always on top of the drawing"),
120 //General snap options124 "borderlayer", _wr, false),
121 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),125
122 _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr),126 _rcb_shad(_("_Show border shadow"),
123 _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),127 _("If set, page border shows a shadow on its right and lower side"),
124 //---------------------------------------------------------------128 "inkscape:showpageshadow", _wr, false),
125 _rsu_sno(_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),129
126 _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),130 _rcp_bg(_("Back_ground color:"), _("Background color"),
127 _("If set, objects only snap to another object when it's within the range specified below"),131 _("Color of the page background. Note: transparency setting ignored"
128 "objecttolerance", _wr),132 "while editing but used when exporting to bitmap."),
129 //Options for snapping to grids133 "pagecolor", "inkscape:pageopacity", _wr),
134
135 _rcp_bord(_("Border _color:"), _("Page border color"),
136 _("Color of the page border"), "bordercolor", "borderopacity", _wr),
137
138 _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr),
139
140 _page_sizer(_wr),
141
142//---------------------------------------------------------------
143// General snap options
144// TODO: might have to clean these up, as might not used anymore.
145
146 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
147
148 _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"),
149 "guidecolor", "guideopacity", _wr),
150
151 _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"),
152 _("Color of a guideline when it is under mouse"),
153 "guidehicolor", "guidehiopacity", _wr),
154//---------------------------------------------------------------
155 _rsu_sno(_("Snap _distance"), _("Snap only when _closer than:"),
156 _("Always snap"),
157 _("Snapping distance, in screen pixels, for snapping to objects"),
158 _("Always snap to objects, regardless of their distance"),
159 _("If set, objects only snap to another object when it's within the range specified below"),
160 "objecttolerance", _wr),
161// Options for snapping to grids
130 _rsu_sn(_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),162 _rsu_sn(_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
131 _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),163 _("Snapping distance, in screen pixels, for snapping to grid"),
132 _("If set, objects only snap to a grid line when it's within the range specified below"),164 _("Always snap to grids, regardless of the distance"),
133 "gridtolerance", _wr),165 _("If set, objects only snap to a grid line when it's within the range specified below"),
134 //Options for snapping to guides166 "gridtolerance", _wr),
167
168// Options for snapping to guides
135 _rsu_gusn(_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),169 _rsu_gusn(_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
136 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),170 _("Snapping distance, in screen pixels, for snapping to guides"),
137 _("If set, objects only snap to a guide when it's within the range specified below"),171 _("Always snap to guides, regardless of the distance"),
138 "guidetolerance", _wr),172 _("If set, objects only snap to a guide when it's within the range specified below"),
139 //---------------------------------------------------------------173 "guidetolerance", _wr),
140 _rcb_snclp(_("Snap to clip paths"), _("When snapping to paths, then also try snapping to clip paths"), "inkscape:snap-path-clip", _wr),174//---------------------------------------------------------------
141 _rcb_snmsk(_("Snap to mask paths"), _("When snapping to paths, then also try snapping to mask paths"), "inkscape:snap-path-mask", _wr),175 _rcb_snclp(_("Snap to clip paths"),
142 _rcb_perp(_("Snap perpendicularly"), _("When snapping to paths or guides, then also try snapping perpendicularly"), "inkscape:snap-perpendicular", _wr),176 _("When snapping to paths, then also try snapping to clip paths"),
143 _rcb_tang(_("Snap tangentially"), _("When snapping to paths or guides, then also try snapping tangentially"), "inkscape:snap-tangential", _wr),177 "inkscape:snap-path-clip", _wr),
144 //---------------------------------------------------------------178
145 _grids_label_crea("", Gtk::ALIGN_START),179 _rcb_snmsk(_("Snap to mask paths"),
146 _grids_button_new(C_("Grid", "_New"), _("Create new grid.")),180 _("When snapping to paths, then also try snapping to mask paths"),
147 _grids_button_remove(C_("Grid", "_Remove"), _("Remove selected grid.")),181 "inkscape:snap-path-mask", _wr),
148 _grids_label_def("", Gtk::ALIGN_START)182
183 _rcb_perp(_("Snap perpendicularly"),
184 _("When snapping to paths or guides, then also try snapping perpendicularly"),
185 "inkscape:snap-perpendicular", _wr),
186
187 _rcb_tang(_("Snap tangentially"),
188 _("When snapping to paths or guides, then also try snapping tangentially"),
189 "inkscape:snap-tangential", _wr),
190//---------------------------------------------------------------
191 _grids_label_crea("", Gtk::ALIGN_START),
192 _grids_button_new(C_("Grid", "_New"), _("Create new grid.")),
193 _grids_button_remove(C_("Grid", "_Remove"), _("Remove selected grid.")),
194 _grids_label_def("", Gtk::ALIGN_START)
149{195{
150 _getContents()->set_spacing (4);196 _getContents()->set_spacing(4);
151 _getContents()->pack_start(_notebook, true, true);197 _getContents()->pack_start(_notebook, true, true);
152198
153 _notebook.append_page(*_page_page, _("Page"));199 _notebook.append_page(*_page_page, _("Page"));
154 _notebook.append_page(*_page_guides, _("Guides"));200 _notebook.append_page(*_page_guides, _("Guides"));
155 _notebook.append_page(_grids_vbox, _("Grids"));201 _notebook.append_page(_grids_vbox, _("Grids"));
156 _notebook.append_page(*_page_snap, _("Snap"));202 _notebook.append_page(*_page_snap, _("Snap"));
157 _notebook.append_page(*_page_cms, _("Color"));203 _notebook.append_page(*_page_cms, _("Color"));
158 _notebook.append_page(*_page_scripting, _("Scripting"));204 _notebook.append_page(*_page_scripting, _("Scripting"));
159 _notebook.append_page(*_page_metadata1, _("Metadata"));205 _notebook.append_page(*_page_metadata1, _("Metadata"));
160 _notebook.append_page(*_page_metadata2, _("License"));206 _notebook.append_page(*_page_metadata2, _("License"));
161207
162 _wr.setUpdating (true);208 _wr.setUpdating(true);
163 build_page();209 build_page();
164 build_guides();210 build_guides();
165 build_gridspage();211 build_gridspage();
@@ -169,7 +215,9 @@
169#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)215#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
170 build_scripting();216 build_scripting();
171 build_metadata();217 build_metadata();
172 _wr.setUpdating (false);218 _wr.setUpdating(false);
219
220 _refresh_guidelist_button.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::populate_guides_list));
173221
174 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));222 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
175 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));223 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
@@ -187,126 +235,138 @@
187 update();235 update();
188236
189 Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();237 Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();
190 repr->addListener (&_repr_events, this);238 repr->addListener(&_repr_events, this);
191 Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr();239 Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr();
192 root->addListener (&_repr_events, this);240 root->addListener(&_repr_events, this);
193241
194 show_all_children();242 show_all_children();
195 _grids_button_remove.hide();243 _grids_button_remove.hide();
244 _guidelist.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
196}245}
197246
198DocumentProperties::~DocumentProperties()247DocumentProperties::~DocumentProperties()
199{248{
200 Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();249 Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();
201 repr->removeListenerByData (this);250 repr->removeListenerByData(this);
202 Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr();251 Inkscape::XML::Node *root = sp_desktop_document(getDesktop())->getRoot()->getRepr();
203 root->removeListenerByData (this);252 root->removeListenerByData(this);
204253
205 for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it)254 for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); ++it) {
206 delete (*it);255 delete (*it);
256 }
207}257}
208258
209//========================================================================259//========================================================================
210260
211/**261/**
212 * Helper function that attaches widgets in a 3xn table. The widgets come in an262 * Helper function that attaches widgets in a 3xn table. The widgets come in an array that has two
213 * array that has two entries per table row. The two entries code for four263 * entries per table row.
214 * possible cases: (0,0) means insert space in first column; (0, non-0) means264 *
215 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and265 * The two entries describe the four possible cases:
266 *
267 * (0, 0) means insert space in first column.
268 *
269 * (0, non-0) means widget in columns 2-3.
270 *
271 * (non-0, 0) means label in columns 1-3.
272 *
216 * (non-0, non-0) means two widgets in columns 2 and 3.273 * (non-0, non-0) means two widgets in columns 2 and 3.
274 *
217 */275 */
218#if WITH_GTKMM_3_0276#if WITH_GTKMM_3_0
219inline void attach_all(Gtk::Grid &table, Gtk::Widget *const arr[], unsigned const n, int start = 0, int docum_prop_flag = 0)277inline void attach_all(Gtk::Grid &table, Gtk::Widget *const arr[], unsigned const n, int start = 0,
278 int docum_prop_flag = 0)
220#else279#else
221inline void attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0, int docum_prop_flag = 0)280inline void attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0,
281 int docum_prop_flag = 0)
222#endif282#endif
223{283{
224 for (unsigned i = 0, r = start; i < n; i += 2) {284 for (unsigned i = 0, r = start; i < n; i += 2) {
225 if (arr[i] && arr[i+1]) {285 if (arr[i] && arr[i + 1]) {
226#if WITH_GTKMM_3_0286#if WITH_GTKMM_3_0
227 arr[i]->set_hexpand();287 arr[i]->set_hexpand();
228 arr[i+1]->set_hexpand();288 arr[i + 1]->set_hexpand();
229 arr[i]->set_valign(Gtk::ALIGN_CENTER);289 arr[i]->set_valign(Gtk::ALIGN_CENTER);
230 arr[i+1]->set_valign(Gtk::ALIGN_CENTER);290 arr[i + 1]->set_valign(Gtk::ALIGN_CENTER);
231 table.attach(*arr[i], 1, r, 1, 1);291 table.attach(*arr[i], 1, r, 1, 1);
232 table.attach(*arr[i+1], 2, r, 1, 1);292 table.attach(*arr[i + 1], 2, r, 1, 1);
233#else293#else
234 table.attach(*arr[i], 1, 2, r, r+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);294 table.attach(*arr[i], 1, 2, r, r + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
235 table.attach(*arr[i+1], 2, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);295 table.attach(*arr[i + 1], 2, 3, r, r + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
236#endif296#endif
237 } else {297 } else {
238 if (arr[i+1]) {298 if (arr[i + 1]) {
239 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;299 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;
240 if (dynamic_cast<Inkscape::UI::Widget::PageSizer*>(arr[i+1])) {300 if (dynamic_cast<Inkscape::UI::Widget::PageSizer *>(arr[i + 1])) {
241 // only the PageSizer in Document Properties|Page should be stretched vertically301 // only the PageSizer in Document Properties|Page should be stretched vertically
242 yoptions = Gtk::FILL|Gtk::EXPAND;302 yoptions = Gtk::FILL | Gtk::EXPAND;
243 }303 }
244 if (docum_prop_flag) {304 if (docum_prop_flag) {
245 // this sets the padding for subordinate widgets on the "Page" page305 // this sets the padding for subordinate widgets on the "Page" page
246 if( i==(n-8) || i==(n-10) ) {306 if (i == (n - 8) || i == (n - 10)) {
247#if WITH_GTKMM_3_0307#if WITH_GTKMM_3_0
248 arr[i+1]->set_hexpand();308 arr[i + 1]->set_hexpand();
249 arr[i+1]->set_margin_left(20);309 arr[i + 1]->set_margin_left(20);
250 arr[i+1]->set_margin_right(20);310 arr[i + 1]->set_margin_right(20);
251311
252 if (yoptions & Gtk::EXPAND)312 if (yoptions & Gtk::EXPAND)
253 arr[i+1]->set_vexpand();313 arr[i + 1]->set_vexpand();
254 else314 else
255 arr[i+1]->set_valign(Gtk::ALIGN_CENTER);315 arr[i + 1]->set_valign(Gtk::ALIGN_CENTER);
256316
257 table.attach(*arr[i+1], 1, r, 2, 1);317 table.attach(*arr[i + 1], 1, r, 2, 1);
258#else318#else
259 table.attach(*arr[i+1], 1, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, yoptions, 20,0);319 table.attach(*arr[i + 1], 1, 3, r, r + 1, Gtk::FILL | Gtk::EXPAND, yoptions, 20, 0);
260#endif320#endif
261 } else {321 } else {
262#if WITH_GTKMM_3_0322#if WITH_GTKMM_3_0
263 arr[i+1]->set_hexpand();323 arr[i + 1]->set_hexpand();
264324
265 if (yoptions & Gtk::EXPAND)325 if (yoptions & Gtk::EXPAND)
266 arr[i+1]->set_vexpand();326 arr[i + 1]->set_vexpand();
267 else327 else
268 arr[i+1]->set_valign(Gtk::ALIGN_CENTER);328 arr[i + 1]->set_valign(Gtk::ALIGN_CENTER);
269329
270 table.attach(*arr[i+1], 1, r, 2, 1);330 table.attach(*arr[i + 1], 1, r, 2, 1);
271#else331#else
272 table.attach(*arr[i+1], 1, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);332 table.attach(*arr[i + 1], 1, 3, r, r + 1, Gtk::FILL | Gtk::EXPAND, yoptions, 0, 0);
273#endif333#endif
274 }334 }
275 } else {335 } else {
276#if WITH_GTKMM_3_0336#if WITH_GTKMM_3_0
277 arr[i+1]->set_hexpand();337 arr[i + 1]->set_hexpand();
278 338
279 if (yoptions & Gtk::EXPAND)339 if (yoptions & Gtk::EXPAND)
280 arr[i+1]->set_vexpand();340 arr[i + 1]->set_vexpand();
281 else341 else
282 arr[i+1]->set_valign(Gtk::ALIGN_CENTER);342 arr[i + 1]->set_valign(Gtk::ALIGN_CENTER);
283343
284 table.attach(*arr[i+1], 1, r, 2, 1);344 table.attach(*arr[i + 1], 1, r, 2, 1);
285#else345#else
286 table.attach(*arr[i+1], 1, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);346 table.attach(*arr[i + 1], 1, 3, r, r + 1, Gtk::FILL | Gtk::EXPAND, yoptions, 0, 0);
287#endif347#endif
288 }348 }
289 } else if (arr[i]) {349 } else if (arr[i]) {
290 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);350 Gtk::Label &label = reinterpret_cast<Gtk::Label &>(*arr[i]);
291 label.set_alignment (0.0);351 label.set_alignment(0.0);
292352
293#if WITH_GTKMM_3_0353#if WITH_GTKMM_3_0
294 label.set_hexpand();354 label.set_hexpand();
295 label.set_valign(Gtk::ALIGN_CENTER);355 label.set_valign(Gtk::ALIGN_CENTER);
296 table.attach(label, 0, r, 3, 1);356 table.attach(label, 0, r, 3, 1);
297#else357#else
298 table.attach (label, 0, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);358 table.attach(label, 0, 3, r, r + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
299#endif359#endif
300 } else {360 } else {
301 Gtk::HBox *space = Gtk::manage (new Gtk::HBox);361 Gtk::HBox *space = Gtk::manage(new Gtk::HBox);
302 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);362 space->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
303363
304#if WITH_GTKMM_3_0364#if WITH_GTKMM_3_0
305 space->set_halign(Gtk::ALIGN_CENTER);365 space->set_halign(Gtk::ALIGN_CENTER);
306 space->set_valign(Gtk::ALIGN_CENTER);366 space->set_valign(Gtk::ALIGN_CENTER);
307 table.attach(*space, 0, r, 1, 1);367 table.attach(*space, 0, r, 1, 1);
308#else368#else
309 table.attach (*space, 0, 1, r, r+1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);369 table.attach(*space, 0, 1, r, r + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 0, 0);
310#endif370#endif
311 }371 }
312 }372 }
@@ -318,20 +378,20 @@
318{378{
319 _page_page->show();379 _page_page->show();
320380
321 Gtk::Label* label_gen = Gtk::manage (new Gtk::Label);381 Gtk::Label *label_gen = Gtk::manage(new Gtk::Label);
322 label_gen->set_markup (_("<b>General</b>"));382 label_gen->set_markup(_("<b>General</b>"));
323 Gtk::Label *label_for = Gtk::manage (new Gtk::Label);383 Gtk::Label *label_for = Gtk::manage(new Gtk::Label);
324 label_for->set_markup (_("<b>Page Size</b>"));384 label_for->set_markup(_("<b>Page Size</b>"));
325 Gtk::Label* label_dsp = Gtk::manage (new Gtk::Label);385 Gtk::Label *label_dsp = Gtk::manage(new Gtk::Label);
326 label_dsp->set_markup (_("<b>Display</b>"));386 label_dsp->set_markup(_("<b>Display</b>"));
327 _page_sizer.init();387 _page_sizer.init();
328388
329 Gtk::Widget *const widget_array[] =389 Gtk::Widget *const widget_array[] =
330 {390 {
331 label_gen, 0,391 label_gen, 0,
332 0, &_rum_deflt,392 0, &_rum_deflt,
333 //label_col, 0,393 // label_col, 0,
334 //_rcp_bg._label, &_rcp_bg,394 // _rcp_bg._label, &_rcp_bg,
335 0, 0,395 0, 0,
336 label_for, 0,396 label_for, 0,
337 0, &_page_sizer,397 0, &_page_sizer,
@@ -345,76 +405,225 @@
345 _rcp_bord._label, &_rcp_bord,405 _rcp_bord._label, &_rcp_bord,
346 };406 };
347407
348 std::list<Gtk::Widget*> _slaveList;408 std::list<Gtk::Widget *> _slaveList;
349 _slaveList.push_back(&_rcb_bord);409 _slaveList.push_back(&_rcb_bord);
350 _slaveList.push_back(&_rcb_shad);410 _slaveList.push_back(&_rcb_shad);
351 _rcb_canb.setSlaveWidgets(_slaveList);411 _rcb_canb.setSlaveWidgets(_slaveList);
352412
353 attach_all(_page_page->table(), widget_array, G_N_ELEMENTS(widget_array),0,1);413 attach_all(_page_page->table(), widget_array, G_N_ELEMENTS(widget_array), 0, 1);
414}
415
416void DocumentProperties::guides_page_config_buttons()
417{
418 _delete_guide_button.set_label(_("Delete"));
419 _delete_guide_button.set_image(*Gtk::manage(new Gtk::Image(Gtk::Stock::REMOVE, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
420 _delete_guide_button.set_tooltip_text(_("Delete guide"));
421 _delete_guide_button.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::delete_selected_guides));
422 _delete_guide_button.set_alignment(0.0, 0.0);
423
424 _refresh_guidelist_button.set_image(
425 *Gtk::manage(new Gtk::Image(Gtk::Stock::REFRESH, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
426 _refresh_guidelist_button.set_tooltip_text(_("Refresh guide list"));
427 _refresh_guidelist_button.set_label(_("Refresh"));
428}
429
430void DocumentProperties::guides_page_attach_widgets()
431{
432#if WITH_GTKMM_3_0
433 // _page_guides->table().attach(*label_guidelist, 0, row++, 1, 1);
434 // _page_guides->table().attach(_guidelist_ListScroller, 0, row++, 1, 1);
435 // _page_guides->table().attach(_delete_guide_button, 0, row++, 1, 1);
436 // _page_guides->table().attach(_refresh_guidelist_button, 0, row, 1, 1);
437#else
438 Gtk::Label *label_gui = Gtk::manage(new Gtk::Label);
439 label_gui->set_markup(_("<b>Guides</b>"));
440
441 Gtk::Widget *const widget_array[] =
442 {
443 label_gui, 0,
444 0, &_rcb_sgui,
445 _rcp_gui._label, &_rcp_gui,
446 _rcp_hgui._label, &_rcp_hgui
447 };
448
449 attach_all(_page_guides->table(), widget_array, G_N_ELEMENTS(widget_array));
450
451 Gtk::Label *label_guidelist = manage(new Gtk::Label("", Gtk::ALIGN_START));
452 label_guidelist->set_markup(_("<b>Guide list:</b>"));
453 label_guidelist->set_alignment(0.0);
454
455 Gtk::HBox *spacer = Gtk::manage(new Gtk::HBox());
456 spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
457
458 _page_guides->set_spacing(4);
459
460 gint row = 4;
461
462 _page_guides->table().attach(*label_guidelist, 0, 1, row, row + 1,
463 Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions) 0,
464 0, 1);
465 row++;
466
467 _page_guides->table().attach(_guidelist_ListScroller, 0, 1, row, row + 1,
468 Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions) 0,
469 0, 0);
470 row++;
471
472 _page_guides->table().attach(_delete_guide_button, 0, 1, row, row + 1,
473 (Gtk::AttachOptions) 0, (Gtk::AttachOptions) 0,
474 0, 0);
475 row++;
476
477 _page_guides->table().attach(_refresh_guidelist_button, 0, 1, row, row + 1,
478 (Gtk::AttachOptions) 0, (Gtk::AttachOptions) 0,
479 0, 0);
480#endif
481}
482
483void DocumentProperties::guides_page_config_guidelist()
484{
485 using Inkscape::UI::Widget::ImageToggler;
486
487 ImageToggler *visiblity_toggler =
488 Gtk::manage(new ImageToggler(INKSCAPE_ICON("object-visible"),
489 INKSCAPE_ICON("object-hidden")));
490
491 ImageToggler *lock_toggler =
492 Gtk::manage(new ImageToggler(INKSCAPE_ICON("object-locked"),
493 INKSCAPE_ICON("object-unlocked")));
494
495 _guidelist_ListStore = Gtk::ListStore::create(_guidelist_columns);
496 _guidelist.set_model(_guidelist_ListStore);
497 _guidelist.append_column("", *visiblity_toggler);
498 _guidelist.append_column("", *lock_toggler);
499 _guidelist.append_column(_("Guide id"), _guidelist_columns.guide_name_column);
500 _guidelist.set_headers_visible(false);
501
502 _guidelist_ListScroller.add(_guidelist);
503 _guidelist_ListScroller.set_shadow_type(Gtk::SHADOW_IN);
504 _guidelist_ListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
505 _guidelist_ListScroller.set_size_request(-1, 90);
354}506}
355507
356void DocumentProperties::build_guides()508void DocumentProperties::build_guides()
357{509{
358 _page_guides->show();510 _page_guides->show();
359511 guides_page_config_buttons();
360 Gtk::Label *label_gui = Gtk::manage (new Gtk::Label);512 guides_page_attach_widgets();
361 label_gui->set_markup (_("<b>Guides</b>"));513 guides_page_config_guidelist();
362514 populate_guides_list();
363 Gtk::Widget *const widget_array[] =515}
364 {516
365 label_gui, 0,517void DocumentProperties::delete_guide_in_treeview_row(const Gtk::TreeModel::iterator &iter)
366 0, &_rcb_sgui,518{
367 _rcp_gui._label, &_rcp_gui,519 SPDesktop *desktop = getDesktop();
368 _rcp_hgui._label, &_rcp_hgui520
369 };521 if (!desktop) {
370522 return;
371 attach_all(_page_guides->table(), widget_array, G_N_ELEMENTS(widget_array));523 }
524
525 SPDocument *document = sp_desktop_document(desktop);
526
527 if (!document) {
528 return;
529 }
530
531 Glib::ustring guide_id = (*iter)[_guidelist_columns.guide_id_column];
532
533 SPObject *guide = document->getObjectById(guide_id.c_str());
534
535 if (!SP_IS_GUIDE(guide)) {
536 return;
537 }
538 else {
539 sp_guide_remove((SPGuide *) guide);
540 DocumentUndo::maybeDone(document, "guide:delete",
541 SP_VERB_NONE, _("Delete selected guides."));
542 }
543}
544
545void DocumentProperties::delete_selected_guides()
546{
547 _guidelist.get_selection()->selected_foreach_iter
548 (sigc::mem_fun(*this, &DocumentProperties::delete_guide_in_treeview_row));
549
550 populate_guides_list();
551}
552
553void DocumentProperties::populate_guides_list()
554{
555 SPDesktop *desktop = getDesktop();
556
557 if (!desktop) {
558 return;
559 }
560
561 SPNamedView *named_view = sp_desktop_namedview(desktop);
562
563 if (!named_view) {
564 return;
565 }
566
567 _guidelist_ListStore->clear();
568
569 for (SPObject *object = named_view->firstChild(); object; object = object->getNext()) {
570
571 if (SP_IS_GUIDE(object)) {
572
573 SPGuide *guide = SP_GUIDE(object);
574 Gtk::TreeModel::Row row = *(_guidelist_ListStore->append());
575
576 const gchar *guide_id = guide->getAttribute("id");
577
578 if (guide_id) {
579
580 if (guide->label != NULL) {
581 row[_guidelist_columns.guide_name_column] = guide->label;
582 }
583 else {
584 row[_guidelist_columns.guide_name_column] = guide_id;
585 }
586
587 row[_guidelist_columns.guide_id_column] = guide_id;
588 }
589 }
590 }
372}591}
373592
374void DocumentProperties::build_snap()593void DocumentProperties::build_snap()
375{594{
376 _page_snap->show();595 _page_snap->show();
377596
378 Gtk::Label *label_o = Gtk::manage (new Gtk::Label);597 Gtk::Label *label_o = Gtk::manage(new Gtk::Label);
379 label_o->set_markup (_("<b>Snap to objects</b>"));598 label_o->set_markup(_("<b>Snap to objects</b>"));
380 Gtk::Label *label_gr = Gtk::manage (new Gtk::Label);599 Gtk::Label *label_gr = Gtk::manage(new Gtk::Label);
381 label_gr->set_markup (_("<b>Snap to grids</b>"));600 label_gr->set_markup(_("<b>Snap to grids</b>"));
382 Gtk::Label *label_gu = Gtk::manage (new Gtk::Label);601 Gtk::Label *label_gu = Gtk::manage(new Gtk::Label);
383 label_gu->set_markup (_("<b>Snap to guides</b>"));602 label_gu->set_markup(_("<b>Snap to guides</b>"));
384 Gtk::Label *label_m = Gtk::manage (new Gtk::Label);603 Gtk::Label *label_m = Gtk::manage(new Gtk::Label);
385 label_m->set_markup (_("<b>Miscellaneous</b>"));604 label_m->set_markup(_("<b>Miscellaneous</b>"));
386605
387 Gtk::Widget *const array[] =606 Gtk::Widget *const array[] = { label_o, 0, 0, _rsu_sno._vbox, 0, &_rcb_snclp,
388 {607 0, &_rcb_snmsk, 0, 0, label_gr, 0,
389 label_o, 0,608 0, _rsu_sn._vbox, 0, 0, label_gu, 0,
390 0, _rsu_sno._vbox,609 0, _rsu_gusn._vbox, 0, 0, label_m, 0,
391 0, &_rcb_snclp,610 0, &_rcb_perp, 0, &_rcb_tang };
392 0, &_rcb_snmsk,
393 0, 0,
394 label_gr, 0,
395 0, _rsu_sn._vbox,
396 0, 0,
397 label_gu, 0,
398 0, _rsu_gusn._vbox,
399 0, 0,
400 label_m, 0,
401 0, &_rcb_perp,
402 0, &_rcb_tang
403 };
404611
405 attach_all(_page_snap->table(), array, G_N_ELEMENTS(array));612 attach_all(_page_snap->table(), array, G_N_ELEMENTS(array));
406 }613}
407614
408#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)615#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
409/// Populates the available color profiles combo box616/// Populates the available color profiles combo box
410void DocumentProperties::populate_available_profiles(){617void DocumentProperties::populate_available_profiles()
618{
411 _combo_avail.remove_all(); // Clear any existing items in the combo box619 _combo_avail.remove_all(); // Clear any existing items in the combo box
412620
413 // Iterate through the list of profiles and add the name to the combo box.621 // Iterate through the list of profiles and add the name to the combo box.
414 std::vector<std::pair<Glib::ustring, Glib::ustring> > pairs = ColorProfile::getProfileFilesWithNames();622 std::vector<std::pair<Glib::ustring, Glib::ustring> > pairs = ColorProfile::getProfileFilesWithNames();
415 for ( std::vector<std::pair<Glib::ustring, Glib::ustring> >::const_iterator it = pairs.begin(); it != pairs.end(); ++it ) {623 for (std::vector<std::pair<Glib::ustring, Glib::ustring> >::const_iterator it = pairs.begin(); it != pairs.end();
624 ++it) {
416 Glib::ustring name = it->second;625 Glib::ustring name = it->second;
417 _combo_avail.append(name);626 _combo_avail.append(name);
418 }627 }
419}628}
420629
@@ -422,29 +631,21 @@
422 * Cleans up name to remove disallowed characters.631 * Cleans up name to remove disallowed characters.
423 * Some discussion at http://markmail.org/message/bhfvdfptt25kgtmj632 * Some discussion at http://markmail.org/message/bhfvdfptt25kgtmj
424 * Allowed ASCII first characters: ':', 'A'-'Z', '_', 'a'-'z'633 * Allowed ASCII first characters: ':', 'A'-'Z', '_', 'a'-'z'
425 * Allowed ASCII remaining chars add: '-', '.', '0'-'9', 634 * Allowed ASCII remaining chars add: '-', '.', '0'-'9',
426 *635 *
427 * @param str the string to clean up.636 * @param str the string to clean up.
428 */637 */
429static void sanitizeName( Glib::ustring& str )638static void sanitizeName(Glib::ustring &str)
430{639{
431 if (str.size() > 1) {640 if (str.size() > 1) {
432 char val = str.at(0);641 char val = str.at(0);
433 if (((val < 'A') || (val > 'Z'))642 if (((val < 'A') || (val > 'Z')) && ((val < 'a') || (val > 'z')) && (val != '_') && (val != ':')) {
434 && ((val < 'a') || (val > 'z'))
435 && (val != '_')
436 && (val != ':')) {
437 str.replace(0, 1, "-");643 str.replace(0, 1, "-");
438 }644 }
439 for (Glib::ustring::size_type i = 1; i < str.size(); i++) {645 for (Glib::ustring::size_type i = 1; i < str.size(); i++) {
440 char val = str.at(i);646 char val = str.at(i);
441 if (((val < 'A') || (val > 'Z'))647 if (((val < 'A') || (val > 'Z')) && ((val < 'a') || (val > 'z')) && ((val < '0') || (val > '9')) &&
442 && ((val < 'a') || (val > 'z'))648 (val != '_') && (val != ':') && (val != '-') && (val != '.')) {
443 && ((val < '0') || (val > '9'))
444 && (val != '_')
445 && (val != ':')
446 && (val != '-')
447 && (val != '.')) {
448 str.replace(i, 1, "-");649 str.replace(i, 1, "-");
449 }650 }
450 }651 }
@@ -454,36 +655,36 @@
454/// Links the selected color profile in the combo box to the document655/// Links the selected color profile in the combo box to the document
455void DocumentProperties::linkSelectedProfile()656void DocumentProperties::linkSelectedProfile()
456{657{
457//store this profile in the SVG document (create <color-profile> element in the XML)658 // store this profile in the SVG document (create <color-profile> element in the XML)
458 // TODO remove use of 'active' desktop659 // TODO remove use of 'active' desktop
459 SPDesktop *desktop = SP_ACTIVE_DESKTOP;660 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
460 if (!desktop){661 if (!desktop) {
461 g_warning("No active desktop");662 g_warning("No active desktop");
462 } else {663 } else {
463 // Find the index of the currently-selected row in the color profiles combobox664 // Find the index of the currently-selected row in the color profiles combobox
464 int row = _combo_avail.get_active_row_number();665 int row = _combo_avail.get_active_row_number();
465666
466 if (row == -1){667 if (row == -1) {
467 g_warning("No color profile available.");668 g_warning("No color profile available.");
468 return;669 return;
469 }670 }
470 671
471 // Read the filename and description from the list of available profiles672 // Read the filename and description from the list of available profiles
472 std::vector<std::pair<Glib::ustring, Glib::ustring> > pairs = ColorProfile::getProfileFilesWithNames();673 std::vector<std::pair<Glib::ustring, Glib::ustring> > pairs = ColorProfile::getProfileFilesWithNames();
473 Glib::ustring file = pairs[row].first;674 Glib::ustring file = pairs[row].first;
474 Glib::ustring name = pairs[row].second;675 Glib::ustring name = pairs[row].second;
475676
476 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();677 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
477 Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");678 Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
478 gchar* tmp = g_strdup(name.c_str());679 gchar *tmp = g_strdup(name.c_str());
479 Glib::ustring nameStr = tmp ? tmp : "profile"; // TODO add some auto-numbering to avoid collisions680 Glib::ustring nameStr = tmp ? tmp : "profile"; // TODO add some auto-numbering to avoid collisions
480 sanitizeName(nameStr);681 sanitizeName(nameStr);
481 cprofRepr->setAttribute("name", nameStr.c_str());682 cprofRepr->setAttribute("name", nameStr.c_str());
482 cprofRepr->setAttribute("xlink:href", (gchar*) file.c_str());683 cprofRepr->setAttribute("xlink:href", (gchar *)file.c_str());
483684
484 // Checks whether there is a defs element. Creates it when needed685 // Checks whether there is a defs element. Creates it when needed
485 Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");686 Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");
486 if (!defsRepr){687 if (!defsRepr) {
487 defsRepr = xml_doc->createElement("svg:defs");688 defsRepr = xml_doc->createElement("svg:defs");
488 xml_doc->root()->addChild(defsRepr, NULL);689 xml_doc->root()->addChild(defsRepr, NULL);
489 }690 }
@@ -492,7 +693,7 @@
492 defsRepr->addChild(cprofRepr, NULL);693 defsRepr->addChild(cprofRepr, NULL);
493694
494 // TODO check if this next line was sometimes needed. It being there caused an assertion.695 // TODO check if this next line was sometimes needed. It being there caused an assertion.
495 //Inkscape::GC::release(defsRepr);696 // Inkscape::GC::release(defsRepr);
496697
497 // inform the document, so we can undo698 // inform the document, so we can undo
498 DocumentUndo::done(desktop->doc(), SP_VERB_EDIT_LINK_COLOR_PROFILE, _("Link Color Profile"));699 DocumentUndo::done(desktop->doc(), SP_VERB_EDIT_LINK_COLOR_PROFILE, _("Link Color Profile"));
@@ -504,44 +705,44 @@
504void DocumentProperties::populate_linked_profiles_box()705void DocumentProperties::populate_linked_profiles_box()
505{706{
506 _LinkedProfilesListStore->clear();707 _LinkedProfilesListStore->clear();
507 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" );708 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("iccprofile");
508 if (current) {709 if (current) {
509 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);710 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
510 }711 }
511 while ( current ) {712 while (current) {
512 SPObject* obj = SP_OBJECT(current->data);713 SPObject *obj = SP_OBJECT(current->data);
513 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);714 Inkscape::ColorProfile *prof = reinterpret_cast<Inkscape::ColorProfile *>(obj);
514 Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append());715 Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append());
515 row[_LinkedProfilesListColumns.nameColumn] = prof->name;716 row[_LinkedProfilesListColumns.nameColumn] = prof->name;
516// row[_LinkedProfilesListColumns.previewColumn] = "Color Preview";717 // row[_LinkedProfilesListColumns.previewColumn] = "Color Preview";
517 current = g_slist_next(current);718 current = g_slist_next(current);
518 }719 }
519}720}
520721
521void DocumentProperties::external_scripts_list_button_release(GdkEventButton* event)722void DocumentProperties::external_scripts_list_button_release(GdkEventButton *event)
522{723{
523 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {724 if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
524 _ExternalScriptsContextMenu.popup(event->button, event->time);725 _ExternalScriptsContextMenu.popup(event->button, event->time);
525 }726 }
526}727}
527728
528void DocumentProperties::embedded_scripts_list_button_release(GdkEventButton* event)729void DocumentProperties::embedded_scripts_list_button_release(GdkEventButton *event)
529{730{
530 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {731 if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
531 _EmbeddedScriptsContextMenu.popup(event->button, event->time);732 _EmbeddedScriptsContextMenu.popup(event->button, event->time);
532 }733 }
533}734}
534735
535void DocumentProperties::linked_profiles_list_button_release(GdkEventButton* event)736void DocumentProperties::linked_profiles_list_button_release(GdkEventButton *event)
536{737{
537 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {738 if ((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
538 _EmbProfContextMenu.popup(event->button, event->time);739 _EmbProfContextMenu.popup(event->button, event->time);
539 }740 }
540}741}
541742
542void DocumentProperties::cms_create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)743void DocumentProperties::cms_create_popup_menu(Gtk::Widget &parent, sigc::slot<void> rem)
543{744{
544 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));745 Gtk::MenuItem *mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
545 _EmbProfContextMenu.append(*mi);746 _EmbProfContextMenu.append(*mi);
546 mi->signal_activate().connect(rem);747 mi->signal_activate().connect(rem);
547 mi->show();748 mi->show();
@@ -549,18 +750,18 @@
549}750}
550751
551752
552void DocumentProperties::external_create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)753void DocumentProperties::external_create_popup_menu(Gtk::Widget &parent, sigc::slot<void> rem)
553{754{
554 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));755 Gtk::MenuItem *mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
555 _ExternalScriptsContextMenu.append(*mi);756 _ExternalScriptsContextMenu.append(*mi);
556 mi->signal_activate().connect(rem);757 mi->signal_activate().connect(rem);
557 mi->show();758 mi->show();
558 _ExternalScriptsContextMenu.accelerate(parent);759 _ExternalScriptsContextMenu.accelerate(parent);
559}760}
560761
561void DocumentProperties::embedded_create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)762void DocumentProperties::embedded_create_popup_menu(Gtk::Widget &parent, sigc::slot<void> rem)
562{763{
563 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));764 Gtk::MenuItem *mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
564 _EmbeddedScriptsContextMenu.append(*mi);765 _EmbeddedScriptsContextMenu.append(*mi);
565 mi->signal_activate().connect(rem);766 mi->signal_activate().connect(rem);
566 mi->show();767 mi->show();
@@ -571,30 +772,31 @@
571{772{
572 Glib::RefPtr<Gtk::TreeSelection> sel = _LinkedProfilesList.get_selection();773 Glib::RefPtr<Gtk::TreeSelection> sel = _LinkedProfilesList.get_selection();
573 if (sel) {774 if (sel) {
574 _unlink_btn.set_sensitive(sel->count_selected_rows () > 0);775 _unlink_btn.set_sensitive(sel->count_selected_rows() > 0);
575 }776 }
576}777}
577778
578779
579void DocumentProperties::removeSelectedProfile(){780void DocumentProperties::removeSelectedProfile()
781{
580 Glib::ustring name;782 Glib::ustring name;
581 if(_LinkedProfilesList.get_selection()) {783 if (_LinkedProfilesList.get_selection()) {
582 Gtk::TreeModel::iterator i = _LinkedProfilesList.get_selection()->get_selected();784 Gtk::TreeModel::iterator i = _LinkedProfilesList.get_selection()->get_selected();
583785
584 if(i){786 if (i) {
585 name = (*i)[_LinkedProfilesListColumns.nameColumn];787 name = (*i)[_LinkedProfilesListColumns.nameColumn];
586 } else {788 } else {
587 return;789 return;
588 }790 }
589 }791 }
590792
591 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" );793 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("iccprofile");
592 while ( current ) {794 while (current) {
593 SPObject* obj = SP_OBJECT(current->data);795 SPObject *obj = SP_OBJECT(current->data);
594 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);796 Inkscape::ColorProfile *prof = reinterpret_cast<Inkscape::ColorProfile *>(obj);
595 if (!name.compare(prof->name)){797 if (!name.compare(prof->name)) {
596798
597 //XML Tree being used directly here while it shouldn't be.799 // XML Tree being used directly here while it shouldn't be.
598 sp_repr_unparent(obj->getRepr());800 sp_repr_unparent(obj->getRepr());
599 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile"));801 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile"));
600 break; // removing the color profile likely invalidates part of the traversed list, stop traversing here.802 break; // removing the color profile likely invalidates part of the traversed list, stop traversing here.
@@ -609,10 +811,10 @@
609void DocumentProperties::build_cms()811void DocumentProperties::build_cms()
610{812{
611 _page_cms->show();813 _page_cms->show();
612 Gtk::Label *label_link= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START));814 Gtk::Label *label_link = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
613 label_link->set_markup (_("<b>Linked Color Profiles:</b>"));815 label_link->set_markup(_("<b>Linked Color Profiles:</b>"));
614 Gtk::Label *label_avail = Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START));816 Gtk::Label *label_avail = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
615 label_avail->set_markup (_("<b>Available Color Profiles:</b>"));817 label_avail->set_markup(_("<b>Available Color Profiles:</b>"));
616818
617 _link_btn.set_tooltip_text(_("Link Profile"));819 _link_btn.set_tooltip_text(_("Link Profile"));
618#if WITH_GTKMM_3_10820#if WITH_GTKMM_3_10
@@ -642,7 +844,7 @@
642 label_link->set_valign(Gtk::ALIGN_CENTER);844 label_link->set_valign(Gtk::ALIGN_CENTER);
643 _page_cms->table().attach(*label_link, 0, row, 3, 1);845 _page_cms->table().attach(*label_link, 0, row, 3, 1);
644#else846#else
645 _page_cms->table().attach(*label_link, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);847 _page_cms->table().attach(*label_link, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
646#endif848#endif
647849
648 row++;850 row++;
@@ -652,12 +854,13 @@
652 _LinkedProfilesListScroller.set_valign(Gtk::ALIGN_CENTER);854 _LinkedProfilesListScroller.set_valign(Gtk::ALIGN_CENTER);
653 _page_cms->table().attach(_LinkedProfilesListScroller, 0, row, 3, 1);855 _page_cms->table().attach(_LinkedProfilesListScroller, 0, row, 3, 1);
654#else856#else
655 _page_cms->table().attach(_LinkedProfilesListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);857 _page_cms->table().attach(_LinkedProfilesListScroller, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
858 (Gtk::AttachOptions)0, 0, 0);
656#endif859#endif
657860
658 row++;861 row++;
659862
660 Gtk::HBox* spacer = Gtk::manage(new Gtk::HBox());863 Gtk::HBox *spacer = Gtk::manage(new Gtk::HBox());
661 spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);864 spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
662865
663#if WITH_GTKMM_3_0866#if WITH_GTKMM_3_0
@@ -665,7 +868,7 @@
665 spacer->set_valign(Gtk::ALIGN_CENTER);868 spacer->set_valign(Gtk::ALIGN_CENTER);
666 _page_cms->table().attach(*spacer, 0, row, 3, 1);869 _page_cms->table().attach(*spacer, 0, row, 3, 1);
667#else870#else
668 _page_cms->table().attach(*spacer, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);871 _page_cms->table().attach(*spacer, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
669#endif872#endif
670873
671 row++;874 row++;
@@ -677,7 +880,7 @@
677 label_avail->set_valign(Gtk::ALIGN_CENTER);880 label_avail->set_valign(Gtk::ALIGN_CENTER);
678 _page_cms->table().attach(*label_avail, 0, row, 3, 1);881 _page_cms->table().attach(*label_avail, 0, row, 3, 1);
679#else882#else
680 _page_cms->table().attach(*label_avail, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);883 _page_cms->table().attach(*label_avail, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
681#endif884#endif
682885
683 row++;886 row++;
@@ -697,7 +900,7 @@
697 _unlink_btn.set_valign(Gtk::ALIGN_CENTER);900 _unlink_btn.set_valign(Gtk::ALIGN_CENTER);
698 _page_cms->table().attach(_unlink_btn, 2, row, 1, 1);901 _page_cms->table().attach(_unlink_btn, 2, row, 1, 1);
699#else902#else
700 _page_cms->table().attach(_combo_avail, 0, 1, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);903 _page_cms->table().attach(_combo_avail, 0, 1, row, row + 1, Gtk::FILL | Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
701 _page_cms->table().attach(_link_btn, 1, 2, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 2, 0);904 _page_cms->table().attach(_link_btn, 1, 2, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 2, 0);
702 _page_cms->table().attach(_unlink_btn, 2, 3, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 0, 0);905 _page_cms->table().attach(_unlink_btn, 2, 3, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 0, 0);
703#endif906#endif
@@ -708,9 +911,9 @@
708 _LinkedProfilesListStore = Gtk::ListStore::create(_LinkedProfilesListColumns);911 _LinkedProfilesListStore = Gtk::ListStore::create(_LinkedProfilesListColumns);
709 _LinkedProfilesList.set_model(_LinkedProfilesListStore);912 _LinkedProfilesList.set_model(_LinkedProfilesListStore);
710 _LinkedProfilesList.append_column(_("Profile Name"), _LinkedProfilesListColumns.nameColumn);913 _LinkedProfilesList.append_column(_("Profile Name"), _LinkedProfilesListColumns.nameColumn);
711// _LinkedProfilesList.append_column(_("Color Preview"), _LinkedProfilesListColumns.previewColumn);914 // _LinkedProfilesList.append_column(_("Color Preview"), _LinkedProfilesListColumns.previewColumn);
712 _LinkedProfilesList.set_headers_visible(false);915 _LinkedProfilesList.set_headers_visible(false);
713// TODO restore? _LinkedProfilesList.set_fixed_height_mode(true);916 // TODO restore? _LinkedProfilesList.set_fixed_height_mode(true);
714917
715 populate_linked_profiles_box();918 populate_linked_profiles_box();
716919
@@ -722,16 +925,19 @@
722 _link_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::linkSelectedProfile));925 _link_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::linkSelectedProfile));
723 _unlink_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));926 _unlink_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));
724927
725 _LinkedProfilesList.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &DocumentProperties::onColorProfileSelectRow) );928 _LinkedProfilesList.get_selection()->signal_changed().connect(
929 sigc::mem_fun(*this, &DocumentProperties::onColorProfileSelectRow));
726930
727 _LinkedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::linked_profiles_list_button_release));931 _LinkedProfilesList.signal_button_release_event().connect_notify(
932 sigc::mem_fun(*this, &DocumentProperties::linked_profiles_list_button_release));
728 cms_create_popup_menu(_LinkedProfilesList, sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));933 cms_create_popup_menu(_LinkedProfilesList, sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));
729934
730 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "defs" );935 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("defs");
731 if (current) {936 if (current) {
732 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);937 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
733 }938 }
734 _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_linked_profiles_box));939 _emb_profiles_observer.signal_changed().connect(
940 sigc::mem_fun(*this, &DocumentProperties::populate_linked_profiles_box));
735 onColorProfileSelectRow();941 onColorProfileSelectRow();
736}942}
737#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)943#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
@@ -740,7 +946,7 @@
740{946{
741 _page_scripting->show();947 _page_scripting->show();
742948
743 _page_scripting->set_spacing (4);949 _page_scripting->set_spacing(4);
744 _page_scripting->pack_start(_scripting_notebook, true, true);950 _page_scripting->pack_start(_scripting_notebook, true, true);
745951
746 _scripting_notebook.append_page(*_page_external_scripts, _("External scripts"));952 _scripting_notebook.append_page(*_page_external_scripts, _("External scripts"));
@@ -748,8 +954,8 @@
748954
749 //# External scripts tab955 //# External scripts tab
750 _page_external_scripts->show();956 _page_external_scripts->show();
751 Gtk::Label *label_external= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START));957 Gtk::Label *label_external = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
752 label_external->set_markup (_("<b>External script files:</b>"));958 label_external->set_markup(_("<b>External script files:</b>"));
753959
754 _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file"));960 _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file"));
755#if WITH_GTKMM_3_10961#if WITH_GTKMM_3_10
@@ -779,7 +985,8 @@
779 label_external->set_valign(Gtk::ALIGN_CENTER);985 label_external->set_valign(Gtk::ALIGN_CENTER);
780 _page_external_scripts->table().attach(*label_external, 0, row, 3, 1);986 _page_external_scripts->table().attach(*label_external, 0, row, 3, 1);
781#else987#else
782 _page_external_scripts->table().attach(*label_external, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);988 _page_external_scripts->table().attach(*label_external, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
989 (Gtk::AttachOptions)0, 0, 0);
783#endif990#endif
784991
785 row++;992 row++;
@@ -789,12 +996,13 @@
789 _ExternalScriptsListScroller.set_valign(Gtk::ALIGN_CENTER);996 _ExternalScriptsListScroller.set_valign(Gtk::ALIGN_CENTER);
790 _page_external_scripts->table().attach(_ExternalScriptsListScroller, 0, row, 3, 1);997 _page_external_scripts->table().attach(_ExternalScriptsListScroller, 0, row, 3, 1);
791#else998#else
792 _page_external_scripts->table().attach(_ExternalScriptsListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);999 _page_external_scripts->table().attach(_ExternalScriptsListScroller, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1000 (Gtk::AttachOptions)0, 0, 0);
793#endif1001#endif
7941002
795 row++;1003 row++;
7961004
797 Gtk::HBox* spacer_external = Gtk::manage(new Gtk::HBox());1005 Gtk::HBox *spacer_external = Gtk::manage(new Gtk::HBox());
798 spacer_external->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);1006 spacer_external->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
7991007
800#if WITH_GTKMM_3_01008#if WITH_GTKMM_3_0
@@ -802,7 +1010,8 @@
802 spacer_external->set_valign(Gtk::ALIGN_CENTER);1010 spacer_external->set_valign(Gtk::ALIGN_CENTER);
803 _page_external_scripts->table().attach(*spacer_external, 0, row, 3, 1);1011 _page_external_scripts->table().attach(*spacer_external, 0, row, 3, 1);
804#else1012#else
805 _page_external_scripts->table().attach(*spacer_external, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1013 _page_external_scripts->table().attach(*spacer_external, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1014 (Gtk::AttachOptions)0, 0, 0);
806#endif1015#endif
8071016
808 row++;1017 row++;
@@ -822,9 +1031,12 @@
822 _external_remove_btn.set_valign(Gtk::ALIGN_CENTER);1031 _external_remove_btn.set_valign(Gtk::ALIGN_CENTER);
823 _page_external_scripts->table().attach(_external_remove_btn, 2, row, 1, 1);1032 _page_external_scripts->table().attach(_external_remove_btn, 2, row, 1, 1);
824#else1033#else
825 _page_external_scripts->table().attach(_script_entry, 0, 1, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1034 _page_external_scripts->table().attach(_script_entry, 0, 1, row, row + 1, Gtk::FILL | Gtk::EXPAND,
826 _page_external_scripts->table().attach(_external_add_btn, 1, 2, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 2, 0);1035 (Gtk::AttachOptions)0, 0, 0);
827 _page_external_scripts->table().attach(_external_remove_btn, 2, 3, row, row + 1, (Gtk::AttachOptions)0, (Gtk::AttachOptions)0, 0, 0);1036 _page_external_scripts->table().attach(_external_add_btn, 1, 2, row, row + 1, (Gtk::AttachOptions)0,
1037 (Gtk::AttachOptions)0, 2, 0);
1038 _page_external_scripts->table().attach(_external_remove_btn, 2, 3, row, row + 1, (Gtk::AttachOptions)0,
1039 (Gtk::AttachOptions)0, 0, 0);
828#endif1040#endif
8291041
830 //# Set up the External Scripts box1042 //# Set up the External Scripts box
@@ -832,13 +1044,13 @@
832 _ExternalScriptsList.set_model(_ExternalScriptsListStore);1044 _ExternalScriptsList.set_model(_ExternalScriptsListStore);
833 _ExternalScriptsList.append_column(_("Filename"), _ExternalScriptsListColumns.filenameColumn);1045 _ExternalScriptsList.append_column(_("Filename"), _ExternalScriptsListColumns.filenameColumn);
834 _ExternalScriptsList.set_headers_visible(true);1046 _ExternalScriptsList.set_headers_visible(true);
835// TODO restore? _ExternalScriptsList.set_fixed_height_mode(true);1047 // TODO restore? _ExternalScriptsList.set_fixed_height_mode(true);
8361048
8371049
838 //# Embedded scripts tab1050 //# Embedded scripts tab
839 _page_embedded_scripts->show();1051 _page_embedded_scripts->show();
840 Gtk::Label *label_embedded= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START));1052 Gtk::Label *label_embedded = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
841 label_embedded->set_markup (_("<b>Embedded script files:</b>"));1053 label_embedded->set_markup(_("<b>Embedded script files:</b>"));
8421054
843 _embed_new_btn.set_tooltip_text(_("New"));1055 _embed_new_btn.set_tooltip_text(_("New"));
844#if WITH_GTKMM_3_101056#if WITH_GTKMM_3_10
@@ -861,10 +1073,10 @@
861#if !WITH_GTKMM_3_01073#if !WITH_GTKMM_3_0
862 // TODO: This has been removed from Gtkmm 3.0. Check that1074 // TODO: This has been removed from Gtkmm 3.0. Check that
863 // everything still looks OK!1075 // everything still looks OK!
864 _embed_button_box.set_child_min_width( 16 );1076 _embed_button_box.set_child_min_width(16);
865 _embed_button_box.set_spacing( 4 );1077 _embed_button_box.set_spacing(4);
866#endif1078#endif
867 _embed_button_box.set_layout (Gtk::BUTTONBOX_START);1079 _embed_button_box.set_layout(Gtk::BUTTONBOX_START);
868 _embed_button_box.add(_embed_new_btn);1080 _embed_button_box.add(_embed_new_btn);
869 _embed_button_box.add(_embed_remove_btn);1081 _embed_button_box.add(_embed_remove_btn);
8701082
@@ -878,7 +1090,8 @@
878 label_embedded->set_valign(Gtk::ALIGN_CENTER);1090 label_embedded->set_valign(Gtk::ALIGN_CENTER);
879 _page_embedded_scripts->table().attach(*label_embedded, 0, row, 3, 1);1091 _page_embedded_scripts->table().attach(*label_embedded, 0, row, 3, 1);
880#else1092#else
881 _page_embedded_scripts->table().attach(*label_embedded, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1093 _page_embedded_scripts->table().attach(*label_embedded, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1094 (Gtk::AttachOptions)0, 0, 0);
882#endif1095#endif
8831096
884 row++;1097 row++;
@@ -888,7 +1101,8 @@
888 _EmbeddedScriptsListScroller.set_valign(Gtk::ALIGN_CENTER);1101 _EmbeddedScriptsListScroller.set_valign(Gtk::ALIGN_CENTER);
889 _page_embedded_scripts->table().attach(_EmbeddedScriptsListScroller, 0, row, 3, 1);1102 _page_embedded_scripts->table().attach(_EmbeddedScriptsListScroller, 0, row, 3, 1);
890#else1103#else
891 _page_embedded_scripts->table().attach(_EmbeddedScriptsListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1104 _page_embedded_scripts->table().attach(_EmbeddedScriptsListScroller, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1105 (Gtk::AttachOptions)0, 0, 0);
892#endif1106#endif
8931107
894 row++;1108 row++;
@@ -898,12 +1112,13 @@
898 _embed_button_box.set_valign(Gtk::ALIGN_CENTER);1112 _embed_button_box.set_valign(Gtk::ALIGN_CENTER);
899 _page_embedded_scripts->table().attach(_embed_button_box, 0, row, 1, 1);1113 _page_embedded_scripts->table().attach(_embed_button_box, 0, row, 1, 1);
900#else1114#else
901 _page_embedded_scripts->table().attach(_embed_button_box, 0, 1, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1115 _page_embedded_scripts->table().attach(_embed_button_box, 0, 1, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1116 (Gtk::AttachOptions)0, 0, 0);
902#endif1117#endif
9031118
904 row++;1119 row++;
9051120
906 Gtk::HBox* spacer_embedded = Gtk::manage(new Gtk::HBox());1121 Gtk::HBox *spacer_embedded = Gtk::manage(new Gtk::HBox());
907 spacer_embedded->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);1122 spacer_embedded->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
9081123
909#if WITH_GTKMM_3_01124#if WITH_GTKMM_3_0
@@ -911,7 +1126,8 @@
911 spacer_embedded->set_valign(Gtk::ALIGN_CENTER);1126 spacer_embedded->set_valign(Gtk::ALIGN_CENTER);
912 _page_embedded_scripts->table().attach(*spacer_embedded, 0, row, 3, 1);1127 _page_embedded_scripts->table().attach(*spacer_embedded, 0, row, 3, 1);
913#else1128#else
914 _page_embedded_scripts->table().attach(*spacer_embedded, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1129 _page_embedded_scripts->table().attach(*spacer_embedded, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1130 (Gtk::AttachOptions)0, 0, 0);
915#endif1131#endif
9161132
917 row++;1133 row++;
@@ -921,11 +1137,11 @@
921 _EmbeddedScriptsList.set_model(_EmbeddedScriptsListStore);1137 _EmbeddedScriptsList.set_model(_EmbeddedScriptsListStore);
922 _EmbeddedScriptsList.append_column(_("Script id"), _EmbeddedScriptsListColumns.idColumn);1138 _EmbeddedScriptsList.append_column(_("Script id"), _EmbeddedScriptsListColumns.idColumn);
923 _EmbeddedScriptsList.set_headers_visible(true);1139 _EmbeddedScriptsList.set_headers_visible(true);
924// TODO restore? _EmbeddedScriptsList.set_fixed_height_mode(true);1140 // TODO restore? _EmbeddedScriptsList.set_fixed_height_mode(true);
9251141
926 //# Set up the Embedded Scripts content box1142 //# Set up the Embedded Scripts content box
927 Gtk::Label *label_embedded_content= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START));1143 Gtk::Label *label_embedded_content = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
928 label_embedded_content->set_markup (_("<b>Content:</b>"));1144 label_embedded_content->set_markup(_("<b>Content:</b>"));
9291145
930 label_embedded_content->set_alignment(0.0);1146 label_embedded_content->set_alignment(0.0);
9311147
@@ -934,7 +1150,8 @@
934 label_embedded_content->set_valign(Gtk::ALIGN_CENTER);1150 label_embedded_content->set_valign(Gtk::ALIGN_CENTER);
935 _page_embedded_scripts->table().attach(*label_embedded_content, 0, row, 3, 1);1151 _page_embedded_scripts->table().attach(*label_embedded_content, 0, row, 3, 1);
936#else1152#else
937 _page_embedded_scripts->table().attach(*label_embedded_content, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1153 _page_embedded_scripts->table().attach(*label_embedded_content, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1154 (Gtk::AttachOptions)0, 0, 0);
938#endif1155#endif
9391156
940 row++;1157 row++;
@@ -944,7 +1161,8 @@
944 _EmbeddedContentScroller.set_valign(Gtk::ALIGN_CENTER);1161 _EmbeddedContentScroller.set_valign(Gtk::ALIGN_CENTER);
945 _page_embedded_scripts->table().attach(_EmbeddedContentScroller, 0, row, 3, 1);1162 _page_embedded_scripts->table().attach(_EmbeddedContentScroller, 0, row, 3, 1);
946#else1163#else
947 _page_embedded_scripts->table().attach(_EmbeddedContentScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);1164 _page_embedded_scripts->table().attach(_EmbeddedContentScroller, 0, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1165 (Gtk::AttachOptions)0, 0, 0);
948#endif1166#endif
9491167
950 _EmbeddedContentScroller.add(_EmbeddedContent);1168 _EmbeddedContentScroller.add(_EmbeddedContent);
@@ -952,12 +1170,16 @@
952 _EmbeddedContentScroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);1170 _EmbeddedContentScroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
953 _EmbeddedContentScroller.set_size_request(-1, 140);1171 _EmbeddedContentScroller.set_size_request(-1, 140);
9541172
955 _EmbeddedScriptsList.signal_cursor_changed().connect(sigc::mem_fun(*this, &DocumentProperties::changeEmbeddedScript));1173 _EmbeddedScriptsList.signal_cursor_changed().connect(
956 _EmbeddedScriptsList.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &DocumentProperties::onEmbeddedScriptSelectRow) );1174 sigc::mem_fun(*this, &DocumentProperties::changeEmbeddedScript));
9571175 _EmbeddedScriptsList.get_selection()->signal_changed().connect(
958 _ExternalScriptsList.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &DocumentProperties::onExternalScriptSelectRow) );1176 sigc::mem_fun(*this, &DocumentProperties::onEmbeddedScriptSelectRow));
9591177
960 _EmbeddedContent.get_buffer()->signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::editEmbeddedScript));1178 _ExternalScriptsList.get_selection()->signal_changed().connect(
1179 sigc::mem_fun(*this, &DocumentProperties::onExternalScriptSelectRow));
1180
1181 _EmbeddedContent.get_buffer()->signal_changed().connect(
1182 sigc::mem_fun(*this, &DocumentProperties::editEmbeddedScript));
9611183
962 populate_script_lists();1184 populate_script_lists();
9631185
@@ -980,15 +1202,17 @@
980 _external_remove_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeExternalScript));1202 _external_remove_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeExternalScript));
981 _embed_remove_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeEmbeddedScript));1203 _embed_remove_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::removeEmbeddedScript));
9821204
983 _ExternalScriptsList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::external_scripts_list_button_release));1205 _ExternalScriptsList.signal_button_release_event().connect_notify(
1206 sigc::mem_fun(*this, &DocumentProperties::external_scripts_list_button_release));
984 external_create_popup_menu(_ExternalScriptsList, sigc::mem_fun(*this, &DocumentProperties::removeExternalScript));1207 external_create_popup_menu(_ExternalScriptsList, sigc::mem_fun(*this, &DocumentProperties::removeExternalScript));
9851208
986 _EmbeddedScriptsList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::embedded_scripts_list_button_release));1209 _EmbeddedScriptsList.signal_button_release_event().connect_notify(
1210 sigc::mem_fun(*this, &DocumentProperties::embedded_scripts_list_button_release));
987 embedded_create_popup_menu(_EmbeddedScriptsList, sigc::mem_fun(*this, &DocumentProperties::removeEmbeddedScript));1211 embedded_create_popup_menu(_EmbeddedScriptsList, sigc::mem_fun(*this, &DocumentProperties::removeEmbeddedScript));
988#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)1212#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
9891213
990//TODO: review this observers code:1214 // TODO: review this observers code:
991 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );1215 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("script");
992 if (current) {1216 if (current) {
993 _scripts_observer.set(SP_OBJECT(current->data)->parent);1217 _scripts_observer.set(SP_OBJECT(current->data)->parent);
994 }1218 }
@@ -1003,26 +1227,26 @@
10031227
1004 _page_metadata1->show();1228 _page_metadata1->show();
10051229
1006 Gtk::Label *label = Gtk::manage (new Gtk::Label);1230 Gtk::Label *label = Gtk::manage(new Gtk::Label);
1007 label->set_markup (_("<b>Dublin Core Entities</b>"));1231 label->set_markup(_("<b>Dublin Core Entities</b>"));
1008 label->set_alignment (0.0);1232 label->set_alignment(0.0);
10091233
1010#if WITH_GTKMM_3_01234#if WITH_GTKMM_3_0
1011 label->set_valign(Gtk::ALIGN_CENTER);1235 label->set_valign(Gtk::ALIGN_CENTER);
1012 _page_metadata1->table().attach (*label, 0,0,3,1);1236 _page_metadata1->table().attach(*label, 0, 0, 3, 1);
1013#else1237#else
1014 _page_metadata1->table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);1238 _page_metadata1->table().attach(*label, 0, 3, 0, 1, Gtk::FILL, (Gtk::AttachOptions)0, 0, 0);
1015#endif1239#endif
10161240
1017 /* add generic metadata entry areas */1241 /* add generic metadata entry areas */
1018 struct rdf_work_entity_t * entity;1242 struct rdf_work_entity_t *entity;
1019 int row = 1;1243 int row = 1;
1020 for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {1244 for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {
1021 if ( entity->editable == RDF_EDIT_GENERIC ) {1245 if (entity->editable == RDF_EDIT_GENERIC) {
1022 EntityEntry *w = EntityEntry::create (entity, _wr);1246 EntityEntry *w = EntityEntry::create(entity, _wr);
1023 _rdflist.push_back (w);1247 _rdflist.push_back(w);
1024 Gtk::HBox *space = Gtk::manage (new Gtk::HBox);1248 Gtk::HBox *space = Gtk::manage(new Gtk::HBox);
1025 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);1249 space->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
10261250
1027#if WITH_GTKMM_3_01251#if WITH_GTKMM_3_0
1028 space->set_valign(Gtk::ALIGN_CENTER);1252 space->set_valign(Gtk::ALIGN_CENTER);
@@ -1035,22 +1259,23 @@
1035 w->_packable->set_valign(Gtk::ALIGN_CENTER);1259 w->_packable->set_valign(Gtk::ALIGN_CENTER);
1036 _page_metadata1->table().attach(*w->_packable, 2, row, 1, 1);1260 _page_metadata1->table().attach(*w->_packable, 2, row, 1, 1);
1037#else1261#else
1038 _page_metadata1->table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);1262 _page_metadata1->table().attach(*space, 0, 1, row, row + 1, Gtk::FILL, (Gtk::AttachOptions)0, 0, 0);
1039 _page_metadata1->table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);1263 _page_metadata1->table().attach(w->_label, 1, 2, row, row + 1, Gtk::FILL, (Gtk::AttachOptions)0, 0, 0);
1040 _page_metadata1->table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);1264 _page_metadata1->table().attach(*w->_packable, 2, 3, row, row + 1, Gtk::FILL | Gtk::EXPAND,
1265 (Gtk::AttachOptions)0, 0, 0);
1041#endif1266#endif
1042 }1267 }
1043 }1268 }
10441269
1045 Gtk::Button *button_save = Gtk::manage (new Gtk::Button(_("_Save as default"),1));1270 Gtk::Button *button_save = Gtk::manage(new Gtk::Button(_("_Save as default"), 1));
1046 button_save->set_tooltip_text(_("Save this metadata as the default metadata"));1271 button_save->set_tooltip_text(_("Save this metadata as the default metadata"));
1047 Gtk::Button *button_load = Gtk::manage (new Gtk::Button(_("Use _default"),1));1272 Gtk::Button *button_load = Gtk::manage(new Gtk::Button(_("Use _default"), 1));
1048 button_load->set_tooltip_text(_("Use the previously saved default metadata here"));1273 button_load->set_tooltip_text(_("Use the previously saved default metadata here"));
10491274
1050#if WITH_GTKMM_3_01275#if WITH_GTKMM_3_0
1051 Gtk::ButtonBox *box_buttons = Gtk::manage (new Gtk::ButtonBox);1276 Gtk::ButtonBox *box_buttons = Gtk::manage(new Gtk::ButtonBox);
1052#else1277#else
1053 Gtk::HButtonBox *box_buttons = Gtk::manage (new Gtk::HButtonBox);1278 Gtk::HButtonBox *box_buttons = Gtk::manage(new Gtk::HButtonBox);
1054#endif1279#endif
10551280
1056 box_buttons->set_layout(Gtk::BUTTONBOX_END);1281 box_buttons->set_layout(Gtk::BUTTONBOX_END);
@@ -1065,22 +1290,22 @@
1065 _page_metadata2->show();1290 _page_metadata2->show();
10661291
1067 row = 0;1292 row = 0;
1068 Gtk::Label *llabel = Gtk::manage (new Gtk::Label);1293 Gtk::Label *llabel = Gtk::manage(new Gtk::Label);
1069 llabel->set_markup (_("<b>License</b>"));1294 llabel->set_markup(_("<b>License</b>"));
1070 llabel->set_alignment (0.0);1295 llabel->set_alignment(0.0);
10711296
1072#if WITH_GTKMM_3_01297#if WITH_GTKMM_3_0
1073 llabel->set_valign(Gtk::ALIGN_CENTER);1298 llabel->set_valign(Gtk::ALIGN_CENTER);
1074 _page_metadata2->table().attach(*llabel, 0, row, 3, 1);1299 _page_metadata2->table().attach(*llabel, 0, row, 3, 1);
1075#else1300#else
1076 _page_metadata2->table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);1301 _page_metadata2->table().attach(*llabel, 0, 3, row, row + 1, Gtk::FILL, (Gtk::AttachOptions)0, 0, 0);
1077#endif1302#endif
10781303
1079 /* add license selector pull-down and URI */1304 /* add license selector pull-down and URI */
1080 ++row;1305 ++row;
1081 _licensor.init (_wr);1306 _licensor.init(_wr);
1082 Gtk::HBox *space = Gtk::manage (new Gtk::HBox);1307 Gtk::HBox *space = Gtk::manage(new Gtk::HBox);
1083 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);1308 space->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
10841309
1085#if WITH_GTKMM_3_01310#if WITH_GTKMM_3_0
1086 space->set_valign(Gtk::ALIGN_CENTER);1311 space->set_valign(Gtk::ALIGN_CENTER);
@@ -1090,12 +1315,14 @@
1090 _licensor.set_valign(Gtk::ALIGN_CENTER);1315 _licensor.set_valign(Gtk::ALIGN_CENTER);
1091 _page_metadata2->table().attach(_licensor, 1, row, 3, 1);1316 _page_metadata2->table().attach(_licensor, 1, row, 3, 1);
1092#else1317#else
1093 _page_metadata2->table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);1318 _page_metadata2->table().attach(*space, 0, 1, row, row + 1, Gtk::FILL, (Gtk::AttachOptions)0, 0, 0);
1094 _page_metadata2->table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);1319 _page_metadata2->table().attach(_licensor, 1, 3, row, row + 1, Gtk::EXPAND | Gtk::FILL, (Gtk::AttachOptions)0, 0,
1320 0);
1095#endif1321#endif
1096}1322}
10971323
1098void DocumentProperties::addExternalScript(){1324void DocumentProperties::addExternalScript()
1325{
10991326
1100 SPDesktop *desktop = SP_ACTIVE_DESKTOP;1327 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1101 if (!desktop) {1328 if (!desktop) {
@@ -1103,7 +1330,7 @@
1103 return;1330 return;
1104 }1331 }
11051332
1106 if (_script_entry.get_text().empty() ) {1333 if (_script_entry.get_text().empty()) {
1107 // Click Add button with no filename, show a Browse dialog1334 // Click Add button with no filename, show a Browse dialog
1108 browseExternalScript();1335 browseExternalScript();
1109 }1336 }
@@ -1112,7 +1339,7 @@
11121339
1113 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();1340 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
1114 Inkscape::XML::Node *scriptRepr = xml_doc->createElement("svg:script");1341 Inkscape::XML::Node *scriptRepr = xml_doc->createElement("svg:script");
1115 scriptRepr->setAttribute("xlink:href", (gchar*) _script_entry.get_text().c_str());1342 scriptRepr->setAttribute("xlink:href", (gchar *)_script_entry.get_text().c_str());
1116 _script_entry.set_text("");1343 _script_entry.set_text("");
11171344
1118 xml_doc->root()->addChild(scriptRepr, NULL);1345 xml_doc->root()->addChild(scriptRepr, NULL);
@@ -1122,12 +1349,12 @@
11221349
1123 populate_script_lists();1350 populate_script_lists();
1124 }1351 }
1125
1126}1352}
11271353
1128static Inkscape::UI::Dialog::FileOpenDialog * selectPrefsFileInstance = NULL;1354static Inkscape::UI::Dialog::FileOpenDialog *selectPrefsFileInstance = NULL;
11291355
1130void DocumentProperties::browseExternalScript() {1356void DocumentProperties::browseExternalScript()
1357{
11311358
1132 //# Get the current directory for finding files1359 //# Get the current directory for finding files
1133 static Glib::ustring open_path;1360 static Glib::ustring open_path;
@@ -1135,16 +1362,15 @@
11351362
11361363
1137 Glib::ustring attr = prefs->getString(_prefs_path);1364 Glib::ustring attr = prefs->getString(_prefs_path);
1138 if (!attr.empty()) open_path = attr;1365 if (!attr.empty())
1366 open_path = attr;
11391367
1140 //# Test if the open_path directory exists1368 //# Test if the open_path directory exists
1141 if (!Inkscape::IO::file_test(open_path.c_str(),1369 if (!Inkscape::IO::file_test(open_path.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1142 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
1143 open_path = "";1370 open_path = "";
11441371
1145 //# If no open path, default to our home directory1372 //# If no open path, default to our home directory
1146 if (open_path.empty())1373 if (open_path.empty()) {
1147 {
1148 open_path = g_get_home_dir();1374 open_path = g_get_home_dir();
1149 open_path.append(G_DIR_SEPARATOR_S);1375 open_path.append(G_DIR_SEPARATOR_S);
1150 }1376 }
@@ -1152,12 +1378,8 @@
1152 //# Create a dialog1378 //# Create a dialog
1153 SPDesktop *desktop = SP_ACTIVE_DESKTOP;1379 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1154 if (!selectPrefsFileInstance) {1380 if (!selectPrefsFileInstance) {
1155 selectPrefsFileInstance =1381 selectPrefsFileInstance = Inkscape::UI::Dialog::FileOpenDialog::create(
1156 Inkscape::UI::Dialog::FileOpenDialog::create(1382 *desktop->getToplevel(), open_path, Inkscape::UI::Dialog::CUSTOM_TYPE, _("Select a script to load"));
1157 *desktop->getToplevel(),
1158 open_path,
1159 Inkscape::UI::Dialog::CUSTOM_TYPE,
1160 _("Select a script to load"));
1161 selectPrefsFileInstance->addFilterMenu("Javascript Files", "*.js");1383 selectPrefsFileInstance->addFilterMenu("Javascript Files", "*.js");
1162 }1384 }
11631385
@@ -1174,9 +1396,10 @@
1174 _script_entry.set_text(fileName);1396 _script_entry.set_text(fileName);
1175}1397}
11761398
1177void DocumentProperties::addEmbeddedScript(){1399void DocumentProperties::addEmbeddedScript()
1400{
1178 SPDesktop *desktop = SP_ACTIVE_DESKTOP;1401 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1179 if (!desktop){1402 if (!desktop) {
1180 g_warning("No active desktop");1403 g_warning("No active desktop");
1181 } else {1404 } else {
1182 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();1405 Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
@@ -1191,32 +1414,34 @@
1191 }1414 }
1192}1415}
11931416
1194void DocumentProperties::removeExternalScript(){1417void DocumentProperties::removeExternalScript()
1418{
1195 Glib::ustring name;1419 Glib::ustring name;
1196 if(_ExternalScriptsList.get_selection()) {1420 if (_ExternalScriptsList.get_selection()) {
1197 Gtk::TreeModel::iterator i = _ExternalScriptsList.get_selection()->get_selected();1421 Gtk::TreeModel::iterator i = _ExternalScriptsList.get_selection()->get_selected();
11981422
1199 if(i){1423 if (i) {
1200 name = (*i)[_ExternalScriptsListColumns.filenameColumn];1424 name = (*i)[_ExternalScriptsListColumns.filenameColumn];
1201 } else {1425 } else {
1202 return;1426 return;
1203 }1427 }
1204 }1428 }
12051429
1206 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );1430 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("script");
1207 while ( current ) {1431 while (current) {
1208 if (current->data && SP_IS_OBJECT(current->data)) {1432 if (current->data && SP_IS_OBJECT(current->data)) {
1209 SPObject* obj = SP_OBJECT(current->data);1433 SPObject *obj = SP_OBJECT(current->data);
1210 SPScript* script = SP_SCRIPT(obj);1434 SPScript *script = SP_SCRIPT(obj);
1211 if (name == script->xlinkhref){1435 if (name == script->xlinkhref) {
12121436
1213 //XML Tree being used directly here while it shouldn't be.1437 // XML Tree being used directly here while it shouldn't be.
1214 Inkscape::XML::Node *repr = obj->getRepr();1438 Inkscape::XML::Node *repr = obj->getRepr();
1215 if (repr){1439 if (repr) {
1216 sp_repr_unparent(repr);1440 sp_repr_unparent(repr);
12171441
1218 // inform the document, so we can undo1442 // inform the document, so we can undo
1219 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, _("Remove external script"));1443 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT,
1444 _("Remove external script"));
1220 }1445 }
1221 }1446 }
1222 }1447 }
@@ -1226,23 +1451,24 @@
1226 populate_script_lists();1451 populate_script_lists();
1227}1452}
12281453
1229void DocumentProperties::removeEmbeddedScript(){1454void DocumentProperties::removeEmbeddedScript()
1455{
1230 Glib::ustring id;1456 Glib::ustring id;
1231 if(_EmbeddedScriptsList.get_selection()) {1457 if (_EmbeddedScriptsList.get_selection()) {
1232 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();1458 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();
12331459
1234 if(i){1460 if (i) {
1235 id = (*i)[_EmbeddedScriptsListColumns.idColumn];1461 id = (*i)[_EmbeddedScriptsListColumns.idColumn];
1236 } else {1462 } else {
1237 return;1463 return;
1238 }1464 }
1239 }1465 }
12401466
1241 SPObject* obj = SP_ACTIVE_DOCUMENT->getObjectById(id);1467 SPObject *obj = SP_ACTIVE_DOCUMENT->getObjectById(id);
1242 if (obj) {1468 if (obj) {
1243 //XML Tree being used directly here while it shouldn't be.1469 // XML Tree being used directly here while it shouldn't be.
1244 Inkscape::XML::Node *repr = obj->getRepr();1470 Inkscape::XML::Node *repr = obj->getRepr();
1245 if (repr){1471 if (repr) {
1246 sp_repr_unparent(repr);1472 sp_repr_unparent(repr);
12471473
1248 // inform the document, so we can undo1474 // inform the document, so we can undo
@@ -1257,7 +1483,7 @@
1257{1483{
1258 Glib::RefPtr<Gtk::TreeSelection> sel = _ExternalScriptsList.get_selection();1484 Glib::RefPtr<Gtk::TreeSelection> sel = _ExternalScriptsList.get_selection();
1259 if (sel) {1485 if (sel) {
1260 _external_remove_btn.set_sensitive(sel->count_selected_rows () > 0);1486 _external_remove_btn.set_sensitive(sel->count_selected_rows() > 0);
1261 }1487 }
1262}1488}
12631489
@@ -1265,45 +1491,47 @@
1265{1491{
1266 Glib::RefPtr<Gtk::TreeSelection> sel = _EmbeddedScriptsList.get_selection();1492 Glib::RefPtr<Gtk::TreeSelection> sel = _EmbeddedScriptsList.get_selection();
1267 if (sel) {1493 if (sel) {
1268 _embed_remove_btn.set_sensitive(sel->count_selected_rows () > 0);1494 _embed_remove_btn.set_sensitive(sel->count_selected_rows() > 0);
1269 }1495 }
1270}1496}
12711497
1272void DocumentProperties::changeEmbeddedScript(){1498void DocumentProperties::changeEmbeddedScript()
1499{
1273 Glib::ustring id;1500 Glib::ustring id;
1274 if(_EmbeddedScriptsList.get_selection()) {1501 if (_EmbeddedScriptsList.get_selection()) {
1275 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();1502 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();
12761503
1277 if(i){1504 if (i) {
1278 id = (*i)[_EmbeddedScriptsListColumns.idColumn];1505 id = (*i)[_EmbeddedScriptsListColumns.idColumn];
1279 } else {1506 } else {
1280 return;1507 return;
1281 }1508 }
1282 }1509 }
12831510
1284 bool voidscript=true;1511 bool voidscript = true;
1285 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );1512 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("script");
1286 while ( current ) {1513 while (current) {
1287 SPObject* obj = SP_OBJECT(current->data);1514 SPObject *obj = SP_OBJECT(current->data);
1288 if (id == obj->getId()){1515 if (id == obj->getId()) {
12891516
1290 int count=0;1517 int count = 0;
1291 for ( SPObject *child = obj->children ; child; child = child->next )1518 for (SPObject *child = obj->children; child; child = child->next) {
1292 {
1293 count++;1519 count++;
1294 }1520 }
12951521
1296 if (count>1)1522 if (count > 1)
1297 g_warning("TODO: Found a script element with multiple (%d) child nodes! We must implement support for that!", count);1523 g_warning(
12981524 "TODO: Found a script element with multiple (%d) child nodes! We must implement support for that!",
1299 //XML Tree being used directly here while it shouldn't be.1525 count);
1300 SPObject* child = obj->firstChild();1526
1301 //TODO: shouldnt we get all children instead of simply the first child?1527 // XML Tree being used directly here while it shouldn't be.
13021528 SPObject *child = obj->firstChild();
1303 if (child && child->getRepr()){1529 // TODO: shouldnt we get all children instead of simply the first child?
1304 const gchar* content = child->getRepr()->content();1530
1305 if (content){1531 if (child && child->getRepr()) {
1306 voidscript=false;1532 const gchar *content = child->getRepr()->content();
1533 if (content) {
1534 voidscript = false;
1307 _EmbeddedContent.get_buffer()->set_text(content);1535 _EmbeddedContent.get_buffer()->set_text(content);
1308 }1536 }
1309 }1537 }
@@ -1315,12 +1543,13 @@
1315 _EmbeddedContent.get_buffer()->set_text("");1543 _EmbeddedContent.get_buffer()->set_text("");
1316}1544}
13171545
1318void DocumentProperties::editEmbeddedScript(){1546void DocumentProperties::editEmbeddedScript()
1547{
1319 Glib::ustring id;1548 Glib::ustring id;
1320 if(_EmbeddedScriptsList.get_selection()) {1549 if (_EmbeddedScriptsList.get_selection()) {
1321 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();1550 Gtk::TreeModel::iterator i = _EmbeddedScriptsList.get_selection()->get_selected();
13221551
1323 if(i){1552 if (i) {
1324 id = (*i)[_EmbeddedScriptsListColumns.idColumn];1553 id = (*i)[_EmbeddedScriptsListColumns.idColumn];
1325 } else {1554 } else {
1326 return;1555 return;
@@ -1328,19 +1557,20 @@
1328 }1557 }
13291558
1330 Inkscape::XML::Document *xml_doc = SP_ACTIVE_DOCUMENT->getReprDoc();1559 Inkscape::XML::Document *xml_doc = SP_ACTIVE_DOCUMENT->getReprDoc();
1331 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );1560 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("script");
1332 while ( current ) {1561 while (current) {
1333 SPObject* obj = SP_OBJECT(current->data);1562 SPObject *obj = SP_OBJECT(current->data);
1334 if (id == obj->getId()){1563 if (id == obj->getId()) {
13351564
1336 //XML Tree being used directly here while it shouldn't be.1565 // XML Tree being used directly here while it shouldn't be.
1337 Inkscape::XML::Node *repr = obj->getRepr();1566 Inkscape::XML::Node *repr = obj->getRepr();
1338 if (repr){1567 if (repr) {
1339 SPObject *child;1568 SPObject *child;
1340 while (NULL != (child = obj->firstChild())) child->deleteObject();1569 while (NULL != (child = obj->firstChild()))
1570 child->deleteObject();
1341 obj->appendChildRepr(xml_doc->createTextNode(_EmbeddedContent.get_buffer()->get_text().c_str()));1571 obj->appendChildRepr(xml_doc->createTextNode(_EmbeddedContent.get_buffer()->get_text().c_str()));
13421572
1343 //TODO repr->set_content(_EmbeddedContent.get_buffer()->get_text());1573 // TODO repr->set_content(_EmbeddedContent.get_buffer()->get_text());
13441574
1345 // inform the document, so we can undo1575 // inform the document, so we can undo
1346 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_EMBEDDED_SCRIPT, _("Edit embedded script"));1576 DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_EMBEDDED_SCRIPT, _("Edit embedded script"));
@@ -1350,20 +1580,20 @@
1350 }1580 }
1351}1581}
13521582
1353void DocumentProperties::populate_script_lists(){1583void DocumentProperties::populate_script_lists()
1584{
1354 _ExternalScriptsListStore->clear();1585 _ExternalScriptsListStore->clear();
1355 _EmbeddedScriptsListStore->clear();1586 _EmbeddedScriptsListStore->clear();
1356 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );1587 const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("script");
1357 if (current) _scripts_observer.set(SP_OBJECT(current->data)->parent);1588 if (current)
1358 while ( current ) {
1359 SPObject* obj = SP_OBJECT(current->data);
1360 SPScript* script = SP_SCRIPT(obj);
1361 if (script->xlinkhref)
1362 {
The diff has been truncated for viewing.