Code

naming: avoid unintentional double-meanings (part 2)
[inkscape.git] / src / widgets / toolbox.cpp
1 #define __SP_MAINTOOLBOX_C__
3 /** \file
4  * Controls bars for some of Inkscape's tools
5  * (for some tools, they are in their own files)
6  */
8 /*
9 *
10 * Authors:
11 *   MenTaLguY <mental@rydia.net>
12 *   Lauris Kaplinski <lauris@kaplinski.com>
13 *   bulia byak <buliabyak@users.sf.net>
14 *   Frank Felfe <innerspace@iname.com>
15 *   John Cliff <simarilius@yahoo.com>
16 *   David Turner <novalis@gnu.org>
17 *   Josh Andler <scislac@scislac.com>
18 *   Jon A. Cruz <jon@joncruz.org>
19 *
20 * Copyright (C) 2004 David Turner
21 * Copyright (C) 2003 MenTaLguY
22 * Copyright (C) 1999-2006 authors
23 * Copyright (C) 2001-2002 Ximian, Inc.
24 *
25 * Released under GNU GPL, read the file 'COPYING' for more information
26 */
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <gtkmm.h>
33 #include <gtk/gtk.h>
34 #include <iostream>
35 #include <sstream>
37 #include "widgets/button.h"
38 #include "widgets/widget-sizes.h"
39 #include "widgets/spw-utilities.h"
40 #include "widgets/spinbutton-events.h"
41 #include "dialogs/text-edit.h"
43 #include "ui/widget/style-swatch.h"
45 #include "prefs-utils.h"
46 #include "verbs.h"
47 #include "sp-namedview.h"
48 #include "desktop.h"
49 #include "desktop-handles.h"
50 #include "xml/repr.h"
51 #include "xml/node-event-vector.h"
52 #include <glibmm/i18n.h>
53 #include "helper/unit-menu.h"
54 #include "helper/units.h"
56 #include "inkscape.h"
57 #include "conn-avoid-ref.h"
60 #include "select-toolbar.h"
61 #include "gradient-toolbar.h"
63 #include "connector-context.h"
64 #include "node-context.h"
65 #include "shape-editor.h"
66 #include "sp-rect.h"
67 #include "box3d.h"
68 #include "box3d-context.h"
69 #include "sp-star.h"
70 #include "sp-spiral.h"
71 #include "sp-ellipse.h"
72 #include "sp-text.h"
73 #include "sp-flowtext.h"
74 #include "style.h"
75 #include "selection.h"
76 #include "document-private.h"
77 #include "desktop-style.h"
78 #include "../libnrtype/font-lister.h"
79 #include "../connection-pool.h"
80 #include "../prefs-utils.h"
81 #include "../inkscape-stock.h"
82 #include "icon.h"
83 #include "graphlayout/graphlayout.h"
85 #include "mod360.h"
87 #include "toolbox.h"
89 #include "flood-context.h"
91 #include "ink-action.h"
92 #include "ege-adjustment-action.h"
93 #include "ege-output-action.h"
94 #include "ege-select-one-action.h"
95 #include "helper/unit-tracker.h"
97 using Inkscape::UnitTracker;
99 typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop);
100 typedef void (*UpdateFunction)(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
102 static void       sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
103 static void       sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
104 static void       sp_zoom_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
105 static void       sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
106 static void       sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
107 static void       sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
108 static void       sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
109 static void       sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
110 static void       sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
111 static void       sp_pen_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
112 static void       sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
113 static void       sp_dropper_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
114 static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop);
115 static void       sp_connector_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
116 static void       sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
118 namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); }
121 static struct {
122     gchar const *type_name;
123     gchar const *data_name;
124     sp_verb_t verb;
125     sp_verb_t doubleclick_verb;
126 } const tools[] = {
127     { "SPSelectContext",   "select_tool",    SP_VERB_CONTEXT_SELECT,  SP_VERB_CONTEXT_SELECT_PREFS},
128     { "SPNodeContext",     "node_tool",      SP_VERB_CONTEXT_NODE, SP_VERB_CONTEXT_NODE_PREFS },
129     { "SPTweakContext",    "tweak_tool",     SP_VERB_CONTEXT_TWEAK, SP_VERB_CONTEXT_TWEAK_PREFS },
130     { "SPZoomContext",     "zoom_tool",      SP_VERB_CONTEXT_ZOOM, SP_VERB_CONTEXT_ZOOM_PREFS },
131     { "SPRectContext",     "rect_tool",      SP_VERB_CONTEXT_RECT, SP_VERB_CONTEXT_RECT_PREFS },
132 //    { "SP3DBoxContext",    "3dbox_tool",     SP_VERB_CONTEXT_3DBOX, SP_VERB_CONTEXT_3DBOX_PREFS },
133     { "SPArcContext",      "arc_tool",       SP_VERB_CONTEXT_ARC, SP_VERB_CONTEXT_ARC_PREFS },
134     { "SPStarContext",     "star_tool",      SP_VERB_CONTEXT_STAR, SP_VERB_CONTEXT_STAR_PREFS },
135     { "SPSpiralContext",   "spiral_tool",    SP_VERB_CONTEXT_SPIRAL, SP_VERB_CONTEXT_SPIRAL_PREFS },
136     { "SPPencilContext",   "pencil_tool",    SP_VERB_CONTEXT_PENCIL, SP_VERB_CONTEXT_PENCIL_PREFS },
137     { "SPPenContext",      "pen_tool",       SP_VERB_CONTEXT_PEN, SP_VERB_CONTEXT_PEN_PREFS },
138     { "SPDynaDrawContext", "dyna_draw_tool", SP_VERB_CONTEXT_CALLIGRAPHIC, SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS },
139     { "SPFloodContext",    "paintbucket_tool",     SP_VERB_CONTEXT_PAINTBUCKET, SP_VERB_CONTEXT_PAINTBUCKET_PREFS },
140     { "SPTextContext",     "text_tool",      SP_VERB_CONTEXT_TEXT, SP_VERB_CONTEXT_TEXT_PREFS },
141     { "SPConnectorContext","connector_tool", SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_CONNECTOR_PREFS },
142     { "SPGradientContext", "gradient_tool",  SP_VERB_CONTEXT_GRADIENT, SP_VERB_CONTEXT_GRADIENT_PREFS },
143     { "SPDropperContext",  "dropper_tool",   SP_VERB_CONTEXT_DROPPER, SP_VERB_CONTEXT_DROPPER_PREFS },
144     { NULL, NULL, 0, 0 }
145 };
147 static struct {
148     gchar const *type_name;
149     gchar const *data_name;
150     GtkWidget *(*create_func)(SPDesktop *desktop);
151     void (*prep_func)(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
152     gchar const *ui_name;
153     gint swatch_verb_id;
154     gchar const *swatch_tool;
155     gchar const *swatch_tip;
156 } const aux_toolboxes[] = {
157     { "SPSelectContext", "select_toolbox", 0, sp_select_toolbox_prep,            "SelectToolbar",
158       SP_VERB_INVALID, 0, 0},
159     { "SPNodeContext",   "node_toolbox",   0, sp_node_toolbox_prep,              "NodeToolbar",
160       SP_VERB_INVALID, 0, 0},
161     { "SPTweakContext",   "tweak_toolbox",   0, sp_tweak_toolbox_prep,              "TweakToolbar",
162       SP_VERB_INVALID, 0, 0},
163     { "SPZoomContext",   "zoom_toolbox",   0, sp_zoom_toolbox_prep,              "ZoomToolbar",
164       SP_VERB_INVALID, 0, 0},
165     { "SPStarContext",   "star_toolbox",   0, sp_star_toolbox_prep,              "StarToolbar",
166       SP_VERB_CONTEXT_STAR_PREFS,   "tools.shapes.star",     _("Style of new stars")},
167     { "SPRectContext",   "rect_toolbox",   0, sp_rect_toolbox_prep,              "RectToolbar",
168       SP_VERB_CONTEXT_RECT_PREFS,   "tools.shapes.rect",     _("Style of new rectangles")},
169     { "SP3DBoxContext",  "3dbox_toolbox",  0, sp_3dbox_toolbox_prep,             "3DBoxToolbar",
170       SP_VERB_CONTEXT_3DBOX_PREFS,  "tools.shapes.3dbox",    _("Style of new 3D boxes")},
171     { "SPArcContext",    "arc_toolbox",    0, sp_arc_toolbox_prep,               "ArcToolbar",
172       SP_VERB_CONTEXT_ARC_PREFS,    "tools.shapes.arc",      _("Style of new ellipses")},
173     { "SPSpiralContext", "spiral_toolbox", 0, sp_spiral_toolbox_prep,            "SpiralToolbar",
174       SP_VERB_CONTEXT_SPIRAL_PREFS, "tools.shapes.spiral",   _("Style of new spirals")},
175     { "SPPencilContext", "pencil_toolbox", 0, sp_pencil_toolbox_prep,            "PencilToolbar",
176       SP_VERB_CONTEXT_PENCIL_PREFS, "tools.freehand.pencil", _("Style of new paths created by Pencil")},
177     { "SPPenContext", "pen_toolbox", 0, sp_pen_toolbox_prep,                     "PenToolbar",
178       SP_VERB_CONTEXT_PEN_PREFS,    "tools.freehand.pen",    _("Style of new paths created by Pen")},
179     { "SPDynaDrawContext", "calligraphy_toolbox", 0, sp_calligraphy_toolbox_prep,"CalligraphyToolbar",
180       SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "tools.calligraphic", _("Style of new calligraphic strokes")},
181     { "SPTextContext",   "text_toolbox",   sp_text_toolbox_new, 0,               0,
182       SP_VERB_INVALID, 0, 0},
183     { "SPDropperContext", "dropper_toolbox", 0, sp_dropper_toolbox_prep,         "DropperToolbar",
184       SP_VERB_INVALID, 0, 0},
185     { "SPGradientContext", "gradient_toolbox", sp_gradient_toolbox_new, 0,       0,
186       SP_VERB_INVALID, 0, 0},
187     { "SPConnectorContext", "connector_toolbox", 0, sp_connector_toolbox_prep,   "ConnectorToolbar",
188       SP_VERB_INVALID, 0, 0},
189     { "SPFloodContext",  "paintbucket_toolbox",  0, sp_paintbucket_toolbox_prep, "PaintbucketToolbar",
190       SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "tools.paintbucket", _("Style of Paint Bucket fill objects")},
191     { NULL, NULL, NULL, NULL, NULL, SP_VERB_INVALID, NULL, NULL }
192 };
195 static gchar const * ui_descr =
196         "<ui>"
197         "  <toolbar name='SelectToolbar'>"
198         "    <toolitem action='ObjectRotate90CCW' />"
199         "    <toolitem action='ObjectRotate90' />"
200         "    <toolitem action='ObjectFlipHorizontally' />"
201         "    <toolitem action='ObjectFlipVertically' />"
202         "    <separator />"
203         "    <toolitem action='SelectionToBack' />"
204         "    <toolitem action='SelectionLower' />"
205         "    <toolitem action='SelectionRaise' />"
206         "    <toolitem action='SelectionToFront' />"
207         "    <separator />"
208         "    <toolitem action='XAction' />"
209         "    <toolitem action='YAction' />"
210         "    <toolitem action='WidthAction' />"
211         "    <toolitem action='LockAction' />"
212         "    <toolitem action='HeightAction' />"
213         "    <toolitem action='UnitsAction' />"
214         "    <separator />"
215         "    <toolitem action='transform_stroke' />"
216         "    <toolitem action='transform_corners' />"
217         "    <toolitem action='transform_gradient' />"
218         "    <toolitem action='transform_pattern' />"
219         "  </toolbar>"
221         "  <toolbar name='NodeToolbar'>"
222         "    <toolitem action='NodeInsertAction' />"
223         "    <toolitem action='NodeDeleteAction' />"
224         "    <separator />"
225         "    <toolitem action='NodeJoinAction' />"
226         "    <toolitem action='NodeJoinSegmentAction' />"
227         "    <toolitem action='NodeDeleteSegmentAction' />"
228         "    <toolitem action='NodeBreakAction' />"
229         "    <separator />"
230         "    <toolitem action='NodeCuspAction' />"
231         "    <toolitem action='NodeSmoothAction' />"
232         "    <toolitem action='NodeSymmetricAction' />"
233         "    <separator />"
234         "    <toolitem action='NodeLineAction' />"
235         "    <toolitem action='NodeCurveAction' />"
236         "    <separator />"
237         "    <toolitem action='ObjectToPath' />"
238         "    <toolitem action='StrokeToPath' />"
239         "    <separator />"
240         "    <toolitem action='NodesShowHandlesAction' />"
241         "  </toolbar>"
243         "  <toolbar name='TweakToolbar'>"
244         "    <toolitem action='TweakWidthAction' />"
245         "    <toolitem action='TweakForceAction' />"
246         "    <separator />"
247         "    <toolitem action='TweakModeAction' />"
248         "    <separator />"
249         "    <toolitem action='TweakFidelityAction' />"
250         "    <toolitem action='TweakPressureAction' />"
251         "  </toolbar>"
253         "  <toolbar name='ZoomToolbar'>"
254         "    <toolitem action='ZoomIn' />"
255         "    <toolitem action='ZoomOut' />"
256         "    <separator />"
257         "    <toolitem action='ZoomSelection' />"
258         "    <toolitem action='ZoomDrawing' />"
259         "    <toolitem action='ZoomPage' />"
260         "    <toolitem action='ZoomPageWidth' />"
261         "    <separator />"
262         "    <toolitem action='ZoomPrev' />"
263         "    <toolitem action='ZoomNext' />"
264         "    <separator />"
265         "    <toolitem action='Zoom1:0' />"
266         "    <toolitem action='Zoom1:2' />"
267         "    <toolitem action='Zoom2:1' />"
268         "  </toolbar>"
270         "  <toolbar name='StarToolbar'>"
271         "    <separator />"
272         "    <toolitem action='StarStateAction' />"
273         "    <separator />"
274         "    <toolitem action='FlatAction' />"
275         "    <separator />"
276         "    <toolitem action='MagnitudeAction' />"
277         "    <toolitem action='SpokeAction' />"
278         "    <toolitem action='RoundednessAction' />"
279         "    <toolitem action='RandomizationAction' />"
280         "    <separator />"
281         "    <toolitem action='StarResetAction' />"
282         "  </toolbar>"
284         "  <toolbar name='RectToolbar'>"
285         "    <toolitem action='RectStateAction' />"
286         "    <toolitem action='RectWidthAction' />"
287         "    <toolitem action='RectHeightAction' />"
288         "    <toolitem action='RadiusXAction' />"
289         "    <toolitem action='RadiusYAction' />"
290         "    <toolitem action='RectUnitsAction' />"
291         "    <separator />"
292         "    <toolitem action='RectResetAction' />"
293         "  </toolbar>"
295         "  <toolbar name='3DBoxToolbar'>"
296         "    <toolitem action='3DBoxVPXAction' />"
297         "    <toolitem action='3DBoxVPYAction' />"
298         "    <toolitem action='3DBoxVPZAction' />"
299         "    <separator />"
300         "  </toolbar>"
302         "  <toolbar name='SpiralToolbar'>"
303         "    <toolitem action='SpiralStateAction' />"
304         "    <toolitem action='SpiralRevolutionAction' />"
305         "    <toolitem action='SpiralExpansionAction' />"
306         "    <toolitem action='SpiralT0Action' />"
307         "    <separator />"
308         "    <toolitem action='SpiralResetAction' />"
309         "  </toolbar>"
311         "  <toolbar name='PenToolbar'>"
312         "  </toolbar>"
314         "  <toolbar name='PencilToolbar'>"
315         "  </toolbar>"
317         "  <toolbar name='CalligraphyToolbar'>"
318         "    <separator />"
319         "    <toolitem action='CalligraphyWidthAction' />"
320         "    <toolitem action='ThinningAction' />"
321         "    <separator />"
322         "    <toolitem action='AngleAction' />"
323         "    <toolitem action='FixationAction' />"
324         "    <toolitem action='CapRoundingAction' />"
325         "    <separator />"
326         "    <toolitem action='TremorAction' />"
327         "    <toolitem action='WiggleAction' />"
328         "    <toolitem action='MassAction' />"
329         "    <separator />"
330         "    <toolitem action='TraceAction' />"
331         "    <toolitem action='PressureAction' />"
332         "    <toolitem action='TiltAction' />"
333         "    <toolitem action='CalligraphyResetAction' />"
334         "  </toolbar>"
336         "  <toolbar name='ArcToolbar'>"
337         "    <toolitem action='ArcStateAction' />"
338         "    <separator />"
339         "    <toolitem action='ArcStartAction' />"
340         "    <toolitem action='ArcEndAction' />"
341         "    <separator />"
342         "    <toolitem action='ArcOpenAction' />"
343         "    <separator />"
344         "    <toolitem action='ArcResetAction' />"
345         "    <separator />"
346         "  </toolbar>"
348         "  <toolbar name='PaintbucketToolbar'>"
349         "    <toolitem action='ChannelsAction' />"
350         "    <separator />"
351         "    <toolitem action='ThresholdAction' />"
352         "    <separator />"
353         "    <toolitem action='OffsetAction' />"
354         "    <toolitem action='PaintbucketUnitsAction' />"
355         "    <separator />"
356         "    <toolitem action='AutoGapAction' />"
357         "    <separator />"
358         "    <toolitem action='PaintbucketResetAction' />"
359         "  </toolbar>"
361         "  <toolbar name='DropperToolbar'>"
362         "    <toolitem action='DropperPickAlphaAction' />"
363         "    <toolitem action='DropperSetAlphaAction' />"
364         "  </toolbar>"
366         "  <toolbar name='ConnectorToolbar'>"
367         "    <toolitem action='ConnectorAvoidAction' />"
368         "    <toolitem action='ConnectorIgnoreAction' />"
369         "    <toolitem action='ConnectorSpacingAction' />"
370         "    <toolitem action='ConnectorGraphAction' />"
371         "    <toolitem action='ConnectorLengthAction' />"
372         "    <toolitem action='ConnectorDirectedAction' />"
373         "    <toolitem action='ConnectorOverlapAction' />"
374         "  </toolbar>"
376         "</ui>"
379 static GtkActionGroup* create_or_fetch_actions( SPDesktop* desktop );
381 static void toolbox_set_desktop (GtkWidget *toolbox, SPDesktop *desktop, SetupFunction setup_func, UpdateFunction update_func, sigc::connection*);
383 static void setup_tool_toolbox (GtkWidget *toolbox, SPDesktop *desktop);
384 static void update_tool_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
386 static void setup_aux_toolbox (GtkWidget *toolbox, SPDesktop *desktop);
387 static void update_aux_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
389 static void setup_commands_toolbox (GtkWidget *toolbox, SPDesktop *desktop);
390 static void update_commands_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
392 /* Global text entry widgets necessary for update */
393 /* GtkWidget *dropper_rgb_entry,
394           *dropper_opacity_entry ; */
395 // should be made a private member once this is converted to class
397 static void delete_connection(GObject *obj, sigc::connection *connection) {
398     connection->disconnect();
399     delete connection;
402 static void purge_repr_listener( GObject* obj, GObject* tbl )
404     (void)obj;
405     Inkscape::XML::Node* oldrepr = reinterpret_cast<Inkscape::XML::Node *>( g_object_get_data( tbl, "repr" ) );
406     if (oldrepr) { // remove old listener
407         sp_repr_remove_listener_by_data(oldrepr, tbl);
408         Inkscape::GC::release(oldrepr);
409         oldrepr = 0;
410         g_object_set_data( tbl, "repr", NULL );
411     }
414 GtkWidget *
415 sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type,
416                                                  Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
417                                                  Inkscape::UI::View::View *view, GtkTooltips *tt)
419     SPAction *action = verb->get_action(view);
420     if (!action) return NULL;
422     SPAction *doubleclick_action;
423     if (doubleclick_verb)
424         doubleclick_action = doubleclick_verb->get_action(view);
425     else
426         doubleclick_action = NULL;
428     /* fixme: Handle sensitive/unsensitive */
429     /* fixme: Implement sp_button_new_from_action */
430     GtkWidget *b = sp_button_new(size, type, action, doubleclick_action, tt);
431     gtk_widget_show(b);
432     gtk_box_pack_start(GTK_BOX(t), b, FALSE, FALSE, 0);
434     return b;
437 GtkWidget *sp_toolbox_button_new_from_verb(GtkWidget *t, Inkscape::IconSize size, SPButtonType type, Inkscape::Verb *verb,
438                                            Inkscape::UI::View::View *view, GtkTooltips *tt)
440     return sp_toolbox_button_new_from_verb_with_doubleclick(t, size, type, verb, NULL, view, tt);
443 GtkWidget * sp_toolbox_button_normal_new_from_verb(GtkWidget *t, Inkscape::IconSize size, Inkscape::Verb *verb,
444                                                    Inkscape::UI::View::View *view, GtkTooltips *tt)
446     return sp_toolbox_button_new_from_verb(t, size, SP_BUTTON_TYPE_NORMAL, verb, view, tt);
450 static void trigger_sp_action( GtkAction* act, gpointer user_data )
452     SPAction* targetAction = SP_ACTION(user_data);
453     if ( targetAction ) {
454         sp_action_perform( targetAction, NULL );
455     }
458 static void sp_action_action_set_sensitive (SPAction *action, unsigned int sensitive, void *data)
460     if ( data ) {
461         GtkAction* act = GTK_ACTION(data);
462         gtk_action_set_sensitive( act, sensitive );
463     }
466 static SPActionEventVector action_event_vector = {
467     {NULL},
468     NULL,
469     NULL,
470     sp_action_action_set_sensitive,
471     NULL,
472     NULL
473 };
475 static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size )
477     GtkAction* act = 0;
479     SPAction* targetAction = verb->get_action(view);
480     InkAction* inky = ink_action_new( verb->get_id(), verb->get_name(), verb->get_tip(), verb->get_image(), size  );
481     act = GTK_ACTION(inky);
482     gtk_action_set_sensitive( act, targetAction->sensitive );
484     g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
486     SPAction*rebound = dynamic_cast<SPAction *>( nr_object_ref( dynamic_cast<NRObject *>(targetAction) ) );
487     nr_active_object_add_listener( (NRActiveObject *)rebound, (NRObjectEventVector *)&action_event_vector, sizeof(SPActionEventVector), inky );
489     return act;
492 GtkActionGroup* create_or_fetch_actions( SPDesktop* desktop )
494     Inkscape::UI::View::View *view = desktop;
495     gint verbsToUse[] = {
496         // disabled until we have icons for them:
497         //find
498         //SP_VERB_EDIT_TILE,
499         //SP_VERB_EDIT_UNTILE,
500         SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
501         SP_VERB_DIALOG_DISPLAY,
502         SP_VERB_DIALOG_FILL_STROKE,
503         SP_VERB_DIALOG_NAMEDVIEW,
504         SP_VERB_DIALOG_TEXT,
505         SP_VERB_DIALOG_XML_EDITOR,
506         SP_VERB_EDIT_CLONE,
507         SP_VERB_EDIT_COPY,
508         SP_VERB_EDIT_CUT,
509         SP_VERB_EDIT_DUPLICATE,
510         SP_VERB_EDIT_PASTE,
511         SP_VERB_EDIT_REDO,
512         SP_VERB_EDIT_UNDO,
513         SP_VERB_EDIT_UNLINK_CLONE,
514         SP_VERB_FILE_EXPORT,
515         SP_VERB_FILE_IMPORT,
516         SP_VERB_FILE_NEW,
517         SP_VERB_FILE_OPEN,
518         SP_VERB_FILE_PRINT,
519         SP_VERB_FILE_SAVE,
520         SP_VERB_OBJECT_TO_CURVE,
521         SP_VERB_SELECTION_GROUP,
522         SP_VERB_SELECTION_OUTLINE,
523         SP_VERB_SELECTION_UNGROUP,
524         SP_VERB_ZOOM_1_1,
525         SP_VERB_ZOOM_1_2,
526         SP_VERB_ZOOM_2_1,
527         SP_VERB_ZOOM_DRAWING,
528         SP_VERB_ZOOM_IN,
529         SP_VERB_ZOOM_NEXT,
530         SP_VERB_ZOOM_OUT,
531         SP_VERB_ZOOM_PAGE,
532         SP_VERB_ZOOM_PAGE_WIDTH,
533         SP_VERB_ZOOM_PREV,
534         SP_VERB_ZOOM_SELECTION,
535     };
537     gint shrinkTop = prefs_get_int_attribute_limited( "toolbox", "small", 1, 0, 1 );
538     Inkscape::IconSize toolboxSize = shrinkTop ? Inkscape::ICON_SIZE_SMALL_TOOLBAR : Inkscape::ICON_SIZE_LARGE_TOOLBAR;
540     static std::map<SPDesktop*, GtkActionGroup*> groups;
541     GtkActionGroup* mainActions = 0;
542     if ( groups.find(desktop) != groups.end() ) {
543         mainActions = groups[desktop];
544     }
546     if ( !mainActions ) {
547         mainActions = gtk_action_group_new("main");
548         groups[desktop] = mainActions;
549     }
551     for ( guint i = 0; i < G_N_ELEMENTS(verbsToUse); i++ ) {
552         Inkscape::Verb* verb = Inkscape::Verb::get(verbsToUse[i]);
553         if ( verb ) {
554             if ( !gtk_action_group_get_action( mainActions, verb->get_id() ) ) {
555                 GtkAction* act = create_action_for_verb( verb, view, toolboxSize );
556                 gtk_action_group_add_action( mainActions, act );
557             }
558         }
559     }
561     return mainActions;
565 GtkWidget *
566 sp_tool_toolbox_new()
568     GtkTooltips *tt = gtk_tooltips_new();
569     GtkWidget *tb = gtk_vbox_new(FALSE, 0);
571     g_object_set_data(G_OBJECT(tb), "desktop", NULL);
572     g_object_set_data(G_OBJECT(tb), "tooltips", tt);
574     gtk_widget_set_sensitive(tb, FALSE);
576     GtkWidget *hb = gtk_handle_box_new();
577     gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(hb), GTK_POS_TOP);
578     gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(hb), GTK_SHADOW_OUT);
579     gtk_handle_box_set_snap_edge(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
581     gtk_container_add(GTK_CONTAINER(hb), tb);
582     gtk_widget_show(GTK_WIDGET(tb));
584     sigc::connection* conn = new sigc::connection;
585     g_object_set_data(G_OBJECT(hb), "event_context_connection", conn);
587     return hb;
590 static void
591 aux_toolbox_attached(GtkHandleBox *toolbox, GtkWidget *child)
593     g_object_set_data(G_OBJECT(child), "is_detached", GINT_TO_POINTER(FALSE));
594     gtk_widget_queue_resize(child);
597 static void
598 aux_toolbox_detached(GtkHandleBox *toolbox, GtkWidget *child)
600     g_object_set_data(G_OBJECT(child), "is_detached", GINT_TO_POINTER(TRUE));
601     gtk_widget_queue_resize(child);
604 GtkWidget *
605 sp_aux_toolbox_new()
607     GtkWidget *tb = gtk_vbox_new(FALSE, 0);
609     GtkWidget *tb_s = gtk_vbox_new(FALSE, 0);
610     GtkWidget *tb_e = gtk_vbox_new(FALSE, 0);
611     gtk_box_set_spacing(GTK_BOX(tb), AUX_SPACING);
612     gtk_box_pack_start(GTK_BOX(tb), GTK_WIDGET(tb_s), FALSE, FALSE, 0);
613     gtk_box_pack_end(GTK_BOX(tb), GTK_WIDGET(tb_e), FALSE, FALSE, 0);
615     g_object_set_data(G_OBJECT(tb), "desktop", NULL);
616     g_object_set_data(G_OBJECT(tb), "top_spacer", tb_s);
618     gtk_widget_set_sensitive(tb, FALSE);
620     GtkWidget *hb = gtk_handle_box_new();
621     gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
622     gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(hb), GTK_SHADOW_OUT);
623     gtk_handle_box_set_snap_edge(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
625     g_signal_connect(G_OBJECT(hb), "child_attached", G_CALLBACK(aux_toolbox_attached), (gpointer)tb);
626     g_signal_connect(G_OBJECT(hb), "child_detached", G_CALLBACK(aux_toolbox_detached), (gpointer)tb);
628     gtk_container_add(GTK_CONTAINER(hb), tb);
629     gtk_widget_show(GTK_WIDGET(tb));
631     sigc::connection* conn = new sigc::connection;
632     g_object_set_data(G_OBJECT(hb), "event_context_connection", conn);
634     return hb;
637 //####################################
638 //# Commands Bar
639 //####################################
641 GtkWidget *
642 sp_commands_toolbox_new()
644     GtkWidget *tb = gtk_vbox_new(FALSE, 0);
646     GtkWidget *tb_s = gtk_vbox_new(FALSE, 0);
647     GtkWidget *tb_e = gtk_vbox_new(FALSE, 0);
648     gtk_box_set_spacing(GTK_BOX(tb), AUX_SPACING);
649     gtk_box_pack_start(GTK_BOX(tb), GTK_WIDGET(tb_s), FALSE, FALSE, 0);
650     gtk_box_pack_end(GTK_BOX(tb), GTK_WIDGET(tb_e), FALSE, FALSE, 0);
652     g_object_set_data(G_OBJECT(tb), "desktop", NULL);
653     gtk_widget_set_sensitive(tb, FALSE);
655     GtkWidget *hb = gtk_handle_box_new();
656     gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
657     gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(hb), GTK_SHADOW_OUT);
658     gtk_handle_box_set_snap_edge(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
660     g_signal_connect(G_OBJECT(hb), "child_attached", G_CALLBACK(aux_toolbox_attached), (gpointer)tb);
661     g_signal_connect(G_OBJECT(hb), "child_detached", G_CALLBACK(aux_toolbox_detached), (gpointer)tb);
663     gtk_container_add(GTK_CONTAINER(hb), tb);
664     gtk_widget_show(GTK_WIDGET(tb));
666     sigc::connection* conn = new sigc::connection;
667     g_object_set_data(G_OBJECT(hb), "event_context_connection", conn);
669     return hb;
673 //####################################
674 //# node editing callbacks
675 //####################################
677 /**
678  * FIXME: Returns current shape_editor in context. // later eliminate this function at all!
679  */
680 static ShapeEditor *get_current_shape_editor()
682     if (!SP_ACTIVE_DESKTOP) {
683         return NULL;
684     }
686     SPEventContext *event_context = (SP_ACTIVE_DESKTOP)->event_context;
688     if (!SP_IS_NODE_CONTEXT(event_context)) {
689         return NULL;
690     }
692     return SP_NODE_CONTEXT(event_context)->shape_editor;
696 void
697 sp_node_path_edit_add(void)
699     ShapeEditor *shape_editor = get_current_shape_editor();
700     if (shape_editor) shape_editor->add_node();
703 void
704 sp_node_path_edit_delete(void)
706     ShapeEditor *shape_editor = get_current_shape_editor();
707     if (shape_editor) shape_editor->delete_nodes();
710 void
711 sp_node_path_edit_delete_segment(void)
713     ShapeEditor *shape_editor = get_current_shape_editor();
714     if (shape_editor) shape_editor->delete_segment();
717 void
718 sp_node_path_edit_break(void)
720     ShapeEditor *shape_editor = get_current_shape_editor();
721     if (shape_editor) shape_editor->break_at_nodes();
724 void
725 sp_node_path_edit_join(void)
727     ShapeEditor *shape_editor = get_current_shape_editor();
728     if (shape_editor) shape_editor->join_nodes();
731 void
732 sp_node_path_edit_join_segment(void)
734     ShapeEditor *shape_editor = get_current_shape_editor();
735     if (shape_editor) shape_editor->join_segments();
738 void
739 sp_node_path_edit_toline(void)
741     ShapeEditor *shape_editor = get_current_shape_editor();
742     if (shape_editor) shape_editor->set_type_of_segments(NR_LINETO);
745 void
746 sp_node_path_edit_tocurve(void)
748     ShapeEditor *shape_editor = get_current_shape_editor();
749     if (shape_editor) shape_editor->set_type_of_segments(NR_CURVETO);
752 void
753 sp_node_path_edit_cusp(void)
755     ShapeEditor *shape_editor = get_current_shape_editor();
756     if (shape_editor) shape_editor->set_node_type(Inkscape::NodePath::NODE_CUSP);
759 void
760 sp_node_path_edit_smooth(void)
762     ShapeEditor *shape_editor = get_current_shape_editor();
763     if (shape_editor) shape_editor->set_node_type(Inkscape::NodePath::NODE_SMOOTH);
766 void
767 sp_node_path_edit_symmetrical(void)
769     ShapeEditor *shape_editor = get_current_shape_editor();
770     if (shape_editor) shape_editor->set_node_type(Inkscape::NodePath::NODE_SYMM);
773 static void toggle_show_handles (GtkToggleAction *act, gpointer data) {
774     bool show = gtk_toggle_action_get_active( act );
775     prefs_set_int_attribute ("tools.nodes", "show_handles",  show ? 1 : 0);
776     ShapeEditor *shape_editor = get_current_shape_editor();
777     if (shape_editor) shape_editor->show_handles(show);
780 //################################
781 //##    Node Editing Toolbox    ##
782 //################################
784 static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
786     {
787         InkAction* inky = ink_action_new( "NodeInsertAction",
788                                           _("Insert"),
789                                           _("Insert new nodes into selected segments"),
790                                           "node_insert",
791                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
792         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_add), 0 );
793         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
794     }
796     {
797         InkAction* inky = ink_action_new( "NodeDeleteAction",
798                                           _("Delete"),
799                                           _("Delete selected nodes"),
800                                           "node_delete",
801                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
802         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_delete), 0 );
803         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
804     }
806     {
807         InkAction* inky = ink_action_new( "NodeJoinAction",
808                                           _("Join"),
809                                           _("Join selected endnodes"),
810                                           "node_join",
811                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
812         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_join), 0 );
813         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
814     }
816     {
817         InkAction* inky = ink_action_new( "NodeJoinSegmentAction",
818                                           _("Join Segment"),
819                                           _("Join selected endnodes with a new segment"),
820                                           "node_join_segment",
821                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
822         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_join_segment), 0 );
823         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
824     }
826     {
827         InkAction* inky = ink_action_new( "NodeDeleteSegmentAction",
828                                           _("Delete Segment"),
829                                           _("Split path between two non-endpoint nodes"),
830                                           "node_delete_segment",
831                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
832         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_delete_segment), 0 );
833         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
834     }
836     {
837         InkAction* inky = ink_action_new( "NodeBreakAction",
838                                           _("Node Break"),
839                                           _("Break path at selected nodes"),
840                                           "node_break",
841                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
842         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_break), 0 );
843         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
844     }
846     {
847         InkAction* inky = ink_action_new( "NodeCuspAction",
848                                           _("Node Cusp"),
849                                           _("Make selected nodes corner"),
850                                           "node_cusp",
851                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
852         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_cusp), 0 );
853         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
854     }
856     {
857         InkAction* inky = ink_action_new( "NodeSmoothAction",
858                                           _("Node Smooth"),
859                                           _("Make selected nodes smooth"),
860                                           "node_smooth",
861                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
862         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_smooth), 0 );
863         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
864     }
866     {
867         InkAction* inky = ink_action_new( "NodeSymmetricAction",
868                                           _("Node Symmetric"),
869                                           _("Make selected nodes symmetric"),
870                                           "node_symmetric",
871                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
872         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_symmetrical), 0 );
873         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
874     }
876     {
877         InkAction* inky = ink_action_new( "NodeLineAction",
878                                           _("Node Line"),
879                                           _("Make selected segments lines"),
880                                           "node_line",
881                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
882         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_toline), 0 );
883         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
884     }
886     {
887         InkAction* inky = ink_action_new( "NodeCurveAction",
888                                           _("Node Curve"),
889                                           _("Make selected segments curves"),
890                                           "node_curve",
891                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
892         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_tocurve), 0 );
893         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
894     }
896     {
897         InkToggleAction* act = ink_toggle_action_new( "NodesShowHandlesAction",
898                                                       _("Show Handles"),
899                                                       _("Show the Bezier handles of selected nodes"),
900                                                       "nodes_show_handles",
901                                                       Inkscape::ICON_SIZE_DECORATION );
902         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
903         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_handles), desktop );
904         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.nodes", "show_handles", 1 ) );
905     }
907 } // end of sp_node_toolbox_prep()
910 //########################
911 //##    Zoom Toolbox    ##
912 //########################
914 static void sp_zoom_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
916     // no custom GtkAction setup needed
917 } // end of sp_zoom_toolbox_prep()
919 void
920 sp_tool_toolbox_set_desktop(GtkWidget *toolbox, SPDesktop *desktop)
922     toolbox_set_desktop(gtk_bin_get_child(GTK_BIN(toolbox)), desktop, setup_tool_toolbox, update_tool_toolbox, static_cast<sigc::connection*>(g_object_get_data(G_OBJECT(toolbox), "event_context_connection")));
926 void
927 sp_aux_toolbox_set_desktop(GtkWidget *toolbox, SPDesktop *desktop)
929     toolbox_set_desktop(gtk_bin_get_child(GTK_BIN(toolbox)), desktop, setup_aux_toolbox, update_aux_toolbox, static_cast<sigc::connection*>(g_object_get_data(G_OBJECT(toolbox), "event_context_connection")));
932 void
933 sp_commands_toolbox_set_desktop(GtkWidget *toolbox, SPDesktop *desktop)
935     toolbox_set_desktop(gtk_bin_get_child(GTK_BIN(toolbox)), desktop, setup_commands_toolbox, update_commands_toolbox, static_cast<sigc::connection*>(g_object_get_data(G_OBJECT(toolbox), "event_context_connection")));
938 static void
939 toolbox_set_desktop(GtkWidget *toolbox, SPDesktop *desktop, SetupFunction setup_func, UpdateFunction update_func, sigc::connection *conn)
941     gpointer ptr = g_object_get_data(G_OBJECT(toolbox), "desktop");
942     SPDesktop *old_desktop = static_cast<SPDesktop*>(ptr);
944     if (old_desktop) {
945         GList *children, *iter;
947         children = gtk_container_get_children(GTK_CONTAINER(toolbox));
948         for ( iter = children ; iter ; iter = iter->next ) {
949             gtk_container_remove( GTK_CONTAINER(toolbox), GTK_WIDGET(iter->data) );
950         }
951         g_list_free(children);
952     }
954     g_object_set_data(G_OBJECT(toolbox), "desktop", (gpointer)desktop);
956     if (desktop) {
957         gtk_widget_set_sensitive(toolbox, TRUE);
958         setup_func(toolbox, desktop);
959         update_func(desktop, desktop->event_context, toolbox);
960         *conn = desktop->connectEventContextChanged
961             (sigc::bind (sigc::ptr_fun(update_func), toolbox));
962     } else {
963         gtk_widget_set_sensitive(toolbox, FALSE);
964     }
966 } // end of toolbox_set_desktop()
969 static void
970 setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
972     GtkTooltips *tooltips=GTK_TOOLTIPS(g_object_get_data(G_OBJECT(toolbox), "tooltips"));
973     gint shrinkLeft = prefs_get_int_attribute_limited( "toolbox.tools", "small", 0, 0, 1 );
974     if ( (shrinkLeft == 0) && (prefs_get_int_attribute_limited( "toolbox.tools", "small", 1, 0, 1 ) == 1) ) {
975         // "toolbox.tools" was not set. Fallback to older value
976         shrinkLeft = prefs_get_int_attribute_limited( "toolbox.left", "small", 0, 0, 1 );
978         // Copy the setting forwards
979         prefs_set_int_attribute( "toolbox.tools", "small", shrinkLeft );
980     }
981     Inkscape::IconSize toolboxSize = shrinkLeft ? Inkscape::ICON_SIZE_SMALL_TOOLBAR : Inkscape::ICON_SIZE_LARGE_TOOLBAR;
983     for (int i = 0 ; tools[i].type_name ; i++ ) {
984         GtkWidget *button =
985             sp_toolbox_button_new_from_verb_with_doubleclick( toolbox, toolboxSize,
986                                                               SP_BUTTON_TYPE_TOGGLE,
987                                                               Inkscape::Verb::get(tools[i].verb),
988                                                               Inkscape::Verb::get(tools[i].doubleclick_verb),
989                                                               desktop,
990                                                               tooltips );
992         g_object_set_data( G_OBJECT(toolbox), tools[i].data_name,
993                            (gpointer)button );
994     }
998 static void
999 update_tool_toolbox( SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox )
1001     gchar const *const tname = ( eventcontext
1002                                  ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext))
1003                                  : NULL );
1004     for (int i = 0 ; tools[i].type_name ; i++ ) {
1005         SPButton *button = SP_BUTTON(g_object_get_data(G_OBJECT(toolbox), tools[i].data_name));
1006         sp_button_toggle_set_down(button, tname && !strcmp(tname, tools[i].type_name));
1007     }
1010 static void
1011 setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
1013     GtkSizeGroup* grouper = gtk_size_group_new( GTK_SIZE_GROUP_BOTH );
1014     GtkActionGroup* mainActions = create_or_fetch_actions( desktop );
1015     GtkUIManager* mgr = gtk_ui_manager_new();
1016     GError* errVal = 0;
1017     gtk_ui_manager_insert_action_group( mgr, mainActions, 0 );
1018     gtk_ui_manager_add_ui_from_string( mgr, ui_descr, -1, &errVal );
1020     std::map<std::string, GtkWidget*> dataHolders;
1022     for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1023         if ( aux_toolboxes[i].prep_func ) {
1024             // converted to GtkActions and UIManager
1026             GtkWidget* kludge = gtk_hbox_new( FALSE, 0 );
1027             g_object_set_data( G_OBJECT(kludge), "dtw", desktop->canvas);
1028             g_object_set_data( G_OBJECT(kludge), "desktop", desktop);
1029             dataHolders[aux_toolboxes[i].type_name] = kludge;
1030             aux_toolboxes[i].prep_func( desktop, mainActions, G_OBJECT(kludge) );
1031         } else {
1033             GtkWidget *sub_toolbox = 0;
1034             if (aux_toolboxes[i].create_func == NULL)
1035                 sub_toolbox = sp_empty_toolbox_new(desktop);
1036             else {
1037                 sub_toolbox = aux_toolboxes[i].create_func(desktop);
1038             }
1040             gtk_size_group_add_widget( grouper, sub_toolbox );
1042             gtk_container_add(GTK_CONTAINER(toolbox), sub_toolbox);
1043             g_object_set_data(G_OBJECT(toolbox), aux_toolboxes[i].data_name, sub_toolbox);
1045         }
1046     }
1048     // Second pass to create toolbars *after* all GtkActions are created
1049     for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1050         if ( aux_toolboxes[i].prep_func ) {
1051             // converted to GtkActions and UIManager
1053             GtkWidget* kludge = dataHolders[aux_toolboxes[i].type_name];
1055             GtkWidget* holder = gtk_table_new( 1, 3, FALSE );
1056             gtk_table_attach( GTK_TABLE(holder), kludge, 2, 3, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1058             gchar* tmp = g_strdup_printf( "/ui/%s", aux_toolboxes[i].ui_name );
1059             GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, tmp );
1060             g_free( tmp );
1061             tmp = 0;
1063             gint shrinkTop = prefs_get_int_attribute_limited( "toolbox", "small", 1, 0, 1 );
1064             Inkscape::IconSize toolboxSize = shrinkTop ? Inkscape::ICON_SIZE_SMALL_TOOLBAR : Inkscape::ICON_SIZE_LARGE_TOOLBAR;
1065             if ( prefs_get_int_attribute_limited( "toolbox", "icononly", 1, 0, 1 ) ) {
1066                 gtk_toolbar_set_style( GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS );
1067             }
1068             gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), static_cast<GtkIconSize>(toolboxSize) );
1071             gtk_table_attach( GTK_TABLE(holder), toolBar, 0, 1, 0, 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0 );
1073             if ( aux_toolboxes[i].swatch_verb_id != SP_VERB_INVALID ) {
1074                 Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch( NULL, aux_toolboxes[i].swatch_tip );
1075                 swatch->setDesktop( desktop );
1076                 swatch->setClickVerb( aux_toolboxes[i].swatch_verb_id );
1077                 swatch->setWatchedTool( aux_toolboxes[i].swatch_tool, true );
1078                 GtkWidget *swatch_ = GTK_WIDGET( swatch->gobj() );
1079                 gtk_table_attach( GTK_TABLE(holder), swatch_, 1, 2, 0, 1, (GtkAttachOptions)(GTK_SHRINK | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), AUX_BETWEEN_BUTTON_GROUPS, 0 );
1080             }
1082             gtk_widget_show_all( holder );
1083             sp_set_font_size_smaller( holder );
1085             gtk_size_group_add_widget( grouper, holder );
1087             gtk_container_add( GTK_CONTAINER(toolbox), holder );
1088             g_object_set_data( G_OBJECT(toolbox), aux_toolboxes[i].data_name, holder );
1089         }
1090     }
1092     g_object_unref( G_OBJECT(grouper) );
1095 static void
1096 update_aux_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox)
1098     gchar const *tname = ( eventcontext
1099                            ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext))
1100                            : NULL );
1101     for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1102         GtkWidget *sub_toolbox = GTK_WIDGET(g_object_get_data(G_OBJECT(toolbox), aux_toolboxes[i].data_name));
1103         if (tname && !strcmp(tname, aux_toolboxes[i].type_name)) {
1104             gtk_widget_show_all(sub_toolbox);
1105             g_object_set_data(G_OBJECT(toolbox), "shows", sub_toolbox);
1106         } else {
1107             gtk_widget_hide(sub_toolbox);
1108         }
1109     }
1112 static void
1113 setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
1115     gchar const * descr =
1116         "<ui>"
1117         "  <toolbar name='CommandsToolbar'>"
1118         "    <toolitem action='FileNew' />"
1119         "    <toolitem action='FileOpen' />"
1120         "    <toolitem action='FileSave' />"
1121         "    <toolitem action='FilePrint' />"
1122         "    <separator />"
1123         "    <toolitem action='FileImport' />"
1124         "    <toolitem action='FileExport' />"
1125         "    <separator />"
1126         "    <toolitem action='EditUndo' />"
1127         "    <toolitem action='EditRedo' />"
1128         "    <separator />"
1129         "    <toolitem action='EditCopy' />"
1130         "    <toolitem action='EditCut' />"
1131         "    <toolitem action='EditPaste' />"
1132         "    <separator />"
1133         "    <toolitem action='ZoomSelection' />"
1134         "    <toolitem action='ZoomDrawing' />"
1135         "    <toolitem action='ZoomPage' />"
1136         "    <separator />"
1137         "    <toolitem action='EditDuplicate' />"
1138         "    <toolitem action='EditClone' />"
1139         "    <toolitem action='EditUnlinkClone' />"
1140         "    <separator />"
1141         "    <toolitem action='SelectionGroup' />"
1142         "    <toolitem action='SelectionUnGroup' />"
1143         "    <separator />"
1144         "    <toolitem action='DialogFillStroke' />"
1145         "    <toolitem action='DialogText' />"
1146         "    <toolitem action='DialogXMLEditor' />"
1147         "    <toolitem action='DialogAlignDistribute' />"
1148         "    <separator />"
1149         "    <toolitem action='DialogPreferences' />"
1150         "    <toolitem action='DialogDocumentProperties' />"
1151         "  </toolbar>"
1152         "</ui>";
1153     GtkActionGroup* mainActions = create_or_fetch_actions( desktop );
1156     GtkUIManager* mgr = gtk_ui_manager_new();
1157     GError* errVal = 0;
1159     gtk_ui_manager_insert_action_group( mgr, mainActions, 0 );
1160     gtk_ui_manager_add_ui_from_string( mgr, descr, -1, &errVal );
1162     GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, "/ui/CommandsToolbar" );
1163     if ( prefs_get_int_attribute_limited( "toolbox", "icononly", 1, 0, 1 ) ) {
1164         gtk_toolbar_set_style( GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS );
1165     }
1166     gint shrinkTop = prefs_get_int_attribute_limited( "toolbox", "small", 1, 0, 1 );
1167     Inkscape::IconSize toolboxSize = shrinkTop ? Inkscape::ICON_SIZE_SMALL_TOOLBAR : Inkscape::ICON_SIZE_LARGE_TOOLBAR;
1168     gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), (GtkIconSize)toolboxSize );
1171     gtk_container_add( GTK_CONTAINER(toolbox), toolBar );
1174 static void
1175 update_commands_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox)
1179 void show_aux_toolbox(GtkWidget *toolbox_toplevel)
1181     gtk_widget_show(toolbox_toplevel);
1182     GtkWidget *toolbox = gtk_bin_get_child(GTK_BIN(toolbox_toplevel));
1184     GtkWidget *shown_toolbox = GTK_WIDGET(g_object_get_data(G_OBJECT(toolbox), "shows"));
1185     if (!shown_toolbox) {
1186         return;
1187     }
1188     gtk_widget_show(toolbox);
1190     // need to show the spacer, or the padding will be off
1191     GtkWidget *spacer = GTK_WIDGET(g_object_get_data(G_OBJECT(toolbox), "top_spacer"));
1192     gtk_widget_show(spacer);
1194     gtk_widget_show_all(shown_toolbox);
1197 void
1198 aux_toolbox_space(GtkWidget *tb, gint space)
1200     gtk_box_pack_start(GTK_BOX(tb), gtk_hbox_new(FALSE, 0), FALSE, FALSE, space);
1203 static GtkWidget *
1204 sp_empty_toolbox_new(SPDesktop *desktop)
1206     GtkWidget *tbl = gtk_hbox_new(FALSE, 0);
1207     gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas);
1208     gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop);
1210     gtk_widget_show_all(tbl);
1211     sp_set_font_size_smaller (tbl);
1213     return tbl;
1216 // helper UI functions
1218 GtkWidget *
1219 sp_tb_spinbutton(
1220     gchar *label, gchar const *tooltip,
1221     gchar const *path, gchar const *data, gdouble def,
1222     GtkWidget *us,
1223     GtkWidget *tbl,
1224     gboolean altx, gchar const *altx_mark,
1225     gdouble lower, gdouble upper, gdouble step, gdouble page,
1226     void (*callback)(GtkAdjustment *, GtkWidget *),
1227     gdouble climb = 0.1, guint digits = 3, double factor = 1.0)
1229     GtkTooltips *tt = gtk_tooltips_new();
1231     GtkWidget *hb = gtk_hbox_new(FALSE, 1);
1233     GtkWidget *l = gtk_label_new(label);
1234     gtk_widget_show(l);
1235     gtk_misc_set_alignment(GTK_MISC(l), 1.0, 0.5);
1236     gtk_container_add(GTK_CONTAINER(hb), l);
1238     GtkObject *a = gtk_adjustment_new(prefs_get_double_attribute(path, data, def) * factor,
1239                                       lower, upper, step, page, page);
1240     gtk_object_set_data(GTK_OBJECT(tbl), data, a);
1241     if (us)
1242         sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(us), GTK_ADJUSTMENT(a));
1244     GtkWidget *sb = gtk_spin_button_new(GTK_ADJUSTMENT(a), climb, digits);
1245     gtk_tooltips_set_tip(tt, sb, tooltip, NULL);
1246     if (altx)
1247         gtk_object_set_data(GTK_OBJECT(sb), altx_mark, sb);
1248     gtk_widget_set_size_request(sb,
1249                                 (upper <= 1.0 || digits == 0)? AUX_SPINBUTTON_WIDTH_SMALL - 10: AUX_SPINBUTTON_WIDTH_SMALL,
1250                                 AUX_SPINBUTTON_HEIGHT);
1251     gtk_widget_show(sb);
1252     gtk_signal_connect(GTK_OBJECT(sb), "focus-in-event", GTK_SIGNAL_FUNC(spinbutton_focus_in), tbl);
1253     gtk_signal_connect(GTK_OBJECT(sb), "key-press-event", GTK_SIGNAL_FUNC(spinbutton_keypress), tbl);
1254     gtk_container_add(GTK_CONTAINER(hb), sb);
1255     gtk_signal_connect(GTK_OBJECT(a), "value_changed", GTK_SIGNAL_FUNC(callback), tbl);
1257     return hb;
1260 static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
1261                                                        gchar const *label, gchar const *tooltip,
1262                                                        gchar const *path, gchar const *data, gdouble def,
1263                                                        GtkWidget *focusTarget,
1264                                                        GtkWidget *us,
1265                                                        GObject *dataKludge,
1266                                                        gboolean altx, gchar const *altx_mark,
1267                                                        gdouble lower, gdouble upper, gdouble step, gdouble page,
1268                                                        gchar const** descrLabels, gdouble const* descrValues, guint descrCount,
1269                                                        void (*callback)(GtkAdjustment *, GObject *),
1270                                                        gdouble climb = 0.1, guint digits = 3, double factor = 1.0 )
1272     GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs_get_double_attribute(path, data, def) * factor,
1273                                                              lower, upper, step, page, page ) );
1274     if (us) {
1275         sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), adj );
1276     }
1278     gtk_signal_connect( GTK_OBJECT(adj), "value-changed", GTK_SIGNAL_FUNC(callback), dataKludge );
1280     EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, label, tooltip, 0, climb, digits );
1282     if ( (descrCount > 0) && descrLabels && descrValues ) {
1283         ege_adjustment_action_set_descriptions( act, descrLabels, descrValues, descrCount );
1284     }
1286     if ( focusTarget ) {
1287         ege_adjustment_action_set_focuswidget( act, focusTarget );
1288     }
1290     if ( altx && altx_mark ) {
1291         g_object_set( G_OBJECT(act), "self-id", altx_mark, NULL );
1292     }
1294     if ( dataKludge ) {
1295         g_object_set_data( dataKludge, data, adj );
1296     }
1298     // Using a cast just to make sure we pass in the right kind of function pointer
1299     g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
1301     return act;
1305 #define MODE_LABEL_WIDTH 70
1307 //########################
1308 //##       Star         ##
1309 //########################
1311 static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKludge )
1313     SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
1315     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1316         // do not remember prefs if this call is initiated by an undo change, because undoing object
1317         // creation sets bogus values to its attributes before it is deleted
1318         prefs_set_int_attribute("tools.shapes.star", "magnitude", (gint)adj->value);
1319     }
1321     // quit if run by the attr_changed listener
1322     if (g_object_get_data( dataKludge, "freeze" )) {
1323         return;
1324     }
1326     // in turn, prevent listener from responding
1327     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
1329     bool modmade = false;
1331     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1332     GSList const *items = selection->itemList();
1333     for (; items != NULL; items = items->next) {
1334         if (SP_IS_STAR((SPItem *) items->data)) {
1335             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
1336             sp_repr_set_int(repr,"sodipodi:sides",(gint)adj->value);
1337             sp_repr_set_svg_double(repr, "sodipodi:arg2",
1338                                    (sp_repr_get_double_attribute(repr, "sodipodi:arg1", 0.5)
1339                                     + M_PI / (gint)adj->value));
1340             SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
1341             modmade = true;
1342         }
1343     }
1344     if (modmade)  sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
1345                                    _("Star: Change number of corners"));
1347     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
1350 static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKludge )
1352     SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
1354     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1355         prefs_set_double_attribute("tools.shapes.star", "proportion", adj->value);
1356     }
1358     // quit if run by the attr_changed listener
1359     if (g_object_get_data( dataKludge, "freeze" )) {
1360         return;
1361     }
1363     // in turn, prevent listener from responding
1364     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
1366     bool modmade = false;
1367     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1368     GSList const *items = selection->itemList();
1369     for (; items != NULL; items = items->next) {
1370         if (SP_IS_STAR((SPItem *) items->data)) {
1371             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
1373             gdouble r1 = sp_repr_get_double_attribute(repr, "sodipodi:r1", 1.0);
1374             gdouble r2 = sp_repr_get_double_attribute(repr, "sodipodi:r2", 1.0);
1375             if (r2 < r1) {
1376                 sp_repr_set_svg_double(repr, "sodipodi:r2", r1*adj->value);
1377             } else {
1378                 sp_repr_set_svg_double(repr, "sodipodi:r1", r2*adj->value);
1379             }
1381             SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
1382             modmade = true;
1383         }
1384     }
1386     if (modmade) sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
1387                                    _("Star: Change spoke ratio"));
1389     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
1392 static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *dataKludge )
1394     SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
1395     bool flat = ege_select_one_action_get_active( act ) == 0;
1397     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1398         prefs_set_string_attribute( "tools.shapes.star", "isflatsided",
1399                                     flat ? "true" : "false" );
1400     }
1402     // quit if run by the attr_changed listener
1403     if (g_object_get_data( dataKludge, "freeze" )) {
1404         return;
1405     }
1407     // in turn, prevent listener from responding
1408     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
1410     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1411     GSList const *items = selection->itemList();
1412     GtkAction* prop_action = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) );
1413     bool modmade = false;
1415     if ( prop_action ) {
1416         gtk_action_set_sensitive( prop_action, !flat );
1417     }
1419     for (; items != NULL; items = items->next) {
1420         if (SP_IS_STAR((SPItem *) items->data)) {
1421             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
1422             repr->setAttribute("inkscape:flatsided", flat ? "true" : "false" );
1423             SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
1424             modmade = true;
1425         }
1426     }
1428     if (modmade) {
1429         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
1430                          flat ? _("Make polygon") : _("Make star"));
1431     }
1433     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
1436 static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludge )
1438     SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
1440     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1441         prefs_set_double_attribute("tools.shapes.star", "rounded", (gdouble) adj->value);
1442     }
1444     // quit if run by the attr_changed listener
1445     if (g_object_get_data( dataKludge, "freeze" )) {
1446         return;
1447     }
1449     // in turn, prevent listener from responding
1450     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
1452     bool modmade = false;
1454     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1455     GSList const *items = selection->itemList();
1456     for (; items != NULL; items = items->next) {
1457         if (SP_IS_STAR((SPItem *) items->data)) {
1458             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
1459             sp_repr_set_svg_double(repr, "inkscape:rounded", (gdouble) adj->value);
1460             SP_OBJECT(items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
1461             modmade = true;
1462         }
1463     }
1464     if (modmade)  sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
1465                                    _("Star: Change rounding"));
1467     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
1470 static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKludge )
1472     SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
1474     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1475         prefs_set_double_attribute("tools.shapes.star", "randomized", (gdouble) adj->value);
1476     }
1478     // quit if run by the attr_changed listener
1479     if (g_object_get_data( dataKludge, "freeze" )) {
1480         return;
1481     }
1483     // in turn, prevent listener from responding
1484     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
1486     bool modmade = false;
1488     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1489     GSList const *items = selection->itemList();
1490     for (; items != NULL; items = items->next) {
1491         if (SP_IS_STAR((SPItem *) items->data)) {
1492             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
1493             sp_repr_set_svg_double(repr, "inkscape:randomized", (gdouble) adj->value);
1494             SP_OBJECT(items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
1495             modmade = true;
1496         }
1497     }
1498     if (modmade)  sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
1499                                    _("Star: Change randomization"));
1501     g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
1505 static void star_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
1506                                        gchar const *old_value, gchar const *new_value,
1507                                        bool is_interactive, gpointer data)
1509     GtkWidget *tbl = GTK_WIDGET(data);
1511     // quit if run by the _changed callbacks
1512     if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
1513         return;
1514     }
1516     // in turn, prevent callbacks from responding
1517     g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
1519     GtkAdjustment *adj = 0;
1521     if (!strcmp(name, "inkscape:randomized")) {
1522         adj = GTK_ADJUSTMENT( gtk_object_get_data(GTK_OBJECT(tbl), "randomized") );
1523         gtk_adjustment_set_value(adj, sp_repr_get_double_attribute(repr, "inkscape:randomized", 0.0));
1524     } else if (!strcmp(name, "inkscape:rounded")) {
1525         adj = GTK_ADJUSTMENT( gtk_object_get_data(GTK_OBJECT(tbl), "rounded") );
1526         gtk_adjustment_set_value(adj, sp_repr_get_double_attribute(repr, "inkscape:rounded", 0.0));
1527     } else if (!strcmp(name, "inkscape:flatsided")) {
1528         GtkAction* prop_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "prop_action") );
1529         char const *flatsides = repr->attribute("inkscape:flatsided");
1530         EgeSelectOneAction* flat_action = EGE_SELECT_ONE_ACTION( g_object_get_data( G_OBJECT(tbl), "flat_action" ) );
1531         if ( flatsides && !strcmp(flatsides,"false") ) {
1532             ege_select_one_action_set_active( flat_action, 1 );
1533             gtk_action_set_sensitive( prop_action, TRUE );
1534         } else {
1535             ege_select_one_action_set_active( flat_action, 0 );
1536             gtk_action_set_sensitive( prop_action, FALSE );
1537         }
1538     } else if (!strcmp(name, "sodipodi:r1") || !strcmp(name, "sodipodi:r2")) {
1539         adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "proportion");
1540         gdouble r1 = sp_repr_get_double_attribute(repr, "sodipodi:r1", 1.0);
1541         gdouble r2 = sp_repr_get_double_attribute(repr, "sodipodi:r2", 1.0);
1542         if (r2 < r1) {
1543             gtk_adjustment_set_value(adj, r2/r1);
1544         } else {
1545             gtk_adjustment_set_value(adj, r1/r2);
1546         }
1547     } else if (!strcmp(name, "sodipodi:sides")) {
1548         adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "magnitude");
1549         gtk_adjustment_set_value(adj, sp_repr_get_int_attribute(repr, "sodipodi:sides", 0));
1550     }
1552     g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
1556 static Inkscape::XML::NodeEventVector star_tb_repr_events =
1558     NULL, /* child_added */
1559     NULL, /* child_removed */
1560     star_tb_event_attr_changed,
1561     NULL, /* content_changed */
1562     NULL  /* order_changed */
1563 };
1566 /**
1567  *  \param selection Should not be NULL.
1568  */
1569 static void
1570 sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
1572     int n_selected = 0;
1573     Inkscape::XML::Node *repr = NULL;
1575     purge_repr_listener( tbl, tbl );
1577     for (GSList const *items = selection->itemList();
1578          items != NULL;
1579          items = items->next)
1580     {
1581         if (SP_IS_STAR((SPItem *) items->data)) {
1582             n_selected++;
1583             repr = SP_OBJECT_REPR((SPItem *) items->data);
1584         }
1585     }
1587     EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
1589     if (n_selected == 0) {
1590         g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
1591     } else if (n_selected == 1) {
1592         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
1594         if (repr) {
1595             g_object_set_data( tbl, "repr", repr );
1596             Inkscape::GC::anchor(repr);
1597             sp_repr_add_listener(repr, &star_tb_repr_events, tbl);
1598             sp_repr_synthesize_events(repr, &star_tb_repr_events, tbl);
1599         }
1600     } else {
1601         // FIXME: implement averaging of all parameters for multiple selected stars
1602         //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
1603         //gtk_label_set_markup(GTK_LABEL(l), _("<b>Change:</b>"));
1604     }
1608 static void sp_stb_defaults( GtkWidget *widget, GObject *dataKludge )
1610     // FIXME: in this and all other _default functions, set some flag telling the value_changed
1611     // callbacks to lump all the changes for all selected objects in one undo step
1613     GtkAdjustment *adj = 0;
1615     // fixme: make settable in prefs!
1616     gint mag = 5;
1617     gdouble prop = 0.5;
1618     gboolean flat = FALSE;
1619     gdouble randomized = 0;
1620     gdouble rounded = 0;
1622     EgeSelectOneAction* flat_action = EGE_SELECT_ONE_ACTION( g_object_get_data( dataKludge, "flat_action" ) );
1623     ege_select_one_action_set_active( flat_action, flat ? 0 : 1 );
1625     GtkAction* sb2 = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) );
1626     gtk_action_set_sensitive( sb2, !flat );
1628     adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "magnitude" ) );
1629     gtk_adjustment_set_value(adj, mag);
1630     gtk_adjustment_value_changed(adj);
1632     adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "proportion" ) );
1633     gtk_adjustment_set_value(adj, prop);
1634     gtk_adjustment_value_changed(adj);
1636     adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "rounded" ) );
1637     gtk_adjustment_set_value(adj, rounded);
1638     gtk_adjustment_value_changed(adj);
1640     adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "randomized" ) );
1641     gtk_adjustment_set_value(adj, randomized);
1642     gtk_adjustment_value_changed(adj);
1646 void
1647 sp_toolbox_add_label(GtkWidget *tbl, gchar const *title, bool wide)
1649     GtkWidget *boxl = gtk_hbox_new(FALSE, 0);
1650     if (wide) gtk_widget_set_size_request(boxl, MODE_LABEL_WIDTH, -1);
1651     GtkWidget *l = gtk_label_new(NULL);
1652     gtk_label_set_markup(GTK_LABEL(l), title);
1653     gtk_box_pack_end(GTK_BOX(boxl), l, FALSE, FALSE, 0);
1654     gtk_box_pack_start(GTK_BOX(tbl), boxl, FALSE, FALSE, 0);
1655     gtk_object_set_data(GTK_OBJECT(tbl), "mode_label", l);
1659 static void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
1661     {
1662         EgeOutputAction* act = ege_output_action_new( "StarStateAction", _("<b>New:</b>"), "", 0 );
1663         ege_output_action_set_use_markup( act, TRUE );
1664         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
1665         g_object_set_data( holder, "mode_action", act );
1666     }
1668     {
1669         //EgeAdjustmentAction* calligraphy_angle = 0;
1670         EgeAdjustmentAction* eact = 0;
1671         gchar const *flatsidedstr = prefs_get_string_attribute( "tools.shapes.star", "isflatsided" );
1672         bool isFlatSided = flatsidedstr ? (strcmp(flatsidedstr, "false") != 0) : true;
1674         /* Flatsided checkbox */
1675         {
1676             GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
1678             GtkTreeIter iter;
1679             gtk_list_store_append( model, &iter );
1680             gtk_list_store_set( model, &iter,
1681                                 0, _("Polygon"),
1682                                 1, _("Regular polygon (with one handle) instead of a star"),
1683                                 2, "star_flat",
1684                                 -1 );
1686             gtk_list_store_append( model, &iter );
1687             gtk_list_store_set( model, &iter,
1688                                 0, _("Star"),
1689                                 1, _("Star instead of a regular polygon (with one handle)"),
1690                                 2, "star_angled",
1691                                 -1 );
1693             EgeSelectOneAction* act = ege_select_one_action_new( "FlatAction", _(""), _(""), NULL, GTK_TREE_MODEL(model) );
1694             gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
1695             g_object_set_data( holder, "flat_action", act );
1697             ege_select_one_action_set_appearance( act, "full" );
1698             ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
1699             g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
1700             ege_select_one_action_set_icon_column( act, 2 );
1701             ege_select_one_action_set_tooltip_column( act, 1  );
1703             ege_select_one_action_set_active( act, isFlatSided ? 0 : 1 );
1704             g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_stb_sides_flat_state_changed), holder);
1705         }
1707         /* Magnitude */
1708         //gchar const* labels[] = {_("tri (default)"), _("quad"), _("pent")};
1709         //gdouble values[] = {3, 4, 5};
1710         eact = create_adjustment_action( "MagnitudeAction",
1711                                          _("Corners:"), _("Number of corners of a polygon or star"),
1712                                          "tools.shapes.star", "magnitude", 3,
1713                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
1714                                          3, 1024, 1, 5,
1715                                          0, 0, 0, // labels, values, G_N_ELEMENTS(labels),
1716                                          sp_stb_magnitude_value_changed,
1717                                          1.0, 0 );
1718         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1719         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
1721         /* Spoke ratio */
1722         //gchar const* labels2[] = {_("(left edge up)"), _("(horizontal)"), _("(default)"), _("(right edge up)")};
1723         //gdouble values2[] = {-90, 0, 30, 90};
1724         eact = create_adjustment_action( "SpokeAction",
1725                                          _("Spoke ratio:"),
1726                                          // TRANSLATORS: Tip radius of a star is the distance from the center to the farthest handle.
1727                                          // Base radius is the same for the closest handle.
1728                                          _("Base radius to tip radius ratio"),
1729                                          "tools.shapes.star", "proportion", 0.5,
1730                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
1731                                          0.01, 1.0, 0.01, 0.1,
1732                                          0, 0, 0, // labels2, values2, G_N_ELEMENTS(labels2),
1733                                          sp_stb_proportion_value_changed );
1734         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1735         g_object_set_data( holder, "prop_action", eact );
1737         if ( !isFlatSided ) {
1738             gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
1739         } else {
1740             gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
1741         }
1743         /* Roundedness */
1744         //gchar const* labels3[] = {_("(left edge up)"), _("(horizontal)"), _("(default)"), _("(right edge up)")};
1745         //gdouble values3[] = {-90, 0, 30, 90};
1746         eact = create_adjustment_action( "RoundednessAction",
1747                                          _("Rounded:"), _("How much rounded are the corners (0 for sharp)"),
1748                                          "tools.shapes.star", "rounded", 0.0,
1749                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
1750                                          -100.0, 100.0, 0.01, 0.1,
1751                                          0, 0, 0, // labels3, values3, G_N_ELEMENTS(labels3),
1752                                          sp_stb_rounded_value_changed );
1753         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1754         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
1756         /* Randomization */
1757         //gchar const* labels4[] = {_("(left edge up)"), _("(horizontal)"), _("(default)"), _("(right edge up)")};
1758         //gdouble values4[] = {-90, 0, 30, 90};
1759         eact = create_adjustment_action( "RandomizationAction",
1760                                          _("Randomized:"), _("Scatter randomly the corners and angles"),
1761                                          "tools.shapes.star", "randomized", 0.0,
1762                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
1763                                          -10.0, 10.0, 0.001, 0.01,
1764                                          0, 0, 0, // labels4, values4, G_N_ELEMENTS(labels4),
1765                                          sp_stb_randomized_value_changed, 0.1, 3 );
1766         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1767         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
1768     }
1770     {
1771         /* Reset */
1772         {
1773             GtkAction* act = gtk_action_new( "StarResetAction",
1774                                              _("Defaults"),
1775                                              _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
1776                                              GTK_STOCK_CLEAR );
1777             g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_stb_defaults), holder );
1778             gtk_action_group_add_action( mainActions, act );
1779             gtk_action_set_sensitive( act, TRUE );
1780         }
1781     }
1783     sigc::connection *connection = new sigc::connection(
1784         sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_star_toolbox_selection_changed), (GObject *)holder))
1785         );
1786     g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
1787     g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
1791 //########################
1792 //##       Rect         ##
1793 //########################
1795 static void sp_rtb_sensitivize( GObject *tbl )
1797     GtkAdjustment *adj1 = GTK_ADJUSTMENT( g_object_get_data(tbl, "rx") );
1798     GtkAdjustment *adj2 = GTK_ADJUSTMENT( g_object_get_data(tbl, "ry") );
1799     GtkAction* not_rounded = GTK_ACTION( g_object_get_data(tbl, "not_rounded") );
1801     if (adj1->value == 0 && adj2->value == 0 && g_object_get_data(tbl, "single")) { // only for a single selected rect (for now)
1802         gtk_action_set_sensitive( not_rounded, FALSE );
1803     } else {
1804         gtk_action_set_sensitive( not_rounded, TRUE );
1805     }
1809 static void
1810 sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name,
1811                           void (*setter)(SPRect *, gdouble))
1813     SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
1815     UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
1816     SPUnit const *unit = tracker->getActiveUnit();
1818     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1819         prefs_set_double_attribute("tools.shapes.rect", value_name, sp_units_get_pixels(adj->value, *unit));
1820     }
1822     // quit if run by the attr_changed listener
1823     if (g_object_get_data( tbl, "freeze" )) {
1824         return;
1825     }
1827     // in turn, prevent listener from responding
1828     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
1830     bool modmade = false;
1831     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1832     for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
1833         if (SP_IS_RECT(items->data)) {
1834             if (adj->value != 0) {
1835                 setter(SP_RECT(items->data), sp_units_get_pixels(adj->value, *unit));
1836             } else {
1837                 SP_OBJECT_REPR(items->data)->setAttribute(value_name, NULL);
1838             }
1839             modmade = true;
1840         }
1841     }
1843     sp_rtb_sensitivize( tbl );
1845     if (modmade) {
1846         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_RECT,
1847                                    _("Change rectangle"));
1848     }
1850     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
1853 static void
1854 sp_rtb_rx_value_changed(GtkAdjustment *adj, GObject *tbl)
1856     sp_rtb_value_changed(adj, tbl, "rx", sp_rect_set_visible_rx);
1859 static void
1860 sp_rtb_ry_value_changed(GtkAdjustment *adj, GObject *tbl)
1862     sp_rtb_value_changed(adj, tbl, "ry", sp_rect_set_visible_ry);
1865 static void
1866 sp_rtb_width_value_changed(GtkAdjustment *adj, GObject *tbl)
1868     sp_rtb_value_changed(adj, tbl, "width", sp_rect_set_visible_width);
1871 static void
1872 sp_rtb_height_value_changed(GtkAdjustment *adj, GObject *tbl)
1874     sp_rtb_value_changed(adj, tbl, "height", sp_rect_set_visible_height);
1879 static void
1880 sp_rtb_defaults( GtkWidget *widget, GObject *obj)
1882     GtkAdjustment *adj = 0;
1884     adj = GTK_ADJUSTMENT( g_object_get_data(obj, "rx") );
1885     gtk_adjustment_set_value(adj, 0.0);
1886     // this is necessary if the previous value was 0, but we still need to run the callback to change all selected objects
1887     gtk_adjustment_value_changed(adj);
1889     adj = GTK_ADJUSTMENT( g_object_get_data(obj, "ry") );
1890     gtk_adjustment_set_value(adj, 0.0);
1891     gtk_adjustment_value_changed(adj);
1893     sp_rtb_sensitivize( obj );
1896 static void rect_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
1897                                        gchar const *old_value, gchar const *new_value,
1898                                        bool is_interactive, gpointer data)
1900     GObject *tbl = G_OBJECT(data);
1902     // quit if run by the _changed callbacks
1903     if (g_object_get_data( tbl, "freeze" )) {
1904         return;
1905     }
1907     // in turn, prevent callbacks from responding
1908     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
1910     UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
1911     SPUnit const *unit = tracker->getActiveUnit();
1913     gpointer item = g_object_get_data( tbl, "item" );
1914     if (item && SP_IS_RECT(item)) {
1915         {
1916             GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) );
1917             gdouble rx = sp_rect_get_visible_rx(SP_RECT(item));
1918             gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit));
1919         }
1921         {
1922             GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) );
1923             gdouble ry = sp_rect_get_visible_ry(SP_RECT(item));
1924             gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit));
1925         }
1927         {
1928             GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) );
1929             gdouble width = sp_rect_get_visible_width (SP_RECT(item));
1930             gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit));
1931         }
1933         {
1934             GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) );
1935             gdouble height = sp_rect_get_visible_height (SP_RECT(item));
1936             gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit));
1937         }
1938     }
1940     sp_rtb_sensitivize( tbl );
1942     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
1946 static Inkscape::XML::NodeEventVector rect_tb_repr_events = {
1947     NULL, /* child_added */
1948     NULL, /* child_removed */
1949     rect_tb_event_attr_changed,
1950     NULL, /* content_changed */
1951     NULL  /* order_changed */
1952 };
1954 /**
1955  *  \param selection should not be NULL.
1956  */
1957 static void
1958 sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
1960     int n_selected = 0;
1961     Inkscape::XML::Node *repr = NULL;
1962     SPItem *item = NULL;
1964     if ( g_object_get_data( tbl, "repr" ) ) {
1965         g_object_set_data( tbl, "item", NULL );
1966     }
1967     purge_repr_listener( tbl, tbl );
1969     for (GSList const *items = selection->itemList();
1970          items != NULL;
1971          items = items->next) {
1972         if (SP_IS_RECT((SPItem *) items->data)) {
1973             n_selected++;
1974             item = (SPItem *) items->data;
1975             repr = SP_OBJECT_REPR(item);
1976         }
1977     }
1979     EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
1981     g_object_set_data( tbl, "single", GINT_TO_POINTER(FALSE) );
1983     if (n_selected == 0) {
1984         g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
1986         GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "width_action" ) );
1987         gtk_action_set_sensitive(w, FALSE);
1988         GtkAction* h = GTK_ACTION( g_object_get_data( tbl, "height_action" ) );
1989         gtk_action_set_sensitive(h, FALSE);
1991     } else if (n_selected == 1) {
1992         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
1993         g_object_set_data( tbl, "single", GINT_TO_POINTER(TRUE) );
1995         GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "width_action" ) );
1996         gtk_action_set_sensitive(w, TRUE);
1997         GtkAction* h = GTK_ACTION( g_object_get_data( tbl, "height_action" ) );
1998         gtk_action_set_sensitive(h, TRUE);
2000         if (repr) {
2001             g_object_set_data( tbl, "repr", repr );
2002             g_object_set_data( tbl, "item", item );
2003             Inkscape::GC::anchor(repr);
2004             sp_repr_add_listener(repr, &rect_tb_repr_events, tbl);
2005             sp_repr_synthesize_events(repr, &rect_tb_repr_events, tbl);
2006         }
2007     } else {
2008         // FIXME: implement averaging of all parameters for multiple selected
2009         //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
2010         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
2011         sp_rtb_sensitivize( tbl );
2012     }
2016 static void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2018     EgeAdjustmentAction* eact = 0;
2020     {
2021         EgeOutputAction* act = ege_output_action_new( "RectStateAction", _("<b>New:</b>"), "", 0 );
2022         ege_output_action_set_use_markup( act, TRUE );
2023         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2024         g_object_set_data( holder, "mode_action", act );
2025     }
2027     // rx/ry units menu: create
2028     UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
2029     //tracker->addUnit( SP_UNIT_PERCENT, 0 );
2030     // fixme: add % meaning per cent of the width/height
2031     tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
2032     g_object_set_data( holder, "tracker", tracker );
2034     /* W */
2035     {
2036         eact = create_adjustment_action( "RectWidthAction",
2037                                          _("W:"), _("Width of rectangle"),
2038                                          "tools.shapes.rect", "width", 0,
2039                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-rect",
2040                                          0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
2041                                          0, 0, 0,
2042                                          sp_rtb_width_value_changed );
2043         tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
2044         g_object_set_data( holder, "width_action", eact );
2045         gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
2046         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2047     }
2049     /* H */
2050     {
2051         eact = create_adjustment_action( "RectHeightAction",
2052                                          _("H:"), _("Height of rectangle"),
2053                                          "tools.shapes.rect", "height", 0,
2054                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
2055                                          0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
2056                                          0, 0, 0,
2057                                          sp_rtb_height_value_changed );
2058         tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
2059         g_object_set_data( holder, "height_action", eact );
2060         gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
2061         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2062     }
2064     /* rx */
2065     {
2066         eact = create_adjustment_action( "RadiusXAction",
2067                                          _("Rx:"), _("Horizontal radius of rounded corners"),
2068                                          "tools.shapes.rect", "rx", 0,
2069                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
2070                                          0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
2071                                          0, 0, 0,
2072                                          sp_rtb_rx_value_changed);
2073         tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
2074         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2075     }
2077     /* ry */
2078     {
2079         eact = create_adjustment_action( "RadiusYAction",
2080                                          _("Ry:"), _("Vertical radius of rounded corners"),
2081                                          "tools.shapes.rect", "ry", 0,
2082                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
2083                                          0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
2084                                          0, 0, 0,
2085                                          sp_rtb_ry_value_changed);
2086         tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
2087         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2088     }
2090     // add the units menu
2091     {
2092         GtkAction* act = tracker->createAction( "RectUnitsAction", _("Units"), _("") );
2093         gtk_action_group_add_action( mainActions, act );
2094     }
2096     /* Reset */
2097     {
2098         InkAction* inky = ink_action_new( "RectResetAction",
2099                                           _("Not rounded"),
2100                                           _("Make corners sharp"),
2101                                           "squared_corner",
2102                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
2103         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_rtb_defaults), holder );
2104         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
2105         gtk_action_set_sensitive( GTK_ACTION(inky), TRUE );
2106         g_object_set_data( holder, "not_rounded", inky );
2107     }
2109     g_object_set_data( holder, "single", GINT_TO_POINTER(TRUE) );
2110     sp_rtb_sensitivize( holder );
2112     sigc::connection *connection = new sigc::connection(
2113         sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_rect_toolbox_selection_changed), (GObject *)holder))
2114         );
2115     g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
2116     g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
2119 //########################
2120 //##       3D Box       ##
2121 //########################
2123 static void sp_3dbox_toggle_vp_changed( GtkToggleAction *act, gpointer data )
2125     SPDocument *document = sp_desktop_document (inkscape_active_desktop ());
2126     Box3D::Axis axis = (Box3D::Axis) GPOINTER_TO_INT(data);
2128     if (document->current_perspective) {
2129         document->current_perspective->toggle_boxes (axis);
2130     }
2131     
2134 static void sp_3dbox_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2136     SPDocument *document = sp_desktop_document (desktop);
2137     bool toggled = false;
2138     /* toggle VP in X direction */
2139     {
2140     InkToggleAction* act = ink_toggle_action_new( "3DBoxVPXAction",
2141                                                   _("Toggle VP in X direction"),
2142                                                   _("Toggle VP in X direction between 'finite' and 'infinite' (=parallel)"),
2143                                                   "toggle_vp_x",
2144                                                   Inkscape::ICON_SIZE_DECORATION );
2145     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2146     if (document->current_perspective) {
2147         toggled = !document->current_perspective->get_vanishing_point(Box3D::X)->is_finite();
2148     }
2149     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
2150     /* we connect the signal after setting the state to avoid switching the state again */
2151     g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::X));
2152     }
2154     /* toggle VP in Y direction */
2155     {
2156     InkToggleAction* act = ink_toggle_action_new( "3DBoxVPYAction",
2157                                                   _("Toggle VP in Y direction"),
2158                                                   _("Toggle VP in Y direction between 'finite' and 'infinite' (=parallel)"),
2159                                                   "toggle_vp_y",
2160                                                   Inkscape::ICON_SIZE_DECORATION );
2161     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2162     if (document->current_perspective) {
2163         toggled = !document->current_perspective->get_vanishing_point(Box3D::Y)->is_finite();
2164     }
2165     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
2166     /* we connect the signal after setting the state to avoid switching the state again */
2167     g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::Y));
2168     }
2170     /* toggle VP in Z direction */
2171     {
2172     InkToggleAction* act = ink_toggle_action_new( "3DBoxVPZAction",
2173                                                   _("Toggle VP in Z direction"),
2174                                                   _("Toggle VP in Z direction between 'finite' and 'infinite' (=parallel)"),
2175                                                   "toggle_vp_z",
2176                                                   Inkscape::ICON_SIZE_DECORATION );
2177     gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2178     if (document->current_perspective) {
2179         toggled = !document->current_perspective->get_vanishing_point(Box3D::Z)->is_finite();
2180     }
2181     /* we connect the signal after setting the state to avoid switching the state again */
2182     gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), toggled );
2183     g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_3dbox_toggle_vp_changed), GINT_TO_POINTER(Box3D::Z));
2184     }
2187 //########################
2188 //##       Spiral       ##
2189 //########################
2191 static void
2192 sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name)
2194     SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
2196     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2197         prefs_set_double_attribute("tools.shapes.spiral", value_name, adj->value);
2198     }
2200     // quit if run by the attr_changed listener
2201     if (g_object_get_data( tbl, "freeze" )) {
2202         return;
2203     }
2205     // in turn, prevent listener from responding
2206     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
2208     gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL);
2210     bool modmade = false;
2211     for (GSList const *items = sp_desktop_selection(desktop)->itemList();
2212          items != NULL;
2213          items = items->next)
2214     {
2215         if (SP_IS_SPIRAL((SPItem *) items->data)) {
2216             Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2217             sp_repr_set_svg_double( repr, namespaced_name, adj->value );
2218             SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
2219             modmade = true;
2220         }
2221     }
2223     g_free(namespaced_name);
2225     if (modmade) {
2226         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SPIRAL,
2227                                    _("Change spiral"));
2228     }
2230     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
2233 static void
2234 sp_spl_tb_revolution_value_changed(GtkAdjustment *adj, GObject *tbl)
2236     sp_spl_tb_value_changed(adj, tbl, "revolution");
2239 static void
2240 sp_spl_tb_expansion_value_changed(GtkAdjustment *adj, GObject *tbl)
2242     sp_spl_tb_value_changed(adj, tbl, "expansion");
2245 static void
2246 sp_spl_tb_t0_value_changed(GtkAdjustment *adj, GObject *tbl)
2248     sp_spl_tb_value_changed(adj, tbl, "t0");
2251 static void
2252 sp_spl_tb_defaults(GtkWidget *widget, GtkObject *obj)
2254     GtkWidget *tbl = GTK_WIDGET(obj);
2256     GtkAdjustment *adj;
2258     // fixme: make settable
2259     gdouble rev = 5;
2260     gdouble exp = 1.0;
2261     gdouble t0 = 0.0;
2263     adj = (GtkAdjustment*)gtk_object_get_data(obj, "revolution");
2264     gtk_adjustment_set_value(adj, rev);
2265     gtk_adjustment_value_changed(adj);
2267     adj = (GtkAdjustment*)gtk_object_get_data(obj, "expansion");
2268     gtk_adjustment_set_value(adj, exp);
2269     gtk_adjustment_value_changed(adj);
2271     adj = (GtkAdjustment*)gtk_object_get_data(obj, "t0");
2272     gtk_adjustment_set_value(adj, t0);
2273     gtk_adjustment_value_changed(adj);
2275     spinbutton_defocus(GTK_OBJECT(tbl));
2279 static void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
2280                                          gchar const *old_value, gchar const *new_value,
2281                                          bool is_interactive, gpointer data)
2283     GtkWidget *tbl = GTK_WIDGET(data);
2285     // quit if run by the _changed callbacks
2286     if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
2287         return;
2288     }
2290     // in turn, prevent callbacks from responding
2291     g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
2293     GtkAdjustment *adj;
2294     adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "revolution");
2295     gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:revolution", 3.0)));
2297     adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "expansion");
2298     gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:expansion", 1.0)));
2300     adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "t0");
2301     gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:t0", 0.0)));
2303     g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
2307 static Inkscape::XML::NodeEventVector spiral_tb_repr_events = {
2308     NULL, /* child_added */
2309     NULL, /* child_removed */
2310     spiral_tb_event_attr_changed,
2311     NULL, /* content_changed */
2312     NULL  /* order_changed */
2313 };
2315 static void
2316 sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
2318     int n_selected = 0;
2319     Inkscape::XML::Node *repr = NULL;
2321     purge_repr_listener( tbl, tbl );
2323     for (GSList const *items = selection->itemList();
2324          items != NULL;
2325          items = items->next)
2326     {
2327         if (SP_IS_SPIRAL((SPItem *) items->data)) {
2328             n_selected++;
2329             repr = SP_OBJECT_REPR((SPItem *) items->data);
2330         }
2331     }
2333     EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
2335     if (n_selected == 0) {
2336         g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
2337     } else if (n_selected == 1) {
2338         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
2340         if (repr) {
2341             g_object_set_data( tbl, "repr", repr );
2342             Inkscape::GC::anchor(repr);
2343             sp_repr_add_listener(repr, &spiral_tb_repr_events, tbl);
2344             sp_repr_synthesize_events(repr, &spiral_tb_repr_events, tbl);
2345         }
2346     } else {
2347         // FIXME: implement averaging of all parameters for multiple selected
2348         //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
2349         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
2350     }
2354 static void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2356     EgeAdjustmentAction* eact = 0;
2358     {
2359         EgeOutputAction* act = ege_output_action_new( "SpiralStateAction", _("<b>New:</b>"), "", 0 );
2360         ege_output_action_set_use_markup( act, TRUE );
2361         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2362         g_object_set_data( holder, "mode_action", act );
2363     }
2365     /* Revolution */
2366     {
2367         eact = create_adjustment_action( "SpiralRevolutionAction",
2368                                          _("Turns:"), _("Number of revolutions"),
2369                                          "tools.shapes.spiral", "revolution", 3.0,
2370                                          GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spiral",
2371                                          0.01, 1024.0, 0.1, 1.0,
2372                                          0, 0, 0,
2373                                          sp_spl_tb_revolution_value_changed, 1, 2);
2374         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2375     }
2377     /* Expansion */
2378     {
2379         eact = create_adjustment_action( "SpiralExpansionAction",
2380                                          _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"),
2381                                          "tools.shapes.spiral", "expansion", 1.0,
2382                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2383                                          0.0, 1000.0, 0.01, 1.0,
2384                                          0, 0, 0,
2385                                          sp_spl_tb_expansion_value_changed);
2386         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2387     }
2389     /* T0 */
2390     {
2391         eact = create_adjustment_action( "SpiralT0Action",
2392                                          _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"),
2393                                          "tools.shapes.spiral", "t0", 0.0,
2394                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2395                                          0.0, 0.999, 0.01, 1.0,
2396                                          0, 0, 0,
2397                                          sp_spl_tb_t0_value_changed);
2398         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2399     }
2401     /* Reset */
2402     {
2403         InkAction* inky = ink_action_new( "SpiralResetAction",
2404                                           _("Defaults"),
2405                                           _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
2406                                           GTK_STOCK_CLEAR,
2407                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
2408         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_spl_tb_defaults), holder );
2409         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
2410     }
2413     sigc::connection *connection = new sigc::connection(
2414         sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_spiral_toolbox_selection_changed), (GObject *)holder))
2415         );
2416     g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
2417     g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
2420 //########################
2421 //##     Pen/Pencil    ##
2422 //########################
2425 static void sp_pen_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2427     // Put stuff here
2430 static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2432     // Put stuff here
2435 //########################
2436 //##       Tweak        ##
2437 //########################
2439 static void sp_tweak_width_value_changed( GtkAdjustment *adj, GObject *tbl )
2441     prefs_set_double_attribute( "tools.tweak", "width", adj->value * 0.01 );
2444 static void sp_tweak_force_value_changed( GtkAdjustment *adj, GObject *tbl )
2446     prefs_set_double_attribute( "tools.tweak", "force", adj->value * 0.01 );
2449 static void sp_tweak_pressure_state_changed( GtkToggleAction *act, gpointer data )
2451     prefs_set_int_attribute( "tools.tweak", "usepressure", gtk_toggle_action_get_active( act ) ? 1 : 0);
2454 static void sp_tweak_mode_changed( EgeSelectOneAction *act, GObject *tbl )
2456     prefs_set_int_attribute("tools.tweak", "mode", ege_select_one_action_get_active( act ));
2459 static void sp_tweak_fidelity_value_changed( GtkAdjustment *adj, GObject *tbl )
2461     prefs_set_double_attribute( "tools.tweak", "fidelity", adj->value * 0.01 );
2465 static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2467     {
2468         /* Width */
2469         gchar const* labels[] = {_("(pinch tweak)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad tweak)")};
2470         gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
2471         EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction",
2472                                                               _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"),
2473                                                               "tools.tweak", "width", 15,
2474                                                               GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak",
2475                                                               1, 100, 1.0, 10.0,
2476                                                               labels, values, G_N_ELEMENTS(labels),
2477                                                               sp_tweak_width_value_changed,  0.01, 0, 100 );
2478         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2479         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2480     }
2483     {
2484         /* Force */
2485         gchar const* labels[] = {_("(minimum force)"), 0, 0, _("(default)"), 0, 0, 0, _("(maximum force)")};
2486         gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100};
2487         EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction",
2488                                                               _("Force:"), _("The force of the tweak action"),
2489                                                               "tools.tweak", "force", 20,
2490                                                               GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force",
2491                                                               1, 100, 1.0, 10.0,
2492                                                               labels, values, G_N_ELEMENTS(labels),
2493                                                               sp_tweak_force_value_changed,  0.01, 0, 100 );
2494         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2495         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2496     }
2498     /* Mode */
2499     {
2500         GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
2502         GtkTreeIter iter;
2503         gtk_list_store_append( model, &iter );
2504         gtk_list_store_set( model, &iter,
2505                             0, _("Push mode"),
2506                             1, _("Switch to Push mode"),
2507                             2, "tweak_push_mode",
2508                             -1 );
2510         gtk_list_store_append( model, &iter );
2511         gtk_list_store_set( model, &iter,
2512                             0, _("Melt mode"),
2513                             1, _("Switch to Melt mode"),
2514                             2, "tweak_suck_mode",
2515                             -1 );
2517         gtk_list_store_append( model, &iter );
2518         gtk_list_store_set( model, &iter,
2519                             0, _("Inflate mode"),
2520                             1, _("Switch to Inflate mode"),
2521                             2, "tweak_inflate_mode",
2522                             -1 );
2524         gtk_list_store_append( model, &iter );
2525         gtk_list_store_set( model, &iter,
2526                             0, _("Roughen mode"),
2527                             1, _("Switch to Roughen mode"),
2528                             2, "tweak_roughen_mode",
2529                             -1 );
2531         EgeSelectOneAction* act = ege_select_one_action_new( "TweakModeAction", _(""), _(""), NULL, GTK_TREE_MODEL(model) );
2532         gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
2533         g_object_set_data( holder, "mode_action", act );
2535         ege_select_one_action_set_appearance( act, "full" );
2536         ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
2537         g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
2538         ege_select_one_action_set_icon_column( act, 2 );
2539         ege_select_one_action_set_tooltip_column( act, 1  );
2541         gint mode = prefs_get_int_attribute("tools.tweak", "mode", 0);
2542         ege_select_one_action_set_active( act, mode );
2543         g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_tweak_mode_changed), holder );
2545         g_object_set_data( G_OBJECT(holder), "tweak_tool_mode", act);
2546     }
2548     {   /* Fidelity */
2549         gchar const* labels[] = {_("(rough, simplified)"), 0, 0, _("(default)"), 0, 0, _("(fine, but many nodes)")};
2550         gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
2551         EgeAdjustmentAction *eact = create_adjustment_action( "TweakFidelityAction",
2552                                                               _("Fidelity:"), _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"),
2553                                                               "tools.tweak", "fidelity", 50,
2554                                                               GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity",
2555                                                               1, 100, 1.0, 10.0,
2556                                                               labels, values, G_N_ELEMENTS(labels),
2557                                                               sp_tweak_fidelity_value_changed,  0.01, 0, 100 );
2558         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2559         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2560     }
2563     /* Use Pressure button */
2564     {
2565         InkToggleAction* act = ink_toggle_action_new( "TweakPressureAction",
2566                                                       _("Pressure"),
2567                                                       _("Use the pressure of the input device to alter the width of the area"),
2568                                                       "use_pressure",
2569                                                       Inkscape::ICON_SIZE_DECORATION );
2570         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2571         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_tweak_pressure_state_changed), NULL);
2572         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.tweak", "usepressure", 1 ) );
2573     }
2578 //########################
2579 //##     Calligraphy    ##
2580 //########################
2582 static void sp_ddc_mass_value_changed( GtkAdjustment *adj, GObject* tbl )
2584     prefs_set_double_attribute( "tools.calligraphic", "mass", adj->value );
2587 static void sp_ddc_wiggle_value_changed( GtkAdjustment *adj, GObject* tbl )
2589     prefs_set_double_attribute( "tools.calligraphic", "wiggle", adj->value );
2592 static void sp_ddc_angle_value_changed( GtkAdjustment *adj, GObject* tbl )
2594     prefs_set_double_attribute( "tools.calligraphic", "angle", adj->value );
2597 static void sp_ddc_width_value_changed( GtkAdjustment *adj, GObject *tbl )
2599     prefs_set_double_attribute( "tools.calligraphic", "width", adj->value * 0.01 );
2602 static void sp_ddc_velthin_value_changed( GtkAdjustment *adj, GObject* tbl )
2604     prefs_set_double_attribute("tools.calligraphic", "thinning", adj->value);
2607 static void sp_ddc_flatness_value_changed( GtkAdjustment *adj, GObject* tbl )
2609     prefs_set_double_attribute( "tools.calligraphic", "flatness", adj->value );
2612 static void sp_ddc_tremor_value_changed( GtkAdjustment *adj, GObject* tbl )
2614     prefs_set_double_attribute( "tools.calligraphic", "tremor", adj->value );
2617 static void sp_ddc_cap_rounding_value_changed( GtkAdjustment *adj, GObject* tbl )
2619     prefs_set_double_attribute( "tools.calligraphic", "cap_rounding", adj->value );
2622 static void sp_ddc_pressure_state_changed( GtkToggleAction *act, gpointer data )
2624     prefs_set_int_attribute( "tools.calligraphic", "usepressure", gtk_toggle_action_get_active( act ) ? 1 : 0);
2627 static void sp_ddc_trace_background_changed( GtkToggleAction *act, gpointer data )
2629     prefs_set_int_attribute( "tools.calligraphic", "tracebackground", gtk_toggle_action_get_active( act ) ? 1 : 0);
2632 static void sp_ddc_tilt_state_changed( GtkToggleAction *act, GtkAction *calligraphy_angle )
2634     prefs_set_int_attribute( "tools.calligraphic", "usetilt", gtk_toggle_action_get_active( act ) ? 1 : 0 );
2636     gtk_action_set_sensitive( calligraphy_angle, !gtk_toggle_action_get_active( act ) );
2639 static void sp_ddc_defaults(GtkWidget *, GObject *dataKludge)
2641     // FIXME: make defaults settable via Inkscape Options
2642     struct KeyValue {
2643         char const *key;
2644         double value;
2645     } const key_values[] = {
2646         {"mass", 0.02},
2647         {"wiggle", 0.0},
2648         {"angle", 30.0},
2649         {"width", 15},
2650         {"thinning", 0.1},
2651         {"tremor", 0.0},
2652         {"flatness", 0.9},
2653         {"cap_rounding", 0.0}
2654     };
2656     for (unsigned i = 0; i < G_N_ELEMENTS(key_values); ++i) {
2657         KeyValue const &kv = key_values[i];
2658         GtkAdjustment* adj = static_cast<GtkAdjustment *>(g_object_get_data(dataKludge, kv.key));
2659         if ( adj ) {
2660             gtk_adjustment_set_value(adj, kv.value);
2661         }
2662     }
2666 static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2668     {
2669         EgeAdjustmentAction* calligraphy_angle = 0;
2671         {
2672         /* Width */
2673         gchar const* labels[] = {_("(hairline)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad stroke)")};
2674         gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
2675         EgeAdjustmentAction *eact = create_adjustment_action( "CalligraphyWidthAction",
2676                                          _("Width:"), _("The width of the calligraphic pen (relative to the visible canvas area)"),
2677                                          "tools.calligraphic", "width", 15,
2678                                          GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy",
2679                                          1, 100, 1.0, 10.0,
2680                                          labels, values, G_N_ELEMENTS(labels),
2681                                          sp_ddc_width_value_changed,  0.01, 0, 100 );
2682         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2683         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2684         }
2686         {
2687         /* Thinning */
2688             gchar const* labels[] = {_("(speed blows up stroke)"), 0, 0, _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), 0, 0, _("(speed deflates stroke)")};
2689             gdouble values[] = {-1, -0.4, -0.2, -0.1, 0, 0.1, 0.2, 0.4, 1};
2690         EgeAdjustmentAction* eact = create_adjustment_action( "ThinningAction",
2691                                          _("Thinning:"), _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"),
2692                                          "tools.calligraphic", "thinning", 0.1,
2693                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2694                                          -1.0, 1.0, 0.01, 0.1,
2695                                          labels, values, G_N_ELEMENTS(labels),
2696                                          sp_ddc_velthin_value_changed, 0.01, 2);
2697         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2698         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2699         }
2701         {
2702         /* Angle */
2703         gchar const* labels[] = {_("(left edge up)"), 0, 0, _("(horizontal)"), _("(default)"), 0, _("(right edge up)")};
2704         gdouble values[] = {-90, -60, -30, 0, 30, 60, 90};
2705         EgeAdjustmentAction* eact = create_adjustment_action( "AngleAction",
2706                                          _("Angle:"), _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"),
2707                                          "tools.calligraphic", "angle", 30,
2708                                          GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle",
2709                                          -90.0, 90.0, 1.0, 10.0,
2710                                          labels, values, G_N_ELEMENTS(labels),
2711                                          sp_ddc_angle_value_changed, 1, 0 );
2712         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2713         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2714         calligraphy_angle = eact;
2715         }
2717         {
2718         /* Fixation */
2719             gchar const* labels[] = {_("(perpendicular to stroke, \"brush\")"), 0, 0, 0, _("(almost fixed, default)"), _("(fixed by Angle, \"pen\")")};
2720         gdouble values[] = {0, 0.2, 0.4, 0.6, 0.9, 1.0};
2721         EgeAdjustmentAction* eact = create_adjustment_action( "FixationAction",
2722                                          _("Fixation:"), _("Angle behavior (0 = nib always perpendicular to stroke direction, 1 = fixed angle)"),
2723                                          "tools.calligraphic", "flatness", 0.9,
2724                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2725                                          0.0, 1.0, 0.01, 0.1,
2726                                          labels, values, G_N_ELEMENTS(labels),
2727                                          sp_ddc_flatness_value_changed, 0.01, 2 );
2728         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2729         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2730         }
2732         {
2733         /* Cap Rounding */
2734             gchar const* labels[] = {_("(blunt caps, default)"), _("(slightly bulging)"), 0, 0, _("(approximately round)"), _("(long protruding caps)")};
2735         gdouble values[] = {0, 0.3, 0.5, 1.0, 1.4, 5.0};
2736         // TRANSLATORS: "cap" means "end" (both start and finish) here
2737         EgeAdjustmentAction* eact = create_adjustment_action( "CapRoundingAction",
2738                                          _("Caps:"), _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"),
2739                                          "tools.calligraphic", "cap_rounding", 0.0,
2740                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2741                                          0.0, 5.0, 0.01, 0.1,
2742                                          labels, values, G_N_ELEMENTS(labels),
2743                                          sp_ddc_cap_rounding_value_changed, 0.01, 2 );
2744         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2745         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2746         }
2748         {
2749         /* Tremor */
2750             gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), 0, 0, _("(maximum tremor)")};
2751         gdouble values[] = {0, 0.1, 0.2, 0.4, 0.6, 1.0};
2752         EgeAdjustmentAction* eact = create_adjustment_action( "TremorAction",
2753                                          _("Tremor:"), _("Increase to make strokes rugged and trembling"),
2754                                          "tools.calligraphic", "tremor", 0.0,
2755                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2756                                          0.0, 1.0, 0.01, 0.1,
2757                                          labels, values, G_N_ELEMENTS(labels),
2758                                          sp_ddc_tremor_value_changed, 0.01, 2 );
2760         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2761         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2762         }
2764         {
2765         /* Wiggle */
2766         gchar const* labels[] = {_("(no wiggle)"), _("(slight deviation)"), 0, 0, _("(wild waves and curls)")};
2767         gdouble values[] = {0, 0.2, 0.4, 0.6, 1.0};
2768         EgeAdjustmentAction* eact = create_adjustment_action( "WiggleAction",
2769                                          _("Wiggle:"), _("Increase to make the pen waver and wiggle"),
2770                                          "tools.calligraphic", "wiggle", 0.0,
2771                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2772                                          0.0, 1.0, 0.01, 0.1,
2773                                          labels, values, G_N_ELEMENTS(labels),
2774                                          sp_ddc_wiggle_value_changed, 0.01, 2 );
2775         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2776         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2777         }
2779         {
2780         /* Mass */
2781             gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), 0, 0, _("(maximum inertia)")};
2782         gdouble values[] = {0.0, 0.02, 0.1, 0.2, 0.5, 1.0};
2783         EgeAdjustmentAction* eact = create_adjustment_action( "MassAction",
2784                                          _("Mass:"), _("Increase to make the pen drag behind, as if slowed by inertia"),
2785                                          "tools.calligraphic", "mass", 0.02,
2786                                          GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2787                                          0.0, 1.0, 0.01, 0.1,
2788                                          labels, values, G_N_ELEMENTS(labels),
2789                                          sp_ddc_mass_value_changed, 0.01, 2 );
2790         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2791         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2792         }
2795         /* Trace Background button */
2796         {
2797             InkToggleAction* act = ink_toggle_action_new( "TraceAction",
2798                                                           _("Trace Background"),
2799                                                           _("Trace the lightness of the background by the width of the pen (white - minimum width, black - maximum width)"),
2800                                                           "trace_background",
2801                                                           Inkscape::ICON_SIZE_DECORATION );
2802             gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2803             g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_trace_background_changed), NULL);
2804             gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.calligraphic", "tracebackground", 0 ) );
2805         }
2807         /* Use Pressure button */
2808         {
2809             InkToggleAction* act = ink_toggle_action_new( "PressureAction",
2810                                                           _("Pressure"),
2811                                                           _("Use the pressure of the input device to alter the width of the pen"),
2812                                                           "use_pressure",
2813                                                           Inkscape::ICON_SIZE_DECORATION );
2814             gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2815             g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_pressure_state_changed), NULL);
2816             gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.calligraphic", "usepressure", 1 ) );
2817         }
2819         /* Use Tilt button */
2820         {
2821             InkToggleAction* act = ink_toggle_action_new( "TiltAction",
2822                                                           _("Tilt"),
2823                                                           _("Use the tilt of the input device to alter the angle of the pen's nib"),
2824                                                           "use_tilt",
2825                                                           Inkscape::ICON_SIZE_DECORATION );
2826             gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2827             g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_tilt_state_changed), calligraphy_angle );
2828             gtk_action_set_sensitive( GTK_ACTION(calligraphy_angle), !prefs_get_int_attribute( "tools.calligraphic", "usetilt", 1 ) );
2829             gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.calligraphic", "usetilt", 1 ) );
2830         }
2832         /* Reset */
2833         {
2834             GtkAction* act = gtk_action_new( "CalligraphyResetAction",
2835                                              _("Defaults"),
2836                                              _("Reset all parameters to defaults"),
2837                                              GTK_STOCK_CLEAR );
2838             g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_ddc_defaults), holder );
2839             gtk_action_group_add_action( mainActions, act );
2840             gtk_action_set_sensitive( act, TRUE );
2841         }
2842     }
2846 //########################
2847 //##    Circle / Arc    ##
2848 //########################
2850 static void sp_arctb_sensitivize( GObject *tbl, double v1, double v2 )
2852     GtkAction *ocb = GTK_ACTION( g_object_get_data( tbl, "open_action" ) );
2853     GtkAction *make_whole = GTK_ACTION( g_object_get_data( tbl, "make_whole" ) );
2855     if (v1 == 0 && v2 == 0) {
2856         if (g_object_get_data( tbl, "single" )) { // only for a single selected ellipse (for now)
2857             gtk_action_set_sensitive( ocb, FALSE );
2858             gtk_action_set_sensitive( make_whole, FALSE );
2859         }
2860     } else {
2861         gtk_action_set_sensitive( ocb, TRUE );
2862         gtk_action_set_sensitive( make_whole, TRUE );
2863     }
2866 static void
2867 sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name, gchar const *other_name)
2869     SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
2871     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2872         prefs_set_double_attribute("tools.shapes.arc", value_name, (adj->value * M_PI)/ 180);
2873     }
2875     // quit if run by the attr_changed listener
2876     if (g_object_get_data( tbl, "freeze" )) {
2877         return;
2878     }
2880     // in turn, prevent listener from responding
2881     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
2883     gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL);
2885     bool modmade = false;
2886     for (GSList const *items = sp_desktop_selection(desktop)->itemList();
2887          items != NULL;
2888          items = items->next)
2889     {
2890         SPItem *item = SP_ITEM(items->data);
2892         if (SP_IS_ARC(item) && SP_IS_GENERICELLIPSE(item)) {
2894             SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
2895             SPArc *arc = SP_ARC(item);
2897             if (!strcmp(value_name, "start"))
2898                 ge->start = (adj->value * M_PI)/ 180;
2899             else
2900                 ge->end = (adj->value * M_PI)/ 180;
2902             sp_genericellipse_normalize(ge);
2903             ((SPObject *)arc)->updateRepr();
2904             ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
2906             modmade = true;
2907         }
2908     }
2910     g_free(namespaced_name);
2912     GtkAdjustment *other = GTK_ADJUSTMENT( g_object_get_data( tbl, other_name ) );
2914     sp_arctb_sensitivize( tbl, adj->value, other->value );
2916     if (modmade) {
2917         sp_document_maybe_done(sp_desktop_document(desktop), value_name, SP_VERB_CONTEXT_ARC,
2918                                    _("Arc: Change start/end"));
2919     }
2921     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
2925 static void sp_arctb_start_value_changed(GtkAdjustment *adj,  GObject *tbl)
2927     sp_arctb_startend_value_changed(adj,  tbl, "start", "end");
2930 static void sp_arctb_end_value_changed(GtkAdjustment *adj, GObject *tbl)
2932     sp_arctb_startend_value_changed(adj,  tbl, "end", "start");
2935 static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl )
2937     SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
2938     if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2939         if ( ege_select_one_action_get_active( act ) != 0 ) {
2940             prefs_set_string_attribute("tools.shapes.arc", "open", "true");
2941         } else {
2942             prefs_set_string_attribute("tools.shapes.arc", "open", NULL);
2943         }
2944     }
2946     // quit if run by the attr_changed listener
2947     if (g_object_get_data( tbl, "freeze" )) {
2948         return;
2949     }
2951     // in turn, prevent listener from responding
2952     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
2954     bool modmade = false;
2956     if ( ege_select_one_action_get_active(act) != 0 ) {
2957         for (GSList const *items = sp_desktop_selection(desktop)->itemList();
2958              items != NULL;
2959              items = items->next)
2960         {
2961             if (SP_IS_ARC((SPItem *) items->data)) {
2962                 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2963                 repr->setAttribute("sodipodi:open", "true");
2964                 SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
2965                 modmade = true;
2966             }
2967         }
2968     } else {
2969         for (GSList const *items = sp_desktop_selection(desktop)->itemList();
2970              items != NULL;
2971              items = items->next)
2972         {
2973             if (SP_IS_ARC((SPItem *) items->data))    {
2974                 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2975                 repr->setAttribute("sodipodi:open", NULL);
2976                 SP_OBJECT((SPItem *) items->data)->updateRepr(repr, SP_OBJECT_WRITE_EXT);
2977                 modmade = true;
2978             }
2979         }
2980     }
2982     if (modmade) {
2983         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
2984                                    _("Arc: Change open/closed"));
2985     }
2987     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
2990 static void sp_arctb_defaults(GtkWidget *, GObject *obj)
2992     GtkAdjustment *adj;
2993     adj = GTK_ADJUSTMENT( g_object_get_data(obj, "start") );
2994     gtk_adjustment_set_value(adj, 0.0);
2995     gtk_adjustment_value_changed(adj);
2997     adj = GTK_ADJUSTMENT( g_object_get_data(obj, "end") );
2998     gtk_adjustment_set_value(adj, 0.0);
2999     gtk_adjustment_value_changed(adj);
3001     spinbutton_defocus( GTK_OBJECT(obj) );
3004 static void arc_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
3005                                       gchar const *old_value, gchar const *new_value,
3006                                       bool is_interactive, gpointer data)
3008     GObject *tbl = G_OBJECT(data);
3010     // quit if run by the _changed callbacks
3011     if (g_object_get_data( tbl, "freeze" )) {
3012         return;
3013     }
3015     // in turn, prevent callbacks from responding
3016     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
3018     gdouble start = sp_repr_get_double_attribute(repr, "sodipodi:start", 0.0);
3019     gdouble end = sp_repr_get_double_attribute(repr, "sodipodi:end", 0.0);
3021     GtkAdjustment *adj1,*adj2;
3022     adj1 = GTK_ADJUSTMENT( g_object_get_data( tbl, "start" ) );
3023     gtk_adjustment_set_value(adj1, mod360((start * 180)/M_PI));
3024     adj2 = GTK_ADJUSTMENT( g_object_get_data( tbl, "end" ) );
3025     gtk_adjustment_set_value(adj2, mod360((end * 180)/M_PI));
3027     sp_arctb_sensitivize( tbl, adj1->value, adj2->value );
3029     char const *openstr = NULL;
3030     openstr = repr->attribute("sodipodi:open");
3031     EgeSelectOneAction *ocb = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "open_action" ) );
3033     if (openstr) {
3034         ege_select_one_action_set_active( ocb, 1 );
3035     } else {
3036         ege_select_one_action_set_active( ocb, 0 );
3037     }
3039     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
3042 static Inkscape::XML::NodeEventVector arc_tb_repr_events = {
3043     NULL, /* child_added */
3044     NULL, /* child_removed */
3045     arc_tb_event_attr_changed,
3046     NULL, /* content_changed */
3047     NULL  /* order_changed */
3048 };
3051 static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
3053     int n_selected = 0;
3054     Inkscape::XML::Node *repr = NULL;
3056     purge_repr_listener( tbl, tbl );
3058     for (GSList const *items = selection->itemList();
3059          items != NULL;
3060          items = items->next)
3061     {
3062         if (SP_IS_ARC((SPItem *) items->data)) {
3063             n_selected++;
3064             repr = SP_OBJECT_REPR((SPItem *) items->data);
3065         }
3066     }
3068     EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
3070     g_object_set_data( tbl, "single", GINT_TO_POINTER(FALSE) );
3071     if (n_selected == 0) {
3072         g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
3073     } else if (n_selected == 1) {
3074         g_object_set_data( tbl, "single", GINT_TO_POINTER(TRUE) );
3075         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3077         if (repr) {
3078             g_object_set_data( tbl, "repr", repr );
3079             Inkscape::GC::anchor(repr);
3080             sp_repr_add_listener(repr, &arc_tb_repr_events, tbl);
3081             sp_repr_synthesize_events(repr, &arc_tb_repr_events, tbl);
3082         }
3083     } else {
3084         // FIXME: implement averaging of all parameters for multiple selected
3085         //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
3086         g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3087         sp_arctb_sensitivize( tbl, 1, 0 );
3088     }
3092 static void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
3094     EgeAdjustmentAction* eact = 0;
3097     {
3098         EgeOutputAction* act = ege_output_action_new( "ArcStateAction", _("<b>New:</b>"), "", 0 );
3099         ege_output_action_set_use_markup( act, TRUE );
3100         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3101         g_object_set_data( holder, "mode_action", act );
3102     }
3104     /* Start */
3105     {
3106         eact = create_adjustment_action( "ArcStartAction",
3107                                          _("Start:"), _("The angle (in degrees) from the horizontal to the arc's start point"),
3108                                          "tools.shapes.arc", "start", 0.0,
3109                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-arc",
3110                                          -360.0, 360.0, 1.0, 10.0,
3111                                          0, 0, 0,
3112                                          sp_arctb_start_value_changed);
3113         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3114     }
3116     /* End */
3117     {
3118         eact = create_adjustment_action( "ArcEndAction",
3119                                          _("End:"), _("The angle (in degrees) from the horizontal to the arc's end point"),
3120                                          "tools.shapes.arc", "end", 0.0,
3121                                          GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
3122                                          -360.0, 360.0, 1.0, 10.0,
3123                                          0, 0, 0,
3124                                          sp_arctb_end_value_changed);
3125         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3126     }
3128     /* Segments / Pie checkbox */
3129     {
3130         GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
3132         GtkTreeIter iter;
3133         gtk_list_store_append( model, &iter );
3134         gtk_list_store_set( model, &iter,
3135                             0, _("Closed arc"),
3136                             1, _("Switch to segment (closed shape with two radii)"),
3137                             2, "circle_closed_arc",
3138                             -1 );
3140         gtk_list_store_append( model, &iter );
3141         gtk_list_store_set( model, &iter,
3142                             0, _("Open Arc"),
3143                             1, _("Switch to arc (unclosed shape)"),
3144                             2, "circle_open_arc",
3145                             -1 );
3147         EgeSelectOneAction* act = ege_select_one_action_new( "ArcOpenAction", _(""), _(""), NULL, GTK_TREE_MODEL(model) );
3148         gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
3149         g_object_set_data( holder, "open_action", act );
3151         ege_select_one_action_set_appearance( act, "full" );
3152         ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
3153         g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
3154         ege_select_one_action_set_icon_column( act, 2 );
3155         ege_select_one_action_set_tooltip_column( act, 1  );
3157         gchar const *openstr = prefs_get_string_attribute("tools.shapes.arc", "open");
3158         bool isClosed = (!openstr || (openstr && !strcmp(openstr, "false")));
3159         ege_select_one_action_set_active( act, isClosed ? 0 : 1 );
3160         g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_arctb_open_state_changed), holder );
3161     }
3163     /* Make Whole */
3164     {
3165         InkAction* inky = ink_action_new( "ArcResetAction",
3166                                           _("Make whole"),
3167                                           _("Make the shape a whole ellipse, not arc or segment"),
3168                                           "reset_circle",
3169                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
3170         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_arctb_defaults), holder );
3171         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
3172         gtk_action_set_sensitive( GTK_ACTION(inky), TRUE );
3173         g_object_set_data( holder, "make_whole", inky );
3174     }
3176     g_object_set_data( G_OBJECT(holder), "single", GINT_TO_POINTER(TRUE) );
3177     // sensitivize make whole and open checkbox
3178     {
3179         GtkAdjustment *adj1 = GTK_ADJUSTMENT( g_object_get_data( holder, "start" ) );
3180         GtkAdjustment *adj2 = GTK_ADJUSTMENT( g_object_get_data( holder, "end" ) );
3181         sp_arctb_sensitivize( holder, adj1->value, adj2->value );
3182     }
3185     sigc::connection *connection = new sigc::connection(
3186         sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_arc_toolbox_selection_changed), (GObject *)holder))
3187         );
3188     g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
3189     g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
3195 // toggle button callbacks and updaters
3197 //########################
3198 //##      Dropper       ##
3199 //########################
3201 static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl ) {
3202     prefs_set_int_attribute( "tools.dropper", "pick", gtk_toggle_action_get_active( act ) );
3203     GtkAction* set_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "set_action") );
3204     if ( set_action ) {
3205         if ( gtk_toggle_action_get_active( act ) ) {
3206             gtk_action_set_sensitive( set_action, TRUE );
3207         } else {
3208             gtk_action_set_sensitive( set_action, FALSE );
3209         }
3210     }
3212     spinbutton_defocus(GTK_OBJECT(tbl));
3215 static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl ) {
3216     prefs_set_int_attribute( "tools.dropper", "setalpha", gtk_toggle_action_get_active( act ) ? 1 : 0 );
3217     spinbutton_defocus(GTK_OBJECT(tbl));
3221 /**
3222  * Dropper auxiliary toolbar construction and setup.
3223  *
3224  * TODO: Would like to add swatch of current color.
3225  * TODO: Add queue of last 5 or so colors selected with new swatches so that
3226  *       can drag and drop places. Will provide a nice mixing palette.
3227  */
3228 static void sp_dropper_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
3230     gint pickAlpha = prefs_get_int_attribute( "tools.dropper", "pick", 1 );
3232     {
3233         InkToggleAction* act = ink_toggle_action_new( "DropperPickAlphaAction",
3234                                                       _("Pick alpha"),
3235                                                       _("Pick both the color and the alpha (transparency) under cursor; otherwise, pick only the visible color premultiplied by alpha"),
3236                                                       "color_alpha_get",
3237                                                       Inkscape::ICON_SIZE_DECORATION );
3238         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3239         g_object_set_data( holder, "pick_action", act );
3240         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), pickAlpha );
3241         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_pick_alpha), holder );
3242     }
3244     {
3245         InkToggleAction* act = ink_toggle_action_new( "DropperSetAlphaAction",
3246                                                       _("Set alpha"),
3247                                                       _("If alpha was picked, assign it to selection as fill or stroke transparency"),
3248                                                       "color_alpha_set",
3249                                                       Inkscape::ICON_SIZE_DECORATION );
3250         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3251         g_object_set_data( holder, "set_action", act );
3252         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.dropper", "setalpha", 1 ) );
3253         // make sure it's disabled if we're not picking alpha
3254         gtk_action_set_sensitive( GTK_ACTION(act), pickAlpha );
3255         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_set_alpha), holder );
3256     }
3260 //########################
3261 //##    Text Toolbox    ##
3262 //########################
3263 /*
3264 static void
3265 sp_text_letter_changed(GtkAdjustment *adj, GtkWidget *tbl)
3267     //Call back for letter sizing spinbutton
3270 static void
3271 sp_text_line_changed(GtkAdjustment *adj, GtkWidget *tbl)
3273     //Call back for line height spinbutton
3276 static void
3277 sp_text_horiz_kern_changed(GtkAdjustment *adj, GtkWidget *tbl)
3279     //Call back for horizontal kerning spinbutton
3282 static void
3283 sp_text_vert_kern_changed(GtkAdjustment *adj, GtkWidget *tbl)
3285     //Call back for vertical kerning spinbutton
3288 static void
3289 sp_text_letter_rotation_changed(GtkAdjustment *adj, GtkWidget *tbl)
3291     //Call back for letter rotation spinbutton
3292 }*/
3294 namespace {
3296 bool visible = false;
3298 void
3299 sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl)
3301     SPStyle *query =
3302         sp_style_new (SP_ACTIVE_DOCUMENT);
3304     int result_family =
3305         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
3307     int result_style =
3308         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
3310     int result_numbers =
3311         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3313     gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
3315     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3316     if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING)
3317     {
3318         Inkscape::XML::Node *repr = inkscape_get_repr (INKSCAPE, "tools.text");
3320         if (repr)
3321         {
3322             sp_style_read_from_repr (query, repr);
3323         }
3324         else
3325         {
3326             return;
3327         }
3328     }
3330     if (query->text)
3331     {
3332         if (result_family == QUERY_STYLE_MULTIPLE_DIFFERENT) {
3333             GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry"));
3334             gtk_entry_set_text (GTK_ENTRY (entry), "");
3336         } else if (query->text->font_family.value) {
3338             GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry"));
3339             gtk_entry_set_text (GTK_ENTRY (entry), query->text->font_family.value);
3341             Gtk::TreePath path;
3342             try {
3343                 path = Inkscape::FontLister::get_instance()->get_row_for_font (query->text->font_family.value);
3344             } catch (...) {
3345                 return;
3346             }
3348             GtkTreeSelection *tselection = GTK_TREE_SELECTION (g_object_get_data (G_OBJECT(tbl), "family-tree-selection"));
3349             GtkTreeView *treeview = GTK_TREE_VIEW (g_object_get_data (G_OBJECT(tbl), "family-tree-view"));
3351             g_object_set_data (G_OBJECT (tselection), "block", gpointer(1));
3353             gtk_tree_selection_select_path (tselection, path.gobj());
3354             gtk_tree_view_scroll_to_cell (treeview, path.gobj(), NULL, TRUE, 0.5, 0.0);
3356             g_object_set_data (G_OBJECT (tselection), "block", gpointer(0));
3357         }
3359         //Size
3360         GtkWidget *cbox = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "combo-box-size"));
3361         char *str = g_strdup_printf ("%.5g", query->font_size.computed);
3362         g_object_set_data (tbl, "size-block", gpointer(1));
3363         gtk_entry_set_text (GTK_ENTRY(GTK_BIN (cbox)->child), str);
3364         g_object_set_data (tbl, "size-block", gpointer(0));
3365         free (str);
3367         //Anchor
3368         if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY)
3369         {
3370             GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-fill"));
3371             g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3372             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
3373             g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3374         }
3375         else
3376         {
3377             if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START)
3378             {
3379                 GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-start"));
3380                 g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3381                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
3382                 g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3383             }
3384             else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE)
3385             {
3386                 GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-middle"));
3387                 g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3388                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
3389                 g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3390             }
3391             else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END)
3392             {
3393                 GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-end"));
3394                 g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3395                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
3396                 g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3397             }
3398         }
3400         //Style
3401         {
3402             GtkToggleButton *button = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (tbl), "style-bold"));
3404             gboolean active = gtk_toggle_button_get_active (button);
3405             gboolean check  = (query->font_weight.computed >= SP_CSS_FONT_WEIGHT_700);
3407             if (active != check)
3408             {
3409                 g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3410                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), check);
3411                 g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3412             }
3413         }
3415         {
3416             GtkToggleButton *button = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (tbl), "style-italic"));
3418             gboolean active = gtk_toggle_button_get_active (button);
3419             gboolean check  = (query->font_style.computed != SP_CSS_FONT_STYLE_NORMAL);
3421             if (active != check)
3422             {
3423                 g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3424                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), check);
3425                 g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3426             }
3427         }
3429         //Orientation
3430         //locking both buttons, changing one affect all group (both)
3431         GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "orientation-horizontal"));
3432         g_object_set_data (G_OBJECT (button), "block", gpointer(1));
3434         GtkWidget *button1 = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "orientation-vertical"));
3435         g_object_set_data (G_OBJECT (button1), "block", gpointer(1));
3437         if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB)
3438         {
3439             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
3440         }
3441         else
3442         {
3443             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button1), TRUE);
3444         }
3445         g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3446         g_object_set_data (G_OBJECT (button1), "block", gpointer(0));
3447     }
3449     sp_style_unref(query);
3452 void
3453 sp_text_toolbox_selection_modified (Inkscape::Selection *selection, guint flags, GObject *tbl)
3455     sp_text_toolbox_selection_changed (selection, tbl);
3458 void
3459 sp_text_toolbox_subselection_changed (gpointer dragger, GObject *tbl)
3461     sp_text_toolbox_selection_changed (NULL, tbl);
3464 void
3465 sp_text_toolbox_family_changed (GtkTreeSelection    *selection,
3466                                 GObject             *tbl)
3468     SPDesktop    *desktop = SP_ACTIVE_DESKTOP;
3469     GtkTreeModel *model = 0;
3470     GtkWidget    *popdown = GTK_WIDGET (g_object_get_data (tbl, "family-popdown-window"));
3471     GtkWidget    *entry = GTK_WIDGET (g_object_get_data (tbl, "family-entry"));
3472     GtkTreeIter   iter;
3473     char         *family = 0;
3475     gdk_pointer_ungrab (GDK_CURRENT_TIME);
3476     gdk_keyboard_ungrab (GDK_CURRENT_TIME);
3478     if ( !gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
3479         return;
3480     }
3482     gtk_tree_model_get (model, &iter, 0, &family, -1);
3484     if (g_object_get_data (G_OBJECT (selection), "block"))
3485     {
3486         gtk_entry_set_text (GTK_ENTRY (entry), family);
3487         return;
3488     }
3490     gtk_widget_hide (popdown);
3491     visible = false;
3493     gtk_entry_set_text (GTK_ENTRY (entry), family);
3495     SPStyle *query =
3496         sp_style_new (SP_ACTIVE_DOCUMENT);
3498     int result_numbers =
3499         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3501     SPCSSAttr *css = sp_repr_css_attr_new ();
3502     sp_repr_css_set_property (css, "font-family", family);
3504     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3505     if (result_numbers == QUERY_STYLE_NOTHING)
3506     {
3507         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
3508         sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace trough a verb
3509     }
3510     else
3511     {
3512         sp_desktop_set_style (desktop, css, true, true);
3513     }
3515     sp_style_unref(query);
3517     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
3518                                    _("Text: Change font family"));
3519     sp_repr_css_attr_unref (css);
3520     free (family);
3521     gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
3523     gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3526 void
3527 sp_text_toolbox_family_entry_activate (GtkEntry     *entry,
3528                                        GObject      *tbl)
3530     const char *family = gtk_entry_get_text (entry);
3532     try {
3533         Gtk::TreePath path = Inkscape::FontLister::get_instance()->get_row_for_font (family);
3534         GtkTreeSelection *selection = GTK_TREE_SELECTION (g_object_get_data (G_OBJECT(tbl), "family-tree-selection"));
3535         GtkTreeView *treeview = GTK_TREE_VIEW (g_object_get_data (G_OBJECT(tbl), "family-tree-view"));
3536         gtk_tree_selection_select_path (selection, path.gobj());
3537         gtk_tree_view_scroll_to_cell (treeview, path.gobj(), NULL, TRUE, 0.5, 0.0);
3538         gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
3539     } catch (...) {
3540         if (family && strlen (family))
3541         {
3542             gtk_widget_show_all (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
3543         }
3544     }
3547 void
3548 sp_text_toolbox_anchoring_toggled (GtkRadioButton   *button,
3549                                    gpointer          data)
3551     if (g_object_get_data (G_OBJECT (button), "block")) return;
3552     if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) return;
3553     int prop = GPOINTER_TO_INT(data);
3555     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3556     SPCSSAttr *css = sp_repr_css_attr_new ();
3558     switch (prop)
3559     {
3560         case 0:
3561         {
3562             sp_repr_css_set_property (css, "text-anchor", "start");
3563             sp_repr_css_set_property (css, "text-align", "start");
3564             break;
3565         }
3566         case 1:
3567         {
3568             sp_repr_css_set_property (css, "text-anchor", "middle");
3569             sp_repr_css_set_property (css, "text-align", "center");
3570             break;
3571         }
3573         case 2:
3574         {
3575             sp_repr_css_set_property (css, "text-anchor", "end");
3576             sp_repr_css_set_property (css, "text-align", "end");
3577             break;
3578         }
3580         case 3:
3581         {
3582             sp_repr_css_set_property (css, "text-anchor", "start");
3583             sp_repr_css_set_property (css, "text-align", "justify");
3584             break;
3585         }
3586     }
3588     SPStyle *query =
3589         sp_style_new (SP_ACTIVE_DOCUMENT);
3590     int result_numbers =
3591         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3593     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3594     if (result_numbers == QUERY_STYLE_NOTHING)
3595     {
3596         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
3597     }
3599     sp_style_unref(query);
3601     sp_desktop_set_style (desktop, css, true, true);
3602     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
3603                                    _("Text: Change alignment"));
3604     sp_repr_css_attr_unref (css);
3606     gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3609 void
3610 sp_text_toolbox_style_toggled (GtkToggleButton  *button,
3611                                gpointer          data)
3613     if (g_object_get_data (G_OBJECT (button), "block")) return;
3615     SPDesktop   *desktop    = SP_ACTIVE_DESKTOP;
3616     SPCSSAttr   *css        = sp_repr_css_attr_new ();
3617     int          prop       = GPOINTER_TO_INT(data);
3618     bool         active     = gtk_toggle_button_get_active (button);
3621     switch (prop)
3622     {
3623         case 0:
3624         {
3625             sp_repr_css_set_property (css, "font-weight", active ? "bold" : "normal" );
3626             break;
3627         }
3629         case 1:
3630         {
3631             sp_repr_css_set_property (css, "font-style", active ? "italic" : "normal");
3632             break;
3633         }
3634     }
3636     SPStyle *query =
3637         sp_style_new (SP_ACTIVE_DOCUMENT);
3638     int result_numbers =
3639         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3641     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3642     if (result_numbers == QUERY_STYLE_NOTHING)
3643     {
3644         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
3645     }
3647     sp_style_unref(query);
3649     sp_desktop_set_style (desktop, css, true, true);
3650     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
3651                                    _("Text: Change font style"));
3652     sp_repr_css_attr_unref (css);
3654     gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3657 void
3658 sp_text_toolbox_orientation_toggled (GtkRadioButton  *button,
3659                                      gpointer         data)
3661     if (g_object_get_data (G_OBJECT (button), "block")) {
3662         g_object_set_data (G_OBJECT (button), "block", gpointer(0));
3663         return;
3664     }
3666     SPDesktop   *desktop    = SP_ACTIVE_DESKTOP;
3667     SPCSSAttr   *css        = sp_repr_css_attr_new ();
3668     int          prop       = GPOINTER_TO_INT(data);
3670     switch (prop)
3671     {
3672         case 0:
3673         {
3674             sp_repr_css_set_property (css, "writing-mode", "lr");
3675             break;
3676         }
3678         case 1:
3679         {
3680             sp_repr_css_set_property (css, "writing-mode", "tb");
3681             break;
3682         }
3683     }
3685     SPStyle *query =
3686         sp_style_new (SP_ACTIVE_DOCUMENT);
3687     int result_numbers =
3688         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3690     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3691     if (result_numbers == QUERY_STYLE_NOTHING)
3692     {
3693         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
3694     }
3696     sp_desktop_set_style (desktop, css, true, true);
3697     sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
3698                                    _("Text: Change orientation"));
3699     sp_repr_css_attr_unref (css);
3701     gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3704 gboolean
3705 sp_text_toolbox_size_keypress (GtkWidget *w, GdkEventKey *event, gpointer data)
3707     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3708     if (!desktop) return FALSE;
3710     switch (get_group0_keyval (event)) {
3711         case GDK_Escape: // defocus
3712             gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3713             return TRUE; // I consumed the event
3714             break;
3715         case GDK_Return: // defocus
3716         case GDK_KP_Enter:
3717             gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3718             return TRUE; // I consumed the event
3719             break;
3720     }
3721     return FALSE;
3724 gboolean
3725 sp_text_toolbox_family_keypress (GtkWidget *w, GdkEventKey *event, GObject *tbl)
3727     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3728     if (!desktop) return FALSE;
3730     switch (get_group0_keyval (event)) {
3731         case GDK_Escape: // defocus
3732             gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3733             sp_text_toolbox_selection_changed (NULL, tbl); // update
3734             return TRUE; // I consumed the event
3735             break;
3736     }
3737     return FALSE;
3740 gboolean
3741 sp_text_toolbox_family_list_keypress (GtkWidget *w, GdkEventKey *event, GObject *tbl)
3743     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3744     if (!desktop) return FALSE;
3746     switch (get_group0_keyval (event)) {
3747         case GDK_Escape: // defocus
3748             gtk_widget_hide (w);
3749             visible = false;
3750             gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3751             return TRUE; // I consumed the event
3752             break;
3753     }
3754     return FALSE;
3758 void
3759 sp_text_toolbox_size_changed  (GtkComboBox *cbox,
3760                                GObject     *tbl)
3762     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3764     if (g_object_get_data (tbl, "size-block")) return;
3766 #if GTK_CHECK_VERSION(2,6,0)
3767     char *text = gtk_combo_box_get_active_text (cbox);
3768 #else // GTK_CHECK_VERSION(2,6,0)
3769     GtkTreeModel *model = gtk_combo_box_get_model (cbox);
3770     GtkTreeIter iter;
3771     char *text = NULL;
3773     if (gtk_combo_box_get_active_iter (cbox, &iter) && model)
3774         gtk_tree_model_get (model, &iter, 0, &text, -1);
3775 #endif // GTK_CHECK_VERSION(2,6,0)
3777     SPCSSAttr *css = sp_repr_css_attr_new ();
3778     sp_repr_css_set_property (css, "font-size", text);
3779     free (text);
3781     SPStyle *query =
3782         sp_style_new (SP_ACTIVE_DOCUMENT);
3783     int result_numbers =
3784         sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
3786     // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
3787     if (result_numbers == QUERY_STYLE_NOTHING)
3788     {
3789         sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
3790     }
3792     sp_style_unref(query);
3794     sp_desktop_set_style (desktop, css, true, true);
3795     sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE,
3796                                    _("Text: Change font size"));
3797     sp_repr_css_attr_unref (css);
3800     if (gtk_combo_box_get_active (cbox) > 0) // if this was from drop-down (as opposed to type-in), defocus
3801         gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3804 void
3805 sp_text_toolbox_text_popdown_clicked    (GtkButton          *button,
3806                                          GObject            *tbl)
3808     GtkWidget *popdown = GTK_WIDGET (g_object_get_data (tbl, "family-popdown-window"));
3809     GtkWidget *widget = GTK_WIDGET (g_object_get_data (tbl, "family-entry"));
3810     int x, y;
3812     if (!visible)
3813     {
3814         gdk_window_get_origin (widget->window, &x, &y);
3815         gtk_window_move (GTK_WINDOW (popdown), x, y + widget->allocation.height + 2); //2px of grace space
3816         gtk_widget_show_all (popdown);
3818         gdk_pointer_grab (widget->window, TRUE,
3819                           GdkEventMask (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
3820                                         GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
3821                                         GDK_POINTER_MOTION_MASK),
3822                           NULL, NULL, GDK_CURRENT_TIME);
3824         gdk_keyboard_grab (widget->window, TRUE, GDK_CURRENT_TIME);
3826         visible = true;
3827     }
3828     else
3829     {
3830         gdk_pointer_ungrab (GDK_CURRENT_TIME);
3831         gdk_keyboard_ungrab (GDK_CURRENT_TIME);
3832         gtk_widget_hide (popdown);
3833         visible = false;
3834     }
3837 gboolean
3838 sp_text_toolbox_entry_focus_in  (GtkWidget        *entry,
3839                                  GdkEventFocus    *event,
3840                                  GObject          *tbl)
3842     gtk_entry_select_region (GTK_ENTRY (entry), 0, -1);
3843     return FALSE;
3846 gboolean
3847 sp_text_toolbox_popdown_focus_out (GtkWidget        *popdown,
3848                                    GdkEventFocus    *event,
3849                                    GObject          *tbl)
3851     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
3853     gtk_widget_hide (popdown);
3854     visible = false;
3855     gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
3856     return TRUE;
3859 void
3860 cell_data_func  (GtkTreeViewColumn *column,
3861                  GtkCellRenderer   *cell,
3862                  GtkTreeModel      *tree_model,
3863                  GtkTreeIter       *iter,
3864                  gpointer           data)
3866     char        *family,
3867         *family_escaped,
3868         *sample_escaped;
3870     static const char *sample = _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()");
3872     gtk_tree_model_get (tree_model, iter, 0, &family, -1);
3874     family_escaped = g_markup_escape_text (family, -1);
3875     sample_escaped = g_markup_escape_text (sample, -1);
3877     std::stringstream markup;
3878     markup << family_escaped << "  <span foreground='darkgray' font_family='" << family_escaped << "'>" << sample_escaped << "</span>";
3879     g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL);
3881     free (family);
3882     free (family_escaped);
3883     free (sample_escaped);
3886 static void delete_completion(GObject *obj, GtkWidget *entry) {
3887     GObject *completion = (GObject *) gtk_object_get_data(GTK_OBJECT(entry), "completion");
3888     if (completion) {
3889         gtk_entry_set_completion (GTK_ENTRY(entry), NULL);
3890         g_object_unref (completion);
3891     }
3894 GtkWidget*
3895 sp_text_toolbox_new (SPDesktop *desktop)
3897     GtkWidget   *tbl = gtk_hbox_new (FALSE, 0);
3899     gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas);
3900     gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop);
3902     GtkTooltips *tt = gtk_tooltips_new();
3903     Glib::RefPtr<Gtk::ListStore> store = Inkscape::FontLister::get_instance()->get_font_list();
3905     ////////////Family
3906     //Window
3907     GtkWidget   *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3908     gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
3910     //Entry
3911     GtkWidget           *entry = gtk_entry_new ();
3912     gtk_object_set_data(GTK_OBJECT(entry), "altx-text", entry);
3913     GtkEntryCompletion  *completion = gtk_entry_completion_new ();
3914     gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (Glib::unwrap(store)));
3915     gtk_entry_completion_set_text_column (completion, 0);
3916     gtk_entry_completion_set_minimum_key_length (completion, 1);
3917     g_object_set (G_OBJECT(completion), "inline-completion", TRUE, "popup-completion", TRUE, NULL);
3918     gtk_entry_set_completion (GTK_ENTRY(entry), completion);
3919     gtk_object_set_data(GTK_OBJECT(entry), "completion", completion);
3920     aux_toolbox_space (tbl, 1);
3921     gtk_box_pack_start (GTK_BOX (tbl), entry, FALSE, FALSE, 0);
3922     g_signal_connect(G_OBJECT(tbl), "destroy", G_CALLBACK(delete_completion), entry);
3924     //Button
3925     GtkWidget   *button = gtk_button_new ();
3926     gtk_container_add       (GTK_CONTAINER (button), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE));
3927     gtk_box_pack_start      (GTK_BOX (tbl), button, FALSE, FALSE, 0);
3929     //Popdown
3930     GtkWidget           *sw = gtk_scrolled_window_new (NULL, NULL);
3931     GtkWidget           *treeview = gtk_tree_view_new ();
3933     GtkCellRenderer     *cell = gtk_cell_renderer_text_new ();
3934     GtkTreeViewColumn   *column = gtk_tree_view_column_new ();
3935     gtk_tree_view_column_pack_start (column, cell, FALSE);
3936     gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
3937     gtk_tree_view_column_set_cell_data_func (column, cell, GtkTreeCellDataFunc (cell_data_func), NULL, NULL);
3938     gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
3940     gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (Glib::unwrap(store)));
3941     gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
3942 #if GTK_CHECK_VERSION(2,6,0)
3943     gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (treeview), TRUE);
3944 #endif // GTK_CHECK_VERSION(2,6,0)
3946     //gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), TRUE);
3948     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3949     gtk_container_add (GTK_CONTAINER (sw), treeview);
3951     gtk_container_add (GTK_CONTAINER (window), sw);
3952     gtk_widget_set_size_request (window, 300, 450);
3954     g_signal_connect (G_OBJECT (entry),  "activate", G_CALLBACK (sp_text_toolbox_family_entry_activate), tbl);
3955     g_signal_connect (G_OBJECT (entry),  "focus-in-event", G_CALLBACK (sp_text_toolbox_entry_focus_in), tbl);
3956     g_signal_connect (G_OBJECT (entry), "key-press-event", G_CALLBACK(sp_text_toolbox_family_keypress), tbl);
3958     g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (sp_text_toolbox_text_popdown_clicked), tbl);
3960     g_signal_connect (G_OBJECT (window), "focus-out-event", G_CALLBACK (sp_text_toolbox_popdown_focus_out), tbl);
3961     g_signal_connect (G_OBJECT (window), "key-press-event", G_CALLBACK(sp_text_toolbox_family_list_keypress), tbl);
3963     GtkTreeSelection *tselection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
3964     g_signal_connect (G_OBJECT (tselection), "changed", G_CALLBACK (sp_text_toolbox_family_changed), tbl);
3966     g_object_set_data (G_OBJECT (tbl), "family-entry", entry);
3967     g_object_set_data (G_OBJECT (tbl), "family-popdown-button", button);
3968     g_object_set_data (G_OBJECT (tbl), "family-popdown-window", window);
3969     g_object_set_data (G_OBJECT (tbl), "family-tree-selection", tselection);
3970     g_object_set_data (G_OBJECT (tbl), "family-tree-view", treeview);
3972     GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
3973     aux_toolbox_space (tbl, 1);
3974     GtkWidget *box = gtk_event_box_new ();
3975     gtk_container_add (GTK_CONTAINER (box), image);
3976     gtk_box_pack_start (GTK_BOX (tbl), box, FALSE, FALSE, 4);
3977     g_object_set_data (G_OBJECT (tbl), "warning-image", box);
3978     GtkTooltips *tooltips = gtk_tooltips_new ();
3979     gtk_tooltips_set_tip (tooltips, box, _("This font is currently not installed on your system. Inkscape will use the default font instead."), "");
3980     gtk_widget_hide (GTK_WIDGET (box));
3981     g_signal_connect_swapped (G_OBJECT (tbl), "show", G_CALLBACK (gtk_widget_hide), box);
3983     ////////////Size
3984     const char *sizes[] = {
3985         "4", "6", "8", "9", "10", "11", "12", "13", "14",
3986         "16", "18", "20", "22", "24", "28",
3987         "32", "36", "40", "48", "56", "64", "72", "144"
3988     };
3990     GtkWidget *cbox = gtk_combo_box_entry_new_text ();
3991     for (unsigned int n = 0; n < G_N_ELEMENTS (sizes); gtk_combo_box_append_text (GTK_COMBO_BOX(cbox), sizes[n++]));
3992     gtk_widget_set_size_request (cbox, 80, -1);
3993     aux_toolbox_space (tbl, 1);
3994     gtk_box_pack_start (GTK_BOX (tbl), cbox, FALSE, FALSE, 0);
3995     g_object_set_data (G_OBJECT (tbl), "combo-box-size", cbox);
3996     g_signal_connect (G_OBJECT (cbox), "changed", G_CALLBACK (sp_text_toolbox_size_changed), tbl);
3997     gtk_signal_connect(GTK_OBJECT(cbox), "key-press-event", GTK_SIGNAL_FUNC(sp_text_toolbox_size_keypress), NULL);
3999     //spacer
4000     aux_toolbox_space (tbl, 4);
4001     gtk_box_pack_start (GTK_BOX (tbl), gtk_vseparator_new (), FALSE, FALSE, 4);
4003     ////////////Text anchor
4004     GtkWidget *group   = gtk_radio_button_new (NULL);
4005     GtkWidget *row     = gtk_hbox_new (FALSE, 4);
4006     g_object_set_data (G_OBJECT (tbl), "anchor-group", group);
4008     // left
4009     GtkWidget *rbutton = group;
4010     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4011     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_LEFT, GTK_ICON_SIZE_SMALL_TOOLBAR));
4012     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4014     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4015     g_object_set_data   (G_OBJECT (tbl), "text-start", rbutton);
4016     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(0));
4017     gtk_tooltips_set_tip(tt, rbutton, _("Align left"), NULL);
4019     // center
4020     rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
4021     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4022     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_CENTER, GTK_ICON_SIZE_SMALL_TOOLBAR));
4023     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4025     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4026     g_object_set_data   (G_OBJECT (tbl), "text-middle", rbutton);
4027     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer (1));
4028     gtk_tooltips_set_tip(tt, rbutton, _("Center"), NULL);
4030     // right
4031     rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
4032     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4033     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_RIGHT, GTK_ICON_SIZE_SMALL_TOOLBAR));
4034     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4036     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4037     g_object_set_data   (G_OBJECT (tbl), "text-end", rbutton);
4038     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(2));
4039     gtk_tooltips_set_tip(tt, rbutton, _("Align right"), NULL);
4041     // fill
4042     rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
4043     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4044     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_FILL, GTK_ICON_SIZE_SMALL_TOOLBAR));
4045     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4047     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4048     g_object_set_data   (G_OBJECT (tbl), "text-fill", rbutton);
4049     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(3));
4050     gtk_tooltips_set_tip(tt, rbutton, _("Justify"), NULL);
4052     aux_toolbox_space (tbl, 1);
4053     gtk_box_pack_start (GTK_BOX (tbl), row, FALSE, FALSE, 4);
4055     //spacer
4056     gtk_box_pack_start (GTK_BOX (tbl), gtk_vseparator_new (), FALSE, FALSE, 4);
4058     ////////////Text style
4059     row = gtk_hbox_new (FALSE, 4);
4061     // bold
4062     rbutton = gtk_toggle_button_new ();
4063     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4064     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_BOLD, GTK_ICON_SIZE_SMALL_TOOLBAR));
4065     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4066     gtk_tooltips_set_tip(tt, rbutton, _("Bold"), NULL);
4068     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4069     g_object_set_data   (G_OBJECT (tbl), "style-bold", rbutton);
4070     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_style_toggled), gpointer(0));
4072     // italic
4073     rbutton = gtk_toggle_button_new ();
4074     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4075     gtk_container_add           (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_ITALIC, GTK_ICON_SIZE_SMALL_TOOLBAR));
4076     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4077     gtk_tooltips_set_tip(tt, rbutton, _("Italic"), NULL);
4079     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4080     g_object_set_data   (G_OBJECT (tbl), "style-italic", rbutton);
4081     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_style_toggled), gpointer (1));
4083     aux_toolbox_space (tbl, 1);
4084     gtk_box_pack_start (GTK_BOX (tbl), row, FALSE, FALSE, 4);
4086     //spacer
4087     gtk_box_pack_start (GTK_BOX (tbl), gtk_vseparator_new (), FALSE, FALSE, 4);
4089     ////////////Text orientation
4090     group   = gtk_radio_button_new (NULL);
4091     row     = gtk_hbox_new (FALSE, 4);
4092     g_object_set_data (G_OBJECT (tbl), "orientation-group", group);
4094     // horizontal
4095     rbutton = group;
4096     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4097     gtk_container_add           (GTK_CONTAINER (rbutton), sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_WRITING_MODE_LR));
4098     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4099     gtk_tooltips_set_tip(tt, rbutton, _("Horizontal text"), NULL);
4101     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4102     g_object_set_data   (G_OBJECT (tbl), "orientation-horizontal", rbutton);
4103     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_orientation_toggled), gpointer(0));
4105     // vertical
4106     rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
4107     gtk_button_set_relief       (GTK_BUTTON (rbutton), GTK_RELIEF_NONE);
4108     gtk_container_add           (GTK_CONTAINER (rbutton), sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_WRITING_MODE_TB));
4109     gtk_toggle_button_set_mode  (GTK_TOGGLE_BUTTON (rbutton), FALSE);
4110     gtk_tooltips_set_tip(tt, rbutton, _("Vertical text"), NULL);
4112     gtk_box_pack_start  (GTK_BOX  (row), rbutton, FALSE, FALSE, 0);
4113     g_object_set_data   (G_OBJECT (tbl), "orientation-vertical", rbutton);
4114     g_signal_connect    (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_orientation_toggled), gpointer (1));
4115     gtk_box_pack_start (GTK_BOX (tbl), row, FALSE, FALSE, 4);
4118     //watch selection
4119     Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISTextToolbox");
4121     sigc::connection *c_selection_changed =
4122         new sigc::connection (sp_desktop_selection (desktop)->connectChanged
4123                               (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)tbl)));
4124     pool->add_connection ("selection-changed", c_selection_changed);
4126     sigc::connection *c_selection_modified =
4127         new sigc::connection (sp_desktop_selection (desktop)->connectModified
4128                               (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)tbl)));
4129     pool->add_connection ("selection-modified", c_selection_modified);
4131     sigc::connection *c_subselection_changed =
4132         new sigc::connection (desktop->connectToolSubselectionChanged
4133                               (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)tbl)));
4134     pool->add_connection ("tool-subselection-changed", c_subselection_changed);
4136     Inkscape::ConnectionPool::connect_destroy (G_OBJECT (tbl), pool);
4139 #if 0
4140     // horizontal
4141     {
4142         GtkWidget *px= sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_WRITING_MODE_LR);
4143         GtkWidget *b = group = gtk_radio_button_new (NULL);
4144         gtk_container_add (GTK_CONTAINER (b), px);
4145         gtk_tooltips_set_tip (tt, b, _("Horizontal text"), NULL);
4146         gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE);
4147         gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE );
4148         gtk_box_pack_start (GTK_BOX (tbl), b, FALSE, FALSE, 0);
4149     }
4151     // vertical
4152     {
4153         GtkWidget *px = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_WRITING_MODE_TB);
4154         GtkWidget *b = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
4155         gtk_container_add (GTK_CONTAINER (b), px);
4156         gtk_tooltips_set_tip (tt, b, _("Vertical text"), NULL);
4157         gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE);
4158         gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE );
4159         gtk_box_pack_start (GTK_BOX (tbl), b, FALSE, FALSE, 0);
4160     }
4162     aux_toolbox_space(tbl, AUX_BETWEEN_BUTTON_GROUPS);
4164     // letter spacing
4165     {
4166         {
4167             GtkWidget *image = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_LETTER_SPACING);
4168             GtkWidget *hb = gtk_hbox_new(FALSE, 1);
4169             gtk_container_add (GTK_CONTAINER (hb), image);
4170             gtk_widget_show(image);
4171             gtk_box_pack_start (GTK_BOX (tbl), hb, FALSE, FALSE, 0);
4172         }
4174         {
4175             GtkWidget *hb = sp_tb_spinbutton(_(""), _("Spacing between letters"),
4176                                              "tools.text", "letter_spacing", 0.0,
4177                                              us, tbl, FALSE, NULL,
4178                                              -1000.0, 1000.0, 0.1, 0.1,
4179                                              sp_text_letter_changed, 0.1, 1);
4180             gtk_widget_set_size_request (hb, 45, 6);
4181             gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 6);
4182         }
4183     }
4185     // line spacing
4186     {
4187         {
4188             GtkWidget *image = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_LINE_SPACING);
4189             GtkWidget *hb = gtk_hbox_new(FALSE, 1);
4190             gtk_container_add (GTK_CONTAINER (hb), image);
4191             gtk_widget_show(image);
4192             gtk_box_pack_start (GTK_BOX (tbl), hb, FALSE, FALSE, 0);
4193         }
4195         {
4196             GtkWidget *hb = sp_tb_spinbutton(_(""), _("Spacing between lines"),
4197                                              "tools.text", "line_spacing", 0,
4198                                              us, tbl, FALSE, NULL,
4199                                              -1000.0, 1000.0, 0.1, 0.1,
4200                                              sp_text_line_changed, 0.1, 1);
4201             gtk_widget_set_size_request (hb, 45, 0);
4202             gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 3);
4203         }
4204     }
4206     {
4207         // horizontal kerning/vertical kerning units menu: create
4208         GtkWidget *us = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
4209         sp_unit_selector_setsize(us, AUX_OPTION_MENU_WIDTH, AUX_OPTION_MENU_HEIGHT);
4210         sp_unit_selector_set_unit(SP_UNIT_SELECTOR(us), desktop->namedview->doc_units);
4212         aux_toolbox_space(tbl, AUX_BETWEEN_BUTTON_GROUPS);
4214         // horizontal kerning
4215         {
4216             {
4217                 GtkWidget *image = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_HORZ_KERN);
4218                 GtkWidget *hb = gtk_hbox_new(FALSE, 1);
4219                 gtk_container_add (GTK_CONTAINER (hb), image);
4220                 gtk_widget_show(image);
4221                 gtk_box_pack_start (GTK_BOX (tbl), hb, FALSE, FALSE, 0);
4222             }
4224             {
4225                 GtkWidget *hb = sp_tb_spinbutton(_(""), _("Horizontal kerning"),
4226                                                  "tools.text", "horizontal_kerning", 0,
4227                                                  us, tbl, FALSE, NULL,
4228                                                  -100.00, 100.00, 0.01, 0.1,
4229                                                  sp_text_horiz_kern_changed);
4230                 gtk_widget_set_size_request (hb, 45, 0);
4231                 gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 6);
4232             }
4233         }
4235         // vertical kerning
4236         {
4237             {
4238                 GtkWidget *image = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_VERT_KERN);
4239                 GtkWidget *hb = gtk_hbox_new(FALSE, 1);
4240                 gtk_container_add (GTK_CONTAINER (hb), image);
4241                 gtk_widget_show(image);
4242                 gtk_box_pack_start (GTK_BOX (tbl), hb, FALSE, FALSE, 0);
4243             }
4245             {
4246                 GtkWidget *hb = sp_tb_spinbutton(_(""), _("Vertical kerning"),
4247                                                  "tools.text", "vertical_kerning", 0,
4248                                                  us, tbl, FALSE, NULL,
4249                                                  -100.00, 100.00, 0.01, 0.1,
4250                                                  sp_text_vert_kern_changed);
4251                 gtk_widget_set_size_request (hb, 45, 0);
4252                 gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 5);
4253             }
4254         }
4256         // add the units menu
4257         gtk_widget_show(us);
4258         gtk_box_pack_start(GTK_BOX(tbl), us, FALSE, FALSE, 1);
4259         gtk_object_set_data(GTK_OBJECT(tbl), "units", us);
4260     }
4262     // letter rotation
4263     aux_toolbox_space(tbl, AUX_BETWEEN_BUTTON_GROUPS);
4264     {
4265         {
4266             GtkWidget *image = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_ROTATION);
4267             GtkWidget *hb = gtk_hbox_new(FALSE, 1);
4268             gtk_container_add (GTK_CONTAINER (hb), image);
4269             gtk_widget_show(image);
4270             gtk_box_pack_start (GTK_BOX (tbl), hb, FALSE, FALSE, 0);
4271         }
4272         {
4273             GtkWidget *hb = sp_tb_spinbutton(_(""), _("Letter rotation"),
4274                                              "tools.text", "letter_rotation", 0,
4275                                              us, tbl, FALSE, NULL,
4276                                              -180.0, 180.0, 0.1, 0.1,
4277                                              sp_text_letter_rotation_changed, 0.1, 1);
4278             gtk_widget_set_size_request (hb, 45, 0);
4279             gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, 6);
4280         }
4281         // rotation degree label
4282         {
4283             GtkWidget *label = gtk_widget_new (GTK_TYPE_LABEL, "label", "\302\260", "xalign", 0.0, NULL);
4284             gtk_box_pack_start(GTK_BOX(tbl), label, FALSE, FALSE, 0);
4285         }
4286     }
4288     // Remove Manual Kerns
4289     {
4290         GtkWidget *px = sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_STOCK_TEXT_REMOVE_KERNS);
4291         GtkWidget *button = gtk_button_new ();
4292         gtk_container_add (GTK_CONTAINER (button), px);
4293         gtk_widget_show(button);
4294         gtk_tooltips_set_tip (tt, button, _("Remove manual kerns"), NULL);
4295         gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
4296         gtk_widget_set_sensitive(button, TRUE);
4297         gtk_box_pack_start (GTK_BOX (tbl), button, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
4298     }
4299 #endif
4301     gtk_widget_show_all (tbl);
4302     return tbl;
4304 } // end of sp_text_toolbox_new()
4306 }//<unnamed> namespace
4309 //#########################
4310 //##  Connector Toolbox  ##
4311 //#########################
4313 static void sp_connector_path_set_avoid(void)
4315     cc_selection_set_avoid(true);
4319 static void sp_connector_path_set_ignore(void)
4321     cc_selection_set_avoid(false);
4326 static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl)
4328     // quit if run by the _changed callbacks
4329     if (g_object_get_data( tbl, "freeze" )) {
4330         return;
4331     }
4333     SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
4334     SPDocument *doc = sp_desktop_document(desktop);
4336     if (!sp_document_get_undo_sensitive(doc))
4337     {
4338         return;
4339     }
4341     Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview);
4343     if ( repr->attribute("inkscape:connector-spacing") ) {
4344         gdouble priorValue = gtk_adjustment_get_value(adj);
4345         sp_repr_get_double( repr, "inkscape:connector-spacing", &priorValue );
4346         if ( priorValue == gtk_adjustment_get_value(adj) ) {
4347             return;
4348         }
4349     } else if ( adj->value == defaultConnSpacing ) {
4350         return;
4351     }
4353     // in turn, prevent callbacks from responding
4354     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
4356     sp_repr_set_css_double(repr, "inkscape:connector-spacing", adj->value);
4357     SP_OBJECT(desktop->namedview)->updateRepr();
4359     GSList *items = get_avoided_items(NULL, desktop->currentRoot(), desktop);
4360     for ( GSList const *iter = items ; iter != NULL ; iter = iter->next ) {
4361         SPItem *item = reinterpret_cast<SPItem *>(iter->data);
4362         NR::Matrix m = NR::identity();
4363         avoid_item_move(&m, item);
4364     }
4366     if (items) {
4367         g_slist_free(items);
4368     }
4370     sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
4371             _("Change connector spacing"));
4373     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
4375     spinbutton_defocus(GTK_OBJECT(tbl));
4378 static void sp_connector_graph_layout(void)
4380     if (!SP_ACTIVE_DESKTOP) return;
4382     // hack for clones, see comment in align-and-distribute.cpp
4383     int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
4384     prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
4386     graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
4388     prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
4390     sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network"));
4393 static void sp_directed_graph_layout_toggled( GtkToggleAction* act, GtkObject *tbl )
4395     if ( gtk_toggle_action_get_active( act ) ) {
4396         prefs_set_string_attribute("tools.connector", "directedlayout",
4397                 "true");
4398     } else {
4399         prefs_set_string_attribute("tools.connector", "directedlayout",
4400                 "false");
4401     }
4404 static void sp_nooverlaps_graph_layout_toggled( GtkToggleAction* act, GtkObject *tbl )
4406     if ( gtk_toggle_action_get_active( act ) ) {
4407         prefs_set_string_attribute("tools.connector", "avoidoverlaplayout",
4408                 "true");
4409     } else {
4410         prefs_set_string_attribute("tools.connector", "avoidoverlaplayout",
4411                 "false");
4412     }
4416 static void connector_length_changed(GtkAdjustment *adj, GObject* tbl)
4418     prefs_set_double_attribute("tools.connector", "length", adj->value);
4419     spinbutton_defocus(GTK_OBJECT(tbl));
4422 static void connector_tb_event_attr_changed(Inkscape::XML::Node *repr,
4423         gchar const *name, gchar const *old_value, gchar const *new_value,
4424         bool is_interactive, gpointer data)
4426     GtkWidget *tbl = GTK_WIDGET(data);
4428     if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
4429         return;
4430     }
4431     if (strcmp(name, "inkscape:connector-spacing") != 0) {
4432         return;
4433     }
4435     GtkAdjustment *adj = (GtkAdjustment*)
4436             gtk_object_get_data(GTK_OBJECT(tbl), "spacing");
4437     gdouble spacing = defaultConnSpacing;
4438     sp_repr_get_double(repr, "inkscape:connector-spacing", &spacing);
4440     gtk_adjustment_set_value(adj, spacing);
4444 static Inkscape::XML::NodeEventVector connector_tb_repr_events = {
4445     NULL, /* child_added */
4446     NULL, /* child_removed */
4447     connector_tb_event_attr_changed,
4448     NULL, /* content_changed */
4449     NULL  /* order_changed */
4450 };
4453 static void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder )
4455     {
4456         InkAction* inky = ink_action_new( "ConnectorAvoidAction",
4457                                           _("Avoid"),
4458                                           _("Make connectors avoid selected objects"),
4459                                           "connector_avoid",
4460                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
4461         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_path_set_avoid), holder );
4462         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
4463     }
4465     {
4466         InkAction* inky = ink_action_new( "ConnectorIgnoreAction",
4467                                           _("Ignore"),
4468                                           _("Make connectors ignore selected objects"),
4469                                           "connector_ignore",
4470                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
4471         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_path_set_ignore), holder );
4472         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
4473     }
4475     EgeAdjustmentAction* eact = 0;
4477     // Spacing spinbox
4478     eact = create_adjustment_action( "ConnectorSpacingAction",
4479                                      _("Spacing:"), _("The amount of space left around objects by auto-routing connectors"),
4480                                      "tools.connector", "spacing", defaultConnSpacing,
4481                                      GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-spacing",
4482                                      0, 100, 1.0, 10.0,
4483                                      0, 0, 0,
4484                                      connector_spacing_changed, 1, 0 );
4485     gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4487     // Graph (connector network) layout
4488     {
4489         InkAction* inky = ink_action_new( "ConnectorGraphAction",
4490                                           _("Graph"),
4491                                           _("Nicely arrange selected connector network"),
4492                                           "graph_layout",
4493                                           Inkscape::ICON_SIZE_SMALL_TOOLBAR );
4494         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_graph_layout), holder );
4495         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
4496     }
4498     // Default connector length spinbox
4499     eact = create_adjustment_action( "ConnectorLengthAction",
4500                                      _("Length:"), _("Ideal length for connectors when layout is applied"),
4501                                      "tools.connector", "length", 100,
4502                                      GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-length",
4503                                      10, 1000, 10.0, 100.0,
4504                                      0, 0, 0,
4505                                      connector_length_changed, 1, 0 );
4506     gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4509     // Directed edges toggle button
4510     {
4511         InkToggleAction* act = ink_toggle_action_new( "ConnectorDirectedAction",
4512                                                       _("Downwards"),
4513                                                       _("Make connectors with end-markers (arrows) point downwards"),
4514                                                       "directed_graph",
4515                                                       Inkscape::ICON_SIZE_DECORATION );
4516         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4518         gchar const* tbuttonstate = prefs_get_string_attribute( "tools.connector", "directedlayout" );
4519         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act),
4520                 (tbuttonstate && !strcmp(tbuttonstate, "true")) ? TRUE:FALSE );
4522         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_directed_graph_layout_toggled), holder );
4523     }
4525     // Avoid overlaps toggle button
4526     {
4527         InkToggleAction* act = ink_toggle_action_new( "ConnectorOverlapAction",
4528                                                       _("Remove overlaps"),
4529                                                       _("Do not allow overlapping shapes"),
4530                                                       "remove_overlaps",
4531                                                       Inkscape::ICON_SIZE_DECORATION );
4532         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4534         gchar const* tbuttonstate = prefs_get_string_attribute( "tools.connector", "avoidoverlaplayout" );
4535         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act),
4536                 (tbuttonstate && !strcmp(tbuttonstate, "true")) ? TRUE:FALSE );
4538         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_nooverlaps_graph_layout_toggled), holder );
4539     }
4541     // Code to watch for changes to the connector-spacing attribute in
4542     // the XML.
4543     Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview);
4544     g_assert(repr != NULL);
4546     purge_repr_listener( holder, holder );
4548     if (repr) {
4549         g_object_set_data( holder, "repr", repr );
4550         Inkscape::GC::anchor(repr);
4551         sp_repr_add_listener( repr, &connector_tb_repr_events, holder );
4552         sp_repr_synthesize_events( repr, &connector_tb_repr_events, holder );
4553     }
4554 } // end of sp_connector_toolbox_prep()
4556 static void paintbucket_channels_changed(EgeSelectOneAction* act, GObject* tbl)
4558     gint channels = ege_select_one_action_get_active( act );
4559     flood_channels_set_channels( channels );
4562 static void paintbucket_threshold_changed(GtkAdjustment *adj, GObject *tbl)
4564     prefs_set_int_attribute("tools.paintbucket", "threshold", (gint)adj->value);
4567 static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject *tbl)
4569     prefs_set_int_attribute("tools.paintbucket", "autogap", ege_select_one_action_get_active( act ));
4572 static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl)
4574     UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
4575     SPUnit const *unit = tracker->getActiveUnit();
4578     prefs_set_double_attribute("tools.paintbucket", "offset", (gdouble)sp_units_get_pixels(adj->value, *unit));
4581 static void paintbucket_defaults(GtkWidget *, GObject *dataKludge)
4583     // FIXME: make defaults settable via Inkscape Options
4584     struct KeyValue {
4585         char const *key;
4586         double value;
4587     } const key_values[] = {
4588         {"threshold", 15},
4589         {"offset", 0.0}
4590     };
4592     for (unsigned i = 0; i < G_N_ELEMENTS(key_values); ++i) {
4593         KeyValue const &kv = key_values[i];
4594         GtkAdjustment* adj = static_cast<GtkAdjustment *>(g_object_get_data(dataKludge, kv.key));
4595         if ( adj ) {
4596             gtk_adjustment_set_value(adj, kv.value);
4597         }
4598     }
4599     
4600     EgeSelectOneAction* channels_action = EGE_SELECT_ONE_ACTION( g_object_get_data( dataKludge, "channels_action" ) );
4601     ege_select_one_action_set_active( channels_action, FLOOD_CHANNELS_RGB );
4602     EgeSelectOneAction* autogap_action = EGE_SELECT_ONE_ACTION( g_object_get_data( dataKludge, "autogap_action" ) );
4603     ege_select_one_action_set_active( autogap_action, 0 );
4606 static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
4608     EgeAdjustmentAction* eact = 0;
4610     {
4611         GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
4613         GList* items = 0;
4614         gint count = 0;
4615         for ( items = flood_channels_dropdown_items_list(); items ; items = g_list_next(items) )
4616         {
4617             GtkTreeIter iter;
4618             gtk_list_store_append( model, &iter );
4619             gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
4620             count++;
4621         }
4622         g_list_free( items );
4623         items = 0;
4624         EgeSelectOneAction* act1 = ege_select_one_action_new( "ChannelsAction", _("Fill by:"), _(""), NULL, GTK_TREE_MODEL(model) );
4625         ege_select_one_action_set_active( act1, prefs_get_int_attribute("tools.paintbucket", "channels", 0) );
4626         g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(paintbucket_channels_changed), holder );
4627         gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
4628         g_object_set_data( holder, "channels_action", act1 );
4629     }
4631     // Spacing spinbox
4632     {
4633         eact = create_adjustment_action(
4634             "ThresholdAction",
4635             _("Threshold:"),
4636             _("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"),
4637             "tools.paintbucket", "threshold", 5, GTK_WIDGET(desktop->canvas), NULL, holder, TRUE,
4638             "inkscape:paintbucket-threshold", 0, 100.0, 1.0, 10.0,
4639             0, 0, 0,
4640             paintbucket_threshold_changed, 1, 0 );
4642         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4643     }
4645     // Create the units menu.
4646     UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
4647     tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
4648     g_object_set_data( holder, "tracker", tracker );
4649     {
4650         GtkAction* act = tracker->createAction( "PaintbucketUnitsAction", _("Units"), _("") );
4651         gtk_action_group_add_action( mainActions, act );
4652     }
4654     // Offset spinbox
4655     {
4656         eact = create_adjustment_action(
4657             "OffsetAction",
4658             _("Grow/shrink by:"),
4659             _("The amount to grow (positive) or shrink (negative) the created fill path"),
4660             "tools.paintbucket", "offset", 0, GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE,
4661             "inkscape:paintbucket-offset", -1e6, 1e6, 0.1, 0.5,
4662             0, 0, 0,
4663             paintbucket_offset_changed, 1, 2);
4664         tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
4666         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4667     }
4668     
4669     /* Auto Gap */
4670     {
4671         GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
4673         GList* items = 0;
4674         gint count = 0;
4675         for ( items = flood_autogap_dropdown_items_list(); items ; items = g_list_next(items) )
4676         {
4677             GtkTreeIter iter;
4678             gtk_list_store_append( model, &iter );
4679             gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
4680             count++;
4681         }
4682         g_list_free( items );
4683         items = 0;
4684         EgeSelectOneAction* act2 = ege_select_one_action_new( "AutoGapAction", _("Fill gaps:"), _(""), NULL, GTK_TREE_MODEL(model) );
4685         ege_select_one_action_set_active( act2, prefs_get_int_attribute("tools.paintbucket", "autogap", 0) );
4686         g_signal_connect( G_OBJECT(act2), "changed", G_CALLBACK(paintbucket_autogap_changed), holder );
4687         gtk_action_group_add_action( mainActions, GTK_ACTION(act2) );
4688         g_object_set_data( holder, "autogap_action", act2 );
4689     }
4691     /* Reset */
4692     {
4693         GtkAction* act = gtk_action_new( "PaintbucketResetAction",
4694                                           _("Defaults"),
4695                                           _("Reset paint bucket parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
4696                                           GTK_STOCK_CLEAR );
4697         g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(paintbucket_defaults), holder );
4698         gtk_action_group_add_action( mainActions, act );
4699         gtk_action_set_sensitive( act, TRUE );
4700     }
4704 /*
4705   Local Variables:
4706   mode:c++
4707   c-file-style:"stroustrup"
4708   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
4709   indent-tabs-mode:nil
4710   fill-column:99
4711   End:
4712 */
4713 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :