Code

Switch selection bounds and center to use NR::Maybe, addressing most of the
[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  *
8  * Copyright (C) 2003-2005 authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
17 #include <gtk/gtk.h>
19 #include "widgets/button.h"
20 #include "widgets/spw-utilities.h"
21 #include "widgets/widget-sizes.h"
22 #include "widgets/spinbutton-events.h"
23 #include "widgets/icon.h"
24 #include "widgets/sp-widget.h"
26 #include "prefs-utils.h"
27 #include "selection-chemistry.h"
28 #include "document.h"
29 #include "inkscape.h"
30 #include "desktop-style.h"
31 #include "desktop.h"
32 #include "desktop-handles.h"
33 #include "sp-namedview.h"
34 #include "toolbox.h"
35 #include <glibmm/i18n.h>
36 #include "helper/unit-menu.h"
37 #include "helper/units.h"
38 #include "inkscape.h"
39 #include "verbs.h"
40 #include "prefs-utils.h"
41 #include "selection.h"
42 #include "selection-chemistry.h"
43 #include "sp-item-transform.h"
44 #include "message-stack.h"
45 #include "display/sp-canvas.h"
47 static void
48 sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
49 {
50     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
51         return;
52     }
54     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
56     GtkWidget *f = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(spw), "frame");
58     using NR::X;
59     using NR::Y;
60     if ( sel && !sel->isEmpty() ) {
61         NR::Maybe<NR::Rect> const bbox(sel->bounds());
62         if ( bbox && ( bbox->extent(X) > 1e-6 || bbox->extent(Y) > 1e-6 ) ) {
63             GtkWidget *us = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(spw), "units");
64             SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us));
66             if (unit.base == SP_UNIT_DIMENSIONLESS) {
67                 char const * const keys[] = {"X", "Y", "width", "height"};
68                 double const val = 1. / unit.unittobase;
69                 for (unsigned i = 0; i < G_N_ELEMENTS(keys); ++i) {
70                     GtkAdjustment *a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), keys[i]);
71                     gtk_adjustment_set_value(a, val);
72                 }
73             } else {
74                 struct { char const *key; double val; } const keyval[] = {
75                     { "X", bbox->min()[X] },
76                     { "Y", bbox->min()[Y] },
77                     { "width", bbox->extent(X) },
78                     { "height", bbox->extent(Y) }
79                 };
80                 for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
81                     GtkAdjustment *a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), keyval[i].key);
82                     gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit));
83                 }
84             }
86             gtk_widget_set_sensitive(f, TRUE);
87         } else {
88             gtk_widget_set_sensitive(f, FALSE);
89         }
90     } else {
91         gtk_widget_set_sensitive(f, FALSE);
92     }
94     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
95 }
98 static void
99 sp_selection_layout_widget_modify_selection(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data)
101     SPDesktop *desktop = (SPDesktop *) data;
102     if ((sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop
103         && (flags & (SP_OBJECT_MODIFIED_FLAG        |
104                      SP_OBJECT_PARENT_MODIFIED_FLAG |
105                      SP_OBJECT_CHILD_MODIFIED_FLAG   )))
106     {
107         sp_selection_layout_widget_update(spw, selection);
108     }
111 static void
112 sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *selection, gpointer data)
114     SPDesktop *desktop = (SPDesktop *) data;
115     if (sp_desktop_selection(desktop) == selection) // only respond to changes in our desktop
116         sp_selection_layout_widget_update(spw, selection);
119 static void
120 sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
122     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
123         return;
124     }
126     GtkWidget *us = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(spw), "units");
127     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us));
128     if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(us))) {
129         /*
130          * When only units are being changed, don't treat changes
131          * to adjuster values as object changes.
132          */
133         return;
134     }
135     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
137     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
138     Inkscape::Selection *selection = sp_desktop_selection(desktop);
139     SPDocument *document = sp_desktop_document(desktop);
141     sp_document_ensure_up_to_date (document);
142     NR::Maybe<NR::Rect> bbox = selection->bounds();
144     if ( !bbox || bbox->extent(NR::X) < 1e-6 || bbox->extent(NR::Y) < 1e-6 ) {
145         return;
146     }
148     gdouble x0, y0, x1, y1, xrel, yrel;
149     GtkAdjustment *a_w;
150     GtkAdjustment *a_h;
152     if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
153         GtkAdjustment *a;
154         a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "X");
155         x0 = sp_units_get_pixels (a->value, unit);
156         a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "Y");
157         y0 = sp_units_get_pixels (a->value, unit);
158         a_w = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "width");
159         x1 = x0 + sp_units_get_pixels (a_w->value, unit);
160         xrel = sp_units_get_pixels (a_w->value, unit) / bbox->extent(NR::X);
161         a_h = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "height");
162         y1 = y0 + sp_units_get_pixels (a_h->value, unit);
163         yrel = sp_units_get_pixels (a_h->value, unit) / bbox->extent(NR::Y);
164     } else {
165         GtkAdjustment *a;
166         a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "X");
167         double const x0_propn = a->value * unit.unittobase;
168         x0 = bbox->min()[NR::X] * x0_propn;
169         a = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "Y");
170         double const y0_propn = a->value * unit.unittobase;
171         y0 = y0_propn * bbox->min()[NR::Y];
172         a_w = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "width");
173         xrel = a_w->value * unit.unittobase;
174         x1 = x0 + xrel * bbox->extent(NR::X);
175         a_h = (GtkAdjustment *) gtk_object_get_data(GTK_OBJECT(spw), "height");
176         yrel = a_h->value * unit.unittobase;
177         y1 = y0 + yrel * bbox->extent(NR::Y);
178     }
180     // Keep proportions if lock is on
181     GtkWidget *lock = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "lock"));
182     if (SP_BUTTON_IS_DOWN(lock)) {
183         if (adj == a_h) {
184             x1 = x0 + yrel * bbox->extent(NR::X);
185         } else if (adj == a_w) {
186             y1 = y0 + xrel * bbox->extent(NR::Y);
187         }
188     }
190     // scales and moves, in px
191     double mh = fabs(x0 - bbox->min()[NR::X]);
192     double sh = fabs(x1 - bbox->max()[NR::X]);
193     double mv = fabs(y0 - bbox->min()[NR::Y]);
194     double sv = fabs(y1 - bbox->max()[NR::Y]);
196     // unless the unit is %, convert the scales and moves to the unit
197     if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
198         mh = sp_pixels_get_units (mh, unit);
199         sh = sp_pixels_get_units (sh, unit);
200         mv = sp_pixels_get_units (mv, unit);
201         sv = sp_pixels_get_units (sv, unit);
202     }
204     // do the action only if one of the scales/moves is greater than half the last significant
205     // digit in the spinbox (currently spinboxes have 3 fractional digits, so that makes 0.0005). If
206     // the value was changed by the user, the difference will be at least that much; otherwise it's
207     // just rounding difference between the spinbox value and actual value, so no action is
208     // performed
209     char const * const actionkey = ( mh > 5e-4 ? "selector:toolbar:move:horizontal" : 
210                                      sh > 5e-4 ? "selector:toolbar:scale:horizontal" : 
211                                      mv > 5e-4 ? "selector:toolbar:move:vertical" : 
212                                      sv > 5e-4 ? "selector:toolbar:scale:vertical" : NULL );
214     if (actionkey != NULL) {
216         // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed
217         sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
219         gdouble strokewidth = stroke_average_width (selection->itemList());
220         int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
222         NR::Matrix scaler = get_scale_transform_with_stroke (*bbox, strokewidth, transform_stroke, x0, y0, x1, y1);
224         sp_selection_apply_affine(selection, scaler);
225         sp_document_maybe_done (document, actionkey, SP_VERB_CONTEXT_SELECT, 
226                                 _("Transform by toolbar"));
228         // defocus spinbuttons by moving focus to the canvas, unless "stay" is on
229         spinbutton_defocus(GTK_OBJECT(spw));
231         // resume interruptibility
232         sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
233     }
235     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
238 GtkWidget *
239 sp_select_toolbox_spinbutton(gchar *label, gchar *data, float lower_limit, GtkWidget *us, GtkWidget *spw, gchar *tooltip, gboolean altx)
241     GtkTooltips *tt = gtk_tooltips_new();
243     GtkWidget *hb = gtk_hbox_new(FALSE, 1);
244     GtkWidget *l = gtk_label_new(Q_(label));
245     gtk_tooltips_set_tip(tt, l, tooltip, NULL);
246     gtk_widget_show(l);
247     gtk_misc_set_alignment(GTK_MISC(l), 1.0, 0.5);
248     gtk_container_add(GTK_CONTAINER(hb), l);
250     GtkObject *a = gtk_adjustment_new(0.0, lower_limit, 1e6, SPIN_STEP, SPIN_PAGE_STEP, SPIN_PAGE_STEP);
251     sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(us), GTK_ADJUSTMENT(a));
252     gtk_object_set_data(GTK_OBJECT(spw), data, a);
254     GtkWidget *sb = gtk_spin_button_new(GTK_ADJUSTMENT(a), SPIN_STEP, 3);
255     gtk_tooltips_set_tip(tt, sb, tooltip, NULL);
256     gtk_widget_set_size_request(sb, AUX_SPINBUTTON_WIDTH, AUX_SPINBUTTON_HEIGHT);
257     gtk_widget_show(sb);
258     gtk_signal_connect(GTK_OBJECT(sb), "focus-in-event", GTK_SIGNAL_FUNC(spinbutton_focus_in), spw);
259     gtk_signal_connect(GTK_OBJECT(sb), "key-press-event", GTK_SIGNAL_FUNC(spinbutton_keypress), spw);
261     gtk_container_add(GTK_CONTAINER(hb), sb);
262     gtk_signal_connect(GTK_OBJECT(a), "value_changed", GTK_SIGNAL_FUNC(sp_object_layout_any_value_changed), spw);
264     if (altx) { // this spinbutton will be activated by alt-x
265         gtk_object_set_data(GTK_OBJECT(sb), "altx", sb);
266     }
268     return hb;
271 static gboolean aux_set_unit(SPUnitSelector *,
272                              SPUnit const *old,
273                              SPUnit const *new_units,
274                              GObject *dlg)
276     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
278     if (!desktop) {
279         return FALSE;
280     }
282     Inkscape::Selection *selection = sp_desktop_selection(desktop);
284     if (selection->isEmpty())
285         return FALSE;
287     if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE)
288         && (new_units->base == SP_UNIT_DIMENSIONLESS))
289     {
291         NR::Maybe<NR::Rect> bbox = selection->bounds();
292         if (!bbox) {
293             return FALSE;
294         }
296         /* Absolute to percentage */
297         g_object_set_data(dlg, "update", GUINT_TO_POINTER(TRUE));
299         GtkAdjustment *ax = GTK_ADJUSTMENT(g_object_get_data(dlg, "X"));
300         GtkAdjustment *ay = GTK_ADJUSTMENT(g_object_get_data(dlg, "Y"));
301         GtkAdjustment *aw = GTK_ADJUSTMENT(g_object_get_data(dlg, "width"));
302         GtkAdjustment *ah = GTK_ADJUSTMENT(g_object_get_data(dlg, "height"));
304         double const x = sp_units_get_pixels (ax->value, *old);
305         double const y = sp_units_get_pixels (ay->value, *old);
306         double const w = sp_units_get_pixels (aw->value, *old);
307         double const h = sp_units_get_pixels (ah->value, *old);
309         gtk_adjustment_set_value(ax, fabs(bbox->min()[NR::X]) > 1e-6? 100.0 * x / bbox->min()[NR::X] : 100.0);
310         gtk_adjustment_set_value(ay, fabs(bbox->min()[NR::Y]) > 1e-6? 100.0 * y / bbox->min()[NR::Y] : 100.0);
311         gtk_adjustment_set_value(aw, fabs(bbox->extent(NR::X)) > 1e-6? 100.0 * w / bbox->extent(NR::X) : 100.0);
312         gtk_adjustment_set_value(ah, fabs(bbox->extent(NR::Y)) > 1e-6? 100.0 * h / bbox->extent(NR::Y) : 100.0);
314         g_object_set_data(dlg, "update", GUINT_TO_POINTER(FALSE));
315         return TRUE;
316     } else if ((old->base == SP_UNIT_DIMENSIONLESS)
317                && (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) {
319         NR::Maybe<NR::Rect> bbox = selection->bounds();
320         if (!bbox) {
321             return FALSE;
322         }
324         /* Percentage to absolute */
325         g_object_set_data(dlg, "update", GUINT_TO_POINTER(TRUE));
327         GtkAdjustment *ax = GTK_ADJUSTMENT(g_object_get_data(dlg, "X"));
328         GtkAdjustment *ay = GTK_ADJUSTMENT(g_object_get_data(dlg, "Y"));
329         GtkAdjustment *aw = GTK_ADJUSTMENT(g_object_get_data(dlg, "width"));
330         GtkAdjustment *ah = GTK_ADJUSTMENT(g_object_get_data(dlg, "height"));
332         gtk_adjustment_set_value(ax, sp_pixels_get_units(0.01 * ax->value * bbox->min()[NR::X], *new_units));
333         gtk_adjustment_set_value(ay, sp_pixels_get_units(0.01 * ay->value * bbox->min()[NR::Y], *new_units));
334         gtk_adjustment_set_value(aw, sp_pixels_get_units(0.01 * aw->value * bbox->extent(NR::X), *new_units));
335         gtk_adjustment_set_value(ah, sp_pixels_get_units(0.01 * ah->value * bbox->extent(NR::Y), *new_units));
337         g_object_set_data(dlg, "update", GUINT_TO_POINTER(FALSE));
338         return TRUE;
339     }
341     return FALSE;
344 // toggle button callbacks and updaters
346 static void toggle_stroke (GtkWidget *button, gpointer data) {
347     prefs_set_int_attribute ("options.transform", "stroke", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 1 : 0);
348     SPDesktop *desktop = (SPDesktop *)data;
349     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
350         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>scaled</b> when objects are scaled."));
351     } else {
352         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>stroke width</b> is <b>not scaled</b> when objects are scaled."));
353     }
356 static void toggle_corners (GtkWidget *button, gpointer data) {
357     prefs_set_int_attribute ("options.transform", "rectcorners", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 1 : 0);
358     SPDesktop *desktop = (SPDesktop *)data;
359     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
360         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>scaled</b> when rectangles are scaled."));
361     } else {
362         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>rounded rectangle corners</b> are <b>not scaled</b> when rectangles are scaled."));
363     }
366 static void toggle_gradient (GtkWidget *button, gpointer data) {
367     prefs_set_int_attribute ("options.transform", "gradient", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 1 : 0);
368     SPDesktop *desktop = (SPDesktop *)data;
369     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
370         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)."));
371     } else {
372         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>gradients</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
373     }
376 static void toggle_pattern (GtkWidget *button, gpointer data) {
377     prefs_set_int_attribute ("options.transform", "pattern", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? 1 : 0);
378     SPDesktop *desktop = (SPDesktop *)data;
379     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
380         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)."));
381     } else {
382         desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Now <b>patterns</b> remain <b>fixed</b> when objects are transformed (moved, scaled, rotated, or skewed)."));
383     }
386 static void toggle_lock (GtkWidget *button, gpointer data) {
388     GtkWidget *old_child = gtk_bin_get_child(GTK_BIN(button));
389     gtk_container_remove (GTK_CONTAINER(button), old_child);
391     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
392         GtkWidget *child = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "width_height_lock");
393         gtk_widget_show (child);
394         gtk_container_add (GTK_CONTAINER (button), child);
395     } else {
396         GtkWidget *child = sp_icon_new (Inkscape::ICON_SIZE_DECORATION, "lock_unlocked");
397         gtk_widget_show (child);
398         gtk_container_add (GTK_CONTAINER (button), child);
399     }
402 GtkWidget *
403 sp_select_toolbox_new(SPDesktop *desktop)
405     Inkscape::UI::View::View *view = desktop;
407     GtkTooltips *tt = gtk_tooltips_new();
408     GtkWidget *tb = gtk_hbox_new(FALSE, 0);
410     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CCW), view, tt);
411     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_OBJECT_ROTATE_90_CW), view, tt);
412     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_HORIZONTAL), view, tt);
413     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_OBJECT_FLIP_VERTICAL), view, tt);
415     aux_toolbox_space(tb, AUX_BETWEEN_BUTTON_GROUPS);
417     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_SELECTION_TO_BACK), view, tt);
418     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_SELECTION_LOWER), view, tt);
419     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_SELECTION_RAISE), view, tt);
420     sp_toolbox_button_normal_new_from_verb(tb, Inkscape::ICON_SIZE_SMALL_TOOLBAR, Inkscape::Verb::get(SP_VERB_SELECTION_TO_FRONT), view, tt);
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     gtk_object_set_data(GTK_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);
432     gtk_object_set_data(GTK_OBJECT(spw), "frame", vb);
434     // Create the units menu.
435     GtkWidget *us = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
436     sp_unit_selector_setsize(us, AUX_OPTION_MENU_WIDTH, AUX_OPTION_MENU_HEIGHT);
437     sp_unit_selector_add_unit(SP_UNIT_SELECTOR(us), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0);
438     sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us), sp_desktop_namedview(desktop)->doc_units);
439     g_signal_connect(G_OBJECT(us), "set_unit", G_CALLBACK(aux_set_unit), spw);
441     // four spinbuttons
443     gtk_container_add(GTK_CONTAINER(vb),
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                       sp_select_toolbox_spinbutton(_("select_toolbar|X"), "X", -1e6, us, spw, _("Horizontal coordinate of selection"), TRUE));
447     aux_toolbox_space(vb, AUX_BETWEEN_SPINBUTTONS);
448     gtk_container_add(GTK_CONTAINER(vb),
449                       //TRANSLATORS: only translate "string" in "context|string". 
450                       // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
451                       sp_select_toolbox_spinbutton(_("select_toolbar|Y"), "Y", -1e6, us, spw, _("Vertical coordinate of selection"), FALSE));
452     aux_toolbox_space(vb, AUX_BETWEEN_BUTTON_GROUPS);
454     gtk_container_add(GTK_CONTAINER(vb),
455                       //TRANSLATORS: only translate "string" in "context|string". 
456                       // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
457                       sp_select_toolbox_spinbutton(_("select_toolbar|W"), "width", 1e-3, us, spw, _("Width of selection"), FALSE));
459     // lock toggle
460     GtkWidget *lockbox = gtk_vbox_new(TRUE, 0);
461     GtkWidget *lock = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
462                                               SP_BUTTON_TYPE_TOGGLE,
463                                               NULL,
464                                               "lock_unlocked",
465                                               _("When locked, change both width and height by the same proportion"),
466                                               tt);
467     gtk_box_pack_start(GTK_BOX(lockbox), lock, TRUE, FALSE, 0);
468     gtk_box_pack_start(GTK_BOX(vb), lockbox, FALSE, FALSE, 0);
469     gtk_object_set_data(GTK_OBJECT(spw), "lock", lock);
470     g_signal_connect_after (G_OBJECT (lock), "clicked", G_CALLBACK (toggle_lock), desktop);
472     gtk_container_add(GTK_CONTAINER(vb),
473                       //TRANSLATORS: only translate "string" in "context|string". 
474                       // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
475                       sp_select_toolbox_spinbutton(_("select_toolbar|H"), "height", 1e-3, us, spw, _("Height of selection"), FALSE));
477     aux_toolbox_space(vb, 2);
479     // Add the units menu.
480     gtk_widget_show(us);
481     gtk_container_add(GTK_CONTAINER(vb), us);
482     gtk_object_set_data(GTK_OBJECT(spw), "units", us);
484     // Set font size.
485     sp_set_font_size_smaller (vb);
487     // Force update when selection changes.
488     gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_modify_selection), desktop);
489     gtk_signal_connect(GTK_OBJECT(spw), "change_selection", GTK_SIGNAL_FUNC(sp_selection_layout_widget_change_selection), desktop);
491     // Update now.
492     sp_selection_layout_widget_update(SP_WIDGET(spw), SP_ACTIVE_DESKTOP ? sp_desktop_selection(SP_ACTIVE_DESKTOP) : NULL);
494     // Insert spw into the toolbar.
495     gtk_box_pack_start(GTK_BOX(tb), spw, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
497     aux_toolbox_space(tb, AUX_BETWEEN_BUTTON_GROUPS);
499     // "Transform with object" buttons
501     GtkWidget *cvbox = gtk_vbox_new (FALSE, 0);
502     GtkWidget *cbox = gtk_hbox_new (FALSE, 0);
504     {
505     GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
506                                               SP_BUTTON_TYPE_TOGGLE,
507                                               NULL,
508                                               "transform_stroke",
509                                               _("When scaling objects, scale the stroke width by the same proportion"),
510                                               tt);
511     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("options.transform", "stroke", 1));
512     g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (toggle_stroke), desktop);
513     gtk_box_pack_start(GTK_BOX(cbox), button, FALSE, FALSE, 0);
514     }
516     {
517     GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
518                                               SP_BUTTON_TYPE_TOGGLE,
519                                               NULL,
520                                               "transform_corners",
521                                               _("When scaling rectangles, scale the radii of rounded corners"),
522                                               tt);
523     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("options.transform", "rectcorners", 1));
524     g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (toggle_corners), desktop);
525     gtk_box_pack_start(GTK_BOX(cbox), button, FALSE, FALSE, 0);
526     }
528     {
529     GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
530                                               SP_BUTTON_TYPE_TOGGLE,
531                                               NULL,
532                                               "transform_gradient",
533                                               _("Transform gradients (in fill or stroke) along with the objects"),
534                                               tt);
535     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("options.transform", "gradient", 1));
536     g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (toggle_gradient), desktop);
537     gtk_box_pack_start(GTK_BOX(cbox), button, FALSE, FALSE, 0);
538     }
540     {
541     GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
542                                               SP_BUTTON_TYPE_TOGGLE,
543                                               NULL,
544                                               "transform_pattern",
545                                               _("Transform patterns (in fill or stroke) along with the objects"),
546                                               tt);
547     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("options.transform", "pattern", 1));
548     g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (toggle_pattern), desktop);
549     gtk_box_pack_start(GTK_BOX(cbox), button, FALSE, FALSE, 0);
550     }
552     gtk_box_pack_start(GTK_BOX(cvbox), cbox, TRUE, FALSE, 0);
553     gtk_box_pack_start(GTK_BOX(tb), cvbox, FALSE, FALSE, 0);
555     gtk_widget_show_all(tb);
557     return tb;
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 :