826fabb06ae1bc545f6081aa19060854a80a3177
1 /** @file
2 * @brief Controls bars for some of Inkscape's tools (for some tools,
3 * they are in their own files)
4 */
5 /* Authors:
6 * MenTaLguY <mental@rydia.net>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 * Frank Felfe <innerspace@iname.com>
10 * John Cliff <simarilius@yahoo.com>
11 * David Turner <novalis@gnu.org>
12 * Josh Andler <scislac@scislac.com>
13 * Jon A. Cruz <jon@joncruz.org>
14 * Maximilian Albert <maximilian.albert@gmail.com>
15 * Tavmjong Bah <tavmjong@free.fr>
16 *
17 * Copyright (C) 2004 David Turner
18 * Copyright (C) 2003 MenTaLguY
19 * Copyright (C) 1999-2010 authors
20 * Copyright (C) 2001-2002 Ximian, Inc.
21 *
22 * Released under GNU GPL, read the file 'COPYING' for more information
23 */
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <cstring>
30 #include <string>
32 #include <gtkmm.h>
33 #include <gtk/gtk.h>
34 #include <iostream>
35 #include <sstream>
36 #include <glibmm/i18n.h>
38 #include "../box3d-context.h"
39 #include "../box3d.h"
40 #include "../conn-avoid-ref.h"
41 #include "../connection-pool.h"
42 #include "../connector-context.h"
43 #include "../desktop.h"
44 #include "../desktop-handles.h"
45 #include "../desktop-style.h"
46 #include "../dialogs/dialog-events.h"
47 #include "../dialogs/text-edit.h"
48 #include "../document-private.h"
49 #include "../ege-adjustment-action.h"
50 #include "../ege-output-action.h"
51 #include "../ege-select-one-action.h"
52 #include "../flood-context.h"
53 #include "gradient-toolbar.h"
54 #include "../graphlayout.h"
55 #include "../helper/unit-menu.h"
56 #include "../helper/units.h"
57 #include "../helper/unit-tracker.h"
58 #include "icon.h"
59 #include "../ink-action.h"
60 #include "../ink-comboboxentry-action.h"
61 #include "../inkscape.h"
62 #include "../interface.h"
63 #include "../libnrtype/font-instance.h"
64 #include "../libnrtype/font-lister.h"
65 #include "../live_effects/effect.h"
66 #include "../live_effects/lpe-angle_bisector.h"
67 #include "../live_effects/lpe-line_segment.h"
68 #include "../lpe-tool-context.h"
69 #include "../mod360.h"
70 #include "../pen-context.h"
71 #include "../preferences.h"
72 #include "../selection-chemistry.h"
73 #include "../selection.h"
74 #include "select-toolbar.h"
75 #include "../shape-editor.h"
76 #include "../shortcuts.h"
77 #include "../sp-clippath.h"
78 #include "../sp-ellipse.h"
79 #include "../sp-flowtext.h"
80 #include "../sp-mask.h"
81 #include "../sp-namedview.h"
82 #include "../sp-rect.h"
83 #include "../sp-spiral.h"
84 #include "../sp-star.h"
85 #include "../sp-text.h"
86 #include "../style.h"
87 #include "../svg/css-ostringstream.h"
88 #include "../tools-switch.h"
89 #include "../tweak-context.h"
90 #include "../spray-context.h"
91 #include "../ui/dialog/calligraphic-profile-rename.h"
92 #include "../ui/icon-names.h"
93 #include "../ui/tool/control-point-selection.h"
94 #include "../ui/tool/node-tool.h"
95 #include "../ui/tool/multi-path-manipulator.h"
96 #include "../ui/widget/style-swatch.h"
97 #include "../verbs.h"
98 #include "../widgets/button.h"
99 #include "../widgets/spinbutton-events.h"
100 #include "../widgets/spw-utilities.h"
101 #include "../widgets/widget-sizes.h"
102 #include "../xml/attribute-record.h"
103 #include "../xml/node-event-vector.h"
104 #include "../xml/repr.h"
105 #include "ui/uxmanager.h"
107 #include "toolbox.h"
109 #define ENABLE_TASK_SUPPORT 1
110 //#define DEBUG_TEXT
112 using Inkscape::UnitTracker;
113 using Inkscape::UI::UXManager;
115 typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop);
116 typedef void (*UpdateFunction)(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
118 enum BarId {
119 BAR_TOOL = 0,
120 BAR_AUX,
121 BAR_COMMANDS,
122 BAR_SNAP,
123 };
125 #define BAR_ID_KEY "BarIdValue"
126 #define HANDLE_POS_MARK "x-inkscape-pos"
128 static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
129 static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
130 static void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
131 static void sp_zoom_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
132 static void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
133 static void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
134 static void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
135 static void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
136 static void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
137 static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
138 static void sp_pen_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
139 static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
140 static void sp_dropper_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
141 static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop);
142 static void sp_connector_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
143 static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
144 static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
145 static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
146 static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
148 #if ENABLE_TASK_SUPPORT
149 static void fireTaskChange( EgeSelectOneAction *act, SPDesktop *dt )
150 {
151 gint selected = ege_select_one_action_get_active( act );
152 UXManager::getInstance()->setTask(dt, selected);
153 }
154 #endif // ENABLE_TASK_SUPPORT
156 using Inkscape::UI::ToolboxFactory;
159 Inkscape::IconSize ToolboxFactory::prefToSize( Glib::ustring const &path, int base ) {
160 static Inkscape::IconSize sizeChoices[] = {
161 Inkscape::ICON_SIZE_LARGE_TOOLBAR,
162 Inkscape::ICON_SIZE_SMALL_TOOLBAR,
163 Inkscape::ICON_SIZE_MENU
164 };
165 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
166 int index = prefs->getIntLimited( path, base, 0, G_N_ELEMENTS(sizeChoices) );
167 return sizeChoices[index];
168 }
170 static struct {
171 gchar const *type_name;
172 gchar const *data_name;
173 sp_verb_t verb;
174 sp_verb_t doubleclick_verb;
175 } const tools[] = {
176 { "SPSelectContext", "select_tool", SP_VERB_CONTEXT_SELECT, SP_VERB_CONTEXT_SELECT_PREFS},
177 { "InkNodeTool", "node_tool", SP_VERB_CONTEXT_NODE, SP_VERB_CONTEXT_NODE_PREFS },
178 { "SPTweakContext", "tweak_tool", SP_VERB_CONTEXT_TWEAK, SP_VERB_CONTEXT_TWEAK_PREFS },
179 { "SPSprayContext", "spray_tool", SP_VERB_CONTEXT_SPRAY, SP_VERB_CONTEXT_SPRAY_PREFS },
180 { "SPZoomContext", "zoom_tool", SP_VERB_CONTEXT_ZOOM, SP_VERB_CONTEXT_ZOOM_PREFS },
181 { "SPRectContext", "rect_tool", SP_VERB_CONTEXT_RECT, SP_VERB_CONTEXT_RECT_PREFS },
182 { "Box3DContext", "3dbox_tool", SP_VERB_CONTEXT_3DBOX, SP_VERB_CONTEXT_3DBOX_PREFS },
183 { "SPArcContext", "arc_tool", SP_VERB_CONTEXT_ARC, SP_VERB_CONTEXT_ARC_PREFS },
184 { "SPStarContext", "star_tool", SP_VERB_CONTEXT_STAR, SP_VERB_CONTEXT_STAR_PREFS },
185 { "SPSpiralContext", "spiral_tool", SP_VERB_CONTEXT_SPIRAL, SP_VERB_CONTEXT_SPIRAL_PREFS },
186 { "SPPencilContext", "pencil_tool", SP_VERB_CONTEXT_PENCIL, SP_VERB_CONTEXT_PENCIL_PREFS },
187 { "SPPenContext", "pen_tool", SP_VERB_CONTEXT_PEN, SP_VERB_CONTEXT_PEN_PREFS },
188 { "SPDynaDrawContext", "dyna_draw_tool", SP_VERB_CONTEXT_CALLIGRAPHIC, SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS },
189 { "SPLPEToolContext", "lpetool_tool", SP_VERB_CONTEXT_LPETOOL, SP_VERB_CONTEXT_LPETOOL_PREFS },
190 { "SPEraserContext", "eraser_tool", SP_VERB_CONTEXT_ERASER, SP_VERB_CONTEXT_ERASER_PREFS },
191 { "SPFloodContext", "paintbucket_tool", SP_VERB_CONTEXT_PAINTBUCKET, SP_VERB_CONTEXT_PAINTBUCKET_PREFS },
192 { "SPTextContext", "text_tool", SP_VERB_CONTEXT_TEXT, SP_VERB_CONTEXT_TEXT_PREFS },
193 { "SPConnectorContext","connector_tool", SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_CONNECTOR_PREFS },
194 { "SPGradientContext", "gradient_tool", SP_VERB_CONTEXT_GRADIENT, SP_VERB_CONTEXT_GRADIENT_PREFS },
195 { "SPDropperContext", "dropper_tool", SP_VERB_CONTEXT_DROPPER, SP_VERB_CONTEXT_DROPPER_PREFS },
196 { NULL, NULL, 0, 0 }
197 };
199 static struct {
200 gchar const *type_name;
201 gchar const *data_name;
202 GtkWidget *(*create_func)(SPDesktop *desktop);
203 void (*prep_func)(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder);
204 gchar const *ui_name;
205 gint swatch_verb_id;
206 gchar const *swatch_tool;
207 gchar const *swatch_tip;
208 } const aux_toolboxes[] = {
209 { "SPSelectContext", "select_toolbox", 0, sp_select_toolbox_prep, "SelectToolbar",
210 SP_VERB_INVALID, 0, 0},
211 { "InkNodeTool", "node_toolbox", 0, sp_node_toolbox_prep, "NodeToolbar",
212 SP_VERB_INVALID, 0, 0},
213 { "SPTweakContext", "tweak_toolbox", 0, sp_tweak_toolbox_prep, "TweakToolbar",
214 SP_VERB_CONTEXT_TWEAK_PREFS, "/tools/tweak", N_("Color/opacity used for color tweaking")},
215 { "SPSprayContext", "spray_toolbox", 0, sp_spray_toolbox_prep, "SprayToolbar",
216 SP_VERB_CONTEXT_SPRAY_PREFS, "/tools/spray", N_("Color/opacity used for color spraying")},
217 { "SPZoomContext", "zoom_toolbox", 0, sp_zoom_toolbox_prep, "ZoomToolbar",
218 SP_VERB_INVALID, 0, 0},
219 { "SPStarContext", "star_toolbox", 0, sp_star_toolbox_prep, "StarToolbar",
220 SP_VERB_CONTEXT_STAR_PREFS, "/tools/shapes/star", N_("Style of new stars")},
221 { "SPRectContext", "rect_toolbox", 0, sp_rect_toolbox_prep, "RectToolbar",
222 SP_VERB_CONTEXT_RECT_PREFS, "/tools/shapes/rect", N_("Style of new rectangles")},
223 { "Box3DContext", "3dbox_toolbox", 0, box3d_toolbox_prep, "3DBoxToolbar",
224 SP_VERB_CONTEXT_3DBOX_PREFS, "/tools/shapes/3dbox", N_("Style of new 3D boxes")},
225 { "SPArcContext", "arc_toolbox", 0, sp_arc_toolbox_prep, "ArcToolbar",
226 SP_VERB_CONTEXT_ARC_PREFS, "/tools/shapes/arc", N_("Style of new ellipses")},
227 { "SPSpiralContext", "spiral_toolbox", 0, sp_spiral_toolbox_prep, "SpiralToolbar",
228 SP_VERB_CONTEXT_SPIRAL_PREFS, "/tools/shapes/spiral", N_("Style of new spirals")},
229 { "SPPencilContext", "pencil_toolbox", 0, sp_pencil_toolbox_prep, "PencilToolbar",
230 SP_VERB_CONTEXT_PENCIL_PREFS, "/tools/freehand/pencil", N_("Style of new paths created by Pencil")},
231 { "SPPenContext", "pen_toolbox", 0, sp_pen_toolbox_prep, "PenToolbar",
232 SP_VERB_CONTEXT_PEN_PREFS, "/tools/freehand/pen", N_("Style of new paths created by Pen")},
233 { "SPDynaDrawContext", "calligraphy_toolbox", 0, sp_calligraphy_toolbox_prep,"CalligraphyToolbar",
234 SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "/tools/calligraphic", N_("Style of new calligraphic strokes")},
235 { "SPEraserContext", "eraser_toolbox", 0, sp_eraser_toolbox_prep,"EraserToolbar",
236 SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")},
237 { "SPLPEToolContext", "lpetool_toolbox", 0, sp_lpetool_toolbox_prep, "LPEToolToolbar",
238 SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")},
239 { "SPTextContext", "text_toolbox", 0, sp_text_toolbox_prep, "TextToolbar",
240 SP_VERB_INVALID, 0, 0},
241 { "SPDropperContext", "dropper_toolbox", 0, sp_dropper_toolbox_prep, "DropperToolbar",
242 SP_VERB_INVALID, 0, 0},
243 { "SPGradientContext", "gradient_toolbox", sp_gradient_toolbox_new, 0, 0,
244 SP_VERB_INVALID, 0, 0},
245 { "SPConnectorContext", "connector_toolbox", 0, sp_connector_toolbox_prep, "ConnectorToolbar",
246 SP_VERB_INVALID, 0, 0},
247 { "SPFloodContext", "paintbucket_toolbox", 0, sp_paintbucket_toolbox_prep, "PaintbucketToolbar",
248 SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "/tools/paintbucket", N_("Style of Paint Bucket fill objects")},
249 { NULL, NULL, NULL, NULL, NULL, SP_VERB_INVALID, NULL, NULL }
250 };
252 #define TOOLBAR_SLIDER_HINT "full"
254 static gchar const * ui_descr =
255 "<ui>"
256 " <toolbar name='SelectToolbar'>"
257 " <toolitem action='EditSelectAll' />"
258 " <toolitem action='EditSelectAllInAllLayers' />"
259 " <toolitem action='EditDeselect' />"
260 " <separator />"
261 " <toolitem action='ObjectRotate90CCW' />"
262 " <toolitem action='ObjectRotate90' />"
263 " <toolitem action='ObjectFlipHorizontally' />"
264 " <toolitem action='ObjectFlipVertically' />"
265 " <separator />"
266 " <toolitem action='SelectionToBack' />"
267 " <toolitem action='SelectionLower' />"
268 " <toolitem action='SelectionRaise' />"
269 " <toolitem action='SelectionToFront' />"
270 " <separator />"
271 " <toolitem action='XAction' />"
272 " <toolitem action='YAction' />"
273 " <toolitem action='WidthAction' />"
274 " <toolitem action='LockAction' />"
275 " <toolitem action='HeightAction' />"
276 " <toolitem action='UnitsAction' />"
277 " <separator />"
278 " <toolitem action='transform_affect_label' />"
279 " <toolitem action='transform_stroke' />"
280 " <toolitem action='transform_corners' />"
281 " <toolitem action='transform_gradient' />"
282 " <toolitem action='transform_pattern' />"
283 " </toolbar>"
285 " <toolbar name='NodeToolbar'>"
286 " <separator />"
287 " <toolitem action='NodeInsertAction' />"
288 " <toolitem action='NodeDeleteAction' />"
289 " <separator />"
290 " <toolitem action='NodeJoinAction' />"
291 " <toolitem action='NodeBreakAction' />"
292 " <separator />"
293 " <toolitem action='NodeJoinSegmentAction' />"
294 " <toolitem action='NodeDeleteSegmentAction' />"
295 " <separator />"
296 " <toolitem action='NodeCuspAction' />"
297 " <toolitem action='NodeSmoothAction' />"
298 " <toolitem action='NodeSymmetricAction' />"
299 " <toolitem action='NodeAutoAction' />"
300 " <separator />"
301 " <toolitem action='NodeLineAction' />"
302 " <toolitem action='NodeCurveAction' />"
303 " <separator />"
304 " <toolitem action='ObjectToPath' />"
305 " <toolitem action='StrokeToPath' />"
306 " <separator />"
307 " <toolitem action='NodeXAction' />"
308 " <toolitem action='NodeYAction' />"
309 " <toolitem action='NodeUnitsAction' />"
310 " <separator />"
311 " <toolitem action='ObjectEditClipPathAction' />"
312 " <toolitem action='ObjectEditMaskPathAction' />"
313 " <toolitem action='EditNextLPEParameterAction' />"
314 " <separator />"
315 " <toolitem action='NodesShowTransformHandlesAction' />"
316 " <toolitem action='NodesShowHandlesAction' />"
317 " <toolitem action='NodesShowHelperpath' />"
318 " </toolbar>"
320 " <toolbar name='TweakToolbar'>"
321 " <toolitem action='TweakWidthAction' />"
322 " <separator />"
323 " <toolitem action='TweakForceAction' />"
324 " <toolitem action='TweakPressureAction' />"
325 " <separator />"
326 " <toolitem action='TweakModeAction' />"
327 " <separator />"
328 " <toolitem action='TweakFidelityAction' />"
329 " <separator />"
330 " <toolitem action='TweakChannelsLabel' />"
331 " <toolitem action='TweakDoH' />"
332 " <toolitem action='TweakDoS' />"
333 " <toolitem action='TweakDoL' />"
334 " <toolitem action='TweakDoO' />"
335 " </toolbar>"
337 " <toolbar name='SprayToolbar'>"
338 " <toolitem action='SprayModeAction' />"
339 " <separator />"
340 " <separator />"
341 " <toolitem action='SprayWidthAction' />"
342 " <toolitem action='SprayPressureAction' />"
343 " <toolitem action='SprayPopulationAction' />"
344 " <separator />"
345 " <toolitem action='SprayRotationAction' />"
346 " <toolitem action='SprayScaleAction' />"
347 " <separator />"
348 " <toolitem action='SprayStandard_deviationAction' />"
349 " <toolitem action='SprayMeanAction' />"
350 " </toolbar>"
352 " <toolbar name='ZoomToolbar'>"
353 " <toolitem action='ZoomIn' />"
354 " <toolitem action='ZoomOut' />"
355 " <separator />"
356 " <toolitem action='Zoom1:0' />"
357 " <toolitem action='Zoom1:2' />"
358 " <toolitem action='Zoom2:1' />"
359 " <separator />"
360 " <toolitem action='ZoomSelection' />"
361 " <toolitem action='ZoomDrawing' />"
362 " <toolitem action='ZoomPage' />"
363 " <toolitem action='ZoomPageWidth' />"
364 " <separator />"
365 " <toolitem action='ZoomPrev' />"
366 " <toolitem action='ZoomNext' />"
367 " </toolbar>"
369 " <toolbar name='StarToolbar'>"
370 " <separator />"
371 " <toolitem action='StarStateAction' />"
372 " <separator />"
373 " <toolitem action='FlatAction' />"
374 " <separator />"
375 " <toolitem action='MagnitudeAction' />"
376 " <toolitem action='SpokeAction' />"
377 " <toolitem action='RoundednessAction' />"
378 " <toolitem action='RandomizationAction' />"
379 " <separator />"
380 " <toolitem action='StarResetAction' />"
381 " </toolbar>"
383 " <toolbar name='RectToolbar'>"
384 " <toolitem action='RectStateAction' />"
385 " <toolitem action='RectWidthAction' />"
386 " <toolitem action='RectHeightAction' />"
387 " <toolitem action='RadiusXAction' />"
388 " <toolitem action='RadiusYAction' />"
389 " <toolitem action='RectUnitsAction' />"
390 " <separator />"
391 " <toolitem action='RectResetAction' />"
392 " </toolbar>"
394 " <toolbar name='3DBoxToolbar'>"
395 " <toolitem action='3DBoxAngleXAction' />"
396 " <toolitem action='3DBoxVPXStateAction' />"
397 " <separator />"
398 " <toolitem action='3DBoxAngleYAction' />"
399 " <toolitem action='3DBoxVPYStateAction' />"
400 " <separator />"
401 " <toolitem action='3DBoxAngleZAction' />"
402 " <toolitem action='3DBoxVPZStateAction' />"
403 " </toolbar>"
405 " <toolbar name='SpiralToolbar'>"
406 " <toolitem action='SpiralStateAction' />"
407 " <toolitem action='SpiralRevolutionAction' />"
408 " <toolitem action='SpiralExpansionAction' />"
409 " <toolitem action='SpiralT0Action' />"
410 " <separator />"
411 " <toolitem action='SpiralResetAction' />"
412 " </toolbar>"
414 " <toolbar name='PenToolbar'>"
415 " <toolitem action='FreehandModeActionPen' />"
416 " <separator />"
417 " <toolitem action='SetPenShapeAction'/>"
418 " </toolbar>"
420 " <toolbar name='PencilToolbar'>"
421 " <toolitem action='FreehandModeActionPencil' />"
422 " <separator />"
423 " <toolitem action='PencilToleranceAction' />"
424 " <separator />"
425 " <toolitem action='PencilResetAction' />"
426 " <separator />"
427 " <toolitem action='SetPencilShapeAction'/>"
428 " </toolbar>"
430 " <toolbar name='CalligraphyToolbar'>"
431 " <separator />"
432 " <toolitem action='SetProfileAction'/>"
433 " <separator />"
434 " <toolitem action='CalligraphyWidthAction' />"
435 " <toolitem action='PressureAction' />"
436 " <toolitem action='TraceAction' />"
437 " <toolitem action='ThinningAction' />"
438 " <separator />"
439 " <toolitem action='AngleAction' />"
440 " <toolitem action='TiltAction' />"
441 " <toolitem action='FixationAction' />"
442 " <separator />"
443 " <toolitem action='CapRoundingAction' />"
444 " <separator />"
445 " <toolitem action='TremorAction' />"
446 " <toolitem action='WiggleAction' />"
447 " <toolitem action='MassAction' />"
448 " <separator />"
449 " </toolbar>"
451 " <toolbar name='ArcToolbar'>"
452 " <toolitem action='ArcStateAction' />"
453 " <separator />"
454 " <toolitem action='ArcStartAction' />"
455 " <toolitem action='ArcEndAction' />"
456 " <separator />"
457 " <toolitem action='ArcOpenAction' />"
458 " <separator />"
459 " <toolitem action='ArcResetAction' />"
460 " <separator />"
461 " </toolbar>"
463 " <toolbar name='PaintbucketToolbar'>"
464 " <toolitem action='ChannelsAction' />"
465 " <separator />"
466 " <toolitem action='ThresholdAction' />"
467 " <separator />"
468 " <toolitem action='OffsetAction' />"
469 " <toolitem action='PaintbucketUnitsAction' />"
470 " <separator />"
471 " <toolitem action='AutoGapAction' />"
472 " <separator />"
473 " <toolitem action='PaintbucketResetAction' />"
474 " </toolbar>"
476 " <toolbar name='EraserToolbar'>"
477 " <toolitem action='EraserWidthAction' />"
478 " <separator />"
479 " <toolitem action='EraserModeAction' />"
480 " </toolbar>"
482 " <toolbar name='TextToolbar'>"
483 " <toolitem action='TextFontFamilyAction' />"
484 " <toolitem action='TextFontSizeAction' />"
485 " <toolitem action='TextBoldAction' />"
486 " <toolitem action='TextItalicAction' />"
487 " <separator />"
488 " <toolitem action='TextAlignAction' />"
489 " <separator />"
490 " <toolitem action='TextLineHeightAction' />"
491 " <toolitem action='TextLetterSpacingAction' />"
492 " <toolitem action='TextWordSpacingAction' />"
493 " <separator />"
494 " <toolitem action='TextOrientationAction' />"
495 " </toolbar>"
497 " <toolbar name='LPEToolToolbar'>"
498 " <toolitem action='LPEToolModeAction' />"
499 " <separator />"
500 " <toolitem action='LPEShowBBoxAction' />"
501 " <toolitem action='LPEBBoxFromSelectionAction' />"
502 " <separator />"
503 " <toolitem action='LPELineSegmentAction' />"
504 " <separator />"
505 " <toolitem action='LPEMeasuringAction' />"
506 " <toolitem action='LPEToolUnitsAction' />"
507 " <separator />"
508 " <toolitem action='LPEOpenLPEDialogAction' />"
509 " </toolbar>"
511 " <toolbar name='DropperToolbar'>"
512 " <toolitem action='DropperOpacityAction' />"
513 " <toolitem action='DropperPickAlphaAction' />"
514 " <toolitem action='DropperSetAlphaAction' />"
515 " </toolbar>"
517 " <toolbar name='ConnectorToolbar'>"
518 // " <toolitem action='ConnectorEditModeAction' />"
519 " <toolitem action='ConnectorAvoidAction' />"
520 " <toolitem action='ConnectorIgnoreAction' />"
521 " <toolitem action='ConnectorOrthogonalAction' />"
522 " <toolitem action='ConnectorCurvatureAction' />"
523 " <toolitem action='ConnectorSpacingAction' />"
524 " <toolitem action='ConnectorGraphAction' />"
525 " <toolitem action='ConnectorLengthAction' />"
526 " <toolitem action='ConnectorDirectedAction' />"
527 " <toolitem action='ConnectorOverlapAction' />"
528 // " <toolitem action='ConnectorNewConnPointAction' />"
529 // " <toolitem action='ConnectorRemoveConnPointAction' />"
530 " </toolbar>"
532 "</ui>"
533 ;
535 static Glib::RefPtr<Gtk::ActionGroup> create_or_fetch_actions( SPDesktop* desktop );
537 static void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop);
539 static void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop);
540 static void update_tool_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
542 static void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop);
543 static void update_aux_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
545 static void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop);
546 static void update_commands_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
548 static GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick( GtkWidget *t, Inkscape::IconSize size, SPButtonType type,
549 Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
550 Inkscape::UI::View::View *view, GtkTooltips *tt);
552 class VerbAction : public Gtk::Action {
553 public:
554 static Glib::RefPtr<VerbAction> create(Inkscape::Verb* verb, Inkscape::Verb* verb2, Inkscape::UI::View::View *view, GtkTooltips *tooltips);
556 virtual ~VerbAction();
557 virtual void set_active(bool active = true);
559 protected:
560 virtual Gtk::Widget* create_menu_item_vfunc();
561 virtual Gtk::Widget* create_tool_item_vfunc();
563 virtual void connect_proxy_vfunc(Gtk::Widget* proxy);
564 virtual void disconnect_proxy_vfunc(Gtk::Widget* proxy);
566 virtual void on_activate();
568 private:
569 Inkscape::Verb* verb;
570 Inkscape::Verb* verb2;
571 Inkscape::UI::View::View *view;
572 GtkTooltips *tooltips;
573 bool active;
575 VerbAction(Inkscape::Verb* verb, Inkscape::Verb* verb2, Inkscape::UI::View::View *view, GtkTooltips *tooltips);
576 };
579 Glib::RefPtr<VerbAction> VerbAction::create(Inkscape::Verb* verb, Inkscape::Verb* verb2, Inkscape::UI::View::View *view, GtkTooltips *tooltips)
580 {
581 Glib::RefPtr<VerbAction> result;
582 SPAction *action = verb->get_action(view);
583 if ( action ) {
584 //SPAction* action2 = verb2 ? verb2->get_action(view) : 0;
585 result = Glib::RefPtr<VerbAction>(new VerbAction(verb, verb2, view, tooltips));
586 }
588 return result;
589 }
591 VerbAction::VerbAction(Inkscape::Verb* verb, Inkscape::Verb* verb2, Inkscape::UI::View::View *view, GtkTooltips *tooltips) :
592 Gtk::Action(Glib::ustring(verb->get_id()), Gtk::StockID(verb->get_image()), Glib::ustring(_(verb->get_name())), Glib::ustring(_(verb->get_tip()))),
593 verb(verb),
594 verb2(verb2),
595 view(view),
596 tooltips(tooltips),
597 active(false)
598 {
599 }
601 VerbAction::~VerbAction()
602 {
603 }
605 Gtk::Widget* VerbAction::create_menu_item_vfunc()
606 {
607 // First call in to get the icon rendered if present in SVG
608 Gtk::Widget *widget = sp_icon_get_icon( property_stock_id().get_value().get_string(), Inkscape::ICON_SIZE_MENU );
609 delete widget;
610 widget = 0;
612 Gtk::Widget* widg = Gtk::Action::create_menu_item_vfunc();
613 // g_message("create_menu_item_vfunc() = %p for '%s'", widg, verb->get_id());
614 return widg;
615 }
617 Gtk::Widget* VerbAction::create_tool_item_vfunc()
618 {
619 // Gtk::Widget* widg = Gtk::Action::create_tool_item_vfunc();
620 Inkscape::IconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/tools/small");
621 GtkWidget* toolbox = 0;
622 GtkWidget *button = sp_toolbox_button_new_from_verb_with_doubleclick( toolbox, toolboxSize,
623 SP_BUTTON_TYPE_TOGGLE,
624 verb,
625 verb2,
626 view,
627 tooltips );
628 if ( active ) {
629 sp_button_toggle_set_down( SP_BUTTON(button), active);
630 }
631 gtk_widget_show_all( button );
632 Gtk::Widget* wrapped = Glib::wrap(button);
633 Gtk::ToolItem* holder = Gtk::manage(new Gtk::ToolItem());
634 holder->add(*wrapped);
636 // g_message("create_tool_item_vfunc() = %p for '%s'", holder, verb->get_id());
637 return holder;
638 }
640 void VerbAction::connect_proxy_vfunc(Gtk::Widget* proxy)
641 {
642 // g_message("connect_proxy_vfunc(%p) for '%s'", proxy, verb->get_id());
643 Gtk::Action::connect_proxy_vfunc(proxy);
644 }
646 void VerbAction::disconnect_proxy_vfunc(Gtk::Widget* proxy)
647 {
648 // g_message("disconnect_proxy_vfunc(%p) for '%s'", proxy, verb->get_id());
649 Gtk::Action::disconnect_proxy_vfunc(proxy);
650 }
652 void VerbAction::set_active(bool active)
653 {
654 this->active = active;
655 Glib::SListHandle<Gtk::Widget*> proxies = get_proxies();
656 for ( Glib::SListHandle<Gtk::Widget*>::iterator it = proxies.begin(); it != proxies.end(); ++it ) {
657 Gtk::ToolItem* ti = dynamic_cast<Gtk::ToolItem*>(*it);
658 if (ti) {
659 // *should* have one child that is the SPButton
660 Gtk::Widget* child = ti->get_child();
661 if ( child && SP_IS_BUTTON(child->gobj()) ) {
662 SPButton* button = SP_BUTTON(child->gobj());
663 sp_button_toggle_set_down( button, active );
664 }
665 }
666 }
667 }
669 void VerbAction::on_activate()
670 {
671 if ( verb ) {
672 SPAction *action = verb->get_action(view);
673 if ( action ) {
674 sp_action_perform(action, 0);
675 }
676 }
677 }
679 /* Global text entry widgets necessary for update */
680 /* GtkWidget *dropper_rgb_entry,
681 *dropper_opacity_entry ; */
682 // should be made a private member once this is converted to class
684 static void delete_connection(GObject * /*obj*/, sigc::connection *connection)
685 {
686 connection->disconnect();
687 delete connection;
688 }
690 static void purge_repr_listener( GObject* /*obj*/, GObject* tbl )
691 {
692 Inkscape::XML::Node* oldrepr = reinterpret_cast<Inkscape::XML::Node *>( g_object_get_data( tbl, "repr" ) );
693 if (oldrepr) { // remove old listener
694 sp_repr_remove_listener_by_data(oldrepr, tbl);
695 Inkscape::GC::release(oldrepr);
696 oldrepr = 0;
697 g_object_set_data( tbl, "repr", NULL );
698 }
699 }
701 // ------------------------------------------------------
703 /**
704 * A simple mediator class that keeps UI controls matched to the preference values they set.
705 */
706 class PrefPusher : public Inkscape::Preferences::Observer
707 {
708 public:
709 /**
710 * Constructor for a boolean value that syncs to the supplied path.
711 * Initializes the widget to the current preference stored state and registers callbacks
712 * for widget changes and preference changes.
713 *
714 * @param act the widget to synchronize preference with.
715 * @param path the path to the preference the widget is synchronized with.
716 * @param callback function to invoke when changes are pushed.
717 * @param cbData data to be passed on to the callback function.
718 */
719 PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*) = 0, GObject *cbData = 0 );
721 /**
722 * Destructor that unregisters the preference callback.
723 */
724 virtual ~PrefPusher();
726 /**
727 * Callback method invoked when the preference setting changes.
728 */
729 virtual void notify(Inkscape::Preferences::Entry const &new_val);
731 private:
732 /**
733 * Callback hook invoked when the widget changes.
734 *
735 * @param act the toggle action widget that was changed.
736 * @param self the PrefPusher instance the callback was registered to.
737 */
738 static void toggleCB( GtkToggleAction *act, PrefPusher *self );
740 /**
741 * Method to handle the widget change.
742 */
743 void handleToggled();
745 GtkToggleAction *act;
746 void (*callback)(GObject*);
747 GObject *cbData;
748 bool freeze;
749 };
751 PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*), GObject *cbData ) :
752 Observer(path),
753 act(act),
754 callback(callback),
755 cbData(cbData),
756 freeze(false)
757 {
758 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggleCB), this);
759 freeze = true;
760 gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path) );
761 freeze = false;
763 Inkscape::Preferences::get()->addObserver(*this);
764 }
766 PrefPusher::~PrefPusher()
767 {
768 Inkscape::Preferences::get()->removeObserver(*this);
769 }
771 void PrefPusher::toggleCB( GtkToggleAction * /*act*/, PrefPusher *self )
772 {
773 if (self) {
774 self->handleToggled();
775 }
776 }
778 void PrefPusher::handleToggled()
779 {
780 if (!freeze) {
781 freeze = true;
782 Inkscape::Preferences::get()->setBool(observed_path, gtk_toggle_action_get_active( act ));
783 if (callback) {
784 (*callback)(cbData);
785 }
786 freeze = false;
787 }
788 }
790 void PrefPusher::notify(Inkscape::Preferences::Entry const &newVal)
791 {
792 bool newBool = newVal.getBool();
793 bool oldBool = gtk_toggle_action_get_active(act);
795 if (!freeze && (newBool != oldBool)) {
796 gtk_toggle_action_set_active( act, newBool );
797 }
798 }
800 static void delete_prefspusher(GtkObject * /*obj*/, PrefPusher *watcher )
801 {
802 delete watcher;
803 }
805 // ------------------------------------------------------
808 GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type,
809 Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
810 Inkscape::UI::View::View *view, GtkTooltips *tt)
811 {
812 SPAction *action = verb->get_action(view);
813 if (!action) {
814 return NULL;
815 }
817 SPAction *doubleclick_action;
818 if (doubleclick_verb) {
819 doubleclick_action = doubleclick_verb->get_action(view);
820 } else {
821 doubleclick_action = NULL;
822 }
824 /* fixme: Handle sensitive/unsensitive */
825 /* fixme: Implement sp_button_new_from_action */
826 GtkWidget *b = sp_button_new(size, type, action, doubleclick_action, tt);
827 gtk_widget_show(b);
830 unsigned int shortcut = sp_shortcut_get_primary(verb);
831 if (shortcut) {
832 gchar key[256];
833 sp_ui_shortcut_string(shortcut, key);
834 gchar *tip = g_strdup_printf ("%s (%s)", action->tip, key);
835 if ( t ) {
836 gtk_toolbar_append_widget( GTK_TOOLBAR(t), b, tip, 0 );
837 }
838 g_free(tip);
839 } else {
840 if ( t ) {
841 gtk_toolbar_append_widget( GTK_TOOLBAR(t), b, action->tip, 0 );
842 }
843 }
845 return b;
846 }
849 static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data )
850 {
851 SPAction* targetAction = SP_ACTION(user_data);
852 if ( targetAction ) {
853 sp_action_perform( targetAction, NULL );
854 }
855 }
857 static void sp_action_action_set_sensitive(SPAction * /*action*/, unsigned int sensitive, void *data)
858 {
859 if ( data ) {
860 GtkAction* act = GTK_ACTION(data);
861 gtk_action_set_sensitive( act, sensitive );
862 }
863 }
865 static SPActionEventVector action_event_vector = {
866 {NULL},
867 NULL,
868 NULL,
869 sp_action_action_set_sensitive,
870 NULL,
871 NULL
872 };
874 static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size )
875 {
876 GtkAction* act = 0;
878 SPAction* targetAction = verb->get_action(view);
879 InkAction* inky = ink_action_new( verb->get_id(), _(verb->get_name()), verb->get_tip(), verb->get_image(), size );
880 act = GTK_ACTION(inky);
881 gtk_action_set_sensitive( act, targetAction->sensitive );
883 g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
885 SPAction*rebound = dynamic_cast<SPAction *>( nr_object_ref( dynamic_cast<NRObject *>(targetAction) ) );
886 nr_active_object_add_listener( (NRActiveObject *)rebound, (NRObjectEventVector *)&action_event_vector, sizeof(SPActionEventVector), inky );
888 return act;
889 }
891 static Glib::RefPtr<Gtk::ActionGroup> create_or_fetch_actions( SPDesktop* desktop )
892 {
893 Inkscape::UI::View::View *view = desktop;
894 gint verbsToUse[] = {
895 // disabled until we have icons for them:
896 //find
897 //SP_VERB_EDIT_TILE,
898 //SP_VERB_EDIT_UNTILE,
899 SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
900 SP_VERB_DIALOG_DISPLAY,
901 SP_VERB_DIALOG_FILL_STROKE,
902 SP_VERB_DIALOG_NAMEDVIEW,
903 SP_VERB_DIALOG_TEXT,
904 SP_VERB_DIALOG_XML_EDITOR,
905 SP_VERB_DIALOG_LAYERS,
906 SP_VERB_EDIT_CLONE,
907 SP_VERB_EDIT_COPY,
908 SP_VERB_EDIT_CUT,
909 SP_VERB_EDIT_DUPLICATE,
910 SP_VERB_EDIT_PASTE,
911 SP_VERB_EDIT_REDO,
912 SP_VERB_EDIT_UNDO,
913 SP_VERB_EDIT_UNLINK_CLONE,
914 SP_VERB_FILE_EXPORT,
915 SP_VERB_FILE_IMPORT,
916 SP_VERB_FILE_NEW,
917 SP_VERB_FILE_OPEN,
918 SP_VERB_FILE_PRINT,
919 SP_VERB_FILE_SAVE,
920 SP_VERB_OBJECT_TO_CURVE,
921 SP_VERB_SELECTION_GROUP,
922 SP_VERB_SELECTION_OUTLINE,
923 SP_VERB_SELECTION_UNGROUP,
924 SP_VERB_ZOOM_1_1,
925 SP_VERB_ZOOM_1_2,
926 SP_VERB_ZOOM_2_1,
927 SP_VERB_ZOOM_DRAWING,
928 SP_VERB_ZOOM_IN,
929 SP_VERB_ZOOM_NEXT,
930 SP_VERB_ZOOM_OUT,
931 SP_VERB_ZOOM_PAGE,
932 SP_VERB_ZOOM_PAGE_WIDTH,
933 SP_VERB_ZOOM_PREV,
934 SP_VERB_ZOOM_SELECTION,
935 };
937 Inkscape::IconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/small");
939 static std::map<SPDesktop*, Glib::RefPtr<Gtk::ActionGroup> > groups;
940 Glib::RefPtr<Gtk::ActionGroup> mainActions;
941 if ( groups.find(desktop) != groups.end() ) {
942 mainActions = groups[desktop];
943 }
945 if ( !mainActions ) {
946 mainActions = Gtk::ActionGroup::create("main");
947 groups[desktop] = mainActions;
948 }
950 for ( guint i = 0; i < G_N_ELEMENTS(verbsToUse); i++ ) {
951 Inkscape::Verb* verb = Inkscape::Verb::get(verbsToUse[i]);
952 if ( verb ) {
953 if (!mainActions->get_action(verb->get_id())) {
954 GtkAction* act = create_action_for_verb( verb, view, toolboxSize );
955 mainActions->add(Glib::wrap(act));
956 }
957 }
958 }
960 if ( !mainActions->get_action("ToolZoom") ) {
961 GtkTooltips *tt = gtk_tooltips_new();
962 for ( guint i = 0; i < G_N_ELEMENTS(tools) && tools[i].type_name; i++ ) {
963 Glib::RefPtr<VerbAction> va = VerbAction::create(Inkscape::Verb::get(tools[i].verb), Inkscape::Verb::get(tools[i].doubleclick_verb), view, tt);
964 if ( va ) {
965 mainActions->add(va);
966 if ( i == 0 ) {
967 va->set_active(true);
968 }
969 }
970 }
971 }
973 #if ENABLE_TASK_SUPPORT
974 if ( !mainActions->get_action("TaskSetAction") ) {
975 GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
977 GtkTreeIter iter;
978 gtk_list_store_append( model, &iter );
979 gtk_list_store_set( model, &iter,
980 0, _("Default"),
981 1, _("Default interface setup"),
982 -1 );
984 gtk_list_store_append( model, &iter );
985 gtk_list_store_set( model, &iter,
986 0, _("Custom"),
987 1, _("Set the custom task"),
988 -1 );
990 gtk_list_store_append( model, &iter );
991 gtk_list_store_set( model, &iter,
992 0, _("Wide"),
993 1, _("Setup for widescreen work"),
994 -1 );
996 EgeSelectOneAction* act = ege_select_one_action_new( "TaskSetAction", _("Task"), (""), NULL, GTK_TREE_MODEL(model) );
997 g_object_set( act, "short_label", _("Task:"), NULL );
998 mainActions->add(Glib::wrap(GTK_ACTION(act)));
999 //g_object_set_data( holder, "mode_action", act );
1001 ege_select_one_action_set_appearance( act, "minimal" );
1002 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
1003 //ege_select_one_action_set_icon_size( act, secondarySize );
1004 ege_select_one_action_set_tooltip_column( act, 1 );
1006 //ege_select_one_action_set_active( act, mode );
1007 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(fireTaskChange), desktop );
1008 }
1009 #endif // ENABLE_TASK_SUPPORT
1011 return mainActions;
1012 }
1015 static void handlebox_detached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/)
1016 {
1017 gtk_widget_set_size_request( widget,
1018 widget->allocation.width,
1019 widget->allocation.height );
1020 }
1022 static void handlebox_attached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/)
1023 {
1024 gtk_widget_set_size_request( widget, -1, -1 );
1025 }
1027 static GtkWidget* toolboxNewCommon( GtkWidget* tb, BarId id, GtkPositionType handlePos )
1028 {
1029 g_object_set_data(G_OBJECT(tb), "desktop", NULL);
1031 gtk_widget_set_sensitive(tb, FALSE);
1033 GtkWidget *hb = 0;
1034 if ( UXManager::getInstance()->isFloatWindowProblem() ) {
1035 hb = gtk_event_box_new(); // A simple, neutral container.
1036 } else {
1037 hb = gtk_handle_box_new();
1038 gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(hb), handlePos);
1039 gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(hb), GTK_SHADOW_OUT);
1040 gtk_handle_box_set_snap_edge(GTK_HANDLE_BOX(hb), GTK_POS_LEFT);
1041 }
1043 gtk_container_add(GTK_CONTAINER(hb), tb);
1044 gtk_widget_show(GTK_WIDGET(tb));
1046 sigc::connection* conn = new sigc::connection;
1047 g_object_set_data(G_OBJECT(hb), "event_context_connection", conn);
1049 if ( GTK_IS_HANDLE_BOX(hb) ) {
1050 g_signal_connect(G_OBJECT(hb), "child_detached", G_CALLBACK(handlebox_detached), static_cast<gpointer>(0));
1051 g_signal_connect(G_OBJECT(hb), "child_attached", G_CALLBACK(handlebox_attached), static_cast<gpointer>(0));
1052 }
1054 gpointer val = GINT_TO_POINTER(id);
1055 g_object_set_data(G_OBJECT(hb), BAR_ID_KEY, val);
1057 return hb;
1058 }
1060 GtkWidget *ToolboxFactory::createToolToolbox()
1061 {
1062 GtkWidget *tb = gtk_vbox_new(FALSE, 0);
1064 return toolboxNewCommon( tb, BAR_TOOL, GTK_POS_TOP );
1065 }
1067 GtkWidget *ToolboxFactory::createAuxToolbox()
1068 {
1069 GtkWidget *tb = gtk_vbox_new(FALSE, 0);
1071 return toolboxNewCommon( tb, BAR_AUX, GTK_POS_LEFT );
1072 }
1074 //####################################
1075 //# Commands Bar
1076 //####################################
1078 GtkWidget *ToolboxFactory::createCommandsToolbox()
1079 {
1080 GtkWidget *tb = gtk_vbox_new(FALSE, 0);
1082 return toolboxNewCommon( tb, BAR_COMMANDS, GTK_POS_LEFT );
1083 }
1085 GtkWidget *ToolboxFactory::createSnapToolbox()
1086 {
1087 GtkWidget *tb = gtk_vbox_new(FALSE, 0);
1089 return toolboxNewCommon( tb, BAR_SNAP, GTK_POS_LEFT );
1090 }
1092 static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
1093 gchar const *label, gchar const *shortLabel, gchar const *tooltip,
1094 Glib::ustring const &path, gdouble def,
1095 GtkWidget *focusTarget,
1096 GtkWidget *us,
1097 GObject *dataKludge,
1098 gboolean altx, gchar const *altx_mark,
1099 gdouble lower, gdouble upper, gdouble step, gdouble page,
1100 gchar const** descrLabels, gdouble const* descrValues, guint descrCount,
1101 void (*callback)(GtkAdjustment *, GObject *),
1102 gdouble climb = 0.1, guint digits = 3, double factor = 1.0 )
1103 {
1104 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1105 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor,
1106 lower, upper, step, page, 0 ) );
1107 if (us) {
1108 sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), adj );
1109 }
1111 gtk_signal_connect( GTK_OBJECT(adj), "value-changed", GTK_SIGNAL_FUNC(callback), dataKludge );
1113 EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, label, tooltip, 0, climb, digits );
1114 if ( shortLabel ) {
1115 g_object_set( act, "short_label", shortLabel, NULL );
1116 }
1118 if ( (descrCount > 0) && descrLabels && descrValues ) {
1119 ege_adjustment_action_set_descriptions( act, descrLabels, descrValues, descrCount );
1120 }
1122 if ( focusTarget ) {
1123 ege_adjustment_action_set_focuswidget( act, focusTarget );
1124 }
1126 if ( altx && altx_mark ) {
1127 g_object_set( G_OBJECT(act), "self-id", altx_mark, NULL );
1128 }
1130 if ( dataKludge ) {
1131 // Rather lame, but it's the only place where we need to get the entry name
1132 // but we don't have an Entry
1133 g_object_set_data( dataKludge, prefs->getEntry(path).getEntryName().data(), adj );
1134 }
1136 // Using a cast just to make sure we pass in the right kind of function pointer
1137 g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
1139 return act;
1140 }
1143 //####################################
1144 //# node editing callbacks
1145 //####################################
1147 /** Temporary hack: Returns the node tool in the active desktop.
1148 * Will go away during tool refactoring. */
1149 static InkNodeTool *get_node_tool()
1150 {
1151 InkNodeTool *tool = 0;
1152 if (SP_ACTIVE_DESKTOP ) {
1153 SPEventContext *ec = SP_ACTIVE_DESKTOP->event_context;
1154 if (INK_IS_NODE_TOOL(ec)) {
1155 tool = static_cast<InkNodeTool*>(ec);
1156 }
1157 }
1158 return tool;
1159 }
1161 static void sp_node_path_edit_add(void)
1162 {
1163 InkNodeTool *nt = get_node_tool();
1164 if (nt) {
1165 nt->_multipath->insertNodes();
1166 }
1167 }
1169 static void sp_node_path_edit_delete(void)
1170 {
1171 InkNodeTool *nt = get_node_tool();
1172 if (nt) {
1173 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1174 nt->_multipath->deleteNodes(prefs->getBool("/tools/nodes/delete_preserves_shape", true));
1175 }
1176 }
1178 static void sp_node_path_edit_delete_segment(void)
1179 {
1180 InkNodeTool *nt = get_node_tool();
1181 if (nt) {
1182 nt->_multipath->deleteSegments();
1183 }
1184 }
1186 static void sp_node_path_edit_break(void)
1187 {
1188 InkNodeTool *nt = get_node_tool();
1189 if (nt) {
1190 nt->_multipath->breakNodes();
1191 }
1192 }
1194 static void sp_node_path_edit_join(void)
1195 {
1196 InkNodeTool *nt = get_node_tool();
1197 if (nt) {
1198 nt->_multipath->joinNodes();
1199 }
1200 }
1202 static void sp_node_path_edit_join_segment(void)
1203 {
1204 InkNodeTool *nt = get_node_tool();
1205 if (nt) {
1206 nt->_multipath->joinSegments();
1207 }
1208 }
1210 static void sp_node_path_edit_toline(void)
1211 {
1212 InkNodeTool *nt = get_node_tool();
1213 if (nt) {
1214 nt->_multipath->setSegmentType(Inkscape::UI::SEGMENT_STRAIGHT);
1215 }
1216 }
1218 static void sp_node_path_edit_tocurve(void)
1219 {
1220 InkNodeTool *nt = get_node_tool();
1221 if (nt) {
1222 nt->_multipath->setSegmentType(Inkscape::UI::SEGMENT_CUBIC_BEZIER);
1223 }
1224 }
1226 static void sp_node_path_edit_cusp(void)
1227 {
1228 InkNodeTool *nt = get_node_tool();
1229 if (nt) {
1230 nt->_multipath->setNodeType(Inkscape::UI::NODE_CUSP);
1231 }
1232 }
1234 static void sp_node_path_edit_smooth(void)
1235 {
1236 InkNodeTool *nt = get_node_tool();
1237 if (nt) {
1238 nt->_multipath->setNodeType(Inkscape::UI::NODE_SMOOTH);
1239 }
1240 }
1242 static void sp_node_path_edit_symmetrical(void)
1243 {
1244 InkNodeTool *nt = get_node_tool();
1245 if (nt) {
1246 nt->_multipath->setNodeType(Inkscape::UI::NODE_SYMMETRIC);
1247 }
1248 }
1250 static void sp_node_path_edit_auto(void)
1251 {
1252 InkNodeTool *nt = get_node_tool();
1253 if (nt) {
1254 nt->_multipath->setNodeType(Inkscape::UI::NODE_AUTO);
1255 }
1256 }
1258 static void sp_node_path_edit_nextLPEparam(GtkAction * /*act*/, gpointer data) {
1259 sp_selection_next_patheffect_param( reinterpret_cast<SPDesktop*>(data) );
1260 }
1262 /* is called when the node selection is modified */
1263 static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tbl)
1264 {
1265 GtkAction* xact = GTK_ACTION( g_object_get_data( tbl, "nodes_x_action" ) );
1266 GtkAction* yact = GTK_ACTION( g_object_get_data( tbl, "nodes_y_action" ) );
1267 GtkAdjustment *xadj = ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION(xact));
1268 GtkAdjustment *yadj = ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION(yact));
1270 // quit if run by the attr_changed listener
1271 if (g_object_get_data( tbl, "freeze" )) {
1272 return;
1273 }
1275 // in turn, prevent listener from responding
1276 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
1278 UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
1279 SPUnit const *unit = tracker->getActiveUnit();
1281 InkNodeTool *nt = get_node_tool();
1282 if (!nt || nt->_selected_nodes->empty()) {
1283 // no path selected
1284 gtk_action_set_sensitive(xact, FALSE);
1285 gtk_action_set_sensitive(yact, FALSE);
1286 } else {
1287 gtk_action_set_sensitive(xact, TRUE);
1288 gtk_action_set_sensitive(yact, TRUE);
1289 Geom::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
1290 Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
1291 Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint();
1293 if (oldx != mid[Geom::X]) {
1294 gtk_adjustment_set_value(xadj, sp_pixels_get_units(mid[Geom::X], *unit));
1295 }
1296 if (oldy != mid[Geom::Y]) {
1297 gtk_adjustment_set_value(yadj, sp_pixels_get_units(mid[Geom::Y], *unit));
1298 }
1299 }
1301 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
1302 }
1304 static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::Dim2 d)
1305 {
1306 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
1307 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1309 UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
1310 SPUnit const *unit = tracker->getActiveUnit();
1312 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
1313 prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"),
1314 sp_units_get_pixels(adj->value, *unit));
1315 }
1317 // quit if run by the attr_changed listener
1318 if (g_object_get_data( tbl, "freeze" )) {
1319 return;
1320 }
1322 // in turn, prevent listener from responding
1323 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
1325 InkNodeTool *nt = get_node_tool();
1326 if (nt && !nt->_selected_nodes->empty()) {
1327 double val = sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit);
1328 double oldval = nt->_selected_nodes->pointwiseBounds()->midpoint()[d];
1329 Geom::Point delta(0,0);
1330 delta[d] = val - oldval;
1331 nt->_multipath->move(delta);
1332 }
1334 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
1335 }
1337 static void sp_node_path_x_value_changed(GtkAdjustment *adj, GObject *tbl)
1338 {
1339 sp_node_path_value_changed(adj, tbl, Geom::X);
1340 }
1342 static void sp_node_path_y_value_changed(GtkAdjustment *adj, GObject *tbl)
1343 {
1344 sp_node_path_value_changed(adj, tbl, Geom::Y);
1345 }
1347 static void sp_node_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl)
1348 {
1349 {
1350 GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "nodes_lpeedit" ) );
1351 SPItem *item = selection->singleItem();
1352 if (item && SP_IS_LPE_ITEM(item)) {
1353 if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) {
1354 gtk_action_set_sensitive(w, TRUE);
1355 } else {
1356 gtk_action_set_sensitive(w, FALSE);
1357 }
1358 } else {
1359 gtk_action_set_sensitive(w, FALSE);
1360 }
1361 }
1362 }
1364 static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl)
1365 {
1366 sp_node_toolbox_sel_changed (selection, tbl);
1367 }
1371 //################################
1372 //## Node Editing Toolbox ##
1373 //################################
1375 static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
1376 {
1377 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
1378 tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
1379 g_object_set_data( holder, "tracker", tracker );
1381 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
1383 {
1384 InkAction* inky = ink_action_new( "NodeInsertAction",
1385 _("Insert node"),
1386 _("Insert new nodes into selected segments"),
1387 INKSCAPE_ICON_NODE_ADD,
1388 secondarySize );
1389 g_object_set( inky, "short_label", _("Insert"), NULL );
1390 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_add), 0 );
1391 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1392 }
1394 {
1395 InkAction* inky = ink_action_new( "NodeDeleteAction",
1396 _("Delete node"),
1397 _("Delete selected nodes"),
1398 INKSCAPE_ICON_NODE_DELETE,
1399 secondarySize );
1400 g_object_set( inky, "short_label", _("Delete"), NULL );
1401 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_delete), 0 );
1402 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1403 }
1405 {
1406 InkAction* inky = ink_action_new( "NodeJoinAction",
1407 _("Join nodes"),
1408 _("Join selected nodes"),
1409 INKSCAPE_ICON_NODE_JOIN,
1410 secondarySize );
1411 g_object_set( inky, "short_label", _("Join"), NULL );
1412 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_join), 0 );
1413 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1414 }
1416 {
1417 InkAction* inky = ink_action_new( "NodeBreakAction",
1418 _("Break nodes"),
1419 _("Break path at selected nodes"),
1420 INKSCAPE_ICON_NODE_BREAK,
1421 secondarySize );
1422 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_break), 0 );
1423 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1424 }
1427 {
1428 InkAction* inky = ink_action_new( "NodeJoinSegmentAction",
1429 _("Join with segment"),
1430 _("Join selected endnodes with a new segment"),
1431 INKSCAPE_ICON_NODE_JOIN_SEGMENT,
1432 secondarySize );
1433 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_join_segment), 0 );
1434 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1435 }
1437 {
1438 InkAction* inky = ink_action_new( "NodeDeleteSegmentAction",
1439 _("Delete segment"),
1440 _("Delete segment between two non-endpoint nodes"),
1441 INKSCAPE_ICON_NODE_DELETE_SEGMENT,
1442 secondarySize );
1443 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_delete_segment), 0 );
1444 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1445 }
1447 {
1448 InkAction* inky = ink_action_new( "NodeCuspAction",
1449 _("Node Cusp"),
1450 _("Make selected nodes corner"),
1451 INKSCAPE_ICON_NODE_TYPE_CUSP,
1452 secondarySize );
1453 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_cusp), 0 );
1454 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1455 }
1457 {
1458 InkAction* inky = ink_action_new( "NodeSmoothAction",
1459 _("Node Smooth"),
1460 _("Make selected nodes smooth"),
1461 INKSCAPE_ICON_NODE_TYPE_SMOOTH,
1462 secondarySize );
1463 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_smooth), 0 );
1464 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1465 }
1467 {
1468 InkAction* inky = ink_action_new( "NodeSymmetricAction",
1469 _("Node Symmetric"),
1470 _("Make selected nodes symmetric"),
1471 INKSCAPE_ICON_NODE_TYPE_SYMMETRIC,
1472 secondarySize );
1473 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_symmetrical), 0 );
1474 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1475 }
1477 {
1478 InkAction* inky = ink_action_new( "NodeAutoAction",
1479 _("Node Auto"),
1480 _("Make selected nodes auto-smooth"),
1481 INKSCAPE_ICON_NODE_TYPE_AUTO_SMOOTH,
1482 secondarySize );
1483 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_auto), 0 );
1484 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1485 }
1487 {
1488 InkAction* inky = ink_action_new( "NodeLineAction",
1489 _("Node Line"),
1490 _("Make selected segments lines"),
1491 INKSCAPE_ICON_NODE_SEGMENT_LINE,
1492 secondarySize );
1493 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_toline), 0 );
1494 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1495 }
1497 {
1498 InkAction* inky = ink_action_new( "NodeCurveAction",
1499 _("Node Curve"),
1500 _("Make selected segments curves"),
1501 INKSCAPE_ICON_NODE_SEGMENT_CURVE,
1502 secondarySize );
1503 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_tocurve), 0 );
1504 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1505 }
1507 {
1508 InkToggleAction* act = ink_toggle_action_new( "NodesShowTransformHandlesAction",
1509 _("Show Transform Handles"),
1510 _("Show node transformation handles"),
1511 "node-transform",
1512 secondarySize );
1513 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
1514 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_transform_handles");
1515 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
1516 }
1518 {
1519 InkToggleAction* act = ink_toggle_action_new( "NodesShowHandlesAction",
1520 _("Show Handles"),
1521 _("Show the Bezier handles of selected nodes"),
1522 INKSCAPE_ICON_SHOW_NODE_HANDLES,
1523 secondarySize );
1524 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
1525 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_handles");
1526 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
1527 }
1529 {
1530 InkToggleAction* act = ink_toggle_action_new( "NodesShowHelperpath",
1531 _("Show Outline"),
1532 _("Show the outline of the path"),
1533 INKSCAPE_ICON_SHOW_PATH_OUTLINE,
1534 secondarySize );
1535 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
1536 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_outline");
1537 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
1538 }
1540 {
1541 InkAction* inky = ink_action_new( "EditNextLPEParameterAction",
1542 _("Next path effect parameter"),
1543 _("Show next path effect parameter for editing"),
1544 INKSCAPE_ICON_PATH_EFFECT_PARAMETER_NEXT,
1545 secondarySize );
1546 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_node_path_edit_nextLPEparam), desktop );
1547 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1548 g_object_set_data( holder, "nodes_lpeedit", inky);
1549 }
1551 {
1552 InkToggleAction* inky = ink_toggle_action_new( "ObjectEditClipPathAction",
1553 _("Edit clipping paths"),
1554 _("Show editing controls for clipping paths of selected objects"),
1555 INKSCAPE_ICON_PATH_CLIP_EDIT,
1556 secondarySize );
1557 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1558 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(inky), "/tools/nodes/edit_clipping_paths");
1559 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
1560 }
1562 {
1563 InkToggleAction* inky = ink_toggle_action_new( "ObjectEditMaskPathAction",
1564 _("Edit masks"),
1565 _("Show editing controls for masks of selected objects"),
1566 INKSCAPE_ICON_PATH_MASK_EDIT,
1567 secondarySize );
1568 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1569 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(inky), "/tools/nodes/edit_masks");
1570 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
1571 }
1573 /* X coord of selected node(s) */
1574 {
1575 EgeAdjustmentAction* eact = 0;
1576 gchar const* labels[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1577 gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
1578 eact = create_adjustment_action( "NodeXAction",
1579 _("X coordinate:"), _("X:"), _("X coordinate of selected node(s)"),
1580 "/tools/nodes/Xcoord", 0,
1581 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-nodes",
1582 -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
1583 labels, values, G_N_ELEMENTS(labels),
1584 sp_node_path_x_value_changed );
1585 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
1586 g_object_set_data( holder, "nodes_x_action", eact );
1587 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
1588 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1589 }
1591 /* Y coord of selected node(s) */
1592 {
1593 EgeAdjustmentAction* eact = 0;
1594 gchar const* labels[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1595 gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
1596 eact = create_adjustment_action( "NodeYAction",
1597 _("Y coordinate:"), _("Y:"), _("Y coordinate of selected node(s)"),
1598 "/tools/nodes/Ycoord", 0,
1599 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
1600 -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
1601 labels, values, G_N_ELEMENTS(labels),
1602 sp_node_path_y_value_changed );
1603 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
1604 g_object_set_data( holder, "nodes_y_action", eact );
1605 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
1606 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1607 }
1609 // add the units menu
1610 {
1611 GtkAction* act = tracker->createAction( "NodeUnitsAction", _("Units"), ("") );
1612 gtk_action_group_add_action( mainActions, act );
1613 }
1616 sp_node_toolbox_sel_changed(sp_desktop_selection(desktop), holder);
1618 //watch selection
1619 Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISNodeToolbox");
1621 sigc::connection *c_selection_changed =
1622 new sigc::connection (sp_desktop_selection (desktop)->connectChanged
1623 (sigc::bind (sigc::ptr_fun (sp_node_toolbox_sel_changed), (GObject*)holder)));
1624 pool->add_connection ("selection-changed", c_selection_changed);
1626 sigc::connection *c_selection_modified =
1627 new sigc::connection (sp_desktop_selection (desktop)->connectModified
1628 (sigc::bind (sigc::ptr_fun (sp_node_toolbox_sel_modified), (GObject*)holder)));
1629 pool->add_connection ("selection-modified", c_selection_modified);
1631 sigc::connection *c_subselection_changed =
1632 new sigc::connection (desktop->connectToolSubselectionChanged
1633 (sigc::bind (sigc::ptr_fun (sp_node_toolbox_coord_changed), (GObject*)holder)));
1634 pool->add_connection ("tool-subselection-changed", c_subselection_changed);
1636 Inkscape::ConnectionPool::connect_destroy (G_OBJECT (holder), pool);
1638 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
1639 } // end of sp_node_toolbox_prep()
1642 //########################
1643 //## Zoom Toolbox ##
1644 //########################
1646 static void sp_zoom_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* /*mainActions*/, GObject* /*holder*/)
1647 {
1648 // no custom GtkAction setup needed
1649 } // end of sp_zoom_toolbox_prep()
1651 void ToolboxFactory::setToolboxDesktop(GtkWidget *toolbox, SPDesktop *desktop)
1652 {
1653 sigc::connection *conn = static_cast<sigc::connection*>(g_object_get_data(G_OBJECT(toolbox),
1654 "event_context_connection"));
1656 BarId id = static_cast<BarId>( GPOINTER_TO_INT(g_object_get_data(G_OBJECT(toolbox), BAR_ID_KEY)) );
1658 SetupFunction setup_func = 0;
1659 UpdateFunction update_func = 0;
1661 switch (id) {
1662 case BAR_TOOL:
1663 setup_func = setup_tool_toolbox;
1664 update_func = update_tool_toolbox;
1665 break;
1667 case BAR_AUX:
1668 toolbox = gtk_bin_get_child(GTK_BIN(toolbox));
1669 setup_func = setup_aux_toolbox;
1670 update_func = update_aux_toolbox;
1671 break;
1673 case BAR_COMMANDS:
1674 setup_func = setup_commands_toolbox;
1675 update_func = update_commands_toolbox;
1676 break;
1678 case BAR_SNAP:
1679 setup_func = setup_snap_toolbox;
1680 update_func = updateSnapToolbox;
1681 break;
1682 default:
1683 g_warning("Unexpected toolbox id encountered.");
1684 }
1686 gpointer ptr = g_object_get_data(G_OBJECT(toolbox), "desktop");
1687 SPDesktop *old_desktop = static_cast<SPDesktop*>(ptr);
1689 if (old_desktop) {
1690 GList *children, *iter;
1692 children = gtk_container_get_children(GTK_CONTAINER(toolbox));
1693 for ( iter = children ; iter ; iter = iter->next ) {
1694 gtk_container_remove( GTK_CONTAINER(toolbox), GTK_WIDGET(iter->data) );
1695 }
1696 g_list_free(children);
1697 }
1699 g_object_set_data(G_OBJECT(toolbox), "desktop", (gpointer)desktop);
1701 if (desktop && setup_func && update_func) {
1702 gtk_widget_set_sensitive(toolbox, TRUE);
1703 setup_func(toolbox, desktop);
1704 update_func(desktop, desktop->event_context, toolbox);
1705 *conn = desktop->connectEventContextChanged(sigc::bind (sigc::ptr_fun(update_func), toolbox));
1706 } else {
1707 gtk_widget_set_sensitive(toolbox, FALSE);
1708 }
1710 } // end of sp_toolbox_set_desktop()
1713 static void setupToolboxCommon( GtkWidget *toolbox,
1714 SPDesktop *desktop,
1715 gchar const *descr,
1716 gchar const* toolbarName,
1717 gchar const* sizePref )
1718 {
1719 Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions( desktop );
1720 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1722 GtkUIManager* mgr = gtk_ui_manager_new();
1723 GError* errVal = 0;
1725 GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
1727 gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 );
1728 gtk_ui_manager_add_ui_from_string( mgr, descr, -1, &errVal );
1730 GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, toolbarName );
1731 if ( prefs->getBool("/toolbox/icononly", true) ) {
1732 gtk_toolbar_set_style( GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS );
1733 }
1735 Inkscape::IconSize toolboxSize = ToolboxFactory::prefToSize(sizePref);
1736 gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), static_cast<GtkIconSize>(toolboxSize) );
1738 if (GTK_IS_HANDLE_BOX(toolbox)) {
1739 // g_message("GRABBING ORIENTATION [%s]", toolbarName);
1740 GtkPositionType pos = gtk_handle_box_get_handle_position(GTK_HANDLE_BOX(toolbox));
1741 orientation = ((pos == GTK_POS_LEFT) || (pos == GTK_POS_RIGHT)) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
1742 } else {
1743 GtkPositionType pos = static_cast<GtkPositionType>(GPOINTER_TO_INT(g_object_get_data( G_OBJECT(toolbox), HANDLE_POS_MARK )));
1744 orientation = ((pos == GTK_POS_LEFT) || (pos == GTK_POS_RIGHT)) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
1745 }
1746 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolBar), orientation);
1747 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolBar), TRUE);
1749 g_object_set_data(G_OBJECT(toolBar), "desktop", NULL);
1751 GtkWidget* child = gtk_bin_get_child(GTK_BIN(toolbox));
1752 if ( child ) {
1753 gtk_container_remove( GTK_CONTAINER(toolbox), child );
1754 }
1756 gtk_container_add( GTK_CONTAINER(toolbox), toolBar );
1757 }
1759 #define noDUMP_DETAILS 1
1761 void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientation)
1762 {
1763 #if DUMP_DETAILS
1764 g_message("Set orientation for %p to be %d", toolbox, orientation);
1765 GType type = GTK_WIDGET_TYPE(toolbox);
1766 g_message(" [%s]", g_type_name(type));
1767 g_message(" %p", g_object_get_data(G_OBJECT(toolbox), BAR_ID_KEY));
1768 #endif
1770 GtkPositionType pos = (orientation == GTK_ORIENTATION_HORIZONTAL) ? GTK_POS_LEFT : GTK_POS_TOP;
1771 GtkHandleBox* handleBox = 0;
1773 if (GTK_IS_BIN(toolbox)) {
1774 #if DUMP_DETAILS
1775 g_message(" is a BIN");
1776 #endif // DUMP_DETAILS
1777 GtkWidget* child = gtk_bin_get_child(GTK_BIN(toolbox));
1778 if (child) {
1779 #if DUMP_DETAILS
1780 GType type2 = GTK_WIDGET_TYPE(child);
1781 g_message(" child [%s]", g_type_name(type2));
1782 #endif // DUMP_DETAILS
1784 if (GTK_IS_BOX(child)) {
1785 #if DUMP_DETAILS
1786 g_message(" is a BOX");
1787 #endif // DUMP_DETAILS
1789 GList* children = gtk_container_get_children(GTK_CONTAINER(child));
1790 if (children) {
1791 for (GList* curr = children; curr; curr = g_list_next(curr)) {
1792 GtkWidget* child2 = GTK_WIDGET(curr->data);
1793 #if DUMP_DETAILS
1794 GType type3 = GTK_WIDGET_TYPE(child2);
1795 g_message(" child2 [%s]", g_type_name(type3));
1796 #endif // DUMP_DETAILS
1798 if (GTK_IS_CONTAINER(child2)) {
1799 GList* children2 = gtk_container_get_children(GTK_CONTAINER(child2));
1800 if (children2) {
1801 for (GList* curr2 = children2; curr2; curr2 = g_list_next(curr2)) {
1802 GtkWidget* child3 = GTK_WIDGET(curr2->data);
1803 #if DUMP_DETAILS
1804 GType type4 = GTK_WIDGET_TYPE(child3);
1805 g_message(" child3 [%s]", g_type_name(type4));
1806 #endif // DUMP_DETAILS
1807 if (GTK_IS_TOOLBAR(child3)) {
1808 GtkToolbar* childBar = GTK_TOOLBAR(child3);
1809 gtk_toolbar_set_orientation(childBar, orientation);
1810 }
1811 }
1812 g_list_free(children2);
1813 }
1814 }
1817 if (GTK_IS_TOOLBAR(child2)) {
1818 GtkToolbar* childBar = GTK_TOOLBAR(child2);
1819 gtk_toolbar_set_orientation(childBar, orientation);
1820 if (GTK_IS_HANDLE_BOX(toolbox)) {
1821 handleBox = GTK_HANDLE_BOX(toolbox);
1822 }
1823 } else {
1824 g_message("need to add dynamic switch");
1825 }
1826 }
1827 g_list_free(children);
1828 } else {
1829 // The call is being made before the toolbox proper has been setup.
1830 if (GTK_IS_HANDLE_BOX(toolbox)) {
1831 handleBox = GTK_HANDLE_BOX(toolbox);
1832 } else {
1833 g_object_set_data(G_OBJECT(toolbox), HANDLE_POS_MARK, GINT_TO_POINTER(pos));
1834 }
1835 }
1836 } else if (GTK_IS_TOOLBAR(child)) {
1837 GtkToolbar* toolbar = GTK_TOOLBAR(child);
1838 gtk_toolbar_set_orientation( toolbar, orientation );
1839 if (GTK_IS_HANDLE_BOX(toolbox)) {
1840 handleBox = GTK_HANDLE_BOX(toolbox);
1841 }
1842 }
1843 }
1844 }
1846 if (handleBox) {
1847 gtk_handle_box_set_handle_position(handleBox, pos);
1848 }
1849 }
1851 void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
1852 {
1853 gchar const * descr =
1854 "<ui>"
1855 " <toolbar name='ToolToolbar'>"
1856 " <toolitem action='ToolSelector' />"
1857 " <toolitem action='ToolNode' />"
1858 " <toolitem action='ToolTweak' />"
1859 " <toolitem action='ToolSpray' />"
1860 " <toolitem action='ToolZoom' />"
1861 " <toolitem action='ToolRect' />"
1862 " <toolitem action='Tool3DBox' />"
1863 " <toolitem action='ToolArc' />"
1864 " <toolitem action='ToolStar' />"
1865 " <toolitem action='ToolSpiral' />"
1866 " <toolitem action='ToolPencil' />"
1867 " <toolitem action='ToolPen' />"
1868 " <toolitem action='ToolCalligraphic' />"
1869 " <toolitem action='ToolEraser' />"
1870 // " <toolitem action='ToolLPETool' />"
1871 " <toolitem action='ToolPaintBucket' />"
1872 " <toolitem action='ToolText' />"
1873 " <toolitem action='ToolConnector' />"
1874 " <toolitem action='ToolGradient' />"
1875 " <toolitem action='ToolDropper' />"
1876 " </toolbar>"
1877 "</ui>";
1879 setupToolboxCommon( toolbox, desktop, descr,
1880 "/ui/ToolToolbar",
1881 "/toolbox/tools/small");
1882 }
1884 void update_tool_toolbox( SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget * /*toolbox*/ )
1885 {
1886 gchar const *const tname = ( eventcontext
1887 ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext))
1888 : NULL );
1889 Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions( desktop );
1891 for (int i = 0 ; tools[i].type_name ; i++ ) {
1892 Glib::RefPtr<Gtk::Action> act = mainActions->get_action( Inkscape::Verb::get(tools[i].verb)->get_id() );
1893 if ( act ) {
1894 bool setActive = tname && !strcmp(tname, tools[i].type_name);
1895 Glib::RefPtr<VerbAction> verbAct = Glib::RefPtr<VerbAction>::cast_dynamic(act);
1896 if ( verbAct ) {
1897 verbAct->set_active(setActive);
1898 }
1899 }
1900 }
1901 }
1903 void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
1904 {
1905 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1906 GtkSizeGroup* grouper = gtk_size_group_new( GTK_SIZE_GROUP_BOTH );
1907 Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions( desktop );
1908 GtkUIManager* mgr = gtk_ui_manager_new();
1909 GError* errVal = 0;
1910 gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 );
1911 gtk_ui_manager_add_ui_from_string( mgr, ui_descr, -1, &errVal );
1913 std::map<std::string, GtkWidget*> dataHolders;
1915 for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1916 if ( aux_toolboxes[i].prep_func ) {
1917 // converted to GtkActions and UIManager
1919 GtkWidget* kludge = gtk_toolbar_new();
1920 g_object_set_data( G_OBJECT(kludge), "dtw", desktop->canvas);
1921 g_object_set_data( G_OBJECT(kludge), "desktop", desktop);
1922 dataHolders[aux_toolboxes[i].type_name] = kludge;
1923 aux_toolboxes[i].prep_func( desktop, mainActions->gobj(), G_OBJECT(kludge) );
1924 } else {
1926 GtkWidget *sub_toolbox = 0;
1927 if (aux_toolboxes[i].create_func == NULL) {
1928 sub_toolbox = sp_empty_toolbox_new(desktop);
1929 } else {
1930 sub_toolbox = aux_toolboxes[i].create_func(desktop);
1931 }
1933 gtk_size_group_add_widget( grouper, sub_toolbox );
1935 gtk_container_add(GTK_CONTAINER(toolbox), sub_toolbox);
1936 g_object_set_data(G_OBJECT(toolbox), aux_toolboxes[i].data_name, sub_toolbox);
1938 }
1939 }
1941 // Second pass to create toolbars *after* all GtkActions are created
1942 for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1943 if ( aux_toolboxes[i].prep_func ) {
1944 // converted to GtkActions and UIManager
1946 GtkWidget* kludge = dataHolders[aux_toolboxes[i].type_name];
1948 GtkWidget* holder = gtk_table_new( 1, 3, FALSE );
1949 gtk_table_attach( GTK_TABLE(holder), kludge, 2, 3, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1951 gchar* tmp = g_strdup_printf( "/ui/%s", aux_toolboxes[i].ui_name );
1952 GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, tmp );
1953 g_free( tmp );
1954 tmp = 0;
1956 if ( prefs->getBool( "/toolbox/icononly", true) ) {
1957 gtk_toolbar_set_style( GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS );
1958 }
1960 Inkscape::IconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/small");
1961 gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), static_cast<GtkIconSize>(toolboxSize) );
1963 gtk_table_attach( GTK_TABLE(holder), toolBar, 0, 1, 0, 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0 );
1965 if ( aux_toolboxes[i].swatch_verb_id != SP_VERB_INVALID ) {
1966 Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch( NULL, _(aux_toolboxes[i].swatch_tip) );
1967 swatch->setDesktop( desktop );
1968 swatch->setClickVerb( aux_toolboxes[i].swatch_verb_id );
1969 swatch->setWatchedTool( aux_toolboxes[i].swatch_tool, true );
1970 GtkWidget *swatch_ = GTK_WIDGET( swatch->gobj() );
1971 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 );
1972 }
1974 gtk_widget_show_all( holder );
1975 sp_set_font_size_smaller( holder );
1977 gtk_size_group_add_widget( grouper, holder );
1979 gtk_container_add( GTK_CONTAINER(toolbox), holder );
1980 g_object_set_data( G_OBJECT(toolbox), aux_toolboxes[i].data_name, holder );
1981 }
1982 }
1984 g_object_unref( G_OBJECT(grouper) );
1985 }
1987 void update_aux_toolbox(SPDesktop * /*desktop*/, SPEventContext *eventcontext, GtkWidget *toolbox)
1988 {
1989 gchar const *tname = ( eventcontext
1990 ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext))
1991 : NULL );
1992 for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) {
1993 GtkWidget *sub_toolbox = GTK_WIDGET(g_object_get_data(G_OBJECT(toolbox), aux_toolboxes[i].data_name));
1994 if (tname && !strcmp(tname, aux_toolboxes[i].type_name)) {
1995 gtk_widget_show_all(sub_toolbox);
1996 g_object_set_data(G_OBJECT(toolbox), "shows", sub_toolbox);
1997 } else {
1998 gtk_widget_hide(sub_toolbox);
1999 }
2000 }
2001 }
2003 void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
2004 {
2005 gchar const * descr =
2006 "<ui>"
2007 " <toolbar name='CommandsToolbar'>"
2008 " <toolitem action='FileNew' />"
2009 " <toolitem action='FileOpen' />"
2010 " <toolitem action='FileSave' />"
2011 " <toolitem action='FilePrint' />"
2012 " <separator />"
2013 " <toolitem action='FileImport' />"
2014 " <toolitem action='FileExport' />"
2015 " <separator />"
2016 " <toolitem action='EditUndo' />"
2017 " <toolitem action='EditRedo' />"
2018 " <separator />"
2019 " <toolitem action='EditCopy' />"
2020 " <toolitem action='EditCut' />"
2021 " <toolitem action='EditPaste' />"
2022 " <separator />"
2023 " <toolitem action='ZoomSelection' />"
2024 " <toolitem action='ZoomDrawing' />"
2025 " <toolitem action='ZoomPage' />"
2026 " <separator />"
2027 " <toolitem action='EditDuplicate' />"
2028 " <toolitem action='EditClone' />"
2029 " <toolitem action='EditUnlinkClone' />"
2030 " <separator />"
2031 " <toolitem action='SelectionGroup' />"
2032 " <toolitem action='SelectionUnGroup' />"
2033 " <separator />"
2034 " <toolitem action='DialogFillStroke' />"
2035 " <toolitem action='DialogText' />"
2036 " <toolitem action='DialogLayers' />"
2037 " <toolitem action='DialogXMLEditor' />"
2038 " <toolitem action='DialogAlignDistribute' />"
2039 " <separator />"
2040 " <toolitem action='DialogPreferences' />"
2041 " <toolitem action='DialogDocumentProperties' />"
2042 #if ENABLE_TASK_SUPPORT
2043 " <separator />"
2044 " <toolitem action='TaskSetAction' />"
2045 #endif // ENABLE_TASK_SUPPORT
2046 " </toolbar>"
2047 "</ui>";
2049 setupToolboxCommon( toolbox, desktop, descr,
2050 "/ui/CommandsToolbar",
2051 "/toolbox/small" );
2052 }
2054 void update_commands_toolbox(SPDesktop * /*desktop*/, SPEventContext * /*eventcontext*/, GtkWidget * /*toolbox*/)
2055 {
2056 }
2058 static void toggle_snap_callback(GtkToggleAction *act, gpointer data) //data points to the toolbox
2059 {
2060 if (g_object_get_data(G_OBJECT(data), "freeze" )) {
2061 return;
2062 }
2064 gpointer ptr = g_object_get_data(G_OBJECT(data), "desktop");
2065 g_assert(ptr != NULL);
2067 SPDesktop *dt = reinterpret_cast<SPDesktop*>(ptr);
2068 SPNamedView *nv = sp_desktop_namedview(dt);
2069 SPDocument *doc = SP_OBJECT_DOCUMENT(nv);
2071 if (dt == NULL || nv == NULL) {
2072 g_warning("No desktop or namedview specified (in toggle_snap_callback)!");
2073 return;
2074 }
2076 Inkscape::XML::Node *repr = SP_OBJECT_REPR(nv);
2078 if (repr == NULL) {
2079 g_warning("This namedview doesn't have a xml representation attached!");
2080 return;
2081 }
2083 bool saved = sp_document_get_undo_sensitive(doc);
2084 sp_document_set_undo_sensitive(doc, false);
2086 bool v = false;
2087 SPAttributeEnum attr = (SPAttributeEnum) GPOINTER_TO_INT(g_object_get_data(G_OBJECT(act), "SP_ATTR_INKSCAPE"));
2089 switch (attr) {
2090 case SP_ATTR_INKSCAPE_SNAP_GLOBAL:
2091 dt->toggleSnapGlobal();
2092 break;
2093 case SP_ATTR_INKSCAPE_SNAP_BBOX:
2094 v = nv->snap_manager.snapprefs.getSnapModeBBox();
2095 sp_repr_set_boolean(repr, "inkscape:snap-bbox", !v);
2096 break;
2097 case SP_ATTR_INKSCAPE_BBOX_PATHS:
2098 v = nv->snap_manager.snapprefs.getSnapToBBoxPath();
2099 sp_repr_set_boolean(repr, "inkscape:bbox-paths", !v);
2100 break;
2101 case SP_ATTR_INKSCAPE_BBOX_NODES:
2102 v = nv->snap_manager.snapprefs.getSnapToBBoxNode();
2103 sp_repr_set_boolean(repr, "inkscape:bbox-nodes", !v);
2104 break;
2105 case SP_ATTR_INKSCAPE_SNAP_NODES:
2106 v = nv->snap_manager.snapprefs.getSnapModeNode();
2107 sp_repr_set_boolean(repr, "inkscape:snap-nodes", !v);
2108 break;
2109 case SP_ATTR_INKSCAPE_OBJECT_PATHS:
2110 v = nv->snap_manager.snapprefs.getSnapToItemPath();
2111 sp_repr_set_boolean(repr, "inkscape:object-paths", !v);
2112 break;
2113 case SP_ATTR_INKSCAPE_OBJECT_NODES:
2114 v = nv->snap_manager.snapprefs.getSnapToItemNode();
2115 sp_repr_set_boolean(repr, "inkscape:object-nodes", !v);
2116 break;
2117 case SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES:
2118 v = nv->snap_manager.snapprefs.getSnapSmoothNodes();
2119 sp_repr_set_boolean(repr, "inkscape:snap-smooth-nodes", !v);
2120 break;
2121 case SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS:
2122 v = nv->snap_manager.snapprefs.getSnapIntersectionCS();
2123 sp_repr_set_boolean(repr, "inkscape:snap-intersection-paths", !v);
2124 break;
2125 case SP_ATTR_INKSCAPE_SNAP_CENTER:
2126 v = nv->snap_manager.snapprefs.getIncludeItemCenter();
2127 sp_repr_set_boolean(repr, "inkscape:snap-center", !v);
2128 break;
2129 case SP_ATTR_INKSCAPE_SNAP_GRIDS:
2130 v = nv->snap_manager.snapprefs.getSnapToGrids();
2131 sp_repr_set_boolean(repr, "inkscape:snap-grids", !v);
2132 break;
2133 case SP_ATTR_INKSCAPE_SNAP_TO_GUIDES:
2134 v = nv->snap_manager.snapprefs.getSnapToGuides();
2135 sp_repr_set_boolean(repr, "inkscape:snap-to-guides", !v);
2136 break;
2137 case SP_ATTR_INKSCAPE_SNAP_PAGE:
2138 v = nv->snap_manager.snapprefs.getSnapToPageBorder();
2139 sp_repr_set_boolean(repr, "inkscape:snap-page", !v);
2140 break;
2141 /*case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE:
2142 v = nv->snap_manager.snapprefs.getSnapIntersectionGG();
2143 sp_repr_set_boolean(repr, "inkscape:snap-intersection-grid-guide", !v);
2144 break;*/
2145 case SP_ATTR_INKSCAPE_SNAP_LINE_MIDPOINTS:
2146 v = nv->snap_manager.snapprefs.getSnapLineMidpoints();
2147 sp_repr_set_boolean(repr, "inkscape:snap-midpoints", !v);
2148 break;
2149 case SP_ATTR_INKSCAPE_SNAP_OBJECT_MIDPOINTS:
2150 v = nv->snap_manager.snapprefs.getSnapObjectMidpoints();
2151 sp_repr_set_boolean(repr, "inkscape:snap-object-midpoints", !v);
2152 break;
2153 case SP_ATTR_INKSCAPE_SNAP_BBOX_EDGE_MIDPOINTS:
2154 v = nv->snap_manager.snapprefs.getSnapBBoxEdgeMidpoints();
2155 sp_repr_set_boolean(repr, "inkscape:snap-bbox-edge-midpoints", !v);
2156 break;
2157 case SP_ATTR_INKSCAPE_SNAP_BBOX_MIDPOINTS:
2158 v = nv->snap_manager.snapprefs.getSnapBBoxMidpoints();
2159 sp_repr_set_boolean(repr, "inkscape:snap-bbox-midpoints", !v);
2160 break;
2161 default:
2162 g_warning("toggle_snap_callback has been called with an ID for which no action has been defined");
2163 break;
2164 }
2166 // The snapping preferences are stored in the document, and therefore toggling makes the document dirty
2167 doc->setModifiedSinceSave();
2169 sp_document_set_undo_sensitive(doc, saved);
2170 }
2172 void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
2173 {
2174 Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions(desktop);
2176 gchar const * descr =
2177 "<ui>"
2178 " <toolbar name='SnapToolbar'>"
2179 " <toolitem action='ToggleSnapGlobal' />"
2180 " <separator />"
2181 " <toolitem action='ToggleSnapFromBBoxCorner' />"
2182 " <toolitem action='ToggleSnapToBBoxPath' />"
2183 " <toolitem action='ToggleSnapToBBoxNode' />"
2184 " <toolitem action='ToggleSnapToFromBBoxEdgeMidpoints' />"
2185 " <toolitem action='ToggleSnapToFromBBoxCenters' />"
2186 " <separator />"
2187 " <toolitem action='ToggleSnapFromNode' />"
2188 " <toolitem action='ToggleSnapToItemPath' />"
2189 " <toolitem action='ToggleSnapToPathIntersections' />"
2190 " <toolitem action='ToggleSnapToItemNode' />"
2191 " <toolitem action='ToggleSnapToSmoothNodes' />"
2192 " <toolitem action='ToggleSnapToFromLineMidpoints' />"
2193 " <toolitem action='ToggleSnapToFromObjectCenters' />"
2194 " <toolitem action='ToggleSnapToFromRotationCenter' />"
2195 " <separator />"
2196 " <toolitem action='ToggleSnapToPageBorder' />"
2197 " <toolitem action='ToggleSnapToGrids' />"
2198 " <toolitem action='ToggleSnapToGuides' />"
2199 //" <toolitem action='ToggleSnapToGridGuideIntersections' />"
2200 " </toolbar>"
2201 "</ui>";
2203 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
2205 {
2206 InkToggleAction* act = ink_toggle_action_new("ToggleSnapGlobal",
2207 _("Snap"), _("Enable snapping"), INKSCAPE_ICON_SNAP, secondarySize,
2208 SP_ATTR_INKSCAPE_SNAP_GLOBAL);
2210 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2211 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2212 }
2214 {
2215 InkToggleAction* act = ink_toggle_action_new("ToggleSnapFromBBoxCorner",
2216 _("Bounding box"), _("Snap bounding box corners"), INKSCAPE_ICON_SNAP_BOUNDING_BOX,
2217 secondarySize, SP_ATTR_INKSCAPE_SNAP_BBOX);
2219 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2220 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2221 }
2223 {
2224 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToBBoxPath",
2225 _("Bounding box edges"), _("Snap to edges of a bounding box"),
2226 INKSCAPE_ICON_SNAP_BOUNDING_BOX_EDGES, secondarySize, SP_ATTR_INKSCAPE_BBOX_PATHS);
2228 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2229 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2230 }
2232 {
2233 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToBBoxNode",
2234 _("Bounding box corners"), _("Snap to bounding box corners"),
2235 INKSCAPE_ICON_SNAP_BOUNDING_BOX_CORNERS, secondarySize, SP_ATTR_INKSCAPE_BBOX_NODES);
2237 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2238 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2239 }
2241 {
2242 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToFromBBoxEdgeMidpoints",
2243 _("BBox Edge Midpoints"), _("Snap from and to midpoints of bounding box edges"),
2244 INKSCAPE_ICON_SNAP_BOUNDING_BOX_MIDPOINTS, secondarySize,
2245 SP_ATTR_INKSCAPE_SNAP_BBOX_EDGE_MIDPOINTS);
2247 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2248 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2249 }
2251 {
2252 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToFromBBoxCenters",
2253 _("BBox Centers"), _("Snapping from and to centers of bounding boxes"),
2254 INKSCAPE_ICON_SNAP_BOUNDING_BOX_CENTER, secondarySize, SP_ATTR_INKSCAPE_SNAP_BBOX_MIDPOINTS);
2256 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2257 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2258 }
2260 {
2261 InkToggleAction* act = ink_toggle_action_new("ToggleSnapFromNode",
2262 _("Nodes"), _("Snap nodes or handles"), INKSCAPE_ICON_SNAP_NODES, secondarySize, SP_ATTR_INKSCAPE_SNAP_NODES);
2264 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2265 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2266 }
2268 {
2269 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToItemPath",
2270 _("Paths"), _("Snap to paths"), INKSCAPE_ICON_SNAP_NODES_PATH, secondarySize,
2271 SP_ATTR_INKSCAPE_OBJECT_PATHS);
2273 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2274 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2275 }
2277 {
2278 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToPathIntersections",
2279 _("Path intersections"), _("Snap to path intersections"),
2280 INKSCAPE_ICON_SNAP_NODES_INTERSECTION, secondarySize, SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS);
2282 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2283 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2284 }
2286 {
2287 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToItemNode",
2288 _("To nodes"), _("Snap to cusp nodes"), INKSCAPE_ICON_SNAP_NODES_CUSP, secondarySize,
2289 SP_ATTR_INKSCAPE_OBJECT_NODES);
2291 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2292 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2293 }
2295 {
2296 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToSmoothNodes",
2297 _("Smooth nodes"), _("Snap to smooth nodes"), INKSCAPE_ICON_SNAP_NODES_SMOOTH,
2298 secondarySize, SP_ATTR_INKSCAPE_SNAP_SMOOTH_NODES);
2300 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2301 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2302 }
2304 {
2305 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToFromLineMidpoints",
2306 _("Line Midpoints"), _("Snap from and to midpoints of line segments"),
2307 INKSCAPE_ICON_SNAP_NODES_MIDPOINT, secondarySize, SP_ATTR_INKSCAPE_SNAP_LINE_MIDPOINTS);
2309 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2310 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2311 }
2313 {
2314 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToFromObjectCenters",
2315 _("Object Centers"), _("Snap from and to centers of objects"),
2316 INKSCAPE_ICON_SNAP_NODES_CENTER, secondarySize, SP_ATTR_INKSCAPE_SNAP_OBJECT_MIDPOINTS);
2318 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2319 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2320 }
2322 {
2323 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToFromRotationCenter",
2324 _("Rotation Centers"), _("Snap from and to an item's rotation center"),
2325 INKSCAPE_ICON_SNAP_NODES_ROTATION_CENTER, secondarySize, SP_ATTR_INKSCAPE_SNAP_CENTER);
2327 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2328 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2329 }
2331 {
2332 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToPageBorder",
2333 _("Page border"), _("Snap to the page border"), INKSCAPE_ICON_SNAP_PAGE,
2334 secondarySize, SP_ATTR_INKSCAPE_SNAP_PAGE);
2336 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2337 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2338 }
2340 {
2341 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGrids",
2342 _("Grids"), _("Snap to grids"), INKSCAPE_ICON_GRID_RECTANGULAR, secondarySize,
2343 SP_ATTR_INKSCAPE_SNAP_GRIDS);
2345 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2346 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2347 }
2349 {
2350 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGuides",
2351 _("Guides"), _("Snap to guides"), INKSCAPE_ICON_GUIDES, secondarySize,
2352 SP_ATTR_INKSCAPE_SNAP_TO_GUIDES);
2354 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2355 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2356 }
2358 /*{
2359 InkToggleAction* act = ink_toggle_action_new("ToggleSnapToGridGuideIntersections",
2360 _("Grid/guide intersections"), _("Snap to intersections of a grid with a guide"),
2361 INKSCAPE_ICON_SNAP_GRID_GUIDE_INTERSECTIONS, secondarySize,
2362 SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE);
2364 gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) );
2365 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );
2366 }*/
2368 setupToolboxCommon( toolbox, desktop, descr,
2369 "/ui/SnapToolbar",
2370 "/toolbox/secondary" );
2371 }
2373 Glib::ustring ToolboxFactory::getToolboxName(GtkWidget* toolbox)
2374 {
2375 Glib::ustring name;
2376 BarId id = static_cast<BarId>( GPOINTER_TO_INT(g_object_get_data(G_OBJECT(toolbox), BAR_ID_KEY)) );
2377 switch(id) {
2378 case BAR_TOOL:
2379 name = "ToolToolbar";
2380 break;
2381 case BAR_AUX:
2382 name = "AuxToolbar";
2383 break;
2384 case BAR_COMMANDS:
2385 name = "CommandsToolbar";
2386 break;
2387 case BAR_SNAP:
2388 name = "SnapToolbar";
2389 break;
2390 }
2392 return name;
2393 }
2395 void ToolboxFactory::updateSnapToolbox(SPDesktop *desktop, SPEventContext * /*eventcontext*/, GtkWidget *toolbox)
2396 {
2397 g_assert(desktop != NULL);
2398 g_assert(toolbox != NULL);
2400 SPNamedView *nv = sp_desktop_namedview(desktop);
2401 if (nv == NULL) {
2402 g_warning("Namedview cannot be retrieved (in updateSnapToolbox)!");
2403 return;
2404 }
2406 Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions(desktop);
2408 Glib::RefPtr<Gtk::Action> act1 = mainActions->get_action("ToggleSnapGlobal");
2409 Glib::RefPtr<Gtk::Action> act2 = mainActions->get_action("ToggleSnapFromBBoxCorner");
2410 Glib::RefPtr<Gtk::Action> act3 = mainActions->get_action("ToggleSnapToBBoxPath");
2411 Glib::RefPtr<Gtk::Action> act4 = mainActions->get_action("ToggleSnapToBBoxNode");
2412 Glib::RefPtr<Gtk::Action> act4b = mainActions->get_action("ToggleSnapToFromBBoxEdgeMidpoints");
2413 Glib::RefPtr<Gtk::Action> act4c = mainActions->get_action("ToggleSnapToFromBBoxCenters");
2414 Glib::RefPtr<Gtk::Action> act5 = mainActions->get_action("ToggleSnapFromNode");
2415 Glib::RefPtr<Gtk::Action> act6 = mainActions->get_action("ToggleSnapToItemPath");
2416 Glib::RefPtr<Gtk::Action> act6b = mainActions->get_action("ToggleSnapToPathIntersections");
2417 Glib::RefPtr<Gtk::Action> act7 = mainActions->get_action("ToggleSnapToItemNode");
2418 Glib::RefPtr<Gtk::Action> act8 = mainActions->get_action("ToggleSnapToSmoothNodes");
2419 Glib::RefPtr<Gtk::Action> act9 = mainActions->get_action("ToggleSnapToFromLineMidpoints");
2420 Glib::RefPtr<Gtk::Action> act10 = mainActions->get_action("ToggleSnapToFromObjectCenters");
2421 Glib::RefPtr<Gtk::Action> act11 = mainActions->get_action("ToggleSnapToFromRotationCenter");
2422 Glib::RefPtr<Gtk::Action> act12 = mainActions->get_action("ToggleSnapToPageBorder");
2423 //Glib::RefPtr<Gtk::Action> act13 = mainActions->get_action("ToggleSnapToGridGuideIntersections");
2424 Glib::RefPtr<Gtk::Action> act14 = mainActions->get_action("ToggleSnapToGrids");
2425 Glib::RefPtr<Gtk::Action> act15 = mainActions->get_action("ToggleSnapToGuides");
2428 if (!act1) {
2429 return; // The snap actions haven't been defined yet (might be the case during startup)
2430 }
2432 // The ..._set_active calls below will toggle the buttons, but this shouldn't lead to
2433 // changes in our document because we're only updating the UI;
2434 // Setting the "freeze" parameter to true will block the code in toggle_snap_callback()
2435 g_object_set_data(G_OBJECT(toolbox), "freeze", GINT_TO_POINTER(TRUE));
2437 bool const c1 = nv->snap_manager.snapprefs.getSnapEnabledGlobally();
2438 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act1->gobj()), c1);
2440 bool const c2 = nv->snap_manager.snapprefs.getSnapModeBBox();
2441 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act2->gobj()), c2);
2442 gtk_action_set_sensitive(GTK_ACTION(act2->gobj()), c1);
2444 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act3->gobj()), nv->snap_manager.snapprefs.getSnapToBBoxPath());
2445 gtk_action_set_sensitive(GTK_ACTION(act3->gobj()), c1 && c2);
2446 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act4->gobj()), nv->snap_manager.snapprefs.getSnapToBBoxNode());
2447 gtk_action_set_sensitive(GTK_ACTION(act4->gobj()), c1 && c2);
2448 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act4b->gobj()), nv->snap_manager.snapprefs.getSnapBBoxEdgeMidpoints());
2449 gtk_action_set_sensitive(GTK_ACTION(act4b->gobj()), c1 && c2);
2450 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act4c->gobj()), nv->snap_manager.snapprefs.getSnapBBoxMidpoints());
2451 gtk_action_set_sensitive(GTK_ACTION(act4c->gobj()), c1 && c2);
2453 bool const c3 = nv->snap_manager.snapprefs.getSnapModeNode();
2454 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act5->gobj()), c3);
2455 gtk_action_set_sensitive(GTK_ACTION(act5->gobj()), c1);
2457 bool const c4 = nv->snap_manager.snapprefs.getSnapToItemPath();
2458 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act6->gobj()), c4);
2459 gtk_action_set_sensitive(GTK_ACTION(act6->gobj()), c1 && c3);
2460 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act6b->gobj()), nv->snap_manager.snapprefs.getSnapIntersectionCS());
2461 gtk_action_set_sensitive(GTK_ACTION(act6b->gobj()), c1 && c3 && c4);
2462 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act7->gobj()), nv->snap_manager.snapprefs.getSnapToItemNode());
2463 gtk_action_set_sensitive(GTK_ACTION(act7->gobj()), c1 && c3);
2464 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act8->gobj()), nv->snap_manager.snapprefs.getSnapSmoothNodes());
2465 gtk_action_set_sensitive(GTK_ACTION(act8->gobj()), c1 && c3);
2466 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act9->gobj()), nv->snap_manager.snapprefs.getSnapLineMidpoints());
2467 gtk_action_set_sensitive(GTK_ACTION(act9->gobj()), c1 && c3);
2468 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act10->gobj()), nv->snap_manager.snapprefs.getSnapObjectMidpoints());
2469 gtk_action_set_sensitive(GTK_ACTION(act10->gobj()), c1 && c3);
2470 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act11->gobj()), nv->snap_manager.snapprefs.getIncludeItemCenter());
2471 gtk_action_set_sensitive(GTK_ACTION(act11->gobj()), c1 && c3);
2473 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act12->gobj()), nv->snap_manager.snapprefs.getSnapToPageBorder());
2474 gtk_action_set_sensitive(GTK_ACTION(act12->gobj()), c1);
2475 //gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act13->gobj()), nv->snap_manager.snapprefs.getSnapIntersectionGG());
2476 //gtk_action_set_sensitive(GTK_ACTION(act13->gobj()), c1);
2478 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act14->gobj()), nv->snap_manager.snapprefs.getSnapToGrids());
2479 gtk_action_set_sensitive(GTK_ACTION(act14->gobj()), c1);
2480 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act15->gobj()), nv->snap_manager.snapprefs.getSnapToGuides());
2481 gtk_action_set_sensitive(GTK_ACTION(act15->gobj()), c1);
2484 g_object_set_data(G_OBJECT(toolbox), "freeze", GINT_TO_POINTER(FALSE)); // unfreeze (see above)
2485 }
2487 void ToolboxFactory::showAuxToolbox(GtkWidget *toolbox_toplevel)
2488 {
2489 gtk_widget_show(toolbox_toplevel);
2490 GtkWidget *toolbox = gtk_bin_get_child(GTK_BIN(toolbox_toplevel));
2492 GtkWidget *shown_toolbox = GTK_WIDGET(g_object_get_data(G_OBJECT(toolbox), "shows"));
2493 if (!shown_toolbox) {
2494 return;
2495 }
2496 gtk_widget_show(toolbox);
2498 gtk_widget_show_all(shown_toolbox);
2499 }
2501 static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop)
2502 {
2503 GtkWidget *tbl = gtk_toolbar_new();
2504 gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas);
2505 gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop);
2507 gtk_widget_show_all(tbl);
2508 sp_set_font_size_smaller (tbl);
2510 return tbl;
2511 }
2513 #define MODE_LABEL_WIDTH 70
2515 //########################
2516 //## Star ##
2517 //########################
2519 static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKludge )
2520 {
2521 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
2523 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2524 // do not remember prefs if this call is initiated by an undo change, because undoing object
2525 // creation sets bogus values to its attributes before it is deleted
2526 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2527 prefs->setInt("/tools/shapes/star/magnitude", (gint)adj->value);
2528 }
2530 // quit if run by the attr_changed listener
2531 if (g_object_get_data( dataKludge, "freeze" )) {
2532 return;
2533 }
2535 // in turn, prevent listener from responding
2536 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
2538 bool modmade = false;
2540 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2541 GSList const *items = selection->itemList();
2542 for (; items != NULL; items = items->next) {
2543 if (SP_IS_STAR((SPItem *) items->data)) {
2544 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2545 sp_repr_set_int(repr,"sodipodi:sides",(gint)adj->value);
2546 sp_repr_set_svg_double(repr, "sodipodi:arg2",
2547 (sp_repr_get_double_attribute(repr, "sodipodi:arg1", 0.5)
2548 + M_PI / (gint)adj->value));
2549 SP_OBJECT((SPItem *) items->data)->updateRepr();
2550 modmade = true;
2551 }
2552 }
2553 if (modmade) {
2554 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
2555 _("Star: Change number of corners"));
2556 }
2558 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
2559 }
2561 static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKludge )
2562 {
2563 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
2565 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2566 if (!IS_NAN(adj->value)) {
2567 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2568 prefs->setDouble("/tools/shapes/star/proportion", adj->value);
2569 }
2570 }
2572 // quit if run by the attr_changed listener
2573 if (g_object_get_data( dataKludge, "freeze" )) {
2574 return;
2575 }
2577 // in turn, prevent listener from responding
2578 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
2580 bool modmade = false;
2581 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2582 GSList const *items = selection->itemList();
2583 for (; items != NULL; items = items->next) {
2584 if (SP_IS_STAR((SPItem *) items->data)) {
2585 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2587 gdouble r1 = sp_repr_get_double_attribute(repr, "sodipodi:r1", 1.0);
2588 gdouble r2 = sp_repr_get_double_attribute(repr, "sodipodi:r2", 1.0);
2589 if (r2 < r1) {
2590 sp_repr_set_svg_double(repr, "sodipodi:r2", r1*adj->value);
2591 } else {
2592 sp_repr_set_svg_double(repr, "sodipodi:r1", r2*adj->value);
2593 }
2595 SP_OBJECT((SPItem *) items->data)->updateRepr();
2596 modmade = true;
2597 }
2598 }
2600 if (modmade) {
2601 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
2602 _("Star: Change spoke ratio"));
2603 }
2605 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
2606 }
2608 static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *dataKludge )
2609 {
2610 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
2611 bool flat = ege_select_one_action_get_active( act ) == 0;
2613 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2614 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2615 prefs->setBool( "/tools/shapes/star/isflatsided", flat);
2616 }
2618 // quit if run by the attr_changed listener
2619 if (g_object_get_data( dataKludge, "freeze" )) {
2620 return;
2621 }
2623 // in turn, prevent listener from responding
2624 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
2626 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2627 GSList const *items = selection->itemList();
2628 GtkAction* prop_action = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) );
2629 bool modmade = false;
2631 if ( prop_action ) {
2632 gtk_action_set_sensitive( prop_action, !flat );
2633 }
2635 for (; items != NULL; items = items->next) {
2636 if (SP_IS_STAR((SPItem *) items->data)) {
2637 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2638 repr->setAttribute("inkscape:flatsided", flat ? "true" : "false" );
2639 SP_OBJECT((SPItem *) items->data)->updateRepr();
2640 modmade = true;
2641 }
2642 }
2644 if (modmade) {
2645 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
2646 flat ? _("Make polygon") : _("Make star"));
2647 }
2649 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
2650 }
2652 static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludge )
2653 {
2654 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
2656 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2657 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2658 prefs->setDouble("/tools/shapes/star/rounded", (gdouble) adj->value);
2659 }
2661 // quit if run by the attr_changed listener
2662 if (g_object_get_data( dataKludge, "freeze" )) {
2663 return;
2664 }
2666 // in turn, prevent listener from responding
2667 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
2669 bool modmade = false;
2671 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2672 GSList const *items = selection->itemList();
2673 for (; items != NULL; items = items->next) {
2674 if (SP_IS_STAR((SPItem *) items->data)) {
2675 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2676 sp_repr_set_svg_double(repr, "inkscape:rounded", (gdouble) adj->value);
2677 SP_OBJECT(items->data)->updateRepr();
2678 modmade = true;
2679 }
2680 }
2681 if (modmade) {
2682 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
2683 _("Star: Change rounding"));
2684 }
2686 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
2687 }
2689 static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKludge )
2690 {
2691 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
2693 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
2694 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2695 prefs->setDouble("/tools/shapes/star/randomized", (gdouble) adj->value);
2696 }
2698 // quit if run by the attr_changed listener
2699 if (g_object_get_data( dataKludge, "freeze" )) {
2700 return;
2701 }
2703 // in turn, prevent listener from responding
2704 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) );
2706 bool modmade = false;
2708 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2709 GSList const *items = selection->itemList();
2710 for (; items != NULL; items = items->next) {
2711 if (SP_IS_STAR((SPItem *) items->data)) {
2712 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
2713 sp_repr_set_svg_double(repr, "inkscape:randomized", (gdouble) adj->value);
2714 SP_OBJECT(items->data)->updateRepr();
2715 modmade = true;
2716 }
2717 }
2718 if (modmade) {
2719 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
2720 _("Star: Change randomization"));
2721 }
2723 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
2724 }
2727 static void star_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
2728 gchar const * /*old_value*/, gchar const * /*new_value*/,
2729 bool /*is_interactive*/, gpointer data)
2730 {
2731 GtkWidget *tbl = GTK_WIDGET(data);
2733 // quit if run by the _changed callbacks
2734 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
2735 return;
2736 }
2738 // in turn, prevent callbacks from responding
2739 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
2741 GtkAdjustment *adj = 0;
2743 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2744 bool isFlatSided = prefs->getBool("/tools/shapes/star/isflatsided", true);
2746 if (!strcmp(name, "inkscape:randomized")) {
2747 adj = GTK_ADJUSTMENT( gtk_object_get_data(GTK_OBJECT(tbl), "randomized") );
2748 gtk_adjustment_set_value(adj, sp_repr_get_double_attribute(repr, "inkscape:randomized", 0.0));
2749 } else if (!strcmp(name, "inkscape:rounded")) {
2750 adj = GTK_ADJUSTMENT( gtk_object_get_data(GTK_OBJECT(tbl), "rounded") );
2751 gtk_adjustment_set_value(adj, sp_repr_get_double_attribute(repr, "inkscape:rounded", 0.0));
2752 } else if (!strcmp(name, "inkscape:flatsided")) {
2753 GtkAction* prop_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "prop_action") );
2754 char const *flatsides = repr->attribute("inkscape:flatsided");
2755 EgeSelectOneAction* flat_action = EGE_SELECT_ONE_ACTION( g_object_get_data( G_OBJECT(tbl), "flat_action" ) );
2756 if ( flatsides && !strcmp(flatsides,"false") ) {
2757 ege_select_one_action_set_active( flat_action, 1 );
2758 gtk_action_set_sensitive( prop_action, TRUE );
2759 } else {
2760 ege_select_one_action_set_active( flat_action, 0 );
2761 gtk_action_set_sensitive( prop_action, FALSE );
2762 }
2763 } else if ((!strcmp(name, "sodipodi:r1") || !strcmp(name, "sodipodi:r2")) && (!isFlatSided) ) {
2764 adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "proportion");
2765 gdouble r1 = sp_repr_get_double_attribute(repr, "sodipodi:r1", 1.0);
2766 gdouble r2 = sp_repr_get_double_attribute(repr, "sodipodi:r2", 1.0);
2767 if (r2 < r1) {
2768 gtk_adjustment_set_value(adj, r2/r1);
2769 } else {
2770 gtk_adjustment_set_value(adj, r1/r2);
2771 }
2772 } else if (!strcmp(name, "sodipodi:sides")) {
2773 adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "magnitude");
2774 gtk_adjustment_set_value(adj, sp_repr_get_int_attribute(repr, "sodipodi:sides", 0));
2775 }
2777 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
2778 }
2781 static Inkscape::XML::NodeEventVector star_tb_repr_events =
2782 {
2783 NULL, /* child_added */
2784 NULL, /* child_removed */
2785 star_tb_event_attr_changed,
2786 NULL, /* content_changed */
2787 NULL /* order_changed */
2788 };
2791 /**
2792 * \param selection Should not be NULL.
2793 */
2794 static void
2795 sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
2796 {
2797 int n_selected = 0;
2798 Inkscape::XML::Node *repr = NULL;
2800 purge_repr_listener( tbl, tbl );
2802 for (GSList const *items = selection->itemList();
2803 items != NULL;
2804 items = items->next)
2805 {
2806 if (SP_IS_STAR((SPItem *) items->data)) {
2807 n_selected++;
2808 repr = SP_OBJECT_REPR((SPItem *) items->data);
2809 }
2810 }
2812 EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
2814 if (n_selected == 0) {
2815 g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
2816 } else if (n_selected == 1) {
2817 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
2819 if (repr) {
2820 g_object_set_data( tbl, "repr", repr );
2821 Inkscape::GC::anchor(repr);
2822 sp_repr_add_listener(repr, &star_tb_repr_events, tbl);
2823 sp_repr_synthesize_events(repr, &star_tb_repr_events, tbl);
2824 }
2825 } else {
2826 // FIXME: implement averaging of all parameters for multiple selected stars
2827 //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
2828 //gtk_label_set_markup(GTK_LABEL(l), _("<b>Change:</b>"));
2829 }
2830 }
2833 static void sp_stb_defaults( GtkWidget * /*widget*/, GObject *dataKludge )
2834 {
2835 // FIXME: in this and all other _default functions, set some flag telling the value_changed
2836 // callbacks to lump all the changes for all selected objects in one undo step
2838 GtkAdjustment *adj = 0;
2840 // fixme: make settable in prefs!
2841 gint mag = 5;
2842 gdouble prop = 0.5;
2843 gboolean flat = FALSE;
2844 gdouble randomized = 0;
2845 gdouble rounded = 0;
2847 EgeSelectOneAction* flat_action = EGE_SELECT_ONE_ACTION( g_object_get_data( dataKludge, "flat_action" ) );
2848 ege_select_one_action_set_active( flat_action, flat ? 0 : 1 );
2850 GtkAction* sb2 = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) );
2851 gtk_action_set_sensitive( sb2, !flat );
2853 adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "magnitude" ) );
2854 gtk_adjustment_set_value(adj, mag);
2855 gtk_adjustment_value_changed(adj);
2857 adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "proportion" ) );
2858 gtk_adjustment_set_value(adj, prop);
2859 gtk_adjustment_value_changed(adj);
2861 adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "rounded" ) );
2862 gtk_adjustment_set_value(adj, rounded);
2863 gtk_adjustment_value_changed(adj);
2865 adj = GTK_ADJUSTMENT( g_object_get_data( dataKludge, "randomized" ) );
2866 gtk_adjustment_set_value(adj, randomized);
2867 gtk_adjustment_value_changed(adj);
2868 }
2871 // public:
2872 void sp_toolbox_add_label(GtkWidget *tbl, gchar const *title, bool wide)
2873 {
2874 GtkWidget *boxl = gtk_hbox_new(FALSE, 0);
2875 if (wide) {
2876 gtk_widget_set_size_request(boxl, MODE_LABEL_WIDTH, -1);
2877 }
2878 GtkWidget *l = gtk_label_new(NULL);
2879 gtk_label_set_markup(GTK_LABEL(l), title);
2880 gtk_box_pack_end(GTK_BOX(boxl), l, FALSE, FALSE, 0);
2881 if ( GTK_IS_TOOLBAR(tbl) ) {
2882 gtk_toolbar_append_widget( GTK_TOOLBAR(tbl), boxl, "", "" );
2883 } else {
2884 gtk_box_pack_start(GTK_BOX(tbl), boxl, FALSE, FALSE, 0);
2885 }
2886 gtk_object_set_data(GTK_OBJECT(tbl), "mode_label", l);
2887 }
2890 static void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
2891 {
2892 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
2894 {
2895 EgeOutputAction* act = ege_output_action_new( "StarStateAction", _("<b>New:</b>"), "", 0 );
2896 ege_output_action_set_use_markup( act, TRUE );
2897 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
2898 g_object_set_data( holder, "mode_action", act );
2899 }
2901 {
2902 EgeAdjustmentAction* eact = 0;
2903 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2904 bool isFlatSided = prefs->getBool("/tools/shapes/star/isflatsided", true);
2906 /* Flatsided checkbox */
2907 {
2908 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
2910 GtkTreeIter iter;
2911 gtk_list_store_append( model, &iter );
2912 gtk_list_store_set( model, &iter,
2913 0, _("Polygon"),
2914 1, _("Regular polygon (with one handle) instead of a star"),
2915 2, INKSCAPE_ICON_DRAW_POLYGON,
2916 -1 );
2918 gtk_list_store_append( model, &iter );
2919 gtk_list_store_set( model, &iter,
2920 0, _("Star"),
2921 1, _("Star instead of a regular polygon (with one handle)"),
2922 2, INKSCAPE_ICON_DRAW_STAR,
2923 -1 );
2925 EgeSelectOneAction* act = ege_select_one_action_new( "FlatAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
2926 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
2927 g_object_set_data( holder, "flat_action", act );
2929 ege_select_one_action_set_appearance( act, "full" );
2930 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
2931 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
2932 ege_select_one_action_set_icon_column( act, 2 );
2933 ege_select_one_action_set_icon_size( act, secondarySize );
2934 ege_select_one_action_set_tooltip_column( act, 1 );
2936 ege_select_one_action_set_active( act, isFlatSided ? 0 : 1 );
2937 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_stb_sides_flat_state_changed), holder);
2938 }
2940 /* Magnitude */
2941 {
2942 gchar const* labels[] = {_("triangle/tri-star"), _("square/quad-star"), _("pentagon/five-pointed star"), _("hexagon/six-pointed star"), 0, 0, 0, 0, 0};
2943 gdouble values[] = {3, 4, 5, 6, 7, 8, 10, 12, 20};
2944 eact = create_adjustment_action( "MagnitudeAction",
2945 _("Corners"), _("Corners:"), _("Number of corners of a polygon or star"),
2946 "/tools/shapes/star/magnitude", 3,
2947 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2948 3, 1024, 1, 5,
2949 labels, values, G_N_ELEMENTS(labels),
2950 sp_stb_magnitude_value_changed,
2951 1.0, 0 );
2952 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2953 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2954 }
2956 /* Spoke ratio */
2957 {
2958 gchar const* labels[] = {_("thin-ray star"), 0, _("pentagram"), _("hexagram"), _("heptagram"), _("octagram"), _("regular polygon")};
2959 gdouble values[] = {0.01, 0.2, 0.382, 0.577, 0.692, 0.765, 1};
2960 eact = create_adjustment_action( "SpokeAction",
2961 _("Spoke ratio"), _("Spoke ratio:"),
2962 // TRANSLATORS: Tip radius of a star is the distance from the center to the farthest handle.
2963 // Base radius is the same for the closest handle.
2964 _("Base radius to tip radius ratio"),
2965 "/tools/shapes/star/proportion", 0.5,
2966 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2967 0.01, 1.0, 0.01, 0.1,
2968 labels, values, G_N_ELEMENTS(labels),
2969 sp_stb_proportion_value_changed );
2970 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2971 g_object_set_data( holder, "prop_action", eact );
2972 }
2974 if ( !isFlatSided ) {
2975 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2976 } else {
2977 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
2978 }
2980 /* Roundedness */
2981 {
2982 gchar const* labels[] = {_("stretched"), _("twisted"), _("slightly pinched"), _("NOT rounded"), _("slightly rounded"), _("visibly rounded"), _("well rounded"), _("amply rounded"), 0, _("stretched"), _("blown up")};
2983 gdouble values[] = {-1, -0.2, -0.03, 0, 0.05, 0.1, 0.2, 0.3, 0.5, 1, 10};
2984 eact = create_adjustment_action( "RoundednessAction",
2985 _("Rounded"), _("Rounded:"), _("How much rounded are the corners (0 for sharp)"),
2986 "/tools/shapes/star/rounded", 0.0,
2987 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
2988 -10.0, 10.0, 0.01, 0.1,
2989 labels, values, G_N_ELEMENTS(labels),
2990 sp_stb_rounded_value_changed );
2991 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
2992 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
2993 }
2995 /* Randomization */
2996 {
2997 gchar const* labels[] = {_("NOT randomized"), _("slightly irregular"), _("visibly randomized"), _("strongly randomized"), _("blown up")};
2998 gdouble values[] = {0, 0.01, 0.1, 0.5, 10};
2999 eact = create_adjustment_action( "RandomizationAction",
3000 _("Randomized"), _("Randomized:"), _("Scatter randomly the corners and angles"),
3001 "/tools/shapes/star/randomized", 0.0,
3002 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
3003 -10.0, 10.0, 0.001, 0.01,
3004 labels, values, G_N_ELEMENTS(labels),
3005 sp_stb_randomized_value_changed, 0.1, 3 );
3006 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3007 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
3008 }
3009 }
3011 {
3012 /* Reset */
3013 {
3014 GtkAction* act = gtk_action_new( "StarResetAction",
3015 _("Defaults"),
3016 _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
3017 GTK_STOCK_CLEAR );
3018 g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_stb_defaults), holder );
3019 gtk_action_group_add_action( mainActions, act );
3020 gtk_action_set_sensitive( act, TRUE );
3021 }
3022 }
3024 sigc::connection *connection = new sigc::connection(
3025 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_star_toolbox_selection_changed), (GObject *)holder))
3026 );
3027 g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
3028 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
3029 }
3032 //########################
3033 //## Rect ##
3034 //########################
3036 static void sp_rtb_sensitivize( GObject *tbl )
3037 {
3038 GtkAdjustment *adj1 = GTK_ADJUSTMENT( g_object_get_data(tbl, "rx") );
3039 GtkAdjustment *adj2 = GTK_ADJUSTMENT( g_object_get_data(tbl, "ry") );
3040 GtkAction* not_rounded = GTK_ACTION( g_object_get_data(tbl, "not_rounded") );
3042 if (adj1->value == 0 && adj2->value == 0 && g_object_get_data(tbl, "single")) { // only for a single selected rect (for now)
3043 gtk_action_set_sensitive( not_rounded, FALSE );
3044 } else {
3045 gtk_action_set_sensitive( not_rounded, TRUE );
3046 }
3047 }
3050 static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name,
3051 void (*setter)(SPRect *, gdouble))
3052 {
3053 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
3055 UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
3056 SPUnit const *unit = tracker->getActiveUnit();
3058 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
3059 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3060 prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name, sp_units_get_pixels(adj->value, *unit));
3061 }
3063 // quit if run by the attr_changed listener
3064 if (g_object_get_data( tbl, "freeze" )) {
3065 return;
3066 }
3068 // in turn, prevent listener from responding
3069 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
3071 bool modmade = false;
3072 Inkscape::Selection *selection = sp_desktop_selection(desktop);
3073 for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
3074 if (SP_IS_RECT(items->data)) {
3075 if (adj->value != 0) {
3076 setter(SP_RECT(items->data), sp_units_get_pixels(adj->value, *unit));
3077 } else {
3078 SP_OBJECT_REPR(items->data)->setAttribute(value_name, NULL);
3079 }
3080 modmade = true;
3081 }
3082 }
3084 sp_rtb_sensitivize( tbl );
3086 if (modmade) {
3087 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_RECT,
3088 _("Change rectangle"));
3089 }
3091 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
3092 }
3094 static void sp_rtb_rx_value_changed(GtkAdjustment *adj, GObject *tbl)
3095 {
3096 sp_rtb_value_changed(adj, tbl, "rx", sp_rect_set_visible_rx);
3097 }
3099 static void sp_rtb_ry_value_changed(GtkAdjustment *adj, GObject *tbl)
3100 {
3101 sp_rtb_value_changed(adj, tbl, "ry", sp_rect_set_visible_ry);
3102 }
3104 static void sp_rtb_width_value_changed(GtkAdjustment *adj, GObject *tbl)
3105 {
3106 sp_rtb_value_changed(adj, tbl, "width", sp_rect_set_visible_width);
3107 }
3109 static void sp_rtb_height_value_changed(GtkAdjustment *adj, GObject *tbl)
3110 {
3111 sp_rtb_value_changed(adj, tbl, "height", sp_rect_set_visible_height);
3112 }
3116 static void sp_rtb_defaults( GtkWidget * /*widget*/, GObject *obj)
3117 {
3118 GtkAdjustment *adj = 0;
3120 adj = GTK_ADJUSTMENT( g_object_get_data(obj, "rx") );
3121 gtk_adjustment_set_value(adj, 0.0);
3122 // this is necessary if the previous value was 0, but we still need to run the callback to change all selected objects
3123 gtk_adjustment_value_changed(adj);
3125 adj = GTK_ADJUSTMENT( g_object_get_data(obj, "ry") );
3126 gtk_adjustment_set_value(adj, 0.0);
3127 gtk_adjustment_value_changed(adj);
3129 sp_rtb_sensitivize( obj );
3130 }
3132 static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar const * /*name*/,
3133 gchar const * /*old_value*/, gchar const * /*new_value*/,
3134 bool /*is_interactive*/, gpointer data)
3135 {
3136 GObject *tbl = G_OBJECT(data);
3138 // quit if run by the _changed callbacks
3139 if (g_object_get_data( tbl, "freeze" )) {
3140 return;
3141 }
3143 // in turn, prevent callbacks from responding
3144 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
3146 UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
3147 SPUnit const *unit = tracker->getActiveUnit();
3149 gpointer item = g_object_get_data( tbl, "item" );
3150 if (item && SP_IS_RECT(item)) {
3151 {
3152 GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) );
3153 gdouble rx = sp_rect_get_visible_rx(SP_RECT(item));
3154 gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit));
3155 }
3157 {
3158 GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) );
3159 gdouble ry = sp_rect_get_visible_ry(SP_RECT(item));
3160 gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit));
3161 }
3163 {
3164 GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) );
3165 gdouble width = sp_rect_get_visible_width (SP_RECT(item));
3166 gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit));
3167 }
3169 {
3170 GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) );
3171 gdouble height = sp_rect_get_visible_height (SP_RECT(item));
3172 gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit));
3173 }
3174 }
3176 sp_rtb_sensitivize( tbl );
3178 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
3179 }
3182 static Inkscape::XML::NodeEventVector rect_tb_repr_events = {
3183 NULL, /* child_added */
3184 NULL, /* child_removed */
3185 rect_tb_event_attr_changed,
3186 NULL, /* content_changed */
3187 NULL /* order_changed */
3188 };
3190 /**
3191 * \param selection should not be NULL.
3192 */
3193 static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
3194 {
3195 int n_selected = 0;
3196 Inkscape::XML::Node *repr = NULL;
3197 SPItem *item = NULL;
3199 if ( g_object_get_data( tbl, "repr" ) ) {
3200 g_object_set_data( tbl, "item", NULL );
3201 }
3202 purge_repr_listener( tbl, tbl );
3204 for (GSList const *items = selection->itemList();
3205 items != NULL;
3206 items = items->next) {
3207 if (SP_IS_RECT((SPItem *) items->data)) {
3208 n_selected++;
3209 item = (SPItem *) items->data;
3210 repr = SP_OBJECT_REPR(item);
3211 }
3212 }
3214 EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
3216 g_object_set_data( tbl, "single", GINT_TO_POINTER(FALSE) );
3218 if (n_selected == 0) {
3219 g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
3221 GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "width_action" ) );
3222 gtk_action_set_sensitive(w, FALSE);
3223 GtkAction* h = GTK_ACTION( g_object_get_data( tbl, "height_action" ) );
3224 gtk_action_set_sensitive(h, FALSE);
3226 } else if (n_selected == 1) {
3227 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3228 g_object_set_data( tbl, "single", GINT_TO_POINTER(TRUE) );
3230 GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "width_action" ) );
3231 gtk_action_set_sensitive(w, TRUE);
3232 GtkAction* h = GTK_ACTION( g_object_get_data( tbl, "height_action" ) );
3233 gtk_action_set_sensitive(h, TRUE);
3235 if (repr) {
3236 g_object_set_data( tbl, "repr", repr );
3237 g_object_set_data( tbl, "item", item );
3238 Inkscape::GC::anchor(repr);
3239 sp_repr_add_listener(repr, &rect_tb_repr_events, tbl);
3240 sp_repr_synthesize_events(repr, &rect_tb_repr_events, tbl);
3241 }
3242 } else {
3243 // FIXME: implement averaging of all parameters for multiple selected
3244 //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
3245 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3246 sp_rtb_sensitivize( tbl );
3247 }
3248 }
3251 static void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
3252 {
3253 EgeAdjustmentAction* eact = 0;
3254 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
3256 {
3257 EgeOutputAction* act = ege_output_action_new( "RectStateAction", _("<b>New:</b>"), "", 0 );
3258 ege_output_action_set_use_markup( act, TRUE );
3259 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3260 g_object_set_data( holder, "mode_action", act );
3261 }
3263 // rx/ry units menu: create
3264 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
3265 //tracker->addUnit( SP_UNIT_PERCENT, 0 );
3266 // fixme: add % meaning per cent of the width/height
3267 tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
3268 g_object_set_data( holder, "tracker", tracker );
3270 /* W */
3271 {
3272 gchar const* labels[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3273 gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
3274 eact = create_adjustment_action( "RectWidthAction",
3275 _("Width"), _("W:"), _("Width of rectangle"),
3276 "/tools/shapes/rect/width", 0,
3277 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-rect",
3278 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
3279 labels, values, G_N_ELEMENTS(labels),
3280 sp_rtb_width_value_changed );
3281 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
3282 g_object_set_data( holder, "width_action", eact );
3283 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
3284 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3285 }
3287 /* H */
3288 {
3289 gchar const* labels[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3290 gdouble values[] = {1, 2, 3, 5, 10, 20, 50, 100, 200, 500};
3291 eact = create_adjustment_action( "RectHeightAction",
3292 _("Height"), _("H:"), _("Height of rectangle"),
3293 "/tools/shapes/rect/height", 0,
3294 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
3295 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
3296 labels, values, G_N_ELEMENTS(labels),
3297 sp_rtb_height_value_changed );
3298 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
3299 g_object_set_data( holder, "height_action", eact );
3300 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
3301 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3302 }
3304 /* rx */
3305 {
3306 gchar const* labels[] = {_("not rounded"), 0, 0, 0, 0, 0, 0, 0, 0};
3307 gdouble values[] = {0.5, 1, 2, 3, 5, 10, 20, 50, 100};
3308 eact = create_adjustment_action( "RadiusXAction",
3309 _("Horizontal radius"), _("Rx:"), _("Horizontal radius of rounded corners"),
3310 "/tools/shapes/rect/rx", 0,
3311 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
3312 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
3313 labels, values, G_N_ELEMENTS(labels),
3314 sp_rtb_rx_value_changed);
3315 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
3316 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3317 }
3319 /* ry */
3320 {
3321 gchar const* labels[] = {_("not rounded"), 0, 0, 0, 0, 0, 0, 0, 0};
3322 gdouble values[] = {0.5, 1, 2, 3, 5, 10, 20, 50, 100};
3323 eact = create_adjustment_action( "RadiusYAction",
3324 _("Vertical radius"), _("Ry:"), _("Vertical radius of rounded corners"),
3325 "/tools/shapes/rect/ry", 0,
3326 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
3327 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
3328 labels, values, G_N_ELEMENTS(labels),
3329 sp_rtb_ry_value_changed);
3330 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
3331 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3332 }
3334 // add the units menu
3335 {
3336 GtkAction* act = tracker->createAction( "RectUnitsAction", _("Units"), ("") );
3337 gtk_action_group_add_action( mainActions, act );
3338 }
3340 /* Reset */
3341 {
3342 InkAction* inky = ink_action_new( "RectResetAction",
3343 _("Not rounded"),
3344 _("Make corners sharp"),
3345 INKSCAPE_ICON_RECTANGLE_MAKE_CORNERS_SHARP,
3346 secondarySize );
3347 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_rtb_defaults), holder );
3348 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
3349 gtk_action_set_sensitive( GTK_ACTION(inky), TRUE );
3350 g_object_set_data( holder, "not_rounded", inky );
3351 }
3353 g_object_set_data( holder, "single", GINT_TO_POINTER(TRUE) );
3354 sp_rtb_sensitivize( holder );
3356 sigc::connection *connection = new sigc::connection(
3357 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_rect_toolbox_selection_changed), (GObject *)holder))
3358 );
3359 g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
3360 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
3361 }
3363 //########################
3364 //## 3D Box ##
3365 //########################
3367 // normalize angle so that it lies in the interval [0,360]
3368 static double box3d_normalize_angle (double a) {
3369 double angle = a + ((int) (a/360.0))*360;
3370 if (angle < 0) {
3371 angle += 360.0;
3372 }
3373 return angle;
3374 }
3376 static void box3d_set_button_and_adjustment(Persp3D *persp,
3377 Proj::Axis axis,
3378 GtkAdjustment *adj,
3379 GtkAction *act,
3380 GtkToggleAction *tact)
3381 {
3382 // TODO: Take all selected perspectives into account but don't touch the state button if not all of them
3383 // have the same state (otherwise a call to box3d_vp_z_state_changed() is triggered and the states
3384 // are reset).
3385 bool is_infinite = !persp3d_VP_is_finite(persp->perspective_impl, axis);
3387 if (is_infinite) {
3388 gtk_toggle_action_set_active(tact, TRUE);
3389 gtk_action_set_sensitive(act, TRUE);
3391 double angle = persp3d_get_infinite_angle(persp, axis);
3392 if (angle != NR_HUGE) { // FIXME: We should catch this error earlier (don't show the spinbutton at all)
3393 gtk_adjustment_set_value(adj, box3d_normalize_angle(angle));
3394 }
3395 } else {
3396 gtk_toggle_action_set_active(tact, FALSE);
3397 gtk_action_set_sensitive(act, FALSE);
3398 }
3399 }
3401 static void box3d_resync_toolbar(Inkscape::XML::Node *persp_repr, GObject *data)
3402 {
3403 if (!persp_repr) {
3404 g_print ("No perspective given to box3d_resync_toolbar().\n");
3405 return;
3406 }
3408 GtkWidget *tbl = GTK_WIDGET(data);
3409 GtkAdjustment *adj = 0;
3410 GtkAction *act = 0;
3411 GtkToggleAction *tact = 0;
3412 Persp3D *persp = persp3d_get_from_repr(persp_repr);
3413 if (!persp) {
3414 // Hmm, is it an error if this happens?
3415 return;
3416 }
3417 {
3418 adj = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(tbl), "box3d_angle_x"));
3419 act = GTK_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_angle_x_action"));
3420 tact = &INK_TOGGLE_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_vp_x_state_action"))->action;
3422 box3d_set_button_and_adjustment(persp, Proj::X, adj, act, tact);
3423 }
3424 {
3425 adj = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(tbl), "box3d_angle_y"));
3426 act = GTK_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_angle_y_action"));
3427 tact = &INK_TOGGLE_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_vp_y_state_action"))->action;
3429 box3d_set_button_and_adjustment(persp, Proj::Y, adj, act, tact);
3430 }
3431 {
3432 adj = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(tbl), "box3d_angle_z"));
3433 act = GTK_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_angle_z_action"));
3434 tact = &INK_TOGGLE_ACTION(g_object_get_data(G_OBJECT(tbl), "box3d_vp_z_state_action"))->action;
3436 box3d_set_button_and_adjustment(persp, Proj::Z, adj, act, tact);
3437 }
3438 }
3440 static void box3d_persp_tb_event_attr_changed(Inkscape::XML::Node *repr,
3441 gchar const * /*name*/,
3442 gchar const * /*old_value*/,
3443 gchar const * /*new_value*/,
3444 bool /*is_interactive*/,
3445 gpointer data)
3446 {
3447 GtkWidget *tbl = GTK_WIDGET(data);
3449 // quit if run by the attr_changed or selection changed listener
3450 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
3451 return;
3452 }
3454 // set freeze so that it can be caught in box3d_angle_z_value_changed() (to avoid calling
3455 // sp_document_maybe_done() when the document is undo insensitive)
3456 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
3458 // TODO: Only update the appropriate part of the toolbar
3459 // if (!strcmp(name, "inkscape:vp_z")) {
3460 box3d_resync_toolbar(repr, G_OBJECT(tbl));
3461 // }
3463 Persp3D *persp = persp3d_get_from_repr(repr);
3464 persp3d_update_box_reprs(persp);
3466 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
3467 }
3469 static Inkscape::XML::NodeEventVector box3d_persp_tb_repr_events =
3470 {
3471 NULL, /* child_added */
3472 NULL, /* child_removed */
3473 box3d_persp_tb_event_attr_changed,
3474 NULL, /* content_changed */
3475 NULL /* order_changed */
3476 };
3478 /**
3479 * \param selection Should not be NULL.
3480 */
3481 // FIXME: This should rather be put into persp3d-reference.cpp or something similar so that it reacts upon each
3482 // Change of the perspective, and not of the current selection (but how to refer to the toolbar then?)
3483 static void box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
3484 {
3485 // Here the following should be done: If all selected boxes have finite VPs in a certain direction,
3486 // disable the angle entry fields for this direction (otherwise entering a value in them should only
3487 // update the perspectives with infinite VPs and leave the other ones untouched).
3489 Inkscape::XML::Node *persp_repr = NULL;
3490 purge_repr_listener(tbl, tbl);
3492 SPItem *item = selection->singleItem();
3493 if (item && SP_IS_BOX3D(item)) {
3494 // FIXME: Also deal with multiple selected boxes
3495 SPBox3D *box = SP_BOX3D(item);
3496 Persp3D *persp = box3d_get_perspective(box);
3497 persp_repr = SP_OBJECT_REPR(persp);
3498 if (persp_repr) {
3499 g_object_set_data(tbl, "repr", persp_repr);
3500 Inkscape::GC::anchor(persp_repr);
3501 sp_repr_add_listener(persp_repr, &box3d_persp_tb_repr_events, tbl);
3502 sp_repr_synthesize_events(persp_repr, &box3d_persp_tb_repr_events, tbl);
3503 }
3505 inkscape_active_document()->setCurrentPersp3D(persp3d_get_from_repr(persp_repr));
3506 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3507 prefs->setString("/tools/shapes/3dbox/persp", persp_repr->attribute("id"));
3509 g_object_set_data(tbl, "freeze", GINT_TO_POINTER(TRUE));
3510 box3d_resync_toolbar(persp_repr, tbl);
3511 g_object_set_data(tbl, "freeze", GINT_TO_POINTER(FALSE));
3512 }
3513 }
3515 static void box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, Proj::Axis axis)
3516 {
3517 SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
3518 SPDocument *document = sp_desktop_document(desktop);
3520 // quit if run by the attr_changed or selection changed listener
3521 if (g_object_get_data( dataKludge, "freeze" )) {
3522 return;
3523 }
3525 // in turn, prevent listener from responding
3526 g_object_set_data(dataKludge, "freeze", GINT_TO_POINTER(TRUE));
3528 std::list<Persp3D *> sel_persps = sp_desktop_selection(desktop)->perspList();
3529 if (sel_persps.empty()) {
3530 // this can happen when the document is created; we silently ignore it
3531 return;
3532 }
3533 Persp3D *persp = sel_persps.front();
3535 persp->perspective_impl->tmat.set_infinite_direction (axis, adj->value);
3536 SP_OBJECT(persp)->updateRepr();
3538 // TODO: use the correct axis here, too
3539 sp_document_maybe_done(document, "perspangle", SP_VERB_CONTEXT_3DBOX, _("3D Box: Change perspective (angle of infinite axis)"));
3541 g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) );
3542 }
3545 static void box3d_angle_x_value_changed(GtkAdjustment *adj, GObject *dataKludge)
3546 {
3547 box3d_angle_value_changed(adj, dataKludge, Proj::X);
3548 }
3550 static void box3d_angle_y_value_changed(GtkAdjustment *adj, GObject *dataKludge)
3551 {
3552 box3d_angle_value_changed(adj, dataKludge, Proj::Y);
3553 }
3555 static void box3d_angle_z_value_changed(GtkAdjustment *adj, GObject *dataKludge)
3556 {
3557 box3d_angle_value_changed(adj, dataKludge, Proj::Z);
3558 }
3561 static void box3d_vp_state_changed( GtkToggleAction *act, GtkAction * /*box3d_angle*/, Proj::Axis axis )
3562 {
3563 // TODO: Take all selected perspectives into account
3564 std::list<Persp3D *> sel_persps = sp_desktop_selection(inkscape_active_desktop())->perspList();
3565 if (sel_persps.empty()) {
3566 // this can happen when the document is created; we silently ignore it
3567 return;
3568 }
3569 Persp3D *persp = sel_persps.front();
3571 bool set_infinite = gtk_toggle_action_get_active(act);
3572 persp3d_set_VP_state (persp, axis, set_infinite ? Proj::VP_INFINITE : Proj::VP_FINITE);
3573 }
3575 static void box3d_vp_x_state_changed( GtkToggleAction *act, GtkAction *box3d_angle )
3576 {
3577 box3d_vp_state_changed(act, box3d_angle, Proj::X);
3578 }
3580 static void box3d_vp_y_state_changed( GtkToggleAction *act, GtkAction *box3d_angle )
3581 {
3582 box3d_vp_state_changed(act, box3d_angle, Proj::Y);
3583 }
3585 static void box3d_vp_z_state_changed( GtkToggleAction *act, GtkAction *box3d_angle )
3586 {
3587 box3d_vp_state_changed(act, box3d_angle, Proj::Z);
3588 }
3590 static void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
3591 {
3592 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3593 EgeAdjustmentAction* eact = 0;
3594 SPDocument *document = sp_desktop_document (desktop);
3595 Persp3DImpl *persp_impl = document->getCurrentPersp3DImpl();
3597 EgeAdjustmentAction* box3d_angle_x = 0;
3598 EgeAdjustmentAction* box3d_angle_y = 0;
3599 EgeAdjustmentAction* box3d_angle_z = 0;
3601 /* Angle X */
3602 {
3603 gchar const* labels[] = { 0, 0, 0, 0, 0, 0, 0 };
3604 gdouble values[] = {-90, -60, -30, 0, 30, 60, 90};
3605 eact = create_adjustment_action( "3DBoxAngleXAction",
3606 _("Angle in X direction"), _("Angle X:"),
3607 // Translators: PL is short for 'perspective line'
3608 _("Angle of PLs in X direction"),
3609 "/tools/shapes/3dbox/box3d_angle_x", 30,
3610 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-box3d",
3611 -360.0, 360.0, 1.0, 10.0,
3612 labels, values, G_N_ELEMENTS(labels),
3613 box3d_angle_x_value_changed );
3614 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3615 g_object_set_data( holder, "box3d_angle_x_action", eact );
3616 box3d_angle_x = eact;
3617 }
3619 if (!persp_impl || !persp3d_VP_is_finite(persp_impl, Proj::X)) {
3620 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
3621 } else {
3622 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
3623 }
3626 /* VP X state */
3627 {
3628 InkToggleAction* act = ink_toggle_action_new( "3DBoxVPXStateAction",
3629 // Translators: VP is short for 'vanishing point'
3630 _("State of VP in X direction"),
3631 _("Toggle VP in X direction between 'finite' and 'infinite' (=parallel)"),
3632 INKSCAPE_ICON_PERSPECTIVE_PARALLEL,
3633 Inkscape::ICON_SIZE_DECORATION );
3634 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3635 g_object_set_data( holder, "box3d_vp_x_state_action", act );
3636 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(box3d_vp_x_state_changed), box3d_angle_x );
3637 gtk_action_set_sensitive( GTK_ACTION(box3d_angle_x), !prefs->getBool("/tools/shapes/3dbox/vp_x_state", true) );
3638 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/shapes/3dbox/vp_x_state", true) );
3639 }
3641 /* Angle Y */
3642 {
3643 gchar const* labels[] = { 0, 0, 0, 0, 0, 0, 0 };
3644 gdouble values[] = {-90, -60, -30, 0, 30, 60, 90};
3645 eact = create_adjustment_action( "3DBoxAngleYAction",
3646 _("Angle in Y direction"), _("Angle Y:"),
3647 // Translators: PL is short for 'perspective line'
3648 _("Angle of PLs in Y direction"),
3649 "/tools/shapes/3dbox/box3d_angle_y", 30,
3650 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
3651 -360.0, 360.0, 1.0, 10.0,
3652 labels, values, G_N_ELEMENTS(labels),
3653 box3d_angle_y_value_changed );
3654 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3655 g_object_set_data( holder, "box3d_angle_y_action", eact );
3656 box3d_angle_y = eact;
3657 }
3659 if (!persp_impl || !persp3d_VP_is_finite(persp_impl, Proj::Y)) {
3660 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
3661 } else {
3662 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
3663 }
3665 /* VP Y state */
3666 {
3667 InkToggleAction* act = ink_toggle_action_new( "3DBoxVPYStateAction",
3668 // Translators: VP is short for 'vanishing point'
3669 _("State of VP in Y direction"),
3670 _("Toggle VP in Y direction between 'finite' and 'infinite' (=parallel)"),
3671 INKSCAPE_ICON_PERSPECTIVE_PARALLEL,
3672 Inkscape::ICON_SIZE_DECORATION );
3673 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3674 g_object_set_data( holder, "box3d_vp_y_state_action", act );
3675 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(box3d_vp_y_state_changed), box3d_angle_y );
3676 gtk_action_set_sensitive( GTK_ACTION(box3d_angle_y), !prefs->getBool("/tools/shapes/3dbox/vp_y_state", true) );
3677 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/shapes/3dbox/vp_y_state", true) );
3678 }
3680 /* Angle Z */
3681 {
3682 gchar const* labels[] = { 0, 0, 0, 0, 0, 0, 0 };
3683 gdouble values[] = {-90, -60, -30, 0, 30, 60, 90};
3684 eact = create_adjustment_action( "3DBoxAngleZAction",
3685 _("Angle in Z direction"), _("Angle Z:"),
3686 // Translators: PL is short for 'perspective line'
3687 _("Angle of PLs in Z direction"),
3688 "/tools/shapes/3dbox/box3d_angle_z", 30,
3689 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
3690 -360.0, 360.0, 1.0, 10.0,
3691 labels, values, G_N_ELEMENTS(labels),
3692 box3d_angle_z_value_changed );
3693 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3694 g_object_set_data( holder, "box3d_angle_z_action", eact );
3695 box3d_angle_z = eact;
3696 }
3698 if (!persp_impl || !persp3d_VP_is_finite(persp_impl, Proj::Z)) {
3699 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
3700 } else {
3701 gtk_action_set_sensitive( GTK_ACTION(eact), FALSE );
3702 }
3704 /* VP Z state */
3705 {
3706 InkToggleAction* act = ink_toggle_action_new( "3DBoxVPZStateAction",
3707 // Translators: VP is short for 'vanishing point'
3708 _("State of VP in Z direction"),
3709 _("Toggle VP in Z direction between 'finite' and 'infinite' (=parallel)"),
3710 INKSCAPE_ICON_PERSPECTIVE_PARALLEL,
3711 Inkscape::ICON_SIZE_DECORATION );
3712 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3713 g_object_set_data( holder, "box3d_vp_z_state_action", act );
3714 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(box3d_vp_z_state_changed), box3d_angle_z );
3715 gtk_action_set_sensitive( GTK_ACTION(box3d_angle_z), !prefs->getBool("/tools/shapes/3dbox/vp_z_state", true) );
3716 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/shapes/3dbox/vp_z_state", true) );
3717 }
3719 sigc::connection *connection = new sigc::connection(
3720 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(box3d_toolbox_selection_changed), (GObject *)holder))
3721 );
3722 g_signal_connect(holder, "destroy", G_CALLBACK(delete_connection), connection);
3723 g_signal_connect(holder, "destroy", G_CALLBACK(purge_repr_listener), holder);
3724 }
3726 //########################
3727 //## Spiral ##
3728 //########################
3730 static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustring const &value_name)
3731 {
3732 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
3734 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
3735 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3736 prefs->setDouble("/tools/shapes/spiral/" + value_name, adj->value);
3737 }
3739 // quit if run by the attr_changed listener
3740 if (g_object_get_data( tbl, "freeze" )) {
3741 return;
3742 }
3744 // in turn, prevent listener from responding
3745 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
3747 gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL);
3749 bool modmade = false;
3750 for (GSList const *items = sp_desktop_selection(desktop)->itemList();
3751 items != NULL;
3752 items = items->next)
3753 {
3754 if (SP_IS_SPIRAL((SPItem *) items->data)) {
3755 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
3756 sp_repr_set_svg_double( repr, namespaced_name, adj->value );
3757 SP_OBJECT((SPItem *) items->data)->updateRepr();
3758 modmade = true;
3759 }
3760 }
3762 g_free(namespaced_name);
3764 if (modmade) {
3765 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SPIRAL,
3766 _("Change spiral"));
3767 }
3769 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
3770 }
3772 static void sp_spl_tb_revolution_value_changed(GtkAdjustment *adj, GObject *tbl)
3773 {
3774 sp_spl_tb_value_changed(adj, tbl, "revolution");
3775 }
3777 static void sp_spl_tb_expansion_value_changed(GtkAdjustment *adj, GObject *tbl)
3778 {
3779 sp_spl_tb_value_changed(adj, tbl, "expansion");
3780 }
3782 static void sp_spl_tb_t0_value_changed(GtkAdjustment *adj, GObject *tbl)
3783 {
3784 sp_spl_tb_value_changed(adj, tbl, "t0");
3785 }
3787 static void sp_spl_tb_defaults(GtkWidget * /*widget*/, GtkObject *obj)
3788 {
3789 GtkWidget *tbl = GTK_WIDGET(obj);
3791 GtkAdjustment *adj;
3793 // fixme: make settable
3794 gdouble rev = 5;
3795 gdouble exp = 1.0;
3796 gdouble t0 = 0.0;
3798 adj = (GtkAdjustment*)gtk_object_get_data(obj, "revolution");
3799 gtk_adjustment_set_value(adj, rev);
3800 gtk_adjustment_value_changed(adj);
3802 adj = (GtkAdjustment*)gtk_object_get_data(obj, "expansion");
3803 gtk_adjustment_set_value(adj, exp);
3804 gtk_adjustment_value_changed(adj);
3806 adj = (GtkAdjustment*)gtk_object_get_data(obj, "t0");
3807 gtk_adjustment_set_value(adj, t0);
3808 gtk_adjustment_value_changed(adj);
3810 spinbutton_defocus(GTK_OBJECT(tbl));
3811 }
3814 static void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr,
3815 gchar const * /*name*/,
3816 gchar const * /*old_value*/,
3817 gchar const * /*new_value*/,
3818 bool /*is_interactive*/,
3819 gpointer data)
3820 {
3821 GtkWidget *tbl = GTK_WIDGET(data);
3823 // quit if run by the _changed callbacks
3824 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
3825 return;
3826 }
3828 // in turn, prevent callbacks from responding
3829 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
3831 GtkAdjustment *adj;
3832 adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "revolution");
3833 gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:revolution", 3.0)));
3835 adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "expansion");
3836 gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:expansion", 1.0)));
3838 adj = (GtkAdjustment*)gtk_object_get_data(GTK_OBJECT(tbl), "t0");
3839 gtk_adjustment_set_value(adj, (sp_repr_get_double_attribute(repr, "sodipodi:t0", 0.0)));
3841 g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
3842 }
3845 static Inkscape::XML::NodeEventVector spiral_tb_repr_events = {
3846 NULL, /* child_added */
3847 NULL, /* child_removed */
3848 spiral_tb_event_attr_changed,
3849 NULL, /* content_changed */
3850 NULL /* order_changed */
3851 };
3853 static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
3854 {
3855 int n_selected = 0;
3856 Inkscape::XML::Node *repr = NULL;
3858 purge_repr_listener( tbl, tbl );
3860 for (GSList const *items = selection->itemList();
3861 items != NULL;
3862 items = items->next)
3863 {
3864 if (SP_IS_SPIRAL((SPItem *) items->data)) {
3865 n_selected++;
3866 repr = SP_OBJECT_REPR((SPItem *) items->data);
3867 }
3868 }
3870 EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
3872 if (n_selected == 0) {
3873 g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
3874 } else if (n_selected == 1) {
3875 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3877 if (repr) {
3878 g_object_set_data( tbl, "repr", repr );
3879 Inkscape::GC::anchor(repr);
3880 sp_repr_add_listener(repr, &spiral_tb_repr_events, tbl);
3881 sp_repr_synthesize_events(repr, &spiral_tb_repr_events, tbl);
3882 }
3883 } else {
3884 // FIXME: implement averaging of all parameters for multiple selected
3885 //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
3886 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
3887 }
3888 }
3891 static void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
3892 {
3893 EgeAdjustmentAction* eact = 0;
3894 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
3896 {
3897 EgeOutputAction* act = ege_output_action_new( "SpiralStateAction", _("<b>New:</b>"), "", 0 );
3898 ege_output_action_set_use_markup( act, TRUE );
3899 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
3900 g_object_set_data( holder, "mode_action", act );
3901 }
3903 /* Revolution */
3904 {
3905 gchar const* labels[] = {_("just a curve"), 0, _("one full revolution"), 0, 0, 0, 0, 0, 0};
3906 gdouble values[] = {0.01, 0.5, 1, 2, 3, 5, 10, 20, 50, 100};
3907 eact = create_adjustment_action( "SpiralRevolutionAction",
3908 _("Number of turns"), _("Turns:"), _("Number of revolutions"),
3909 "/tools/shapes/spiral/revolution", 3.0,
3910 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spiral",
3911 0.01, 1024.0, 0.1, 1.0,
3912 labels, values, G_N_ELEMENTS(labels),
3913 sp_spl_tb_revolution_value_changed, 1, 2);
3914 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3915 }
3917 /* Expansion */
3918 {
3919 gchar const* labels[] = {_("circle"), _("edge is much denser"), _("edge is denser"), _("even"), _("center is denser"), _("center is much denser"), 0};
3920 gdouble values[] = {0, 0.1, 0.5, 1, 1.5, 5, 20};
3921 eact = create_adjustment_action( "SpiralExpansionAction",
3922 _("Divergence"), _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"),
3923 "/tools/shapes/spiral/expansion", 1.0,
3924 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
3925 0.0, 1000.0, 0.01, 1.0,
3926 labels, values, G_N_ELEMENTS(labels),
3927 sp_spl_tb_expansion_value_changed);
3928 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3929 }
3931 /* T0 */
3932 {
3933 gchar const* labels[] = {_("starts from center"), _("starts mid-way"), _("starts near edge")};
3934 gdouble values[] = {0, 0.5, 0.9};
3935 eact = create_adjustment_action( "SpiralT0Action",
3936 _("Inner radius"), _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"),
3937 "/tools/shapes/spiral/t0", 0.0,
3938 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
3939 0.0, 0.999, 0.01, 1.0,
3940 labels, values, G_N_ELEMENTS(labels),
3941 sp_spl_tb_t0_value_changed);
3942 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
3943 }
3945 /* Reset */
3946 {
3947 InkAction* inky = ink_action_new( "SpiralResetAction",
3948 _("Defaults"),
3949 _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
3950 GTK_STOCK_CLEAR,
3951 secondarySize );
3952 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_spl_tb_defaults), holder );
3953 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
3954 }
3957 sigc::connection *connection = new sigc::connection(
3958 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_spiral_toolbox_selection_changed), (GObject *)holder))
3959 );
3960 g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
3961 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
3962 }
3964 //########################
3965 //## Pen/Pencil ##
3966 //########################
3968 /* This is used in generic functions below to share large portions of code between pen and pencil tool */
3969 static Glib::ustring const freehand_tool_name(GObject *dataKludge)
3970 {
3971 SPDesktop *desktop = (SPDesktop *) g_object_get_data(dataKludge, "desktop");
3972 return ( tools_isactive(desktop, TOOLS_FREEHAND_PEN)
3973 ? "/tools/freehand/pen"
3974 : "/tools/freehand/pencil" );
3975 }
3977 static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
3978 {
3979 gint mode = ege_select_one_action_get_active(act);
3981 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3982 prefs->setInt(freehand_tool_name(tbl) + "/freehand-mode", mode);
3984 SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop");
3986 // in pen tool we have more options than in pencil tool; if one of them was chosen, we do any
3987 // preparatory work here
3988 if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
3989 SPPenContext *pc = SP_PEN_CONTEXT(desktop->event_context);
3990 sp_pen_context_set_polyline_mode(pc);
3991 }
3992 }
3994 static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
3995 {
3996 /* Freehand mode toggle buttons */
3997 {
3998 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3999 guint freehandMode = prefs->getInt(( tool_is_pencil ? "/tools/freehand/pencil/freehand-mode" : "/tools/freehand/pen/freehand-mode" ), 0);
4000 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
4002 {
4003 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
4005 GtkTreeIter iter;
4006 gtk_list_store_append( model, &iter );
4007 gtk_list_store_set( model, &iter,
4008 0, _("Bezier"),
4009 1, _("Create regular Bezier path"),
4010 2, INKSCAPE_ICON_PATH_MODE_BEZIER,
4011 -1 );
4013 gtk_list_store_append( model, &iter );
4014 gtk_list_store_set( model, &iter,
4015 0, _("Spiro"),
4016 1, _("Create Spiro path"),
4017 2, INKSCAPE_ICON_PATH_MODE_SPIRO,
4018 -1 );
4020 if (!tool_is_pencil) {
4021 gtk_list_store_append( model, &iter );
4022 gtk_list_store_set( model, &iter,
4023 0, _("Zigzag"),
4024 1, _("Create a sequence of straight line segments"),
4025 2, INKSCAPE_ICON_PATH_MODE_POLYLINE,
4026 -1 );
4028 gtk_list_store_append( model, &iter );
4029 gtk_list_store_set( model, &iter,
4030 0, _("Paraxial"),
4031 1, _("Create a sequence of paraxial line segments"),
4032 2, INKSCAPE_ICON_PATH_MODE_POLYLINE_PARAXIAL,
4033 -1 );
4034 }
4036 EgeSelectOneAction* act = ege_select_one_action_new(tool_is_pencil ?
4037 "FreehandModeActionPencil" :
4038 "FreehandModeActionPen",
4039 (_("Mode:")), (_("Mode of new lines drawn by this tool")), NULL, GTK_TREE_MODEL(model) );
4040 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
4042 ege_select_one_action_set_appearance( act, "full" );
4043 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
4044 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
4045 ege_select_one_action_set_icon_column( act, 2 );
4046 ege_select_one_action_set_icon_size( act, secondarySize );
4047 ege_select_one_action_set_tooltip_column( act, 1 );
4049 ege_select_one_action_set_active( act, freehandMode);
4050 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(freehand_mode_changed), holder);
4051 }
4052 }
4053 }
4055 static void freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) {
4056 gint shape = ege_select_one_action_get_active( act );
4057 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4058 prefs->setInt(freehand_tool_name(dataKludge) + "/shape", shape);
4059 }
4061 /**
4062 * \brief Generate the list of freehand advanced shape option entries.
4063 */
4064 static GList * freehand_shape_dropdown_items_list() {
4065 GList *glist = NULL;
4067 glist = g_list_append (glist, _("None"));
4068 glist = g_list_append (glist, _("Triangle in"));
4069 glist = g_list_append (glist, _("Triangle out"));
4070 glist = g_list_append (glist, _("Ellipse"));
4071 glist = g_list_append (glist, _("From clipboard"));
4073 return glist;
4074 }
4076 static void freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
4077 {
4078 /*advanced shape options */
4079 {
4080 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4081 GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
4083 GList* items = 0;
4084 gint count = 0;
4085 for ( items = freehand_shape_dropdown_items_list(); items ; items = g_list_next(items) )
4086 {
4087 GtkTreeIter iter;
4088 gtk_list_store_append( model, &iter );
4089 gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
4090 count++;
4091 }
4092 g_list_free( items );
4093 items = 0;
4094 EgeSelectOneAction* act1 = ege_select_one_action_new(
4095 tool_is_pencil ? "SetPencilShapeAction" : "SetPenShapeAction",
4096 _("Shape:"), (_("Shape of new paths drawn by this tool")), NULL, GTK_TREE_MODEL(model));
4097 g_object_set( act1, "short_label", _("Shape:"), NULL );
4098 ege_select_one_action_set_appearance( act1, "compact" );
4099 ege_select_one_action_set_active( act1, prefs->getInt(( tool_is_pencil ? "/tools/freehand/pencil/shape" : "/tools/freehand/pen/shape" ), 0) );
4100 g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(freehand_change_shape), holder );
4101 gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
4102 g_object_set_data( holder, "shape_action", act1 );
4103 }
4104 }
4106 static void sp_pen_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder)
4107 {
4108 sp_add_freehand_mode_toggle(mainActions, holder, false);
4109 freehand_add_advanced_shape_options(mainActions, holder, false);
4110 }
4113 static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GtkObject *obj)
4114 {
4115 GtkWidget *tbl = GTK_WIDGET(obj);
4117 GtkAdjustment *adj;
4119 // fixme: make settable
4120 gdouble tolerance = 4;
4122 adj = (GtkAdjustment*)gtk_object_get_data(obj, "tolerance");
4123 gtk_adjustment_set_value(adj, tolerance);
4124 gtk_adjustment_value_changed(adj);
4126 spinbutton_defocus(GTK_OBJECT(tbl));
4127 }
4129 static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl)
4130 {
4131 // quit if run by the attr_changed listener
4132 if (g_object_get_data( tbl, "freeze" )) {
4133 return;
4134 }
4135 // in turn, prevent listener from responding
4136 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4137 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
4138 prefs->setDouble("/tools/freehand/pencil/tolerance", adj->value);
4139 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
4140 }
4142 /*
4143 class PencilToleranceObserver : public Inkscape::Preferences::Observer {
4144 public:
4145 PencilToleranceObserver(Glib::ustring const &path, GObject *x) : Observer(path), _obj(x)
4146 {
4147 g_object_set_data(_obj, "prefobserver", this);
4148 }
4149 virtual ~PencilToleranceObserver() {
4150 if (g_object_get_data(_obj, "prefobserver") == this) {
4151 g_object_set_data(_obj, "prefobserver", NULL);
4152 }
4153 }
4154 virtual void notify(Inkscape::Preferences::Entry const &val) {
4155 GObject* tbl = _obj;
4156 if (g_object_get_data( tbl, "freeze" )) {
4157 return;
4158 }
4159 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
4161 GtkAdjustment * adj = (GtkAdjustment*)g_object_get_data(tbl, "tolerance");
4163 double v = val.getDouble(adj->value);
4164 gtk_adjustment_set_value(adj, v);
4165 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
4166 }
4167 private:
4168 GObject *_obj;
4169 };
4170 */
4172 static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
4173 {
4174 sp_add_freehand_mode_toggle(mainActions, holder, true);
4176 EgeAdjustmentAction* eact = 0;
4178 /* Tolerance */
4179 {
4180 gchar const* labels[] = {_("(many nodes, rough)"), _("(default)"), 0, 0, 0, 0, _("(few nodes, smooth)")};
4181 gdouble values[] = {1, 10, 20, 30, 50, 75, 100};
4182 eact = create_adjustment_action( "PencilToleranceAction",
4183 _("Smoothing:"), _("Smoothing: "),
4184 _("How much smoothing (simplifying) is applied to the line"),
4185 "/tools/freehand/pencil/tolerance",
4186 3.0,
4187 GTK_WIDGET(desktop->canvas), NULL,
4188 holder, TRUE, "altx-pencil",
4189 1, 100.0, 0.5, 1.0,
4190 labels, values, G_N_ELEMENTS(labels),
4191 sp_pencil_tb_tolerance_value_changed,
4192 1, 2);
4193 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4194 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4195 }
4197 /* advanced shape options */
4198 freehand_add_advanced_shape_options(mainActions, holder, true);
4200 /* Reset */
4201 {
4202 InkAction* inky = ink_action_new( "PencilResetAction",
4203 _("Defaults"),
4204 _("Reset pencil parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
4205 GTK_STOCK_CLEAR,
4206 Inkscape::ICON_SIZE_SMALL_TOOLBAR );
4207 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_pencil_tb_defaults), holder );
4208 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
4209 }
4211 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
4213 }
4216 //########################
4217 //## Tweak ##
4218 //########################
4220 static void sp_tweak_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4221 {
4222 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4223 prefs->setDouble( "/tools/tweak/width", adj->value * 0.01 );
4224 }
4226 static void sp_tweak_force_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4227 {
4228 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4229 prefs->setDouble( "/tools/tweak/force", adj->value * 0.01 );
4230 }
4232 static void sp_tweak_pressure_state_changed( GtkToggleAction *act, gpointer /*data*/ )
4233 {
4234 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4235 prefs->setBool("/tools/tweak/usepressure", gtk_toggle_action_get_active(act));
4236 }
4238 static void sp_tweak_mode_changed( EgeSelectOneAction *act, GObject *tbl )
4239 {
4240 int mode = ege_select_one_action_get_active( act );
4241 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4242 prefs->setInt("/tools/tweak/mode", mode);
4244 static gchar const* names[] = {"tweak_doh", "tweak_dos", "tweak_dol", "tweak_doo", "tweak_channels_label"};
4245 bool flag = ((mode == TWEAK_MODE_COLORPAINT) || (mode == TWEAK_MODE_COLORJITTER));
4246 for (size_t i = 0; i < G_N_ELEMENTS(names); ++i) {
4247 GtkAction *act = GTK_ACTION(g_object_get_data( tbl, names[i] ));
4248 if (act) {
4249 gtk_action_set_sensitive(act, flag);
4250 }
4251 }
4252 GtkAction *fid = GTK_ACTION(g_object_get_data( tbl, "tweak_fidelity"));
4253 if (fid) {
4254 gtk_action_set_sensitive(fid, !flag);
4255 }
4256 }
4258 static void sp_tweak_fidelity_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4259 {
4260 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4261 prefs->setDouble( "/tools/tweak/fidelity", adj->value * 0.01 );
4262 }
4264 static void tweak_toggle_doh(GtkToggleAction *act, gpointer /*data*/) {
4265 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4266 prefs->setBool("/tools/tweak/doh", gtk_toggle_action_get_active(act));
4267 }
4268 static void tweak_toggle_dos(GtkToggleAction *act, gpointer /*data*/) {
4269 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4270 prefs->setBool("/tools/tweak/dos", gtk_toggle_action_get_active(act));
4271 }
4272 static void tweak_toggle_dol(GtkToggleAction *act, gpointer /*data*/) {
4273 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4274 prefs->setBool("/tools/tweak/dol", gtk_toggle_action_get_active(act));
4275 }
4276 static void tweak_toggle_doo(GtkToggleAction *act, gpointer /*data*/) {
4277 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4278 prefs->setBool("/tools/tweak/doo", gtk_toggle_action_get_active(act));
4279 }
4281 static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
4282 {
4283 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
4284 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4286 {
4287 /* Width */
4288 gchar const* labels[] = {_("(pinch tweak)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad tweak)")};
4289 gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
4290 EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction",
4291 _("Width"), _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"),
4292 "/tools/tweak/width", 15,
4293 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak",
4294 1, 100, 1.0, 10.0,
4295 labels, values, G_N_ELEMENTS(labels),
4296 sp_tweak_width_value_changed, 0.01, 0, 100 );
4297 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4298 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4299 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4300 }
4303 {
4304 /* Force */
4305 gchar const* labels[] = {_("(minimum force)"), 0, 0, _("(default)"), 0, 0, 0, _("(maximum force)")};
4306 gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100};
4307 EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction",
4308 _("Force"), _("Force:"), _("The force of the tweak action"),
4309 "/tools/tweak/force", 20,
4310 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force",
4311 1, 100, 1.0, 10.0,
4312 labels, values, G_N_ELEMENTS(labels),
4313 sp_tweak_force_value_changed, 0.01, 0, 100 );
4314 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4315 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4316 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4317 }
4319 /* Mode */
4320 {
4321 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
4323 GtkTreeIter iter;
4324 gtk_list_store_append( model, &iter );
4325 gtk_list_store_set( model, &iter,
4326 0, _("Move mode"),
4327 1, _("Move objects in any direction"),
4328 2, INKSCAPE_ICON_OBJECT_TWEAK_PUSH,
4329 -1 );
4331 gtk_list_store_append( model, &iter );
4332 gtk_list_store_set( model, &iter,
4333 0, _("Move in/out mode"),
4334 1, _("Move objects towards cursor; with Shift from cursor"),
4335 2, INKSCAPE_ICON_OBJECT_TWEAK_ATTRACT,
4336 -1 );
4338 gtk_list_store_append( model, &iter );
4339 gtk_list_store_set( model, &iter,
4340 0, _("Move jitter mode"),
4341 1, _("Move objects in random directions"),
4342 2, INKSCAPE_ICON_OBJECT_TWEAK_RANDOMIZE,
4343 -1 );
4345 gtk_list_store_append( model, &iter );
4346 gtk_list_store_set( model, &iter,
4347 0, _("Scale mode"),
4348 1, _("Shrink objects, with Shift enlarge"),
4349 2, INKSCAPE_ICON_OBJECT_TWEAK_SHRINK,
4350 -1 );
4352 gtk_list_store_append( model, &iter );
4353 gtk_list_store_set( model, &iter,
4354 0, _("Rotate mode"),
4355 1, _("Rotate objects, with Shift counterclockwise"),
4356 2, INKSCAPE_ICON_OBJECT_TWEAK_ROTATE,
4357 -1 );
4359 gtk_list_store_append( model, &iter );
4360 gtk_list_store_set( model, &iter,
4361 0, _("Duplicate/delete mode"),
4362 1, _("Duplicate objects, with Shift delete"),
4363 2, INKSCAPE_ICON_OBJECT_TWEAK_DUPLICATE,
4364 -1 );
4366 gtk_list_store_append( model, &iter );
4367 gtk_list_store_set( model, &iter,
4368 0, _("Push mode"),
4369 1, _("Push parts of paths in any direction"),
4370 2, INKSCAPE_ICON_PATH_TWEAK_PUSH,
4371 -1 );
4373 gtk_list_store_append( model, &iter );
4374 gtk_list_store_set( model, &iter,
4375 0, _("Shrink/grow mode"),
4376 1, _("Shrink (inset) parts of paths; with Shift grow (outset)"),
4377 2, INKSCAPE_ICON_PATH_TWEAK_SHRINK,
4378 -1 );
4380 gtk_list_store_append( model, &iter );
4381 gtk_list_store_set( model, &iter,
4382 0, _("Attract/repel mode"),
4383 1, _("Attract parts of paths towards cursor; with Shift from cursor"),
4384 2, INKSCAPE_ICON_PATH_TWEAK_ATTRACT,
4385 -1 );
4387 gtk_list_store_append( model, &iter );
4388 gtk_list_store_set( model, &iter,
4389 0, _("Roughen mode"),
4390 1, _("Roughen parts of paths"),
4391 2, INKSCAPE_ICON_PATH_TWEAK_ROUGHEN,
4392 -1 );
4394 gtk_list_store_append( model, &iter );
4395 gtk_list_store_set( model, &iter,
4396 0, _("Color paint mode"),
4397 1, _("Paint the tool's color upon selected objects"),
4398 2, INKSCAPE_ICON_OBJECT_TWEAK_PAINT,
4399 -1 );
4401 gtk_list_store_append( model, &iter );
4402 gtk_list_store_set( model, &iter,
4403 0, _("Color jitter mode"),
4404 1, _("Jitter the colors of selected objects"),
4405 2, INKSCAPE_ICON_OBJECT_TWEAK_JITTER_COLOR,
4406 -1 );
4408 gtk_list_store_append( model, &iter );
4409 gtk_list_store_set( model, &iter,
4410 0, _("Blur mode"),
4411 1, _("Blur selected objects more; with Shift, blur less"),
4412 2, INKSCAPE_ICON_OBJECT_TWEAK_BLUR,
4413 -1 );
4416 EgeSelectOneAction* act = ege_select_one_action_new( "TweakModeAction", _("Mode"), (""), NULL, GTK_TREE_MODEL(model) );
4417 g_object_set( act, "short_label", _("Mode:"), NULL );
4418 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
4419 g_object_set_data( holder, "mode_action", act );
4421 ege_select_one_action_set_appearance( act, "full" );
4422 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
4423 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
4424 ege_select_one_action_set_icon_column( act, 2 );
4425 ege_select_one_action_set_icon_size( act, secondarySize );
4426 ege_select_one_action_set_tooltip_column( act, 1 );
4428 gint mode = prefs->getInt("/tools/tweak/mode", 0);
4429 ege_select_one_action_set_active( act, mode );
4430 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_tweak_mode_changed), holder );
4432 g_object_set_data( G_OBJECT(holder), "tweak_tool_mode", act);
4433 }
4435 guint mode = prefs->getInt("/tools/tweak/mode", 0);
4437 {
4438 EgeOutputAction* act = ege_output_action_new( "TweakChannelsLabel", _("Channels:"), "", 0 );
4439 ege_output_action_set_use_markup( act, TRUE );
4440 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4441 if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) {
4442 gtk_action_set_sensitive (GTK_ACTION(act), FALSE);
4443 }
4444 g_object_set_data( holder, "tweak_channels_label", act);
4445 }
4447 {
4448 InkToggleAction* act = ink_toggle_action_new( "TweakDoH",
4449 _("Hue"),
4450 _("In color mode, act on objects' hue"),
4451 NULL,
4452 Inkscape::ICON_SIZE_DECORATION );
4453 //TRANSLATORS: "H" here stands for hue
4454 g_object_set( act, "short_label", _("H"), NULL );
4455 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4456 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doh), desktop );
4457 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doh", true) );
4458 if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) {
4459 gtk_action_set_sensitive (GTK_ACTION(act), FALSE);
4460 }
4461 g_object_set_data( holder, "tweak_doh", act);
4462 }
4463 {
4464 InkToggleAction* act = ink_toggle_action_new( "TweakDoS",
4465 _("Saturation"),
4466 _("In color mode, act on objects' saturation"),
4467 NULL,
4468 Inkscape::ICON_SIZE_DECORATION );
4469 //TRANSLATORS: "S" here stands for Saturation
4470 g_object_set( act, "short_label", _("S"), NULL );
4471 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4472 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dos), desktop );
4473 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dos", true) );
4474 if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) {
4475 gtk_action_set_sensitive (GTK_ACTION(act), FALSE);
4476 }
4477 g_object_set_data( holder, "tweak_dos", act );
4478 }
4479 {
4480 InkToggleAction* act = ink_toggle_action_new( "TweakDoL",
4481 _("Lightness"),
4482 _("In color mode, act on objects' lightness"),
4483 NULL,
4484 Inkscape::ICON_SIZE_DECORATION );
4485 //TRANSLATORS: "L" here stands for Lightness
4486 g_object_set( act, "short_label", _("L"), NULL );
4487 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4488 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dol), desktop );
4489 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dol", true) );
4490 if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) {
4491 gtk_action_set_sensitive (GTK_ACTION(act), FALSE);
4492 }
4493 g_object_set_data( holder, "tweak_dol", act );
4494 }
4495 {
4496 InkToggleAction* act = ink_toggle_action_new( "TweakDoO",
4497 _("Opacity"),
4498 _("In color mode, act on objects' opacity"),
4499 NULL,
4500 Inkscape::ICON_SIZE_DECORATION );
4501 //TRANSLATORS: "O" here stands for Opacity
4502 g_object_set( act, "short_label", _("O"), NULL );
4503 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4504 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doo), desktop );
4505 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doo", true) );
4506 if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) {
4507 gtk_action_set_sensitive (GTK_ACTION(act), FALSE);
4508 }
4509 g_object_set_data( holder, "tweak_doo", act );
4510 }
4512 { /* Fidelity */
4513 gchar const* labels[] = {_("(rough, simplified)"), 0, 0, _("(default)"), 0, 0, _("(fine, but many nodes)")};
4514 gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
4515 EgeAdjustmentAction *eact = create_adjustment_action( "TweakFidelityAction",
4516 _("Fidelity"), _("Fidelity:"),
4517 _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"),
4518 "/tools/tweak/fidelity", 50,
4519 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity",
4520 1, 100, 1.0, 10.0,
4521 labels, values, G_N_ELEMENTS(labels),
4522 sp_tweak_fidelity_value_changed, 0.01, 0, 100 );
4523 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4524 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4525 if (mode == TWEAK_MODE_COLORPAINT || mode == TWEAK_MODE_COLORJITTER) {
4526 gtk_action_set_sensitive (GTK_ACTION(eact), FALSE);
4527 }
4528 g_object_set_data( holder, "tweak_fidelity", eact );
4529 }
4532 /* Use Pressure button */
4533 {
4534 InkToggleAction* act = ink_toggle_action_new( "TweakPressureAction",
4535 _("Pressure"),
4536 _("Use the pressure of the input device to alter the force of tweak action"),
4537 INKSCAPE_ICON_DRAW_USE_PRESSURE,
4538 Inkscape::ICON_SIZE_DECORATION );
4539 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4540 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_tweak_pressure_state_changed), NULL);
4541 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/usepressure", true) );
4542 }
4544 }
4547 //########################
4548 //## Spray ##
4549 //########################
4551 static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4552 {
4553 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4554 prefs->setDouble( "/tools/spray/width", adj->value );
4555 }
4557 static void sp_spray_mean_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4558 {
4559 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4560 prefs->setDouble( "/tools/spray/mean", adj->value );
4561 }
4563 static void sp_spray_standard_deviation_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4564 {
4565 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4566 prefs->setDouble( "/tools/spray/standard_deviation", adj->value );
4567 }
4569 static void sp_spray_pressure_state_changed( GtkToggleAction *act, gpointer /*data*/ )
4570 {
4571 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4572 prefs->setBool("/tools/spray/usepressure", gtk_toggle_action_get_active(act));
4573 }
4575 static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * /*tbl*/ )
4576 {
4577 int mode = ege_select_one_action_get_active( act );
4578 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4579 prefs->setInt("/tools/spray/mode", mode);
4580 }
4582 static void sp_spray_population_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4583 {
4584 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4585 prefs->setDouble( "/tools/spray/population", adj->value );
4586 }
4588 static void sp_spray_rotation_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4589 {
4590 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4591 prefs->setDouble( "/tools/spray/rotation_variation", adj->value );
4592 }
4594 static void sp_spray_scale_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ )
4595 {
4596 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4597 prefs->setDouble( "/tools/spray/scale_variation", adj->value );
4598 }
4601 static void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
4602 {
4603 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
4604 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4606 {
4607 /* Width */
4608 gchar const* labels[] = {_("(narrow spray)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad spray)")};
4609 gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
4610 EgeAdjustmentAction *eact = create_adjustment_action( "SprayWidthAction",
4611 _("Width"), _("Width:"), _("The width of the spray area (relative to the visible canvas area)"),
4612 "/tools/spray/width", 15,
4613 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spray",
4614 1, 100, 1.0, 10.0,
4615 labels, values, G_N_ELEMENTS(labels),
4616 sp_spray_width_value_changed, 1, 0 );
4617 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4618 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4619 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4620 }
4622 {
4623 /* Mean */
4624 gchar const* labels[] = {_("(minimum mean)"), 0, 0, _("(default)"), 0, 0, 0, _("(maximum mean)")};
4625 gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100};
4626 EgeAdjustmentAction *eact = create_adjustment_action( "SprayMeanAction",
4627 _("Focus"), _("Focus:"), _("0 to spray a spot. Increase to enlarge the ring radius."),
4628 "/tools/spray/mean", 0,
4629 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-mean",
4630 0, 100, 1.0, 10.0,
4631 labels, values, G_N_ELEMENTS(labels),
4632 sp_spray_mean_value_changed, 1, 0 );
4633 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4634 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4635 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4636 }
4638 {
4639 /* Standard_deviation */
4640 gchar const* labels[] = {_("(minimum scatter)"), 0, 0, _("(default)"), 0, 0, 0, _("(maximum scatter)")};
4641 gdouble values[] = {1, 5, 10, 20, 30, 50, 70, 100};
4642 EgeAdjustmentAction *eact = create_adjustment_action( "SprayStandard_deviationAction",
4643 _("Scatter"), _("Scatter:"), _("Increase to scatter sprayed objects."),
4644 "/tools/spray/standard_deviation", 70,
4645 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-standard_deviation",
4646 1, 100, 1.0, 10.0,
4647 labels, values, G_N_ELEMENTS(labels),
4648 sp_spray_standard_deviation_value_changed, 1, 0 );
4649 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4650 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4651 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4652 }
4654 /* Mode */
4655 {
4656 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
4658 GtkTreeIter iter;
4659 gtk_list_store_append( model, &iter );
4660 gtk_list_store_set( model, &iter,
4661 0, _("Spray with copies"),
4662 1, _("Spray copies of the initial selection"),
4663 2, INKSCAPE_ICON_SPRAY_COPY_MODE,
4664 -1 );
4666 gtk_list_store_append( model, &iter );
4667 gtk_list_store_set( model, &iter,
4668 0, _("Spray with clones"),
4669 1, _("Spray clones of the initial selection"),
4670 2, INKSCAPE_ICON_SPRAY_CLONE_MODE,
4671 -1 );
4673 gtk_list_store_append( model, &iter );
4674 gtk_list_store_set( model, &iter,
4675 0, _("Spray single path"),
4676 1, _("Spray objects in a single path"),
4677 2, INKSCAPE_ICON_SPRAY_UNION_MODE,
4678 -1 );
4680 EgeSelectOneAction* act = ege_select_one_action_new( "SprayModeAction", _("Mode"), (""), NULL, GTK_TREE_MODEL(model) );
4681 g_object_set( act, "short_label", _("Mode:"), NULL );
4682 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
4683 g_object_set_data( holder, "mode_action", act );
4685 ege_select_one_action_set_appearance( act, "full" );
4686 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
4687 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
4688 ege_select_one_action_set_icon_column( act, 2 );
4689 ege_select_one_action_set_icon_size( act, secondarySize );
4690 ege_select_one_action_set_tooltip_column( act, 1 );
4692 gint mode = prefs->getInt("/tools/spray/mode", 1);
4693 ege_select_one_action_set_active( act, mode );
4694 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_spray_mode_changed), holder );
4696 g_object_set_data( G_OBJECT(holder), "spray_tool_mode", act);
4697 }
4699 { /* Population */
4700 gchar const* labels[] = {_("(low population)"), 0, 0, _("(default)"), 0, 0, _("(high population)")};
4701 gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
4702 EgeAdjustmentAction *eact = create_adjustment_action( "SprayPopulationAction",
4703 _("Amount"), _("Amount:"),
4704 _("Adjusts the number of items sprayed per clic."),
4705 "/tools/spray/population", 70,
4706 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-population",
4707 1, 100, 1.0, 10.0,
4708 labels, values, G_N_ELEMENTS(labels),
4709 sp_spray_population_value_changed, 1, 0 );
4710 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4711 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4712 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4713 g_object_set_data( holder, "spray_population", eact );
4714 }
4716 /* Use Pressure button */
4717 {
4718 InkToggleAction* act = ink_toggle_action_new( "SprayPressureAction",
4719 _("Pressure"),
4720 _("Use the pressure of the input device to alter the amount of sprayed objects."),
4721 "use_pressure",
4722 Inkscape::ICON_SIZE_DECORATION );
4723 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
4724 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_spray_pressure_state_changed), NULL);
4725 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/usepressure", true) );
4726 }
4728 { /* Rotation */
4729 gchar const* labels[] = {_("(low rotation variation)"), 0, 0, _("(default)"), 0, 0, _("(high rotation variation)")};
4730 gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
4731 EgeAdjustmentAction *eact = create_adjustment_action( "SprayRotationAction",
4732 _("Rotation"), _("Rotation:"),
4733 // xgettext:no-c-format
4734 _("Variation of the rotation of the sprayed objects. 0% for the same rotation than the original object."),
4735 "/tools/spray/rotation_variation", 0,
4736 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-rotation",
4737 0, 100, 1.0, 10.0,
4738 labels, values, G_N_ELEMENTS(labels),
4739 sp_spray_rotation_value_changed, 1, 0 );
4740 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4741 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4742 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4743 g_object_set_data( holder, "spray_rotation", eact );
4744 }
4746 { /* Scale */
4747 gchar const* labels[] = {_("(low scale variation)"), 0, 0, _("(default)"), 0, 0, _("(high scale variation)")};
4748 gdouble values[] = {10, 25, 35, 50, 60, 80, 100};
4749 EgeAdjustmentAction *eact = create_adjustment_action( "SprayScaleAction",
4750 _("Scale"), _("Scale:"),
4751 // xgettext:no-c-format
4752 _("Variation in the scale of the sprayed objects. 0% for the same scale than the original object."),
4753 "/tools/spray/scale_variation", 0,
4754 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-scale",
4755 0, 100, 1.0, 10.0,
4756 labels, values, G_N_ELEMENTS(labels),
4757 sp_spray_scale_value_changed, 1, 0 );
4758 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
4759 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
4760 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
4761 g_object_set_data( holder, "spray_scale", eact );
4762 }
4766 }
4769 //########################
4770 //## Calligraphy ##
4771 //########################
4772 static void update_presets_list(GObject *tbl)
4773 {
4774 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4775 if (g_object_get_data(tbl, "presets_blocked")) {
4776 return;
4777 }
4779 EgeSelectOneAction *sel = static_cast<EgeSelectOneAction *>(g_object_get_data(tbl, "profile_selector"));
4780 if (!sel) {
4781 // WTF!? This will cause a segfault if ever reached
4782 //ege_select_one_action_set_active(sel, 0);
4783 return;
4784 }
4786 std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset");
4788 int ege_index = 1;
4789 for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i, ++ege_index) {
4790 bool match = true;
4792 std::vector<Inkscape::Preferences::Entry> preset = prefs->getAllEntries(*i);
4793 for (std::vector<Inkscape::Preferences::Entry>::iterator j = preset.begin(); j != preset.end(); ++j) {
4794 Glib::ustring entry_name = j->getEntryName();
4795 if (entry_name == "id" || entry_name == "name") {
4796 continue;
4797 }
4799 void *widget = g_object_get_data(tbl, entry_name.data());
4800 if (widget) {
4801 if (GTK_IS_ADJUSTMENT(widget)) {
4802 double v = j->getDouble();
4803 GtkAdjustment* adj = static_cast<GtkAdjustment *>(widget);
4804 //std::cout << "compared adj " << attr_name << gtk_adjustment_get_value(adj) << " to " << v << "\n";
4805 if (fabs(gtk_adjustment_get_value(adj) - v) > 1e-6) {
4806 match = false;
4807 break;
4808 }
4809 } else if (GTK_IS_TOGGLE_ACTION(widget)) {
4810 bool v = j->getBool();
4811 GtkToggleAction* toggle = static_cast<GtkToggleAction *>(widget);
4812 //std::cout << "compared toggle " << attr_name << gtk_toggle_action_get_active(toggle) << " to " << v << "\n";
4813 if ( static_cast<bool>(gtk_toggle_action_get_active(toggle)) != v ) {
4814 match = false;
4815 break;
4816 }
4817 }
4818 }
4819 }
4821 if (match) {
4822 // newly added item is at the same index as the
4823 // save command, so we need to change twice for it to take effect
4824 ege_select_one_action_set_active(sel, 0);
4825 ege_select_one_action_set_active(sel, ege_index); // one-based index
4826 return;
4827 }
4828 }
4830 // no match found
4831 ege_select_one_action_set_active(sel, 0);
4832 }
4834 static void sp_ddc_mass_value_changed( GtkAdjustment *adj, GObject* tbl )
4835 {
4836 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4837 prefs->setDouble( "/tools/calligraphic/mass", adj->value );
4838 update_presets_list(tbl);
4839 }
4841 static void sp_ddc_wiggle_value_changed( GtkAdjustment *adj, GObject* tbl )
4842 {
4843 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4844 prefs->setDouble( "/tools/calligraphic/wiggle", adj->value );
4845 update_presets_list(tbl);
4846 }
4848 static void sp_ddc_angle_value_changed( GtkAdjustment *adj, GObject* tbl )
4849 {
4850 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4851 prefs->setDouble( "/tools/calligraphic/angle", adj->value );
4852 update_presets_list(tbl);
4853 }
4855 static void sp_ddc_width_value_changed( GtkAdjustment *adj, GObject *tbl )
4856 {
4857 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4858 prefs->setDouble( "/tools/calligraphic/width", adj->value );
4859 update_presets_list(tbl);
4860 }
4862 static void sp_ddc_velthin_value_changed( GtkAdjustment *adj, GObject* tbl )
4863 {
4864 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4865 prefs->setDouble("/tools/calligraphic/thinning", adj->value );
4866 update_presets_list(tbl);
4867 }
4869 static void sp_ddc_flatness_value_changed( GtkAdjustment *adj, GObject* tbl )
4870 {
4871 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4872 prefs->setDouble( "/tools/calligraphic/flatness", adj->value );
4873 update_presets_list(tbl);
4874 }
4876 static void sp_ddc_tremor_value_changed( GtkAdjustment *adj, GObject* tbl )
4877 {
4878 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4879 prefs->setDouble( "/tools/calligraphic/tremor", adj->value );
4880 update_presets_list(tbl);
4881 }
4883 static void sp_ddc_cap_rounding_value_changed( GtkAdjustment *adj, GObject* tbl )
4884 {
4885 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4886 prefs->setDouble( "/tools/calligraphic/cap_rounding", adj->value );
4887 update_presets_list(tbl);
4888 }
4890 static void sp_ddc_tilt_state_changed( GtkToggleAction *act, GObject* tbl )
4891 {
4892 // TODO merge into PrefPusher
4893 GtkAction * calligraphy_angle = static_cast<GtkAction *> (g_object_get_data(tbl,"angle_action"));
4894 if (calligraphy_angle ) {
4895 gtk_action_set_sensitive( calligraphy_angle, !gtk_toggle_action_get_active( act ) );
4896 }
4897 }
4900 static gchar const *const widget_names[] = {
4901 "width",
4902 "mass",
4903 "wiggle",
4904 "angle",
4905 "thinning",
4906 "tremor",
4907 "flatness",
4908 "cap_rounding",
4909 "usepressure",
4910 "tracebackground",
4911 "usetilt"
4912 };
4915 static void sp_dcc_build_presets_list(GObject *tbl)
4916 {
4917 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(TRUE));
4919 EgeSelectOneAction* selector = static_cast<EgeSelectOneAction *>(g_object_get_data(tbl, "profile_selector"));
4920 GtkListStore* model = GTK_LIST_STORE(ege_select_one_action_get_model(selector));
4921 gtk_list_store_clear (model);
4923 {
4924 GtkTreeIter iter;
4925 gtk_list_store_append( model, &iter );
4926 gtk_list_store_set( model, &iter, 0, _("No preset"), 1, 0, -1 );
4927 }
4929 // iterate over all presets to populate the list
4930 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4931 std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset");
4932 int ii=1;
4934 for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i) {
4935 GtkTreeIter iter;
4936 Glib::ustring preset_name = prefs->getString(*i + "/name");
4937 gtk_list_store_append( model, &iter );
4938 gtk_list_store_set( model, &iter, 0, _(preset_name.data()), 1, ii++, -1 );
4939 }
4941 {
4942 GtkTreeIter iter;
4943 gtk_list_store_append( model, &iter );
4944 gtk_list_store_set( model, &iter, 0, _("Save..."), 1, ii, -1 );
4945 g_object_set_data(tbl, "save_presets_index", GINT_TO_POINTER(ii));
4946 }
4948 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE));
4950 update_presets_list (tbl);
4951 }
4953 static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl)
4954 {
4955 using Inkscape::UI::Dialog::CalligraphicProfileRename;
4956 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4957 SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop" );
4958 if (! desktop) {
4959 return;
4960 }
4962 if (g_object_get_data(tbl, "presets_blocked")) {
4963 return;
4964 }
4966 CalligraphicProfileRename::show(desktop);
4967 if ( !CalligraphicProfileRename::applied()) {
4968 // dialog cancelled
4969 update_presets_list (tbl);
4970 return;
4971 }
4972 Glib::ustring profile_name = CalligraphicProfileRename::getProfileName();
4974 if (profile_name.empty()) {
4975 // empty name entered
4976 update_presets_list (tbl);
4977 return;
4978 }
4980 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(TRUE));
4982 // If there's a preset with the given name, find it and set save_path appropriately
4983 std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset");
4984 int total_presets = presets.size();
4985 int new_index = -1;
4986 Glib::ustring save_path; // profile pref path without a trailing slash
4988 int temp_index = 0;
4989 for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i, ++temp_index) {
4990 Glib::ustring name = prefs->getString(*i + "/name");
4991 if (!name.empty() && profile_name == name) {
4992 new_index = temp_index;
4993 save_path = *i;
4994 break;
4995 }
4996 }
4998 if (new_index == -1) {
4999 // no preset with this name, create
5000 new_index = total_presets + 1;
5001 gchar *profile_id = g_strdup_printf("/dcc%d", new_index);
5002 save_path = Glib::ustring("/tools/calligraphic/preset") + profile_id;
5003 g_free(profile_id);
5004 }
5006 for (unsigned i = 0; i < G_N_ELEMENTS(widget_names); ++i) {
5007 gchar const *const widget_name = widget_names[i];
5008 void *widget = g_object_get_data(tbl, widget_name);
5009 if (widget) {
5010 if (GTK_IS_ADJUSTMENT(widget)) {
5011 GtkAdjustment* adj = static_cast<GtkAdjustment *>(widget);
5012 prefs->setDouble(save_path + "/" + widget_name, gtk_adjustment_get_value(adj));
5013 //std::cout << "wrote adj " << widget_name << ": " << v << "\n";
5014 } else if (GTK_IS_TOGGLE_ACTION(widget)) {
5015 GtkToggleAction* toggle = static_cast<GtkToggleAction *>(widget);
5016 prefs->setBool(save_path + "/" + widget_name, gtk_toggle_action_get_active(toggle));
5017 //std::cout << "wrote tog " << widget_name << ": " << v << "\n";
5018 } else {
5019 g_warning("Unknown widget type for preset: %s\n", widget_name);
5020 }
5021 } else {
5022 g_warning("Bad key when writing preset: %s\n", widget_name);
5023 }
5024 }
5025 prefs->setString(save_path + "/name", profile_name);
5027 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE));
5028 sp_dcc_build_presets_list (tbl);
5029 }
5032 static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl)
5033 {
5034 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5036 gint preset_index = ege_select_one_action_get_active( act );
5037 // This is necessary because EgeSelectOneAction spams us with GObject "changed" signal calls
5038 // even when the preset is not changed. It would be good to replace it with something more
5039 // modern. Index 0 means "No preset", so we don't do anything.
5040 if (preset_index == 0) {
5041 return;
5042 }
5044 gint save_presets_index = GPOINTER_TO_INT(g_object_get_data(tbl, "save_presets_index"));
5046 if (preset_index == save_presets_index) {
5047 // this is the Save command
5048 sp_dcc_save_profile(NULL, tbl);
5049 return;
5050 }
5052 if (g_object_get_data(tbl, "presets_blocked")) {
5053 return;
5054 }
5056 // preset_index is one-based so we subtract 1
5057 std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset");
5058 Glib::ustring preset_path = presets.at(preset_index - 1);
5060 if (!preset_path.empty()) {
5061 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(TRUE)); //temporarily block the selector so no one will updadte it while we're reading it
5063 std::vector<Inkscape::Preferences::Entry> preset = prefs->getAllEntries(preset_path);
5065 // Shouldn't this be std::map?
5066 for (std::vector<Inkscape::Preferences::Entry>::iterator i = preset.begin(); i != preset.end(); ++i) {
5067 Glib::ustring entry_name = i->getEntryName();
5068 if (entry_name == "id" || entry_name == "name") {
5069 continue;
5070 }
5071 void *widget = g_object_get_data(tbl, entry_name.data());
5072 if (widget) {
5073 if (GTK_IS_ADJUSTMENT(widget)) {
5074 GtkAdjustment* adj = static_cast<GtkAdjustment *>(widget);
5075 gtk_adjustment_set_value(adj, i->getDouble());
5076 //std::cout << "set adj " << attr_name << " to " << v << "\n";
5077 } else if (GTK_IS_TOGGLE_ACTION(widget)) {
5078 GtkToggleAction* toggle = static_cast<GtkToggleAction *>(widget);
5079 gtk_toggle_action_set_active(toggle, i->getBool());
5080 //std::cout << "set toggle " << attr_name << " to " << v << "\n";
5081 } else {
5082 g_warning("Unknown widget type for preset: %s\n", entry_name.data());
5083 }
5084 } else {
5085 g_warning("Bad key found in a preset record: %s\n", entry_name.data());
5086 }
5087 }
5088 g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE));
5089 }
5090 }
5092 static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
5093 {
5094 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5095 {
5096 g_object_set_data(holder, "presets_blocked", GINT_TO_POINTER(TRUE));
5098 EgeAdjustmentAction* calligraphy_angle = 0;
5100 {
5101 /* Width */
5102 gchar const* labels[] = {_("(hairline)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad stroke)")};
5103 gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
5104 EgeAdjustmentAction *eact = create_adjustment_action( "CalligraphyWidthAction",
5105 _("Pen Width"), _("Width:"),
5106 _("The width of the calligraphic pen (relative to the visible canvas area)"),
5107 "/tools/calligraphic/width", 15,
5108 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy",
5109 1, 100, 1.0, 10.0,
5110 labels, values, G_N_ELEMENTS(labels),
5111 sp_ddc_width_value_changed, 1, 0 );
5112 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
5113 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5114 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5115 }
5117 {
5118 /* Thinning */
5119 gchar const* labels[] = {_("(speed blows up stroke)"), 0, 0, _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), 0, 0, _("(speed deflates stroke)")};
5120 gdouble values[] = {-100, -40, -20, -10, 0, 10, 20, 40, 100};
5121 EgeAdjustmentAction* eact = create_adjustment_action( "ThinningAction",
5122 _("Stroke Thinning"), _("Thinning:"),
5123 _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"),
5124 "/tools/calligraphic/thinning", 10,
5125 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5126 -100, 100, 1, 10.0,
5127 labels, values, G_N_ELEMENTS(labels),
5128 sp_ddc_velthin_value_changed, 1, 0);
5129 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5130 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5131 }
5133 {
5134 /* Angle */
5135 gchar const* labels[] = {_("(left edge up)"), 0, 0, _("(horizontal)"), _("(default)"), 0, _("(right edge up)")};
5136 gdouble values[] = {-90, -60, -30, 0, 30, 60, 90};
5137 EgeAdjustmentAction* eact = create_adjustment_action( "AngleAction",
5138 _("Pen Angle"), _("Angle:"),
5139 _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"),
5140 "/tools/calligraphic/angle", 30,
5141 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle",
5142 -90.0, 90.0, 1.0, 10.0,
5143 labels, values, G_N_ELEMENTS(labels),
5144 sp_ddc_angle_value_changed, 1, 0 );
5145 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5146 g_object_set_data( holder, "angle_action", eact );
5147 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5148 calligraphy_angle = eact;
5149 }
5151 {
5152 /* Fixation */
5153 gchar const* labels[] = {_("(perpendicular to stroke, \"brush\")"), 0, 0, 0, _("(almost fixed, default)"), _("(fixed by Angle, \"pen\")")};
5154 gdouble values[] = {0, 20, 40, 60, 90, 100};
5155 EgeAdjustmentAction* eact = create_adjustment_action( "FixationAction",
5156 _("Fixation"), _("Fixation:"),
5157 _("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)"),
5158 "/tools/calligraphic/flatness", 90,
5159 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5160 0.0, 100, 1.0, 10.0,
5161 labels, values, G_N_ELEMENTS(labels),
5162 sp_ddc_flatness_value_changed, 1, 0);
5163 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5164 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5165 }
5167 {
5168 /* Cap Rounding */
5169 gchar const* labels[] = {_("(blunt caps, default)"), _("(slightly bulging)"), 0, 0, _("(approximately round)"), _("(long protruding caps)")};
5170 gdouble values[] = {0, 0.3, 0.5, 1.0, 1.4, 5.0};
5171 // TRANSLATORS: "cap" means "end" (both start and finish) here
5172 EgeAdjustmentAction* eact = create_adjustment_action( "CapRoundingAction",
5173 _("Cap rounding"), _("Caps:"),
5174 _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"),
5175 "/tools/calligraphic/cap_rounding", 0.0,
5176 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5177 0.0, 5.0, 0.01, 0.1,
5178 labels, values, G_N_ELEMENTS(labels),
5179 sp_ddc_cap_rounding_value_changed, 0.01, 2 );
5180 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5181 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5182 }
5184 {
5185 /* Tremor */
5186 gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), 0, 0, _("(maximum tremor)")};
5187 gdouble values[] = {0, 10, 20, 40, 60, 100};
5188 EgeAdjustmentAction* eact = create_adjustment_action( "TremorAction",
5189 _("Stroke Tremor"), _("Tremor:"),
5190 _("Increase to make strokes rugged and trembling"),
5191 "/tools/calligraphic/tremor", 0.0,
5192 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5193 0.0, 100, 1, 10.0,
5194 labels, values, G_N_ELEMENTS(labels),
5195 sp_ddc_tremor_value_changed, 1, 0);
5197 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
5198 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5199 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5200 }
5202 {
5203 /* Wiggle */
5204 gchar const* labels[] = {_("(no wiggle)"), _("(slight deviation)"), 0, 0, _("(wild waves and curls)")};
5205 gdouble values[] = {0, 20, 40, 60, 100};
5206 EgeAdjustmentAction* eact = create_adjustment_action( "WiggleAction",
5207 _("Pen Wiggle"), _("Wiggle:"),
5208 _("Increase to make the pen waver and wiggle"),
5209 "/tools/calligraphic/wiggle", 0.0,
5210 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5211 0.0, 100, 1, 10.0,
5212 labels, values, G_N_ELEMENTS(labels),
5213 sp_ddc_wiggle_value_changed, 1, 0);
5214 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
5215 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5216 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5217 }
5219 {
5220 /* Mass */
5221 gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), 0, 0, _("(maximum inertia)")};
5222 gdouble values[] = {0.0, 2, 10, 20, 50, 100};
5223 EgeAdjustmentAction* eact = create_adjustment_action( "MassAction",
5224 _("Pen Mass"), _("Mass:"),
5225 _("Increase to make the pen drag behind, as if slowed by inertia"),
5226 "/tools/calligraphic/mass", 2.0,
5227 GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
5228 0.0, 100, 1, 10.0,
5229 labels, values, G_N_ELEMENTS(labels),
5230 sp_ddc_mass_value_changed, 1, 0);
5231 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
5232 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5233 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
5234 }
5237 /* Trace Background button */
5238 {
5239 InkToggleAction* act = ink_toggle_action_new( "TraceAction",
5240 _("Trace Background"),
5241 _("Trace the lightness of the background by the width of the pen (white - minimum width, black - maximum width)"),
5242 INKSCAPE_ICON_DRAW_TRACE_BACKGROUND,
5243 Inkscape::ICON_SIZE_DECORATION );
5244 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5245 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/tracebackground", update_presets_list, holder);
5246 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
5247 g_object_set_data( holder, "tracebackground", act );
5248 }
5250 /* Use Pressure button */
5251 {
5252 InkToggleAction* act = ink_toggle_action_new( "PressureAction",
5253 _("Pressure"),
5254 _("Use the pressure of the input device to alter the width of the pen"),
5255 INKSCAPE_ICON_DRAW_USE_PRESSURE,
5256 Inkscape::ICON_SIZE_DECORATION );
5257 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5258 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/usepressure", update_presets_list, holder);
5259 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
5260 g_object_set_data( holder, "usepressure", act );
5261 }
5263 /* Use Tilt button */
5264 {
5265 InkToggleAction* act = ink_toggle_action_new( "TiltAction",
5266 _("Tilt"),
5267 _("Use the tilt of the input device to alter the angle of the pen's nib"),
5268 INKSCAPE_ICON_DRAW_USE_TILT,
5269 Inkscape::ICON_SIZE_DECORATION );
5270 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5271 PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/usetilt", update_presets_list, holder);
5272 g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher);
5273 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_tilt_state_changed), holder );
5274 gtk_action_set_sensitive( GTK_ACTION(calligraphy_angle), !prefs->getBool("/tools/calligraphic/usetilt", true) );
5275 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/calligraphic/usetilt", true) );
5276 g_object_set_data( holder, "usetilt", act );
5277 }
5279 /*calligraphic profile */
5280 {
5281 GtkListStore* model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
5282 EgeSelectOneAction* act1 = ege_select_one_action_new ("SetProfileAction", "" , (_("Choose a preset")), NULL, GTK_TREE_MODEL(model));
5283 ege_select_one_action_set_appearance (act1, "compact");
5284 g_object_set_data (holder, "profile_selector", act1 );
5286 g_object_set_data(holder, "presets_blocked", GINT_TO_POINTER(FALSE));
5288 sp_dcc_build_presets_list (holder);
5290 g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(sp_ddc_change_profile), holder);
5291 gtk_action_group_add_action(mainActions, GTK_ACTION(act1));
5292 }
5293 }
5294 }
5297 //########################
5298 //## Circle / Arc ##
5299 //########################
5301 static void sp_arctb_sensitivize( GObject *tbl, double v1, double v2 )
5302 {
5303 GtkAction *ocb = GTK_ACTION( g_object_get_data( tbl, "open_action" ) );
5304 GtkAction *make_whole = GTK_ACTION( g_object_get_data( tbl, "make_whole" ) );
5306 if (v1 == 0 && v2 == 0) {
5307 if (g_object_get_data( tbl, "single" )) { // only for a single selected ellipse (for now)
5308 gtk_action_set_sensitive( ocb, FALSE );
5309 gtk_action_set_sensitive( make_whole, FALSE );
5310 }
5311 } else {
5312 gtk_action_set_sensitive( ocb, TRUE );
5313 gtk_action_set_sensitive( make_whole, TRUE );
5314 }
5315 }
5317 static void
5318 sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name, gchar const *other_name)
5319 {
5320 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
5322 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
5323 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5324 prefs->setDouble(Glib::ustring("/tools/shapes/arc/") + value_name, adj->value);
5325 }
5327 // quit if run by the attr_changed listener
5328 if (g_object_get_data( tbl, "freeze" )) {
5329 return;
5330 }
5332 // in turn, prevent listener from responding
5333 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
5335 gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL);
5337 bool modmade = false;
5338 for (GSList const *items = sp_desktop_selection(desktop)->itemList();
5339 items != NULL;
5340 items = items->next)
5341 {
5342 SPItem *item = SP_ITEM(items->data);
5344 if (SP_IS_ARC(item) && SP_IS_GENERICELLIPSE(item)) {
5346 SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
5347 SPArc *arc = SP_ARC(item);
5349 if (!strcmp(value_name, "start")) {
5350 ge->start = (adj->value * M_PI)/ 180;
5351 } else {
5352 ge->end = (adj->value * M_PI)/ 180;
5353 }
5355 sp_genericellipse_normalize(ge);
5356 ((SPObject *)arc)->updateRepr();
5357 ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
5359 modmade = true;
5360 }
5361 }
5363 g_free(namespaced_name);
5365 GtkAdjustment *other = GTK_ADJUSTMENT( g_object_get_data( tbl, other_name ) );
5367 sp_arctb_sensitivize( tbl, adj->value, other->value );
5369 if (modmade) {
5370 sp_document_maybe_done(sp_desktop_document(desktop), value_name, SP_VERB_CONTEXT_ARC,
5371 _("Arc: Change start/end"));
5372 }
5374 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
5375 }
5378 static void sp_arctb_start_value_changed(GtkAdjustment *adj, GObject *tbl)
5379 {
5380 sp_arctb_startend_value_changed(adj, tbl, "start", "end");
5381 }
5383 static void sp_arctb_end_value_changed(GtkAdjustment *adj, GObject *tbl)
5384 {
5385 sp_arctb_startend_value_changed(adj, tbl, "end", "start");
5386 }
5389 static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl )
5390 {
5391 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
5392 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
5393 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5394 prefs->setBool("/tools/shapes/arc/open", ege_select_one_action_get_active(act) != 0);
5395 }
5397 // quit if run by the attr_changed listener
5398 if (g_object_get_data( tbl, "freeze" )) {
5399 return;
5400 }
5402 // in turn, prevent listener from responding
5403 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
5405 bool modmade = false;
5407 if ( ege_select_one_action_get_active(act) != 0 ) {
5408 for (GSList const *items = sp_desktop_selection(desktop)->itemList();
5409 items != NULL;
5410 items = items->next)
5411 {
5412 if (SP_IS_ARC((SPItem *) items->data)) {
5413 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
5414 repr->setAttribute("sodipodi:open", "true");
5415 SP_OBJECT((SPItem *) items->data)->updateRepr();
5416 modmade = true;
5417 }
5418 }
5419 } else {
5420 for (GSList const *items = sp_desktop_selection(desktop)->itemList();
5421 items != NULL;
5422 items = items->next)
5423 {
5424 if (SP_IS_ARC((SPItem *) items->data)) {
5425 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data);
5426 repr->setAttribute("sodipodi:open", NULL);
5427 SP_OBJECT((SPItem *) items->data)->updateRepr();
5428 modmade = true;
5429 }
5430 }
5431 }
5433 if (modmade) {
5434 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
5435 _("Arc: Change open/closed"));
5436 }
5438 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
5439 }
5441 static void sp_arctb_defaults(GtkWidget *, GObject *obj)
5442 {
5443 GtkAdjustment *adj;
5444 adj = GTK_ADJUSTMENT( g_object_get_data(obj, "start") );
5445 gtk_adjustment_set_value(adj, 0.0);
5446 gtk_adjustment_value_changed(adj);
5448 adj = GTK_ADJUSTMENT( g_object_get_data(obj, "end") );
5449 gtk_adjustment_set_value(adj, 0.0);
5450 gtk_adjustment_value_changed(adj);
5452 spinbutton_defocus( GTK_OBJECT(obj) );
5453 }
5455 static void arc_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const * /*name*/,
5456 gchar const * /*old_value*/, gchar const * /*new_value*/,
5457 bool /*is_interactive*/, gpointer data)
5458 {
5459 GObject *tbl = G_OBJECT(data);
5461 // quit if run by the _changed callbacks
5462 if (g_object_get_data( tbl, "freeze" )) {
5463 return;
5464 }
5466 // in turn, prevent callbacks from responding
5467 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
5469 gdouble start = sp_repr_get_double_attribute(repr, "sodipodi:start", 0.0);
5470 gdouble end = sp_repr_get_double_attribute(repr, "sodipodi:end", 0.0);
5472 GtkAdjustment *adj1,*adj2;
5473 adj1 = GTK_ADJUSTMENT( g_object_get_data( tbl, "start" ) );
5474 gtk_adjustment_set_value(adj1, mod360((start * 180)/M_PI));
5475 adj2 = GTK_ADJUSTMENT( g_object_get_data( tbl, "end" ) );
5476 gtk_adjustment_set_value(adj2, mod360((end * 180)/M_PI));
5478 sp_arctb_sensitivize( tbl, adj1->value, adj2->value );
5480 char const *openstr = NULL;
5481 openstr = repr->attribute("sodipodi:open");
5482 EgeSelectOneAction *ocb = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "open_action" ) );
5484 if (openstr) {
5485 ege_select_one_action_set_active( ocb, 1 );
5486 } else {
5487 ege_select_one_action_set_active( ocb, 0 );
5488 }
5490 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
5491 }
5493 static Inkscape::XML::NodeEventVector arc_tb_repr_events = {
5494 NULL, /* child_added */
5495 NULL, /* child_removed */
5496 arc_tb_event_attr_changed,
5497 NULL, /* content_changed */
5498 NULL /* order_changed */
5499 };
5502 static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
5503 {
5504 int n_selected = 0;
5505 Inkscape::XML::Node *repr = NULL;
5507 purge_repr_listener( tbl, tbl );
5509 for (GSList const *items = selection->itemList();
5510 items != NULL;
5511 items = items->next)
5512 {
5513 if (SP_IS_ARC((SPItem *) items->data)) {
5514 n_selected++;
5515 repr = SP_OBJECT_REPR((SPItem *) items->data);
5516 }
5517 }
5519 EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
5521 g_object_set_data( tbl, "single", GINT_TO_POINTER(FALSE) );
5522 if (n_selected == 0) {
5523 g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
5524 } else if (n_selected == 1) {
5525 g_object_set_data( tbl, "single", GINT_TO_POINTER(TRUE) );
5526 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
5528 if (repr) {
5529 g_object_set_data( tbl, "repr", repr );
5530 Inkscape::GC::anchor(repr);
5531 sp_repr_add_listener(repr, &arc_tb_repr_events, tbl);
5532 sp_repr_synthesize_events(repr, &arc_tb_repr_events, tbl);
5533 }
5534 } else {
5535 // FIXME: implement averaging of all parameters for multiple selected
5536 //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
5537 g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
5538 sp_arctb_sensitivize( tbl, 1, 0 );
5539 }
5540 }
5543 static void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
5544 {
5545 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5547 EgeAdjustmentAction* eact = 0;
5548 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
5551 {
5552 EgeOutputAction* act = ege_output_action_new( "ArcStateAction", _("<b>New:</b>"), "", 0 );
5553 ege_output_action_set_use_markup( act, TRUE );
5554 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5555 g_object_set_data( holder, "mode_action", act );
5556 }
5558 /* Start */
5559 {
5560 eact = create_adjustment_action( "ArcStartAction",
5561 _("Start"), _("Start:"),
5562 _("The angle (in degrees) from the horizontal to the arc's start point"),
5563 "/tools/shapes/arc/start", 0.0,
5564 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-arc",
5565 -360.0, 360.0, 1.0, 10.0,
5566 0, 0, 0,
5567 sp_arctb_start_value_changed);
5568 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5569 }
5571 /* End */
5572 {
5573 eact = create_adjustment_action( "ArcEndAction",
5574 _("End"), _("End:"),
5575 _("The angle (in degrees) from the horizontal to the arc's end point"),
5576 "/tools/shapes/arc/end", 0.0,
5577 GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
5578 -360.0, 360.0, 1.0, 10.0,
5579 0, 0, 0,
5580 sp_arctb_end_value_changed);
5581 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
5582 }
5584 /* Segments / Pie checkbox */
5585 {
5586 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
5588 GtkTreeIter iter;
5589 gtk_list_store_append( model, &iter );
5590 gtk_list_store_set( model, &iter,
5591 0, _("Closed arc"),
5592 1, _("Switch to segment (closed shape with two radii)"),
5593 2, INKSCAPE_ICON_DRAW_ELLIPSE_SEGMENT,
5594 -1 );
5596 gtk_list_store_append( model, &iter );
5597 gtk_list_store_set( model, &iter,
5598 0, _("Open Arc"),
5599 1, _("Switch to arc (unclosed shape)"),
5600 2, INKSCAPE_ICON_DRAW_ELLIPSE_ARC,
5601 -1 );
5603 EgeSelectOneAction* act = ege_select_one_action_new( "ArcOpenAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
5604 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
5605 g_object_set_data( holder, "open_action", act );
5607 ege_select_one_action_set_appearance( act, "full" );
5608 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
5609 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
5610 ege_select_one_action_set_icon_column( act, 2 );
5611 ege_select_one_action_set_icon_size( act, secondarySize );
5612 ege_select_one_action_set_tooltip_column( act, 1 );
5614 bool isClosed = !prefs->getBool("/tools/shapes/arc/open", false);
5615 ege_select_one_action_set_active( act, isClosed ? 0 : 1 );
5616 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_arctb_open_state_changed), holder );
5617 }
5619 /* Make Whole */
5620 {
5621 InkAction* inky = ink_action_new( "ArcResetAction",
5622 _("Make whole"),
5623 _("Make the shape a whole ellipse, not arc or segment"),
5624 INKSCAPE_ICON_DRAW_ELLIPSE_WHOLE,
5625 secondarySize );
5626 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_arctb_defaults), holder );
5627 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
5628 gtk_action_set_sensitive( GTK_ACTION(inky), TRUE );
5629 g_object_set_data( holder, "make_whole", inky );
5630 }
5632 g_object_set_data( G_OBJECT(holder), "single", GINT_TO_POINTER(TRUE) );
5633 // sensitivize make whole and open checkbox
5634 {
5635 GtkAdjustment *adj1 = GTK_ADJUSTMENT( g_object_get_data( holder, "start" ) );
5636 GtkAdjustment *adj2 = GTK_ADJUSTMENT( g_object_get_data( holder, "end" ) );
5637 sp_arctb_sensitivize( holder, adj1->value, adj2->value );
5638 }
5641 sigc::connection *connection = new sigc::connection(
5642 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_arc_toolbox_selection_changed), (GObject *)holder))
5643 );
5644 g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
5645 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
5646 }
5651 // toggle button callbacks and updaters
5653 //########################
5654 //## Dropper ##
5655 //########################
5657 static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl )
5658 {
5659 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5660 prefs->setInt( "/tools/dropper/pick", gtk_toggle_action_get_active( act ) );
5661 GtkAction* set_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "set_action") );
5662 if ( set_action ) {
5663 if ( gtk_toggle_action_get_active( act ) ) {
5664 gtk_action_set_sensitive( set_action, TRUE );
5665 } else {
5666 gtk_action_set_sensitive( set_action, FALSE );
5667 }
5668 }
5670 spinbutton_defocus(GTK_OBJECT(tbl));
5671 }
5673 static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl )
5674 {
5675 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5676 prefs->setBool( "/tools/dropper/setalpha", gtk_toggle_action_get_active( act ) );
5677 spinbutton_defocus(GTK_OBJECT(tbl));
5678 }
5681 /**
5682 * Dropper auxiliary toolbar construction and setup.
5683 *
5684 * TODO: Would like to add swatch of current color.
5685 * TODO: Add queue of last 5 or so colors selected with new swatches so that
5686 * can drag and drop places. Will provide a nice mixing palette.
5687 */
5688 static void sp_dropper_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder)
5689 {
5690 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5691 gint pickAlpha = prefs->getInt( "/tools/dropper/pick", 1 );
5693 {
5694 EgeOutputAction* act = ege_output_action_new( "DropperOpacityAction", _("Opacity:"), "", 0 );
5695 ege_output_action_set_use_markup( act, TRUE );
5696 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5697 }
5699 {
5700 InkToggleAction* act = ink_toggle_action_new( "DropperPickAlphaAction",
5701 _("Pick opacity"),
5702 _("Pick both the color and the alpha (transparency) under cursor; otherwise, pick only the visible color premultiplied by alpha"),
5703 NULL,
5704 Inkscape::ICON_SIZE_DECORATION );
5705 g_object_set( act, "short_label", _("Pick"), NULL );
5706 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5707 g_object_set_data( holder, "pick_action", act );
5708 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), pickAlpha );
5709 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_pick_alpha), holder );
5710 }
5712 {
5713 InkToggleAction* act = ink_toggle_action_new( "DropperSetAlphaAction",
5714 _("Assign opacity"),
5715 _("If alpha was picked, assign it to selection as fill or stroke transparency"),
5716 NULL,
5717 Inkscape::ICON_SIZE_DECORATION );
5718 g_object_set( act, "short_label", _("Assign"), NULL );
5719 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
5720 g_object_set_data( holder, "set_action", act );
5721 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool( "/tools/dropper/setalpha", true) );
5722 // make sure it's disabled if we're not picking alpha
5723 gtk_action_set_sensitive( GTK_ACTION(act), pickAlpha );
5724 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_dropper_set_alpha), holder );
5725 }
5726 }
5729 //########################
5730 //## LPETool ##
5731 //########################
5733 // the subtools from which the toolbar is built automatically are listed in lpe-tool-context.h
5735 // this is called when the mode is changed via the toolbar (i.e., one of the subtool buttons is pressed)
5736 static void sp_lpetool_mode_changed(EgeSelectOneAction *act, GObject *tbl)
5737 {
5738 using namespace Inkscape::LivePathEffect;
5740 SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop");
5741 SPEventContext *ec = desktop->event_context;
5742 if (!SP_IS_LPETOOL_CONTEXT(ec)) {
5743 return;
5744 }
5746 // only take action if run by the attr_changed listener
5747 if (!g_object_get_data(tbl, "freeze")) {
5748 // in turn, prevent listener from responding
5749 g_object_set_data(tbl, "freeze", GINT_TO_POINTER(TRUE));
5751 gint mode = ege_select_one_action_get_active(act);
5752 EffectType type = lpesubtools[mode].type;
5754 SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(desktop->event_context);
5755 bool success = lpetool_try_construction(lc, type);
5756 if (success) {
5757 // since the construction was already performed, we set the state back to inactive
5758 ege_select_one_action_set_active(act, 0);
5759 mode = 0;
5760 } else {
5761 // switch to the chosen subtool
5762 SP_LPETOOL_CONTEXT(desktop->event_context)->mode = type;
5763 }
5765 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
5766 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5767 prefs->setInt( "/tools/lpetool/mode", mode );
5768 }
5770 g_object_set_data(tbl, "freeze", GINT_TO_POINTER(FALSE));
5771 }
5772 }
5774 static void sp_lpetool_toolbox_sel_modified(Inkscape::Selection *selection, guint /*flags*/, GObject * /*tbl*/)
5775 {
5776 SPEventContext *ec = selection->desktop()->event_context;
5777 if (SP_IS_LPETOOL_CONTEXT(ec)) {
5778 lpetool_update_measuring_items(SP_LPETOOL_CONTEXT(ec));
5779 }
5780 }
5782 static void sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl)
5783 {
5784 using namespace Inkscape::LivePathEffect;
5785 SPEventContext *ec = selection->desktop()->event_context;
5786 if (!SP_IS_LPETOOL_CONTEXT(ec)) {
5787 return;
5788 }
5789 SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec);
5791 lpetool_delete_measuring_items(lc);
5792 lpetool_create_measuring_items(lc, selection);
5794 // activate line segment combo box if a single item with LPELineSegment is selected
5795 GtkAction* w = GTK_ACTION(g_object_get_data(tbl, "lpetool_line_segment_action"));
5796 SPItem *item = selection->singleItem();
5797 if (item && SP_IS_LPE_ITEM(item) && lpetool_item_has_construction(lc, item)) {
5798 SPLPEItem *lpeitem = SP_LPE_ITEM(item);
5799 Effect* lpe = sp_lpe_item_get_current_lpe(lpeitem);
5800 if (lpe && lpe->effectType() == LINE_SEGMENT) {
5801 LPELineSegment *lpels = static_cast<LPELineSegment*>(lpe);
5802 g_object_set_data(tbl, "currentlpe", lpe);
5803 g_object_set_data(tbl, "currentlpeitem", lpeitem);
5804 gtk_action_set_sensitive(w, TRUE);
5805 ege_select_one_action_set_active(EGE_SELECT_ONE_ACTION(w), lpels->end_type.get_value());
5806 } else {
5807 g_object_set_data(tbl, "currentlpe", NULL);
5808 g_object_set_data(tbl, "currentlpeitem", NULL);
5809 gtk_action_set_sensitive(w, FALSE);
5810 }
5811 } else {
5812 g_object_set_data(tbl, "currentlpe", NULL);
5813 g_object_set_data(tbl, "currentlpeitem", NULL);
5814 gtk_action_set_sensitive(w, FALSE);
5815 }
5816 }
5818 static void lpetool_toggle_show_bbox(GtkToggleAction *act, gpointer data) {
5819 SPDesktop *desktop = static_cast<SPDesktop *>(data);
5820 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5822 bool show = gtk_toggle_action_get_active( act );
5823 prefs->setBool("/tools/lpetool/show_bbox", show);
5825 if (tools_isactive(desktop, TOOLS_LPETOOL)) {
5826 SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(desktop->event_context);
5827 lpetool_context_reset_limiting_bbox(lc);
5828 }
5829 }
5831 static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tbl)
5832 {
5833 SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(tbl, "desktop"));
5834 if (!tools_isactive(desktop, TOOLS_LPETOOL)) {
5835 return;
5836 }
5838 GtkAction *unitact = static_cast<GtkAction*>(g_object_get_data(tbl, "lpetool_units_action"));
5839 SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(desktop->event_context);
5840 if (tools_isactive(desktop, TOOLS_LPETOOL)) {
5841 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5842 bool show = gtk_toggle_action_get_active( act );
5843 prefs->setBool("/tools/lpetool/show_measuring_info", show);
5844 lpetool_show_measuring_info(lc, show);
5845 gtk_action_set_sensitive(GTK_ACTION(unitact), show);
5846 }
5847 }
5849 static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl)
5850 {
5851 UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
5852 SPUnit const *unit = tracker->getActiveUnit();
5853 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5854 prefs->setInt("/tools/lpetool/unitid", unit->unit_id);
5856 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
5857 if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) {
5858 SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(desktop->event_context);
5859 lpetool_delete_measuring_items(lc);
5860 lpetool_create_measuring_items(lc);
5861 }
5862 }
5864 static void lpetool_toggle_set_bbox(GtkToggleAction *act, gpointer data)
5865 {
5866 SPDesktop *desktop = static_cast<SPDesktop *>(data);
5867 Inkscape::Selection *selection = desktop->selection;
5869 Geom::OptRect bbox = selection->bounds();
5871 if (bbox) {
5872 Geom::Point A(bbox->min());
5873 Geom::Point B(bbox->max());
5875 A *= desktop->doc2dt();
5876 B *= desktop->doc2dt();
5878 // TODO: should we provide a way to store points in prefs?
5879 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5880 prefs->setDouble("/tools/lpetool/bbox_upperleftx", A[Geom::X]);
5881 prefs->setDouble("/tools/lpetool/bbox_upperlefty", A[Geom::Y]);
5882 prefs->setDouble("/tools/lpetool/bbox_lowerrightx", B[Geom::X]);
5883 prefs->setDouble("/tools/lpetool/bbox_lowerrighty", B[Geom::Y]);
5885 lpetool_context_reset_limiting_bbox(SP_LPETOOL_CONTEXT(desktop->event_context));
5886 }
5888 gtk_toggle_action_set_active(act, false);
5889 }
5891 static void sp_line_segment_build_list(GObject *tbl)
5892 {
5893 g_object_set_data(tbl, "line_segment_list_blocked", GINT_TO_POINTER(TRUE));
5895 EgeSelectOneAction* selector = static_cast<EgeSelectOneAction *>(g_object_get_data(tbl, "lpetool_line_segment_action"));
5896 GtkListStore* model = GTK_LIST_STORE(ege_select_one_action_get_model(selector));
5897 gtk_list_store_clear (model);
5899 // TODO: we add the entries of rht combo box manually; later this should be done automatically
5900 {
5901 GtkTreeIter iter;
5902 gtk_list_store_append( model, &iter );
5903 gtk_list_store_set( model, &iter, 0, _("Closed"), 1, 0, -1 );
5904 gtk_list_store_append( model, &iter );
5905 gtk_list_store_set( model, &iter, 0, _("Open start"), 1, 1, -1 );
5906 gtk_list_store_append( model, &iter );
5907 gtk_list_store_set( model, &iter, 0, _("Open end"), 1, 2, -1 );
5908 gtk_list_store_append( model, &iter );
5909 gtk_list_store_set( model, &iter, 0, _("Open both"), 1, 3, -1 );
5910 }
5912 g_object_set_data(tbl, "line_segment_list_blocked", GINT_TO_POINTER(FALSE));
5913 }
5915 static void sp_lpetool_change_line_segment_type(EgeSelectOneAction* act, GObject* tbl)
5916 {
5917 using namespace Inkscape::LivePathEffect;
5919 // quit if run by the attr_changed listener
5920 if (g_object_get_data(tbl, "freeze")) {
5921 return;
5922 }
5924 // in turn, prevent listener from responding
5925 g_object_set_data(tbl, "freeze", GINT_TO_POINTER(TRUE));
5927 LPELineSegment *lpe = static_cast<LPELineSegment *>(g_object_get_data(tbl, "currentlpe"));
5928 SPLPEItem *lpeitem = static_cast<SPLPEItem *>(g_object_get_data(tbl, "currentlpeitem"));
5929 if (lpeitem) {
5930 SPLPEItem *lpeitem = static_cast<SPLPEItem *>(g_object_get_data(tbl, "currentlpeitem"));
5931 lpe->end_type.param_set_value(static_cast<Inkscape::LivePathEffect::EndType>(ege_select_one_action_get_active(act)));
5932 sp_lpe_item_update_patheffect(lpeitem, true, true);
5933 }
5935 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
5936 }
5938 static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data)
5939 {
5940 SPDesktop *desktop = static_cast<SPDesktop *>(data);
5942 if (tools_isactive(desktop, TOOLS_LPETOOL)) {
5943 sp_action_perform(Inkscape::Verb::get(SP_VERB_DIALOG_LIVE_PATH_EFFECT)->get_action(desktop), NULL);
5944 }
5945 gtk_toggle_action_set_active(act, false);
5946 }
5948 static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
5949 {
5950 UnitTracker* tracker = new UnitTracker(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
5951 tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units);
5952 g_object_set_data(holder, "tracker", tracker);
5953 SPUnit const *unit = tracker->getActiveUnit();
5955 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
5956 prefs->setInt("/tools/lpetool/unitid", unit->unit_id);
5958 /** Automatically create a list of LPEs that get added to the toolbar **/
5959 {
5960 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
5962 GtkTreeIter iter;
5964 // the first toggle button represents the state that no subtool is active (remove this when
5965 // this can be modeled by EgeSelectOneAction or some other action)
5966 gtk_list_store_append( model, &iter );
5967 gtk_list_store_set( model, &iter,
5968 0, _("All inactive"),
5969 1, _("No geometric tool is active"),
5970 2, "draw-geometry-inactive",
5971 -1 );
5973 Inkscape::LivePathEffect::EffectType type;
5974 for (int i = 1; i < num_subtools; ++i) { // we start with i = 1 because INVALID_LPE was already added
5975 type = lpesubtools[i].type;
5976 gtk_list_store_append( model, &iter );
5977 gtk_list_store_set( model, &iter,
5978 0, Inkscape::LivePathEffect::LPETypeConverter.get_label(type).c_str(),
5979 1, Inkscape::LivePathEffect::LPETypeConverter.get_label(type).c_str(),
5980 2, lpesubtools[i].icon_name,
5981 -1 );
5982 }
5984 EgeSelectOneAction* act = ege_select_one_action_new( "LPEToolModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
5985 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
5986 g_object_set_data( holder, "lpetool_mode_action", act );
5988 ege_select_one_action_set_appearance( act, "full" );
5989 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
5990 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
5991 ege_select_one_action_set_icon_column( act, 2 );
5992 ege_select_one_action_set_tooltip_column( act, 1 );
5994 gint lpeToolMode = prefs->getInt("/tools/lpetool/mode", 0);
5995 ege_select_one_action_set_active( act, lpeToolMode );
5996 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_lpetool_mode_changed), holder );
5997 }
5999 /* Show limiting bounding box */
6000 {
6001 InkToggleAction* act = ink_toggle_action_new( "LPEShowBBoxAction",
6002 _("Show limiting bounding box"),
6003 _("Show bounding box (used to cut infinite lines)"),
6004 "show-bounding-box",
6005 Inkscape::ICON_SIZE_DECORATION );
6006 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
6007 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_toggle_show_bbox), desktop );
6008 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool( "/tools/lpetool/show_bbox", true ) );
6009 }
6011 /* Set limiting bounding box to bbox of current selection */
6012 {
6013 InkToggleAction* act = ink_toggle_action_new( "LPEBBoxFromSelectionAction",
6014 _("Get limiting bounding box from selection"),
6015 _("Set limiting bounding box (used to cut infinite lines) to the bounding box of current selection"),
6016 "draw-geometry-set-bounding-box",
6017 Inkscape::ICON_SIZE_DECORATION );
6018 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
6019 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_toggle_set_bbox), desktop );
6020 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), FALSE );
6021 }
6024 /* Combo box to choose line segment type */
6025 {
6026 GtkListStore* model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
6027 EgeSelectOneAction* act = ege_select_one_action_new ("LPELineSegmentAction", "" , (_("Choose a line segment type")), NULL, GTK_TREE_MODEL(model));
6028 ege_select_one_action_set_appearance (act, "compact");
6029 g_object_set_data (holder, "lpetool_line_segment_action", act );
6031 g_object_set_data(holder, "line_segment_list_blocked", GINT_TO_POINTER(FALSE));
6033 sp_line_segment_build_list (holder);
6035 g_signal_connect(G_OBJECT(act), "changed", G_CALLBACK(sp_lpetool_change_line_segment_type), holder);
6036 gtk_action_set_sensitive( GTK_ACTION(act), FALSE );
6037 gtk_action_group_add_action(mainActions, GTK_ACTION(act));
6038 }
6040 /* Display measuring info for selected items */
6041 {
6042 InkToggleAction* act = ink_toggle_action_new( "LPEMeasuringAction",
6043 _("Display measuring info"),
6044 _("Display measuring info for selected items"),
6045 "draw-geometry-show-measuring-info",
6046 Inkscape::ICON_SIZE_DECORATION );
6047 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
6048 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_toggle_show_measuring_info), holder );
6049 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool( "/tools/lpetool/show_measuring_info", true ) );
6050 }
6052 // add the units menu
6053 {
6054 GtkAction* act = tracker->createAction( "LPEToolUnitsAction", _("Units"), ("") );
6055 gtk_action_group_add_action( mainActions, act );
6056 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(lpetool_unit_changed), (GObject*)holder );
6057 g_object_set_data(holder, "lpetool_units_action", act);
6058 gtk_action_set_sensitive(act, prefs->getBool("/tools/lpetool/show_measuring_info", true));
6059 }
6061 /* Open LPE dialog (to adapt parameters numerically) */
6062 {
6063 InkToggleAction* act = ink_toggle_action_new( "LPEOpenLPEDialogAction",
6064 _("Open LPE dialog"),
6065 _("Open LPE dialog (to adapt parameters numerically)"),
6066 "dialog-geometry",
6067 Inkscape::ICON_SIZE_DECORATION );
6068 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
6069 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_open_lpe_dialog), desktop );
6070 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), FALSE );
6071 }
6073 //watch selection
6074 Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISNodeToolbox");
6076 sigc::connection *c_selection_modified =
6077 new sigc::connection (sp_desktop_selection (desktop)->connectModified
6078 (sigc::bind (sigc::ptr_fun (sp_lpetool_toolbox_sel_modified), (GObject*)holder)));
6079 pool->add_connection ("selection-modified", c_selection_modified);
6081 sigc::connection *c_selection_changed =
6082 new sigc::connection (sp_desktop_selection (desktop)->connectChanged
6083 (sigc::bind (sigc::ptr_fun(sp_lpetool_toolbox_sel_changed), (GObject*)holder)));
6084 pool->add_connection ("selection-changed", c_selection_changed);
6085 }
6087 //########################
6088 //## Eraser ##
6089 //########################
6091 static void sp_erc_width_value_changed( GtkAdjustment *adj, GObject *tbl )
6092 {
6093 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6094 prefs->setDouble( "/tools/eraser/width", adj->value );
6095 update_presets_list(tbl);
6096 }
6098 static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl )
6099 {
6100 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
6101 bool eraserMode = ege_select_one_action_get_active( act ) != 0;
6102 if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) {
6103 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6104 prefs->setBool( "/tools/eraser/mode", eraserMode );
6105 }
6107 // only take action if run by the attr_changed listener
6108 if (!g_object_get_data( tbl, "freeze" )) {
6109 // in turn, prevent listener from responding
6110 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6112 if ( eraserMode != 0 ) {
6113 } else {
6114 }
6115 // TODO finish implementation
6117 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6118 }
6119 }
6121 static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
6122 {
6123 {
6124 /* Width */
6125 gchar const* labels[] = {_("(hairline)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad stroke)")};
6126 gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100};
6127 EgeAdjustmentAction *eact = create_adjustment_action( "EraserWidthAction",
6128 _("Pen Width"), _("Width:"),
6129 _("The width of the eraser pen (relative to the visible canvas area)"),
6130 "/tools/eraser/width", 15,
6131 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-eraser",
6132 1, 100, 1.0, 10.0,
6133 labels, values, G_N_ELEMENTS(labels),
6134 sp_erc_width_value_changed, 1, 0);
6135 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
6136 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
6137 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
6138 }
6140 {
6141 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
6143 GtkTreeIter iter;
6144 gtk_list_store_append( model, &iter );
6145 gtk_list_store_set( model, &iter,
6146 0, _("Delete"),
6147 1, _("Delete objects touched by the eraser"),
6148 2, INKSCAPE_ICON_DRAW_ERASER_DELETE_OBJECTS,
6149 -1 );
6151 gtk_list_store_append( model, &iter );
6152 gtk_list_store_set( model, &iter,
6153 0, _("Cut"),
6154 1, _("Cut out from objects"),
6155 2, INKSCAPE_ICON_PATH_DIFFERENCE,
6156 -1 );
6158 EgeSelectOneAction* act = ege_select_one_action_new( "EraserModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
6159 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
6160 g_object_set_data( holder, "eraser_mode_action", act );
6162 ege_select_one_action_set_appearance( act, "full" );
6163 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
6164 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
6165 ege_select_one_action_set_icon_column( act, 2 );
6166 ege_select_one_action_set_tooltip_column( act, 1 );
6168 /// @todo Convert to boolean?
6169 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6170 gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
6171 ege_select_one_action_set_active( act, eraserMode );
6172 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder );
6173 }
6175 }
6177 //########################
6178 //## Text Toolbox ##
6179 //########################
6181 // Functions for debugging:
6182 #ifdef DEBUG_TEXT
6184 static void sp_print_font( SPStyle *query ) {
6186 bool family_set = query->text->font_family.set;
6187 bool style_set = query->font_style.set;
6188 bool fontspec_set = query->text->font_specification.set;
6190 std::cout << " Family set? " << family_set
6191 << " Style set? " << style_set
6192 << " FontSpec set? " << fontspec_set
6193 << std::endl;
6194 std::cout << " Family: "
6195 << (query->text->font_family.value ? query->text->font_family.value : "No value")
6196 << " Style: " << query->font_style.computed
6197 << " Weight: " << query->font_weight.computed
6198 << " FontSpec: "
6199 << (query->text->font_specification.value ? query->text->font_specification.value : "No value")
6200 << std::endl;
6201 }
6203 static void sp_print_fontweight( SPStyle *query ) {
6204 const gchar* names[] = {"100", "200", "300", "400", "500", "600", "700", "800", "900",
6205 "NORMAL", "BOLD", "LIGHTER", "BOLDER", "Out of range"};
6206 // Missing book = 380
6207 int index = query->font_weight.computed;
6208 if( index < 0 || index > 13 ) index = 13;
6209 std::cout << " Weight: " << names[ index ]
6210 << " (" << query->font_weight.computed << ")" << std::endl;
6212 }
6214 static void sp_print_fontstyle( SPStyle *query ) {
6216 const gchar* names[] = {"NORMAL", "ITALIC", "OBLIQUE", "Out of range"};
6217 int index = query->font_style.computed;
6218 if( index < 0 || index > 3 ) index = 3;
6219 std::cout << " Style: " << names[ index ] << std::endl;
6221 }
6222 #endif
6224 // Format family drop-down menu.
6225 static void cell_data_func(GtkCellLayout * /*cell_layout*/,
6226 GtkCellRenderer *cell,
6227 GtkTreeModel *tree_model,
6228 GtkTreeIter *iter,
6229 gpointer /*data*/)
6230 {
6231 gchar *family;
6232 gtk_tree_model_get(tree_model, iter, 0, &family, -1);
6233 gchar *const family_escaped = g_markup_escape_text(family, -1);
6235 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6236 int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1);
6237 if (show_sample) {
6239 Glib::ustring sample = prefs->getString("/tools/text/font_sample");
6240 gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1);
6242 std::stringstream markup;
6243 markup << family_escaped << " <span foreground='gray' font_family='"
6244 << family_escaped << "'>" << sample_escaped << "</span>";
6245 g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL);
6247 g_free(sample_escaped);
6248 } else {
6249 g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL);
6250 }
6252 g_free(family);
6253 g_free(family_escaped);
6254 }
6256 // Font family
6257 static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl )
6258 {
6259 #ifdef DEBUG_TEXT
6260 std::cout << std::endl;
6261 std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl;
6262 std::cout << "sp_text_fontfamily_value_changed: " << std::endl;
6263 #endif
6265 // quit if run by the _changed callbacks
6266 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6267 return;
6268 }
6269 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6271 gchar *family = ink_comboboxentry_action_get_active_text( act );
6272 #ifdef DEBUG_TEXT
6273 std::cout << " New family: " << family << std::endl;
6274 #endif
6276 // First try to get the old font spec from the stored value
6277 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6278 int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
6280 Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : "";
6282 // If that didn't work, try to get font spec from style
6283 if (fontSpec.empty()) {
6285 // Must query all to fill font-family, font-style, font-weight, font-specification
6286 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
6287 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
6288 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6290 // Construct a new font specification if it does not yet exist
6291 font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
6292 if( fontFromStyle ) {
6293 fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
6294 fontFromStyle->Unref();
6295 }
6296 #ifdef DEBUG_TEXT
6297 std::cout << " Fontspec not defined, reconstructed from style :" << fontSpec << ":" << std::endl;
6298 sp_print_font( query );
6299 #endif
6300 }
6302 // And if that didn't work use default
6303 if( fontSpec.empty() ) {
6304 sp_style_read_from_prefs(query, "/tools/text");
6305 #ifdef DEBUG_TEXT
6306 std::cout << " read style from prefs:" << std::endl;
6307 sp_print_font( query );
6308 #endif
6309 // Construct a new font specification if it does not yet exist
6310 font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
6311 if( fontFromStyle ) {
6312 fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
6313 fontFromStyle->Unref();
6314 }
6315 #ifdef DEBUG_TEXT
6316 std::cout << " Fontspec not defined, reconstructed from style :" << fontSpec << ":" << std::endl;
6317 sp_print_font( query );
6318 #endif
6319 }
6321 SPCSSAttr *css = sp_repr_css_attr_new ();
6322 if (!fontSpec.empty()) {
6324 // Now we have a font specification, replace family.
6325 Glib::ustring newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family);
6327 #ifdef DEBUG_TEXT
6328 std::cout << " New FontSpec from ReplaceFontSpecificationFamily :" << newFontSpec << ":" << std::endl;
6329 #endif
6331 if (!newFontSpec.empty()) {
6333 if (fontSpec != newFontSpec) {
6335 font_instance *font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str());
6337 if (font) {
6338 sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str());
6340 // Set all the these just in case they were altered when finding the best
6341 // match for the new family and old style...
6343 gchar c[256];
6345 font->Family(c, 256);
6347 sp_repr_css_set_property (css, "font-family", c);
6349 font->Attribute( "weight", c, 256);
6350 sp_repr_css_set_property (css, "font-weight", c);
6352 font->Attribute("style", c, 256);
6353 sp_repr_css_set_property (css, "font-style", c);
6355 font->Attribute("stretch", c, 256);
6356 sp_repr_css_set_property (css, "font-stretch", c);
6358 font->Attribute("variant", c, 256);
6359 sp_repr_css_set_property (css, "font-variant", c);
6361 font->Unref();
6362 }
6363 }
6365 } else {
6367 // newFontSpec empty
6368 // If the old font on selection (or default) does not exist on the system,
6369 // or the new font family does not exist,
6370 // ReplaceFontSpecificationFamily does not work. In that case we fall back to blindly
6371 // setting the family reported by the family chooser.
6373 // g_print ("fallback setting family: %s\n", family);
6374 sp_repr_css_set_property (css, "-inkscape-font-specification", family);
6375 sp_repr_css_set_property (css, "font-family", family);
6376 // Shoud we set other css font attributes?
6377 }
6379 } // fontSpec not empty or not
6381 // If querying returned nothing, update default style.
6382 if (result_fontspec == QUERY_STYLE_NOTHING)
6383 {
6384 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6385 prefs->mergeStyle("/tools/text/style", css);
6386 sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace through a verb
6387 }
6388 else
6389 {
6390 sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true);
6391 }
6393 sp_style_unref(query);
6395 g_free (family);
6397 // Save for undo
6398 sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
6399 _("Text: Change font family"));
6400 sp_repr_css_attr_unref (css);
6402 // unfreeze
6403 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6405 // focus to canvas
6406 gtk_widget_grab_focus (GTK_WIDGET((SP_ACTIVE_DESKTOP)->canvas));
6408 #ifdef DEBUG_TEXT
6409 std::cout << "sp_text_toolbox_fontfamily_changes: exit" << std::endl;
6410 std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl;
6411 std::cout << std::endl;
6412 #endif
6413 }
6415 // Font size
6416 static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl )
6417 {
6418 // quit if run by the _changed callbacks
6419 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6420 return;
6421 }
6422 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6424 gchar *text = ink_comboboxentry_action_get_active_text( act );
6425 gchar *endptr;
6426 gdouble size = g_strtod( text, &endptr );
6427 if (endptr == text) { // Conversion failed, non-numeric input.
6428 g_warning( "Conversion of size text to double failed, input: %s\n", text );
6429 g_free( text );
6430 return;
6431 }
6432 g_free( text );
6434 // Set css font size.
6435 SPCSSAttr *css = sp_repr_css_attr_new ();
6436 Inkscape::CSSOStringStream osfs;
6437 osfs << size << "px"; // For now always use px
6438 sp_repr_css_set_property (css, "font-size", osfs.str().c_str());
6440 // Apply font size to selected objects.
6441 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6442 sp_desktop_set_style (desktop, css, true, true);
6444 // Save for undo
6445 sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE,
6446 _("Text: Change font size"));
6448 // If no selected objects, set default.
6449 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6450 int result_numbers =
6451 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6452 if (result_numbers == QUERY_STYLE_NOTHING)
6453 {
6454 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6455 prefs->mergeStyle("/tools/text/style", css);
6456 }
6457 sp_style_unref(query);
6459 sp_repr_css_attr_unref (css);
6461 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6462 }
6464 // Handles both Bold and Italic/Oblique
6465 static void sp_text_style_changed( InkToggleAction* act, GObject *tbl )
6466 {
6467 // quit if run by the _changed callbacks
6468 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6469 return;
6470 }
6471 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6473 // Called by Bold or Italics button?
6474 const gchar* name = gtk_action_get_name( GTK_ACTION( act ) );
6475 gint prop = (strcmp(name, "TextBoldAction") == 0) ? 0 : 1;
6477 // First query font-specification, this is the most complete font face description.
6478 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6479 int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
6481 // font_specification will not be set unless defined explicitely on a tspan.
6482 // This should be fixed!
6483 Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : "";
6485 if (fontSpec.empty()) {
6486 // Construct a new font specification if it does not yet exist
6487 // Must query font-family, font-style, font-weight, to find correct font face.
6488 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
6489 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
6490 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6492 font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query);
6493 if( fontFromStyle ) {
6494 fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle);
6495 fontFromStyle->Unref();
6496 }
6497 }
6499 // Now that we have the old face, find the new face.
6500 Glib::ustring newFontSpec = "";
6501 SPCSSAttr *css = sp_repr_css_attr_new ();
6502 gboolean nochange = true;
6503 gboolean active = gtk_toggle_action_get_active( GTK_TOGGLE_ACTION(act) );
6505 switch (prop)
6506 {
6507 case 0:
6508 {
6509 // Bold
6510 if (!fontSpec.empty()) {
6512 newFontSpec = font_factory::Default()->FontSpecificationSetBold(fontSpec, active);
6514 if (!newFontSpec.empty()) {
6516 // Set weight if we found font.
6517 font_instance * font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str());
6518 if (font) {
6519 gchar c[256];
6520 font->Attribute( "weight", c, 256);
6521 sp_repr_css_set_property (css, "font-weight", c);
6522 font->Unref();
6523 font = NULL;
6524 }
6525 nochange = false;
6526 }
6527 }
6528 // Reset button if no change.
6529 // The reset code didn't work in 0.47 and doesn't here... one must prevent an infinite loop
6530 /*
6531 if(nochange) {
6532 gtk_action_block_activate( GTK_ACTION(act) );
6533 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), !active );
6534 gtk_action_unblock_activate( GTK_ACTION(act) );
6535 }
6536 */
6537 break;
6538 }
6540 case 1:
6541 {
6542 // Italic/Oblique
6543 if (!fontSpec.empty()) {
6545 newFontSpec = font_factory::Default()->FontSpecificationSetItalic(fontSpec, active);
6547 if (!newFontSpec.empty()) {
6549 // Don't even set the italic/oblique if the font didn't exist on the system
6550 if( active ) {
6551 if( newFontSpec.find( "Italic" ) != Glib::ustring::npos ) {
6552 sp_repr_css_set_property (css, "font-style", "italic");
6553 } else {
6554 sp_repr_css_set_property (css, "font-style", "oblique");
6555 }
6556 } else {
6557 sp_repr_css_set_property (css, "font-style", "normal");
6558 }
6559 nochange = false;
6560 }
6561 }
6562 // Reset button if no change.
6563 // The reset code didn't work in 0.47... one must prevent an infinite loop
6564 /*
6565 if(nochange) {
6566 gtk_action_block_activate( GTK_ACTION(act) );
6567 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), !active );
6568 gtk_action_unblock_activate( GTK_ACTION(act) );
6569 }
6570 */
6571 break;
6572 }
6573 }
6575 if (!newFontSpec.empty()) {
6576 sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str());
6577 }
6579 // If querying returned nothing, update default style.
6580 if (result_fontspec == QUERY_STYLE_NOTHING)
6581 {
6582 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6583 prefs->mergeStyle("/tools/text/style", css);
6584 }
6586 sp_style_unref(query);
6588 // Do we need to update other CSS values?
6589 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6590 sp_desktop_set_style (desktop, css, true, true);
6591 sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
6592 _("Text: Change font style"));
6593 sp_repr_css_attr_unref (css);
6595 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6596 }
6598 static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
6599 {
6600 // quit if run by the _changed callbacks
6601 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6602 return;
6603 }
6604 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6606 int mode = ege_select_one_action_get_active( act );
6608 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6609 prefs->setInt("/tools/text/align_mode", mode);
6611 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6613 // move the x of all texts to preserve the same bbox
6614 Inkscape::Selection *selection = sp_desktop_selection(desktop);
6615 for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
6616 if (SP_IS_TEXT((SPItem *) items->data)) {
6617 SPItem *item = SP_ITEM(items->data);
6619 unsigned writing_mode = SP_OBJECT_STYLE(item)->writing_mode.value;
6620 // below, variable names suggest horizontal move, but we check the writing direction
6621 // and move in the corresponding axis
6622 int axis;
6623 if (writing_mode == SP_CSS_WRITING_MODE_LR_TB || writing_mode == SP_CSS_WRITING_MODE_RL_TB) {
6624 axis = NR::X;
6625 } else {
6626 axis = NR::Y;
6627 }
6629 Geom::OptRect bbox
6630 = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX);
6631 if (!bbox)
6632 continue;
6633 double width = bbox->dimensions()[axis];
6634 // If you want to align within some frame, other than the text's own bbox, calculate
6635 // the left and right (or top and bottom for tb text) slacks of the text inside that
6636 // frame (currently unused)
6637 double left_slack = 0;
6638 double right_slack = 0;
6639 unsigned old_align = SP_OBJECT_STYLE(item)->text_align.value;
6640 double move = 0;
6641 if (old_align == SP_CSS_TEXT_ALIGN_START || old_align == SP_CSS_TEXT_ALIGN_LEFT) {
6642 switch (mode) {
6643 case 0:
6644 move = -left_slack;
6645 break;
6646 case 1:
6647 move = width/2 + (right_slack - left_slack)/2;
6648 break;
6649 case 2:
6650 move = width + right_slack;
6651 break;
6652 }
6653 } else if (old_align == SP_CSS_TEXT_ALIGN_CENTER) {
6654 switch (mode) {
6655 case 0:
6656 move = -width/2 - left_slack;
6657 break;
6658 case 1:
6659 move = (right_slack - left_slack)/2;
6660 break;
6661 case 2:
6662 move = width/2 + right_slack;
6663 break;
6664 }
6665 } else if (old_align == SP_CSS_TEXT_ALIGN_END || old_align == SP_CSS_TEXT_ALIGN_RIGHT) {
6666 switch (mode) {
6667 case 0:
6668 move = -width - left_slack;
6669 break;
6670 case 1:
6671 move = -width/2 + (right_slack - left_slack)/2;
6672 break;
6673 case 2:
6674 move = right_slack;
6675 break;
6676 }
6677 }
6678 Geom::Point XY = SP_TEXT(item)->attributes.firstXY();
6679 if (axis == NR::X) {
6680 XY = XY + Geom::Point (move, 0);
6681 } else {
6682 XY = XY + Geom::Point (0, move);
6683 }
6684 SP_TEXT(item)->attributes.setFirstXY(XY);
6685 SP_OBJECT(item)->updateRepr();
6686 SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6687 }
6688 }
6690 SPCSSAttr *css = sp_repr_css_attr_new ();
6691 switch (mode)
6692 {
6693 case 0:
6694 {
6695 sp_repr_css_set_property (css, "text-anchor", "start");
6696 sp_repr_css_set_property (css, "text-align", "start");
6697 break;
6698 }
6699 case 1:
6700 {
6701 sp_repr_css_set_property (css, "text-anchor", "middle");
6702 sp_repr_css_set_property (css, "text-align", "center");
6703 break;
6704 }
6706 case 2:
6707 {
6708 sp_repr_css_set_property (css, "text-anchor", "end");
6709 sp_repr_css_set_property (css, "text-align", "end");
6710 break;
6711 }
6713 case 3:
6714 {
6715 sp_repr_css_set_property (css, "text-anchor", "start");
6716 sp_repr_css_set_property (css, "text-align", "justify");
6717 break;
6718 }
6719 }
6721 SPStyle *query =
6722 sp_style_new (SP_ACTIVE_DOCUMENT);
6723 int result_numbers =
6724 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6726 // If querying returned nothing, update default style.
6727 if (result_numbers == QUERY_STYLE_NOTHING)
6728 {
6729 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6730 prefs->mergeStyle("/tools/text/style", css);
6731 }
6733 sp_style_unref(query);
6735 sp_desktop_set_style (desktop, css, true, true);
6736 sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
6737 _("Text: Change alignment"));
6738 sp_repr_css_attr_unref (css);
6740 gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
6742 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6743 }
6745 static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
6746 {
6747 // quit if run by the _changed callbacks
6748 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6749 return;
6750 }
6751 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6753 // At the moment this handles only numerical values (i.e. no percent).
6754 // Set css line height.
6755 SPCSSAttr *css = sp_repr_css_attr_new ();
6756 Inkscape::CSSOStringStream osfs;
6757 osfs << adj->value*100 << "%";
6758 sp_repr_css_set_property (css, "line-height", osfs.str().c_str());
6760 // Apply line-height to selected objects.
6761 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6762 sp_desktop_set_style (desktop, css, true, true);
6764 // Save for undo
6765 sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:line-height", SP_VERB_NONE,
6766 _("Text: Change line-height"));
6768 // If no selected objects, set default.
6769 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6770 int result_numbers =
6771 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6772 if (result_numbers == QUERY_STYLE_NOTHING)
6773 {
6774 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6775 prefs->mergeStyle("/tools/text/style", css);
6776 }
6777 sp_style_unref(query);
6779 sp_repr_css_attr_unref (css);
6781 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6782 }
6784 static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl )
6785 {
6786 // quit if run by the _changed callbacks
6787 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6788 return;
6789 }
6790 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6792 // At the moment this handles only numerical values (i.e. no em unit).
6793 // Set css word-spacing
6794 SPCSSAttr *css = sp_repr_css_attr_new ();
6795 Inkscape::CSSOStringStream osfs;
6796 osfs << adj->value;
6797 sp_repr_css_set_property (css, "word-spacing", osfs.str().c_str());
6799 // Apply word-spacing to selected objects.
6800 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6801 sp_desktop_set_style (desktop, css, true, true);
6803 // Save for undo
6804 sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:word-spacing", SP_VERB_NONE,
6805 _("Text: Change word-spacing"));
6807 // If no selected objects, set default.
6808 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6809 int result_numbers =
6810 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6811 if (result_numbers == QUERY_STYLE_NOTHING)
6812 {
6813 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6814 prefs->mergeStyle("/tools/text/style", css);
6815 }
6816 sp_style_unref(query);
6818 sp_repr_css_attr_unref (css);
6820 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6821 }
6823 static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tbl )
6824 {
6825 // quit if run by the _changed callbacks
6826 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6827 return;
6828 }
6829 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6831 // At the moment this handles only numerical values (i.e. no em unit).
6832 // Set css letter-spacing
6833 SPCSSAttr *css = sp_repr_css_attr_new ();
6834 Inkscape::CSSOStringStream osfs;
6835 osfs << adj->value;
6836 sp_repr_css_set_property (css, "letter-spacing", osfs.str().c_str());
6838 // Apply letter-spacing to selected objects.
6839 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
6840 sp_desktop_set_style (desktop, css, true, true);
6842 // Save for undo
6843 sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:letter-spacing", SP_VERB_NONE,
6844 _("Text: Change letter-spacing"));
6846 // If no selected objects, set default.
6847 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
6848 int result_numbers =
6849 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6850 if (result_numbers == QUERY_STYLE_NOTHING)
6851 {
6852 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6853 prefs->mergeStyle("/tools/text/style", css);
6854 }
6855 sp_style_unref(query);
6857 sp_repr_css_attr_unref (css);
6859 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6860 }
6862 static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject *tbl )
6863 {
6864 // quit if run by the _changed callbacks
6865 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6866 return;
6867 }
6868 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6870 int mode = ege_select_one_action_get_active( act );
6872 SPCSSAttr *css = sp_repr_css_attr_new ();
6873 switch (mode)
6874 {
6875 case 0:
6876 {
6877 sp_repr_css_set_property (css, "writing-mode", "lr");
6878 break;
6879 }
6881 case 1:
6882 {
6883 sp_repr_css_set_property (css, "writing-mode", "tb");
6884 break;
6885 }
6886 }
6888 SPStyle *query =
6889 sp_style_new (SP_ACTIVE_DOCUMENT);
6890 int result_numbers =
6891 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6893 // If querying returned nothing, update default style.
6894 if (result_numbers == QUERY_STYLE_NOTHING)
6895 {
6896 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6897 prefs->mergeStyle("/tools/text/style", css);
6898 }
6900 sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true);
6901 sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
6902 _("Text: Change orientation"));
6903 sp_repr_css_attr_unref (css);
6905 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6906 }
6908 /*
6909 * This function sets up the text-tool tool-controls, setting the entry boxes
6910 * etc. to the values from the current selection or the default if no selection.
6911 * It is called whenever a text selection is changed, including stepping cursor
6912 * through text.
6913 */
6914 static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/, GObject *tbl)
6915 {
6916 #ifdef DEBUG_TEXT
6917 static int count = 0;
6918 ++count;
6919 std::cout << std::endl;
6920 std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
6921 std::cout << "sp_text_toolbox_selection_changed: start " << count << std::endl;
6923 std::cout << " Selected items:" << std::endl;
6924 for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList();
6925 items != NULL;
6926 items = items->next)
6927 {
6928 const gchar* id = SP_OBJECT_ID((SPItem *) items->data);
6929 std::cout << " " << id << std::endl;
6930 }
6931 #endif
6933 // quit if run by the _changed callbacks
6934 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
6935 #ifdef DEBUG_TEXT
6936 std::cout << " Frozen, returning" << std::endl;
6937 std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
6938 std::cout << std::endl;
6939 #endif
6940 return;
6941 }
6942 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
6944 /*
6945 * Query from current selection:
6946 * Font family (font-family)
6947 * Style (font-weight, font-style, font-stretch, font-variant, font-align)
6948 * Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode)
6949 * Font specification (Inkscape private attribute)
6950 */
6951 SPStyle *query =
6952 sp_style_new (SP_ACTIVE_DOCUMENT);
6953 int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
6954 int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
6955 int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
6956 // Used later:
6957 sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
6959 /*
6960 * If no text in selection (querying returned nothing), read the style from
6961 * the /tools/text preferencess (default style for new texts). Return if
6962 * tool bar already set to these preferences.
6963 */
6964 if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) {
6965 // There are no texts in selection, read from preferences.
6966 sp_style_read_from_prefs(query, "/tools/text");
6967 #ifdef DEBUG_TEXT
6968 std::cout << " read style from prefs:" << std::endl;
6969 sp_print_font( query );
6970 #endif
6971 if (g_object_get_data(tbl, "text_style_from_prefs")) {
6972 // Do not reset the toolbar style from prefs if we already did it last time
6973 sp_style_unref(query);
6974 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
6975 #ifdef DEBUG_TEXT
6976 std::cout << " text_style_from_prefs: toolbar already set" << std:: endl;
6977 std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
6978 std::cout << std::endl;
6979 #endif
6980 return;
6981 }
6983 g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE));
6984 } else {
6985 g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE));
6986 }
6988 // If we have valid query data for text (font-family, font-specification) set toolbar accordingly.
6989 if (query->text)
6990 {
6991 // Font family
6992 if( query->text->font_family.value ) {
6993 gchar *fontFamily = query->text->font_family.value;
6995 Ink_ComboBoxEntry_Action* fontFamilyAction =
6996 INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) );
6997 ink_comboboxentry_action_set_active_text( fontFamilyAction, fontFamily );
6998 }
7000 // Size (average of text selected)
7001 double size = query->font_size.computed;
7002 gchar size_text[G_ASCII_DTOSTR_BUF_SIZE];
7003 g_ascii_dtostr (size_text, sizeof (size_text), size);
7005 Ink_ComboBoxEntry_Action* fontSizeAction =
7006 INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontSizeAction" ) );
7007 ink_comboboxentry_action_set_active_text( fontSizeAction, size_text );
7009 // Weight (Bold)
7010 // Note: in the enumeration, normal and lighter come at the end so we must explicitly test for them.
7011 gboolean boldSet = ((query->font_weight.computed >= SP_CSS_FONT_WEIGHT_700) &&
7012 (query->font_weight.computed != SP_CSS_FONT_WEIGHT_NORMAL) &&
7013 (query->font_weight.computed != SP_CSS_FONT_WEIGHT_LIGHTER));
7015 InkToggleAction* textBoldAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextBoldAction" ) );
7016 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textBoldAction), boldSet );
7019 // Style (Italic/Oblique)
7020 gboolean italicSet = (query->font_style.computed != SP_CSS_FONT_STYLE_NORMAL);
7022 InkToggleAction* textItalicAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextItalicAction" ) );
7023 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textItalicAction), italicSet );
7026 // Alignment
7027 // Note: SVG 1.1 doesn't include text-align, SVG 1.2 Tiny doesn't include text-align="justify"
7028 // text-align="justify" was a draft SVG 1.2 item (along with flowed text).
7029 // Only flowed text can be left and right justified at the same time.
7030 // Check if we have flowed text and disable botton.
7031 // NEED: ege_select_one_action_set_sensitve( )
7032 /*
7033 gboolean isFlow = false;
7034 for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList();
7035 items != NULL;
7036 items = items->next) {
7037 const gchar* id = SP_OBJECT_ID((SPItem *) items->data);
7038 std::cout << " " << id << std::endl;
7039 if( SP_IS_FLOWTEXT(( SPItem *) items->data )) {
7040 isFlow = true;
7041 std::cout << " Found flowed text" << std::endl;
7042 break;
7043 }
7044 }
7045 if( isFlow ) {
7046 // enable justify button
7047 } else {
7048 // disable justify button
7049 }
7050 */
7052 int activeButton = 0;
7053 if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY)
7054 {
7055 activeButton = 3;
7056 } else {
7057 if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0;
7058 if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1;
7059 if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2;
7060 }
7061 EgeSelectOneAction* textAlignAction = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextAlignAction" ) );
7062 ege_select_one_action_set_active( textAlignAction, activeButton );
7065 // Line height (spacing)
7066 double height;
7067 if (query->line_height.normal) {
7068 height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
7069 } else {
7070 if (query->line_height.unit == SP_CSS_UNIT_PERCENT) {
7071 height = query->line_height.value;
7072 } else {
7073 height = query->line_height.computed;
7074 }
7075 }
7077 GtkAction* lineHeightAction = GTK_ACTION( g_object_get_data( tbl, "TextLineHeightAction" ) );
7078 GtkAdjustment *lineHeightAdjustment =
7079 ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( lineHeightAction ));
7080 gtk_adjustment_set_value( lineHeightAdjustment, height );
7083 // Word spacing
7084 double wordSpacing;
7085 if (query->word_spacing.normal) wordSpacing = 0.0;
7086 else wordSpacing = query->word_spacing.computed; // Assume no units (change in desktop-style.cpp)
7088 GtkAction* wordSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextWordSpacingAction" ) );
7089 GtkAdjustment *wordSpacingAdjustment =
7090 ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( wordSpacingAction ));
7091 gtk_adjustment_set_value( wordSpacingAdjustment, wordSpacing );
7094 // Letter spacing
7095 double letterSpacing;
7096 if (query->letter_spacing.normal) letterSpacing = 0.0;
7097 else letterSpacing = query->letter_spacing.computed; // Assume no units (change in desktop-style.cpp)
7099 GtkAction* letterSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextLetterSpacingAction" ) );
7100 GtkAdjustment *letterSpacingAdjustment =
7101 ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( letterSpacingAction ));
7102 gtk_adjustment_set_value( letterSpacingAdjustment, letterSpacing );
7105 // Orientation
7106 int activeButton2 = (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1);
7108 EgeSelectOneAction* textOrientationAction =
7109 EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextOrientationAction" ) );
7110 ege_select_one_action_set_active( textOrientationAction, activeButton2 );
7113 } // if( query->text )
7115 #ifdef DEBUG_TEXT
7116 std::cout << " GUI: fontfamily.value: "
7117 << (query->text->font_family.value ? query->text->font_family.value : "No value")
7118 << std::endl;
7119 std::cout << " GUI: font_size.computed: " << query->font_size.computed << std::endl;
7120 std::cout << " GUI: font_weight.computed: " << query->font_weight.computed << std::endl;
7121 std::cout << " GUI: font_style.computed: " << query->font_style.computed << std::endl;
7122 std::cout << " GUI: text_anchor.computed: " << query->text_anchor.computed << std::endl;
7123 std::cout << " GUI: text_align.computed: " << query->text_align.computed << std::endl;
7124 std::cout << " GUI: line_height.computed: " << query->line_height.computed
7125 << " line_height.value: " << query->line_height.value
7126 << " line_height.unit: " << query->line_height.unit << std::endl;
7127 std::cout << " GUI: word_spacing.computed: " << query->word_spacing.computed
7128 << " word_spacing.value: " << query->word_spacing.value
7129 << " word_spacing.unit: " << query->word_spacing.unit << std::endl;
7130 std::cout << " GUI: letter_spacing.computed: " << query->letter_spacing.computed
7131 << " letter_spacing.value: " << query->letter_spacing.value
7132 << " letter_spacing.unit: " << query->letter_spacing.unit << std::endl;
7133 std::cout << " GUI: writing_mode.computed: " << query->writing_mode.computed << std::endl;
7134 std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl;
7135 std::cout << std::endl;
7136 #endif
7138 sp_style_unref(query);
7140 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
7142 }
7144 static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl)
7145 {
7146 sp_text_toolbox_selection_changed (selection, tbl);
7147 }
7149 void
7150 sp_text_toolbox_subselection_changed (gpointer /*tc*/, GObject *tbl)
7151 {
7152 sp_text_toolbox_selection_changed (NULL, tbl);
7153 }
7155 // Define all the "widgets" in the toolbar.
7156 static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
7157 {
7158 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7159 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
7161 // Is this used?
7162 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
7163 tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
7164 g_object_set_data( holder, "tracker", tracker );
7166 /* Font family */
7167 {
7168 // Font list
7169 Glib::RefPtr<Gtk::ListStore> store = Inkscape::FontLister::get_instance()->get_font_list();
7170 GtkListStore* model = store->gobj();
7172 Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction",
7173 _("Font Family"),
7174 _("Select Font Family"),
7175 NULL,
7176 GTK_TREE_MODEL(model),
7177 -1, // Set width
7178 (gpointer)cell_data_func ); // Cell layout
7179 ink_comboboxentry_action_popup_enable( act ); // Enable entry completion
7180 gchar *const warning = _("Font not found on system");
7181 ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font
7182 g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder );
7183 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
7184 g_object_set_data( holder, "TextFontFamilyAction", act );
7185 }
7187 /* Font size */
7188 {
7189 // List of font sizes for drop-down menu
7190 GtkListStore* model_size = gtk_list_store_new( 1, G_TYPE_STRING );
7191 gchar const *const sizes[] = {
7192 "4", "6", "8", "9", "10", "11", "12", "13", "14", "16",
7193 "18", "20", "22", "24", "28", "32", "36", "40", "48", "56",
7194 "64", "72", "144"
7195 };
7196 for( unsigned int i = 0; i < G_N_ELEMENTS(sizes); ++i ) {
7197 GtkTreeIter iter;
7198 gtk_list_store_append( model_size, &iter );
7199 gtk_list_store_set( model_size, &iter, 0, sizes[i], -1 );
7200 }
7202 Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontSizeAction",
7203 _("Font Size"),
7204 _("Select Font Size"),
7205 NULL,
7206 GTK_TREE_MODEL(model_size),
7207 4 ); // Width in characters
7208 g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontsize_value_changed), holder );
7209 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
7210 g_object_set_data( holder, "TextFontSizeAction", act );
7211 }
7213 /* Style - Bold */
7214 {
7215 InkToggleAction* act = ink_toggle_action_new( "TextBoldAction", // Name
7216 _("Toggle Bold"), // Label
7217 _("Toggle On/Off Bold Style"), // Tooltip
7218 GTK_STOCK_BOLD, // Icon (inkId)
7219 secondarySize ); // Icon size
7220 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7221 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_text_style_changed), holder );
7222 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/text/bold", false) );
7223 g_object_set_data( holder, "TextBoldAction", act );
7224 }
7226 /* Style - Italic/Oblique */
7227 {
7228 InkToggleAction* act = ink_toggle_action_new( "TextItalicAction", // Name
7229 _("Toggle Italic/Oblique"), // Label
7230 _("Toggle On/Off Italic/Oblique Style"),// Tooltip
7231 GTK_STOCK_ITALIC, // Icon (inkId)
7232 secondarySize ); // Icon size
7233 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7234 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_text_style_changed), holder );
7235 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/text/italic", false) );
7236 g_object_set_data( holder, "TextItalicAction", act );
7237 }
7239 /* Alignment */
7240 {
7241 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
7243 GtkTreeIter iter;
7245 gtk_list_store_append( model, &iter );
7246 gtk_list_store_set( model, &iter,
7247 0, _("Align left"),
7248 1, _("Align left"),
7249 2, GTK_STOCK_JUSTIFY_LEFT,
7250 -1 );
7252 gtk_list_store_append( model, &iter );
7253 gtk_list_store_set( model, &iter,
7254 0, _("Align center"),
7255 1, _("Align center"),
7256 2, GTK_STOCK_JUSTIFY_CENTER,
7257 -1 );
7259 gtk_list_store_append( model, &iter );
7260 gtk_list_store_set( model, &iter,
7261 0, _("Align right"),
7262 1, _("Align right"),
7263 2, GTK_STOCK_JUSTIFY_RIGHT,
7264 -1 );
7266 gtk_list_store_append( model, &iter );
7267 gtk_list_store_set( model, &iter,
7268 0, _("Justify"),
7269 1, _("Justify - Only flowed text"),
7270 2, GTK_STOCK_JUSTIFY_FILL,
7271 -1 );
7273 EgeSelectOneAction* act = ege_select_one_action_new( "TextAlignAction", // Name
7274 _("Alignment"), // Label
7275 _("Text Alignment"), // Tooltip
7276 NULL, // StockID
7277 GTK_TREE_MODEL(model) ); // Model
7278 g_object_set( act, "short_label", _("Align"), NULL );
7279 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
7280 g_object_set_data( holder, "TextAlignAction", act );
7282 ege_select_one_action_set_appearance( act, "full" );
7283 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
7284 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
7285 ege_select_one_action_set_icon_column( act, 2 );
7286 ege_select_one_action_set_icon_size( act, secondarySize );
7287 ege_select_one_action_set_tooltip_column( act, 1 );
7289 gint mode = prefs->getInt("/tools/text/align_mode", 0);
7290 ege_select_one_action_set_active( act, mode );
7291 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_align_mode_changed), holder );
7292 }
7294 /* Orientation (Left to Right, Top to Bottom */
7295 {
7296 GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
7298 GtkTreeIter iter;
7300 gtk_list_store_append( model, &iter );
7301 gtk_list_store_set( model, &iter,
7302 0, _("Horizontal"),
7303 1, _("Horizontal Text"),
7304 2, INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_HORIZONTAL,
7305 -1 );
7307 gtk_list_store_append( model, &iter );
7308 gtk_list_store_set( model, &iter,
7309 0, _("Vertical"),
7310 1, _("Vertical Text"),
7311 2, INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_VERTICAL,
7312 -1 );
7314 EgeSelectOneAction* act = ege_select_one_action_new( "TextOrientationAction", // Name
7315 _("Orientation"), // Label
7316 _("Text Orientation"), // Tooltip
7317 NULL, // StockID
7318 GTK_TREE_MODEL(model) ); // Model
7320 g_object_set( act, "short_label", _("O:"), NULL );
7321 gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
7322 g_object_set_data( holder, "TextOrientationAction", act );
7324 ege_select_one_action_set_appearance( act, "full" );
7325 ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
7326 g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
7327 ege_select_one_action_set_icon_column( act, 2 );
7328 ege_select_one_action_set_icon_size( act, secondarySize );
7329 ege_select_one_action_set_tooltip_column( act, 1 );
7331 gint mode = prefs->getInt("/tools/text/orientation", 0);
7332 ege_select_one_action_set_active( act, mode );
7333 g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_orientation_mode_changed), holder );
7334 }
7336 /* Line height */
7337 {
7338 // Drop down menu
7339 gchar const* labels[] = {_("Smaller spacing"), 0, 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, _("Larger spacing")};
7340 gdouble values[] = { 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1,2, 1.3, 1.4, 1.5, 2.0};
7342 EgeAdjustmentAction *eact = create_adjustment_action(
7343 "TextLineHeightAction", /* name */
7344 _("Line Height"), /* label */
7345 _("Line:"), /* short label */
7346 _("Spacing between lines."), /* tooltip */
7347 "/tools/text/lineheight", /* path? */
7348 0.0, /* default */
7349 GTK_WIDGET(desktop->canvas), /* focusTarget */
7350 NULL, /* unit selector */
7351 holder, /* dataKludge */
7352 FALSE, /* altx? */
7353 NULL, /* altx_mark? */
7354 0.0, 10.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */
7355 labels, values, G_N_ELEMENTS(labels), /* drop down menu */
7356 sp_text_lineheight_value_changed, /* callback */
7357 0.1, /* step (used?) */
7358 2, /* digits to show */
7359 1.0 /* factor (multiplies default) */
7360 );
7361 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7362 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
7363 g_object_set_data( holder, "TextLineHeightAction", eact );
7364 }
7366 /* Word spacing */
7367 {
7368 // Drop down menu
7369 gchar const* labels[] = {_("Negative spacing"), 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, 0, 0, _("Positive spacing")};
7370 gdouble values[] = {-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0};
7372 EgeAdjustmentAction *eact = create_adjustment_action(
7373 "TextWordSpacingAction", /* name */
7374 _("Word spacing"), /* label */
7375 _("Word:"), /* short label */
7376 _("Spacing between words."), /* tooltip */
7377 "/tools/text/wordspacing", /* path? */
7378 0.0, /* default */
7379 GTK_WIDGET(desktop->canvas), /* focusTarget */
7380 NULL, /* unit selector */
7381 holder, /* dataKludge */
7382 FALSE, /* altx? */
7383 NULL, /* altx_mark? */
7384 -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */
7385 labels, values, G_N_ELEMENTS(labels), /* drop down menu */
7386 sp_text_wordspacing_value_changed, /* callback */
7387 0.1, /* step (used?) */
7388 2, /* digits to show */
7389 1.0 /* factor (multiplies default) */
7390 );
7391 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7392 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
7393 g_object_set_data( holder, "TextWordSpacingAction", eact );
7394 }
7396 /* Letter spacing */
7397 {
7398 // Drop down menu
7399 gchar const* labels[] = {_("Negative spacing"), 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, 0, 0, _("Positive spacing")};
7400 gdouble values[] = {-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0};
7402 EgeAdjustmentAction *eact = create_adjustment_action(
7403 "TextLetterSpacingAction", /* name */
7404 _("Letter spacing"), /* label */
7405 _("Letter:"), /* short label */
7406 _("Spacing between letters."), /* tooltip */
7407 "/tools/text/letterspacing", /* path? */
7408 0.0, /* default */
7409 GTK_WIDGET(desktop->canvas), /* focusTarget */
7410 NULL, /* unit selector */
7411 holder, /* dataKludge */
7412 FALSE, /* altx? */
7413 NULL, /* altx_mark? */
7414 -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */
7415 labels, values, G_N_ELEMENTS(labels), /* drop down menu */
7416 sp_text_letterspacing_value_changed, /* callback */
7417 0.1, /* step (used?) */
7418 2, /* digits to show */
7419 1.0 /* factor (multiplies default) */
7420 );
7421 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7422 gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
7423 g_object_set_data( holder, "TextLetterSpacingAction", eact );
7424 }
7426 // Is this necessary to call? Shouldn't hurt.
7427 sp_text_toolbox_selection_changed(sp_desktop_selection(desktop), holder);
7429 // Watch selection
7430 Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISTextToolboxGTK");
7432 sigc::connection *c_selection_changed =
7433 new sigc::connection (sp_desktop_selection (desktop)->connectChanged
7434 (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)holder)));
7435 pool->add_connection ("selection-changed", c_selection_changed);
7437 sigc::connection *c_selection_modified =
7438 new sigc::connection (sp_desktop_selection (desktop)->connectModified
7439 (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)holder)));
7440 pool->add_connection ("selection-modified", c_selection_modified);
7442 sigc::connection *c_subselection_changed =
7443 new sigc::connection (desktop->connectToolSubselectionChanged
7444 (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)holder)));
7445 pool->add_connection ("tool-subselection-changed", c_subselection_changed);
7447 Inkscape::ConnectionPool::connect_destroy (G_OBJECT (holder), pool);
7449 g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
7451 }
7454 //#########################
7455 //## Connector ##
7456 //#########################
7458 static void sp_connector_mode_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ )
7459 {
7460 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7461 prefs->setBool("/tools/connector/mode",
7462 gtk_toggle_action_get_active( act ));
7463 }
7465 static void sp_connector_path_set_avoid(void)
7466 {
7467 cc_selection_set_avoid(true);
7468 }
7471 static void sp_connector_path_set_ignore(void)
7472 {
7473 cc_selection_set_avoid(false);
7474 }
7476 static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl )
7477 {
7478 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
7479 Inkscape::Selection * selection = sp_desktop_selection(desktop);
7480 SPDocument *doc = sp_desktop_document(desktop);
7482 if (!sp_document_get_undo_sensitive(doc)) {
7483 return;
7484 }
7487 // quit if run by the _changed callbacks
7488 if (g_object_get_data( tbl, "freeze" )) {
7489 return;
7490 }
7492 // in turn, prevent callbacks from responding
7493 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
7495 bool is_orthog = gtk_toggle_action_get_active( act );
7496 gchar orthog_str[] = "orthogonal";
7497 gchar polyline_str[] = "polyline";
7498 gchar *value = is_orthog ? orthog_str : polyline_str ;
7500 bool modmade = false;
7501 GSList *l = (GSList *) selection->itemList();
7502 while (l) {
7503 SPItem *item = (SPItem *) l->data;
7505 if (cc_item_is_connector(item)) {
7506 sp_object_setAttribute(item, "inkscape:connector-type",
7507 value, false);
7508 item->avoidRef->handleSettingChange();
7509 modmade = true;
7510 }
7511 l = l->next;
7512 }
7514 if (!modmade) {
7515 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7516 prefs->setBool("/tools/connector/orthogonal", is_orthog);
7517 }
7519 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
7520 is_orthog ? _("Set connector type: orthogonal"): _("Set connector type: polyline"));
7522 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
7523 }
7525 static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl)
7526 {
7527 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
7528 Inkscape::Selection * selection = sp_desktop_selection(desktop);
7529 SPDocument *doc = sp_desktop_document(desktop);
7531 if (!sp_document_get_undo_sensitive(doc)) {
7532 return;
7533 }
7536 // quit if run by the _changed callbacks
7537 if (g_object_get_data( tbl, "freeze" )) {
7538 return;
7539 }
7541 // in turn, prevent callbacks from responding
7542 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
7544 gdouble newValue = gtk_adjustment_get_value(adj);
7545 gchar value[G_ASCII_DTOSTR_BUF_SIZE];
7546 g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue);
7548 bool modmade = false;
7549 GSList *l = (GSList *) selection->itemList();
7550 while (l) {
7551 SPItem *item = (SPItem *) l->data;
7553 if (cc_item_is_connector(item)) {
7554 sp_object_setAttribute(item, "inkscape:connector-curvature",
7555 value, false);
7556 item->avoidRef->handleSettingChange();
7557 modmade = true;
7558 }
7559 l = l->next;
7560 }
7562 if (!modmade) {
7563 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7564 prefs->setDouble(Glib::ustring("/tools/connector/curvature"), newValue);
7565 }
7567 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
7568 _("Change connector curvature"));
7570 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
7571 }
7574 static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl)
7575 {
7576 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
7577 SPDocument *doc = sp_desktop_document(desktop);
7579 if (!sp_document_get_undo_sensitive(doc)) {
7580 return;
7581 }
7583 Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview);
7585 if ( !repr->attribute("inkscape:connector-spacing") &&
7586 ( adj->value == defaultConnSpacing )) {
7587 // Don't need to update the repr if the attribute doesn't
7588 // exist and it is being set to the default value -- as will
7589 // happen at startup.
7590 return;
7591 }
7593 // quit if run by the attr_changed listener
7594 if (g_object_get_data( tbl, "freeze" )) {
7595 return;
7596 }
7598 // in turn, prevent listener from responding
7599 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
7601 sp_repr_set_css_double(repr, "inkscape:connector-spacing", adj->value);
7602 SP_OBJECT(desktop->namedview)->updateRepr();
7604 GSList *items = get_avoided_items(NULL, desktop->currentRoot(), desktop);
7605 for ( GSList const *iter = items ; iter != NULL ; iter = iter->next ) {
7606 SPItem *item = reinterpret_cast<SPItem *>(iter->data);
7607 Geom::Matrix m = Geom::identity();
7608 avoid_item_move(&m, item);
7609 }
7611 if (items) {
7612 g_slist_free(items);
7613 }
7615 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
7616 _("Change connector spacing"));
7618 g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
7619 }
7621 static void sp_connector_graph_layout(void)
7622 {
7623 if (!SP_ACTIVE_DESKTOP) {
7624 return;
7625 }
7626 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7628 // hack for clones, see comment in align-and-distribute.cpp
7629 int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
7630 prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
7632 graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
7634 prefs->setInt("/options/clonecompensation/value", saved_compensation);
7636 sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network"));
7637 }
7639 static void sp_directed_graph_layout_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ )
7640 {
7641 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7642 prefs->setBool("/tools/connector/directedlayout",
7643 gtk_toggle_action_get_active( act ));
7644 }
7646 static void sp_nooverlaps_graph_layout_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ )
7647 {
7648 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7649 prefs->setBool("/tools/connector/avoidoverlaplayout",
7650 gtk_toggle_action_get_active( act ));
7651 }
7654 static void connector_length_changed(GtkAdjustment *adj, GObject* /*tbl*/)
7655 {
7656 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7657 prefs->setDouble("/tools/connector/length", adj->value);
7658 }
7660 static void connector_tb_event_attr_changed(Inkscape::XML::Node *repr,
7661 gchar const *name, gchar const * /*old_value*/, gchar const * /*new_value*/,
7662 bool /*is_interactive*/, gpointer data)
7663 {
7664 GtkWidget *tbl = GTK_WIDGET(data);
7666 if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
7667 return;
7668 }
7669 if (strcmp(name, "inkscape:connector-spacing") == 0)
7670 {
7671 GtkAdjustment *adj = (GtkAdjustment*)
7672 gtk_object_get_data(GTK_OBJECT(tbl), "spacing");
7673 gdouble spacing = defaultConnSpacing;
7674 sp_repr_get_double(repr, "inkscape:connector-spacing", &spacing);
7676 gtk_adjustment_set_value(adj, spacing);
7677 gtk_adjustment_value_changed(adj);
7678 }
7680 spinbutton_defocus(GTK_OBJECT(tbl));
7681 }
7683 static void sp_connector_new_connection_point(GtkWidget *, GObject *tbl)
7684 {
7685 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
7686 SPConnectorContext* cc = SP_CONNECTOR_CONTEXT(desktop->event_context);
7688 if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) {
7689 cc_create_connection_point(cc);
7690 }
7691 }
7693 static void sp_connector_remove_connection_point(GtkWidget *, GObject *tbl)
7694 {
7695 SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" );
7696 SPConnectorContext* cc = SP_CONNECTOR_CONTEXT(desktop->event_context);
7698 if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) {
7699 cc_remove_connection_point(cc);
7700 }
7701 }
7703 static Inkscape::XML::NodeEventVector connector_tb_repr_events = {
7704 NULL, /* child_added */
7705 NULL, /* child_removed */
7706 connector_tb_event_attr_changed,
7707 NULL, /* content_changed */
7708 NULL /* order_changed */
7709 };
7711 static void sp_connector_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
7712 {
7713 GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "curvature" ) );
7714 GtkToggleAction *act = GTK_TOGGLE_ACTION( g_object_get_data( tbl, "orthogonal" ) );
7715 SPItem *item = selection->singleItem();
7716 if (SP_IS_PATH(item))
7717 {
7718 gdouble curvature = SP_PATH(item)->connEndPair.getCurvature();
7719 bool is_orthog = SP_PATH(item)->connEndPair.isOrthogonal();
7720 gtk_toggle_action_set_active(act, is_orthog);
7721 gtk_adjustment_set_value(adj, curvature);
7722 }
7724 }
7726 static void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder )
7727 {
7728 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7729 Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
7731 // Editing mode toggle button
7732 {
7733 InkToggleAction* act = ink_toggle_action_new( "ConnectorEditModeAction",
7734 _("EditMode"),
7735 _("Switch between connection point editing and connector drawing mode"),
7736 INKSCAPE_ICON_CONNECTOR_EDIT,
7737 Inkscape::ICON_SIZE_DECORATION );
7738 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7740 bool tbuttonstate = prefs->getBool("/tools/connector/mode");
7741 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), ( tbuttonstate ? TRUE : FALSE ));
7742 g_object_set_data( holder, "mode", act );
7743 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_connector_mode_toggled), holder );
7744 }
7747 {
7748 InkAction* inky = ink_action_new( "ConnectorAvoidAction",
7749 _("Avoid"),
7750 _("Make connectors avoid selected objects"),
7751 INKSCAPE_ICON_CONNECTOR_AVOID,
7752 secondarySize );
7753 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_path_set_avoid), holder );
7754 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
7755 }
7757 {
7758 InkAction* inky = ink_action_new( "ConnectorIgnoreAction",
7759 _("Ignore"),
7760 _("Make connectors ignore selected objects"),
7761 INKSCAPE_ICON_CONNECTOR_IGNORE,
7762 secondarySize );
7763 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_path_set_ignore), holder );
7764 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
7765 }
7767 // Orthogonal connectors toggle button
7768 {
7769 InkToggleAction* act = ink_toggle_action_new( "ConnectorOrthogonalAction",
7770 _("Orthogonal"),
7771 _("Make connector orthogonal or polyline"),
7772 INKSCAPE_ICON_CONNECTOR_ORTHOGONAL,
7773 Inkscape::ICON_SIZE_DECORATION );
7774 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7776 bool tbuttonstate = prefs->getBool("/tools/connector/orthogonal");
7777 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), ( tbuttonstate ? TRUE : FALSE ));
7778 g_object_set_data( holder, "orthogonal", act );
7779 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_connector_orthogonal_toggled), holder );
7780 }
7782 EgeAdjustmentAction* eact = 0;
7783 // Curvature spinbox
7784 eact = create_adjustment_action( "ConnectorCurvatureAction",
7785 _("Connector Curvature"), _("Curvature:"),
7786 _("The amount of connectors curvature"),
7787 "/tools/connector/curvature", defaultConnCurvature,
7788 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-curvature",
7789 0, 100, 1.0, 10.0,
7790 0, 0, 0,
7791 connector_curvature_changed, 1, 0 );
7792 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7794 // Spacing spinbox
7795 eact = create_adjustment_action( "ConnectorSpacingAction",
7796 _("Connector Spacing"), _("Spacing:"),
7797 _("The amount of space left around objects by auto-routing connectors"),
7798 "/tools/connector/spacing", defaultConnSpacing,
7799 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-spacing",
7800 0, 100, 1.0, 10.0,
7801 0, 0, 0,
7802 connector_spacing_changed, 1, 0 );
7803 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7805 // Graph (connector network) layout
7806 {
7807 InkAction* inky = ink_action_new( "ConnectorGraphAction",
7808 _("Graph"),
7809 _("Nicely arrange selected connector network"),
7810 INKSCAPE_ICON_DISTRIBUTE_GRAPH,
7811 secondarySize );
7812 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_graph_layout), holder );
7813 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
7814 }
7816 // Default connector length spinbox
7817 eact = create_adjustment_action( "ConnectorLengthAction",
7818 _("Connector Length"), _("Length:"),
7819 _("Ideal length for connectors when layout is applied"),
7820 "/tools/connector/length", 100,
7821 GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-length",
7822 10, 1000, 10.0, 100.0,
7823 0, 0, 0,
7824 connector_length_changed, 1, 0 );
7825 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7828 // Directed edges toggle button
7829 {
7830 InkToggleAction* act = ink_toggle_action_new( "ConnectorDirectedAction",
7831 _("Downwards"),
7832 _("Make connectors with end-markers (arrows) point downwards"),
7833 INKSCAPE_ICON_DISTRIBUTE_GRAPH_DIRECTED,
7834 Inkscape::ICON_SIZE_DECORATION );
7835 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7837 bool tbuttonstate = prefs->getBool("/tools/connector/directedlayout");
7838 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), ( tbuttonstate ? TRUE : FALSE ));
7840 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_directed_graph_layout_toggled), holder );
7841 sp_desktop_selection(desktop)->connectChanged(sigc::bind(sigc::ptr_fun(sp_connector_toolbox_selection_changed), (GObject *)holder));
7842 }
7844 // Avoid overlaps toggle button
7845 {
7846 InkToggleAction* act = ink_toggle_action_new( "ConnectorOverlapAction",
7847 _("Remove overlaps"),
7848 _("Do not allow overlapping shapes"),
7849 INKSCAPE_ICON_DISTRIBUTE_REMOVE_OVERLAPS,
7850 Inkscape::ICON_SIZE_DECORATION );
7851 gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
7853 bool tbuttonstate = prefs->getBool("/tools/connector/avoidoverlaplayout");
7854 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), (tbuttonstate ? TRUE : FALSE ));
7856 g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_nooverlaps_graph_layout_toggled), holder );
7857 }
7860 // New connection point button
7861 {
7862 InkAction* inky = ink_action_new( "ConnectorNewConnPointAction",
7863 _("New connection point"),
7864 _("Add a new connection point to the currently selected item"),
7865 INKSCAPE_ICON_CONNECTOR_NEW_CONNPOINT,
7866 secondarySize );
7867 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_new_connection_point), holder );
7868 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
7869 }
7871 // Remove selected connection point button
7873 {
7874 InkAction* inky = ink_action_new( "ConnectorRemoveConnPointAction",
7875 _("Remove connection point"),
7876 _("Remove the currently selected connection point"),
7877 INKSCAPE_ICON_CONNECTOR_REMOVE_CONNPOINT,
7878 secondarySize );
7879 g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_connector_remove_connection_point), holder );
7880 gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
7881 }
7884 // Code to watch for changes to the connector-spacing attribute in
7885 // the XML.
7886 Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview);
7887 g_assert(repr != NULL);
7889 purge_repr_listener( holder, holder );
7891 if (repr) {
7892 g_object_set_data( holder, "repr", repr );
7893 Inkscape::GC::anchor(repr);
7894 sp_repr_add_listener( repr, &connector_tb_repr_events, holder );
7895 sp_repr_synthesize_events( repr, &connector_tb_repr_events, holder );
7896 }
7897 } // end of sp_connector_toolbox_prep()
7900 //#########################
7901 //## Paintbucket ##
7902 //#########################
7904 static void paintbucket_channels_changed(EgeSelectOneAction* act, GObject* /*tbl*/)
7905 {
7906 gint channels = ege_select_one_action_get_active( act );
7907 flood_channels_set_channels( channels );
7908 }
7910 static void paintbucket_threshold_changed(GtkAdjustment *adj, GObject * /*tbl*/)
7911 {
7912 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7913 prefs->setInt("/tools/paintbucket/threshold", (gint)adj->value);
7914 }
7916 static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl*/)
7917 {
7918 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7919 prefs->setBool("/tools/paintbucket/autogap", ege_select_one_action_get_active( act ));
7920 }
7922 static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl)
7923 {
7924 UnitTracker* tracker = static_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
7925 SPUnit const *unit = tracker->getActiveUnit();
7926 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7928 prefs->setDouble("/tools/paintbucket/offset", (gdouble)sp_units_get_pixels(adj->value, *unit));
7929 prefs->setString("/tools/paintbucket/offsetunits", sp_unit_get_abbreviation(unit));
7930 }
7932 static void paintbucket_defaults(GtkWidget *, GObject *tbl)
7933 {
7934 // FIXME: make defaults settable via Inkscape Options
7935 struct KeyValue {
7936 char const *key;
7937 double value;
7938 } const key_values[] = {
7939 {"threshold", 15},
7940 {"offset", 0.0}
7941 };
7943 for (unsigned i = 0; i < G_N_ELEMENTS(key_values); ++i) {
7944 KeyValue const &kv = key_values[i];
7945 GtkAdjustment* adj = static_cast<GtkAdjustment *>(g_object_get_data(tbl, kv.key));
7946 if ( adj ) {
7947 gtk_adjustment_set_value(adj, kv.value);
7948 }
7949 }
7951 EgeSelectOneAction* channels_action = EGE_SELECT_ONE_ACTION( g_object_get_data (tbl, "channels_action" ) );
7952 ege_select_one_action_set_active( channels_action, FLOOD_CHANNELS_RGB );
7953 EgeSelectOneAction* autogap_action = EGE_SELECT_ONE_ACTION( g_object_get_data (tbl, "autogap_action" ) );
7954 ege_select_one_action_set_active( autogap_action, 0 );
7955 }
7957 static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
7958 {
7959 EgeAdjustmentAction* eact = 0;
7960 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7962 {
7963 GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
7965 GList* items = 0;
7966 gint count = 0;
7967 for ( items = flood_channels_dropdown_items_list(); items ; items = g_list_next(items) )
7968 {
7969 GtkTreeIter iter;
7970 gtk_list_store_append( model, &iter );
7971 gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
7972 count++;
7973 }
7974 g_list_free( items );
7975 items = 0;
7976 EgeSelectOneAction* act1 = ege_select_one_action_new( "ChannelsAction", _("Fill by"), (""), NULL, GTK_TREE_MODEL(model) );
7977 g_object_set( act1, "short_label", _("Fill by:"), NULL );
7978 ege_select_one_action_set_appearance( act1, "compact" );
7979 ege_select_one_action_set_active( act1, prefs->getInt("/tools/paintbucket/channels", 0) );
7980 g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(paintbucket_channels_changed), holder );
7981 gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
7982 g_object_set_data( holder, "channels_action", act1 );
7983 }
7985 // Spacing spinbox
7986 {
7987 eact = create_adjustment_action(
7988 "ThresholdAction",
7989 _("Fill Threshold"), _("Threshold:"),
7990 _("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"),
7991 "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), NULL, holder, TRUE,
7992 "inkscape:paintbucket-threshold", 0, 100.0, 1.0, 10.0,
7993 0, 0, 0,
7994 paintbucket_threshold_changed, 1, 0 );
7996 ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
7997 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
7998 }
8000 // Create the units menu.
8001 UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
8002 Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits");
8003 if (!stored_unit.empty()) {
8004 tracker->setActiveUnit(sp_unit_get_by_abbreviation(stored_unit.data()));
8005 }
8006 g_object_set_data( holder, "tracker", tracker );
8007 {
8008 GtkAction* act = tracker->createAction( "PaintbucketUnitsAction", _("Units"), ("") );
8009 gtk_action_group_add_action( mainActions, act );
8010 }
8012 // Offset spinbox
8013 {
8014 eact = create_adjustment_action(
8015 "OffsetAction",
8016 _("Grow/shrink by"), _("Grow/shrink by:"),
8017 _("The amount to grow (positive) or shrink (negative) the created fill path"),
8018 "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE,
8019 "inkscape:paintbucket-offset", -1e6, 1e6, 0.1, 0.5,
8020 0, 0, 0,
8021 paintbucket_offset_changed, 1, 2);
8022 tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
8024 gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
8025 }
8027 /* Auto Gap */
8028 {
8029 GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
8031 GList* items = 0;
8032 gint count = 0;
8033 for ( items = flood_autogap_dropdown_items_list(); items ; items = g_list_next(items) )
8034 {
8035 GtkTreeIter iter;
8036 gtk_list_store_append( model, &iter );
8037 gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
8038 count++;
8039 }
8040 g_list_free( items );
8041 items = 0;
8042 EgeSelectOneAction* act2 = ege_select_one_action_new( "AutoGapAction", _("Close gaps"), (""), NULL, GTK_TREE_MODEL(model) );
8043 g_object_set( act2, "short_label", _("Close gaps:"), NULL );
8044 ege_select_one_action_set_appearance( act2, "compact" );
8045 ege_select_one_action_set_active( act2, prefs->getBool("/tools/paintbucket/autogap") );
8046 g_signal_connect( G_OBJECT(act2), "changed", G_CALLBACK(paintbucket_autogap_changed), holder );
8047 gtk_action_group_add_action( mainActions, GTK_ACTION(act2) );
8048 g_object_set_data( holder, "autogap_action", act2 );
8049 }
8051 /* Reset */
8052 {
8053 GtkAction* act = gtk_action_new( "PaintbucketResetAction",
8054 _("Defaults"),
8055 _("Reset paint bucket parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
8056 GTK_STOCK_CLEAR );
8057 g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(paintbucket_defaults), holder );
8058 gtk_action_group_add_action( mainActions, act );
8059 gtk_action_set_sensitive( act, TRUE );
8060 }
8062 }
8064 /*
8065 Local Variables:
8066 mode:c++
8067 c-file-style:"stroustrup"
8068 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
8069 indent-tabs-mode:nil
8070 fill-column:99
8071 End:
8072 */
8073 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :