index d4bc26c5d08a68879f9d9ae2a555ecced6bb3384..19f6c4751d569f211766ce1d066934625c8491c2 100644 (file)
#include "layer-fns.h"
#include "context-fns.h"
#include <map>
+#include "helper/units.h"
+#include "sp-item.h"
using NR::X;
using NR::Y;
if (tools_isactive (desktop, TOOLS_TEXT))
if (sp_text_delete_selection(desktop->event_context)) {
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
return;
}
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
*/
tools_switch ( desktop, tools_active ( desktop ) );
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
/* fixme: sequencing */
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
Inkscape::GC::release(copy);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
selection->setReprList(newsel);
if (!dt)
return;
- SPDocument *doc = SP_DT_DOCUMENT(dt);
- SP_DT_SELECTION(dt)->clear();
+ SPDocument *doc = sp_desktop_document(dt);
+ sp_desktop_selection(dt)->clear();
g_return_if_fail(SP_IS_GROUP(dt->currentLayer()));
GSList *items = sp_item_group_item_list(SP_GROUP(dt->currentLayer()));
if (!dt)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(dt);
+ Inkscape::Selection *selection = sp_desktop_selection(dt);
g_return_if_fail(SP_IS_GROUP(dt->currentLayer()));
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT (desktop);
+ SPDocument *document = sp_desktop_document (desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// Check if something is selected.
if (selection->isEmpty()) {
// Move to the position of the topmost, reduced by the number of items deleted from topmost_parent
group->setPosition(topmost + 1);
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
selection->set(group);
Inkscape::GC::release(group);
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>group</b> to ungroup."));
g_slist_free(items);
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
static SPGroup *
if (!desktop)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
GSList const *items = (GSList *) selection->itemList();
if (!items) {
rev = g_slist_remove(rev, child);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
void sp_selection_raise_to_top()
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise to top."));
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
GSList const *items = (GSList *) selection->itemList();
if (!items) {
rev = g_slist_remove(rev, child);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower to bottom."));
void
sp_undo(SPDesktop *desktop, SPDocument *)
{
- if (!sp_document_undo(SP_DT_DOCUMENT(desktop)))
+ if (!sp_document_undo(sp_desktop_document(desktop)))
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to undo."));
}
void
sp_redo(SPDesktop *desktop, SPDocument *)
{
- if (!sp_document_redo(SP_DT_DOCUMENT(desktop)))
+ if (!sp_document_redo(sp_desktop_document(desktop)))
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to redo."));
}
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (tools_isactive (desktop, TOOLS_DROPPER)) {
sp_dropper_context_copy(desktop->event_context);
return;
}
- SPDocument *document = SP_DT_DOCUMENT(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
if (Inkscape::have_viable_layer(desktop, desktop->messageStack()) == false) {
return;
}
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (tools_isactive (desktop, TOOLS_TEXT)) {
if (sp_text_paste_inline(desktop->event_context))
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop == NULL) return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is in the clipboard
if (clipboard == NULL) {
return;
}
- paste_defs (&defs_clipboard, SP_DT_DOCUMENT(desktop));
+ paste_defs (&defs_clipboard, sp_desktop_document(desktop));
sp_desktop_set_style (desktop, style_clipboard);
- sp_document_done(SP_DT_DOCUMENT (desktop));
+ sp_document_done(sp_desktop_document (desktop));
}
void sp_selection_paste_size (bool apply_x, bool apply_y)
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop == NULL) return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is in the clipboard
if (size_clipboard.extent(NR::X) < 1e-6 || size_clipboard.extent(NR::Y) < 1e-6) {
apply_x? scale_x : (desktop->isToolboxButtonActive ("lock")? scale_y : 1.0),
apply_y? scale_y : (desktop->isToolboxButtonActive ("lock")? scale_x : 1.0)));
- sp_document_done(SP_DT_DOCUMENT (desktop));
+ sp_document_done(sp_desktop_document (desktop));
}
void sp_selection_paste_size_separately (bool apply_x, bool apply_y)
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop == NULL) return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is in the clipboard
if (size_clipboard.extent(NR::X) < 1e-6 || size_clipboard.extent(NR::Y) < 1e-6) {
}
- sp_document_done(SP_DT_DOCUMENT (desktop));
+ sp_document_done(sp_desktop_document (desktop));
}
void sp_selection_to_next_layer ()
{
SPDesktop *dt = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(dt);
+ Inkscape::Selection *selection = sp_desktop_selection(dt);
// check if something is selected
if (selection->isEmpty()) {
GSList *temp_clip = NULL;
sp_selection_copy_impl (items, &temp_clip, NULL, NULL); // we're in the same doc, so no need to copy defs
sp_selection_delete_impl (items);
- GSList *copied = sp_selection_paste_impl (SP_DT_DOCUMENT (dt), next, &temp_clip, NULL);
+ GSList *copied = sp_selection_paste_impl (sp_desktop_document (dt), next, &temp_clip, NULL);
selection->setReprList((GSList const *) copied);
g_slist_free (copied);
if (temp_clip) g_slist_free (temp_clip);
dt->setCurrentLayer(next);
- sp_document_done(SP_DT_DOCUMENT (dt));
+ sp_document_done(sp_desktop_document (dt));
} else {
dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above."));
}
{
SPDesktop *dt = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(dt);
+ Inkscape::Selection *selection = sp_desktop_selection(dt);
// check if something is selected
if (selection->isEmpty()) {
GSList *temp_clip = NULL;
sp_selection_copy_impl (items, &temp_clip, NULL, NULL); // we're in the same doc, so no need to copy defs
sp_selection_delete_impl (items);
- GSList *copied = sp_selection_paste_impl (SP_DT_DOCUMENT (dt), next, &temp_clip, NULL);
+ GSList *copied = sp_selection_paste_impl (sp_desktop_document (dt), next, &temp_clip, NULL);
selection->setReprList((GSList const *) copied);
g_slist_free (copied);
if (temp_clip) g_slist_free (temp_clip);
dt->setCurrentLayer(next);
- sp_document_done(SP_DT_DOCUMENT (dt));
+ sp_document_done(sp_desktop_document (dt));
} else {
dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers below."));
}
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
GSList const *l = (GSList *) selection->reprList();
while (l != NULL) {
l = l->next;
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
void
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty())
return;
sp_item_rotate_rel(item, rot_neg_90);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty())
return;
sp_item_rotate_rel(item, rot_neg_90);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
void
@@ -1542,7 +1544,7 @@ sp_selection_rotate(Inkscape::Selection *selection, gdouble const angle_degrees)
sp_selection_rotate_relative(selection, center, angle_degrees);
- sp_document_maybe_done(SP_DT_DOCUMENT(selection->desktop()),
+ sp_document_maybe_done(sp_desktop_document(selection->desktop()),
( ( angle_degrees > 0 )
? "selector:rotate:ccw"
: "selector:rotate:cw" ));
sp_selection_rotate_relative(selection, center, zangle);
- sp_document_maybe_done(SP_DT_DOCUMENT(selection->desktop()),
+ sp_document_maybe_done(sp_desktop_document(selection->desktop()),
( (angle > 0)
? "selector:rotate:ccw"
: "selector:rotate:cw" ));
double const times = 1.0 + grow / max_len;
sp_selection_scale_relative(selection, center, NR::scale(times, times));
- sp_document_maybe_done(SP_DT_DOCUMENT(selection->desktop()),
+ sp_document_maybe_done(sp_desktop_document(selection->desktop()),
( (grow > 0)
? "selector:scale:larger"
: "selector:scale:smaller" ));
NR::Point const center(selection->bounds().midpoint());
sp_selection_scale_relative(selection, center, NR::scale(times, times));
- sp_document_done(SP_DT_DOCUMENT(selection->desktop()));
+ sp_document_done(sp_desktop_document(selection->desktop()));
}
void
sp_selection_move(gdouble dx, gdouble dy)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
return;
}
sp_selection_move_relative(selection, dx, dy);
if (dx == 0) {
- sp_document_maybe_done(SP_DT_DOCUMENT(desktop), "selector:move:vertical");
+ sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:vertical");
} else if (dy == 0) {
- sp_document_maybe_done(SP_DT_DOCUMENT(desktop), "selector:move:horizontal");
+ sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:horizontal");
} else {
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
}
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
return;
}
sp_selection_move_relative(selection, zdx, zdy);
if (dx == 0) {
- sp_document_maybe_done(SP_DT_DOCUMENT(desktop), "selector:move:vertical");
+ sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:vertical");
} else if (dy == 0) {
- sp_document_maybe_done(SP_DT_DOCUMENT(desktop), "selector:move:horizontal");
+ sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:horizontal");
} else {
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
}
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
g_return_if_fail(desktop != NULL);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs_get_int_attribute ("options.kbselection", "inlayer", PREFS_SELECTION_LAYER);
bool onlyvisible = prefs_get_int_attribute ("options.kbselection", "onlyvisible", 1);
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
g_return_if_fail(document != NULL);
g_return_if_fail(desktop != NULL);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs_get_int_attribute ("options.kbselection", "inlayer", PREFS_SELECTION_LAYER);
bool onlyvisible = prefs_get_int_attribute ("options.kbselection", "onlyvisible", 1);
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
Inkscape::GC::release(clone);
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
selection->setReprList(newsel);
if (!desktop)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>clone</b> to unlink."));
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to unlink</b> in the selection."));
}
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
}
void
if (desktop == NULL)
return;
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPItem *item = selection->singleItem();
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
// restore parent and position
SP_OBJECT_REPR (parent)->appendChild(rect);
rect->setPosition(pos > 0 ? pos : 0);
- SPItem *rectangle = (SPItem *) SP_DT_DOCUMENT (desktop)->getObjectByRepr(rect);
+ SPItem *rectangle = (SPItem *) sp_desktop_document (desktop)->getObjectByRepr(rect);
Inkscape::GC::release(rect);
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
if (!did) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No pattern fills</b> in the selection."));
} else {
- sp_document_done(SP_DT_DOCUMENT(desktop));
+ sp_document_done(sp_desktop_document(desktop));
selection->setList(new_select);
}
}
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
bool is_empty = selection->isEmpty();
if ( apply_to_layer && is_empty) {
- desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create mask from."));
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create clippath or mask from."));
return;
} else if (!apply_to_layer && ( is_empty || NULL == selection->itemList()->next )) {
- desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and <b>object(s)</b> to apply mask to."));
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and <b>object(s)</b> to apply clippath or mask to."));
return;
}
if (desktop == NULL)
return;
- SPDocument *document = SP_DT_DOCUMENT(desktop);
- Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+ SPDocument *document = sp_desktop_document(desktop);
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
// check if something is selected
if (selection->isEmpty()) {
- desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove mask from."));
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove clippath or mask from."));
return;
}
obj->deleteObject(false);
}
+ // remember parent and position of the item to which the clippath/mask was applied
+ Inkscape::XML::Node *parent = SP_OBJECT_REPR((*it).second)->parent();
+ gint pos = SP_OBJECT_REPR((*it).second)->position();
+
for (GSList *i = items_to_move; NULL != i; i = i->next) {
- SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr((Inkscape::XML::Node *)i->data));
- selection->add((Inkscape::XML::Node *)i->data);
+ Inkscape::XML::Node *repr = (Inkscape::XML::Node *)i->data;
+
+ // insert into parent, restore pos
+ parent->appendChild(repr);
+ repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0);
+
+ SPItem *mask_item = (SPItem *) sp_desktop_document (desktop)->getObjectByRepr(repr);
+ selection->add(repr);
- // transform mask, so it is moved the same spot there mask was applied
- NR::Matrix transform (item->transform);
+ // transform mask, so it is moved the same spot where mask was applied
+ NR::Matrix transform (mask_item->transform);
transform *= (*it).second->transform;
- sp_item_write_transform(item, SP_OBJECT_REPR(item), transform);
+ sp_item_write_transform(mask_item, SP_OBJECT_REPR(mask_item), transform);
}
g_slist_free (items_to_move);
sp_document_done (document);
}
+void fit_canvas_to_selection(SPDesktop *desktop) {
+ g_return_if_fail(desktop != NULL);
+ SPDocument *doc = sp_desktop_document(desktop);
+
+ g_return_if_fail(doc != NULL);
+ g_return_if_fail(desktop->selection != NULL);
+ g_return_if_fail(!desktop->selection->isEmpty());
+ NRRect bbox = {0,0,0,0};
+
+ desktop->selection->bounds(&bbox);
+ if (!empty(bbox)) {
+ doc->fitToRect(bbox);
+ }
+};
+
+void fit_canvas_to_drawing(SPDocument *doc) {
+ g_return_if_fail(doc != NULL);
+ NRRect bbox = {0,0,0,0};
+
+ sp_document_ensure_up_to_date (doc);
+ sp_item_invoke_bbox(SP_ITEM(doc->root), &bbox, sp_item_i2r_affine(SP_ITEM(doc->root)), TRUE);
+
+ if (!empty(bbox)) {
+ doc->fitToRect(bbox);
+ }
+};
+
+void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) {
+ g_return_if_fail(desktop != NULL);
+ SPDocument *doc = sp_desktop_document(desktop);
+
+ g_return_if_fail(doc != NULL);
+ g_return_if_fail(desktop->selection != NULL);
+
+ if (desktop->selection->isEmpty()) {
+ fit_canvas_to_drawing(doc);
+ } else {
+ fit_canvas_to_selection(desktop);
+ }
+
+ sp_document_done(doc);
+};
+
/*
Local Variables:
mode:c++