Code

Make curvature work again by fixing a minor omission
[inkscape.git] / src / widgets / select-toolbar.cpp
index f996abe7a062a83028e5b70b3e6503f62986044b..f168cedeb3d779b8e6659dabacea369e7fd1e499 100644 (file)
@@ -25,7 +25,7 @@
 #include "widgets/icon.h"
 #include "widgets/sp-widget.h"
 
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "selection-chemistry.h"
 #include "document.h"
 #include "inkscape.h"
@@ -39,7 +39,6 @@
 #include "helper/units.h"
 #include "inkscape.h"
 #include "verbs.h"
-#include "prefs-utils.h"
 #include "selection.h"
 #include "selection-chemistry.h"
 #include "sp-item-transform.h"
@@ -49,6 +48,8 @@
 #include "ege-adjustment-action.h"
 #include "ege-output-action.h"
 #include "ink-action.h"
+#include <2geom/rect.h>
+#include "ui/icon-names.h"
 
 using Inkscape::UnitTracker;
 
@@ -61,19 +62,23 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
 
     g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
 
-    using NR::X;
-    using NR::Y;
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    using Geom::X;
+    using Geom::Y;
     if ( sel && !sel->isEmpty() ) {
-        NR::Maybe<NR::Rect> const bbox(sel->bounds());
-        if ( bbox && !bbox->isEmpty() ) {
+        int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);
+        SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
+            SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
+        Geom::OptRect const bbox(sel->bounds(bbox_type));
+        if ( bbox ) {
             UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
             SPUnit const &unit = *tracker->getActiveUnit();
 
             struct { char const *key; double val; } const keyval[] = {
                 { "X", bbox->min()[X] },
                 { "Y", bbox->min()[Y] },
-                { "width", bbox->extent(X) },
-                { "height", bbox->extent(Y) }
+                { "width", bbox->dimensions()[X] },
+                { "height", bbox->dimensions()[Y] }
             };
 
             if (unit.base == SP_UNIT_DIMENSIONLESS) {
@@ -151,9 +156,13 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
     SPDocument *document = sp_desktop_document(desktop);
 
     sp_document_ensure_up_to_date (document);
-    NR::Maybe<NR::Rect> bbox = selection->bounds();
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    int prefs_bbox = prefs->getInt("/tools/bounding_box");
+    SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
+        SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
+    Geom::OptRect bbox = selection->bounds(bbox_type);
 
-    if ( !bbox || bbox->isEmpty() ) {
+    if ( !bbox ) {
         g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
         return;
     }
@@ -175,35 +184,35 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
         x0 = sp_units_get_pixels (a_x->value, unit);
         y0 = sp_units_get_pixels (a_y->value, unit);
         x1 = x0 + sp_units_get_pixels (a_w->value, unit);
-        xrel = sp_units_get_pixels (a_w->value, unit) / bbox->extent(NR::X);
+        xrel = sp_units_get_pixels (a_w->value, unit) / bbox->dimensions()[Geom::X];
         y1 = y0 + sp_units_get_pixels (a_h->value, unit);
-        yrel = sp_units_get_pixels (a_h->value, unit) / bbox->extent(NR::Y);
+        yrel = sp_units_get_pixels (a_h->value, unit) / bbox->dimensions()[Geom::Y];
     } else {
         double const x0_propn = a_x->value * unit.unittobase;
-        x0 = bbox->min()[NR::X] * x0_propn;
+        x0 = bbox->min()[Geom::X] * x0_propn;
         double const y0_propn = a_y->value * unit.unittobase;
-        y0 = y0_propn * bbox->min()[NR::Y];
+        y0 = y0_propn * bbox->min()[Geom::Y];
         xrel = a_w->value * unit.unittobase;
-        x1 = x0 + xrel * bbox->extent(NR::X);
+        x1 = x0 + xrel * bbox->dimensions()[Geom::X];
         yrel = a_h->value * unit.unittobase;
-        y1 = y0 + yrel * bbox->extent(NR::Y);
+        y1 = y0 + yrel * bbox->dimensions()[Geom::Y];
     }
 
     // Keep proportions if lock is on
     GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(G_OBJECT(spw), "lock") );
     if ( gtk_toggle_action_get_active(lock) ) {
         if (adj == a_h) {
-            x1 = x0 + yrel * bbox->extent(NR::X);
+            x1 = x0 + yrel * bbox->dimensions()[Geom::X];
         } else if (adj == a_w) {
-            y1 = y0 + xrel * bbox->extent(NR::Y);
+            y1 = y0 + xrel * bbox->dimensions()[Geom::Y];
         }
     }
 
     // scales and moves, in px
-    double mh = fabs(x0 - bbox->min()[NR::X]);
-    double sh = fabs(x1 - bbox->max()[NR::X]);
-    double mv = fabs(y0 - bbox->min()[NR::Y]);
-    double sv = fabs(y1 - bbox->max()[NR::Y]);
+    double mh = fabs(x0 - bbox->min()[Geom::X]);
+    double sh = fabs(x1 - bbox->max()[Geom::X]);
+    double mv = fabs(y0 - bbox->min()[Geom::Y]);
+    double sv = fabs(y1 - bbox->max()[Geom::Y]);
 
     // unless the unit is %, convert the scales and moves to the unit
     if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
@@ -229,9 +238,9 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
         sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
 
         gdouble strokewidth = stroke_average_width (selection->itemList());
-        int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
+        int transform_stroke = prefs->getBool("/options/transform/stroke", true) ? 1 : 0;
 
-        NR::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
+        Geom::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
 
         sp_selection_apply_affine(selection, scaler);
         sp_document_maybe_done (document, actionkey, SP_VERB_CONTEXT_SELECT,
@@ -255,7 +264,7 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
                                                        gchar const *tooltip,
                                                        gboolean altx )
 {
-    GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, SPIN_PAGE_STEP ) );
+    GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, 0 ) );
     if (tracker) {
         tracker->addAdjustment(adj);
     }
@@ -285,9 +294,11 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
 
 // toggle button callbacks and updaters
 
-static void toggle_stroke( GtkToggleAction* act, gpointer data ) {
-    gboolean active = gtk_toggle_action_get_active( act );
-    prefs_set_int_attribute( "options.transform", "stroke", active ? 1 : 0 );
+static void toggle_stroke( GtkToggleAction* act, gpointer data )
+{
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gboolean active = gtk_toggle_action_get_active(act);
+    prefs->setBool("/options/transform/stroke", active);
     SPDesktop *desktop = (SPDesktop *)data;
     if ( active ) {
         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
@@ -296,9 +307,11 @@ static void toggle_stroke( GtkToggleAction* act, gpointer data ) {
     }
 }
 
-static void toggle_corners( GtkToggleAction* act, gpointer data) {
-    gboolean active = gtk_toggle_action_get_active( act );
-    prefs_set_int_attribute( "options.transform", "rectcorners", active ? 1 : 0 );
+static void toggle_corners( GtkToggleAction* act, gpointer data)
+{
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gboolean active = gtk_toggle_action_get_active(act);
+    prefs->setBool("/options/transform/rectcorners", active);
     SPDesktop *desktop = (SPDesktop *)data;
     if ( active ) {
         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
@@ -307,9 +320,11 @@ static void toggle_corners( GtkToggleAction* act, gpointer data) {
     }
 }
 
-static void toggle_gradient( GtkToggleAction *act, gpointer data ) {
-    gboolean active = gtk_toggle_action_get_active( act );
-    prefs_set_int_attribute( "options.transform", "gradient", active ? 1 : 0 );
+static void toggle_gradient( GtkToggleAction *act, gpointer data )
+{
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gboolean active = gtk_toggle_action_get_active(act);
+    prefs->setBool("/options/transform/gradient", active);
     SPDesktop *desktop = (SPDesktop *)data;
     if ( active ) {
         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> are <b>transformed</b> along with their objects when those are transformed (moved, scaled, rotated, or skewed)."));
@@ -318,9 +333,11 @@ static void toggle_gradient( GtkToggleAction *act, gpointer data ) {
     }
 }
 
-static void toggle_pattern( GtkToggleAction* act, gpointer data ) {
-    gboolean active = gtk_toggle_action_get_active( act );
-    prefs_set_int_attribute( "options.transform", "pattern", active ? 1 : 0 );
+static void toggle_pattern( GtkToggleAction* act, gpointer data )
+{
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gboolean active = gtk_toggle_action_get_active(act);
+    prefs->setInt("/options/transform/pattern", active);
     SPDesktop *desktop = (SPDesktop *)data;
     if ( active ) {
         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>patterns</b> are <b>transformed</b> along with their objects when those are transformed (moved, scaled, rotated, or skewed)."));
@@ -332,9 +349,9 @@ static void toggle_pattern( GtkToggleAction* act, gpointer data ) {
 static void toggle_lock( GtkToggleAction *act, gpointer /*data*/ ) {
     gboolean active = gtk_toggle_action_get_active( act );
     if ( active ) {
-        g_object_set( G_OBJECT(act), "iconId", "width_height_lock", NULL );
+        g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON_OBJECT_LOCKED, NULL );
     } else {
-        g_object_set( G_OBJECT(act), "iconId", "lock_unlocked", NULL );
+        g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON_OBJECT_UNLOCKED, NULL );
     }
 }
 
@@ -365,49 +382,53 @@ static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::Vi
 
     g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
 
+    Inkscape::queueIconPrerender( verb->get_image(), size );
+
     return act;
 }
 
 void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
 {
     Inkscape::UI::View::View *view = desktop;
+    Inkscape::IconSize secondarySize = prefToSize("/toolbox/secondary", 1);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
     GtkAction* act = 0;
 
     GtkActionGroup* selectionActions = mainActions; // temporary
     std::vector<GtkAction*>* contextActions = new std::vector<GtkAction*>();
 
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_DESELECT), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_DESELECT), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
 
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CW), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CW), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_HORIZONTAL), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_HORIZONTAL), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
 
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
-    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, Inkscape::ICON_SIZE_SMALL_TOOLBAR );
+    act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, secondarySize );
     gtk_action_group_add_action( selectionActions, act );
     contextActions->push_back( act );
 
@@ -463,7 +484,7 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     InkToggleAction* itact = ink_toggle_action_new( "LockAction",
                                                     _("Lock width and height"),
                                                     _("When locked, change both width and height by the same proportion"),
-                                                    "lock_unlocked",
+                                                    INKSCAPE_ICON_OBJECT_UNLOCKED,
                                                     Inkscape::ICON_SIZE_DECORATION );
     g_object_set( itact, "short_label", "Lock", NULL );
     g_object_set_data( G_OBJECT(spw), "lock", itact );
@@ -501,12 +522,18 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     }
 
     // Insert spw into the toolbar.
-    gtk_box_pack_start(GTK_BOX(holder), spw, FALSE, FALSE, 0);
+    if ( GTK_IS_BOX(holder) ) {
+        gtk_box_pack_start(GTK_BOX(holder), spw, FALSE, FALSE, 0);
+    } else if ( GTK_IS_TOOLBAR(holder) ) {
+        gtk_toolbar_append_widget( GTK_TOOLBAR(holder), spw, "Text", "priv" );
+    } else {
+        g_warning("Unexpected holder type");
+    }
 
     // "Transform with object" buttons
 
     {
-        EgeOutputAction* act = ege_output_action_new( "transform_affect_label", _("Affect:"), "", 0 );
+        EgeOutputAction* act = ege_output_action_new( "transform_affect_label", _("Affect:"), _("Control whether or not to scale stroke widths, scale rectangle corners, transform gradient fills, and transform pattern fills with the object"), 0 ); 
         ege_output_action_set_use_markup( act, TRUE );
         g_object_set( act, "visible-overflown", FALSE, NULL );
         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
@@ -516,9 +543,9 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     InkToggleAction* itact = ink_toggle_action_new( "transform_stroke",
                                                     _("Scale stroke width"),
                                                     _("When scaling objects, scale the stroke width by the same proportion"),
-                                                    "transform_stroke",
+                                                    INKSCAPE_ICON_TRANSFORM_AFFECT_STROKE,
                                                     Inkscape::ICON_SIZE_DECORATION );
-    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "stroke", 1) );
+    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/stroke", true) );
     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_stroke), desktop) ;
     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
     }
@@ -527,9 +554,9 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     InkToggleAction* itact = ink_toggle_action_new( "transform_corners",
                                                     _("Scale rounded corners"),
                                                     _("When scaling rectangles, scale the radii of rounded corners"),
-                                                    "transform_corners",
+                                                    INKSCAPE_ICON_TRANSFORM_AFFECT_ROUNDED_CORNERS,
                                                   Inkscape::ICON_SIZE_DECORATION );
-    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "rectcorners", 1) );
+    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/rectcorners", true) );
     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_corners), desktop) ;
     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
     }
@@ -538,9 +565,9 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     InkToggleAction* itact = ink_toggle_action_new( "transform_gradient",
                                                     _("Move gradients"),
                                                     _("Move gradients (in fill or stroke) along with the objects"),
-                                                    "transform_gradient",
+                                                    INKSCAPE_ICON_TRANSFORM_AFFECT_GRADIENT,
                                                   Inkscape::ICON_SIZE_DECORATION );
-    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "gradient", 1) );
+    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/gradient", true) );
     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_gradient), desktop) ;
     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
     }
@@ -549,9 +576,9 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
     InkToggleAction* itact = ink_toggle_action_new( "transform_pattern",
                                                     _("Move patterns"),
                                                     _("Move patterns (in fill or stroke) along with the objects"),
-                                                    "transform_pattern",
+                                                    INKSCAPE_ICON_TRANSFORM_AFFECT_PATTERN,
                                                   Inkscape::ICON_SIZE_DECORATION );
-    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "pattern", 1) );
+    gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/pattern", true) );
     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_pattern), desktop) ;
     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
     }