1 /** @file
2 * @brief Stroke style dialog
3 */
4 /* Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * Bryce Harrington <brycehar@bryceharrington.org>
7 * bulia byak <buliabyak@users.sf.net>
8 * Maximilian Albert <maximilian.albert@gmail.com>
9 * Josh Andler <scislac@users.sf.net>
10 *
11 * Copyright (C) 2001-2005 authors
12 * Copyright (C) 2001 Ximian, Inc.
13 * Copyright (C) 2004 John Cliff
14 * Copyright (C) 2008 Maximilian Albert (gtkmm-ification)
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #define noSP_SS_VERBOSE
21 #include <glib/gmem.h>
22 #include <gtk/gtk.h>
23 #include <glibmm/i18n.h>
25 #include "desktop-handles.h"
26 #include "desktop-style.h"
27 #include "dialogs/dialog-events.h"
28 #include "display/nr-arena.h"
29 #include "display/nr-arena-item.h"
30 #include "document-private.h"
31 #include "gradient-chemistry.h"
32 #include "helper/stock-items.h"
33 #include "helper/unit-menu.h"
34 #include "helper/units.h"
35 #include "inkscape.h"
36 #include "io/sys.h"
37 #include "marker.h"
38 #include "path-prefix.h"
39 #include "selection.h"
40 #include "sp-linear-gradient.h"
41 #include "sp-namedview.h"
42 #include "sp-pattern.h"
43 #include "sp-radial-gradient.h"
44 #include "sp-rect.h"
45 #include "sp-text.h"
46 #include "style.h"
47 #include "svg/css-ostringstream.h"
48 #include "ui/cache/svg_preview_cache.h"
49 #include "ui/icon-names.h"
50 #include "widgets/dash-selector.h"
51 #include "widgets/icon.h"
52 #include "widgets/paint-selector.h"
53 #include "widgets/sp-widget.h"
54 #include "widgets/spw-utilities.h"
55 #include "xml/repr.h"
57 #include "widgets/stroke-style.h"
60 /* Paint */
62 static void sp_stroke_style_paint_selection_modified (SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel);
63 static void sp_stroke_style_paint_selection_changed (SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel);
64 static void sp_stroke_style_paint_update(SPWidget *spw);
66 static void sp_stroke_style_paint_mode_changed(SPPaintSelector *psel, SPPaintSelectorMode mode, SPWidget *spw);
67 static void sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw);
68 static void sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw);
70 static void sp_stroke_style_widget_change_subselection ( Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw );
71 static void sp_stroke_style_widget_transientize_callback(Inkscape::Application *inkscape,
72 SPDesktop *desktop,
73 SPWidget *spw );
75 /** Marker selection option menus */
76 static Gtk::OptionMenu * marker_start_menu = NULL;
77 static Gtk::OptionMenu * marker_mid_menu = NULL;
78 static Gtk::OptionMenu * marker_end_menu = NULL;
80 sigc::connection marker_start_menu_connection;
81 sigc::connection marker_mid_menu_connection;
82 sigc::connection marker_end_menu_connection;
84 static SPObject *ink_extract_marker_name(gchar const *n, SPDocument *doc);
85 static void ink_markers_menu_update(Gtk::Container* spw, SPMarkerLoc const which);
87 static Inkscape::UI::Cache::SvgPreview svg_preview_cache;
89 /**
90 * Create the stroke style widget, and hook up all the signals.
91 */
92 GtkWidget *
93 sp_stroke_style_paint_widget_new(void)
94 {
95 GtkWidget *spw, *psel;
97 spw = sp_widget_new_global(INKSCAPE);
99 psel = sp_paint_selector_new(false); // without fillrule selector
100 gtk_widget_show(psel);
101 gtk_container_add(GTK_CONTAINER(spw), psel);
102 gtk_object_set_data(GTK_OBJECT(spw), "paint-selector", psel);
104 gtk_signal_connect(GTK_OBJECT(spw), "modify_selection",
105 GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_modified),
106 psel);
107 gtk_signal_connect(GTK_OBJECT(spw), "change_selection",
108 GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_changed),
109 psel);
111 g_signal_connect (INKSCAPE, "change_subselection", G_CALLBACK (sp_stroke_style_widget_change_subselection), spw);
113 g_signal_connect (G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK (sp_stroke_style_widget_transientize_callback), spw );
115 gtk_signal_connect(GTK_OBJECT(psel), "mode_changed",
116 GTK_SIGNAL_FUNC(sp_stroke_style_paint_mode_changed),
117 spw);
118 gtk_signal_connect(GTK_OBJECT(psel), "dragged",
119 GTK_SIGNAL_FUNC(sp_stroke_style_paint_dragged),
120 spw);
121 gtk_signal_connect(GTK_OBJECT(psel), "changed",
122 GTK_SIGNAL_FUNC(sp_stroke_style_paint_changed),
123 spw);
125 sp_stroke_style_paint_update (SP_WIDGET(spw));
126 return spw;
127 }
129 /**
130 * On signal modified, invokes an update of the stroke style paint object.
131 */
132 static void
133 sp_stroke_style_paint_selection_modified( SPWidget *spw,
134 Inkscape::Selection */*selection*/,
135 guint flags,
136 SPPaintSelector */*psel*/ )
137 {
138 if (flags & ( SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG |
139 SP_OBJECT_STYLE_MODIFIED_FLAG) ) {
140 sp_stroke_style_paint_update(spw);
141 }
142 }
145 /**
146 * On signal selection changed, invokes an update of the stroke style paint object.
147 */
148 static void
149 sp_stroke_style_paint_selection_changed( SPWidget *spw,
150 Inkscape::Selection */*selection*/,
151 SPPaintSelector */*psel*/ )
152 {
153 sp_stroke_style_paint_update (spw);
154 }
157 /**
158 * On signal change subselection, invoke an update of the stroke style widget.
159 */
160 static void
161 sp_stroke_style_widget_change_subselection( Inkscape::Application */*inkscape*/,
162 SPDesktop */*desktop*/,
163 SPWidget *spw )
164 {
165 sp_stroke_style_paint_update (spw);
166 }
168 /**
169 * Gets the active stroke style property, then sets the appropriate color, alpha, gradient,
170 * pattern, etc. for the paint-selector.
171 */
172 static void
173 sp_stroke_style_paint_update (SPWidget *spw)
174 {
175 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
176 return;
177 }
179 gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
181 SPPaintSelector *psel = SP_PAINT_SELECTOR(gtk_object_get_data(GTK_OBJECT(spw), "paint-selector"));
183 // create temporary style
184 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
185 // query into it
186 int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKE);
188 switch (result) {
189 case QUERY_STYLE_NOTHING:
190 {
191 /* No paint at all */
192 sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_EMPTY);
193 break;
194 }
196 case QUERY_STYLE_SINGLE:
197 case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector
198 case QUERY_STYLE_MULTIPLE_SAME:
199 {
200 SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, false);
201 sp_paint_selector_set_mode (psel, pselmode);
203 if (query->stroke.set && query->stroke.isPaintserver()) {
205 SPPaintServer *server = SP_STYLE_STROKE_SERVER (query);
207 if (server && server->isSwatch()) {
208 sp_paint_selector_set_swatch( psel, server );
209 } else if (SP_IS_LINEARGRADIENT (server)) {
210 SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
211 sp_paint_selector_set_gradient_linear (psel, vector);
213 SPLinearGradient *lg = SP_LINEARGRADIENT (server);
214 sp_paint_selector_set_gradient_properties (psel,
215 SP_GRADIENT_UNITS (lg),
216 SP_GRADIENT_SPREAD (lg));
217 } else if (SP_IS_RADIALGRADIENT (server)) {
218 SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
219 sp_paint_selector_set_gradient_radial (psel, vector);
221 SPRadialGradient *rg = SP_RADIALGRADIENT (server);
222 sp_paint_selector_set_gradient_properties (psel,
223 SP_GRADIENT_UNITS (rg),
224 SP_GRADIENT_SPREAD (rg));
225 } else if (SP_IS_PATTERN (server)) {
226 SPPattern *pat = pattern_getroot (SP_PATTERN (server));
227 sp_update_pattern_list (psel, pat);
228 }
229 } else if (query->stroke.set && query->stroke.isColor()) {
230 sp_paint_selector_set_color_alpha (psel, &query->stroke.value.color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value));
232 }
233 break;
234 }
236 case QUERY_STYLE_MULTIPLE_DIFFERENT:
237 {
238 sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_MULTIPLE);
239 break;
240 }
241 }
243 sp_style_unref(query);
245 gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
246 }
248 /**
249 * When the mode is changed, invoke a regular changed handler.
250 */
251 static void
252 sp_stroke_style_paint_mode_changed( SPPaintSelector *psel,
253 SPPaintSelectorMode /*mode*/,
254 SPWidget *spw )
255 {
256 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
257 return;
258 }
260 /* TODO: Does this work?
261 * Not really, here we have to get old color back from object
262 * Instead of relying on paint widget having meaningful colors set
263 */
264 sp_stroke_style_paint_changed(psel, spw);
265 }
267 static gchar const *const undo_label_1 = "stroke:flatcolor:1";
268 static gchar const *const undo_label_2 = "stroke:flatcolor:2";
269 static gchar const *undo_label = undo_label_1;
271 /**
272 * When a drag callback occurs on a paint selector object, if it is a RGB or CMYK
273 * color mode, then set the stroke opacity to psel's flat color.
274 */
275 static void
276 sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw)
277 {
278 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
279 return;
280 }
282 switch (psel->mode) {
283 case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
284 case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
285 {
286 sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity");
287 sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE,
288 _("Set stroke color"));
289 break;
290 }
292 default:
293 g_warning( "file %s: line %d: Paint %d should not emit 'dragged'",
294 __FILE__, __LINE__, psel->mode);
295 break;
296 }
297 }
299 /**
300 * When the stroke style's paint settings change, this handler updates the
301 * repr's stroke css style and applies the style to relevant drawing items.
302 */
303 static void
304 sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw)
305 {
306 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
307 return;
308 }
309 g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE));
311 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
312 SPDocument *document = sp_desktop_document (desktop);
313 Inkscape::Selection *selection = sp_desktop_selection (desktop);
315 GSList const *items = selection->itemList();
317 switch (psel->mode) {
318 case SP_PAINT_SELECTOR_MODE_EMPTY:
319 // This should not happen.
320 g_warning ( "file %s: line %d: Paint %d should not emit 'changed'",
321 __FILE__, __LINE__, psel->mode);
322 break;
323 case SP_PAINT_SELECTOR_MODE_MULTIPLE:
324 // This happens when you switch multiple objects with different gradients to flat color;
325 // nothing to do here.
326 break;
328 case SP_PAINT_SELECTOR_MODE_NONE:
329 {
330 SPCSSAttr *css = sp_repr_css_attr_new();
331 sp_repr_css_set_property(css, "stroke", "none");
333 sp_desktop_set_style (desktop, css);
335 sp_repr_css_attr_unref(css);
337 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
338 _("Remove stroke"));
339 break;
340 }
342 case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
343 case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
344 {
345 sp_paint_selector_set_flat_color (psel, desktop, "stroke", "stroke-opacity");
346 sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE,
347 _("Set stroke color"));
349 // on release, toggle undo_label so that the next drag will not be lumped with this one
350 if (undo_label == undo_label_1)
351 undo_label = undo_label_2;
352 else
353 undo_label = undo_label_1;
355 break;
356 }
358 case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR:
359 case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL:
360 if (items) {
361 SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR
362 ? SP_GRADIENT_TYPE_LINEAR
363 : SP_GRADIENT_TYPE_RADIAL );
364 SPGradient *vector = sp_paint_selector_get_gradient_vector(psel);
365 if (!vector) {
366 /* No vector in paint selector should mean that we just changed mode */
368 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
369 int result = objects_query_fillstroke ((GSList *) items, query, false);
370 guint32 common_rgb = 0;
371 if (result == QUERY_STYLE_MULTIPLE_SAME) {
372 if (!query->fill.isColor()) {
373 common_rgb = sp_desktop_get_color(desktop, false);
374 } else {
375 common_rgb = query->stroke.value.color.toRGBA32( 0xff );
376 }
377 vector = sp_document_default_gradient_vector(document, common_rgb);
378 }
379 sp_style_unref(query);
381 for (GSList const *i = items; i != NULL; i = i->next) {
382 if (!vector) {
383 sp_item_set_gradient(SP_ITEM(i->data),
384 sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), false),
385 gradient_type, false);
386 } else {
387 sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
388 }
389 }
390 } else {
391 vector = sp_gradient_ensure_vector_normalized(vector);
392 for (GSList const *i = items; i != NULL; i = i->next) {
393 SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
394 sp_gradient_selector_attrs_to_gradient(gr, psel);
395 }
396 }
398 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
399 _("Set gradient on stroke"));
400 }
401 break;
403 case SP_PAINT_SELECTOR_MODE_PATTERN:
405 if (items) {
407 SPPattern *pattern = sp_paint_selector_get_pattern (psel);
408 if (!pattern) {
410 /* No Pattern in paint selector should mean that we just
411 * changed mode - dont do jack.
412 */
414 } else {
415 Inkscape::XML::Node *patrepr = SP_OBJECT_REPR(pattern);
416 SPCSSAttr *css = sp_repr_css_attr_new ();
417 gchar *urltext = g_strdup_printf ("url(#%s)", patrepr->attribute("id"));
418 sp_repr_css_set_property (css, "stroke", urltext);
420 for (GSList const *i = items; i != NULL; i = i->next) {
421 Inkscape::XML::Node *selrepr = SP_OBJECT_REPR (i->data);
422 SPObject *selobj = SP_OBJECT (i->data);
423 if (!selrepr)
424 continue;
426 SPStyle *style = SP_OBJECT_STYLE (selobj);
427 if (style && style->stroke.isPaintserver()) {
428 SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (selobj);
429 if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern)
430 // only if this object's pattern is not rooted in our selected pattern, apply
431 continue;
432 }
434 sp_repr_css_change_recursive (selrepr, css, "style");
435 }
437 sp_repr_css_attr_unref (css);
438 g_free (urltext);
440 } // end if
442 sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
443 _("Set pattern on stroke"));
444 } // end if
446 break;
448 case SP_PAINT_SELECTOR_MODE_SWATCH:
449 // TODO
450 break;
452 case SP_PAINT_SELECTOR_MODE_UNSET:
453 if (items) {
454 SPCSSAttr *css = sp_repr_css_attr_new ();
455 sp_repr_css_unset_property (css, "stroke");
456 sp_repr_css_unset_property (css, "stroke-opacity");
457 sp_repr_css_unset_property (css, "stroke-width");
458 sp_repr_css_unset_property (css, "stroke-miterlimit");
459 sp_repr_css_unset_property (css, "stroke-linejoin");
460 sp_repr_css_unset_property (css, "stroke-linecap");
461 sp_repr_css_unset_property (css, "stroke-dashoffset");
462 sp_repr_css_unset_property (css, "stroke-dasharray");
464 sp_desktop_set_style (desktop, css);
465 sp_repr_css_attr_unref (css);
467 sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
468 _("Unset stroke"));
469 }
470 break;
472 default:
473 g_warning( "file %s: line %d: Paint selector should not be in "
474 "mode %d",
475 __FILE__, __LINE__,
476 psel->mode );
477 break;
478 }
480 g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE));
481 }
487 /* Line */
489 static void sp_stroke_style_line_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data);
490 static void sp_stroke_style_line_selection_changed(SPWidget *spw, Inkscape::Selection *selection, gpointer data);
492 static void sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel);
494 static void sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
496 static void sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
498 static void sp_stroke_style_width_changed(Gtk::Container *spw);
499 static void sp_stroke_style_miterlimit_changed(Gtk::Container *spw);
500 static void sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw);
501 static void sp_stroke_style_line_dash_changed(Gtk::Container *spw);
503 static void sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects);
506 /**
507 * Helper function for creating radio buttons. This should probably be re-thought out
508 * when reimplementing this with Gtkmm.
509 */
510 static Gtk::RadioButton *
511 sp_stroke_radio_button(Gtk::RadioButton *tb, char const *icon,
512 Gtk::HBox *hb, Gtk::Container *spw,
513 gchar const *key, gchar const *data)
514 {
515 g_assert(icon != NULL);
516 g_assert(hb != NULL);
517 g_assert(spw != NULL);
519 if (tb == NULL) {
520 tb = new Gtk::RadioButton();
521 } else {
522 Gtk::RadioButtonGroup grp = tb->get_group();
523 tb = new Gtk::RadioButton(grp);
524 }
526 tb->show();
527 tb->set_mode(false);
528 hb->pack_start(*tb, false, false, 0);
529 spw->set_data(icon, tb);
530 tb->set_data(key, (gpointer*)data);
531 tb->signal_toggled().connect(sigc::bind<Gtk::RadioButton *, Gtk::Container *>(
532 sigc::ptr_fun(&sp_stroke_style_any_toggled), tb, spw));
533 Gtk::Widget *px = manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon)));
534 g_assert(px != NULL);
535 px->show();
536 tb->add(*px);
538 return tb;
540 }
542 static void
543 sp_stroke_style_widget_transientize_callback(Inkscape::Application */*inkscape*/,
544 SPDesktop */*desktop*/,
545 SPWidget */*spw*/ )
546 {
547 // TODO: Either of these will cause crashes sometimes
548 // sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
549 // ink_markers_menu_update(spw);
550 }
552 /**
553 * Creates a copy of the marker named mname, determines its visible and renderable
554 * area in menu_id's bounding box, and then renders it. This allows us to fill in
555 * preview images of each marker in the marker menu.
556 */
557 static Gtk::Image *
558 sp_marker_prev_new(unsigned psize, gchar const *mname,
559 SPDocument *source, SPDocument *sandbox,
560 gchar const *menu_id, NRArena const */*arena*/, unsigned /*visionkey*/, NRArenaItem *root)
561 {
562 // Retrieve the marker named 'mname' from the source SVG document
563 SPObject const *marker = source->getObjectById(mname);
564 if (marker == NULL)
565 return NULL;
567 // Create a copy repr of the marker with id="sample"
568 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sandbox);
569 Inkscape::XML::Node *mrepr = SP_OBJECT_REPR (marker)->duplicate(xml_doc);
570 mrepr->setAttribute("id", "sample");
572 // Replace the old sample in the sandbox by the new one
573 Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (sandbox->getObjectById("defs"));
574 SPObject *oldmarker = sandbox->getObjectById("sample");
575 if (oldmarker)
576 oldmarker->deleteObject(false);
577 defsrepr->appendChild(mrepr);
578 Inkscape::GC::release(mrepr);
580 // Uncomment this to get the sandbox documents saved (useful for debugging)
581 //FILE *fp = fopen (g_strconcat(menu_id, mname, ".svg", NULL), "w");
582 //sp_repr_save_stream (sp_document_repr_doc (sandbox), fp);
583 //fclose (fp);
585 // object to render; note that the id is the same as that of the menu we're building
586 SPObject *object = sandbox->getObjectById(menu_id);
587 sp_document_root (sandbox)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
588 sp_document_ensure_up_to_date(sandbox);
590 if (object == NULL || !SP_IS_ITEM(object))
591 return NULL; // sandbox broken?
593 // Find object's bbox in document
594 Geom::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
595 Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc);
597 if (!dbox) {
598 return NULL;
599 }
601 /* Update to renderable state */
602 double sf = 0.8;
604 gchar *cache_name = g_strconcat(menu_id, mname, NULL);
605 Glib::ustring key = svg_preview_cache.cache_key(source->uri, cache_name, psize);
606 g_free (cache_name);
607 // TODO: is this correct?
608 Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(svg_preview_cache.get_preview_from_cache(key));
610 if (!pixbuf) {
611 pixbuf = Glib::wrap(render_pixbuf(root, sf, *dbox, psize));
612 svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj());
613 }
615 // Create widget
616 Gtk::Image *pb = new Gtk::Image(pixbuf);
618 return pb;
619 }
621 /**
622 * Returns a list of markers in the defs of the given source document as a GSList object
623 * Returns NULL if there are no markers in the document.
624 */
625 GSList *
626 ink_marker_list_get (SPDocument *source)
627 {
628 if (source == NULL)
629 return NULL;
631 GSList *ml = NULL;
632 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS (source);
633 for ( SPObject *child = sp_object_first_child(SP_OBJECT(defs));
634 child != NULL;
635 child = SP_OBJECT_NEXT (child) )
636 {
637 if (SP_IS_MARKER(child)) {
638 ml = g_slist_prepend (ml, child);
639 }
640 }
641 return ml;
642 }
644 #define MARKER_ITEM_MARGIN 0
646 /**
647 * Adds previews of markers in marker_list to the given menu widget
648 */
649 static void
650 sp_marker_menu_build (Gtk::Menu *m, GSList *marker_list, SPDocument *source, SPDocument *sandbox, gchar const *menu_id)
651 {
652 // Do this here, outside of loop, to speed up preview generation:
653 NRArena const *arena = NRArena::create();
654 unsigned const visionkey = sp_item_display_key_new(1);
655 NRArenaItem *root = sp_item_invoke_show(SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY);
657 for (; marker_list != NULL; marker_list = marker_list->next) {
658 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) marker_list->data);
659 Gtk::MenuItem *i = new Gtk::MenuItem();
660 i->show();
662 if (repr->attribute("inkscape:stockid"))
663 i->set_data("stockid", (void *) "true");
664 else
665 i->set_data("stockid", (void *) "false");
667 gchar const *markid = repr->attribute("id");
668 i->set_data("marker", (void *) markid);
670 Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN);
671 hb->show();
673 // generate preview
675 Gtk::Image *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root);
676 prv->show();
677 hb->pack_start(*prv, false, false, 6);
679 // create label
680 Gtk::Label *l = new Gtk::Label(repr->attribute("id"));
681 l->show();
682 l->set_alignment(0.0, 0.5);
684 hb->pack_start(*l, true, true, 0);
686 hb->show();
687 i->add(*hb);
689 m->append(*i);
690 }
692 sp_item_invoke_hide(SP_ITEM(sp_document_root(sandbox)), visionkey);
693 nr_object_unref((NRObject *) arena);
694 }
696 /**
697 * sp_marker_list_from_doc()
698 *
699 * \brief Pick up all markers from source, except those that are in
700 * current_doc (if non-NULL), and add items to the m menu
701 *
702 */
703 static void
704 sp_marker_list_from_doc (Gtk::Menu *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id)
705 {
706 GSList *ml = ink_marker_list_get(source);
707 GSList *clean_ml = NULL;
709 for (; ml != NULL; ml = ml->next) {
710 if (!SP_IS_MARKER(ml->data))
711 continue;
713 // Add to the list of markers we really do wish to show
714 clean_ml = g_slist_prepend (clean_ml, ml->data);
715 }
716 sp_marker_menu_build(m, clean_ml, source, sandbox, menu_id);
718 g_slist_free (ml);
719 g_slist_free (clean_ml);
720 }
722 /**
723 * Returns a new document containing default start, mid, and end markers.
724 */
725 SPDocument *
726 ink_markers_preview_doc ()
727 {
728 gchar const *buffer = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">"
729 " <defs id=\"defs\" />"
731 " <g id=\"marker-start\">"
732 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:url(#sample);marker-mid:none;marker-end:none\""
733 " d=\"M 12.5,13 L 25,13\" id=\"path1\" />"
734 " <rect style=\"fill:none;stroke:none\" id=\"rect2\""
735 " width=\"25\" height=\"25\" x=\"0\" y=\"0\" />"
736 " </g>"
738 " <g id=\"marker-mid\">"
739 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:url(#sample);marker-end:none\""
740 " d=\"M 0,113 L 12.5,113 L 25,113\" id=\"path11\" />"
741 " <rect style=\"fill:none;stroke:none\" id=\"rect22\""
742 " width=\"25\" height=\"25\" x=\"0\" y=\"100\" />"
743 " </g>"
745 " <g id=\"marker-end\">"
746 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:none;marker-end:url(#sample)\""
747 " d=\"M 0,213 L 12.5,213\" id=\"path111\" />"
748 " <rect style=\"fill:none;stroke:none\" id=\"rect222\""
749 " width=\"25\" height=\"25\" x=\"0\" y=\"200\" />"
750 " </g>"
752 "</svg>";
754 return sp_document_new_from_mem (buffer, strlen(buffer), FALSE);
755 }
757 static void
758 ink_marker_menu_create_menu(Gtk::Menu *m, gchar const *menu_id, SPDocument *doc, SPDocument *sandbox)
759 {
760 static SPDocument *markers_doc = NULL;
762 // add "None"
763 Gtk::MenuItem *i = new Gtk::MenuItem();
764 i->show();
766 i->set_data("marker", (void *) "none");
768 Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN);
769 hb->show();
771 Gtk::Label *l = new Gtk::Label( _("None") );
772 l->show();
773 l->set_alignment(0.0, 0.5);
775 hb->pack_start(*l, true, true, 0);
777 hb->show();
778 i->add(*hb);
779 m->append(*i);
781 // find and load markers.svg
782 if (markers_doc == NULL) {
783 char *markers_source = g_build_filename(INKSCAPE_MARKERSDIR, "markers.svg", NULL);
784 if (Inkscape::IO::file_test(markers_source, G_FILE_TEST_IS_REGULAR)) {
785 markers_doc = sp_document_new(markers_source, FALSE);
786 }
787 g_free(markers_source);
788 }
790 // suck in from current doc
791 sp_marker_list_from_doc(m, NULL, doc, markers_doc, sandbox, menu_id);
793 // add separator
794 {
795 //Gtk::Separator *i = gtk_separator_menu_item_new();
796 Gtk::SeparatorMenuItem *i = new Gtk::SeparatorMenuItem();
797 i->show();
798 m->append(*i);
799 }
801 // suck in from markers.svg
802 if (markers_doc) {
803 sp_document_ensure_up_to_date(doc);
804 sp_marker_list_from_doc(m, doc, markers_doc, NULL, sandbox, menu_id);
805 }
807 }
809 /**
810 * Creates a menu widget to display markers from markers.svg
811 */
812 static Gtk::OptionMenu *
813 ink_marker_menu(Gtk::Widget */*tbl*/, gchar const *menu_id, SPDocument *sandbox)
814 {
815 SPDesktop *desktop = inkscape_active_desktop();
816 SPDocument *doc = sp_desktop_document(desktop);
817 Gtk::OptionMenu *mnu = new Gtk::OptionMenu();
819 /* Create new menu widget */
820 Gtk::Menu *m = new Gtk::Menu();
821 m->show();
823 mnu->set_data("updating", (gpointer) FALSE);
825 if (!doc) {
826 Gtk::MenuItem *i = new Gtk::MenuItem(_("No document selected"));
827 i->show();
828 m->append(*i);
829 mnu->set_sensitive(false);
831 } else {
832 ink_marker_menu_create_menu(m, menu_id, doc, sandbox);
834 mnu->set_sensitive(true);
835 }
837 mnu->set_data("menu_id", const_cast<gchar *>(menu_id));
838 mnu->set_menu(*m);
840 /* Set history */
841 mnu->set_history(0);
843 return mnu;
844 }
846 /**
847 * Handles when user selects one of the markers from the marker menu.
848 * Defines a uri string to refer to it, then applies it to all selected
849 * items in the current desktop.
850 */
851 static void
852 sp_marker_select(Gtk::OptionMenu *mnu, Gtk::Container *spw, SPMarkerLoc const which)
853 {
854 if (spw->get_data("update")) {
855 return;
856 }
858 SPDesktop *desktop = inkscape_active_desktop();
859 SPDocument *document = sp_desktop_document(desktop);
860 if (!document) {
861 return;
862 }
864 /* Get Marker */
865 if (!mnu->get_menu()->get_active()->get_data("marker"))
866 {
867 return;
868 }
869 gchar *markid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("marker"));
870 gchar const *marker = "";
871 if (strcmp(markid, "none")) {
872 gchar *stockid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("stockid"));
874 gchar *markurn = markid;
875 if (!strcmp(stockid,"true")) markurn = g_strconcat("urn:inkscape:marker:",markid,NULL);
876 SPObject *mark = get_stock_item(markurn);
877 if (mark) {
878 Inkscape::XML::Node *repr = SP_OBJECT_REPR(mark);
879 marker = g_strconcat("url(#", repr->attribute("id"), ")", NULL);
880 }
881 } else {
882 marker = markid;
883 }
884 SPCSSAttr *css = sp_repr_css_attr_new();
885 gchar const *menu_id = static_cast<gchar const *>(mnu->get_data("menu_id"));
886 sp_repr_css_set_property(css, menu_id, marker);
888 // Also update the marker dropdown menus, so the document's markers
889 // show up at the top of the menu
890 // sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
891 ink_markers_menu_update(spw, which);
893 Inkscape::Selection *selection = sp_desktop_selection(desktop);
894 GSList const *items = selection->itemList();
895 for (; items != NULL; items = items->next) {
896 SPItem *item = (SPItem *) items->data;
897 if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) // can't set marker to rect, until it's converted to using <path>
898 continue;
899 Inkscape::XML::Node *selrepr = SP_OBJECT_REPR((SPItem *) items->data);
900 if (selrepr) {
901 sp_repr_css_change_recursive(selrepr, css, "style");
902 }
903 SP_OBJECT(items->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
904 SP_OBJECT(items->data)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
905 }
907 sp_repr_css_attr_unref(css);
909 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
910 _("Set markers"));
912 };
914 static unsigned int
915 ink_marker_menu_get_pos(Gtk::Menu *mnu, gchar const *markname)
916 {
917 if (markname == NULL)
918 markname = static_cast<gchar const *>(mnu->get_active()->get_data("marker"));
920 if (markname == NULL)
921 return 0;
923 std::vector<Gtk::Widget *> kids = mnu->get_children();
924 unsigned int i = 0;
925 for (; i < kids.size();) {
926 gchar const *mark = static_cast<gchar const *>(kids[i]->get_data("marker"));
927 if (mark && strcmp(mark, markname) == 0) {
928 break;
929 }
930 ++i;
931 }
933 return i;
934 }
936 static void
937 ink_markers_menu_update(Gtk::Container* /*spw*/, SPMarkerLoc const which) {
938 SPDesktop *desktop = inkscape_active_desktop();
939 SPDocument *document = sp_desktop_document(desktop);
940 SPDocument *sandbox = ink_markers_preview_doc ();
941 Gtk::Menu *m;
942 int pos;
944 // TODO: this code can be shortened by abstracting out marker_(start|mid|end)_...
945 switch (which) {
946 case SP_MARKER_LOC_START:
947 marker_start_menu_connection.block();
948 pos = ink_marker_menu_get_pos(marker_start_menu->get_menu(), NULL);
949 m = new Gtk::Menu();
950 m->show();
951 ink_marker_menu_create_menu(m, "marker-start", document, sandbox);
952 marker_start_menu->remove_menu();
953 marker_start_menu->set_menu(*m);
954 marker_start_menu->set_history(pos);
955 marker_start_menu_connection.unblock();
956 break;
958 case SP_MARKER_LOC_MID:
959 marker_mid_menu_connection.block();
960 pos = ink_marker_menu_get_pos(marker_mid_menu->get_menu(), NULL);
961 m = new Gtk::Menu();
962 m->show();
963 ink_marker_menu_create_menu(m, "marker-mid", document, sandbox);
964 marker_mid_menu->remove_menu();
965 marker_mid_menu->set_menu(*m);
966 marker_mid_menu->set_history(pos);
967 marker_mid_menu_connection.unblock();
968 break;
970 case SP_MARKER_LOC_END:
971 marker_end_menu_connection.block();
972 pos = ink_marker_menu_get_pos(marker_end_menu->get_menu(), NULL);
973 m = new Gtk::Menu();
974 m->show();
975 ink_marker_menu_create_menu(m, "marker-end", document, sandbox);
976 marker_end_menu->remove_menu();
977 marker_end_menu->set_menu(*m);
978 marker_end_menu->set_history(pos);
979 marker_end_menu_connection.unblock();
980 break;
981 default:
982 g_assert_not_reached();
983 }
984 }
986 /**
987 * Sets the stroke width units for all selected items.
988 * Also handles absolute and dimensionless units.
989 */
990 static gboolean stroke_width_set_unit(SPUnitSelector *,
991 SPUnit const *old,
992 SPUnit const *new_units,
993 Gtk::Container *spw)
994 {
995 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
997 if (!desktop) {
998 return FALSE;
999 }
1001 Inkscape::Selection *selection = sp_desktop_selection (desktop);
1003 if (selection->isEmpty())
1004 return FALSE;
1006 GSList const *objects = selection->itemList();
1008 if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) &&
1009 (new_units->base == SP_UNIT_DIMENSIONLESS)) {
1011 /* Absolute to percentage */
1012 spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1014 Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1015 float w = sp_units_get_pixels (a->get_value(), *old);
1017 gdouble average = stroke_average_width (objects);
1019 if (average == NR_HUGE || average == 0)
1020 return FALSE;
1022 a->set_value (100.0 * w / average);
1024 spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1025 return TRUE;
1027 } else if ((old->base == SP_UNIT_DIMENSIONLESS) &&
1028 (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) {
1030 /* Percentage to absolute */
1031 spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1033 Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data ("width"));
1035 gdouble average = stroke_average_width (objects);
1037 a->set_value (sp_pixels_get_units (0.01 * a->get_value() * average, *new_units));
1039 spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1040 return TRUE;
1041 }
1043 return FALSE;
1044 }
1047 /**
1048 * \brief Creates a new widget for the line stroke style.
1049 *
1050 */
1051 Gtk::Container *
1052 sp_stroke_style_line_widget_new(void)
1053 {
1054 Gtk::Widget *us;
1055 SPDashSelector *ds;
1056 GtkWidget *us_old, *spw_old;
1057 Gtk::Container *spw;
1058 Gtk::Table *t;
1059 Gtk::Adjustment *a;
1060 Gtk::SpinButton *sb;
1061 Gtk::RadioButton *tb;
1062 Gtk::HBox *f, *hb;
1064 Gtk::Tooltips *tt = new Gtk::Tooltips();
1066 spw_old = sp_widget_new_global(INKSCAPE);
1067 spw = dynamic_cast<Gtk::Container *>(manage(Glib::wrap(spw_old)));
1069 f = new Gtk::HBox(false, 0);
1070 f->show();
1071 spw->add(*f);
1073 t = new Gtk::Table(3, 6, false);
1074 t->show();
1075 t->set_border_width(4);
1076 t->set_row_spacings(4);
1077 f->add(*t);
1078 spw->set_data("stroke", t);
1080 gint i = 0;
1082 //TRANSLATORS: only translate "string" in "context|string".
1083 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
1084 /* Stroke width */
1085 spw_label(t, Q_("StrokeWidth|Width:"), 0, i);
1087 hb = spw_hbox(t, 3, 1, i);
1089 // TODO: when this is gtkmmified, use an Inkscape::UI::Widget::ScalarUnit instead of the separate
1090 // spinbutton and unit selector for stroke width. In sp_stroke_style_line_update, use
1091 // setHundredPercent to remember the aeraged width corresponding to 100%. Then the
1092 // stroke_width_set_unit will be removed (because ScalarUnit takes care of conversions itself), and
1093 // with it, the two remaining calls of stroke_average_width, allowing us to get rid of that
1094 // function in desktop-style.
1096 a = new Gtk::Adjustment(1.0, 0.0, 1000.0, 0.1, 10.0, 0.0);
1097 spw->set_data("width", a);
1098 sb = new Gtk::SpinButton(*a, 0.1, 3);
1099 tt->set_tip(*sb, _("Stroke width"));
1100 sb->show();
1102 sp_dialog_defocus_on_enter_cpp(sb);
1104 hb->pack_start(*sb, false, false, 0);
1105 us_old = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
1106 us = manage(Glib::wrap(us_old));
1107 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1108 if (desktop)
1109 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us_old), sp_desktop_namedview(desktop)->doc_units);
1110 sp_unit_selector_add_unit(SP_UNIT_SELECTOR(us_old), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0);
1111 g_signal_connect ( G_OBJECT (us_old), "set_unit", G_CALLBACK (stroke_width_set_unit), spw );
1112 us->show();
1113 sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us_old), GTK_ADJUSTMENT(a->gobj()) );
1114 hb->pack_start(*us, FALSE, FALSE, 0);
1115 spw->set_data("units", us_old);
1117 a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_width_changed), spw));
1118 i++;
1120 /* Join type */
1121 // TRANSLATORS: The line join style specifies the shape to be used at the
1122 // corners of paths. It can be "miter", "round" or "bevel".
1123 spw_label(t, _("Join:"), 0, i);
1125 hb = spw_hbox(t, 3, 1, i);
1127 tb = NULL;
1129 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_MITER,
1130 hb, spw, "join", "miter");
1132 // TRANSLATORS: Miter join: joining lines with a sharp (pointed) corner.
1133 // For an example, draw a triangle with a large stroke width and modify the
1134 // "Join" option (in the Fill and Stroke dialog).
1135 tt->set_tip(*tb, _("Miter join"));
1136 spw->set_data("miter join", tb);
1138 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_ROUND,
1139 hb, spw, "join", "round");
1142 // TRANSLATORS: Round join: joining lines with a rounded corner.
1143 // For an example, draw a triangle with a large stroke width and modify the
1144 // "Join" option (in the Fill and Stroke dialog).
1145 tt->set_tip(*tb, _("Round join"));
1146 spw->set_data("round join", tb);
1148 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_BEVEL,
1149 hb, spw, "join", "bevel");
1152 // TRANSLATORS: Bevel join: joining lines with a blunted (flattened) corner.
1153 // For an example, draw a triangle with a large stroke width and modify the
1154 // "Join" option (in the Fill and Stroke dialog).
1155 tt->set_tip(*tb, _("Bevel join"));
1156 spw->set_data("bevel join", tb);
1158 i++;
1160 /* Miterlimit */
1161 // TRANSLATORS: Miter limit: only for "miter join", this limits the length
1162 // of the sharp "spike" when the lines connect at too sharp an angle.
1163 // When two line segments meet at a sharp angle, a miter join results in a
1164 // spike that extends well beyond the connection point. The purpose of the
1165 // miter limit is to cut off such spikes (i.e. convert them into bevels)
1166 // when they become too long.
1167 spw_label(t, _("Miter limit:"), 0, i);
1169 hb = spw_hbox(t, 3, 1, i);
1171 a = new Gtk::Adjustment(4.0, 0.0, 100.0, 0.1, 10.0, 0.0);
1172 spw->set_data("miterlimit", a);
1174 sb = new Gtk::SpinButton(*a, 0.1, 2);
1175 tt->set_tip(*sb, _("Maximum length of the miter (in units of stroke width)"));
1176 sb->show();
1177 spw->set_data("miterlimit_sb", sb);
1178 sp_dialog_defocus_on_enter_cpp(sb);
1180 hb->pack_start(*sb, false, false, 0);
1182 a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_miterlimit_changed), spw));
1183 i++;
1185 /* Cap type */
1186 // TRANSLATORS: cap type specifies the shape for the ends of lines
1187 spw_label(t, _("Cap:"), 0, i);
1189 hb = spw_hbox(t, 3, 1, i);
1191 tb = NULL;
1193 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_BUTT,
1194 hb, spw, "cap", "butt");
1195 spw->set_data("cap butt", tb);
1197 // TRANSLATORS: Butt cap: the line shape does not extend beyond the end point
1198 // of the line; the ends of the line are square
1199 tt->set_tip(*tb, _("Butt cap"));
1201 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_ROUND,
1202 hb, spw, "cap", "round");
1203 spw->set_data("cap round", tb);
1205 // TRANSLATORS: Round cap: the line shape extends beyond the end point of the
1206 // line; the ends of the line are rounded
1207 tt->set_tip(*tb, _("Round cap"));
1209 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_SQUARE,
1210 hb, spw, "cap", "square");
1211 spw->set_data("cap square", tb);
1213 // TRANSLATORS: Square cap: the line shape extends beyond the end point of the
1214 // line; the ends of the line are square
1215 tt->set_tip(*tb, _("Square cap"));
1217 i++;
1220 /* Dash */
1221 spw_label(t, _("Dashes:"), 0, i);
1222 ds = manage(new SPDashSelector);
1224 ds->show();
1225 t->attach(*ds, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1226 spw->set_data("dash", ds);
1227 ds->changed_signal.connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_line_dash_changed), spw));
1228 i++;
1230 /* Drop down marker selectors*/
1231 // TODO: this code can be shortened by iterating over the possible menus!
1233 // doing this here once, instead of for each preview, to speed things up
1234 SPDocument *sandbox = ink_markers_preview_doc ();
1236 // TRANSLATORS: Path markers are an SVG feature that allows you to attach arbitrary shapes
1237 // (arrowheads, bullets, faces, whatever) to the start, end, or middle nodes of a path.
1238 spw_label(t, _("Start Markers:"), 0, i);
1239 marker_start_menu = ink_marker_menu(spw ,"marker-start", sandbox);
1240 tt->set_tip(*marker_start_menu, _("Start Markers are drawn on the first node of a path or shape"));
1241 marker_start_menu_connection = marker_start_menu->signal_changed().connect(
1242 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1243 sigc::ptr_fun(&sp_marker_select), marker_start_menu, spw, SP_MARKER_LOC_START));
1244 marker_start_menu->show();
1245 t->attach(*marker_start_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1246 spw->set_data("start_mark_menu", marker_start_menu);
1248 i++;
1249 spw_label(t, _("Mid Markers:"), 0, i);
1250 marker_mid_menu = ink_marker_menu(spw ,"marker-mid", sandbox);
1251 tt->set_tip(*marker_mid_menu, _("Mid Markers are drawn on every node of a path or shape except the first and last nodes"));
1252 marker_mid_menu_connection = marker_mid_menu->signal_changed().connect(
1253 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1254 sigc::ptr_fun(&sp_marker_select), marker_mid_menu,spw, SP_MARKER_LOC_MID));
1255 marker_mid_menu->show();
1256 t->attach(*marker_mid_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1257 spw->set_data("mid_mark_menu", marker_mid_menu);
1259 i++;
1260 spw_label(t, _("End Markers:"), 0, i);
1261 marker_end_menu = ink_marker_menu(spw ,"marker-end", sandbox);
1262 tt->set_tip(*marker_end_menu, _("End Markers are drawn on the last node of a path or shape"));
1263 marker_end_menu_connection = marker_end_menu->signal_changed().connect(
1264 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1265 sigc::ptr_fun(&sp_marker_select), marker_end_menu, spw, SP_MARKER_LOC_END));
1266 marker_end_menu->show();
1267 t->attach(*marker_end_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1268 spw->set_data("end_mark_menu", marker_end_menu);
1270 i++;
1272 // FIXME: we cheat and still use gtk+ signals
1274 gtk_signal_connect(GTK_OBJECT(spw_old), "modify_selection",
1275 GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified),
1276 spw);
1277 gtk_signal_connect(GTK_OBJECT(spw_old), "change_selection",
1278 GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed),
1279 spw);
1281 sp_stroke_style_line_update(spw, desktop ? sp_desktop_selection(desktop) : NULL);
1283 return spw;
1284 }
1286 /**
1287 * Callback for when stroke style widget is modified.
1288 * Triggers update action.
1289 */
1290 static void
1291 sp_stroke_style_line_selection_modified(SPWidget *,
1292 Inkscape::Selection *selection,
1293 guint flags,
1294 gpointer data)
1295 {
1296 Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1297 if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG)) {
1298 sp_stroke_style_line_update(spw, selection);
1299 }
1301 }
1303 /**
1304 * Callback for when stroke style widget is changed.
1305 * Triggers update action.
1306 */
1307 static void
1308 sp_stroke_style_line_selection_changed(SPWidget *,
1309 Inkscape::Selection *selection,
1310 gpointer data)
1311 {
1312 Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1313 sp_stroke_style_line_update(spw, selection);
1314 }
1316 /**
1317 * Sets selector widgets' dash style from an SPStyle object.
1318 */
1319 static void
1320 sp_dash_selector_set_from_style(SPDashSelector *dsel, SPStyle *style)
1321 {
1322 if (style->stroke_dash.n_dash > 0) {
1323 double d[64];
1324 int len = MIN(style->stroke_dash.n_dash, 64);
1325 for (int i = 0; i < len; i++) {
1326 if (style->stroke_width.computed != 0)
1327 d[i] = style->stroke_dash.dash[i] / style->stroke_width.computed;
1328 else
1329 d[i] = style->stroke_dash.dash[i]; // is there a better thing to do for stroke_width==0?
1330 }
1331 dsel->set_dash(len, d, style->stroke_width.computed != 0 ?
1332 style->stroke_dash.offset / style->stroke_width.computed :
1333 style->stroke_dash.offset);
1334 } else {
1335 dsel->set_dash(0, NULL, 0.0);
1336 }
1337 }
1339 /**
1340 * Sets the join type for a line, and updates the stroke style widget's buttons
1341 */
1342 static void
1343 sp_jointype_set (Gtk::Container *spw, unsigned const jointype)
1344 {
1345 Gtk::RadioButton *tb = NULL;
1346 switch (jointype) {
1347 case SP_STROKE_LINEJOIN_MITER:
1348 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_MITER));
1349 break;
1350 case SP_STROKE_LINEJOIN_ROUND:
1351 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_ROUND));
1352 break;
1353 case SP_STROKE_LINEJOIN_BEVEL:
1354 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_BEVEL));
1355 break;
1356 default:
1357 break;
1358 }
1359 sp_stroke_style_set_join_buttons(spw, tb);
1360 }
1362 /**
1363 * Sets the cap type for a line, and updates the stroke style widget's buttons
1364 */
1365 static void
1366 sp_captype_set (Gtk::Container *spw, unsigned const captype)
1367 {
1368 Gtk::RadioButton *tb = NULL;
1369 switch (captype) {
1370 case SP_STROKE_LINECAP_BUTT:
1371 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_BUTT));
1372 break;
1373 case SP_STROKE_LINECAP_ROUND:
1374 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_ROUND));
1375 break;
1376 case SP_STROKE_LINECAP_SQUARE:
1377 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_SQUARE));
1378 break;
1379 default:
1380 break;
1381 }
1382 sp_stroke_style_set_cap_buttons(spw, tb);
1383 }
1385 /**
1386 * Callback for when stroke style widget is updated, including markers, cap type,
1387 * join type, etc.
1388 */
1389 static void
1390 sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel)
1391 {
1392 if (spw->get_data("update")) {
1393 return;
1394 }
1396 spw->set_data("update", GINT_TO_POINTER(TRUE));
1398 Gtk::Table *sset = static_cast<Gtk::Table *>(spw->get_data("stroke"));
1399 Gtk::Adjustment *width = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1400 Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1401 SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1402 SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1404 // create temporary style
1405 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
1406 // query into it
1407 int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
1408 int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
1409 int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP);
1410 int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
1412 if (!sel || sel->isEmpty()) {
1413 // Nothing selected, grey-out all controls in the stroke-style dialog
1414 sset->set_sensitive(false);
1416 spw->set_data("update", GINT_TO_POINTER(FALSE));
1418 return;
1419 } else {
1420 sset->set_sensitive(true);
1422 SPUnit const *unit = sp_unit_selector_get_unit(us);
1424 if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) {
1425 sp_unit_selector_set_unit(us, &sp_unit_get_by_id(SP_UNIT_PERCENT));
1426 } else {
1427 // same width, or only one object; no sense to keep percent, switch to absolute
1428 if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1429 sp_unit_selector_set_unit(us, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
1430 }
1431 }
1433 unit = sp_unit_selector_get_unit(us);
1435 if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1436 double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit);
1437 width->set_value(avgwidth);
1438 } else {
1439 width->set_value(100);
1440 }
1442 // if none of the selected objects has a stroke, than quite some controls should be disabled
1443 // The markers might still be shown though, so these will not be disabled
1444 bool enabled = (result_sw != QUERY_STYLE_NOTHING) && !query->stroke.isNoneSet();
1445 /* No objects stroked, set insensitive */
1446 Gtk::RadioButton *tb = NULL;
1447 tb = static_cast<Gtk::RadioButton *>(spw->get_data("miter join"));
1448 tb->set_sensitive(enabled);
1449 tb = static_cast<Gtk::RadioButton *>(spw->get_data("round join"));
1450 tb->set_sensitive(enabled);
1451 tb = static_cast<Gtk::RadioButton *>(spw->get_data("bevel join"));
1452 tb->set_sensitive(enabled);
1454 Gtk::SpinButton* sb = NULL;
1455 sb = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1456 sb->set_sensitive(enabled);
1458 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap butt"));
1459 tb->set_sensitive(enabled);
1460 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap round"));
1461 tb->set_sensitive(enabled);
1462 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap square"));
1463 tb->set_sensitive(enabled);
1465 dsel->set_sensitive(enabled);
1466 }
1468 if (result_ml != QUERY_STYLE_NOTHING)
1469 ml->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness?
1471 if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1472 sp_jointype_set(spw, query->stroke_linejoin.value);
1473 } else {
1474 sp_stroke_style_set_join_buttons(spw, NULL);
1475 }
1477 if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1478 sp_captype_set (spw, query->stroke_linecap.value);
1479 } else {
1480 sp_stroke_style_set_cap_buttons(spw, NULL);
1481 }
1483 sp_style_unref(query);
1485 if (!sel || sel->isEmpty())
1486 return;
1488 GSList const *objects = sel->itemList();
1489 SPObject * const object = SP_OBJECT(objects->data);
1490 SPStyle * const style = SP_OBJECT_STYLE(object);
1492 /* Markers */
1493 sp_stroke_style_update_marker_menus(spw, objects); // FIXME: make this desktop query too
1495 /* Dash */
1496 sp_dash_selector_set_from_style(dsel, style); // FIXME: make this desktop query too
1498 sset->set_sensitive(true);
1500 spw->set_data("update", GINT_TO_POINTER(FALSE));
1501 }
1503 /**
1504 * Sets a line's dash properties in a CSS style object.
1505 */
1506 static void
1507 sp_stroke_style_set_scaled_dash(SPCSSAttr *css,
1508 int ndash, double *dash, double offset,
1509 double scale)
1510 {
1511 if (ndash > 0) {
1512 Inkscape::CSSOStringStream osarray;
1513 for (int i = 0; i < ndash; i++) {
1514 osarray << dash[i] * scale;
1515 if (i < (ndash - 1)) {
1516 osarray << ",";
1517 }
1518 }
1519 sp_repr_css_set_property(css, "stroke-dasharray", osarray.str().c_str());
1521 Inkscape::CSSOStringStream osoffset;
1522 osoffset << offset * scale;
1523 sp_repr_css_set_property(css, "stroke-dashoffset", osoffset.str().c_str());
1524 } else {
1525 sp_repr_css_set_property(css, "stroke-dasharray", "none");
1526 sp_repr_css_set_property(css, "stroke-dashoffset", NULL);
1527 }
1528 }
1530 /**
1531 * Sets line properties like width, dashes, markers, etc. on all currently selected items.
1532 */
1533 static void
1534 sp_stroke_style_scale_line(Gtk::Container *spw)
1535 {
1536 if (spw->get_data("update")) {
1537 return;
1538 }
1540 spw->set_data("update", GINT_TO_POINTER(TRUE));
1542 Gtk::Adjustment *wadj = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1543 SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1544 SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1545 Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1547 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1548 SPDocument *document = sp_desktop_document (desktop);
1549 Inkscape::Selection *selection = sp_desktop_selection (desktop);
1551 GSList const *items = selection->itemList();
1553 /* TODO: Create some standardized method */
1554 SPCSSAttr *css = sp_repr_css_attr_new();
1556 if (items) {
1558 double width_typed = wadj->get_value();
1559 double const miterlimit = ml->get_value();
1561 SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us));
1563 double *dash, offset;
1564 int ndash;
1565 dsel->get_dash(&ndash, &dash, &offset);
1567 for (GSList const *i = items; i != NULL; i = i->next) {
1568 /* Set stroke width */
1569 double width;
1570 if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1571 width = sp_units_get_pixels (width_typed, *unit);
1572 } else { // percentage
1573 gdouble old_w = SP_OBJECT_STYLE (i->data)->stroke_width.computed;
1574 width = old_w * width_typed / 100;
1575 }
1577 {
1578 Inkscape::CSSOStringStream os_width;
1579 os_width << width;
1580 sp_repr_css_set_property(css, "stroke-width", os_width.str().c_str());
1581 }
1583 {
1584 Inkscape::CSSOStringStream os_ml;
1585 os_ml << miterlimit;
1586 sp_repr_css_set_property(css, "stroke-miterlimit", os_ml.str().c_str());
1587 }
1589 /* Set dash */
1590 sp_stroke_style_set_scaled_dash(css, ndash, dash, offset, width);
1592 sp_desktop_apply_css_recursive (SP_OBJECT(i->data), css, true);
1593 }
1595 g_free(dash);
1597 if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1598 // reset to 100 percent
1599 wadj->set_value(100.0);
1600 }
1602 }
1604 // we have already changed the items, so set style without changing selection
1605 // FIXME: move the above stroke-setting stuff, including percentages, to desktop-style
1606 sp_desktop_set_style (desktop, css, false);
1608 sp_repr_css_attr_unref(css);
1610 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
1611 _("Set stroke style"));
1613 spw->set_data("update", GINT_TO_POINTER(FALSE));
1614 }
1616 /**
1617 * Callback for when the stroke style's width changes.
1618 * Causes all line styles to be applied to all selected items.
1619 */
1620 static void
1621 sp_stroke_style_width_changed(Gtk::Container *spw)
1622 {
1623 if (spw->get_data("update")) {
1624 return;
1625 }
1627 sp_stroke_style_scale_line(spw);
1628 }
1630 /**
1631 * Callback for when the stroke style's miterlimit changes.
1632 * Causes all line styles to be applied to all selected items.
1633 */
1634 static void
1635 sp_stroke_style_miterlimit_changed(Gtk::Container *spw)
1636 {
1637 if (spw->get_data("update")) {
1638 return;
1639 }
1641 sp_stroke_style_scale_line(spw);
1642 }
1644 /**
1645 * Callback for when the stroke style's dash changes.
1646 * Causes all line styles to be applied to all selected items.
1647 */
1649 static void
1650 sp_stroke_style_line_dash_changed(Gtk::Container *spw)
1651 {
1652 if (spw->get_data("update")) {
1653 return;
1654 }
1656 sp_stroke_style_scale_line(spw);
1657 }
1659 /**
1660 * \brief This routine handles toggle events for buttons in the stroke style
1661 * dialog.
1662 * When activated, this routine gets the data for the various widgets, and then
1663 * calls the respective routines to update css properties, etc.
1664 *
1665 */
1666 static void
1667 sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw)
1668 {
1669 if (spw->get_data("update")) {
1670 return;
1671 }
1673 if (tb->get_active()) {
1675 gchar const *join
1676 = static_cast<gchar const *>(tb->get_data("join"));
1677 gchar const *cap
1678 = static_cast<gchar const *>(tb->get_data("cap"));
1680 if (join) {
1681 Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1682 ml->set_sensitive(!strcmp(join, "miter"));
1683 }
1685 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1687 /* TODO: Create some standardized method */
1688 SPCSSAttr *css = sp_repr_css_attr_new();
1690 if (join) {
1691 sp_repr_css_set_property(css, "stroke-linejoin", join);
1693 sp_desktop_set_style (desktop, css);
1695 sp_stroke_style_set_join_buttons(spw, tb);
1696 } else if (cap) {
1697 sp_repr_css_set_property(css, "stroke-linecap", cap);
1699 sp_desktop_set_style (desktop, css);
1701 sp_stroke_style_set_cap_buttons(spw, tb);
1702 }
1704 sp_repr_css_attr_unref(css);
1706 sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_FILL_STROKE,
1707 _("Set stroke style"));
1708 }
1709 }
1711 /**
1712 * Updates the join style toggle buttons
1713 */
1714 static void
1715 sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1716 {
1717 Gtk::RadioButton *tb;
1719 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_MITER));
1720 tb->set_active(active == tb);
1722 Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1723 ml->set_sensitive(active == tb);
1725 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_ROUND));
1726 tb->set_active(active == tb);
1728 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_BEVEL));
1729 tb->set_active(active == tb);
1730 }
1732 /**
1733 * Updates the cap style toggle buttons
1734 */
1735 static void
1736 sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1737 {
1738 Gtk::RadioButton *tb;
1740 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_BUTT));
1741 tb->set_active(active == tb);
1742 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_ROUND));
1743 tb->set_active(active == tb);
1744 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_SQUARE));
1745 tb->set_active(active == tb);
1746 }
1748 /**
1749 * Sets the current marker in the marker menu.
1750 */
1751 static void
1752 ink_marker_menu_set_current(SPObject *marker, Gtk::OptionMenu *mnu)
1753 {
1754 mnu->set_data("update", GINT_TO_POINTER(TRUE));
1756 Gtk::Menu *m = mnu->get_menu();
1757 if (marker != NULL) {
1758 bool mark_is_stock = false;
1759 if (SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"))
1760 mark_is_stock = true;
1762 gchar *markname;
1763 if (mark_is_stock)
1764 markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"));
1765 else
1766 markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("id"));
1768 int markpos = ink_marker_menu_get_pos(m, markname);
1769 mnu->set_history(markpos);
1771 g_free (markname);
1772 }
1773 else {
1774 mnu->set_history(0);
1775 }
1776 mnu->set_data("update", GINT_TO_POINTER(FALSE));
1777 }
1779 /**
1780 * Updates the marker menus to highlight the appropriate marker and scroll to
1781 * that marker.
1782 */
1783 static void
1784 sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects)
1785 {
1786 struct { char const *key; int loc; } const keyloc[] = {
1787 { "start_mark_menu", SP_MARKER_LOC_START },
1788 { "mid_mark_menu", SP_MARKER_LOC_MID },
1789 { "end_mark_menu", SP_MARKER_LOC_END }
1790 };
1792 bool all_texts = true;
1793 for (GSList *i = (GSList *) objects; i != NULL; i = i->next) {
1794 if (!SP_IS_TEXT (i->data)) {
1795 all_texts = false;
1796 }
1797 }
1799 for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1800 Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1801 // Per SVG spec, text objects cannot have markers; disable menus if only texts are selected
1802 mnu->set_sensitive(!all_texts);
1803 }
1805 // We show markers of the first object in the list only
1806 // FIXME: use the first in the list that has the marker of each type, if any
1807 SPObject *object = SP_OBJECT(objects->data);
1809 for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1810 // For all three marker types,
1812 // find the corresponding menu
1813 Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1815 // Quit if we're in update state
1816 if (mnu->get_data("update")) {
1817 return;
1818 }
1820 if (object->style->marker[keyloc[i].loc].value != NULL && !all_texts) {
1821 // If the object has this type of markers,
1823 // Extract the name of the marker that the object uses
1824 SPObject *marker = ink_extract_marker_name(object->style->marker[keyloc[i].loc].value, SP_OBJECT_DOCUMENT(object));
1825 // Scroll the menu to that marker
1826 ink_marker_menu_set_current(marker, mnu);
1828 } else {
1829 mnu->set_history(0);
1830 }
1831 }
1832 }
1835 /**
1836 * Extract the actual name of the link
1837 * e.g. get mTriangle from url(#mTriangle).
1838 * \return Buffer containing the actual name, allocated from GLib;
1839 * the caller should free the buffer when they no longer need it.
1840 */
1841 static SPObject*
1842 ink_extract_marker_name(gchar const *n, SPDocument *doc)
1843 {
1844 gchar const *p = n;
1845 while (*p != '\0' && *p != '#') {
1846 p++;
1847 }
1849 if (*p == '\0' || p[1] == '\0') {
1850 return NULL;
1851 }
1853 p++;
1854 int c = 0;
1855 while (p[c] != '\0' && p[c] != ')') {
1856 c++;
1857 }
1859 if (p[c] == '\0') {
1860 return NULL;
1861 }
1863 gchar* b = g_strdup(p);
1864 b[c] = '\0';
1866 // FIXME: get the document from the object and let the caller pass it in
1867 SPObject *marker = doc->getObjectById(b);
1868 return marker;
1869 }
1871 /*
1872 Local Variables:
1873 mode:c++
1874 c-file-style:"stroustrup"
1875 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1876 indent-tabs-mode:nil
1877 fill-column:99
1878 End:
1879 */
1880 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :