summaryrefslogtreecommitdiffstats
path: root/src/selection.cpp
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2013-08-29 21:06:10 +0000
committer~suv <suv-sf@users.sourceforge.net>2013-08-29 21:06:10 +0000
commit4d331e73a76dce7d703716093923ca01b3cc5936 (patch)
treeb444657ba269b25f60684e66858a138b74fe240d /src/selection.cpp
parentFix compiler warnings (diff)
parentUpdating outdated test. Fixes bug #1202271. (diff)
downloadinkscape-4d331e73a76dce7d703716093923ca01b3cc5936.tar.gz
inkscape-4d331e73a76dce7d703716093923ca01b3cc5936.zip
merge from trunk (r12487)
(bzr r11668.1.75)
Diffstat (limited to 'src/selection.cpp')
-rw-r--r--src/selection.cpp51
1 files changed, 40 insertions, 11 deletions
diff --git a/src/selection.cpp b/src/selection.cpp
index 564f1fdd3..1335c5fca 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -21,9 +21,8 @@
#endif
#include "macros.h"
#include "inkscape-private.h"
-#include "desktop.h"
-#include "desktop-handles.h"
#include "document.h"
+#include "layer-model.h"
#include "selection.h"
#include <2geom/rect.h>
#include "xml/repr.h"
@@ -42,10 +41,11 @@
namespace Inkscape {
-Selection::Selection(SPDesktop *desktop) :
+Selection::Selection(LayerModel *layers, SPDesktop *desktop) :
_objs(NULL),
_reprs(NULL),
_items(NULL),
+ _layers(layers),
_desktop(desktop),
_selection_context(NULL),
_flags(0),
@@ -55,7 +55,7 @@ Selection::Selection(SPDesktop *desktop) :
Selection::~Selection() {
_clear();
- _desktop = NULL;
+ _layers = NULL;
if (_idle) {
g_source_remove(_idle);
_idle = 0;
@@ -96,7 +96,7 @@ void Selection::_emitModified(guint flags) {
void Selection::_emitChanged(bool persist_selection_context/* = false */) {
if (persist_selection_context) {
if (NULL == _selection_context) {
- _selection_context = desktop()->currentLayer();
+ _selection_context = _layers->currentLayer();
sp_object_ref(_selection_context, NULL);
_context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext));
}
@@ -139,7 +139,7 @@ void Selection::_clear() {
SPObject *Selection::activeContext() {
if (NULL != _selection_context)
return _selection_context;
- return desktop()->currentLayer();
+ return _layers->currentLayer();
}
bool Selection::includes(SPObject *obj) const {
@@ -329,11 +329,11 @@ std::list<Persp3D *> const Selection::perspList() {
std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) {
std::list<SPBox3D *> boxes;
if (persp) {
- SPBox3D *box;
for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
- box = *i;
- if (persp == box3d_get_perspective(box))
+ SPBox3D *box = *i;
+ if (persp == box3d_get_perspective(box)) {
boxes.push_back(box);
+ }
}
} else {
boxes = _3dboxes;
@@ -358,6 +358,35 @@ SPItem *Selection::singleItem() {
}
}
+SPItem *Selection::smallestItem(Selection::CompareSize compare) {
+ return _sizeistItem(true, compare);
+}
+
+SPItem *Selection::largestItem(Selection::CompareSize compare) {
+ return _sizeistItem(false, compare);
+}
+
+SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) {
+ GSList const *items = const_cast<Selection *>(this)->itemList();
+ gdouble max = sml ? 1e18 : 0;
+ SPItem *ist = NULL;
+
+ for ( GSList const *i = items; i != NULL ; i = i->next ) {
+ Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds();
+ if (!obox || obox.isEmpty()) continue;
+ Geom::Rect bbox = *obox;
+
+ gdouble size = compare == 2 ? bbox.area() :
+ (compare == 1 ? bbox.width() : bbox.height());
+ size = sml ? size : size * -1;
+ if (size < max) {
+ max = size;
+ ist = SP_ITEM(i->data);
+ }
+ }
+ return ist;
+}
+
Inkscape::XML::Node *Selection::singleRepr() {
SPObject *obj=single();
return obj ? obj->getRepr() : NULL;
@@ -487,7 +516,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const {
g_return_val_if_fail(repr != NULL, NULL);
gchar const *id = repr->attribute("id");
g_return_val_if_fail(id != NULL, NULL);
- SPObject *object=sp_desktop_document(_desktop)->getObjectById(id);
+ SPObject *object=_layers->getDocument()->getObjectById(id);
g_return_val_if_fail(object != NULL, NULL);
return object;
}
@@ -496,7 +525,7 @@ guint Selection::numberOfLayers() {
GSList const *items = const_cast<Selection *>(this)->itemList();
GSList *layers = NULL;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- SPObject *layer = desktop()->layerForObject(SP_OBJECT(iter->data));
+ SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data));
if (g_slist_find (layers, layer) == NULL) {
layers = g_slist_prepend (layers, layer);
}