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