Code

fix compile
[inkscape.git] / src / ui / dialog / transformation.cpp
index 28710ace33e6a55de612afc16932b41e8e2cf162..be5a8bb03faf32a1bd6df1f5abd805d9d8ae124e 100644 (file)
@@ -88,9 +88,9 @@ Transformation::Transformation()
       _scalar_rotate          (_("A_ngle"), _("Rotation angle (positive = counterclockwise)"), UNIT_TYPE_RADIAL, 
                                "", "transform_rotate", &_units_rotate),
       _scalar_skew_horizontal (_("_Horizontal"), _("Horizontal skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"), UNIT_TYPE_LINEAR, 
-                               "", "arrows_hor", &_units_skew),
+                               "", "transform_scew_hor", &_units_skew),
       _scalar_skew_vertical   (_("_Vertical"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR, 
-                               "", "arrows_ver", &_units_skew),
+                               "", "transform_scew_ver", &_units_skew),
 
       _scalar_transform_a     ("_A", _("Transformation matrix element A")),
       _scalar_transform_b     ("_B", _("Transformation matrix element B")),
@@ -134,6 +134,15 @@ Transformation::Transformation()
     _check_apply_separately.set_active(prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1));
     _check_apply_separately.signal_toggled().connect(sigc::mem_fun(*this, &Transformation::onApplySeparatelyToggled));
 
+    // make sure all spinbuttons activate Apply on pressing Enter
+      ((Gtk::Entry *) (_scalar_move_horizontal.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_move_vertical.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_scale_horizontal.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_scale_vertical.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_rotate.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_skew_horizontal.getWidget()))->set_activates_default(true);
+      ((Gtk::Entry *) (_scalar_skew_vertical.getWidget()))->set_activates_default(true);
+
     updateSelection(PAGE_MOVE, _getSelection());
 
     resetButton = add_button(Gtk::Stock::CLEAR, 0);
@@ -147,6 +156,7 @@ Transformation::Transformation()
     if (applyButton) {
         tooltips.set_tip((*applyButton), _("Apply transformation to selection"));
         applyButton->set_sensitive(false);
+        set_default (*applyButton); // activable by Enter in spinbuttons
     }
 
     // Connect to the global selection changed & modified signals
@@ -445,13 +455,14 @@ Transformation::updatePageMove(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
         if (!_check_move_relative.get_active()) {
+            NR::Maybe<NR::Rect> bbox = selection->bounds();
+            if (bbox) {
+                double x = bbox->min()[NR::X];
+                double y = bbox->min()[NR::Y];
 
-            NR::Rect bbox = selection->bounds();
-            double x = bbox.min()[NR::X];
-            double y = bbox.min()[NR::Y];
-
-            _scalar_move_horizontal.setValue(x, "px");
-            _scalar_move_vertical.setValue(y, "px");
+                _scalar_move_horizontal.setValue(x, "px");
+                _scalar_move_vertical.setValue(y, "px");
+            }
         } else {
             // do nothing, so you can apply the same relative move to many objects in turn
         }
@@ -465,13 +476,17 @@ void
 Transformation::updatePageScale(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
-        NR::Rect bbox = selection->bounds();
-        double w = bbox.extent(NR::X);
-        double h = bbox.extent(NR::Y);
-        _scalar_scale_horizontal.setHundredPercent(w);
-        _scalar_scale_vertical.setHundredPercent(h);
-        onScaleXValueChanged(); // to update x/y proportionality if switch is on
-        _page_scale.set_sensitive(true);
+        NR::Maybe<NR::Rect> bbox = selection->bounds();
+        if (bbox) {
+            double w = bbox->extent(NR::X);
+            double h = bbox->extent(NR::Y);
+            _scalar_scale_horizontal.setHundredPercent(w);
+            _scalar_scale_vertical.setHundredPercent(h);
+            onScaleXValueChanged(); // to update x/y proportionality if switch is on
+            _page_scale.set_sensitive(true);
+        } else {
+            _page_scale.set_sensitive(false);
+        }
     } else {
         _page_scale.set_sensitive(false);
     }
@@ -576,12 +591,15 @@ Transformation::applyPageMove(Inkscape::Selection *selection)
     if (_check_move_relative.get_active()) {
         sp_selection_move_relative(selection, x, y);
     } else {
-        NR::Rect bbox = selection->bounds();
-        sp_selection_move_relative(selection,
-            x - bbox.min()[NR::X], y - bbox.min()[NR::Y]);
+        NR::Maybe<NR::Rect> bbox = selection->bounds();
+        if (bbox) {
+            sp_selection_move_relative(selection,
+                x - bbox->min()[NR::X], y - bbox->min()[NR::Y]);
+        }
     }
 
-    sp_document_done ( sp_desktop_document (selection->desktop()) );
+    sp_document_done ( sp_desktop_document (selection->desktop()) , SP_VERB_DIALOG_TRANSFORM, 
+                       _("Move"));
 }
 
 void
@@ -593,15 +611,17 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
     if (prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1) == 1) {
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
             SPItem *item = SP_ITEM(l->data);
-            NR::Rect  bbox (sp_item_bbox_desktop(item));
             NR::scale scale (0,0);
             // the values are increments! 
             if (_units_scale.isAbsolute()) {
-                double new_width = bbox.extent(NR::X) + scaleX;
-                if (new_width < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
-                double new_height = bbox.extent(NR::Y) + scaleY;
-                if (new_height < 1e-6) new_height = 1e-6;
-                scale = NR::scale(new_width / bbox.extent(NR::X), new_height / bbox.extent(NR::Y));
+                NR::Maybe<NR::Rect> bbox(sp_item_bbox_desktop(item));
+                if (bbox) {
+                    double new_width = bbox->extent(NR::X) + scaleX;
+                    if (new_width < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
+                    double new_height = bbox->extent(NR::Y) + scaleY;
+                    if (new_height < 1e-6) new_height = 1e-6;
+                    scale = NR::scale(new_width / bbox->extent(NR::X), new_height / bbox->extent(NR::Y));
+                }
             } else {
                 double new_width = 100 + scaleX;
                 if (new_width < 1e-6) new_width = 1e-6;
@@ -612,27 +632,30 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
             sp_item_scale_rel (item, scale);
         }
     } else {
-        NR::Rect  bbox(selection->bounds());
-        NR::Point center(bbox.midpoint()); // use rotation center?
-        NR::scale scale (0,0);
-        // the values are increments!
-        if (_units_scale.isAbsolute()) {
-            double new_width = bbox.extent(NR::X) + scaleX;
-            if (new_width < 1e-6) new_width = 1e-6;
-            double new_height = bbox.extent(NR::Y) + scaleY;
-            if (new_height < 1e-6) new_height = 1e-6;
-            scale = NR::scale(new_width / bbox.extent(NR::X), new_height / bbox.extent(NR::Y));
-        } else {
-            double new_width = 100 + scaleX;
-            if (new_width < 1e-6) new_width = 1e-6;
-            double new_height = 100 + scaleY;
-            if (new_height < 1e-6) new_height = 1e-6;
-            scale = NR::scale(new_width / 100.0, new_height / 100.0);
+        NR::Maybe<NR::Rect> bbox(selection->bounds());
+        if (bbox) {
+            NR::Point center(bbox->midpoint()); // use rotation center?
+            NR::scale scale (0,0);
+            // the values are increments!
+            if (_units_scale.isAbsolute()) {
+                double new_width = bbox->extent(NR::X) + scaleX;
+                if (new_width < 1e-6) new_width = 1e-6;
+                double new_height = bbox->extent(NR::Y) + scaleY;
+                if (new_height < 1e-6) new_height = 1e-6;
+                scale = NR::scale(new_width / bbox->extent(NR::X), new_height / bbox->extent(NR::Y));
+            } else {
+                double new_width = 100 + scaleX;
+                if (new_width < 1e-6) new_width = 1e-6;
+                double new_height = 100 + scaleY;
+                if (new_height < 1e-6) new_height = 1e-6;
+                scale = NR::scale(new_width / 100.0, new_height / 100.0);
+            }
+            sp_selection_scale_relative(selection, center, scale);
         }
-        sp_selection_scale_relative(selection, center, scale);
     }
 
-    sp_document_done(sp_desktop_document(selection->desktop()));
+    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, 
+                     _("Scale"));
 }
 
 void
@@ -646,11 +669,14 @@ Transformation::applyPageRotate(Inkscape::Selection *selection)
             sp_item_rotate_rel(item, NR::rotate (angle*M_PI/180.0));
         }
     } else {
-        NR::Point center = selection->center();
-        sp_selection_rotate_relative(selection, center, angle);
+        NR::Maybe<NR::Point> center = selection->center();
+        if (center) {
+            sp_selection_rotate_relative(selection, *center, angle);
+        }
     }
 
-    sp_document_done(sp_desktop_document(selection->desktop()));
+    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, 
+                     _("Rotate"));
 }
 
 void
@@ -673,36 +699,42 @@ Transformation::applyPageSkew(Inkscape::Selection *selection)
             } else { // absolute displacement
                 double skewX = _scalar_skew_horizontal.getValue("px");
                 double skewY = _scalar_skew_vertical.getValue("px");
-                NR::Rect bbox(sp_item_bbox_desktop(item));
-                double width = bbox.dimensions()[NR::X];
-                double height = bbox.dimensions()[NR::Y];
-                sp_item_skew_rel (item, skewX/height, skewY/width);
+                NR::Maybe<NR::Rect> bbox(sp_item_bbox_desktop(item));
+                if (bbox) {
+                    double width = bbox->extent(NR::X);
+                    double height = bbox->extent(NR::Y);
+                    sp_item_skew_rel (item, skewX/height, skewY/width);
+                }
             }
         }
     } else { // transform whole selection
-        NR::Rect bbox = selection->bounds();
-        double width  = bbox.max()[NR::X] - bbox.min()[NR::X];
-        double height = bbox.max()[NR::Y] - bbox.min()[NR::Y];
-        NR::Point center = selection->center();
-
-        if (!_units_skew.isAbsolute()) { // percentage
-            double skewX = _scalar_skew_horizontal.getValue("%");
-            double skewY = _scalar_skew_vertical.getValue("%");
-            sp_selection_skew_relative(selection, center, 0.01*skewX, 0.01*skewY);
-        } else if (_units_skew.isRadial()) { //deg or rad
-            double angleX = _scalar_skew_horizontal.getValue("rad");
-            double angleY = _scalar_skew_vertical.getValue("rad");
-            double skewX = tan(-angleX);
-            double skewY = tan(angleY);
-            sp_selection_skew_relative(selection, center, skewX, skewY);
-        } else { // absolute displacement
-            double skewX = _scalar_skew_horizontal.getValue("px");
-            double skewY = _scalar_skew_vertical.getValue("px");
-            sp_selection_skew_relative(selection, center, skewX/height, skewY/width);
+        NR::Maybe<NR::Rect> bbox = selection->bounds();
+        NR::Maybe<NR::Point> center = selection->center();
+
+        if ( bbox && center ) {
+            double width  = bbox->extent(NR::X);
+            double height = bbox->extent(NR::Y);
+
+            if (!_units_skew.isAbsolute()) { // percentage
+                double skewX = _scalar_skew_horizontal.getValue("%");
+                double skewY = _scalar_skew_vertical.getValue("%");
+                sp_selection_skew_relative(selection, *center, 0.01*skewX, 0.01*skewY);
+            } else if (_units_skew.isRadial()) { //deg or rad
+                double angleX = _scalar_skew_horizontal.getValue("rad");
+                double angleY = _scalar_skew_vertical.getValue("rad");
+                double skewX = tan(-angleX);
+                double skewY = tan(angleY);
+                sp_selection_skew_relative(selection, *center, skewX, skewY);
+            } else { // absolute displacement
+                double skewX = _scalar_skew_horizontal.getValue("px");
+                double skewY = _scalar_skew_vertical.getValue("px");
+                sp_selection_skew_relative(selection, *center, skewX/height, skewY/width);
+            }
         }
     }
 
-    sp_document_done(sp_desktop_document(selection->desktop()));
+    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, 
+                     _("Skew"));
 }
 
 
@@ -722,12 +754,14 @@ Transformation::applyPageTransform(Inkscape::Selection *selection)
         for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
             SPItem *item = SP_ITEM(l->data);
             sp_item_set_item_transform(item, displayed);
+            SP_OBJECT(item)->updateRepr();
         }
     } else {
         sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform
     }
 
-    sp_document_done(sp_desktop_document(selection->desktop()));
+    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM, 
+                     _("Edit transformation matrix"));
 }
 
 
@@ -757,19 +791,20 @@ Transformation::onMoveRelativeToggled()
 
     //g_message("onMoveRelativeToggled: %f, %f px\n", x, y);
 
-    NR::Rect bbox = selection->bounds();
+    NR::Maybe<NR::Rect> bbox = selection->bounds();
 
-    if (_check_move_relative.get_active()) {
-        // From absolute to relative
-        _scalar_move_horizontal.setValue(x - bbox.min()[NR::X], "px");
-        _scalar_move_vertical.setValue(  y - bbox.min()[NR::Y], "px");
-    } else {
-        // From relative to absolute
-        _scalar_move_horizontal.setValue(bbox.min()[NR::X] + x, "px");
-        _scalar_move_vertical.setValue(  bbox.min()[NR::Y] + y, "px");
+    if (bbox) {
+        if (_check_move_relative.get_active()) {
+            // From absolute to relative
+            _scalar_move_horizontal.setValue(x - bbox->min()[NR::X], "px");
+            _scalar_move_vertical.setValue(  y - bbox->min()[NR::Y], "px");
+        } else {
+            // From relative to absolute
+            _scalar_move_horizontal.setValue(bbox->min()[NR::X] + x, "px");
+            _scalar_move_vertical.setValue(  bbox->min()[NR::Y] + y, "px");
+        }
     }
 
-
     set_response_sensitive(Gtk::RESPONSE_APPLY, true);
 }
 
@@ -896,9 +931,11 @@ Transformation::onClear()
             _scalar_move_horizontal.setValue(0);
             _scalar_move_vertical.setValue(0);
         } else {
-            NR::Rect bbox = selection->bounds();
-            _scalar_move_horizontal.setValue(bbox.min()[NR::X], "px");
-            _scalar_move_vertical.setValue(bbox.min()[NR::Y], "px");
+            NR::Maybe<NR::Rect> bbox = selection->bounds();
+            if (bbox) {
+                _scalar_move_horizontal.setValue(bbox->min()[NR::X], "px");
+                _scalar_move_vertical.setValue(bbox->min()[NR::Y], "px");
+            }
         }
         break;
     }