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 * Abhishek Sharma
9 *
10 * Copyright (C) 2003-2005 authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #include <gtk/gtk.h>
20 #include <gtk/gtkaction.h>
22 #include "widgets/button.h"
23 #include "widgets/spw-utilities.h"
24 #include "widgets/widget-sizes.h"
25 #include "widgets/spinbutton-events.h"
26 #include "widgets/icon.h"
27 #include "widgets/sp-widget.h"
29 #include "preferences.h"
30 #include "selection-chemistry.h"
31 #include "document.h"
32 #include "inkscape.h"
33 #include "desktop-style.h"
34 #include "desktop.h"
35 #include "desktop-handles.h"
36 #include "sp-namedview.h"
37 #include "toolbox.h"
38 #include <glibmm/i18n.h>
39 #include "helper/unit-menu.h"
40 #include "helper/units.h"
41 #include "inkscape.h"
42 #include "verbs.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>
53 #include "ui/icon-names.h"
55 using Inkscape::UnitTracker;
56 using Inkscape::DocumentUndo;
58 static void
59 sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
60 {
61 if (g_object_get_data(G_OBJECT(spw), "update")) {
62 return;
63 }
65 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
67 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
68 using Geom::X;
69 using Geom::Y;
70 if ( sel && !sel->isEmpty() ) {
71 int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);
72 SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
73 SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
74 Geom::OptRect const bbox(sel->bounds(bbox_type));
75 if ( bbox ) {
76 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
77 SPUnit const &unit = *tracker->getActiveUnit();
79 struct { char const *key; double val; } const keyval[] = {
80 { "X", bbox->min()[X] },
81 { "Y", bbox->min()[Y] },
82 { "width", bbox->dimensions()[X] },
83 { "height", bbox->dimensions()[Y] }
84 };
86 if (unit.base == SP_UNIT_DIMENSIONLESS) {
87 double const val = 1. / unit.unittobase;
88 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
89 GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
90 gtk_adjustment_set_value(a, val);
91 tracker->setFullVal( a, keyval[i].val );
92 }
93 } else {
94 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
95 GtkAdjustment *a = (GtkAdjustment *) g_object_get_data(G_OBJECT(spw), keyval[i].key);
96 gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit));
97 }
98 }
99 }
100 }
102 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
103 }
106 static void
107 sp_selection_layout_widget_modify_selection(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data)
108 {
109 SPDesktop *desktop = (SPDesktop *) data;
110 if ((sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop
111 && (flags & (SP_OBJECT_MODIFIED_FLAG |
112 SP_OBJECT_PARENT_MODIFIED_FLAG |
113 SP_OBJECT_CHILD_MODIFIED_FLAG )))
114 {
115 sp_selection_layout_widget_update(spw, selection);
116 }
117 }
119 static void
120 sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *selection, gpointer data)
121 {
122 SPDesktop *desktop = (SPDesktop *) data;
123 if (sp_desktop_selection(desktop) == selection) { // only respond to changes in our desktop
124 gboolean setActive = (selection && !selection->isEmpty());
125 std::vector<GtkAction*> *contextActions = reinterpret_cast<std::vector<GtkAction*> *>(g_object_get_data(G_OBJECT(spw), "contextActions"));
126 if ( contextActions ) {
127 for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
128 iter != contextActions->end(); ++iter) {
129 if ( setActive != gtk_action_is_sensitive(*iter) ) {
130 gtk_action_set_sensitive( *iter, setActive );
131 }
132 }
133 }
135 sp_selection_layout_widget_update(spw, selection);
136 }
137 }
139 static void
140 sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
141 {
142 if (g_object_get_data(G_OBJECT(spw), "update")) {
143 return;
144 }
146 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
147 if ( !tracker || tracker->isUpdating() ) {
148 /*
149 * When only units are being changed, don't treat changes
150 * to adjuster values as object changes.
151 */
152 return;
153 }
154 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
156 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
157 Inkscape::Selection *selection = sp_desktop_selection(desktop);
158 SPDocument *document = sp_desktop_document(desktop);
160 document->ensureUpToDate ();
161 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
162 int prefs_bbox = prefs->getInt("/tools/bounding_box");
163 SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
164 SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
165 Geom::OptRect bbox = selection->bounds(bbox_type);
167 if ( !bbox ) {
168 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
169 return;
170 }
172 gdouble x0 = 0;
173 gdouble y0 = 0;
174 gdouble x1 = 0;
175 gdouble y1 = 0;
176 gdouble xrel = 0;
177 gdouble yrel = 0;
178 SPUnit const &unit = *tracker->getActiveUnit();
180 GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
181 GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
182 GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
183 GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
185 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
186 x0 = sp_units_get_pixels (a_x->value, unit);
187 y0 = sp_units_get_pixels (a_y->value, unit);
188 x1 = x0 + sp_units_get_pixels (a_w->value, unit);
189 xrel = sp_units_get_pixels (a_w->value, unit) / bbox->dimensions()[Geom::X];
190 y1 = y0 + sp_units_get_pixels (a_h->value, unit);
191 yrel = sp_units_get_pixels (a_h->value, unit) / bbox->dimensions()[Geom::Y];
192 } else {
193 double const x0_propn = a_x->value * unit.unittobase;
194 x0 = bbox->min()[Geom::X] * x0_propn;
195 double const y0_propn = a_y->value * unit.unittobase;
196 y0 = y0_propn * bbox->min()[Geom::Y];
197 xrel = a_w->value * unit.unittobase;
198 x1 = x0 + xrel * bbox->dimensions()[Geom::X];
199 yrel = a_h->value * unit.unittobase;
200 y1 = y0 + yrel * bbox->dimensions()[Geom::Y];
201 }
203 // Keep proportions if lock is on
204 GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(G_OBJECT(spw), "lock") );
205 if ( gtk_toggle_action_get_active(lock) ) {
206 if (adj == a_h) {
207 x1 = x0 + yrel * bbox->dimensions()[Geom::X];
208 } else if (adj == a_w) {
209 y1 = y0 + xrel * bbox->dimensions()[Geom::Y];
210 }
211 }
213 // scales and moves, in px
214 double mh = fabs(x0 - bbox->min()[Geom::X]);
215 double sh = fabs(x1 - bbox->max()[Geom::X]);
216 double mv = fabs(y0 - bbox->min()[Geom::Y]);
217 double sv = fabs(y1 - bbox->max()[Geom::Y]);
219 // unless the unit is %, convert the scales and moves to the unit
220 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
221 mh = sp_pixels_get_units (mh, unit);
222 sh = sp_pixels_get_units (sh, unit);
223 mv = sp_pixels_get_units (mv, unit);
224 sv = sp_pixels_get_units (sv, unit);
225 }
227 // do the action only if one of the scales/moves is greater than half the last significant
228 // digit in the spinbox (currently spinboxes have 3 fractional digits, so that makes 0.0005). If
229 // the value was changed by the user, the difference will be at least that much; otherwise it's
230 // just rounding difference between the spinbox value and actual value, so no action is
231 // performed
232 char const * const actionkey = ( mh > 5e-4 ? "selector:toolbar:move:horizontal" :
233 sh > 5e-4 ? "selector:toolbar:scale:horizontal" :
234 mv > 5e-4 ? "selector:toolbar:move:vertical" :
235 sv > 5e-4 ? "selector:toolbar:scale:vertical" : NULL );
237 if (actionkey != NULL) {
239 // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed
240 sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
242 gdouble strokewidth = stroke_average_width (selection->itemList());
243 int transform_stroke = prefs->getBool("/options/transform/stroke", true) ? 1 : 0;
245 Geom::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
247 sp_selection_apply_affine(selection, scaler);
248 DocumentUndo::maybeDone(document, actionkey, SP_VERB_CONTEXT_SELECT,
249 _("Transform by toolbar"));
251 // resume interruptibility
252 sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
253 }
255 g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
256 }
258 static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
259 gchar const *label,
260 gchar const *shortLabel,
261 gchar const *data,
262 gdouble lower,
263 GtkWidget* focusTarget,
264 UnitTracker* tracker,
265 GtkWidget* spw,
266 gchar const *tooltip,
267 gboolean altx )
268 {
269 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, 0 ) );
270 if (tracker) {
271 tracker->addAdjustment(adj);
272 }
273 if ( spw ) {
274 g_object_set_data( G_OBJECT(spw), data, adj );
275 }
277 EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, Q_(label), tooltip, 0, SPIN_STEP, 3 );
278 if ( shortLabel ) {
279 g_object_set( act, "short_label", Q_(shortLabel), NULL );
280 }
282 gtk_signal_connect( GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(sp_object_layout_any_value_changed), spw );
283 if ( focusTarget ) {
284 ege_adjustment_action_set_focuswidget( act, focusTarget );
285 }
287 if ( altx ) { // this spinbutton will be activated by alt-x
288 g_object_set( G_OBJECT(act), "self-id", "altx", NULL );
289 }
291 // Using a cast just to make sure we pass in the right kind of function pointer
292 g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
294 return act;
295 }
297 // toggle button callbacks and updaters
299 static void toggle_stroke( GtkToggleAction* act, gpointer data )
300 {
301 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
302 gboolean active = gtk_toggle_action_get_active(act);
303 prefs->setBool("/options/transform/stroke", active);
304 SPDesktop *desktop = (SPDesktop *)data;
305 if ( active ) {
306 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
307 } else {
308 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>not scaled</b> when objects are scaled."));
309 }
310 }
312 static void toggle_corners( GtkToggleAction* act, gpointer data)
313 {
314 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
315 gboolean active = gtk_toggle_action_get_active(act);
316 prefs->setBool("/options/transform/rectcorners", active);
317 SPDesktop *desktop = (SPDesktop *)data;
318 if ( active ) {
319 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
320 } else {
321 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>not scaled</b> when rectangles are scaled."));
322 }
323 }
325 static void toggle_gradient( GtkToggleAction *act, gpointer data )
326 {
327 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
328 gboolean active = gtk_toggle_action_get_active(act);
329 prefs->setBool("/options/transform/gradient", active);
330 SPDesktop *desktop = (SPDesktop *)data;
331 if ( active ) {
332 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)."));
333 } else {
334 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
335 }
336 }
338 static void toggle_pattern( GtkToggleAction* act, gpointer data )
339 {
340 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
341 gboolean active = gtk_toggle_action_get_active(act);
342 prefs->setInt("/options/transform/pattern", active);
343 SPDesktop *desktop = (SPDesktop *)data;
344 if ( active ) {
345 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)."));
346 } else {
347 desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>patterns</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
348 }
349 }
351 static void toggle_lock( GtkToggleAction *act, gpointer /*data*/ ) {
352 gboolean active = gtk_toggle_action_get_active( act );
353 if ( active ) {
354 g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON_OBJECT_LOCKED, NULL );
355 } else {
356 g_object_set( G_OBJECT(act), "iconId", INKSCAPE_ICON_OBJECT_UNLOCKED, NULL );
357 }
358 }
360 static void destroy_tracker( GObject* obj, gpointer /*user_data*/ )
361 {
362 UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(obj, "tracker"));
363 if ( tracker ) {
364 delete tracker;
365 g_object_set_data( obj, "tracker", 0 );
366 }
367 }
369 static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data )
370 {
371 SPAction* targetAction = SP_ACTION(user_data);
372 if ( targetAction ) {
373 sp_action_perform( targetAction, NULL );
374 }
375 }
377 static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size )
378 {
379 GtkAction* act = 0;
381 SPAction* targetAction = verb->get_action(view);
382 InkAction* inky = ink_action_new( verb->get_id(), verb->get_name(), verb->get_tip(), verb->get_image(), size );
383 act = GTK_ACTION(inky);
385 g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
387 Inkscape::queueIconPrerender( verb->get_image(), size );
389 return act;
390 }
392 void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
393 {
394 Inkscape::UI::View::View *view = desktop;
395 Inkscape::IconSize secondarySize = Inkscape::UI::ToolboxFactory::prefToSize("/toolbox/secondary", 1);
396 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
398 GtkAction* act = 0;
400 GtkActionGroup* selectionActions = mainActions; // temporary
401 std::vector<GtkAction*>* contextActions = new std::vector<GtkAction*>();
403 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL), view, secondarySize );
404 gtk_action_group_add_action( selectionActions, act );
405 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS), view, secondarySize );
406 gtk_action_group_add_action( selectionActions, act );
407 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_EDIT_DESELECT), view, secondarySize );
408 gtk_action_group_add_action( selectionActions, act );
409 contextActions->push_back( act );
411 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), 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_OBJECT_ROTATE_90_CW), 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_OBJECT_FLIP_HORIZONTAL), view, secondarySize );
418 gtk_action_group_add_action( selectionActions, act );
419 contextActions->push_back( act );
420 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, secondarySize );
421 gtk_action_group_add_action( selectionActions, act );
422 contextActions->push_back( act );
424 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, secondarySize );
425 gtk_action_group_add_action( selectionActions, act );
426 contextActions->push_back( act );
427 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, secondarySize );
428 gtk_action_group_add_action( selectionActions, act );
429 contextActions->push_back( act );
430 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, secondarySize );
431 gtk_action_group_add_action( selectionActions, act );
432 contextActions->push_back( act );
433 act = create_action_for_verb( Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, secondarySize );
434 gtk_action_group_add_action( selectionActions, act );
435 contextActions->push_back( act );
437 // Create the parent widget for x y w h tracker.
438 GtkWidget *spw = sp_widget_new_global(INKSCAPE);
440 // Remember the desktop's canvas widget, to be used for defocusing.
441 g_object_set_data(G_OBJECT(spw), "dtw", sp_desktop_canvas(desktop));
443 // The vb frame holds all other widgets and is used to set sensitivity depending on selection state.
444 GtkWidget *vb = gtk_hbox_new(FALSE, 0);
445 gtk_widget_show(vb);
446 gtk_container_add(GTK_CONTAINER(spw), vb);
448 // Create the units menu.
449 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
450 tracker->addUnit( SP_UNIT_PERCENT, 0 );
451 tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
453 g_object_set_data( G_OBJECT(spw), "tracker", tracker );
454 g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw );
456 EgeAdjustmentAction* eact = 0;
458 // four spinbuttons
460 eact = create_adjustment_action( "XAction", C_("Select toolbar", "X position"), C_("Select toolbar", "X:"), "X",
461 -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
462 _("Horizontal coordinate of selection"), TRUE );
463 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
464 contextActions->push_back( GTK_ACTION(eact) );
466 eact = create_adjustment_action( "YAction", C_("Select toolbar", "Y position"), C_("Select toolbar", "Y:"), "Y",
467 -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
468 _("Vertical coordinate of selection"), FALSE );
469 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
470 contextActions->push_back( GTK_ACTION(eact) );
472 eact = create_adjustment_action( "WidthAction", C_("Select toolbar", "Width"), C_("Select toolbar", "W:"), "width",
473 1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
474 _("Width of selection"), FALSE );
475 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
476 contextActions->push_back( GTK_ACTION(eact) );
478 // lock toggle
479 {
480 InkToggleAction* itact = ink_toggle_action_new( "LockAction",
481 _("Lock width and height"),
482 _("When locked, change both width and height by the same proportion"),
483 INKSCAPE_ICON_OBJECT_UNLOCKED,
484 Inkscape::ICON_SIZE_DECORATION );
485 g_object_set( itact, "short_label", "Lock", NULL );
486 g_object_set_data( G_OBJECT(spw), "lock", itact );
487 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_lock), desktop) ;
488 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
489 }
491 eact = create_adjustment_action( "HeightAction", C_("Select toolbar", "Height"), C_("Select toolbar", "H:"), "height",
492 1e-3, GTK_WIDGET(desktop->canvas), tracker, spw,
493 _("Height of selection"), FALSE );
494 gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
495 contextActions->push_back( GTK_ACTION(eact) );
497 // Add the units menu.
498 act = tracker->createAction( "UnitsAction", _("Units"), ("") );
499 gtk_action_group_add_action( selectionActions, act );
501 g_object_set_data( G_OBJECT(spw), "selectionActions", selectionActions );
502 g_object_set_data( G_OBJECT(spw), "contextActions", contextActions );
504 // Force update when selection changes.
505 gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_modify_selection), desktop);
506 gtk_signal_connect(GTK_OBJECT(spw), "change_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_change_selection), desktop);
508 // Update now.
509 sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? sp_desktop_selection(SP_ACTIVE_DESKTOP) : NULL);
511 for ( std::vector<GtkAction*>::iterator iter = contextActions->begin();
512 iter != contextActions->end(); ++iter) {
513 if ( gtk_action_is_sensitive(*iter) ) {
514 gtk_action_set_sensitive( *iter, FALSE );
515 }
516 }
518 // Insert spw into the toolbar.
519 if ( GTK_IS_BOX(holder) ) {
520 gtk_box_pack_start(GTK_BOX(holder), spw, FALSE, FALSE, 0);
521 } else if ( GTK_IS_TOOLBAR(holder) ) {
522 gtk_toolbar_append_widget( GTK_TOOLBAR(holder), spw, "Text", "priv" );
523 } else {
524 g_warning("Unexpected holder type");
525 }
527 // "Transform with object" buttons
529 {
530 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 );
531 ege_output_action_set_use_markup( act, TRUE );
532 g_object_set( act, "visible-overflown", FALSE, NULL );
533 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
534 }
536 {
537 InkToggleAction* itact = ink_toggle_action_new( "transform_stroke",
538 _("Scale stroke width"),
539 _("When scaling objects, scale the stroke width by the same proportion"),
540 INKSCAPE_ICON_TRANSFORM_AFFECT_STROKE,
541 Inkscape::ICON_SIZE_DECORATION );
542 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/stroke", true) );
543 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_stroke), desktop) ;
544 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
545 }
547 {
548 InkToggleAction* itact = ink_toggle_action_new( "transform_corners",
549 _("Scale rounded corners"),
550 _("When scaling rectangles, scale the radii of rounded corners"),
551 INKSCAPE_ICON_TRANSFORM_AFFECT_ROUNDED_CORNERS,
552 Inkscape::ICON_SIZE_DECORATION );
553 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/rectcorners", true) );
554 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_corners), desktop) ;
555 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
556 }
558 {
559 InkToggleAction* itact = ink_toggle_action_new( "transform_gradient",
560 _("Move gradients"),
561 _("Move gradients (in fill or stroke) along with the objects"),
562 INKSCAPE_ICON_TRANSFORM_AFFECT_GRADIENT,
563 Inkscape::ICON_SIZE_DECORATION );
564 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/gradient", true) );
565 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_gradient), desktop) ;
566 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
567 }
569 {
570 InkToggleAction* itact = ink_toggle_action_new( "transform_pattern",
571 _("Move patterns"),
572 _("Move patterns (in fill or stroke) along with the objects"),
573 INKSCAPE_ICON_TRANSFORM_AFFECT_PATTERN,
574 Inkscape::ICON_SIZE_DECORATION );
575 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(itact), prefs->getBool("/options/transform/pattern", true) );
576 g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(toggle_pattern), desktop) ;
577 gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
578 }
579 }
582 /*
583 Local Variables:
584 mode:c++
585 c-file-style:"stroustrup"
586 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
587 indent-tabs-mode:nil
588 fill-column:99
589 End:
590 */
591 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :