Code

Conversion to toolbars and preserve size upon undock
[inkscape.git] / src / widgets / select-toolbar.cpp
1 /*
2  * Selector aux toolbar
3  *
4  * Authors:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *   bulia byak <buliabyak@users.sf.net>
7  *   Jon A. Cruz <jon@joncruz.org>
8  *
9  * Copyright (C) 2003-2005 authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
18 #include <gtk/gtk.h>
19 #include <gtk/gtkaction.h>
21 #include "widgets/button.h"
22 #include "widgets/spw-utilities.h"
23 #include "widgets/widget-sizes.h"
24 #include "widgets/spinbutton-events.h"
25 #include "widgets/icon.h"
26 #include "widgets/sp-widget.h"
28 #include "prefs-utils.h"
29 #include "selection-chemistry.h"
30 #include "document.h"
31 #include "inkscape.h"
32 #include "desktop-style.h"
33 #include "desktop.h"
34 #include "desktop-handles.h"
35 #include "sp-namedview.h"
36 #include "toolbox.h"
37 #include <glibmm/i18n.h>
38 #include "helper/unit-menu.h"
39 #include "helper/units.h"
40 #include "inkscape.h"
41 #include "verbs.h"
42 #include "prefs-utils.h"
43 #include "selection.h"
44 #include "selection-chemistry.h"
45 #include "sp-item-transform.h"
46 #include "message-stack.h"
47 #include "display/sp-canvas.h"
48 #include "helper/unit-tracker.h"
49 #include "ege-adjustment-action.h"
50 #include "ege-output-action.h"
51 #include "ink-action.h"
53 using Inkscape::UnitTracker;
55 static void
56 sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
57 {
58     if (g_object_get_data(G_OBJECT(spw), "update")) {
59         return;
60     }
62     g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
64     using NR::X;
65     using NR::Y;
66     if ( sel && !sel->isEmpty() ) {
67         int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
68         SPItem::BBoxType bbox_type = (prefs_bbox ==0)? 
69             SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
70         NR::Maybe<NR::Rect> const bbox(sel->bounds(bbox_type));
71         if ( bbox && !bbox->isEmpty() ) {
72             UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
73             SPUnit const &unit = *tracker->getActiveUnit();
75             struct { char const *key; double val; } const keyval[] = {
76                 { "X", bbox->min()[X] },
77                 { "Y", bbox->min()[Y] },
78                 { "width", bbox->extent(X) },
79                 { "height", bbox->extent(Y) }
80             };
82             if (unit.base == SP_UNIT_DIMENSIONLESS) {
83                 double const val = 1. / unit.unittobase;
84                 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
85                     GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
86                     gtk_adjustment_set_value(a, val);
87                     tracker->setFullVal( a, keyval[i].val );
88                 }
89             } else {
90                 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
91                     GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
92                     gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit));
93                 }
94             }
95         }
96     }
98     g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
99 }
102 static void
103 sp_selection_layout_widget_modify_selection(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data)
105     SPDesktop *desktop = (SPDesktop *) data;
106     if ((sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop
107         && (flags & (SP_OBJECT_MODIFIED_FLAG        |
108                      SP_OBJECT_PARENT_MODIFIED_FLAG |
109                      SP_OBJECT_CHILD_MODIFIED_FLAG   )))
110     {
111         sp_selection_layout_widget_update(spw, selection);
112     }
115 static void
116 sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *selection, gpointer data)
118     SPDesktop *desktop = (SPDesktop *) data;
119     if (sp_desktop_selection(desktop) == selection) { // only respond to changes in our desktop
120         gboolean setActive = (selection && !selection->isEmpty());
121         std::vector<GtkAction*> *contextActions = reinterpret_cast<std::vector<GtkAction*> *>(g_object_get_data(G_OBJECT(spw), "contextActions"));
122         if ( contextActions ) {
123             for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
124                   iter != contextActions->end(); ++iter) {
125                 if ( setActive != gtk_action_is_sensitive(*iter) ) {
126                     gtk_action_set_sensitive( *iter, setActive );
127                 }
128             }
129         }
131         sp_selection_layout_widget_update(spw, selection);
132     }
135 static void
136 sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
138     if (g_object_get_data(G_OBJECT(spw), "update")) {
139         return;
140     }
142     UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
143     if ( !tracker || tracker->isUpdating() ) {
144         /*
145          * When only units are being changed, don't treat changes
146          * to adjuster values as object changes.
147          */
148         return;
149     }
150     g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
152     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
153     Inkscape::Selection *selection = sp_desktop_selection(desktop);
154     SPDocument *document = sp_desktop_document(desktop);
156     sp_document_ensure_up_to_date (document);
157     int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
158     SPItem::BBoxType bbox_type = (prefs_bbox ==0)? 
159         SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
160     NR::Maybe<NR::Rect> bbox = selection->bounds(bbox_type);
162     if ( !bbox || bbox->isEmpty() ) {
163         g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
164         return;
165     }
167     gdouble x0 = 0;
168     gdouble y0 = 0;
169     gdouble x1 = 0;
170     gdouble y1 = 0;
171     gdouble xrel = 0;
172     gdouble yrel = 0;
173     SPUnit const &unit = *tracker->getActiveUnit();
175     GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
176     GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
177     GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
178     GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
180     if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
181         x0 = sp_units_get_pixels (a_x->value, unit);
182         y0 = sp_units_get_pixels (a_y->value, unit);
183         x1 = x0 + sp_units_get_pixels (a_w->value, unit);
184         xrel = sp_units_get_pixels (a_w->value, unit) / bbox->extent(NR::X);
185         y1 = y0 + sp_units_get_pixels (a_h->value, unit);
186         yrel = sp_units_get_pixels (a_h->value, unit) / bbox->extent(NR::Y);
187     } else {
188         double const x0_propn = a_x->value * unit.unittobase;
189         x0 = bbox->min()[NR::X] * x0_propn;
190         double const y0_propn = a_y->value * unit.unittobase;
191         y0 = y0_propn * bbox->min()[NR::Y];
192         xrel = a_w->value * unit.unittobase;
193         x1 = x0 + xrel * bbox->extent(NR::X);
194         yrel = a_h->value * unit.unittobase;
195         y1 = y0 + yrel * bbox->extent(NR::Y);
196     }
198     // Keep proportions if lock is on
199     GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(G_OBJECT(spw), "lock") );
200     if ( gtk_toggle_action_get_active(lock) ) {
201         if (adj == a_h) {
202             x1 = x0 + yrel * bbox->extent(NR::X);
203         } else if (adj == a_w) {
204             y1 = y0 + xrel * bbox->extent(NR::Y);
205         }
206     }
208     // scales and moves, in px
209     double mh = fabs(x0 - bbox->min()[NR::X]);
210     double sh = fabs(x1 - bbox->max()[NR::X]);
211     double mv = fabs(y0 - bbox->min()[NR::Y]);
212     double sv = fabs(y1 - bbox->max()[NR::Y]);
214     // unless the unit is %, convert the scales and moves to the unit
215     if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
216         mh = sp_pixels_get_units (mh, unit);
217         sh = sp_pixels_get_units (sh, unit);
218         mv = sp_pixels_get_units (mv, unit);
219         sv = sp_pixels_get_units (sv, unit);
220     }
222     // do the action only if one of the scales/moves is greater than half the last significant
223     // digit in the spinbox (currently spinboxes have 3 fractional digits, so that makes 0.0005). If
224     // the value was changed by the user, the difference will be at least that much; otherwise it's
225     // just rounding difference between the spinbox value and actual value, so no action is
226     // performed
227     char const * const actionkey = ( mh > 5e-4 ? "selector:toolbar:move:horizontal" :
228                                      sh > 5e-4 ? "selector:toolbar:scale:horizontal" :
229                                      mv > 5e-4 ? "selector:toolbar:move:vertical" :
230                                      sv > 5e-4 ? "selector:toolbar:scale:vertical" : NULL );
232     if (actionkey != NULL) {
234         // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed
235         sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
237         gdouble strokewidth = stroke_average_width (selection->itemList());
238         int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
240         NR::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
242         sp_selection_apply_affine(selection, scaler);
243         sp_document_maybe_done (document, actionkey, SP_VERB_CONTEXT_SELECT,
244                                 _("Transform by toolbar"));
246         // resume interruptibility
247         sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
248     }
250     g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
253 static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
254                                                        gchar const *label,
255                                                        gchar const *shortLabel,
256                                                        gchar const *data,
257                                                        gdouble lower,
258                                                        GtkWidget* focusTarget,
259                                                        UnitTracker* tracker,
260                                                        GtkWidget* spw,
261                                                        gchar const *tooltip,
262                                                        gboolean altx )
264     GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, SPIN_PAGE_STEP ) );
265     if (tracker) {
266         tracker->addAdjustment(adj);
267     }
268     if ( spw ) {
269         g_object_set_data( G_OBJECT(spw), data, adj );
270     }
272     EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, Q_(label), tooltip, 0, SPIN_STEP, 3 );
273     if ( shortLabel ) {
274         g_object_set( act, "short_label", Q_(shortLabel), NULL );
275     }
277     gtk_signal_connect( GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(sp_object_layout_any_value_changed), spw );
278     if ( focusTarget ) {
279         ege_adjustment_action_set_focuswidget( act, focusTarget );
280     }
282     if ( altx ) { // this spinbutton will be activated by alt-x
283         g_object_set( G_OBJECT(act), "self-id", "altx", NULL );
284     }
286     // Using a cast just to make sure we pass in the right kind of function pointer
287     g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
289     return act;
292 // toggle button callbacks and updaters
294 static void toggle_stroke( GtkToggleAction* act, gpointer data ) {
295     gboolean active = gtk_toggle_action_get_active( act );
296     prefs_set_int_attribute( "options.transform", "stroke", active ? 1 : 0 );
297     SPDesktop *desktop = (SPDesktop *)data;
298     if ( active ) {
299         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
300     } else {
301         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>not scaled</b> when objects are scaled."));
302     }
305 static void toggle_corners( GtkToggleAction* act, gpointer data) {
306     gboolean active = gtk_toggle_action_get_active( act );
307     prefs_set_int_attribute( "options.transform", "rectcorners", active ? 1 : 0 );
308     SPDesktop *desktop = (SPDesktop *)data;
309     if ( active ) {
310         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
311     } else {
312         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>not scaled</b> when rectangles are scaled."));
313     }
316 static void toggle_gradient( GtkToggleAction *act, gpointer data ) {
317     gboolean active = gtk_toggle_action_get_active( act );
318     prefs_set_int_attribute( "options.transform", "gradient", active ? 1 : 0 );
319     SPDesktop *desktop = (SPDesktop *)data;
320     if ( active ) {
321         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)."));
322     } else {
323         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
324     }
327 static void toggle_pattern( GtkToggleAction* act, gpointer data ) {
328     gboolean active = gtk_toggle_action_get_active( act );
329     prefs_set_int_attribute( "options.transform", "pattern", active ? 1 : 0 );
330     SPDesktop *desktop = (SPDesktop *)data;
331     if ( active ) {
332         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)."));
333     } else {
334         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>patterns</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
335     }
338 static void toggle_lock( GtkToggleAction *act, gpointer /*data*/ ) {
339     gboolean active = gtk_toggle_action_get_active( act );
340     if ( active ) {
341         g_object_set( G_OBJECT(act), "iconId", "width_height_lock", NULL );
342     } else {
343         g_object_set( G_OBJECT(act), "iconId", "lock_unlocked", NULL );
344     }
347 static void destroy_tracker( GObject* obj, gpointer /*user_data*/ )
349     UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(obj, "tracker"));
350     if ( tracker ) {
351         delete tracker;
352         g_object_set_data( obj, "tracker", 0 );
353     }
356 static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data )
358     SPAction* targetAction = SP_ACTION(user_data);
359     if ( targetAction ) {
360         sp_action_perform( targetAction, NULL );
361     }
364 static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size )
366     GtkAction* act = 0;
368     SPAction* targetAction = verb->get_action(view);
369     InkAction* inky = ink_action_new( verb->get_id(), verb->get_name(), verb->get_tip(), verb->get_image(), size  );
370     act = GTK_ACTION(inky);
372     g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
374     return act;
377 void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
379     Inkscape::UI::View::View *view = desktop;
380     Inkscape::IconSize secondarySize = prefToSize("toolbox", "secondary", 1);
382     GtkAction* act = 0;
384     GtkActionGroup* selectionActions = mainActions; // temporary
385     std::vector<GtkAction*>* contextActions = new std::vector<GtkAction*>();
387     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL), view, secondarySize );
388     gtk_action_group_add_action( selectionActions, act );
389     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS), view, secondarySize );
390     gtk_action_group_add_action( selectionActions, act );
391     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_DESELECT), view, secondarySize );
392     gtk_action_group_add_action( selectionActions, act );
393     contextActions->push_back( act );
395     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), view, secondarySize );
396     gtk_action_group_add_action( selectionActions, act );
397     contextActions->push_back( act );
398     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CW), view, secondarySize );
399     gtk_action_group_add_action( selectionActions, act );
400     contextActions->push_back( act );
401     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_HORIZONTAL), view, secondarySize );
402     gtk_action_group_add_action( selectionActions, act );
403     contextActions->push_back( act );
404     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, secondarySize );
405     gtk_action_group_add_action( selectionActions, act );
406     contextActions->push_back( act );
408     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, secondarySize );
409     gtk_action_group_add_action( selectionActions, act );
410     contextActions->push_back( act );
411     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, secondarySize );
412     gtk_action_group_add_action( selectionActions, act );
413     contextActions->push_back( act );
414     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, secondarySize );
415     gtk_action_group_add_action( selectionActions, act );
416     contextActions->push_back( act );
417     act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, secondarySize );
418     gtk_action_group_add_action( selectionActions, act );
419     contextActions->push_back( act );
421     // Create the parent widget for x y w h tracker.
422     GtkWidget *spw = sp_widget_new_global(INKSCAPE);
424     // Remember the desktop's canvas widget, to be used for defocusing.
425     g_object_set_data(G_OBJECT(spw), "dtw", sp_desktop_canvas(desktop));
427     // The vb frame holds all other widgets and is used to set sensitivity depending on selection state.
428     GtkWidget *vb = gtk_hbox_new(FALSE, 0);
429     gtk_widget_show(vb);
430     gtk_container_add(GTK_CONTAINER(spw), vb);
432     // Create the units menu.
433     UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
434     tracker->addUnit( SP_UNIT_PERCENT, 0 );
435     tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
437     g_object_set_data( G_OBJECT(spw), "tracker", tracker );
438     g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw );
440     EgeAdjustmentAction* eact = 0;
442     // four spinbuttons
444     //TRANSLATORS: only translate "string" in "context|string".
445     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
446     eact = create_adjustment_action( "XAction", _("select_toolbar|X position"), _("select_toolbar|X"), "X",
447                                      -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
448                                      _("Horizontal coordinate of selection"), TRUE );
449     gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
450     contextActions->push_back( GTK_ACTION(eact) );
452     //TRANSLATORS: only translate "string" in "context|string".
453     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
454     eact = create_adjustment_action( "YAction", _("select_toolbar|Y position"), _("select_toolbar|Y"), "Y",
455                                      -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
456                                      _("Vertical coordinate of selection"), FALSE );
457     gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
458     contextActions->push_back( GTK_ACTION(eact) );
460     //TRANSLATORS: only translate "string" in "context|string".
461     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
462     eact = create_adjustment_action( "WidthAction", _("select_toolbar|Width"), _("select_toolbar|W"), "width",
463                                      1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
464                                      _("Width of selection"), FALSE );
465     gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
466     contextActions->push_back( GTK_ACTION(eact) );
468     // lock toggle
469     {
470     InkToggleAction* itact = ink_toggle_action_new( "LockAction",
471                                                     _("Lock width and height"),
472                                                     _("When locked, change both width and height by the same proportion"),
473                                                     "lock_unlocked",
474                                                     Inkscape::ICON_SIZE_DECORATION );
475     g_object_set( itact, "short_label", "Lock", NULL );
476     g_object_set_data( G_OBJECT(spw), "lock", itact );
477     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_lock), desktop) ;
478     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
479     }
481     //TRANSLATORS: only translate "string" in "context|string".
482     // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
483     eact = create_adjustment_action( "HeightAction", _("select_toolbar|Height"), _("select_toolbar|H"), "height",
484                                      1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
485                                      _("Height of selection"), FALSE );
486     gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
487     contextActions->push_back( GTK_ACTION(eact) );
489     // Add the units menu.
490     act = tracker->createAction( "UnitsAction", _("Units"), ("") );
491     gtk_action_group_add_action( selectionActions, act );
493     g_object_set_data( G_OBJECT(spw), "selectionActions", selectionActions );
494     g_object_set_data( G_OBJECT(spw), "contextActions", contextActions );
496     // Force update when selection changes.
497     gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_modify_selection), desktop);
498     gtk_signal_connect(GTK_OBJECT(spw), "change_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_change_selection), desktop);
500     // Update now.
501     sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? sp_desktop_selection(SP_ACTIVE_DESKTOP) : NULL);
503     for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
504           iter != contextActions->end(); ++iter) {
505         if ( gtk_action_is_sensitive(*iter) ) {
506             gtk_action_set_sensitive( *iter, FALSE );
507         }
508     }
510     // Insert spw into the toolbar.
511     if ( GTK_IS_BOX(holder) ) {
512         gtk_box_pack_start(GTK_BOX(holder), spw, FALSE, FALSE, 0);
513     } else if ( GTK_IS_TOOLBAR(holder) ) {
514         gtk_toolbar_append_widget( GTK_TOOLBAR(holder), spw, "Text", "priv" );
515     } else {
516         g_warning("Unexpected holder type");
517     }
519     // "Transform with object" buttons
521     {
522         EgeOutputAction* act = ege_output_action_new( "transform_affect_label", _("Affect:"), "", 0 );
523         ege_output_action_set_use_markup( act, TRUE );
524         g_object_set( act, "visible-overflown", FALSE, NULL );
525         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
526     }
528     {
529     InkToggleAction* itact = ink_toggle_action_new( "transform_stroke",
530                                                     _("Scale stroke width"),
531                                                     _("When scaling objects, scale the stroke width by the same proportion"),
532                                                     "transform_stroke",
533                                                     Inkscape::ICON_SIZE_DECORATION );
534     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "stroke", 1) );
535     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_stroke), desktop) ;
536     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
537     }
539     {
540     InkToggleAction* itact = ink_toggle_action_new( "transform_corners",
541                                                     _("Scale rounded corners"),
542                                                     _("When scaling rectangles, scale the radii of rounded corners"),
543                                                     "transform_corners",
544                                                   Inkscape::ICON_SIZE_DECORATION );
545     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "rectcorners", 1) );
546     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_corners), desktop) ;
547     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
548     }
550     {
551     InkToggleAction* itact = ink_toggle_action_new( "transform_gradient",
552                                                     _("Move gradients"),
553                                                     _("Move gradients (in fill or stroke) along with the objects"),
554                                                     "transform_gradient",
555                                                   Inkscape::ICON_SIZE_DECORATION );
556     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "gradient", 1) );
557     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_gradient), desktop) ;
558     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
559     }
561     {
562     InkToggleAction* itact = ink_toggle_action_new( "transform_pattern",
563                                                     _("Move patterns"),
564                                                     _("Move patterns (in fill or stroke) along with the objects"),
565                                                     "transform_pattern",
566                                                   Inkscape::ICON_SIZE_DECORATION );
567     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "pattern", 1) );
568     g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_pattern), desktop) ;
569     gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
570     }
574 /*
575   Local Variables:
576   mode:c++
577   c-file-style:"stroustrup"
578   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
579   indent-tabs-mode:nil
580   fill-column:99
581   End:
582 */
583 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :