Code

Merge from trunk
[inkscape.git] / src / dialogs / stroke-style.cpp
1 #define __SP_STROKE_STYLE_C__
3 /**
4  * \brief  Stroke style dialog
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Bryce Harrington <brycehar@bryceharrington.org>
9  *   bulia byak <buliabyak@users.sf.net>
10  *   Maximilian Albert <maximilian.albert@gmail.com>
11  *   Josh Andler <scislac@users.sf.net>
12  *
13  * Copyright (C) 2001-2005 authors
14  * Copyright (C) 2001 Ximian, Inc.
15  * Copyright (C) 2004 John Cliff
16  * Copyright (C) 2008 Maximilian Albert (gtkmm-ification)
17  *
18  * Released under GNU GPL, read the file 'COPYING' for more information
19  */
21 #define noSP_SS_VERBOSE
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
29 #include <glib/gmem.h>
30 #include <gtk/gtk.h>
32 #include <glibmm/i18n.h>
33 #include "helper/unit-menu.h"
34 #include "helper/units.h"
35 #include "svg/css-ostringstream.h"
36 #include "widgets/sp-widget.h"
37 #include "widgets/spw-utilities.h"
38 #include "sp-linear-gradient.h"
39 #include "sp-radial-gradient.h"
40 #include "marker.h"
41 #include "sp-pattern.h"
42 #include "widgets/paint-selector.h"
43 #include "widgets/dash-selector.h"
44 #include "style.h"
45 #include "gradient-chemistry.h"
46 #include "sp-namedview.h"
47 #include "desktop-handles.h"
48 #include "desktop-style.h"
49 #include "selection.h"
50 #include "inkscape.h"
51 #include "inkscape-stock.h"
52 #include "dialogs/dialog-events.h"
53 #include "sp-text.h"
54 #include "sp-rect.h"
55 #include "document-private.h"
56 #include "display/nr-arena.h"
57 #include "display/nr-arena-item.h"
58 #include "path-prefix.h"
59 #include "widgets/icon.h"
60 #include "helper/stock-items.h"
61 #include "io/sys.h"
62 #include "ui/cache/svg_preview_cache.h"
63 #include "xml/repr.h"
65 #include "dialogs/stroke-style.h"
68 /* Paint */
70 static void sp_stroke_style_paint_selection_modified (SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel);
71 static void sp_stroke_style_paint_selection_changed (SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel);
72 static void sp_stroke_style_paint_update(SPWidget *spw);
74 static void sp_stroke_style_paint_mode_changed(SPPaintSelector *psel, SPPaintSelectorMode mode, SPWidget *spw);
75 static void sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw);
76 static void sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw);
78 static void sp_stroke_style_widget_change_subselection ( Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw );
79 static void sp_stroke_style_widget_transientize_callback(Inkscape::Application *inkscape,
80                                                          SPDesktop *desktop,
81                                                          SPWidget *spw );
83 /** Marker selection option menus */
84 static Gtk::OptionMenu * marker_start_menu = NULL;
85 static Gtk::OptionMenu * marker_mid_menu = NULL;
86 static Gtk::OptionMenu * marker_end_menu = NULL;
88 sigc::connection marker_start_menu_connection;
89 sigc::connection marker_mid_menu_connection;
90 sigc::connection marker_end_menu_connection;
92 static SPObject *ink_extract_marker_name(gchar const *n, SPDocument *doc);
93 static void      ink_markers_menu_update(Gtk::Container* spw, SPMarkerLoc const which);
95 static Inkscape::UI::Cache::SvgPreview svg_preview_cache;
97 /**
98  * Create the stroke style widget, and hook up all the signals.
99  */
100 GtkWidget *
101 sp_stroke_style_paint_widget_new(void)
103     GtkWidget *spw, *psel;
105     spw = sp_widget_new_global(INKSCAPE);
107     psel = sp_paint_selector_new(false); // without fillrule selector
108     gtk_widget_show(psel);
109     gtk_container_add(GTK_CONTAINER(spw), psel);
110     gtk_object_set_data(GTK_OBJECT(spw), "paint-selector", psel);
112     gtk_signal_connect(GTK_OBJECT(spw), "modify_selection",
113                        GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_modified),
114                        psel);
115     gtk_signal_connect(GTK_OBJECT(spw), "change_selection",
116                        GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_changed),
117                        psel);
119     g_signal_connect (INKSCAPE, "change_subselection", G_CALLBACK (sp_stroke_style_widget_change_subselection), spw);
121     g_signal_connect (G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK (sp_stroke_style_widget_transientize_callback), spw );
123     gtk_signal_connect(GTK_OBJECT(psel), "mode_changed",
124                        GTK_SIGNAL_FUNC(sp_stroke_style_paint_mode_changed),
125                        spw);
126     gtk_signal_connect(GTK_OBJECT(psel), "dragged",
127                        GTK_SIGNAL_FUNC(sp_stroke_style_paint_dragged),
128                        spw);
129     gtk_signal_connect(GTK_OBJECT(psel), "changed",
130                        GTK_SIGNAL_FUNC(sp_stroke_style_paint_changed),
131                        spw);
133     sp_stroke_style_paint_update (SP_WIDGET(spw));
134     return spw;
137 /**
138  * On signal modified, invokes an update of the stroke style paint object.
139  */
140 static void
141 sp_stroke_style_paint_selection_modified( SPWidget *spw,
142                                           Inkscape::Selection */*selection*/,
143                                           guint flags,
144                                           SPPaintSelector */*psel*/ )
146     if (flags & ( SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG |
147                   SP_OBJECT_STYLE_MODIFIED_FLAG) ) {
148         sp_stroke_style_paint_update(spw);
149     }
153 /**
154  * On signal selection changed, invokes an update of the stroke style paint object.
155  */
156 static void
157 sp_stroke_style_paint_selection_changed( SPWidget *spw,
158                                          Inkscape::Selection */*selection*/,
159                                          SPPaintSelector */*psel*/ )
161     sp_stroke_style_paint_update (spw);
165 /**
166  * On signal change subselection, invoke an update of the stroke style widget.
167  */
168 static void
169 sp_stroke_style_widget_change_subselection( Inkscape::Application */*inkscape*/,
170                                             SPDesktop */*desktop*/,
171                                             SPWidget *spw )
173     sp_stroke_style_paint_update (spw);
176 /**
177  * Gets the active stroke style property, then sets the appropriate color, alpha, gradient,
178  * pattern, etc. for the paint-selector.
179  */
180 static void
181 sp_stroke_style_paint_update (SPWidget *spw)
183     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
184         return;
185     }
187     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
189     SPPaintSelector *psel = SP_PAINT_SELECTOR(gtk_object_get_data(GTK_OBJECT(spw), "paint-selector"));
191     // create temporary style
192     SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
193     // query into it
194     int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKE);
196     switch (result) {
197         case QUERY_STYLE_NOTHING:
198         {
199             /* No paint at all */
200             sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_EMPTY);
201             break;
202         }
204         case QUERY_STYLE_SINGLE:
205         case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector
206         case QUERY_STYLE_MULTIPLE_SAME:
207         {
208             SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, false);
209             sp_paint_selector_set_mode (psel, pselmode);
211             if (query->stroke.set && query->stroke.isPaintserver()) {
213                 SPPaintServer *server = SP_STYLE_STROKE_SERVER (query);
215                 if (SP_IS_LINEARGRADIENT (server)) {
216                     SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
217                     sp_paint_selector_set_gradient_linear (psel, vector);
219                     SPLinearGradient *lg = SP_LINEARGRADIENT (server);
220                     sp_paint_selector_set_gradient_properties (psel,
221                                                        SP_GRADIENT_UNITS (lg),
222                                                        SP_GRADIENT_SPREAD (lg));
223                 } else if (SP_IS_RADIALGRADIENT (server)) {
224                     SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
225                     sp_paint_selector_set_gradient_radial (psel, vector);
227                     SPRadialGradient *rg = SP_RADIALGRADIENT (server);
228                     sp_paint_selector_set_gradient_properties (psel,
229                                                        SP_GRADIENT_UNITS (rg),
230                                                        SP_GRADIENT_SPREAD (rg));
231                 } else if (SP_IS_PATTERN (server)) {
232                     SPPattern *pat = pattern_getroot (SP_PATTERN (server));
233                     sp_update_pattern_list (psel, pat);
234                 }
235             } else if (query->stroke.set && query->stroke.isColor()) {
236                 sp_paint_selector_set_color_alpha (psel, &query->stroke.value.color, SP_SCALE24_TO_FLOAT (query->stroke_opacity.value));
238             }
239             break;
240         }
242         case QUERY_STYLE_MULTIPLE_DIFFERENT:
243         {
244             sp_paint_selector_set_mode (psel, SP_PAINT_SELECTOR_MODE_MULTIPLE);
245             break;
246         }
247     }
249     sp_style_unref(query);
251     gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
254 /**
255  * When the mode is changed, invoke a regular changed handler.
256  */
257 static void
258 sp_stroke_style_paint_mode_changed( SPPaintSelector *psel,
259                                     SPPaintSelectorMode /*mode*/,
260                                     SPWidget *spw )
262     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
263         return;
264     }
266     /* TODO: Does this work?
267      * Not really, here we have to get old color back from object
268      * Instead of relying on paint widget having meaningful colors set
269      */
270     sp_stroke_style_paint_changed(psel, spw);
273 static gchar const *const undo_label_1 = "stroke:flatcolor:1";
274 static gchar const *const undo_label_2 = "stroke:flatcolor:2";
275 static gchar const *undo_label = undo_label_1;
277 /**
278  * When a drag callback occurs on a paint selector object, if it is a RGB or CMYK
279  * color mode, then set the stroke opacity to psel's flat color.
280  */
281 static void
282 sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw)
284     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
285         return;
286     }
288     switch (psel->mode) {
289         case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
290         case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
291         {
292             sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity");
293             sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE,
294                                     _("Set stroke color"));
295             break;
296         }
298         default:
299             g_warning( "file %s: line %d: Paint %d should not emit 'dragged'",
300                        __FILE__, __LINE__, psel->mode);
301             break;
302     }
305 /**
306  * When the stroke style's paint settings change, this handler updates the
307  * repr's stroke css style and applies the style to relevant drawing items.
308  */
309 static void
310 sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw)
312     if (gtk_object_get_data(GTK_OBJECT(spw), "update")) {
313         return;
314     }
315     g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE));
317     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
318     SPDocument *document = sp_desktop_document (desktop);
319     Inkscape::Selection *selection = sp_desktop_selection (desktop);
321     GSList const *items = selection->itemList();
323     switch (psel->mode) {
324         case SP_PAINT_SELECTOR_MODE_EMPTY:
325             // This should not happen.
326             g_warning ( "file %s: line %d: Paint %d should not emit 'changed'",
327                         __FILE__, __LINE__, psel->mode);
328             break;
329         case SP_PAINT_SELECTOR_MODE_MULTIPLE:
330             // This happens when you switch multiple objects with different gradients to flat color;
331             // nothing to do here.
332             break;
334         case SP_PAINT_SELECTOR_MODE_NONE:
335         {
336             SPCSSAttr *css = sp_repr_css_attr_new();
337             sp_repr_css_set_property(css, "stroke", "none");
339             sp_desktop_set_style (desktop, css);
341             sp_repr_css_attr_unref(css);
343             sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
344                              _("Remove stroke"));
345             break;
346         }
348         case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
349         case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
350         {
351             sp_paint_selector_set_flat_color (psel, desktop, "stroke", "stroke-opacity");
352             sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE,
353                                     _("Set stroke color"));
355             // on release, toggle undo_label so that the next drag will not be lumped with this one
356             if (undo_label == undo_label_1)
357                 undo_label = undo_label_2;
358             else
359                 undo_label = undo_label_1;
361             break;
362         }
364         case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR:
365         case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL:
366             if (items) {
367                 SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR
368                                                        ? SP_GRADIENT_TYPE_LINEAR
369                                                        : SP_GRADIENT_TYPE_RADIAL );
370                 SPGradient *vector = sp_paint_selector_get_gradient_vector(psel);
371                 if (!vector) {
372                     /* No vector in paint selector should mean that we just changed mode */
374                     SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
375                     int result = objects_query_fillstroke ((GSList *) items, query, false);
376                     guint32 common_rgb = 0;
377                     if (result == QUERY_STYLE_MULTIPLE_SAME) {
378                         if (!query->fill.isColor()) {
379                             common_rgb = sp_desktop_get_color(desktop, false);
380                         } else {
381                             common_rgb = query->stroke.value.color.toRGBA32( 0xff );
382                         }
383                         vector = sp_document_default_gradient_vector(document, common_rgb);
384                     }
385                     sp_style_unref(query);
387                     for (GSList const *i = items; i != NULL; i = i->next) {
388                         if (!vector) {
389                             sp_item_set_gradient(SP_ITEM(i->data),
390                                                  sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), false),
391                                                  gradient_type, false);
392                         } else {
393                             sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
394                         }
395                     }
396                 } else {
397                     vector = sp_gradient_ensure_vector_normalized(vector);
398                     for (GSList const *i = items; i != NULL; i = i->next) {
399                         SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false);
400                         sp_gradient_selector_attrs_to_gradient(gr, psel);
401                     }
402                 }
404                 sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
405                                  _("Set gradient on stroke"));
406             }
407             break;
409         case SP_PAINT_SELECTOR_MODE_PATTERN:
411             if (items) {
413                 SPPattern *pattern = sp_paint_selector_get_pattern (psel);
414                 if (!pattern) {
416                     /* No Pattern in paint selector should mean that we just
417                      * changed mode - dont do jack.
418                      */
420                 } else {
421                     Inkscape::XML::Node *patrepr = SP_OBJECT_REPR(pattern);
422                     SPCSSAttr *css = sp_repr_css_attr_new ();
423                     gchar *urltext = g_strdup_printf ("url(#%s)", patrepr->attribute("id"));
424                     sp_repr_css_set_property (css, "stroke", urltext);
426                     for (GSList const *i = items; i != NULL; i = i->next) {
427                          Inkscape::XML::Node *selrepr = SP_OBJECT_REPR (i->data);
428                          SPObject *selobj = SP_OBJECT (i->data);
429                          if (!selrepr)
430                              continue;
432                          SPStyle *style = SP_OBJECT_STYLE (selobj);
433                          if (style && style->stroke.isPaintserver()) {
434                              SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (selobj);
435                              if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern)
436                                  // only if this object's pattern is not rooted in our selected pattern, apply
437                                  continue;
438                          }
440                          sp_repr_css_change_recursive (selrepr, css, "style");
441                      }
443                     sp_repr_css_attr_unref (css);
444                     g_free (urltext);
446                 } // end if
448                 sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
449                                   _("Set pattern on stroke"));
450             } // end if
452             break;
454         case SP_PAINT_SELECTOR_MODE_UNSET:
455             if (items) {
456                     SPCSSAttr *css = sp_repr_css_attr_new ();
457                     sp_repr_css_unset_property (css, "stroke");
458                     sp_repr_css_unset_property (css, "stroke-opacity");
459                     sp_repr_css_unset_property (css, "stroke-width");
460                     sp_repr_css_unset_property (css, "stroke-miterlimit");
461                     sp_repr_css_unset_property (css, "stroke-linejoin");
462                     sp_repr_css_unset_property (css, "stroke-linecap");
463                     sp_repr_css_unset_property (css, "stroke-dashoffset");
464                     sp_repr_css_unset_property (css, "stroke-dasharray");
466                     sp_desktop_set_style (desktop, css);
467                     sp_repr_css_attr_unref (css);
469                     sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE,
470                                       _("Unset stroke"));
471             }
472             break;
474         default:
475             g_warning( "file %s: line %d: Paint selector should not be in "
476                        "mode %d",
477                        __FILE__, __LINE__,
478                        psel->mode );
479             break;
480     }
482     g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE));
489 /* Line */
491 static void sp_stroke_style_line_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data);
492 static void sp_stroke_style_line_selection_changed(SPWidget *spw, Inkscape::Selection *selection, gpointer data);
494 static void sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel);
496 static void sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
498 static void sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active);
500 static void sp_stroke_style_width_changed(Gtk::Container *spw);
501 static void sp_stroke_style_miterlimit_changed(Gtk::Container *spw);
502 static void sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw);
503 static void sp_stroke_style_line_dash_changed(Gtk::Container *spw);
505 static void sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects);
508 /**
509  * Helper function for creating radio buttons.  This should probably be re-thought out
510  * when reimplementing this with Gtkmm.
511  */
512 static Gtk::RadioButton *
513 sp_stroke_radio_button(Gtk::RadioButton *tb, char const *icon,
514                        Gtk::HBox *hb, Gtk::Container *spw,
515                        gchar const *key, gchar const *data)
517     g_assert(icon != NULL);
518     g_assert(hb  != NULL);
519     g_assert(spw != NULL);
521     if (tb == NULL) {
522         tb = new Gtk::RadioButton();
523     } else {
524         Gtk::RadioButtonGroup grp = tb->get_group();
525         tb = new Gtk::RadioButton(grp);
526     }
528     tb->show();
529     tb->set_mode(false);
530     hb->pack_start(*tb, false, false, 0);
531     spw->set_data(icon, tb);
532     tb->set_data(key, (gpointer*)data);
533     tb->signal_toggled().connect(sigc::bind<Gtk::RadioButton *, Gtk::Container *>(
534                                      sigc::ptr_fun(&sp_stroke_style_any_toggled), tb, spw));
535     Gtk::Widget *px = manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon)));
536     g_assert(px != NULL);
537     px->show();
538     tb->add(*px);
540     return tb;
544 static void
545 sp_stroke_style_widget_transientize_callback(Inkscape::Application */*inkscape*/,
546                                              SPDesktop */*desktop*/,
547                                              SPWidget */*spw*/ )
549 // TODO:  Either of these will cause crashes sometimes
550 //    sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
551 //    ink_markers_menu_update(spw);
554 /**
555  * Creates a copy of the marker named mname, determines its visible and renderable
556  * area in menu_id's bounding box, and then renders it.  This allows us to fill in
557  * preview images of each marker in the marker menu.
558  */
559 static Gtk::Image *
560 sp_marker_prev_new(unsigned psize, gchar const *mname,
561                    SPDocument *source, SPDocument *sandbox,
562                    gchar const *menu_id, NRArena const */*arena*/, unsigned /*visionkey*/, NRArenaItem *root)
564     // Retrieve the marker named 'mname' from the source SVG document
565     SPObject const *marker = source->getObjectById(mname);
566     if (marker == NULL)
567         return NULL;
569     // Create a copy repr of the marker with id="sample"
570     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sandbox);
571     Inkscape::XML::Node *mrepr = SP_OBJECT_REPR (marker)->duplicate(xml_doc);
572     mrepr->setAttribute("id", "sample");
574     // Replace the old sample in the sandbox by the new one
575     Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (sandbox->getObjectById("defs"));
576     SPObject *oldmarker = sandbox->getObjectById("sample");
577     if (oldmarker)
578         oldmarker->deleteObject(false);
579     defsrepr->appendChild(mrepr);
580     Inkscape::GC::release(mrepr);
582 // Uncomment this to get the sandbox documents saved (useful for debugging)
583     //FILE *fp = fopen (g_strconcat(menu_id, mname, ".svg", NULL), "w");
584     //sp_repr_save_stream (sp_document_repr_doc (sandbox), fp);
585     //fclose (fp);
587     // object to render; note that the id is the same as that of the menu we're building
588     SPObject *object = sandbox->getObjectById(menu_id);
589     sp_document_root (sandbox)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
590     sp_document_ensure_up_to_date(sandbox);
592     if (object == NULL || !SP_IS_ITEM(object))
593         return NULL; // sandbox broken?
595     // Find object's bbox in document
596     Geom::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
597     boost::optional<Geom::Rect> dbox = SP_ITEM(object)->getBounds(i2doc);
599     if (!dbox) {
600         return NULL;
601     }
603     /* Update to renderable state */
604     double sf = 0.8;
606     gchar *cache_name = g_strconcat(menu_id, mname, NULL);
607     Glib::ustring key = svg_preview_cache.cache_key(source->uri, cache_name, psize);
608     g_free (cache_name);
609     // TODO: is this correct?
610     Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(svg_preview_cache.get_preview_from_cache(key));
612     if (!pixbuf) {
613         pixbuf = Glib::wrap(render_pixbuf(root, sf, *dbox, psize));
614         svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj());
615     }
617     // Create widget
618     Gtk::Image *pb = new Gtk::Image(pixbuf);
620     return pb;
623 /**
624  *  Returns a list of markers in the defs of the given source document as a GSList object
625  *  Returns NULL if there are no markers in the document.
626  */
627 GSList *
628 ink_marker_list_get (SPDocument *source)
630     if (source == NULL)
631         return NULL;
633     GSList *ml   = NULL;
634     SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS (source);
635     for ( SPObject *child = sp_object_first_child(SP_OBJECT(defs));
636           child != NULL;
637           child = SP_OBJECT_NEXT (child) )
638     {
639         if (SP_IS_MARKER(child)) {
640             ml = g_slist_prepend (ml, child);
641         }
642     }
643     return ml;
646 #define MARKER_ITEM_MARGIN 0
648 /**
649  * Adds previews of markers in marker_list to the given menu widget
650  */
651 static void
652 sp_marker_menu_build (Gtk::Menu *m, GSList *marker_list, SPDocument *source, SPDocument *sandbox, gchar const *menu_id)
654     // Do this here, outside of loop, to speed up preview generation:
655     NRArena const *arena = NRArena::create();
656     unsigned const visionkey = sp_item_display_key_new(1);
657     NRArenaItem *root =  sp_item_invoke_show(SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY);
659     for (; marker_list != NULL; marker_list = marker_list->next) {
660         Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) marker_list->data);
661         Gtk::MenuItem *i = new Gtk::MenuItem();
662         i->show();
664         if (repr->attribute("inkscape:stockid"))
665             i->set_data("stockid", (void *) "true");
666         else
667             i->set_data("stockid", (void *) "false");
669         gchar const *markid = repr->attribute("id");
670         i->set_data("marker", (void *) markid);
672         Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN);
673         hb->show();
675         // generate preview
677         Gtk::Image *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root);
678         prv->show();
679         hb->pack_start(*prv, false, false, 6);
681         // create label
682         Gtk::Label *l = new Gtk::Label(repr->attribute("id"));
683         l->show();
684         l->set_alignment(0.0, 0.5);
686         hb->pack_start(*l, true, true, 0);
688         hb->show();
689         i->add(*hb);
691         m->append(*i);
692     }
694     sp_item_invoke_hide(SP_ITEM(sp_document_root(sandbox)), visionkey);
695     nr_object_unref((NRObject *) arena);
698 /**
699  * sp_marker_list_from_doc()
700  *
701  * \brief Pick up all markers from source, except those that are in
702  * current_doc (if non-NULL), and add items to the m menu
703  *
704  */
705 static void
706 sp_marker_list_from_doc (Gtk::Menu *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id)
708     GSList *ml = ink_marker_list_get(source);
709     GSList *clean_ml = NULL;
711     for (; ml != NULL; ml = ml->next) {
712         if (!SP_IS_MARKER(ml->data))
713             continue;
715         // Add to the list of markers we really do wish to show
716         clean_ml = g_slist_prepend (clean_ml, ml->data);
717     }
718     sp_marker_menu_build(m, clean_ml, source, sandbox, menu_id);
720     g_slist_free (ml);
721     g_slist_free (clean_ml);
724 /**
725  * Returns a new document containing default start, mid, and end markers.
726  */
727 SPDocument *
728 ink_markers_preview_doc ()
730 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\">"
731 "  <defs id=\"defs\" />"
733 "  <g id=\"marker-start\">"
734 "    <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:url(#sample);marker-mid:none;marker-end:none\""
735 "       d=\"M 12.5,13 L 25,13\" id=\"path1\" />"
736 "    <rect style=\"fill:none;stroke:none\" id=\"rect2\""
737 "       width=\"25\" height=\"25\" x=\"0\" y=\"0\" />"
738 "  </g>"
740 "  <g id=\"marker-mid\">"
741 "    <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:url(#sample);marker-end:none\""
742 "       d=\"M 0,113 L 12.5,113 L 25,113\" id=\"path11\" />"
743 "    <rect style=\"fill:none;stroke:none\" id=\"rect22\""
744 "       width=\"25\" height=\"25\" x=\"0\" y=\"100\" />"
745 "  </g>"
747 "  <g id=\"marker-end\">"
748 "    <path style=\"fill:none;stroke:black;stroke-width:1.7;marker-start:none;marker-mid:none;marker-end:url(#sample)\""
749 "       d=\"M 0,213 L 12.5,213\" id=\"path111\" />"
750 "    <rect style=\"fill:none;stroke:none\" id=\"rect222\""
751 "       width=\"25\" height=\"25\" x=\"0\" y=\"200\" />"
752 "  </g>"
754 "</svg>";
756     return sp_document_new_from_mem (buffer, strlen(buffer), FALSE);
759 static void
760 ink_marker_menu_create_menu(Gtk::Menu *m, gchar const *menu_id, SPDocument *doc, SPDocument *sandbox)
762     static SPDocument *markers_doc = NULL;
764     // add "None"
765     Gtk::MenuItem *i = new Gtk::MenuItem();
766     i->show();
768     i->set_data("marker", (void *) "none");
770     Gtk::HBox *hb = new Gtk::HBox(false,  MARKER_ITEM_MARGIN);
771     hb->show();
773     Gtk::Label *l = new Gtk::Label( _("None") );
774     l->show();
775     l->set_alignment(0.0, 0.5);
777     hb->pack_start(*l, true, true, 0);
779     hb->show();
780     i->add(*hb);
781     m->append(*i);
783     // find and load markers.svg
784     if (markers_doc == NULL) {
785         char *markers_source = g_build_filename(INKSCAPE_MARKERSDIR, "markers.svg", NULL);
786         if (Inkscape::IO::file_test(markers_source, G_FILE_TEST_IS_REGULAR)) {
787             markers_doc = sp_document_new(markers_source, FALSE);
788         }
789         g_free(markers_source);
790     }
792     // suck in from current doc
793     sp_marker_list_from_doc(m, NULL, doc, markers_doc, sandbox, menu_id);
795     // add separator
796     {
797         //Gtk::Separator *i = gtk_separator_menu_item_new();
798         Gtk::SeparatorMenuItem *i = new Gtk::SeparatorMenuItem();
799         i->show();
800         m->append(*i);
801     }
803     // suck in from markers.svg
804     if (markers_doc) {
805         sp_document_ensure_up_to_date(doc);
806         sp_marker_list_from_doc(m, doc, markers_doc, NULL, sandbox, menu_id);
807     }
811 /**
812  * Creates a menu widget to display markers from markers.svg
813  */
814 static Gtk::OptionMenu *
815 ink_marker_menu(Gtk::Widget */*tbl*/, gchar const *menu_id, SPDocument *sandbox)
817     SPDesktop *desktop = inkscape_active_desktop();
818     SPDocument *doc = sp_desktop_document(desktop);
819     Gtk::OptionMenu *mnu = new Gtk::OptionMenu();
821     /* Create new menu widget */
822     Gtk::Menu *m = new Gtk::Menu();
823     m->show();
825     mnu->set_data("updating", (gpointer) FALSE);
827     if (!doc) {
828         Gtk::MenuItem *i = new Gtk::MenuItem(_("No document selected"));
829         i->show();
830         m->append(*i);
831         mnu->set_sensitive(false);
833     } else {
834         ink_marker_menu_create_menu(m, menu_id, doc, sandbox);
836         mnu->set_sensitive(true);
837     }
839     mnu->set_data("menu_id", const_cast<gchar *>(menu_id));
840     mnu->set_menu(*m);
842     /* Set history */
843     mnu->set_history(0);
845     return mnu;
848 /**
849  * Handles when user selects one of the markers from the marker menu.
850  * Defines a uri string to refer to it, then applies it to all selected
851  * items in the current desktop.
852  */
853 static void
854 sp_marker_select(Gtk::OptionMenu *mnu, Gtk::Container *spw, SPMarkerLoc const which)
856     if (spw->get_data("update")) {
857         return;
858     }
860     SPDesktop *desktop = inkscape_active_desktop();
861     SPDocument *document = sp_desktop_document(desktop);
862     if (!document) {
863         return;
864     }
866     /* Get Marker */
867     if (!mnu->get_menu()->get_active()->get_data("marker"))
868     {
869         return;
870     }
871     gchar *markid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("marker"));
872     gchar const *marker = "";
873     if (strcmp(markid, "none")) {
874        gchar *stockid = static_cast<gchar *>(mnu->get_menu()->get_active()->get_data("stockid"));
876        gchar *markurn = markid;
877        if (!strcmp(stockid,"true")) markurn = g_strconcat("urn:inkscape:marker:",markid,NULL);
878        SPObject *mark = get_stock_item(markurn);
879        if (mark) {
880             Inkscape::XML::Node *repr = SP_OBJECT_REPR(mark);
881             marker = g_strconcat("url(#", repr->attribute("id"), ")", NULL);
882         }
883     } else {
884         marker = markid;
885     }
886     SPCSSAttr *css = sp_repr_css_attr_new();
887     gchar const *menu_id = static_cast<gchar const *>(mnu->get_data("menu_id"));
888     sp_repr_css_set_property(css, menu_id, marker);
890     // Also update the marker dropdown menus, so the document's markers
891     // show up at the top of the menu
892 //    sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
893     ink_markers_menu_update(spw, which);
895     Inkscape::Selection *selection = sp_desktop_selection(desktop);
896     GSList const *items = selection->itemList();
897     for (; items != NULL; items = items->next) {
898          SPItem *item = (SPItem *) items->data;
899          if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) // can't set marker to rect, until it's converted to using <path>
900              continue;
901          Inkscape::XML::Node *selrepr = SP_OBJECT_REPR((SPItem *) items->data);
902          if (selrepr) {
903              sp_repr_css_change_recursive(selrepr, css, "style");
904          }
905          SP_OBJECT(items->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
906          SP_OBJECT(items->data)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
907      }
909     sp_repr_css_attr_unref(css);
911     sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
912                      _("Set markers"));
914 };
916 static unsigned int
917 ink_marker_menu_get_pos(Gtk::Menu *mnu, gchar const *markname)
919     if (markname == NULL)
920         markname = static_cast<gchar const *>(mnu->get_active()->get_data("marker"));
922     if (markname == NULL)
923         return 0;
925     std::vector<Gtk::Widget *> kids = mnu->get_children();
926     unsigned int i = 0;
927     for (; i < kids.size();) {
928         gchar const *mark = static_cast<gchar const *>(kids[i]->get_data("marker"));
929         if (mark && strcmp(mark, markname) == 0) {
930             break;
931         }
932         ++i;
933     }
935     return i;
938 static void
939 ink_markers_menu_update(Gtk::Container* /*spw*/, SPMarkerLoc const which) {
940     SPDesktop  *desktop = inkscape_active_desktop();
941     SPDocument *document = sp_desktop_document(desktop);
942     SPDocument *sandbox = ink_markers_preview_doc ();
943     Gtk::Menu  *m;
944     int        pos;
946     // TODO: this code can be shortened by abstracting out marker_(start|mid|end)_...
947     switch (which) {
948         case SP_MARKER_LOC_START:
949             marker_start_menu_connection.block();
950             pos = ink_marker_menu_get_pos(marker_start_menu->get_menu(), NULL);
951             m = new Gtk::Menu();
952             m->show();
953             ink_marker_menu_create_menu(m, "marker-start", document, sandbox);
954             marker_start_menu->remove_menu();
955             marker_start_menu->set_menu(*m);
956             marker_start_menu->set_history(pos);
957             marker_start_menu_connection.unblock();
958             break;
960         case SP_MARKER_LOC_MID:
961             marker_mid_menu_connection.block();
962             pos = ink_marker_menu_get_pos(marker_mid_menu->get_menu(), NULL);
963             m = new Gtk::Menu();
964             m->show();
965             ink_marker_menu_create_menu(m, "marker-mid", document, sandbox);
966             marker_mid_menu->remove_menu();
967             marker_mid_menu->set_menu(*m);
968             marker_mid_menu->set_history(pos);
969             marker_mid_menu_connection.unblock();
970             break;
972         case SP_MARKER_LOC_END:
973             marker_end_menu_connection.block();
974             pos = ink_marker_menu_get_pos(marker_end_menu->get_menu(), NULL);
975             m = new Gtk::Menu();
976             m->show();
977             ink_marker_menu_create_menu(m, "marker-end", document, sandbox);
978             marker_end_menu->remove_menu();
979             marker_end_menu->set_menu(*m);
980             marker_end_menu->set_history(pos);
981             marker_end_menu_connection.unblock();
982             break;
983         default:
984             g_assert_not_reached();
985     }
988 /**
989  * Sets the stroke width units for all selected items.
990  * Also handles absolute and dimensionless units.
991  */
992 static gboolean stroke_width_set_unit(SPUnitSelector *,
993                                       SPUnit const *old,
994                                       SPUnit const *new_units,
995                                       Gtk::Container *spw)
997     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
999     if (!desktop) {
1000         return FALSE;
1001     }
1003     Inkscape::Selection *selection = sp_desktop_selection (desktop);
1005     if (selection->isEmpty())
1006         return FALSE;
1008     GSList const *objects = selection->itemList();
1010     if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) &&
1011        (new_units->base == SP_UNIT_DIMENSIONLESS)) {
1013         /* Absolute to percentage */
1014         spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1016         Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1017         float w = sp_units_get_pixels (a->get_value(), *old);
1019         gdouble average = stroke_average_width (objects);
1021         if (average == NR_HUGE || average == 0)
1022             return FALSE;
1024         a->set_value (100.0 * w / average);
1026         spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1027         return TRUE;
1029     } else if ((old->base == SP_UNIT_DIMENSIONLESS) &&
1030               (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) {
1032         /* Percentage to absolute */
1033         spw->set_data ("update", GUINT_TO_POINTER (TRUE));
1035         Gtk::Adjustment *a = static_cast<Gtk::Adjustment *>(spw->get_data ("width"));
1037         gdouble average = stroke_average_width (objects);
1039         a->set_value (sp_pixels_get_units (0.01 * a->get_value() * average, *new_units));
1041         spw->set_data ("update", GUINT_TO_POINTER (FALSE));
1042         return TRUE;
1043     }
1045     return FALSE;
1049 /**
1050  * \brief  Creates a new widget for the line stroke style.
1051  *
1052  */
1053 Gtk::Container *
1054 sp_stroke_style_line_widget_new(void)
1056     Gtk::Widget *us;
1057     SPDashSelector *ds;
1058     GtkWidget *us_old, *spw_old;
1059     Gtk::Container *spw;
1060     Gtk::Table *t;
1061     Gtk::Adjustment *a;
1062     Gtk::SpinButton *sb;
1063     Gtk::RadioButton *tb;
1064     Gtk::HBox *f, *hb;
1066     Gtk::Tooltips *tt = new Gtk::Tooltips();
1068     spw_old = sp_widget_new_global(INKSCAPE);
1069     spw = dynamic_cast<Gtk::Container *>(manage(Glib::wrap(spw_old)));
1071     f = new Gtk::HBox(false, 0);
1072     f->show();
1073     spw->add(*f);
1075     t = new Gtk::Table(3, 6, false);
1076     t->show();
1077     t->set_border_width(4);
1078     t->set_row_spacings(4);
1079     f->add(*t);
1080     spw->set_data("stroke", t);
1082     gint i = 0;
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, 10.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_STOCK_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"));
1137     tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_JOIN_ROUND,
1138                                 hb, spw, "join", "round");
1140     // TRANSLATORS: Round join: joining lines with a rounded corner.
1141     //  For an example, draw a triangle with a large stroke width and modify the
1142     //  "Join" option (in the Fill and Stroke dialog).
1143     tt->set_tip(*tb, _("Round join"));
1145     tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_JOIN_BEVEL,
1146                                 hb, spw, "join", "bevel");
1148     // TRANSLATORS: Bevel join: joining lines with a blunted (flattened) corner.
1149     //  For an example, draw a triangle with a large stroke width and modify the
1150     //  "Join" option (in the Fill and Stroke dialog).
1151     tt->set_tip(*tb, _("Bevel join"));
1153     i++;
1155     /* Miterlimit  */
1156     // TRANSLATORS: Miter limit: only for "miter join", this limits the length
1157     //  of the sharp "spike" when the lines connect at too sharp an angle.
1158     // When two line segments meet at a sharp angle, a miter join results in a
1159     //  spike that extends well beyond the connection point. The purpose of the
1160     //  miter limit is to cut off such spikes (i.e. convert them into bevels)
1161     //  when they become too long.
1162     spw_label(t, _("Miter limit:"), 0, i);
1164     hb = spw_hbox(t, 3, 1, i);
1166     a = new Gtk::Adjustment(4.0, 0.0, 100.0, 0.1, 10.0, 10.0);
1167     spw->set_data("miterlimit", a);
1169     sb = new Gtk::SpinButton(*a, 0.1, 2);
1170     tt->set_tip(*sb, _("Maximum length of the miter (in units of stroke width)"));
1171     sb->show();
1172     spw->set_data("miterlimit_sb", sb);
1173     sp_dialog_defocus_on_enter_cpp(sb);
1175     hb->pack_start(*sb, false, false, 0);
1177     a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_miterlimit_changed), spw));
1178     i++;
1180     /* Cap type */
1181     // TRANSLATORS: cap type specifies the shape for the ends of lines
1182     spw_label(t, _("Cap:"), 0, i);
1184     hb = spw_hbox(t, 3, 1, i);
1186     tb = NULL;
1188     tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_CAP_BUTT,
1189                                 hb, spw, "cap", "butt");
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_STOCK_CAP_ROUND,
1196                                 hb, spw, "cap", "round");
1198     // TRANSLATORS: Round cap: the line shape extends beyond the end point of the
1199     //  line; the ends of the line are rounded
1200     tt->set_tip(*tb, _("Round cap"));
1202     tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_CAP_SQUARE,
1203                                 hb, spw, "cap", "square");
1205     // TRANSLATORS: Square cap: the line shape extends beyond the end point of the
1206     //  line; the ends of the line are square
1207     tt->set_tip(*tb, _("Square cap"));
1209     i++;
1212     /* Dash */
1213     spw_label(t, _("Dashes:"), 0, i);
1214     ds = manage(new SPDashSelector);
1216     ds->show();
1217     t->attach(*ds, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1218     spw->set_data("dash", ds);
1219     ds->changed_signal.connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_line_dash_changed), spw));
1220     i++;
1222     /* Drop down marker selectors*/
1223     // TODO: this code can be shortened by iterating over the possible menus!
1225     // doing this here once, instead of for each preview, to speed things up
1226     SPDocument *sandbox = ink_markers_preview_doc ();
1228     // TRANSLATORS: Path markers are an SVG feature that allows you to attach arbitrary shapes
1229     // (arrowheads, bullets, faces, whatever) to the start, end, or middle nodes of a path.
1230     spw_label(t, _("Start Markers:"), 0, i);
1231     marker_start_menu = ink_marker_menu(spw ,"marker-start", sandbox);
1232     tt->set_tip(*marker_start_menu, _("Start Markers are drawn on the first node of a path or shape"));
1233     marker_start_menu_connection = marker_start_menu->signal_changed().connect(
1234         sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1235             sigc::ptr_fun(&sp_marker_select), marker_start_menu, spw, SP_MARKER_LOC_START));
1236     marker_start_menu->show();
1237     t->attach(*marker_start_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1238     spw->set_data("start_mark_menu", marker_start_menu);
1240     i++;
1241     spw_label(t, _("Mid Markers:"), 0, i);
1242     marker_mid_menu = ink_marker_menu(spw ,"marker-mid", sandbox);
1243     tt->set_tip(*marker_mid_menu, _("Mid Markers are drawn on every node of a path or shape except the first and last nodes"));
1244     marker_mid_menu_connection = marker_mid_menu->signal_changed().connect(
1245         sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1246             sigc::ptr_fun(&sp_marker_select), marker_mid_menu,spw, SP_MARKER_LOC_MID));
1247     marker_mid_menu->show();
1248     t->attach(*marker_mid_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1249     spw->set_data("mid_mark_menu", marker_mid_menu);
1251     i++;
1252     spw_label(t, _("End Markers:"), 0, i);
1253     marker_end_menu = ink_marker_menu(spw ,"marker-end", sandbox);
1254     tt->set_tip(*marker_end_menu, _("End Markers are drawn on the last node of a path or shape"));
1255     marker_end_menu_connection = marker_end_menu->signal_changed().connect(
1256         sigc::bind<Gtk::OptionMenu *, Gtk::Container *, SPMarkerLoc>(
1257             sigc::ptr_fun(&sp_marker_select), marker_end_menu, spw, SP_MARKER_LOC_END));
1258     marker_end_menu->show();
1259     t->attach(*marker_end_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast<Gtk::AttachOptions>(0), 0, 0);
1260     spw->set_data("end_mark_menu", marker_end_menu);
1262     i++;
1264     // FIXME: we cheat and still use gtk+ signals
1266     gtk_signal_connect(GTK_OBJECT(spw_old), "modify_selection",
1267                        GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified),
1268                        spw);
1269     gtk_signal_connect(GTK_OBJECT(spw_old), "change_selection",
1270                        GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed),
1271                        spw);
1273     sp_stroke_style_line_update(spw, desktop ? sp_desktop_selection(desktop) : NULL);
1275     return spw;
1278 /**
1279  * Callback for when stroke style widget is modified.
1280  * Triggers update action.
1281  */
1282 static void
1283 sp_stroke_style_line_selection_modified(SPWidget *,
1284                                         Inkscape::Selection *selection,
1285                                         guint flags,
1286                                         gpointer data)
1288     Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1289     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG)) {
1290         sp_stroke_style_line_update(spw, selection);
1291     }
1295 /**
1296  * Callback for when stroke style widget is changed.
1297  * Triggers update action.
1298  */
1299 static void
1300 sp_stroke_style_line_selection_changed(SPWidget *,
1301                                        Inkscape::Selection *selection,
1302                                        gpointer data)
1304     Gtk::Container *spw = static_cast<Gtk::Container *>(data);
1305     sp_stroke_style_line_update(spw, selection);
1308 /**
1309  * Sets selector widgets' dash style from an SPStyle object.
1310  */
1311 static void
1312 sp_dash_selector_set_from_style(SPDashSelector *dsel, SPStyle *style)
1314     if (style->stroke_dash.n_dash > 0) {
1315         double d[64];
1316         int len = MIN(style->stroke_dash.n_dash, 64);
1317         for (int i = 0; i < len; i++) {
1318             if (style->stroke_width.computed != 0)
1319                 d[i] = style->stroke_dash.dash[i] / style->stroke_width.computed;
1320             else
1321                 d[i] = style->stroke_dash.dash[i]; // is there a better thing to do for stroke_width==0?
1322         }
1323         dsel->set_dash(len, d, style->stroke_width.computed != 0 ?
1324                        style->stroke_dash.offset / style->stroke_width.computed  :
1325                        style->stroke_dash.offset);
1326     } else {
1327         dsel->set_dash(0, NULL, 0.0);
1328     }
1331 /**
1332  * Sets the join type for a line, and updates the stroke style widget's buttons
1333  */
1334 static void
1335 sp_jointype_set (Gtk::Container *spw, unsigned const jointype)
1337     Gtk::RadioButton *tb = NULL;
1338     switch (jointype) {
1339         case SP_STROKE_LINEJOIN_MITER:
1340             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_MITER));
1341             break;
1342         case SP_STROKE_LINEJOIN_ROUND:
1343             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_ROUND));
1344             break;
1345         case SP_STROKE_LINEJOIN_BEVEL:
1346             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_BEVEL));
1347             break;
1348         default:
1349             break;
1350     }
1351     sp_stroke_style_set_join_buttons(spw, tb);
1354 /**
1355  * Sets the cap type for a line, and updates the stroke style widget's buttons
1356  */
1357 static void
1358 sp_captype_set (Gtk::Container *spw, unsigned const captype)
1360     Gtk::RadioButton *tb = NULL;
1361     switch (captype) {
1362         case SP_STROKE_LINECAP_BUTT:
1363             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_BUTT));
1364             break;
1365         case SP_STROKE_LINECAP_ROUND:
1366             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_ROUND));
1367             break;
1368         case SP_STROKE_LINECAP_SQUARE:
1369             tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_SQUARE));
1370             break;
1371         default:
1372             break;
1373     }
1374     sp_stroke_style_set_cap_buttons(spw, tb);
1377 /**
1378  * Callback for when stroke style widget is updated, including markers, cap type,
1379  * join type, etc.
1380  */
1381 static void
1382 sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel)
1384     if (spw->get_data("update")) {
1385         return;
1386     }
1388     spw->set_data("update", GINT_TO_POINTER(TRUE));
1390     Gtk::Table *sset = static_cast<Gtk::Table *>(spw->get_data("stroke"));
1391     Gtk::Adjustment *width = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1392     Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1393     SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1394     SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1396     // create temporary style
1397     SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
1398     // query into it
1399     int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
1400     int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
1401     int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP);
1402     int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
1404     if (result_sw == QUERY_STYLE_NOTHING) {
1405         /* No objects stroked, set insensitive */
1406         sset->set_sensitive(false);
1408         spw->set_data("update", GINT_TO_POINTER(FALSE));
1409         return;
1410     } else {
1411         sset->set_sensitive(true);
1413         SPUnit const *unit = sp_unit_selector_get_unit(us);
1415         if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) {
1416             sp_unit_selector_set_unit(us, &sp_unit_get_by_id(SP_UNIT_PERCENT));
1417         } else {
1418             // same width, or only one object; no sense to keep percent, switch to absolute
1419             if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1420                 sp_unit_selector_set_unit(us, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
1421             }
1422         }
1424         unit = sp_unit_selector_get_unit(us);
1426         if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1427             double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit);
1428             width->set_value(avgwidth);
1429         } else {
1430             width->set_value(100);
1431         }
1432     }
1434     if (result_ml != QUERY_STYLE_NOTHING)
1435         ml->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness?
1437     if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1438         sp_jointype_set(spw, query->stroke_linejoin.value);
1439     } else {
1440         sp_stroke_style_set_join_buttons(spw, NULL);
1441     }
1443     if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT) {
1444         sp_captype_set (spw, query->stroke_linecap.value);
1445     } else {
1446         sp_stroke_style_set_cap_buttons(spw, NULL);
1447     }
1449     sp_style_unref(query);
1451     if (!sel || sel->isEmpty())
1452         return;
1454     GSList const *objects = sel->itemList();
1455     SPObject * const object = SP_OBJECT(objects->data);
1456     SPStyle * const style = SP_OBJECT_STYLE(object);
1458     /* Markers */
1459     sp_stroke_style_update_marker_menus(spw, objects); // FIXME: make this desktop query too
1461     /* Dash */
1462     sp_dash_selector_set_from_style(dsel, style); // FIXME: make this desktop query too
1464     sset->set_sensitive(true);
1466     spw->set_data("update", GINT_TO_POINTER(FALSE));
1469 /**
1470  * Sets a line's dash properties in a CSS style object.
1471  */
1472 static void
1473 sp_stroke_style_set_scaled_dash(SPCSSAttr *css,
1474                                 int ndash, double *dash, double offset,
1475                                 double scale)
1477     if (ndash > 0) {
1478         Inkscape::CSSOStringStream osarray;
1479         for (int i = 0; i < ndash; i++) {
1480             osarray << dash[i] * scale;
1481             if (i < (ndash - 1)) {
1482                 osarray << ",";
1483             }
1484         }
1485         sp_repr_css_set_property(css, "stroke-dasharray", osarray.str().c_str());
1487         Inkscape::CSSOStringStream osoffset;
1488         osoffset << offset * scale;
1489         sp_repr_css_set_property(css, "stroke-dashoffset", osoffset.str().c_str());
1490     } else {
1491         sp_repr_css_set_property(css, "stroke-dasharray", "none");
1492         sp_repr_css_set_property(css, "stroke-dashoffset", NULL);
1493     }
1496 /**
1497  * Sets line properties like width, dashes, markers, etc. on all currently selected items.
1498  */
1499 static void
1500 sp_stroke_style_scale_line(Gtk::Container *spw)
1502     if (spw->get_data("update")) {
1503         return;
1504     }
1506     spw->set_data("update", GINT_TO_POINTER(TRUE));
1508     Gtk::Adjustment *wadj = static_cast<Gtk::Adjustment *>(spw->get_data("width"));
1509     SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units"));
1510     SPDashSelector *dsel = static_cast<SPDashSelector *>(spw->get_data("dash"));
1511     Gtk::Adjustment *ml = static_cast<Gtk::Adjustment *>(spw->get_data("miterlimit"));
1513     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1514     SPDocument *document = sp_desktop_document (desktop);
1515     Inkscape::Selection *selection = sp_desktop_selection (desktop);
1517     GSList const *items = selection->itemList();
1519     /* TODO: Create some standardized method */
1520     SPCSSAttr *css = sp_repr_css_attr_new();
1522     if (items) {
1524         double width_typed = wadj->get_value();
1525         double const miterlimit = ml->get_value();
1527         SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us));
1529         double *dash, offset;
1530         int ndash;
1531         dsel->get_dash(&ndash, &dash, &offset);
1533         for (GSList const *i = items; i != NULL; i = i->next) {
1534             /* Set stroke width */
1535             double width;
1536             if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
1537                 width = sp_units_get_pixels (width_typed, *unit);
1538             } else { // percentage
1539                 gdouble old_w = SP_OBJECT_STYLE (i->data)->stroke_width.computed;
1540                 width = old_w * width_typed / 100;
1541             }
1543             {
1544                 Inkscape::CSSOStringStream os_width;
1545                 os_width << width;
1546                 sp_repr_css_set_property(css, "stroke-width", os_width.str().c_str());
1547             }
1549             {
1550                 Inkscape::CSSOStringStream os_ml;
1551                 os_ml << miterlimit;
1552                 sp_repr_css_set_property(css, "stroke-miterlimit", os_ml.str().c_str());
1553             }
1555             /* Set dash */
1556             sp_stroke_style_set_scaled_dash(css, ndash, dash, offset, width);
1558             sp_desktop_apply_css_recursive (SP_OBJECT(i->data), css, true);
1559         }
1561         g_free(dash);
1563         if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
1564             // reset to 100 percent
1565             wadj->set_value(100.0);
1566         }
1568     }
1570     // we have already changed the items, so set style without changing selection
1571     // FIXME: move the above stroke-setting stuff, including percentages, to desktop-style
1572     sp_desktop_set_style (desktop, css, false);
1574     sp_repr_css_attr_unref(css);
1576     sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
1577                      _("Set stroke style"));
1579     spw->set_data("update", GINT_TO_POINTER(FALSE));
1582 /**
1583  * Callback for when the stroke style's width changes.
1584  * Causes all line styles to be applied to all selected items.
1585  */
1586 static void
1587 sp_stroke_style_width_changed(Gtk::Container *spw)
1589     if (spw->get_data("update")) {
1590         return;
1591     }
1593     sp_stroke_style_scale_line(spw);
1596 /**
1597  * Callback for when the stroke style's miterlimit changes.
1598  * Causes all line styles to be applied to all selected items.
1599  */
1600 static void
1601 sp_stroke_style_miterlimit_changed(Gtk::Container *spw)
1603     if (spw->get_data("update")) {
1604         return;
1605     }
1607     sp_stroke_style_scale_line(spw);
1610 /**
1611  * Callback for when the stroke style's dash changes.
1612  * Causes all line styles to be applied to all selected items.
1613  */
1615 static void
1616 sp_stroke_style_line_dash_changed(Gtk::Container *spw)
1618     if (spw->get_data("update")) {
1619         return;
1620     }
1622     sp_stroke_style_scale_line(spw);
1625 /**
1626  * \brief  This routine handles toggle events for buttons in the stroke style
1627  *         dialog.
1628  * When activated, this routine gets the data for the various widgets, and then
1629  * calls the respective routines to update css properties, etc.
1630  *
1631  */
1632 static void
1633 sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw)
1635     if (spw->get_data("update")) {
1636         return;
1637     }
1639     if (tb->get_active()) {
1641         gchar const *join
1642             = static_cast<gchar const *>(tb->get_data("join"));
1643         gchar const *cap
1644             = static_cast<gchar const *>(tb->get_data("cap"));
1646         if (join) {
1647             Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1648             ml->set_sensitive(!strcmp(join, "miter"));
1649         }
1651         SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1653         /* TODO: Create some standardized method */
1654         SPCSSAttr *css = sp_repr_css_attr_new();
1656         if (join) {
1657             sp_repr_css_set_property(css, "stroke-linejoin", join);
1659             sp_desktop_set_style (desktop, css);
1661             sp_stroke_style_set_join_buttons(spw, tb);
1662         } else if (cap) {
1663             sp_repr_css_set_property(css, "stroke-linecap", cap);
1665             sp_desktop_set_style (desktop, css);
1667             sp_stroke_style_set_cap_buttons(spw, tb);
1668         }
1670         sp_repr_css_attr_unref(css);
1672         sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_FILL_STROKE,
1673                          _("Set stroke style"));
1674     }
1677 /**
1678  * Updates the join style toggle buttons
1679  */
1680 static void
1681 sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1683     Gtk::RadioButton *tb;
1685     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_MITER));
1686     tb->set_active(active == tb);
1688     Gtk::SpinButton *ml = static_cast<Gtk::SpinButton *>(spw->get_data("miterlimit_sb"));
1689     ml->set_sensitive(active == tb);
1691     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_ROUND));
1692     tb->set_active(active == tb);
1694     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_JOIN_BEVEL));
1695     tb->set_active(active == tb);
1698 /**
1699  * Updates the cap style toggle buttons
1700  */
1701 static void
1702 sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active)
1704     Gtk::RadioButton *tb;
1706     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_BUTT));
1707     tb->set_active(active == tb);
1708     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_ROUND));
1709     tb->set_active(active == tb);
1710     tb = static_cast<Gtk::RadioButton *>(spw->get_data(INKSCAPE_STOCK_CAP_SQUARE));
1711     tb->set_active(active == tb);
1714 /**
1715  * Sets the current marker in the marker menu.
1716  */
1717 static void
1718 ink_marker_menu_set_current(SPObject *marker, Gtk::OptionMenu *mnu)
1720     mnu->set_data("update", GINT_TO_POINTER(TRUE));
1722     Gtk::Menu *m = mnu->get_menu();
1723     if (marker != NULL) {
1724         bool mark_is_stock = false;
1725         if (SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"))
1726             mark_is_stock = true;
1728         gchar *markname;
1729         if (mark_is_stock)
1730             markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("inkscape:stockid"));
1731         else
1732             markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("id"));
1734         int markpos = ink_marker_menu_get_pos(m, markname);
1735         mnu->set_history(markpos);
1737         g_free (markname);
1738     }
1739     else {
1740         mnu->set_history(0);
1741     }
1742     mnu->set_data("update", GINT_TO_POINTER(FALSE));
1745 /**
1746  * Updates the marker menus to highlight the appropriate marker and scroll to
1747  * that marker.
1748  */
1749 static void
1750 sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects)
1752     struct { char const *key; int loc; } const keyloc[] = {
1753         { "start_mark_menu", SP_MARKER_LOC_START },
1754         { "mid_mark_menu", SP_MARKER_LOC_MID },
1755         { "end_mark_menu", SP_MARKER_LOC_END }
1756     };
1758     bool all_texts = true;
1759     for (GSList *i = (GSList *) objects; i != NULL; i = i->next) {
1760         if (!SP_IS_TEXT (i->data)) {
1761             all_texts = false;
1762         }
1763     }
1765     for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1766         Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1767         // Per SVG spec, text objects cannot have markers; disable menus if only texts are selected
1768         mnu->set_sensitive(!all_texts);
1769     }
1771     // We show markers of the first object in the list only
1772     // FIXME: use the first in the list that has the marker of each type, if any
1773     SPObject *object = SP_OBJECT(objects->data);
1775     for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) {
1776         // For all three marker types,
1778         // find the corresponding menu
1779         Gtk::OptionMenu *mnu = static_cast<Gtk::OptionMenu *>(spw->get_data(keyloc[i].key));
1781         // Quit if we're in update state
1782         if (mnu->get_data("update")) {
1783             return;
1784         }
1786         if (object->style->marker[keyloc[i].loc].value != NULL && !all_texts) {
1787             // If the object has this type of markers,
1789             // Extract the name of the marker that the object uses
1790             SPObject *marker = ink_extract_marker_name(object->style->marker[keyloc[i].loc].value, SP_OBJECT_DOCUMENT(object));
1791             // Scroll the menu to that marker
1792             ink_marker_menu_set_current(marker, mnu);
1794         } else {
1795             mnu->set_history(0);
1796         }
1797     }
1801 /**
1802  * Extract the actual name of the link
1803  * e.g. get mTriangle from url(#mTriangle).
1804  * \return Buffer containing the actual name, allocated from GLib;
1805  * the caller should free the buffer when they no longer need it.
1806  */
1807 static SPObject*
1808 ink_extract_marker_name(gchar const *n, SPDocument *doc)
1810     gchar const *p = n;
1811     while (*p != '\0' && *p != '#') {
1812         p++;
1813     }
1815     if (*p == '\0' || p[1] == '\0') {
1816         return NULL;
1817     }
1819     p++;
1820     int c = 0;
1821     while (p[c] != '\0' && p[c] != ')') {
1822         c++;
1823     }
1825     if (p[c] == '\0') {
1826         return NULL;
1827     }
1829     gchar* b = g_strdup(p);
1830     b[c] = '\0';
1832     // FIXME: get the document from the object and let the caller pass it in
1833     SPObject *marker = doc->getObjectById(b);
1834     return marker;
1838 /*
1839   Local Variables:
1840   mode:c++
1841   c-file-style:"stroustrup"
1842   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1843   indent-tabs-mode:nil
1844   fill-column:99
1845   End:
1846 */
1847 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :