048c46a2055b0496aa24dedf3c6d3c59aff12746
1 /** @file
2 * @brief Align and Distribute dialog - implementation
3 */
4 /* Authors:
5 * Bryce W. Harrington <bryce@bryceharrington.org>
6 * Aubanel MONNIER <aubi@libertysurf.fr>
7 * Frank Felfe <innerspace@iname.com>
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Tim Dwyer <tgdwyer@gmail.com>
10 *
11 * Copyright (C) 1999-2004, 2005 Authors
12 *
13 * Released under GNU GPL. Read the file 'COPYING' for more information.
14 */
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
21 #include <gtkmm/spinbutton.h>
23 #include "desktop-handles.h"
24 #include "unclump.h"
25 #include "document.h"
26 #include "enums.h"
27 #include "graphlayout.h"
28 #include "inkscape.h"
29 #include "macros.h"
30 #include "preferences.h"
31 #include "removeoverlap.h"
32 #include "selection.h"
33 #include "sp-flowtext.h"
34 #include "sp-item-transform.h"
35 #include "sp-text.h"
36 #include "text-editing.h"
37 #include "tools-switch.h"
38 #include "ui/icon-names.h"
39 #include "ui/tool/node-tool.h"
40 #include "ui/tool/multi-path-manipulator.h"
41 #include "util/glib-list-iterators.h"
42 #include "verbs.h"
43 #include "widgets/icon.h"
45 #include "align-and-distribute.h"
47 namespace Inkscape {
48 namespace UI {
49 namespace Dialog {
51 /////////helper classes//////////////////////////////////
53 class Action {
54 public :
55 Action(const Glib::ustring &id,
56 const Glib::ustring &tiptext,
57 guint row, guint column,
58 Gtk::Table &parent,
59 Gtk::Tooltips &tooltips,
60 AlignAndDistribute &dialog):
61 _dialog(dialog),
62 _id(id),
63 _parent(parent)
64 {
65 Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( _id, Inkscape::ICON_SIZE_LARGE_TOOLBAR) );
66 Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
67 pButton->set_relief(Gtk::RELIEF_NONE);
68 pIcon->show();
69 pButton->add(*pIcon);
70 pButton->show();
72 pButton->signal_clicked()
73 .connect(sigc::mem_fun(*this, &Action::on_button_click));
74 tooltips.set_tip(*pButton, tiptext);
75 parent.attach(*pButton, column, column+1, row, row+1, Gtk::FILL, Gtk::FILL);
76 }
77 virtual ~Action(){}
79 AlignAndDistribute &_dialog;
81 private :
82 virtual void on_button_click(){}
84 Glib::ustring _id;
85 Gtk::Table &_parent;
86 };
89 class ActionAlign : public Action {
90 public :
91 struct Coeffs {
92 double mx0, mx1, my0, my1;
93 double sx0, sx1, sy0, sy1;
94 };
95 ActionAlign(const Glib::ustring &id,
96 const Glib::ustring &tiptext,
97 guint row, guint column,
98 AlignAndDistribute &dialog,
99 guint coeffIndex):
100 Action(id, tiptext, row, column,
101 dialog.align_table(), dialog.tooltips(), dialog),
102 _index(coeffIndex),
103 _dialog(dialog)
104 {}
106 private :
108 virtual void on_button_click() {
109 //Retreive selected objects
110 SPDesktop *desktop = _dialog.getDesktop();
111 if (!desktop) return;
113 Inkscape::Selection *selection = sp_desktop_selection(desktop);
114 if (!selection) return;
116 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
117 bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups");
119 using Inkscape::Util::GSListConstIterator;
120 std::list<SPItem *> selected;
121 selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
122 if (selected.empty()) return;
124 Geom::Point mp; //Anchor point
125 AlignAndDistribute::AlignTarget target = _dialog.getAlignTarget();
126 const Coeffs &a= _allCoeffs[_index];
127 switch (target)
128 {
129 case AlignAndDistribute::LAST:
130 case AlignAndDistribute::FIRST:
131 case AlignAndDistribute::BIGGEST:
132 case AlignAndDistribute::SMALLEST:
133 {
134 //Check 2 or more selected objects
135 std::list<SPItem *>::iterator second(selected.begin());
136 ++second;
137 if (second == selected.end())
138 return;
139 //Find the master (anchor on which the other objects are aligned)
140 std::list<SPItem *>::iterator master(
141 _dialog.find_master (
142 selected,
143 (a.mx0 != 0.0) ||
144 (a.mx1 != 0.0) )
145 );
146 //remove the master from the selection
147 SPItem * thing = *master;
148 // TODO: either uncomment or remove the following commented lines, depending on which
149 // behaviour of moving objects makes most sense; also cf. discussion at
150 // https://bugs.launchpad.net/inkscape/+bug/255933
151 /*if (!sel_as_group) { */
152 selected.erase(master);
153 /*}*/
154 //Compute the anchor point
155 Geom::OptRect b = sp_item_bbox_desktop (thing);
156 if (b) {
157 mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X],
158 a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]);
159 } else {
160 return;
161 }
162 break;
163 }
165 case AlignAndDistribute::PAGE:
166 mp = Geom::Point(a.mx1 * sp_document_width(sp_desktop_document(desktop)),
167 a.my1 * sp_document_height(sp_desktop_document(desktop)));
168 break;
170 case AlignAndDistribute::DRAWING:
171 {
172 Geom::OptRect b = sp_item_bbox_desktop
173 ( (SPItem *) sp_document_root (sp_desktop_document (desktop)) );
174 if (b) {
175 mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X],
176 a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]);
177 } else {
178 return;
179 }
180 break;
181 }
183 case AlignAndDistribute::SELECTION:
184 {
185 Geom::OptRect b = selection->bounds();
186 if (b) {
187 mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X],
188 a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]);
189 } else {
190 return;
191 }
192 break;
193 }
195 default:
196 g_assert_not_reached ();
197 break;
198 }; // end of switch
200 // Top hack: temporarily set clone compensation to unmoved, so that we can align/distribute
201 // clones with their original (and the move of the original does not disturb the
202 // clones). The only problem with this is that if there are outside-of-selection clones of
203 // a selected original, they will be unmoved too, possibly contrary to user's
204 // expecation. However this is a minor point compared to making align/distribute always
205 // work as expected, and "unmoved" is the default option anyway.
206 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
207 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
209 bool changed = false;
210 Geom::OptRect b;
211 if (sel_as_group)
212 b = selection->bounds();
214 //Move each item in the selected list separately
215 for (std::list<SPItem *>::iterator it(selected.begin());
216 it != selected.end();
217 it++)
218 {
219 sp_document_ensure_up_to_date(sp_desktop_document (desktop));
220 if (!sel_as_group)
221 b = sp_item_bbox_desktop (*it);
222 if (b) {
223 Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X],
224 a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]);
225 Geom::Point const mp_rel( mp - sp );
226 if (LInfty(mp_rel) > 1e-9) {
227 sp_item_move_rel(*it, Geom::Translate(mp_rel));
228 changed = true;
229 }
230 }
231 }
233 // restore compensation setting
234 prefs->setInt("/options/clonecompensation/value", saved_compensation);
236 if (changed) {
237 sp_document_done ( sp_desktop_document (desktop) , SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
238 _("Align"));
239 }
242 }
243 guint _index;
244 AlignAndDistribute &_dialog;
246 static const Coeffs _allCoeffs[10];
248 };
249 ActionAlign::Coeffs const ActionAlign::_allCoeffs[10] = {
250 {1., 0., 0., 0., 0., 1., 0., 0.},
251 {1., 0., 0., 0., 1., 0., 0., 0.},
252 {.5, .5, 0., 0., .5, .5, 0., 0.},
253 {0., 1., 0., 0., 0., 1., 0., 0.},
254 {0., 1., 0., 0., 1., 0., 0., 0.},
255 {0., 0., 0., 1., 0., 0., 1., 0.},
256 {0., 0., 0., 1., 0., 0., 0., 1.},
257 {0., 0., .5, .5, 0., 0., .5, .5},
258 {0., 0., 1., 0., 0., 0., 1., 0.},
259 {0., 0., 1., 0., 0., 0., 0., 1.}
260 };
262 BBoxSort::BBoxSort(SPItem *pItem, Geom::Rect bounds, Geom::Dim2 orientation, double kBegin, double kEnd) :
263 item(pItem),
264 bbox (bounds)
265 {
266 anchor = kBegin * bbox.min()[orientation] + kEnd * bbox.max()[orientation];
267 }
268 BBoxSort::BBoxSort(const BBoxSort &rhs) :
269 //NOTE : this copy ctor is called O(sort) when sorting the vector
270 //this is bad. The vector should be a vector of pointers.
271 //But I'll wait the bohem GC before doing that
272 item(rhs.item), anchor(rhs.anchor), bbox(rhs.bbox)
273 {
274 }
276 bool operator< (const BBoxSort &a, const BBoxSort &b)
277 {
278 return (a.anchor < b.anchor);
279 }
281 class ActionDistribute : public Action {
282 public :
283 ActionDistribute(const Glib::ustring &id,
284 const Glib::ustring &tiptext,
285 guint row, guint column,
286 AlignAndDistribute &dialog,
287 bool onInterSpace,
288 Geom::Dim2 orientation,
289 double kBegin, double kEnd
290 ):
291 Action(id, tiptext, row, column,
292 dialog.distribute_table(), dialog.tooltips(), dialog),
293 _dialog(dialog),
294 _onInterSpace(onInterSpace),
295 _orientation(orientation),
296 _kBegin(kBegin),
297 _kEnd( kEnd)
298 {}
300 private :
301 virtual void on_button_click() {
302 //Retreive selected objects
303 SPDesktop *desktop = _dialog.getDesktop();
304 if (!desktop) return;
306 Inkscape::Selection *selection = sp_desktop_selection(desktop);
307 if (!selection) return;
309 using Inkscape::Util::GSListConstIterator;
310 std::list<SPItem *> selected;
311 selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
312 if (selected.empty()) return;
314 //Check 2 or more selected objects
315 std::list<SPItem *>::iterator second(selected.begin());
316 ++second;
317 if (second == selected.end()) return;
320 std::vector< BBoxSort > sorted;
321 for (std::list<SPItem *>::iterator it(selected.begin());
322 it != selected.end();
323 ++it)
324 {
325 Geom::OptRect bbox = sp_item_bbox_desktop(*it);
326 if (bbox) {
327 sorted.push_back(BBoxSort(*it, *bbox, _orientation, _kBegin, _kEnd));
328 }
329 }
330 //sort bbox by anchors
331 std::sort(sorted.begin(), sorted.end());
333 // see comment in ActionAlign above
334 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
335 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
336 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
338 unsigned int len = sorted.size();
339 bool changed = false;
340 if (_onInterSpace)
341 {
342 //overall bboxes span
343 float dist = (sorted.back().bbox.max()[_orientation] -
344 sorted.front().bbox.min()[_orientation]);
345 //space eaten by bboxes
346 float span = 0;
347 for (unsigned int i = 0; i < len; i++)
348 {
349 span += sorted[i].bbox[_orientation].extent();
350 }
351 //new distance between each bbox
352 float step = (dist - span) / (len - 1);
353 float pos = sorted.front().bbox.min()[_orientation];
354 for ( std::vector<BBoxSort> ::iterator it (sorted.begin());
355 it < sorted.end();
356 it ++ )
357 {
358 if (!NR_DF_TEST_CLOSE (pos, it->bbox.min()[_orientation], 1e-6)) {
359 Geom::Point t(0.0, 0.0);
360 t[_orientation] = pos - it->bbox.min()[_orientation];
361 sp_item_move_rel(it->item, Geom::Translate(t));
362 changed = true;
363 }
364 pos += it->bbox[_orientation].extent();
365 pos += step;
366 }
367 }
368 else
369 {
370 //overall anchor span
371 float dist = sorted.back().anchor - sorted.front().anchor;
372 //distance between anchors
373 float step = dist / (len - 1);
375 for ( unsigned int i = 0; i < len ; i ++ )
376 {
377 BBoxSort & it(sorted[i]);
378 //new anchor position
379 float pos = sorted.front().anchor + i * step;
380 //Don't move if we are really close
381 if (!NR_DF_TEST_CLOSE (pos, it.anchor, 1e-6)) {
382 //Compute translation
383 Geom::Point t(0.0, 0.0);
384 t[_orientation] = pos - it.anchor;
385 //translate
386 sp_item_move_rel(it.item, Geom::Translate(t));
387 changed = true;
388 }
389 }
390 }
392 // restore compensation setting
393 prefs->setInt("/options/clonecompensation/value", saved_compensation);
395 if (changed) {
396 sp_document_done ( sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
397 _("Distribute"));
398 }
399 }
400 guint _index;
401 AlignAndDistribute &_dialog;
402 bool _onInterSpace;
403 Geom::Dim2 _orientation;
405 double _kBegin;
406 double _kEnd;
408 };
411 class ActionNode : public Action {
412 public :
413 ActionNode(const Glib::ustring &id,
414 const Glib::ustring &tiptext,
415 guint column,
416 AlignAndDistribute &dialog,
417 Geom::Dim2 orientation, bool distribute):
418 Action(id, tiptext, 0, column,
419 dialog.nodes_table(), dialog.tooltips(), dialog),
420 _orientation(orientation),
421 _distribute(distribute)
422 {}
424 private :
425 Geom::Dim2 _orientation;
426 bool _distribute;
427 virtual void on_button_click()
428 {
430 if (!_dialog.getDesktop()) return;
431 SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop());
432 if (!INK_IS_NODE_TOOL (event_context)) return;
433 InkNodeTool *nt = INK_NODE_TOOL(event_context);
435 if (_distribute)
436 nt->_multipath->distributeNodes(_orientation);
437 else
438 nt->_multipath->alignNodes(_orientation);
440 }
441 };
443 class ActionRemoveOverlaps : public Action {
444 private:
445 Gtk::Label removeOverlapXGapLabel;
446 Gtk::Label removeOverlapYGapLabel;
447 Gtk::SpinButton removeOverlapXGap;
448 Gtk::SpinButton removeOverlapYGap;
450 public:
451 ActionRemoveOverlaps(Glib::ustring const &id,
452 Glib::ustring const &tiptext,
453 guint row,
454 guint column,
455 AlignAndDistribute &dialog) :
456 Action(id, tiptext, row, column + 4,
457 dialog.removeOverlap_table(), dialog.tooltips(), dialog)
458 {
459 dialog.removeOverlap_table().set_col_spacings(3);
461 removeOverlapXGap.set_digits(1);
462 removeOverlapXGap.set_size_request(60, -1);
463 removeOverlapXGap.set_increments(1.0, 0);
464 removeOverlapXGap.set_range(-1000.0, 1000.0);
465 removeOverlapXGap.set_value(0);
466 dialog.tooltips().set_tip(removeOverlapXGap,
467 _("Minimum horizontal gap (in px units) between bounding boxes"));
468 //TRANSLATORS: only translate "string" in "context|string".
469 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
470 // "H:" stands for horizontal gap
471 removeOverlapXGapLabel.set_label(Q_("gap|H:"));
473 removeOverlapYGap.set_digits(1);
474 removeOverlapYGap.set_size_request(60, -1);
475 removeOverlapYGap.set_increments(1.0, 0);
476 removeOverlapYGap.set_range(-1000.0, 1000.0);
477 removeOverlapYGap.set_value(0);
478 dialog.tooltips().set_tip(removeOverlapYGap,
479 _("Minimum vertical gap (in px units) between bounding boxes"));
480 /* TRANSLATORS: Vertical gap */
481 removeOverlapYGapLabel.set_label(_("V:"));
483 dialog.removeOverlap_table().attach(removeOverlapXGapLabel, column, column+1, row, row+1, Gtk::FILL, Gtk::FILL);
484 dialog.removeOverlap_table().attach(removeOverlapXGap, column+1, column+2, row, row+1, Gtk::FILL, Gtk::FILL);
485 dialog.removeOverlap_table().attach(removeOverlapYGapLabel, column+2, column+3, row, row+1, Gtk::FILL, Gtk::FILL);
486 dialog.removeOverlap_table().attach(removeOverlapYGap, column+3, column+4, row, row+1, Gtk::FILL, Gtk::FILL);
488 }
490 private :
491 virtual void on_button_click()
492 {
493 if (!_dialog.getDesktop()) return;
495 // see comment in ActionAlign above
496 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
497 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
498 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
500 // xGap and yGap are the minimum space required between bounding rectangles.
501 double const xGap = removeOverlapXGap.get_value();
502 double const yGap = removeOverlapYGap.get_value();
503 removeoverlap(sp_desktop_selection(_dialog.getDesktop())->itemList(),
504 xGap, yGap);
506 // restore compensation setting
507 prefs->setInt("/options/clonecompensation/value", saved_compensation);
509 sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
510 _("Remove overlaps"));
511 }
512 };
514 class ActionGraphLayout : public Action {
515 public:
516 ActionGraphLayout(Glib::ustring const &id,
517 Glib::ustring const &tiptext,
518 guint row,
519 guint column,
520 AlignAndDistribute &dialog) :
521 Action(id, tiptext, row, column,
522 dialog.rearrange_table(), dialog.tooltips(), dialog)
523 {}
525 private :
526 virtual void on_button_click()
527 {
528 if (!_dialog.getDesktop()) return;
530 // see comment in ActionAlign above
531 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
532 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
533 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
535 graphlayout(sp_desktop_selection(_dialog.getDesktop())->itemList());
537 // restore compensation setting
538 prefs->setInt("/options/clonecompensation/value", saved_compensation);
540 sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
541 _("Arrange connector network"));
542 }
543 };
545 class ActionExchangePositions : public Action {
546 public:
547 enum SortOrder {
548 None,
549 ZOrder,
550 Clockwise
551 };
553 ActionExchangePositions(Glib::ustring const &id,
554 Glib::ustring const &tiptext,
555 guint row,
556 guint column,
557 AlignAndDistribute &dialog, SortOrder order = None) :
558 Action(id, tiptext, row, column,
559 dialog.rearrange_table(), dialog.tooltips(), dialog),
560 sortOrder(order)
561 {};
564 private :
565 const SortOrder sortOrder;
566 static boost::optional<Geom::Point> center;
568 static bool sort_compare(const SPItem * a,const SPItem * b) {
569 if (a == NULL) return false;
570 if (b == NULL) return true;
571 if (center) {
572 Geom::Point point_a = a->getCenter() - (*center);
573 Geom::Point point_b = b->getCenter() - (*center);
574 // First criteria: Sort according to the angle to the center point
575 double angle_a = atan2(double(point_a[Geom::Y]), double(point_a[Geom::X]));
576 double angle_b = atan2(double(point_b[Geom::Y]), double(point_b[Geom::X]));
577 if (angle_a != angle_b) return (angle_a < angle_b);
578 // Second criteria: Sort according to the distance the center point
579 Geom::Coord length_a = point_a.length();
580 Geom::Coord length_b = point_b.length();
581 if (length_a != length_b) return (length_a > length_b);
582 }
583 // Last criteria: Sort according to the z-coordinate
584 return (a->isSiblingOf(b));
585 }
587 virtual void on_button_click()
588 {
589 SPDesktop *desktop = _dialog.getDesktop();
590 if (!desktop) return;
592 Inkscape::Selection *selection = sp_desktop_selection(desktop);
593 if (!selection) return;
595 using Inkscape::Util::GSListConstIterator;
596 std::list<SPItem *> selected;
597 selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
598 if (selected.empty()) return;
600 //Check 2 or more selected objects
601 if (selected.size() < 2) return;
603 // see comment in ActionAlign above
604 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
605 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
606 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
608 // sort the list
609 if (sortOrder != None) {
610 if (sortOrder == Clockwise) {
611 center = selection->center();
612 } else { // sorting by ZOrder is outomatically done by not setting the center
613 center.reset();
614 }
615 selected.sort(ActionExchangePositions::sort_compare);
616 }
617 std::list<SPItem *>::iterator it(selected.begin());
618 Geom::Point p1 = (*it)->getCenter();
619 for (++it ;it != selected.end(); ++it)
620 {
621 Geom::Point p2 = (*it)->getCenter();
622 Geom::Point delta = p1 - p2;
623 sp_item_move_rel((*it),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
624 p1 = p2;
625 }
626 Geom::Point p2 = selected.front()->getCenter();
627 Geom::Point delta = p1 - p2;
628 sp_item_move_rel(selected.front(),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
630 // restore compensation setting
631 prefs->setInt("/options/clonecompensation/value", saved_compensation);
633 sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
634 _("Exchange Positions"));
635 }
636 };
637 // instantiae the private static member
638 boost::optional<Geom::Point> ActionExchangePositions::center;
640 class ActionUnclump : public Action {
641 public :
642 ActionUnclump(const Glib::ustring &id,
643 const Glib::ustring &tiptext,
644 guint row,
645 guint column,
646 AlignAndDistribute &dialog):
647 Action(id, tiptext, row, column,
648 dialog.rearrange_table(), dialog.tooltips(), dialog)
649 {}
651 private :
652 virtual void on_button_click()
653 {
654 if (!_dialog.getDesktop()) return;
656 // see comment in ActionAlign above
657 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
658 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
659 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
661 unclump ((GSList *) sp_desktop_selection(_dialog.getDesktop())->itemList());
663 // restore compensation setting
664 prefs->setInt("/options/clonecompensation/value", saved_compensation);
666 sp_document_done (sp_desktop_document (_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
667 _("Unclump"));
668 }
669 };
671 class ActionRandomize : public Action {
672 public :
673 ActionRandomize(const Glib::ustring &id,
674 const Glib::ustring &tiptext,
675 guint row,
676 guint column,
677 AlignAndDistribute &dialog):
678 Action(id, tiptext, row, column,
679 dialog.rearrange_table(), dialog.tooltips(), dialog)
680 {}
682 private :
683 virtual void on_button_click()
684 {
685 SPDesktop *desktop = _dialog.getDesktop();
686 if (!desktop) return;
688 Inkscape::Selection *selection = sp_desktop_selection(desktop);
689 if (!selection) return;
691 using Inkscape::Util::GSListConstIterator;
692 std::list<SPItem *> selected;
693 selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
694 if (selected.empty()) return;
696 //Check 2 or more selected objects
697 if (selected.size() < 2) return;
699 Geom::OptRect sel_bbox = selection->bounds();
700 if (!sel_bbox) {
701 return;
702 }
704 // This bbox is cached between calls to randomize, so that there's no growth nor shrink
705 // nor drift on sequential randomizations. Discard cache on global (or better active
706 // desktop's) selection_change signal.
707 if (!_dialog.randomize_bbox) {
708 _dialog.randomize_bbox = *sel_bbox;
709 }
711 // see comment in ActionAlign above
712 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
713 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
714 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
716 for (std::list<SPItem *>::iterator it(selected.begin());
717 it != selected.end();
718 ++it)
719 {
720 sp_document_ensure_up_to_date(sp_desktop_document (desktop));
721 Geom::OptRect item_box = sp_item_bbox_desktop (*it);
722 if (item_box) {
723 // find new center, staying within bbox
724 double x = _dialog.randomize_bbox->min()[Geom::X] + (*item_box)[Geom::X].extent() /2 +
725 g_random_double_range (0, (*_dialog.randomize_bbox)[Geom::X].extent() - (*item_box)[Geom::X].extent());
726 double y = _dialog.randomize_bbox->min()[Geom::Y] + (*item_box)[Geom::Y].extent()/2 +
727 g_random_double_range (0, (*_dialog.randomize_bbox)[Geom::Y].extent() - (*item_box)[Geom::Y].extent());
728 // displacement is the new center minus old:
729 Geom::Point t = Geom::Point (x, y) - 0.5*(item_box->max() + item_box->min());
730 sp_item_move_rel(*it, Geom::Translate(t));
731 }
732 }
734 // restore compensation setting
735 prefs->setInt("/options/clonecompensation/value", saved_compensation);
737 sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
738 _("Randomize positions"));
739 }
740 };
742 struct Baselines
743 {
744 SPItem *_item;
745 Geom::Point _base;
746 Geom::Dim2 _orientation;
747 Baselines(SPItem *item, Geom::Point base, Geom::Dim2 orientation) :
748 _item (item),
749 _base (base),
750 _orientation (orientation)
751 {}
752 };
754 bool operator< (const Baselines &a, const Baselines &b)
755 {
756 return (a._base[a._orientation] < b._base[b._orientation]);
757 }
759 class ActionBaseline : public Action {
760 public :
761 ActionBaseline(const Glib::ustring &id,
762 const Glib::ustring &tiptext,
763 guint row,
764 guint column,
765 AlignAndDistribute &dialog,
766 Gtk::Table &table,
767 Geom::Dim2 orientation, bool distribute):
768 Action(id, tiptext, row, column,
769 table, dialog.tooltips(), dialog),
770 _orientation(orientation),
771 _distribute(distribute)
772 {}
774 private :
775 Geom::Dim2 _orientation;
776 bool _distribute;
777 virtual void on_button_click()
778 {
779 SPDesktop *desktop = _dialog.getDesktop();
780 if (!desktop) return;
782 Inkscape::Selection *selection = sp_desktop_selection(desktop);
783 if (!selection) return;
785 using Inkscape::Util::GSListConstIterator;
786 std::list<SPItem *> selected;
787 selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
788 if (selected.empty()) return;
790 //Check 2 or more selected objects
791 if (selected.size() < 2) return;
793 Geom::Point b_min = Geom::Point (HUGE_VAL, HUGE_VAL);
794 Geom::Point b_max = Geom::Point (-HUGE_VAL, -HUGE_VAL);
796 std::vector<Baselines> sorted;
798 for (std::list<SPItem *>::iterator it(selected.begin());
799 it != selected.end();
800 ++it)
801 {
802 if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
803 Inkscape::Text::Layout const *layout = te_get_layout(*it);
804 boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
805 if (pt) {
806 Geom::Point base = *pt * sp_item_i2d_affine(*it);
807 if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X];
808 if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y];
809 if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X];
810 if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y];
811 Baselines b (*it, base, _orientation);
812 sorted.push_back(b);
813 }
814 }
815 }
817 if (sorted.size() <= 1) return;
819 //sort baselines
820 std::sort(sorted.begin(), sorted.end());
822 bool changed = false;
824 if (_distribute) {
825 double step = (b_max[_orientation] - b_min[_orientation])/(sorted.size() - 1);
826 for (unsigned int i = 0; i < sorted.size(); i++) {
827 SPItem *item = sorted[i]._item;
828 Geom::Point base = sorted[i]._base;
829 Geom::Point t(0.0, 0.0);
830 t[_orientation] = b_min[_orientation] + step * i - base[_orientation];
831 sp_item_move_rel(item, Geom::Translate(t));
832 changed = true;
833 }
835 if (changed) {
836 sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
837 _("Distribute text baselines"));
838 }
840 } else {
841 for (std::list<SPItem *>::iterator it(selected.begin());
842 it != selected.end();
843 ++it)
844 {
845 if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
846 Inkscape::Text::Layout const *layout = te_get_layout(*it);
847 boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
848 if (pt) {
849 Geom::Point base = *pt * sp_item_i2d_affine(*it);
850 Geom::Point t(0.0, 0.0);
851 t[_orientation] = b_min[_orientation] - base[_orientation];
852 sp_item_move_rel(*it, Geom::Translate(t));
853 changed = true;
854 }
855 }
856 }
858 if (changed) {
859 sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
860 _("Align text baselines"));
861 }
862 }
863 }
864 };
868 void on_tool_changed(Inkscape::Application */*inkscape*/, SPEventContext */*context*/, AlignAndDistribute *daad)
869 {
870 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
871 if (desktop && sp_desktop_event_context(desktop))
872 daad->setMode(tools_active(desktop) == TOOLS_NODES);
873 }
875 void on_selection_changed(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, AlignAndDistribute *daad)
876 {
877 daad->randomize_bbox = Geom::OptRect();
878 }
880 /////////////////////////////////////////////////////////
885 AlignAndDistribute::AlignAndDistribute()
886 : UI::Widget::Panel ("", "/dialogs/align", SP_VERB_DIALOG_ALIGN_DISTRIBUTE),
887 randomize_bbox(),
888 _alignFrame(_("Align")),
889 _distributeFrame(_("Distribute")),
890 _rearrangeFrame(_("Rearrange")),
891 _removeOverlapFrame(_("Remove overlaps")),
892 _nodesFrame(_("Nodes")),
893 _alignTable(2, 6, true),
894 _distributeTable(2, 6, true),
895 _rearrangeTable(1, 5, false),
896 _removeOverlapTable(1, 5, false),
897 _nodesTable(1, 4, true),
898 _anchorLabel(_("Relative to: ")),
899 _selgrpLabel(_("Treat selection as group: "))
900 {
901 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
903 //Instanciate the align buttons
904 addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_RIGHT_TO_ANCHOR,
905 _("Align right edges of objects to the left edge of the anchor"),
906 0, 0);
907 addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_LEFT,
908 _("Align left edges"),
909 0, 1);
910 addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_CENTER,
911 _("Center on vertical axis"),
912 0, 2);
913 addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_RIGHT,
914 _("Align right sides"),
915 0, 3);
916 addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_LEFT_TO_ANCHOR,
917 _("Align left edges of objects to the right edge of the anchor"),
918 0, 4);
919 addAlignButton(INKSCAPE_ICON_ALIGN_VERTICAL_BOTTOM_TO_ANCHOR,
920 _("Align bottom edges of objects to the top edge of the anchor"),
921 1, 0);
922 addAlignButton(INKSCAPE_ICON_ALIGN_VERTICAL_TOP,
923 _("Align top edges"),
924 1, 1);
925 addAlignButton(INKSCAPE_ICON_ALIGN_VERTICAL_CENTER,
926 _("Center on horizontal axis"),
927 1, 2);
928 addAlignButton(INKSCAPE_ICON_ALIGN_VERTICAL_BOTTOM,
929 _("Align bottom edges"),
930 1, 3);
931 addAlignButton(INKSCAPE_ICON_ALIGN_VERTICAL_TOP_TO_ANCHOR,
932 _("Align top edges of objects to the bottom edge of the anchor"),
933 1, 4);
935 //Baseline aligns
936 addBaselineButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_BASELINE,
937 _("Align baseline anchors of texts horizontally"),
938 0, 5, this->align_table(), Geom::X, false);
939 addBaselineButton(INKSCAPE_ICON_ALIGN_VERTICAL_BASELINE,
940 _("Align baselines of texts"),
941 1, 5, this->align_table(), Geom::Y, false);
943 //The distribute buttons
944 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_GAPS,
945 _("Make horizontal gaps between objects equal"),
946 0, 4, true, Geom::X, .5, .5);
948 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_LEFT,
949 _("Distribute left edges equidistantly"),
950 0, 1, false, Geom::X, 1., 0.);
951 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_CENTER,
952 _("Distribute centers equidistantly horizontally"),
953 0, 2, false, Geom::X, .5, .5);
954 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_RIGHT,
955 _("Distribute right edges equidistantly"),
956 0, 3, false, Geom::X, 0., 1.);
958 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_GAPS,
959 _("Make vertical gaps between objects equal"),
960 1, 4, true, Geom::Y, .5, .5);
962 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_TOP,
963 _("Distribute top edges equidistantly"),
964 1, 1, false, Geom::Y, 0, 1);
965 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_CENTER,
966 _("Distribute centers equidistantly vertically"),
967 1, 2, false, Geom::Y, .5, .5);
968 addDistributeButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_BOTTOM,
969 _("Distribute bottom edges equidistantly"),
970 1, 3, false, Geom::Y, 1., 0.);
972 //Baseline distribs
973 addBaselineButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_BASELINE,
974 _("Distribute baseline anchors of texts horizontally"),
975 0, 5, this->distribute_table(), Geom::X, true);
976 addBaselineButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_BASELINE,
977 _("Distribute baselines of texts vertically"),
978 1, 5, this->distribute_table(), Geom::Y, true);
980 // Rearrange
981 //Graph Layout
982 addGraphLayoutButton(INKSCAPE_ICON_DISTRIBUTE_GRAPH,
983 _("Nicely arrange selected connector network"),
984 0, 0);
985 addExchangePositionsButton(INKSCAPE_ICON_EXCHANGE_POSITIONS,
986 _("Exchange positions of selected objects - selection order"),
987 0, 1);
988 addExchangePositionsByZOrderButton(INKSCAPE_ICON_EXCHANGE_POSITIONS_ZORDER,
989 _("Exchange positions of selected objects - stacking order"),
990 0, 2);
991 addExchangePositionsClockwiseButton(INKSCAPE_ICON_EXCHANGE_POSITIONS_CLOCKWISE,
992 _("Exchange positions of selected objects - clockwise rotate"),
993 0, 3);
995 //Randomize & Unclump
996 addRandomizeButton(INKSCAPE_ICON_DISTRIBUTE_RANDOMIZE,
997 _("Randomize centers in both dimensions"),
998 0, 4);
999 addUnclumpButton(INKSCAPE_ICON_DISTRIBUTE_UNCLUMP,
1000 _("Unclump objects: try to equalize edge-to-edge distances"),
1001 0, 5);
1003 //Remove overlaps
1004 addRemoveOverlapsButton(INKSCAPE_ICON_DISTRIBUTE_REMOVE_OVERLAPS,
1005 _("Move objects as little as possible so that their bounding boxes do not overlap"),
1006 0, 0);
1008 //Node Mode buttons
1009 // NOTE: "align nodes vertically" means "move nodes vertically until they align on a common
1010 // _horizontal_ line". This is analogous to what the "align-vertical-center" icon means.
1011 // There is no doubt some ambiguity. For this reason the descriptions are different.
1012 addNodeButton(INKSCAPE_ICON_ALIGN_VERTICAL_NODES,
1013 _("Align selected nodes to a common horizontal line"),
1014 0, Geom::X, false);
1015 addNodeButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_NODES,
1016 _("Align selected nodes to a common vertical line"),
1017 1, Geom::Y, false);
1018 addNodeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_NODE,
1019 _("Distribute selected nodes horizontally"),
1020 2, Geom::X, true);
1021 addNodeButton(INKSCAPE_ICON_DISTRIBUTE_VERTICAL_NODE,
1022 _("Distribute selected nodes vertically"),
1023 3, Geom::Y, true);
1025 //Rest of the widgetry
1027 _combo.append_text(_("Last selected"));
1028 _combo.append_text(_("First selected"));
1029 _combo.append_text(_("Biggest object"));
1030 _combo.append_text(_("Smallest object"));
1031 _combo.append_text(_("Page"));
1032 _combo.append_text(_("Drawing"));
1033 _combo.append_text(_("Selection"));
1035 _combo.set_active(prefs->getInt("/dialogs/align/align-to", 6));
1036 _combo.signal_changed().connect(sigc::mem_fun(*this, &AlignAndDistribute::on_ref_change));
1038 _anchorBox.pack_start(_anchorLabel);
1039 _anchorBox.pack_start(_combo);
1041 _selgrpBox.pack_start(_selgrpLabel);
1042 _selgrpBox.pack_start(_selgrp);
1043 _selgrp.set_active(prefs->getBool("/dialogs/align/sel-as-groups"));
1044 _selgrp.signal_toggled().connect(sigc::mem_fun(*this, &AlignAndDistribute::on_selgrp_toggled));
1046 _alignBox.pack_start(_anchorBox);
1047 _alignBox.pack_start(_selgrpBox);
1048 _alignBox.pack_start(_alignTable);
1050 _alignFrame.add(_alignBox);
1051 _distributeFrame.add(_distributeTable);
1052 _rearrangeFrame.add(_rearrangeTable);
1053 _removeOverlapFrame.add(_removeOverlapTable);
1054 _nodesFrame.add(_nodesTable);
1056 Gtk::Box *contents = _getContents();
1057 contents->set_spacing(4);
1059 // Notebook for individual transformations
1061 contents->pack_start(_alignFrame, true, true);
1062 contents->pack_start(_distributeFrame, true, true);
1063 contents->pack_start(_rearrangeFrame, true, true);
1064 contents->pack_start(_removeOverlapFrame, true, true);
1065 contents->pack_start(_nodesFrame, true, true);
1067 //Connect to the global tool change signal
1068 g_signal_connect (G_OBJECT (INKSCAPE), "set_eventcontext", G_CALLBACK (on_tool_changed), this);
1070 // Connect to the global selection change, to invalidate cached randomize_bbox
1071 g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this);
1072 randomize_bbox = Geom::OptRect();
1074 show_all_children();
1076 on_tool_changed (NULL, NULL, this); // set current mode
1077 }
1079 AlignAndDistribute::~AlignAndDistribute()
1080 {
1081 sp_signal_disconnect_by_data (G_OBJECT (INKSCAPE), this);
1083 for (std::list<Action *>::iterator it = _actionList.begin();
1084 it != _actionList.end();
1085 it ++)
1086 delete *it;
1087 }
1089 void AlignAndDistribute::on_ref_change(){
1090 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1091 prefs->setInt("/dialogs/align/align-to", _combo.get_active_row_number());
1093 //Make blink the master
1094 }
1096 void AlignAndDistribute::on_selgrp_toggled(){
1097 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1098 prefs->setInt("/dialogs/align/sel-as-groups", _selgrp.get_active());
1100 //Make blink the master
1101 }
1106 void AlignAndDistribute::setMode(bool nodeEdit)
1107 {
1108 //Act on widgets used in node mode
1109 void ( Gtk::Widget::*mNode) () = nodeEdit ?
1110 &Gtk::Widget::show_all : &Gtk::Widget::hide_all;
1112 //Act on widgets used in selection mode
1113 void ( Gtk::Widget::*mSel) () = nodeEdit ?
1114 &Gtk::Widget::hide_all : &Gtk::Widget::show_all;
1117 ((_alignFrame).*(mSel))();
1118 ((_distributeFrame).*(mSel))();
1119 ((_rearrangeFrame).*(mSel))();
1120 ((_removeOverlapFrame).*(mSel))();
1121 ((_nodesFrame).*(mNode))();
1123 }
1124 void AlignAndDistribute::addAlignButton(const Glib::ustring &id, const Glib::ustring tiptext,
1125 guint row, guint col)
1126 {
1127 _actionList.push_back(
1128 new ActionAlign(
1129 id, tiptext, row, col,
1130 *this , col + row * 5));
1131 }
1132 void AlignAndDistribute::addDistributeButton(const Glib::ustring &id, const Glib::ustring tiptext,
1133 guint row, guint col, bool onInterSpace,
1134 Geom::Dim2 orientation, float kBegin, float kEnd)
1135 {
1136 _actionList.push_back(
1137 new ActionDistribute(
1138 id, tiptext, row, col, *this ,
1139 onInterSpace, orientation,
1140 kBegin, kEnd
1141 )
1142 );
1143 }
1145 void AlignAndDistribute::addNodeButton(const Glib::ustring &id, const Glib::ustring tiptext,
1146 guint col, Geom::Dim2 orientation, bool distribute)
1147 {
1148 _actionList.push_back(
1149 new ActionNode(
1150 id, tiptext, col,
1151 *this, orientation, distribute));
1152 }
1154 void AlignAndDistribute::addRemoveOverlapsButton(const Glib::ustring &id, const Glib::ustring tiptext,
1155 guint row, guint col)
1156 {
1157 _actionList.push_back(
1158 new ActionRemoveOverlaps(
1159 id, tiptext, row, col, *this)
1160 );
1161 }
1163 void AlignAndDistribute::addGraphLayoutButton(const Glib::ustring &id, const Glib::ustring tiptext,
1164 guint row, guint col)
1165 {
1166 _actionList.push_back(
1167 new ActionGraphLayout(
1168 id, tiptext, row, col, *this)
1169 );
1170 }
1172 void AlignAndDistribute::addExchangePositionsButton(const Glib::ustring &id, const Glib::ustring tiptext,
1173 guint row, guint col)
1174 {
1175 _actionList.push_back(
1176 new ActionExchangePositions(
1177 id, tiptext, row, col, *this)
1178 );
1179 }
1181 void AlignAndDistribute::addExchangePositionsByZOrderButton(const Glib::ustring &id, const Glib::ustring tiptext,
1182 guint row, guint col)
1183 {
1184 _actionList.push_back(
1185 new ActionExchangePositions(
1186 id, tiptext, row, col, *this, ActionExchangePositions::ZOrder)
1187 );
1188 }
1190 void AlignAndDistribute::addExchangePositionsClockwiseButton(const Glib::ustring &id, const Glib::ustring tiptext,
1191 guint row, guint col)
1192 {
1193 _actionList.push_back(
1194 new ActionExchangePositions(
1195 id, tiptext, row, col, *this, ActionExchangePositions::Clockwise)
1196 );
1197 }
1199 void AlignAndDistribute::addUnclumpButton(const Glib::ustring &id, const Glib::ustring tiptext,
1200 guint row, guint col)
1201 {
1202 _actionList.push_back(
1203 new ActionUnclump(
1204 id, tiptext, row, col, *this)
1205 );
1206 }
1208 void AlignAndDistribute::addRandomizeButton(const Glib::ustring &id, const Glib::ustring tiptext,
1209 guint row, guint col)
1210 {
1211 _actionList.push_back(
1212 new ActionRandomize(
1213 id, tiptext, row, col, *this)
1214 );
1215 }
1217 void AlignAndDistribute::addBaselineButton(const Glib::ustring &id, const Glib::ustring tiptext,
1218 guint row, guint col, Gtk::Table &table, Geom::Dim2 orientation, bool distribute)
1219 {
1220 _actionList.push_back(
1221 new ActionBaseline(
1222 id, tiptext, row, col,
1223 *this, table, orientation, distribute));
1224 }
1229 std::list<SPItem *>::iterator AlignAndDistribute::find_master( std::list<SPItem *> &list, bool horizontal){
1230 std::list<SPItem *>::iterator master = list.end();
1231 switch (getAlignTarget()) {
1232 case LAST:
1233 return list.begin();
1234 break;
1236 case FIRST:
1237 return --(list.end());
1238 break;
1240 case BIGGEST:
1241 {
1242 gdouble max = -1e18;
1243 for (std::list<SPItem *>::iterator it = list.begin(); it != list.end(); it++) {
1244 Geom::OptRect b = sp_item_bbox_desktop (*it);
1245 if (b) {
1246 gdouble dim = (*b)[horizontal ? Geom::X : Geom::Y].extent();
1247 if (dim > max) {
1248 max = dim;
1249 master = it;
1250 }
1251 }
1252 }
1253 return master;
1254 break;
1255 }
1257 case SMALLEST:
1258 {
1259 gdouble max = 1e18;
1260 for (std::list<SPItem *>::iterator it = list.begin(); it != list.end(); it++) {
1261 Geom::OptRect b = sp_item_bbox_desktop (*it);
1262 if (b) {
1263 gdouble dim = (*b)[horizontal ? Geom::X : Geom::Y].extent();
1264 if (dim < max) {
1265 max = dim;
1266 master = it;
1267 }
1268 }
1269 }
1270 return master;
1271 break;
1272 }
1274 default:
1275 g_assert_not_reached ();
1276 break;
1278 } // end of switch statement
1279 return master;
1280 }
1282 AlignAndDistribute::AlignTarget AlignAndDistribute::getAlignTarget()const {
1283 return AlignTarget(_combo.get_active_row_number());
1284 }
1288 } // namespace Dialog
1289 } // namespace UI
1290 } // namespace Inkscape
1292 /*
1293 Local Variables:
1294 mode:c++
1295 c-file-style:"stroustrup"
1296 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1297 indent-tabs-mode:nil
1298 fill-column:99
1299 End:
1300 */
1301 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :