~ubuntu-branches/ubuntu/utopic/inkscape/utopic-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
/** @file
 * Multi path manipulator - implementation
 */
/* Authors:
 *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
 *
 * Copyright (C) 2009 Authors
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include <boost/shared_ptr.hpp>
#include <glib.h>
#include <glibmm/i18n.h>
#include "desktop.h"
#include "desktop-handles.h"
#include "document.h"
#include "live_effects/lpeobject.h"
#include "message-stack.h"
#include "preferences.h"
#include "sp-path.h"
#include "ui/tool/control-point-selection.h"
#include "ui/tool/event-utils.h"
#include "ui/tool/node.h"
#include "ui/tool/multi-path-manipulator.h"
#include "ui/tool/path-manipulator.h"
#include "util/unordered-containers.h"

#ifdef USE_GNU_HASHES
namespace __gnu_cxx {
template<>
struct hash<Inkscape::UI::NodeList::iterator> {
    size_t operator()(Inkscape::UI::NodeList::iterator const &n) const {
        return reinterpret_cast<size_t>(n.ptr());
    }
};
} // namespace __gnu_cxx
#endif // USE_GNU_HASHES

namespace Inkscape {
namespace UI {

namespace {

struct hash_nodelist_iterator
    : public std::unary_function<NodeList::iterator, std::size_t>
{
    std::size_t operator()(NodeList::iterator i) const {
        return INK_HASH<NodeList::iterator::pointer>()(&*i);
    }
};

typedef std::pair<NodeList::iterator, NodeList::iterator> IterPair;
typedef std::vector<IterPair> IterPairList;
typedef INK_UNORDERED_SET<NodeList::iterator, hash_nodelist_iterator> IterSet;
typedef std::multimap<double, IterPair> DistanceMap;
typedef std::pair<double, IterPair> DistanceMapItem;

/** Find pairs of selected endnodes suitable for joining. */
void find_join_iterators(ControlPointSelection &sel, IterPairList &pairs)
{
    IterSet join_iters;
    DistanceMap dists;

    // find all endnodes in selection
    for (ControlPointSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
        Node *node = dynamic_cast<Node*>(*i);
        if (!node) continue;
        NodeList::iterator iter = NodeList::get_iterator(node);
        if (!iter.next() || !iter.prev()) join_iters.insert(iter);
    }

    if (join_iters.size() < 2) return;

    // Below we find the closest pairs. The algorithm is O(N^3).
    // We can go down to O(N^2 log N) by using O(N^2) memory, by putting all pairs
    // with their distances in a multimap (not worth it IMO).
    while (join_iters.size() >= 2) {
        double closest = DBL_MAX;
        IterPair closest_pair;
        for (IterSet::iterator i = join_iters.begin(); i != join_iters.end(); ++i) {
            for (IterSet::iterator j = join_iters.begin(); j != i; ++j) {
                double dist = Geom::distance(**i, **j);
                if (dist < closest) {
                    closest = dist;
                    closest_pair = std::make_pair(*i, *j);
                }
            }
        }
        pairs.push_back(closest_pair);
        join_iters.erase(closest_pair.first);
        join_iters.erase(closest_pair.second);
    }
}

/** After this function, first should be at the end of path and second at the beginnning.
 * @returns True if the nodes are in the same subpath */
bool prepare_join(IterPair &join_iters)
{
    if (&NodeList::get(join_iters.first) == &NodeList::get(join_iters.second)) {
        if (join_iters.first.next()) // if first is begin, swap the iterators
            std::swap(join_iters.first, join_iters.second);
        return true;
    }

    NodeList &sp_first = NodeList::get(join_iters.first);
    NodeList &sp_second = NodeList::get(join_iters.second);
    if (join_iters.first.next()) { // first is begin
        if (join_iters.second.next()) { // second is begin
            sp_first.reverse();
        } else { // second is end
            std::swap(join_iters.first, join_iters.second);
        }
    } else { // first is end
        if (join_iters.second.next()) { // second is begin
            // do nothing
        } else { // second is end
            sp_second.reverse();
        }
    }
    return false;
}
} // anonymous namespace


MultiPathManipulator::MultiPathManipulator(PathSharedData &data, sigc::connection &chg)
    : PointManipulator(data.node_data.desktop, *data.node_data.selection)
    , _path_data(data)
    , _changed(chg)
{
    _selection.signal_commit.connect(
        sigc::mem_fun(*this, &MultiPathManipulator::_commit));
    _selection.signal_point_changed.connect(
        sigc::hide( sigc::hide(
            signal_coords_changed.make_slot())));
}

MultiPathManipulator::~MultiPathManipulator()
{
    _mmap.clear();
}

/** Remove empty manipulators. */
void MultiPathManipulator::cleanup()
{
    for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ) {
        if (i->second->empty()) _mmap.erase(i++);
        else ++i;
    }
}

/** @brief Change the set of items to edit.
 *
 * This method attempts to preserve as much of the state as possible. */
void MultiPathManipulator::setItems(std::set<ShapeRecord> const &s)
{
    std::set<ShapeRecord> shapes(s);

    // iterate over currently edited items, modifying / removing them as necessary
    for (MapType::iterator i = _mmap.begin(); i != _mmap.end();) {
        std::set<ShapeRecord>::iterator si = shapes.find(i->first);
        if (si == shapes.end()) {
            // This item is no longer supposed to be edited - remove its manipulator
            _mmap.erase(i++);
        } else {
            ShapeRecord const &sr = i->first;
            ShapeRecord const &sr_new = *si;
            // if the shape record differs, replace the key only and modify other values
            if (sr.edit_transform != sr_new.edit_transform ||
                sr.role != sr_new.role)
            {
                boost::shared_ptr<PathManipulator> hold(i->second);
                if (sr.edit_transform != sr_new.edit_transform)
                    hold->setControlsTransform(sr_new.edit_transform);
                if (sr.role != sr_new.role) {
                    //hold->setOutlineColor(_getOutlineColor(sr_new.role));
                }
                _mmap.erase(sr);
                _mmap.insert(std::make_pair(sr_new, hold));
            }
            shapes.erase(si); // remove the processed record
            ++i;
        }
    }

    // add newly selected items
    for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
        ShapeRecord const &r = *i;
        if (!SP_IS_PATH(r.item) && !IS_LIVEPATHEFFECT(r.item)) continue;
        boost::shared_ptr<PathManipulator> newpm(new PathManipulator(*this, (SPPath*) r.item,
            r.edit_transform, _getOutlineColor(r.role), r.lpe_key));
        newpm->showHandles(_show_handles);
        // always show outlines for clips and masks
        newpm->showOutline(_show_outline || r.role != SHAPE_ROLE_NORMAL);
        newpm->showPathDirection(_show_path_direction);
        newpm->setLiveOutline(_live_outline);
        newpm->setLiveObjects(_live_objects);
        _mmap.insert(std::make_pair(r, newpm));
    }
}

void MultiPathManipulator::selectSubpaths()
{
    if (_selection.empty()) {
        _selection.selectAll();
    } else {
        invokeForAll(&PathManipulator::selectSubpaths);
    }
}

void MultiPathManipulator::shiftSelection(int dir)
{
    if (empty()) return;

    // 1. find last selected node
    // 2. select the next node; if the last node or nothing is selected,
    //    select first node
    MapType::iterator last_i;
    SubpathList::iterator last_j;
    NodeList::iterator last_k;
    bool anything_found = false;
    bool anynode_found = false;

    for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
        SubpathList &sp = i->second->subpathList();
        for (SubpathList::iterator j = sp.begin(); j != sp.end(); ++j) {
            anynode_found = true;
            for (NodeList::iterator k = (*j)->begin(); k != (*j)->end(); ++k) {
                if (k->selected()) {
                    last_i = i;
                    last_j = j;
                    last_k = k;
                    anything_found = true;
                    // when tabbing backwards, we want the first node
                    if (dir == -1) goto exit_loop;
                }
            }
        }
    }
    exit_loop:

    // NOTE: we should not assume the _selection contains only nodes
    // in future it might also contain handles and other types of control points
    // this is why we use a flag instead in the loop above, instead of calling
    // selection.empty()
    if (!anything_found) {
        // select first / last node
        // this should never fail because there must be at least 1 non-empty manipulator
        if (anynode_found) {
          if (dir == 1) {
            _selection.insert((*_mmap.begin()->second->subpathList().begin())->begin().ptr());
          } else {
            _selection.insert((--(*--(--_mmap.end())->second->subpathList().end())->end()).ptr());
          }
        }
        return;
    }

    // three levels deep - w00t!
    if (dir == 1) {
        if (++last_k == (*last_j)->end()) {
            // here, last_k points to the node to be selected
            ++last_j;
            if (last_j == last_i->second->subpathList().end()) {
                ++last_i;
                if (last_i == _mmap.end()) {
                    last_i = _mmap.begin();
                }
                last_j = last_i->second->subpathList().begin();
            }
            last_k = (*last_j)->begin();
        }
    } else {
        if (!last_k || last_k == (*last_j)->begin()) {
            if (last_j == last_i->second->subpathList().begin()) {
                if (last_i == _mmap.begin()) {
                    last_i = _mmap.end();
                }
                --last_i;
                last_j = last_i->second->subpathList().end();
            }
            --last_j;
            last_k = (*last_j)->end();
        }
        --last_k;
    }
    _selection.clear();
    _selection.insert(last_k.ptr());
}

void MultiPathManipulator::invertSelectionInSubpaths()
{
    invokeForAll(&PathManipulator::invertSelectionInSubpaths);
}

void MultiPathManipulator::setNodeType(NodeType type)
{
    if (_selection.empty()) return;

    // When all selected nodes are already cusp, retract their handles
    bool retract_handles = (type == NODE_CUSP);

    for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
        Node *node = dynamic_cast<Node*>(*i);
        if (node) {
            retract_handles &= (node->type() == NODE_CUSP);
            node->setType(type);
        }
    }

    if (retract_handles) {
        for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
            Node *node = dynamic_cast<Node*>(*i);
            if (node) {
                node->front()->retract();
                node->back()->retract();
            }
        }
    }

    _done(retract_handles ? _("Retract handles") : _("Change node type"));
}

void MultiPathManipulator::setSegmentType(SegmentType type)
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::setSegmentType, type);
    if (type == SEGMENT_STRAIGHT) {
        _done(_("Straighten segments"));
    } else {
        _done(_("Make segments curves"));
    }
}

void MultiPathManipulator::insertNodes()
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::insertNodes);
    _done(_("Add nodes"));
}

void MultiPathManipulator::duplicateNodes()
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::duplicateNodes);
    _done(_("Duplicate nodes"));
}

void MultiPathManipulator::joinNodes()
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::hideDragPoint);
    // Node join has two parts. In the first one we join two subpaths by fusing endpoints
    // into one. In the second we fuse nodes in each subpath.
    IterPairList joins;
    NodeList::iterator preserve_pos;
    Node *mouseover_node = dynamic_cast<Node*>(ControlPoint::mouseovered_point);
    if (mouseover_node) {
        preserve_pos = NodeList::get_iterator(mouseover_node);
    }
    find_join_iterators(_selection, joins);

    for (IterPairList::iterator i = joins.begin(); i != joins.end(); ++i) {
        bool same_path = prepare_join(*i);
        NodeList &sp_first = NodeList::get(i->first);
        NodeList &sp_second = NodeList::get(i->second);
        i->first->setType(NODE_CUSP, false);

        Geom::Point joined_pos, pos_handle_front, pos_handle_back;
        pos_handle_front = *i->second->front();
        pos_handle_back = *i->first->back();

        // When we encounter the mouseover node, we unset the iterator - it will be invalidated
        if (i->first == preserve_pos) {
            joined_pos = *i->first;
            preserve_pos = NodeList::iterator();
        } else if (i->second == preserve_pos) {
            joined_pos = *i->second;
            preserve_pos = NodeList::iterator();
        } else {
            joined_pos = Geom::middle_point(*i->first, *i->second);
        }

        // if the handles aren't degenerate, don't move them
        i->first->move(joined_pos);
        Node *joined_node = i->first.ptr();
        if (!i->second->front()->isDegenerate()) {
            joined_node->front()->setPosition(pos_handle_front);
        }
        if (!i->first->back()->isDegenerate()) {
            joined_node->back()->setPosition(pos_handle_back);
        }
        sp_second.erase(i->second);

        if (same_path) {
            sp_first.setClosed(true);
        } else {
            sp_first.splice(sp_first.end(), sp_second);
            sp_second.kill();
        }
        _selection.insert(i->first.ptr());
    }

    if (joins.empty()) {
        // Second part replaces contiguous selections of nodes with single nodes
        invokeForAll(&PathManipulator::weldNodes, preserve_pos);
    }

    _doneWithCleanup(_("Join nodes"));
}

void MultiPathManipulator::breakNodes()
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::breakNodes);
    _done(_("Break nodes"));
}

void MultiPathManipulator::deleteNodes(bool keep_shape)
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::deleteNodes, keep_shape);
    _doneWithCleanup(_("Delete nodes"));
}

/** Join selected endpoints to create segments. */
void MultiPathManipulator::joinSegments()
{
    if (_selection.empty()) return;
    IterPairList joins;
    find_join_iterators(_selection, joins);

    for (IterPairList::iterator i = joins.begin(); i != joins.end(); ++i) {
        bool same_path = prepare_join(*i);
        NodeList &sp_first = NodeList::get(i->first);
        NodeList &sp_second = NodeList::get(i->second);
        i->first->setType(NODE_CUSP, false);
        i->second->setType(NODE_CUSP, false);
        if (same_path) {
            sp_first.setClosed(true);
        } else {
            sp_first.splice(sp_first.end(), sp_second);
            sp_second.kill();
        }
    }

    if (joins.empty()) {
        invokeForAll(&PathManipulator::weldSegments);
    }
    _doneWithCleanup("Join segments");
}

void MultiPathManipulator::deleteSegments()
{
    if (_selection.empty()) return;
    invokeForAll(&PathManipulator::deleteSegments);
    _doneWithCleanup("Delete segments");
}

void MultiPathManipulator::alignNodes(Geom::Dim2 d)
{
    if (_selection.empty()) return;
    _selection.align(d);
    if (d == Geom::X) {
        _done("Align nodes to a horizontal line");
    } else {
        _done("Align nodes to a vertical line");
    }
}

void MultiPathManipulator::distributeNodes(Geom::Dim2 d)
{
    if (_selection.empty()) return;
    _selection.distribute(d);
    if (d == Geom::X) {
        _done("Distrubute nodes horizontally");
    } else {
        _done("Distribute nodes vertically");
    }
}

void MultiPathManipulator::reverseSubpaths()
{
    if (_selection.empty()) {
        invokeForAll(&PathManipulator::reverseSubpaths, false);
        _done("Reverse subpaths");
    } else {
        invokeForAll(&PathManipulator::reverseSubpaths, true);
        _done("Reverse selected subpaths");
    }
}

void MultiPathManipulator::move(Geom::Point const &delta)
{
    _selection.transform(Geom::Translate(delta));
    _done("Move nodes");
}

void MultiPathManipulator::showOutline(bool show)
{
    for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
        // always show outlines for clipping paths and masks
        i->second->showOutline(show || i->first.role != SHAPE_ROLE_NORMAL);
    }
    _show_outline = show;
}

void MultiPathManipulator::showHandles(bool show)
{
    invokeForAll(&PathManipulator::showHandles, show);
    _show_handles = show;
}

void MultiPathManipulator::showPathDirection(bool show)
{
    invokeForAll(&PathManipulator::showPathDirection, show);
    _show_path_direction = show;
}

/** @brief Set live outline update status
 * When set to true, outline will be updated continuously when dragging
 * or transforming nodes. Otherwise it will only update when changes are committed
 * to XML. */
void MultiPathManipulator::setLiveOutline(bool set)
{
    invokeForAll(&PathManipulator::setLiveOutline, set);
    _live_outline = set;
}

/** @brief Set live object update status
 * When set to true, objects will be updated continuously when dragging
 * or transforming nodes. Otherwise they will only update when changes are committed
 * to XML. */
void MultiPathManipulator::setLiveObjects(bool set)
{
    invokeForAll(&PathManipulator::setLiveObjects, set);
    _live_objects = set;
}

void MultiPathManipulator::updateOutlineColors()
{
    //for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
    //    i->second->setOutlineColor(_getOutlineColor(i->first.role));
    //}
}

bool MultiPathManipulator::event(SPEventContext *event_context, GdkEvent *event)
{
    _tracker.event(event);
    guint key = 0;
    if (event->type == GDK_KEY_PRESS) {
        key = shortcut_key(event->key);
    }

    // Single handle adjustments go here.
    if (_selection.size() == 1 && event->type == GDK_KEY_PRESS) {
        do {
            Node *n = dynamic_cast<Node *>(*_selection.begin());
            if (!n) break;

            PathManipulator &pm = n->nodeList().subpathList().pm();

            int which = 0;
            if (_tracker.rightAlt() || _tracker.rightControl()) {
                which = 1;
            }
            if (_tracker.leftAlt() || _tracker.leftControl()) {
                if (which != 0) break; // ambiguous
                which = -1;
            }
            if (which == 0) break; // no handle chosen
            bool one_pixel = _tracker.leftAlt() || _tracker.rightAlt();
            bool handled = true;

            switch (key) {
            // single handle functions
            // rotation
            case GDK_bracketleft:
            case GDK_braceleft:
                pm.rotateHandle(n, which, 1, one_pixel);
                break;
            case GDK_bracketright:
            case GDK_braceright:
                pm.rotateHandle(n, which, -1, one_pixel);
                break;
            // adjust length
            case GDK_period:
            case GDK_greater:
                pm.scaleHandle(n, which, 1, one_pixel);
                break;
            case GDK_comma:
            case GDK_less:
                pm.scaleHandle(n, which, -1, one_pixel);
                break;
            default:
                handled = false;
                break;
            }

            if (handled) return true;
        } while(0);
    }


    switch (event->type) {
    case GDK_KEY_PRESS:
        switch (key) {
        case GDK_Insert:
        case GDK_KP_Insert:
            // Insert - insert nodes in the middle of selected segments
            insertNodes();
            return true;
        case GDK_i:
        case GDK_I:
            if (held_only_shift(event->key)) {
                // Shift+I - insert nodes (alternate keybinding for Mac keyboards
                //           that don't have the Insert key)
                insertNodes();
                return true;
            }
            break;
        case GDK_d:
        case GDK_D:
            if (held_only_shift(event->key)) {
                duplicateNodes();
                return true;
            }
        case GDK_j:
        case GDK_J:
            if (held_only_shift(event->key)) {
                // Shift+J - join nodes
                joinNodes();
                return true;
            }
            if (held_only_alt(event->key)) {
                // Alt+J - join segments
                joinSegments();
                return true;
            }
            break;
        case GDK_b:
        case GDK_B:
            if (held_only_shift(event->key)) {
                // Shift+B - break nodes
                breakNodes();
                return true;
            }
            break;
        case GDK_Delete:
        case GDK_KP_Delete:
        case GDK_BackSpace:
            if (held_shift(event->key)) break;
            if (held_alt(event->key)) {
                // Alt+Delete - delete segments
                deleteSegments();
            } else {
                Inkscape::Preferences *prefs = Inkscape::Preferences::get();
                bool del_preserves_shape = prefs->getBool("/tools/nodes/delete_preserves_shape", true);
                // pass keep_shape = true when:
                // a) del preserves shape, and control is not pressed
                // b) ctrl+del preserves shape (del_preserves_shape is false), and control is pressed
                // Hence xor
                deleteNodes(del_preserves_shape ^ held_control(event->key));
            }
            return true;
        case GDK_c:
        case GDK_C:
            if (held_only_shift(event->key)) {
                // Shift+C - make nodes cusp
                setNodeType(NODE_CUSP);
                return true;
            }
            break;
        case GDK_s:
        case GDK_S:
            if (held_only_shift(event->key)) {
                // Shift+S - make nodes smooth
                setNodeType(NODE_SMOOTH);
                return true;
            }
            break;
        case GDK_a:
        case GDK_A:
            if (held_only_shift(event->key)) {
                // Shift+A - make nodes auto-smooth
                setNodeType(NODE_AUTO);
                return true;
            }
            break;
        case GDK_y:
        case GDK_Y:
            if (held_only_shift(event->key)) {
                // Shift+Y - make nodes symmetric
                setNodeType(NODE_SYMMETRIC);
                return true;
            }
            break;
        case GDK_r:
        case GDK_R:
            if (held_only_shift(event->key)) {
                // Shift+R - reverse subpaths
                reverseSubpaths();
                return true;
            }
            break;
        case GDK_l:
        case GDK_L:
            if (held_only_shift(event->key)) {
                // Shift+L - make segments linear
                setSegmentType(SEGMENT_STRAIGHT);
                return true;
            }
        case GDK_u:
        case GDK_U:
            if (held_only_shift(event->key)) {
                // Shift+U - make segments curves
                setSegmentType(SEGMENT_CUBIC_BEZIER);
                return true;
            }
        default:
            break;
        }
        break;
    case GDK_MOTION_NOTIFY:
        combine_motion_events(_desktop->canvas, event->motion, 0);
        for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
            if (i->second->event(event_context, event)) return true;
        }
        break;
    default: break;
    }

    return false;
}

/** Commit changes to XML and add undo stack entry based on the action that was done. Invoked
 * by sub-manipulators, for example TransformHandleSet and ControlPointSelection. */
void MultiPathManipulator::_commit(CommitEvent cps)
{
    gchar const *reason = NULL;
    gchar const *key = NULL;
    switch(cps) {
    case COMMIT_MOUSE_MOVE:
        reason = _("Move nodes");
        break;
    case COMMIT_KEYBOARD_MOVE_X:
        reason = _("Move nodes horizontally");
        key = "node:move:x";
        break;
    case COMMIT_KEYBOARD_MOVE_Y:
        reason = _("Move nodes vertically");
        key = "node:move:y";
        break;
    case COMMIT_MOUSE_ROTATE:
        reason = _("Rotate nodes");
        break;
    case COMMIT_KEYBOARD_ROTATE:
        reason = _("Rotate nodes");
        key = "node:rotate";
        break;
    case COMMIT_MOUSE_SCALE_UNIFORM:
        reason = _("Scale nodes uniformly");
        break;
    case COMMIT_MOUSE_SCALE:
        reason = _("Scale nodes");
        break;
    case COMMIT_KEYBOARD_SCALE_UNIFORM:
        reason = _("Scale nodes uniformly");
        key = "node:scale:uniform";
        break;
    case COMMIT_KEYBOARD_SCALE_X:
        reason = _("Scale nodes horizontally");
        key = "node:scale:x";
        break;
    case COMMIT_KEYBOARD_SCALE_Y:
        reason = _("Scale nodes vertically");
        key = "node:scale:y";
        break;
    case COMMIT_MOUSE_SKEW_X:
        reason = _("Skew nodes horizontally");
        key = "node:skew:x";
        break;
    case COMMIT_MOUSE_SKEW_Y:
        reason = _("Skew nodes vertically");
        key = "node:skew:y";
        break;
    case COMMIT_FLIP_X:
        reason = _("Flip nodes horizontally");
        break;
    case COMMIT_FLIP_Y:
        reason = _("Flip nodes vertically");
        break;
    default: return;
    }
    
    _selection.signal_update.emit();
    invokeForAll(&PathManipulator::writeXML);
    if (key) {
        sp_document_maybe_done(sp_desktop_document(_desktop), key, SP_VERB_CONTEXT_NODE, reason);
    } else {
        sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
    }
    signal_coords_changed.emit();
}

/** Commits changes to XML and adds undo stack entry. */
void MultiPathManipulator::_done(gchar const *reason) {
    invokeForAll(&PathManipulator::update);
    invokeForAll(&PathManipulator::writeXML);
    sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
    signal_coords_changed.emit();
}

/** Commits changes to XML, adds undo stack entry and removes empty manipulators. */
void MultiPathManipulator::_doneWithCleanup(gchar const *reason) {
    _changed.block();
    _done(reason);
    cleanup();
    _changed.unblock();
}

/** Get an outline color based on the shape's role (normal, mask, LPE parameter, etc.). */
guint32 MultiPathManipulator::_getOutlineColor(ShapeRole role)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    switch(role) {
    case SHAPE_ROLE_CLIPPING_PATH:
        return prefs->getColor("/tools/nodes/clipping_path_color", 0x00ff00ff);
    case SHAPE_ROLE_MASK:
        return prefs->getColor("/tools/nodes/mask_color", 0x0000ffff);
    case SHAPE_ROLE_LPE_PARAM:
        return prefs->getColor("/tools/nodes/lpe_param_color", 0x009000ff);
    case SHAPE_ROLE_NORMAL:
    default:
        return prefs->getColor("/tools/nodes/outline_color", 0xff0000ff);
    }
}

} // namespace UI
} // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :