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 (SP_IS_LINEARGRADIENT (server)) {
208 SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
209 sp_paint_selector_set_gradient_linear (psel, vector);
211 SPLinearGradient *lg = SP_LINEARGRADIENT (server);
212 sp_paint_selector_set_gradient_properties (psel,
213 SP_GRADIENT_UNITS (lg),
214 SP_GRADIENT_SPREAD (lg));
215 } else if (SP_IS_RADIALGRADIENT (server)) {
216 SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
217 sp_paint_selector_set_gradient_radial (psel, vector);
219 SPRadialGradient *rg = SP_RADIALGRADIENT (server);
220 sp_paint_selector_set_gradient_properties (psel,
221 SP_GRADIENT_UNITS (rg),
222 SP_GRADIENT_SPREAD (rg));
223 } else if (SP_IS_PATTERN (server)) {
224 SPPattern *pat = pattern_getroot (SP_PATTERN (server));
225 sp_update_pattern_list (psel, pat);
226 }
227 } else if (query->stroke.set && query->stroke.isColor()) {
228 sp_paint_selector_set_color_alpha (psel, &query->stroke.value.color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value));
230 }
231 break;
232 }
234 case QUERY_STYLE_MULTIPLE_DIFFERENT:
235 {
236 sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_MULTIPLE);
237 break;
238 }
239 }
241 sp_style_unref(query);
243 gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
244 }
246 /**
247 * When the mode is changed, invoke a regular changed handler.
248 */
249 static void
250 sp_stroke_style_paint_mode_changed( SPPaintSelector *psel,
251 SPPaintSelectorMode /*mode*/,
252 SPWidget *spw )
253 {
254 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
255 return;
256 }
258 /* TODO: Does this work?
259 * Not really, here we have to get old color back from object
260 * Instead of relying on paint widget having meaningful colors set
261 */
262 sp_stroke_style_paint_changed(psel, spw);
263 }
265 static gchar const *const undo_label_1 = "stroke:flatcolor:1";
266 static gchar const *const undo_label_2 = "stroke:flatcolor:2";
267 static gchar const *undo_label = undo_label_1;
269 /**
270 * When a drag callback occurs on a paint selector object, if it is a RGB or CMYK
271 * color mode, then set the stroke opacity to psel's flat color.
272 */
273 static void
274 sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw)
275 {
276 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
277 return;
278 }
280 switch (psel->mode) {
281 case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
282 case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
283 {
284 sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity");
285 sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE,
286 _("Set stroke color"));
287 break;
288 }
290 default:
291 g_warning( "file %s: line %d: Paint %d should not emit 'dragged'",
292 __FILE__, __LINE__, psel->mode);
293 break;
294 }
295 }
297 /**
298 * When the stroke style's paint settings change, this handler updates the
299 * repr's stroke css style and applies the style to relevant drawing items.
300 */
301 static void
302 sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw)
303 {
304 if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
305 return;
306 }
307 g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE));
309 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
310 SPDocument *document = sp_desktop_document (desktop);
311 Inkscape::Selection *selection = sp_desktop_selection (desktop);
313 GSList const *items = selection->itemList();
315 switch (psel->mode) {
316 case SP_PAINT_SELECTOR_MODE_EMPTY:
317 // This should not happen.
318 g_warning ( "file %s: line %d: Paint %d should not emit 'changed'",
319 __FILE__, __LINE__, psel->mode);
320 break;
321 case SP_PAINT_SELECTOR_MODE_MULTIPLE:
322 // This happens when you switch multiple objects with different gradients to flat color;
323 // nothing to do here.
324 break;
326 case SP_PAINT_SELECTOR_MODE_NONE:
327 {
328 SPCSSAttr *css = sp_repr_css_attr_new();
329 sp_repr_css_set_property(css, "stroke", "none");
331 sp_desktop_set_style (desktop, css);
333 sp_repr_css_attr_unref(css);
335 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
336 _("Remove stroke"));
337 break;
338 }
340 case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
341 case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
342 {
343 sp_paint_selector_set_flat_color (psel, desktop, "stroke", "stroke-opacity");
344 sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE,
345 _("Set stroke color"));
347 // on release, toggle undo_label so that the next drag will not be lumped with this one
348 if (undo_label == undo_label_1)
349 undo_label = undo_label_2;
350 else
351 undo_label = undo_label_1;
353 break;
354 }
356 case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR:
357 case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL:
358 if (items) {
359 SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR
360 ? SP_GRADIENT_TYPE_LINEAR
361 : SP_GRADIENT_TYPE_RADIAL );
362 SPGradient *vector = sp_paint_selector_get_gradient_vector(psel);
363 if (!vector) {
364 /* No vector in paint selector should mean that we just changed mode */
366 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
367 int result = objects_query_fillstroke ((GSList *) items, query, false);
368 guint32 common_rgb = 0;
369 if (result == QUERY_STYLE_MULTIPLE_SAME) {
370 if (!query->fill.isColor()) {
371 common_rgb = sp_desktop_get_color(desktop, false);
372 } else {
373 common_rgb = query->stroke.value.color.toRGBA32( 0xff );
374 }
375 vector = sp_document_default_gradient_vector(document, common_rgb);
376 }
377 sp_style_unref(query);
379 for (GSList const *i = items; i != NULL; i = i->next) {
380 if (!vector) {
381 sp_item_set_gradient(SP_ITEM(i->data),
382 sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), false),
383 gradient_type, false);
384 } else {
385 sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
386 }
387 }
388 } else {
389 vector = sp_gradient_ensure_vector_normalized(vector);
390 for (GSList const *i = items; i != NULL; i = i->next) {
391 SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
392 sp_gradient_selector_attrs_to_gradient(gr, psel);
393 }
394 }
396 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
397 _("Set gradient on stroke"));
398 }
399 break;
401 case SP_PAINT_SELECTOR_MODE_PATTERN:
403 if (items) {
405 SPPattern *pattern = sp_paint_selector_get_pattern (psel);
406 if (!pattern) {
408 /* No Pattern in paint selector should mean that we just
409 * changed mode - dont do jack.
410 */
412 } else {
413 Inkscape::XML::Node *patrepr = SP_OBJECT_REPR(pattern);
414 SPCSSAttr *css = sp_repr_css_attr_new ();
415 gchar *urltext = g_strdup_printf ("url(#%s)", patrepr->attribute("id"));
416 sp_repr_css_set_property (css, "stroke", urltext);
418 for (GSList const *i = items; i != NULL; i = i->next) {
419 Inkscape::XML::Node *selrepr = SP_OBJECT_REPR (i->data);
420 SPObject *selobj = SP_OBJECT (i->data);
421 if (!selrepr)
422 continue;
424 SPStyle *style = SP_OBJECT_STYLE (selobj);
425 if (style && style->stroke.isPaintserver()) {
426 SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (selobj);
427 if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern)
428 // only if this object's pattern is not rooted in our selected pattern, apply
429 continue;
430 }
432 sp_repr_css_change_recursive (selrepr, css, "style");
433 }
435 sp_repr_css_attr_unref (css);
436 g_free (urltext);
438 } // end if
440 sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
441 _("Set pattern on stroke"));
442 } // end if
444 break;
446 case SP_PAINT_SELECTOR_MODE_UNSET:
447 if (items) {
448 SPCSSAttr *css = sp_repr_css_attr_new ();
449 sp_repr_css_unset_property (css, "stroke");
450 sp_repr_css_unset_property (css, "stroke-opacity");
451 sp_repr_css_unset_property (css, "stroke-width");
452 sp_repr_css_unset_property (css, "stroke-miterlimit");
453 sp_repr_css_unset_property (css, "stroke-linejoin");
454 sp_repr_css_unset_property (css, "stroke-linecap");
455 sp_repr_css_unset_property (css, "stroke-dashoffset");
456 sp_repr_css_unset_property (css, "stroke-dasharray");
458 sp_desktop_set_style (desktop, css);
459 sp_repr_css_attr_unref (css);
461 sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
462 _("Unset stroke"));
463 }
464 break;
466 default:
467 g_warning( "file %s: line %d: Paint selector should not be in "
468 "mode %d",
469 __FILE__, __LINE__,
470 psel->mode );
471 break;
472 }
474 g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE));
475 }
481 /* Line */
483 static void sp_stroke_style_line_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data);
484 static void sp_stroke_style_line_selection_changed(SPWidget *spw, Inkscape::Selection *selection, gpointer data);
486 static void sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel);
488 static void sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
490 static void sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
492 static void sp_stroke_style_width_changed(Gtk::Container *spw);
493 static void sp_stroke_style_miterlimit_changed(Gtk::Container *spw);
494 static void sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw);
495 static void sp_stroke_style_line_dash_changed(Gtk::Container *spw);
497 static void sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects);
500 /**
501 * Helper function for creating radio buttons. This should probably be re-thought out
502 * when reimplementing this with Gtkmm.
503 */
504 static Gtk::RadioButton *
505 sp_stroke_radio_button(Gtk::RadioButton *tb, char const *icon,
506 Gtk::HBox *hb, Gtk::Container *spw,
507 gchar const *key, gchar const *data)
508 {
509 g_assert(icon != NULL);
510 g_assert(hb != NULL);
511 g_assert(spw != NULL);
513 if (tb == NULL) {
514 tb = new Gtk::RadioButton();
515 } else {
516 Gtk::RadioButtonGroup grp = tb->get_group();
517 tb = new Gtk::RadioButton(grp);
518 }
520 tb->show();
521 tb->set_mode(false);
522 hb->pack_start(*tb, false, false, 0);
523 spw->set_data(icon, tb);
524 tb->set_data(key, (gpointer*)data);
525 tb->signal_toggled().connect(sigc::bind<Gtk::RadioButton *, Gtk::Container *>(
526 sigc::ptr_fun(&sp_stroke_style_any_toggled), tb, spw));
527 Gtk::Widget *px = manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon)));
528 g_assert(px != NULL);
529 px->show();
530 tb->add(*px);
532 return tb;
534 }
536 static void
537 sp_stroke_style_widget_transientize_callback(Inkscape::Application */*inkscape*/,
538 SPDesktop */*desktop*/,
539 SPWidget */*spw*/ )
540 {
541 // TODO: Either of these will cause crashes sometimes
542 // sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
543 // ink_markers_menu_update(spw);
544 }
546 /**
547 * Creates a copy of the marker named mname, determines its visible and renderable
548 * area in menu_id's bounding box, and then renders it. This allows us to fill in
549 * preview images of each marker in the marker menu.
550 */
551 static Gtk::Image *
552 sp_marker_prev_new(unsigned psize, gchar const *mname,
553 SPDocument *source, SPDocument *sandbox,
554 gchar const *menu_id, NRArena const */*arena*/, unsigned /*visionkey*/, NRArenaItem *root)
555 {
556 // Retrieve the marker named 'mname' from the source SVG document
557 SPObject const *marker = source->getObjectById(mname);
558 if (marker == NULL)
559 return NULL;
561 // Create a copy repr of the marker with id="sample"
562 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sandbox);
563 Inkscape::XML::Node *mrepr = SP_OBJECT_REPR (marker)->duplicate(xml_doc);
564 mrepr->setAttribute("id", "sample");
566 // Replace the old sample in the sandbox by the new one
567 Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (sandbox->getObjectById("defs"));
568 SPObject *oldmarker = sandbox->getObjectById("sample");
569 if (oldmarker)
570 oldmarker->deleteObject(false);
571 defsrepr->appendChild(mrepr);
572 Inkscape::GC::release(mrepr);
574 // Uncomment this to get the sandbox documents saved (useful for debugging)
575 //FILE *fp = fopen (g_strconcat(menu_id, mname, ".svg", NULL), "w");
576 //sp_repr_save_stream (sp_document_repr_doc (sandbox), fp);
577 //fclose (fp);
579 // object to render; note that the id is the same as that of the menu we're building
580 SPObject *object = sandbox->getObjectById(menu_id);
581 sp_document_root (sandbox)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
582 sp_document_ensure_up_to_date(sandbox);
584 if (object == NULL || !SP_IS_ITEM(object))
585 return NULL; // sandbox broken?
587 // Find object's bbox in document
588 Geom::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
589 Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc);
591 if (!dbox) {
592 return NULL;
593 }
595 /* Update to renderable state */
596 double sf = 0.8;
598 gchar *cache_name = g_strconcat(menu_id, mname, NULL);
599 Glib::ustring key = svg_preview_cache.cache_key(source->uri, cache_name, psize);
600 g_free (cache_name);
601 // TODO: is this correct?
602 Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(svg_preview_cache.get_preview_from_cache(key));
604 if (!pixbuf) {
605 pixbuf = Glib::wrap(render_pixbuf(root, sf, *dbox, psize));
606 svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj());
607 }
609 // Create widget
610 Gtk::Image *pb = new Gtk::Image(pixbuf);
612 return pb;
613 }
615 /**
616 * Returns a list of markers in the defs of the given source document as a GSList object
617 * Returns NULL if there are no markers in the document.
618 */
619 GSList *
620 ink_marker_list_get (SPDocument *source)
621 {
622 if (source == NULL)
623 return NULL;
625 GSList *ml = NULL;
626 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS (source);
627 for ( SPObject *child = sp_object_first_child(SP_OBJECT(defs));
628 child != NULL;
629 child = SP_OBJECT_NEXT (child) )
630 {
631 if (SP_IS_MARKER(child)) {
632 ml = g_slist_prepend (ml, child);
633 }
634 }
635 return ml;
636 }
638 #define MARKER_ITEM_MARGIN 0
640 /**
641 * Adds previews of markers in marker_list to the given menu widget
642 */
643 static void
644 sp_marker_menu_build (Gtk::Menu *m, GSList *marker_list, SPDocument *source, SPDocument *sandbox, gchar const *menu_id)
645 {
646 // Do this here, outside of loop, to speed up preview generation:
647 NRArena const *arena = NRArena::create();
648 unsigned const visionkey = sp_item_display_key_new(1);
649 NRArenaItem *root = sp_item_invoke_show(SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY);
651 for (; marker_list != NULL; marker_list = marker_list->next) {
652 Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) marker_list->data);
653 Gtk::MenuItem *i = new Gtk::MenuItem();
654 i->show();
656 if (repr->attribute("inkscape:stockid"))
657 i->set_data("stockid", (void *) "true");
658 else
659 i->set_data("stockid", (void *) "false");
661 gchar const *markid = repr->attribute("id");
662 i->set_data("marker", (void *) markid);
664 Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN);
665 hb->show();
667 // generate preview
669 Gtk::Image *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root);
670 prv->show();
671 hb->pack_start(*prv, false, false, 6);
673 // create label
674 Gtk::Label *l = new Gtk::Label(repr->attribute("id"));
675 l->show();
676 l->set_alignment(0.0, 0.5);
678 hb->pack_start(*l, true, true, 0);
680 hb->show();
681 i->add(*hb);
683 m->append(*i);
684 }
686 sp_item_invoke_hide(SP_ITEM(sp_document_root(sandbox)), visionkey);
687 nr_object_unref((NRObject *) arena);
688 }
690 /**
691 * sp_marker_list_from_doc()
692 *
693 * \brief Pick up all markers from source, except those that are in
694 * current_doc (if non-NULL), and add items to the m menu
695 *
696 */
697 static void
698 sp_marker_list_from_doc (Gtk::Menu *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id)
699 {
700 GSList *ml = ink_marker_list_get(source);
701 GSList *clean_ml = NULL;
703 for (; ml != NULL; ml = ml->next) {
704 if (!SP_IS_MARKER(ml->data))
705 continue;
707 // Add to the list of markers we really do wish to show
708 clean_ml = g_slist_prepend (clean_ml, ml->data);
709 }
710 sp_marker_menu_build(m, clean_ml, source, sandbox, menu_id);
712 g_slist_free (ml);
713 g_slist_free (clean_ml);
714 }
716 /**
717 * Returns a new document containing default start, mid, and end markers.
718 */
719 SPDocument *
720 ink_markers_preview_doc ()
721 {
722 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\">"
723 " <defs id=\"defs\" />"
725 " <g id=\"marker-start\">"
726 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:url(#sample);marker-mid:none;marker-end:none\""
727 " d=\"M 12.5,13 L 25,13\" id=\"path1\" />"
728 " <rect style=\"fill:none;stroke:none\" id=\"rect2\""
729 " width=\"25\" height=\"25\" x=\"0\" y=\"0\" />"
730 " </g>"
732 " <g id=\"marker-mid\">"
733 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:url(#sample);marker-end:none\""
734 " d=\"M 0,113 L 12.5,113 L 25,113\" id=\"path11\" />"
735 " <rect style=\"fill:none;stroke:none\" id=\"rect22\""
736 " width=\"25\" height=\"25\" x=\"0\" y=\"100\" />"
737 " </g>"
739 " <g id=\"marker-end\">"
740 " <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:none;marker-end:url(#sample)\""
741 " d=\"M 0,213 L 12.5,213\" id=\"path111\" />"
742 " <rect style=\"fill:none;stroke:none\" id=\"rect222\""
743 " width=\"25\" height=\"25\" x=\"0\" y=\"200\" />"
744 " </g>"
746 "</svg>";
748 return sp_document_new_from_mem (buffer, strlen(buffer), FALSE);
749 }
751 static void
752 ink_marker_menu_create_menu(Gtk::Menu *m, gchar const *menu_id, SPDocument *doc, SPDocument *sandbox)
753 {
754 static SPDocument *markers_doc = NULL;
756 // add "None"
757 Gtk::MenuItem *i = new Gtk::MenuItem();
758 i->show();
760 i->set_data("marker", (void *) "none");
762 Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN);
763 hb->show();
765 Gtk::Label *l = new Gtk::Label( _("None") );
766 l->show();
767 l->set_alignment(0.0, 0.5);
769 hb->pack_start(*l, true, true, 0);
771 hb->show();
772 i->add(*hb);
773 m->append(*i);
775 // find and load markers.svg
776 if (markers_doc == NULL) {
777 char *markers_source = g_build_filename(INKSCAPE_MARKERSDIR, "markers.svg", NULL);
778 if (Inkscape::IO::file_test(markers_source, G_FILE_TEST_IS_REGULAR)) {
779 markers_doc = sp_document_new(markers_source, FALSE);
780 }
781 g_free(markers_source);
782 }
784 // suck in from current doc
785 sp_marker_list_from_doc(m, NULL, doc, markers_doc, sandbox, menu_id);
787 // add separator
788 {
789 //Gtk::Separator *i = gtk_separator_menu_item_new();
790 Gtk::SeparatorMenuItem *i = new Gtk::SeparatorMenuItem();
791 i->show();
792 m->append(*i);
793 }
795 // suck in from markers.svg
796 if (markers_doc) {
797 sp_document_ensure_up_to_date(doc);
798 sp_marker_list_from_doc(m, doc, markers_doc, NULL, sandbox, menu_id);
799 }
801 }
803 /**
804 * Creates a menu widget to display markers from markers.svg
805 */
806 static Gtk::OptionMenu *
807 ink_marker_menu(Gtk::Widget */*tbl*/, gchar const *menu_id, SPDocument *sandbox)
808 {
809 SPDesktop *desktop = inkscape_active_desktop();
810 SPDocument *doc = sp_desktop_document(desktop);
811 Gtk::OptionMenu *mnu = new Gtk::OptionMenu();
813 /* Create new menu widget */
814 Gtk::Menu *m = new Gtk::Menu();
815 m->show();
817 mnu->set_data("updating", (gpointer) FALSE);
819 if (!doc) {
820 Gtk::MenuItem *i = new Gtk::MenuItem(_("No document selected"));
821 i->show();
822 m->append(*i);
823 mnu->set_sensitive(false);
825 } else {
826 ink_marker_menu_create_menu(m, menu_id, doc, sandbox);
828 mnu->set_sensitive(true);
829 }
831 mnu->set_data("menu_id", const_cast<gchar *>(menu_id));
832 mnu->set_menu(*m);
834 /* Set history */
835 mnu->set_history(0);
837 return mnu;
838 }
840 /**
841 * Handles when user selects one of the markers from the marker menu.
842 * Defines a uri string to refer to it, then applies it to all selected
843 * items in the current desktop.
844 */
845 static void
846 sp_marker_select(Gtk::OptionMenu *mnu, Gtk::Container *spw, SPMarkerLoc const which)
847 {
848 if (spw->get_data("update")) {
849 return;
850 }
852 SPDesktop *desktop = inkscape_active_desktop();
853 SPDocument *document = sp_desktop_document(desktop);
854 if (!document) {
855 return;
856 }
858 /* Get Marker */
859 if (!mnu->get_menu()->get_active()->get_data("marker"))
860 {
861 return;
862 }
863 gchar *markid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("marker"));
864 gchar const *marker = "";
865 if (strcmp(markid, "none")) {
866 gchar *stockid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("stockid"));
868 gchar *markurn = markid;
869 if (!strcmp(stockid,"true")) markurn = g_strconcat("urn:inkscape:marker:",markid,NULL);
870 SPObject *mark = get_stock_item(markurn);
871 if (mark) {
872 Inkscape::XML::Node *repr = SP_OBJECT_REPR(mark);
873 marker = g_strconcat("url(#", repr->attribute("id"), ")", NULL);
874 }
875 } else {
876 marker = markid;
877 }
878 SPCSSAttr *css = sp_repr_css_attr_new();
879 gchar const *menu_id = static_cast<gchar const *>(mnu->get_data("menu_id"));
880 sp_repr_css_set_property(css, menu_id, marker);
882 // Also update the marker dropdown menus, so the document's markers
883 // show up at the top of the menu
884 // sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
885 ink_markers_menu_update(spw, which);
887 Inkscape::Selection *selection = sp_desktop_selection(desktop);
888 GSList const *items = selection->itemList();
889 for (; items != NULL; items = items->next) {
890 SPItem *item = (SPItem *) items->data;
891 if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) // can't set marker to rect, until it's converted to using <path>
892 continue;
893 Inkscape::XML::Node *selrepr = SP_OBJECT_REPR((SPItem *) items->data);
894 if (selrepr) {
895 sp_repr_css_change_recursive(selrepr, css, "style");
896 }
897 SP_OBJECT(items->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
898 SP_OBJECT(items->data)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
899 }
901 sp_repr_css_attr_unref(css);
903 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
904 _("Set markers"));
906 };
908 static unsigned int
909 ink_marker_menu_get_pos(Gtk::Menu *mnu, gchar const *markname)
910 {
911 if (markname == NULL)
912 markname = static_cast<gchar const *>(mnu->get_active()->get_data("marker"));
914 if (markname == NULL)
915 return 0;
917 std::vector<Gtk::Widget *> kids = mnu->get_children();
918 unsigned int i = 0;
919 for (; i < kids.size();) {
920 gchar const *mark = static_cast<gchar const *>(kids[i]->get_data("marker"));
921 if (mark && strcmp(mark, markname) == 0) {
922 break;
923 }
924 ++i;
925 }
927 return i;
928 }
930 static void
931 ink_markers_menu_update(Gtk::Container* /*spw*/, SPMarkerLoc const which) {
932 SPDesktop *desktop = inkscape_active_desktop();
933 SPDocument *document = sp_desktop_document(desktop);
934 SPDocument *sandbox = ink_markers_preview_doc ();
935 Gtk::Menu *m;
936 int pos;
938 // TODO: this code can be shortened by abstracting out marker_(start|mid|end)_...
939 switch (which) {
940 case SP_MARKER_LOC_START:
941 marker_start_menu_connection.block();
942 pos = ink_marker_menu_get_pos(marker_start_menu->get_menu(), NULL);
943 m = new Gtk::Menu();
944 m->show();
945 ink_marker_menu_create_menu(m, "marker-start", document, sandbox);
946 marker_start_menu->remove_menu();
947 marker_start_menu->set_menu(*m);
948 marker_start_menu->set_history(pos);
949 marker_start_menu_connection.unblock();
950 break;
952 case SP_MARKER_LOC_MID:
953 marker_mid_menu_connection.block();
954 pos = ink_marker_menu_get_pos(marker_mid_menu->get_menu(), NULL);
955 m = new Gtk::Menu();
956 m->show();
957 ink_marker_menu_create_menu(m, "marker-mid", document, sandbox);
958 marker_mid_menu->remove_menu();
959 marker_mid_menu->set_menu(*m);
960 marker_mid_menu->set_history(pos);
961 marker_mid_menu_connection.unblock();
962 break;
964 case SP_MARKER_LOC_END:
965 marker_end_menu_connection.block();
966 pos = ink_marker_menu_get_pos(marker_end_menu->get_menu(), NULL);
967 m = new Gtk::Menu();
968 m->show();
969 ink_marker_menu_create_menu(m, "marker-end", document, sandbox);
970 marker_end_menu->remove_menu();
971 marker_end_menu->set_menu(*m);
972 marker_end_menu->set_history(pos);
973 marker_end_menu_connection.unblock();
974 break;
975 default:
976 g_assert_not_reached();
977 }
978 }
980 /**
981 * Sets the stroke width units for all selected items.
982 * Also handles absolute and dimensionless units.
983 */
984 static gboolean stroke_width_set_unit(SPUnitSelector *,
985 SPUnit const *old,
986 SPUnit const *new_units,
987 Gtk::Container *spw)
988 {
989 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
991 if (!desktop) {
992 return FALSE;
993 }
995 Inkscape::Selection *selection = sp_desktop_selection (desktop);
997 if (selection->isEmpty())
998 return FALSE;
1000 GSList const *objects = selection->itemList();
1002 if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) &&
1003 (new_units->base == SP_UNIT_DIMENSIONLESS)) {
1005 /* Absolute to percentage */
1006 spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1008 Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1009 float w = sp_units_get_pixels (a->get_value(), *old);
1011 gdouble average = stroke_average_width (objects);
1013 if (average == NR_HUGE || average == 0)
1014 return FALSE;
1016 a->set_value (100.0 * w / average);
1018 spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1019 return TRUE;
1021 } else if ((old->base == SP_UNIT_DIMENSIONLESS) &&
1022 (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) {
1024 /* Percentage to absolute */
1025 spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1027 Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data ("width"));
1029 gdouble average = stroke_average_width (objects);
1031 a->set_value (sp_pixels_get_units (0.01 * a->get_value() * average, *new_units));
1033 spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1034 return TRUE;
1035 }
1037 return FALSE;
1038 }
1041 /**
1042 * \brief Creates a new widget for the line stroke style.
1043 *
1044 */
1045 Gtk::Container *
1046 sp_stroke_style_line_widget_new(void)
1047 {
1048 Gtk::Widget *us;
1049 SPDashSelector *ds;
1050 GtkWidget *us_old, *spw_old;
1051 Gtk::Container *spw;
1052 Gtk::Table *t;
1053 Gtk::Adjustment *a;
1054 Gtk::SpinButton *sb;
1055 Gtk::RadioButton *tb;
1056 Gtk::HBox *f, *hb;
1058 Gtk::Tooltips *tt = new Gtk::Tooltips();
1060 spw_old = sp_widget_new_global(INKSCAPE);
1061 spw = dynamic_cast<Gtk::Container *>(manage(Glib::wrap(spw_old)));
1063 f = new Gtk::HBox(false, 0);
1064 f->show();
1065 spw->add(*f);
1067 t = new Gtk::Table(3, 6, false);
1068 t->show();
1069 t->set_border_width(4);
1070 t->set_row_spacings(4);
1071 f->add(*t);
1072 spw->set_data("stroke", t);
1074 gint i = 0;
1076 //TRANSLATORS: only translate "string" in "context|string".
1077 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
1078 /* Stroke width */
1079 spw_label(t, Q_("StrokeWidth|Width:"), 0, i);
1081 hb = spw_hbox(t, 3, 1, i);
1083 // TODO: when this is gtkmmified, use an Inkscape::UI::Widget::ScalarUnit instead of the separate
1084 // spinbutton and unit selector for stroke width. In sp_stroke_style_line_update, use
1085 // setHundredPercent to remember the aeraged width corresponding to 100%. Then the
1086 // stroke_width_set_unit will be removed (because ScalarUnit takes care of conversions itself), and
1087 // with it, the two remaining calls of stroke_average_width, allowing us to get rid of that
1088 // function in desktop-style.
1090 a = new Gtk::Adjustment(1.0, 0.0, 1000.0, 0.1, 10.0, 0.0);
1091 spw->set_data("width", a);
1092 sb = new Gtk::SpinButton(*a, 0.1, 3);
1093 tt->set_tip(*sb, _("Stroke width"));
1094 sb->show();
1096 sp_dialog_defocus_on_enter_cpp(sb);
1098 hb->pack_start(*sb, false, false, 0);
1099 us_old = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
1100 us = manage(Glib::wrap(us_old));
1101 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1102 if (desktop)
1103 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us_old), sp_desktop_namedview(desktop)->doc_units);
1104 sp_unit_selector_add_unit(SP_UNIT_SELECTOR(us_old), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0);
1105 g_signal_connect ( G_OBJECT (us_old), "set_unit", G_CALLBACK (stroke_width_set_unit), spw );
1106 us->show();
1107 sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us_old), GTK_ADJUSTMENT(a->gobj()) );
1108 hb->pack_start(*us, FALSE, FALSE, 0);
1109 spw->set_data("units", us_old);
1111 a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_width_changed), spw));
1112 i++;
1114 /* Join type */
1115 // TRANSLATORS: The line join style specifies the shape to be used at the
1116 // corners of paths. It can be "miter", "round" or "bevel".
1117 spw_label(t, _("Join:"), 0, i);
1119 hb = spw_hbox(t, 3, 1, i);
1121 tb = NULL;
1123 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_MITER,
1124 hb, spw, "join", "miter");
1126 // TRANSLATORS: Miter join: joining lines with a sharp (pointed) corner.
1127 // For an example, draw a triangle with a large stroke width and modify the
1128 // "Join" option (in the Fill and Stroke dialog).
1129 tt->set_tip(*tb, _("Miter join"));
1130 spw->set_data("miter join", tb);
1132 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_ROUND,
1133 hb, spw, "join", "round");
1136 // TRANSLATORS: Round join: joining lines with a rounded corner.
1137 // For an example, draw a triangle with a large stroke width and modify the
1138 // "Join" option (in the Fill and Stroke dialog).
1139 tt->set_tip(*tb, _("Round join"));
1140 spw->set_data("round join", tb);
1142 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_JOIN_BEVEL,
1143 hb, spw, "join", "bevel");
1146 // TRANSLATORS: Bevel join: joining lines with a blunted (flattened) corner.
1147 // For an example, draw a triangle with a large stroke width and modify the
1148 // "Join" option (in the Fill and Stroke dialog).
1149 tt->set_tip(*tb, _("Bevel join"));
1150 spw->set_data("bevel join", tb);
1152 i++;
1154 /* Miterlimit */
1155 // TRANSLATORS: Miter limit: only for "miter join", this limits the length
1156 // of the sharp "spike" when the lines connect at too sharp an angle.
1157 // When two line segments meet at a sharp angle, a miter join results in a
1158 // spike that extends well beyond the connection point. The purpose of the
1159 // miter limit is to cut off such spikes (i.e. convert them into bevels)
1160 // when they become too long.
1161 spw_label(t, _("Miter limit:"), 0, i);
1163 hb = spw_hbox(t, 3, 1, i);
1165 a = new Gtk::Adjustment(4.0, 0.0, 100.0, 0.1, 10.0, 0.0);
1166 spw->set_data("miterlimit", a);
1168 sb = new Gtk::SpinButton(*a, 0.1, 2);
1169 tt->set_tip(*sb, _("Maximum length of the miter (in units of stroke width)"));
1170 sb->show();
1171 spw->set_data("miterlimit_sb", sb);
1172 sp_dialog_defocus_on_enter_cpp(sb);
1174 hb->pack_start(*sb, false, false, 0);
1176 a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_miterlimit_changed), spw));
1177 i++;
1179 /* Cap type */
1180 // TRANSLATORS: cap type specifies the shape for the ends of lines
1181 spw_label(t, _("Cap:"), 0, i);
1183 hb = spw_hbox(t, 3, 1, i);
1185 tb = NULL;
1187 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_BUTT,
1188 hb, spw, "cap", "butt");
1189 spw->set_data("cap butt", tb);
1191 // TRANSLATORS: Butt cap: the line shape does not extend beyond the end point
1192 // of the line; the ends of the line are square
1193 tt->set_tip(*tb, _("Butt cap"));
1195 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_ROUND,
1196 hb, spw, "cap", "round");
1197 spw->set_data("cap round", tb);
1199 // TRANSLATORS: Round cap: the line shape extends beyond the end point of the
1200 // line; the ends of the line are rounded
1201 tt->set_tip(*tb, _("Round cap"));
1203 tb = sp_stroke_radio_button(tb, INKSCAPE_ICON_STROKE_CAP_SQUARE,
1204 hb, spw, "cap", "square");
1205 spw->set_data("cap square", tb);
1207 // TRANSLATORS: Square cap: the line shape extends beyond the end point of the
1208 // line; the ends of the line are square
1209 tt->set_tip(*tb, _("Square cap"));
1211 i++;
1214 /* Dash */
1215 spw_label(t, _("Dashes:"), 0, i);
1216 ds = manage(new SPDashSelector);
1218 ds->show();
1219 t->attach(*ds, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1220 spw->set_data("dash", ds);
1221 ds->changed_signal.connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_line_dash_changed), spw));
1222 i++;
1224 /* Drop down marker selectors*/
1225 // TODO: this code can be shortened by iterating over the possible menus!
1227 // doing this here once, instead of for each preview, to speed things up
1228 SPDocument *sandbox = ink_markers_preview_doc ();
1230 // TRANSLATORS: Path markers are an SVG feature that allows you to attach arbitrary shapes
1231 // (arrowheads, bullets, faces, whatever) to the start, end, or middle nodes of a path.
1232 spw_label(t, _("Start Markers:"), 0, i);
1233 marker_start_menu = ink_marker_menu(spw ,"marker-start", sandbox);
1234 tt->set_tip(*marker_start_menu, _("Start Markers are drawn on the first node of a path or shape"));
1235 marker_start_menu_connection = marker_start_menu->signal_changed().connect(
1236 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1237 sigc::ptr_fun(&sp_marker_select), marker_start_menu, spw, SP_MARKER_LOC_START));
1238 marker_start_menu->show();
1239 t->attach(*marker_start_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1240 spw->set_data("start_mark_menu", marker_start_menu);
1242 i++;
1243 spw_label(t, _("Mid Markers:"), 0, i);
1244 marker_mid_menu = ink_marker_menu(spw ,"marker-mid", sandbox);
1245 tt->set_tip(*marker_mid_menu, _("Mid Markers are drawn on every node of a path or shape except the first and last nodes"));
1246 marker_mid_menu_connection = marker_mid_menu->signal_changed().connect(
1247 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1248 sigc::ptr_fun(&sp_marker_select), marker_mid_menu,spw, SP_MARKER_LOC_MID));
1249 marker_mid_menu->show();
1250 t->attach(*marker_mid_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1251 spw->set_data("mid_mark_menu", marker_mid_menu);
1253 i++;
1254 spw_label(t, _("End Markers:"), 0, i);
1255 marker_end_menu = ink_marker_menu(spw ,"marker-end", sandbox);
1256 tt->set_tip(*marker_end_menu, _("End Markers are drawn on the last node of a path or shape"));
1257 marker_end_menu_connection = marker_end_menu->signal_changed().connect(
1258 sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1259 sigc::ptr_fun(&sp_marker_select), marker_end_menu, spw, SP_MARKER_LOC_END));
1260 marker_end_menu->show();
1261 t->attach(*marker_end_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1262 spw->set_data("end_mark_menu", marker_end_menu);
1264 i++;
1266 // FIXME: we cheat and still use gtk+ signals
1268 gtk_signal_connect(GTK_OBJECT(spw_old), "modify_selection",
1269 GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified),
1270 spw);
1271 gtk_signal_connect(GTK_OBJECT(spw_old), "change_selection",
1272 GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed),
1273 spw);
1275 sp_stroke_style_line_update(spw, desktop ? sp_desktop_selection(desktop) : NULL);
1277 return spw;
1278 }
1280 /**
1281 * Callback for when stroke style widget is modified.
1282 * Triggers update action.
1283 */
1284 static void
1285 sp_stroke_style_line_selection_modified(SPWidget *,
1286 Inkscape::Selection *selection,
1287 guint flags,
1288 gpointer data)
1289 {
1290 Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1291 if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG)) {
1292 sp_stroke_style_line_update(spw, selection);
1293 }
1295 }
1297 /**
1298 * Callback for when stroke style widget is changed.
1299 * Triggers update action.
1300 */
1301 static void
1302 sp_stroke_style_line_selection_changed(SPWidget *,
1303 Inkscape::Selection *selection,
1304 gpointer data)
1305 {
1306 Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1307 sp_stroke_style_line_update(spw, selection);
1308 }
1310 /**
1311 * Sets selector widgets' dash style from an SPStyle object.
1312 */
1313 static void
1314 sp_dash_selector_set_from_style(SPDashSelector *dsel, SPStyle *style)
1315 {
1316 if (style->stroke_dash.n_dash > 0) {
1317 double d[64];
1318 int len = MIN(style->stroke_dash.n_dash, 64);
1319 for (int i = 0; i < len; i++) {
1320 if (style->stroke_width.computed != 0)
1321 d[i] = style->stroke_dash.dash[i] / style->stroke_width.computed;
1322 else
1323 d[i] = style->stroke_dash.dash[i]; // is there a better thing to do for stroke_width==0?
1324 }
1325 dsel->set_dash(len, d, style->stroke_width.computed != 0 ?
1326 style->stroke_dash.offset / style->stroke_width.computed :
1327 style->stroke_dash.offset);
1328 } else {
1329 dsel->set_dash(0, NULL, 0.0);
1330 }
1331 }
1333 /**
1334 * Sets the join type for a line, and updates the stroke style widget's buttons
1335 */
1336 static void
1337 sp_jointype_set (Gtk::Container *spw, unsigned const jointype)
1338 {
1339 Gtk::RadioButton *tb = NULL;
1340 switch (jointype) {
1341 case SP_STROKE_LINEJOIN_MITER:
1342 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_MITER));
1343 break;
1344 case SP_STROKE_LINEJOIN_ROUND:
1345 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_ROUND));
1346 break;
1347 case SP_STROKE_LINEJOIN_BEVEL:
1348 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_BEVEL));
1349 break;
1350 default:
1351 break;
1352 }
1353 sp_stroke_style_set_join_buttons(spw, tb);
1354 }
1356 /**
1357 * Sets the cap type for a line, and updates the stroke style widget's buttons
1358 */
1359 static void
1360 sp_captype_set (Gtk::Container *spw, unsigned const captype)
1361 {
1362 Gtk::RadioButton *tb = NULL;
1363 switch (captype) {
1364 case SP_STROKE_LINECAP_BUTT:
1365 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_BUTT));
1366 break;
1367 case SP_STROKE_LINECAP_ROUND:
1368 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_ROUND));
1369 break;
1370 case SP_STROKE_LINECAP_SQUARE:
1371 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_SQUARE));
1372 break;
1373 default:
1374 break;
1375 }
1376 sp_stroke_style_set_cap_buttons(spw, tb);
1377 }
1379 /**
1380 * Callback for when stroke style widget is updated, including markers, cap type,
1381 * join type, etc.
1382 */
1383 static void
1384 sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel)
1385 {
1386 if (spw->get_data("update")) {
1387 return;
1388 }
1390 spw->set_data("update", GINT_TO_POINTER(TRUE));
1392 Gtk::Table *sset = static_cast<Gtk::Table *>(spw->get_data("stroke"));
1393 Gtk::Adjustment *width = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1394 Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1395 SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1396 SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1398 // create temporary style
1399 SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
1400 // query into it
1401 int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
1402 int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
1403 int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP);
1404 int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
1406 if (!sel || sel->isEmpty()) {
1407 // Nothing selected, grey-out all controls in the stroke-style dialog
1408 sset->set_sensitive(false);
1410 spw->set_data("update", GINT_TO_POINTER(FALSE));
1412 return;
1413 } else {
1414 sset->set_sensitive(true);
1416 SPUnit const *unit = sp_unit_selector_get_unit(us);
1418 if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) {
1419 sp_unit_selector_set_unit(us, &sp_unit_get_by_id(SP_UNIT_PERCENT));
1420 } else {
1421 // same width, or only one object; no sense to keep percent, switch to absolute
1422 if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1423 sp_unit_selector_set_unit(us, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
1424 }
1425 }
1427 unit = sp_unit_selector_get_unit(us);
1429 if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1430 double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit);
1431 width->set_value(avgwidth);
1432 } else {
1433 width->set_value(100);
1434 }
1436 // if none of the selected objects has a stroke, than quite some controls should be disabled
1437 // The markers might still be shown though, so these will not be disabled
1438 bool enabled = (result_sw != QUERY_STYLE_NOTHING) && !query->stroke.isNoneSet();
1439 /* No objects stroked, set insensitive */
1440 Gtk::RadioButton *tb = NULL;
1441 tb = static_cast<Gtk::RadioButton *>(spw->get_data("miter join"));
1442 tb->set_sensitive(enabled);
1443 tb = static_cast<Gtk::RadioButton *>(spw->get_data("round join"));
1444 tb->set_sensitive(enabled);
1445 tb = static_cast<Gtk::RadioButton *>(spw->get_data("bevel join"));
1446 tb->set_sensitive(enabled);
1448 Gtk::SpinButton* sb = NULL;
1449 sb = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1450 sb->set_sensitive(enabled);
1452 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap butt"));
1453 tb->set_sensitive(enabled);
1454 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap round"));
1455 tb->set_sensitive(enabled);
1456 tb = static_cast<Gtk::RadioButton *>(spw->get_data("cap square"));
1457 tb->set_sensitive(enabled);
1459 dsel->set_sensitive(enabled);
1460 }
1462 if (result_ml != QUERY_STYLE_NOTHING)
1463 ml->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness?
1465 if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1466 sp_jointype_set(spw, query->stroke_linejoin.value);
1467 } else {
1468 sp_stroke_style_set_join_buttons(spw, NULL);
1469 }
1471 if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1472 sp_captype_set (spw, query->stroke_linecap.value);
1473 } else {
1474 sp_stroke_style_set_cap_buttons(spw, NULL);
1475 }
1477 sp_style_unref(query);
1479 if (!sel || sel->isEmpty())
1480 return;
1482 GSList const *objects = sel->itemList();
1483 SPObject * const object = SP_OBJECT(objects->data);
1484 SPStyle * const style = SP_OBJECT_STYLE(object);
1486 /* Markers */
1487 sp_stroke_style_update_marker_menus(spw, objects); // FIXME: make this desktop query too
1489 /* Dash */
1490 sp_dash_selector_set_from_style(dsel, style); // FIXME: make this desktop query too
1492 sset->set_sensitive(true);
1494 spw->set_data("update", GINT_TO_POINTER(FALSE));
1495 }
1497 /**
1498 * Sets a line's dash properties in a CSS style object.
1499 */
1500 static void
1501 sp_stroke_style_set_scaled_dash(SPCSSAttr *css,
1502 int ndash, double *dash, double offset,
1503 double scale)
1504 {
1505 if (ndash > 0) {
1506 Inkscape::CSSOStringStream osarray;
1507 for (int i = 0; i < ndash; i++) {
1508 osarray << dash[i] * scale;
1509 if (i < (ndash - 1)) {
1510 osarray << ",";
1511 }
1512 }
1513 sp_repr_css_set_property(css, "stroke-dasharray", osarray.str().c_str());
1515 Inkscape::CSSOStringStream osoffset;
1516 osoffset << offset * scale;
1517 sp_repr_css_set_property(css, "stroke-dashoffset", osoffset.str().c_str());
1518 } else {
1519 sp_repr_css_set_property(css, "stroke-dasharray", "none");
1520 sp_repr_css_set_property(css, "stroke-dashoffset", NULL);
1521 }
1522 }
1524 /**
1525 * Sets line properties like width, dashes, markers, etc. on all currently selected items.
1526 */
1527 static void
1528 sp_stroke_style_scale_line(Gtk::Container *spw)
1529 {
1530 if (spw->get_data("update")) {
1531 return;
1532 }
1534 spw->set_data("update", GINT_TO_POINTER(TRUE));
1536 Gtk::Adjustment *wadj = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1537 SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1538 SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1539 Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1541 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1542 SPDocument *document = sp_desktop_document (desktop);
1543 Inkscape::Selection *selection = sp_desktop_selection (desktop);
1545 GSList const *items = selection->itemList();
1547 /* TODO: Create some standardized method */
1548 SPCSSAttr *css = sp_repr_css_attr_new();
1550 if (items) {
1552 double width_typed = wadj->get_value();
1553 double const miterlimit = ml->get_value();
1555 SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us));
1557 double *dash, offset;
1558 int ndash;
1559 dsel->get_dash(&ndash, &dash, &offset);
1561 for (GSList const *i = items; i != NULL; i = i->next) {
1562 /* Set stroke width */
1563 double width;
1564 if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1565 width = sp_units_get_pixels (width_typed, *unit);
1566 } else { // percentage
1567 gdouble old_w = SP_OBJECT_STYLE (i->data)->stroke_width.computed;
1568 width = old_w * width_typed / 100;
1569 }
1571 {
1572 Inkscape::CSSOStringStream os_width;
1573 os_width << width;
1574 sp_repr_css_set_property(css, "stroke-width", os_width.str().c_str());
1575 }
1577 {
1578 Inkscape::CSSOStringStream os_ml;
1579 os_ml << miterlimit;
1580 sp_repr_css_set_property(css, "stroke-miterlimit", os_ml.str().c_str());
1581 }
1583 /* Set dash */
1584 sp_stroke_style_set_scaled_dash(css, ndash, dash, offset, width);
1586 sp_desktop_apply_css_recursive (SP_OBJECT(i->data), css, true);
1587 }
1589 g_free(dash);
1591 if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1592 // reset to 100 percent
1593 wadj->set_value(100.0);
1594 }
1596 }
1598 // we have already changed the items, so set style without changing selection
1599 // FIXME: move the above stroke-setting stuff, including percentages, to desktop-style
1600 sp_desktop_set_style (desktop, css, false);
1602 sp_repr_css_attr_unref(css);
1604 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
1605 _("Set stroke style"));
1607 spw->set_data("update", GINT_TO_POINTER(FALSE));
1608 }
1610 /**
1611 * Callback for when the stroke style's width changes.
1612 * Causes all line styles to be applied to all selected items.
1613 */
1614 static void
1615 sp_stroke_style_width_changed(Gtk::Container *spw)
1616 {
1617 if (spw->get_data("update")) {
1618 return;
1619 }
1621 sp_stroke_style_scale_line(spw);
1622 }
1624 /**
1625 * Callback for when the stroke style's miterlimit changes.
1626 * Causes all line styles to be applied to all selected items.
1627 */
1628 static void
1629 sp_stroke_style_miterlimit_changed(Gtk::Container *spw)
1630 {
1631 if (spw->get_data("update")) {
1632 return;
1633 }
1635 sp_stroke_style_scale_line(spw);
1636 }
1638 /**
1639 * Callback for when the stroke style's dash changes.
1640 * Causes all line styles to be applied to all selected items.
1641 */
1643 static void
1644 sp_stroke_style_line_dash_changed(Gtk::Container *spw)
1645 {
1646 if (spw->get_data("update")) {
1647 return;
1648 }
1650 sp_stroke_style_scale_line(spw);
1651 }
1653 /**
1654 * \brief This routine handles toggle events for buttons in the stroke style
1655 * dialog.
1656 * When activated, this routine gets the data for the various widgets, and then
1657 * calls the respective routines to update css properties, etc.
1658 *
1659 */
1660 static void
1661 sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw)
1662 {
1663 if (spw->get_data("update")) {
1664 return;
1665 }
1667 if (tb->get_active()) {
1669 gchar const *join
1670 = static_cast<gchar const *>(tb->get_data("join"));
1671 gchar const *cap
1672 = static_cast<gchar const *>(tb->get_data("cap"));
1674 if (join) {
1675 Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1676 ml->set_sensitive(!strcmp(join, "miter"));
1677 }
1679 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1681 /* TODO: Create some standardized method */
1682 SPCSSAttr *css = sp_repr_css_attr_new();
1684 if (join) {
1685 sp_repr_css_set_property(css, "stroke-linejoin", join);
1687 sp_desktop_set_style (desktop, css);
1689 sp_stroke_style_set_join_buttons(spw, tb);
1690 } else if (cap) {
1691 sp_repr_css_set_property(css, "stroke-linecap", cap);
1693 sp_desktop_set_style (desktop, css);
1695 sp_stroke_style_set_cap_buttons(spw, tb);
1696 }
1698 sp_repr_css_attr_unref(css);
1700 sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_FILL_STROKE,
1701 _("Set stroke style"));
1702 }
1703 }
1705 /**
1706 * Updates the join style toggle buttons
1707 */
1708 static void
1709 sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1710 {
1711 Gtk::RadioButton *tb;
1713 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_MITER));
1714 tb->set_active(active == tb);
1716 Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1717 ml->set_sensitive(active == tb);
1719 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_ROUND));
1720 tb->set_active(active == tb);
1722 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_JOIN_BEVEL));
1723 tb->set_active(active == tb);
1724 }
1726 /**
1727 * Updates the cap style toggle buttons
1728 */
1729 static void
1730 sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1731 {
1732 Gtk::RadioButton *tb;
1734 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_BUTT));
1735 tb->set_active(active == tb);
1736 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_ROUND));
1737 tb->set_active(active == tb);
1738 tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_ICON_STROKE_CAP_SQUARE));
1739 tb->set_active(active == tb);
1740 }
1742 /**
1743 * Sets the current marker in the marker menu.
1744 */
1745 static void
1746 ink_marker_menu_set_current(SPObject *marker, Gtk::OptionMenu *mnu)
1747 {
1748 mnu->set_data("update", GINT_TO_POINTER(TRUE));
1750 Gtk::Menu *m = mnu->get_menu();
1751 if (marker != NULL) {
1752 bool mark_is_stock = false;
1753 if (SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"))
1754 mark_is_stock = true;
1756 gchar *markname;
1757 if (mark_is_stock)
1758 markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"));
1759 else
1760 markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("id"));
1762 int markpos = ink_marker_menu_get_pos(m, markname);
1763 mnu->set_history(markpos);
1765 g_free (markname);
1766 }
1767 else {
1768 mnu->set_history(0);
1769 }
1770 mnu->set_data("update", GINT_TO_POINTER(FALSE));
1771 }
1773 /**
1774 * Updates the marker menus to highlight the appropriate marker and scroll to
1775 * that marker.
1776 */
1777 static void
1778 sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects)
1779 {
1780 struct { char const *key; int loc; } const keyloc[] = {
1781 { "start_mark_menu", SP_MARKER_LOC_START },
1782 { "mid_mark_menu", SP_MARKER_LOC_MID },
1783 { "end_mark_menu", SP_MARKER_LOC_END }
1784 };
1786 bool all_texts = true;
1787 for (GSList *i = (GSList *) objects; i != NULL; i = i->next) {
1788 if (!SP_IS_TEXT (i->data)) {
1789 all_texts = false;
1790 }
1791 }
1793 for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1794 Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1795 // Per SVG spec, text objects cannot have markers; disable menus if only texts are selected
1796 mnu->set_sensitive(!all_texts);
1797 }
1799 // We show markers of the first object in the list only
1800 // FIXME: use the first in the list that has the marker of each type, if any
1801 SPObject *object = SP_OBJECT(objects->data);
1803 for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1804 // For all three marker types,
1806 // find the corresponding menu
1807 Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1809 // Quit if we're in update state
1810 if (mnu->get_data("update")) {
1811 return;
1812 }
1814 if (object->style->marker[keyloc[i].loc].value != NULL && !all_texts) {
1815 // If the object has this type of markers,
1817 // Extract the name of the marker that the object uses
1818 SPObject *marker = ink_extract_marker_name(object->style->marker[keyloc[i].loc].value, SP_OBJECT_DOCUMENT(object));
1819 // Scroll the menu to that marker
1820 ink_marker_menu_set_current(marker, mnu);
1822 } else {
1823 mnu->set_history(0);
1824 }
1825 }
1826 }
1829 /**
1830 * Extract the actual name of the link
1831 * e.g. get mTriangle from url(#mTriangle).
1832 * \return Buffer containing the actual name, allocated from GLib;
1833 * the caller should free the buffer when they no longer need it.
1834 */
1835 static SPObject*
1836 ink_extract_marker_name(gchar const *n, SPDocument *doc)
1837 {
1838 gchar const *p = n;
1839 while (*p != '\0' && *p != '#') {
1840 p++;
1841 }
1843 if (*p == '\0' || p[1] == '\0') {
1844 return NULL;
1845 }
1847 p++;
1848 int c = 0;
1849 while (p[c] != '\0' && p[c] != ')') {
1850 c++;
1851 }
1853 if (p[c] == '\0') {
1854 return NULL;
1855 }
1857 gchar* b = g_strdup(p);
1858 b[c] = '\0';
1860 // FIXME: get the document from the object and let the caller pass it in
1861 SPObject *marker = doc->getObjectById(b);
1862 return marker;
1863 }
1865 /*
1866 Local Variables:
1867 mode:c++
1868 c-file-style:"stroustrup"
1869 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1870 indent-tabs-mode:nil
1871 fill-column:99
1872 End:
1873 */
1874 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :