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"
52 #include <2geom/rect.h>
54 using Inkscape::UnitTracker;
56 static void
57 sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
58 {
59 if (g_object_get_data(G_OBJECT(spw), "update")) {
60 return;
61 }
63 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
65 using Geom::X;
66 using Geom::Y;
67 if ( sel && !sel->isEmpty() ) {
68 int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
69 SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
70 SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
71 boost::optional<Geom::Rect> const bbox(sel->bounds(bbox_type));
72 if ( bbox && !bbox->isEmpty() ) {
73 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
74 SPUnit const &unit = *tracker->getActiveUnit();
76 struct { char const *key; double val; } const keyval[] = {
77 { "X", bbox->min()[X] },
78 { "Y", bbox->min()[Y] },
79 { "width", bbox->dimensions()[X] },
80 { "height", bbox->dimensions()[Y] }
81 };
83 if (unit.base == SP_UNIT_DIMENSIONLESS) {
84 double const val = 1. / unit.unittobase;
85 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
86 GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
87 gtk_adjustment_set_value(a, val);
88 tracker->setFullVal( a, keyval[i].val );
89 }
90 } else {
91 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
92 GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
93 gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit));
94 }
95 }
96 }
97 }
99 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
100 }
103 static void
104 sp_selection_layout_widget_modify_selection(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data)
105 {
106 SPDesktop *desktop = (SPDesktop *) data;
107 if ((sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop
108 && (flags & (SP_OBJECT_MODIFIED_FLAG |
109 SP_OBJECT_PARENT_MODIFIED_FLAG |
110 SP_OBJECT_CHILD_MODIFIED_FLAG )))
111 {
112 sp_selection_layout_widget_update(spw, selection);
113 }
114 }
116 static void
117 sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *selection, gpointer data)
118 {
119 SPDesktop *desktop = (SPDesktop *) data;
120 if (sp_desktop_selection(desktop) == selection) { // only respond to changes in our desktop
121 gboolean setActive = (selection && !selection->isEmpty());
122 std::vector<GtkAction*> *contextActions = reinterpret_cast<std::vector<GtkAction*> *>(g_object_get_data(G_OBJECT(spw), "contextActions"));
123 if ( contextActions ) {
124 for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
125 iter != contextActions->end(); ++iter) {
126 if ( setActive != gtk_action_is_sensitive(*iter) ) {
127 gtk_action_set_sensitive( *iter, setActive );
128 }
129 }
130 }
132 sp_selection_layout_widget_update(spw, selection);
133 }
134 }
136 static void
137 sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
138 {
139 if (g_object_get_data(G_OBJECT(spw), "update")) {
140 return;
141 }
143 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
144 if ( !tracker || tracker->isUpdating() ) {
145 /*
146 * When only units are being changed, don't treat changes
147 * to adjuster values as object changes.
148 */
149 return;
150 }
151 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
153 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
154 Inkscape::Selection *selection = sp_desktop_selection(desktop);
155 SPDocument *document = sp_desktop_document(desktop);
157 sp_document_ensure_up_to_date (document);
158 int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
159 SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
160 SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
161 boost::optional<Geom::Rect> bbox = selection->bounds(bbox_type);
163 if ( !bbox || bbox->isEmpty() ) {
164 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
165 return;
166 }
168 gdouble x0 = 0;
169 gdouble y0 = 0;
170 gdouble x1 = 0;
171 gdouble y1 = 0;
172 gdouble xrel = 0;
173 gdouble yrel = 0;
174 SPUnit const &unit = *tracker->getActiveUnit();
176 GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
177 GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
178 GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
179 GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
181 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
182 x0 = sp_units_get_pixels (a_x->value, unit);
183 y0 = sp_units_get_pixels (a_y->value, unit);
184 x1 = x0 + sp_units_get_pixels (a_w->value, unit);
185 xrel = sp_units_get_pixels (a_w->value, unit) / bbox->dimensions()[Geom::X];
186 y1 = y0 + sp_units_get_pixels (a_h->value, unit);
187 yrel = sp_units_get_pixels (a_h->value, unit) / bbox->dimensions()[Geom::Y];
188 } else {
189 double const x0_propn = a_x->value * unit.unittobase;
190 x0 = bbox->min()[Geom::X] * x0_propn;
191 double const y0_propn = a_y->value * unit.unittobase;
192 y0 = y0_propn * bbox->min()[Geom::Y];
193 xrel = a_w->value * unit.unittobase;
194 x1 = x0 + xrel * bbox->dimensions()[Geom::X];
195 yrel = a_h->value * unit.unittobase;
196 y1 = y0 + yrel * bbox->dimensions()[Geom::Y];
197 }
199 // Keep proportions if lock is on
200 GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(G_OBJECT(spw), "lock") );
201 if ( gtk_toggle_action_get_active(lock) ) {
202 if (adj == a_h) {
203 x1 = x0 + yrel * bbox->dimensions()[Geom::X];
204 } else if (adj == a_w) {
205 y1 = y0 + xrel * bbox->dimensions()[Geom::Y];
206 }
207 }
209 // scales and moves, in px
210 double mh = fabs(x0 - bbox->min()[Geom::X]);
211 double sh = fabs(x1 - bbox->max()[Geom::X]);
212 double mv = fabs(y0 - bbox->min()[Geom::Y]);
213 double sv = fabs(y1 - bbox->max()[Geom::Y]);
215 // unless the unit is %, convert the scales and moves to the unit
216 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
217 mh = sp_pixels_get_units (mh, unit);
218 sh = sp_pixels_get_units (sh, unit);
219 mv = sp_pixels_get_units (mv, unit);
220 sv = sp_pixels_get_units (sv, unit);
221 }
223 // do the action only if one of the scales/moves is greater than half the last significant
224 // digit in the spinbox (currently spinboxes have 3 fractional digits, so that makes 0.0005). If
225 // the value was changed by the user, the difference will be at least that much; otherwise it's
226 // just rounding difference between the spinbox value and actual value, so no action is
227 // performed
228 char const * const actionkey = ( mh > 5e-4 ? "selector:toolbar:move:horizontal" :
229 sh > 5e-4 ? "selector:toolbar:scale:horizontal" :
230 mv > 5e-4 ? "selector:toolbar:move:vertical" :
231 sv > 5e-4 ? "selector:toolbar:scale:vertical" : NULL );
233 if (actionkey != NULL) {
235 // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed
236 sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
238 gdouble strokewidth = stroke_average_width (selection->itemList());
239 int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
241 NR::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
243 sp_selection_apply_affine(selection, scaler);
244 sp_document_maybe_done (document, actionkey, SP_VERB_CONTEXT_SELECT,
245 _("Transform by toolbar"));
247 // resume interruptibility
248 sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
249 }
251 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
252 }
254 static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
255 gchar const *label,
256 gchar const *shortLabel,
257 gchar const *data,
258 gdouble lower,
259 GtkWidget* focusTarget,
260 UnitTracker* tracker,
261 GtkWidget* spw,
262 gchar const *tooltip,
263 gboolean altx )
264 {
265 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, SPIN_PAGE_STEP ) );
266 if (tracker) {
267 tracker->addAdjustment(adj);
268 }
269 if ( spw ) {
270 g_object_set_data( G_OBJECT(spw), data, adj );
271 }
273 EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, Q_(label), tooltip, 0, SPIN_STEP, 3 );
274 if ( shortLabel ) {
275 g_object_set( act, "short_label", Q_(shortLabel), NULL );
276 }
278 gtk_signal_connect( GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(sp_object_layout_any_value_changed), spw );
279 if ( focusTarget ) {
280 ege_adjustment_action_set_focuswidget( act, focusTarget );
281 }
283 if ( altx ) { // this spinbutton will be activated by alt-x
284 g_object_set( G_OBJECT(act), "self-id", "altx", NULL );
285 }
287 // Using a cast just to make sure we pass in the right kind of function pointer
288 g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
290 return act;
291 }
293 // toggle button callbacks and updaters
295 static void toggle_stroke( GtkToggleAction* act, gpointer data ) {
296 gboolean active = gtk_toggle_action_get_active( act );
297 prefs_set_int_attribute( "options.transform", "stroke", active ? 1 : 0 );
298 SPDesktop *desktop = (SPDesktop *)data;
299 if ( active ) {
300 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
301 } else {
302 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>not scaled</b> when objects are scaled."));
303 }
304 }
306 static void toggle_corners( GtkToggleAction* act, gpointer data) {
307 gboolean active = gtk_toggle_action_get_active( act );
308 prefs_set_int_attribute( "options.transform", "rectcorners", active ? 1 : 0 );
309 SPDesktop *desktop = (SPDesktop *)data;
310 if ( active ) {
311 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
312 } else {
313 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>not scaled</b> when rectangles are scaled."));
314 }
315 }
317 static void toggle_gradient( GtkToggleAction *act, gpointer data ) {
318 gboolean active = gtk_toggle_action_get_active( act );
319 prefs_set_int_attribute( "options.transform", "gradient", active ? 1 : 0 );
320 SPDesktop *desktop = (SPDesktop *)data;
321 if ( active ) {
322 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)."));
323 } else {
324 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
325 }
326 }
328 static void toggle_pattern( GtkToggleAction* act, gpointer data ) {
329 gboolean active = gtk_toggle_action_get_active( act );
330 prefs_set_int_attribute( "options.transform", "pattern", active ? 1 : 0 );
331 SPDesktop *desktop = (SPDesktop *)data;
332 if ( active ) {
333 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)."));
334 } else {
335 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>patterns</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
336 }
337 }
339 static void toggle_lock( GtkToggleAction *act, gpointer /*data*/ ) {
340 gboolean active = gtk_toggle_action_get_active( act );
341 if ( active ) {
342 g_object_set( G_OBJECT(act), "iconId", "width_height_lock", NULL );
343 } else {
344 g_object_set( G_OBJECT(act), "iconId", "lock_unlocked", NULL );
345 }
346 }
348 static void destroy_tracker( GObject* obj, gpointer /*user_data*/ )
349 {
350 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(obj, "tracker"));
351 if ( tracker ) {
352 delete tracker;
353 g_object_set_data( obj, "tracker", 0 );
354 }
355 }
357 static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data )
358 {
359 SPAction* targetAction = SP_ACTION(user_data);
360 if ( targetAction ) {
361 sp_action_perform( targetAction, NULL );
362 }
363 }
365 static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size )
366 {
367 GtkAction* act = 0;
369 SPAction* targetAction = verb->get_action(view);
370 InkAction* inky = ink_action_new( verb->get_id(), verb->get_name(), verb->get_tip(), verb->get_image(), size );
371 act = GTK_ACTION(inky);
373 g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
375 return act;
376 }
378 void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
379 {
380 Inkscape::UI::View::View *view = desktop;
381 Inkscape::IconSize secondarySize = prefToSize("toolbox", "secondary", 1);
383 GtkAction* act = 0;
385 GtkActionGroup* selectionActions = mainActions; // temporary
386 std::vector<GtkAction*>* contextActions = new std::vector<GtkAction*>();
388 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL), view, secondarySize );
389 gtk_action_group_add_action( selectionActions, act );
390 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS), view, secondarySize );
391 gtk_action_group_add_action( selectionActions, act );
392 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_DESELECT), view, secondarySize );
393 gtk_action_group_add_action( selectionActions, act );
394 contextActions->push_back( act );
396 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), view, secondarySize );
397 gtk_action_group_add_action( selectionActions, act );
398 contextActions->push_back( act );
399 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CW), view, secondarySize );
400 gtk_action_group_add_action( selectionActions, act );
401 contextActions->push_back( act );
402 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_HORIZONTAL), view, secondarySize );
403 gtk_action_group_add_action( selectionActions, act );
404 contextActions->push_back( act );
405 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, secondarySize );
406 gtk_action_group_add_action( selectionActions, act );
407 contextActions->push_back( act );
409 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, secondarySize );
410 gtk_action_group_add_action( selectionActions, act );
411 contextActions->push_back( act );
412 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, secondarySize );
413 gtk_action_group_add_action( selectionActions, act );
414 contextActions->push_back( act );
415 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, secondarySize );
416 gtk_action_group_add_action( selectionActions, act );
417 contextActions->push_back( act );
418 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, secondarySize );
419 gtk_action_group_add_action( selectionActions, act );
420 contextActions->push_back( act );
422 // Create the parent widget for x y w h tracker.
423 GtkWidget *spw = sp_widget_new_global(INKSCAPE);
425 // Remember the desktop's canvas widget, to be used for defocusing.
426 g_object_set_data(G_OBJECT(spw), "dtw", sp_desktop_canvas(desktop));
428 // The vb frame holds all other widgets and is used to set sensitivity depending on selection state.
429 GtkWidget *vb = gtk_hbox_new(FALSE, 0);
430 gtk_widget_show(vb);
431 gtk_container_add(GTK_CONTAINER(spw), vb);
433 // Create the units menu.
434 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
435 tracker->addUnit( SP_UNIT_PERCENT, 0 );
436 tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
438 g_object_set_data( G_OBJECT(spw), "tracker", tracker );
439 g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw );
441 EgeAdjustmentAction* eact = 0;
443 // four spinbuttons
445 //TRANSLATORS: only translate "string" in "context|string".
446 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
447 eact = create_adjustment_action( "XAction", _("select_toolbar|X position"), _("select_toolbar|X"), "X",
448 -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
449 _("Horizontal coordinate of selection"), TRUE );
450 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
451 contextActions->push_back( GTK_ACTION(eact) );
453 //TRANSLATORS: only translate "string" in "context|string".
454 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
455 eact = create_adjustment_action( "YAction", _("select_toolbar|Y position"), _("select_toolbar|Y"), "Y",
456 -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
457 _("Vertical coordinate of selection"), FALSE );
458 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
459 contextActions->push_back( GTK_ACTION(eact) );
461 //TRANSLATORS: only translate "string" in "context|string".
462 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
463 eact = create_adjustment_action( "WidthAction", _("select_toolbar|Width"), _("select_toolbar|W"), "width",
464 1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
465 _("Width of selection"), FALSE );
466 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
467 contextActions->push_back( GTK_ACTION(eact) );
469 // lock toggle
470 {
471 InkToggleAction* itact = ink_toggle_action_new( "LockAction",
472 _("Lock width and height"),
473 _("When locked, change both width and height by the same proportion"),
474 "lock_unlocked",
475 Inkscape::ICON_SIZE_DECORATION );
476 g_object_set( itact, "short_label", "Lock", NULL );
477 g_object_set_data( G_OBJECT(spw), "lock", itact );
478 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_lock), desktop) ;
479 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
480 }
482 //TRANSLATORS: only translate "string" in "context|string".
483 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
484 eact = create_adjustment_action( "HeightAction", _("select_toolbar|Height"), _("select_toolbar|H"), "height",
485 1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
486 _("Height of selection"), FALSE );
487 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
488 contextActions->push_back( GTK_ACTION(eact) );
490 // Add the units menu.
491 act = tracker->createAction( "UnitsAction", _("Units"), ("") );
492 gtk_action_group_add_action( selectionActions, act );
494 g_object_set_data( G_OBJECT(spw), "selectionActions", selectionActions );
495 g_object_set_data( G_OBJECT(spw), "contextActions", contextActions );
497 // Force update when selection changes.
498 gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_modify_selection), desktop);
499 gtk_signal_connect(GTK_OBJECT(spw), "change_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_change_selection), desktop);
501 // Update now.
502 sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? sp_desktop_selection(SP_ACTIVE_DESKTOP) : NULL);
504 for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
505 iter != contextActions->end(); ++iter) {
506 if ( gtk_action_is_sensitive(*iter) ) {
507 gtk_action_set_sensitive( *iter, FALSE );
508 }
509 }
511 // Insert spw into the toolbar.
512 if ( GTK_IS_BOX(holder) ) {
513 gtk_box_pack_start(GTK_BOX(holder), spw, FALSE, FALSE, 0);
514 } else if ( GTK_IS_TOOLBAR(holder) ) {
515 gtk_toolbar_append_widget( GTK_TOOLBAR(holder), spw, "Text", "priv" );
516 } else {
517 g_warning("Unexpected holder type");
518 }
520 // "Transform with object" buttons
522 {
523 EgeOutputAction* act = ege_output_action_new( "transform_affect_label", _("Affect:"), "", 0 );
524 ege_output_action_set_use_markup( act, TRUE );
525 g_object_set( act, "visible-overflown", FALSE, NULL );
526 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
527 }
529 {
530 InkToggleAction* itact = ink_toggle_action_new( "transform_stroke",
531 _("Scale stroke width"),
532 _("When scaling objects, scale the stroke width by the same proportion"),
533 "transform_stroke",
534 Inkscape::ICON_SIZE_DECORATION );
535 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "stroke", 1) );
536 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_stroke), desktop) ;
537 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
538 }
540 {
541 InkToggleAction* itact = ink_toggle_action_new( "transform_corners",
542 _("Scale rounded corners"),
543 _("When scaling rectangles, scale the radii of rounded corners"),
544 "transform_corners",
545 Inkscape::ICON_SIZE_DECORATION );
546 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "rectcorners", 1) );
547 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_corners), desktop) ;
548 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
549 }
551 {
552 InkToggleAction* itact = ink_toggle_action_new( "transform_gradient",
553 _("Move gradients"),
554 _("Move gradients (in fill or stroke) along with the objects"),
555 "transform_gradient",
556 Inkscape::ICON_SIZE_DECORATION );
557 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "gradient", 1) );
558 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_gradient), desktop) ;
559 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
560 }
562 {
563 InkToggleAction* itact = ink_toggle_action_new( "transform_pattern",
564 _("Move patterns"),
565 _("Move patterns (in fill or stroke) along with the objects"),
566 "transform_pattern",
567 Inkscape::ICON_SIZE_DECORATION );
568 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs_get_int_attribute("options.transform", "pattern", 1) );
569 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_pattern), desktop) ;
570 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
571 }
572 }
575 /*
576 Local Variables:
577 mode:c++
578 c-file-style:"stroustrup"
579 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
580 indent-tabs-mode:nil
581 fill-column:99
582 End:
583 */
584 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :