From 34b7a09e4015b0689b4e7e6385ab695ee40a7e75 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sat, 9 Aug 2008 23:23:12 +0000 Subject: [PATCH] gtkmm-ify the 'Stroke style' tab of Fill and Stroke dialog --- src/dialogs/dialog-events.cpp | 28 +- src/dialogs/dialog-events.h | 9 + src/dialogs/stroke-style.cpp | 816 ++++++++++++++---------------- src/dialogs/stroke-style.h | 2 +- src/ui/dialog/fill-and-stroke.cpp | 4 +- src/widgets/Makefile_insert | 2 + src/widgets/dash-selector.cpp | 578 ++++++++++----------- src/widgets/dash-selector.h | 44 +- src/widgets/spw-utilities.cpp | 45 +- src/widgets/spw-utilities.h | 25 +- 10 files changed, 780 insertions(+), 773 deletions(-) diff --git a/src/dialogs/dialog-events.cpp b/src/dialogs/dialog-events.cpp index 3443a6ccb..dc9f4ac2a 100644 --- a/src/dialogs/dialog-events.cpp +++ b/src/dialogs/dialog-events.cpp @@ -27,6 +27,8 @@ #include "dialog-events.h" +#include + /** * \brief This function is called to zero the transientize semaphore by a @@ -45,6 +47,19 @@ sp_allow_again (gpointer *wd) * \brief Remove focus from window to whoever it is transient for... * */ +void +sp_dialog_defocus_cpp (Gtk::Window *win) +{ + Gtk::Window *w; + //find out the document window we're transient for + w = win->get_transient_for(); + + //switch to it + if (w) { + w->present(); + } +} + void sp_dialog_defocus (GtkWindow *win) { @@ -59,11 +74,16 @@ sp_dialog_defocus (GtkWindow *win) } - /** * \brief Callback to defocus a widget's parent dialog. * */ +void +sp_dialog_defocus_callback_cpp (Gtk::Entry *e) +{ + sp_dialog_defocus_cpp(dynamic_cast(e->get_toplevel())); +} + void sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data) { @@ -73,6 +93,12 @@ sp_dialog_defocus_callback (GtkWindow */*win*/, gpointer data) +void +sp_dialog_defocus_on_enter_cpp (Gtk::Entry *e) +{ + e->signal_activate().connect(sigc::bind(sigc::ptr_fun(&sp_dialog_defocus_callback_cpp), e)); +} + void sp_dialog_defocus_on_enter (GtkWidget *w) { diff --git a/src/dialogs/dialog-events.h b/src/dialogs/dialog-events.h index 7cc64c6a2..46cbc7a67 100644 --- a/src/dialogs/dialog-events.h +++ b/src/dialogs/dialog-events.h @@ -24,6 +24,11 @@ * stop is the transientize semaphore: when 0, retransientizing this dialog * is allowed */ + +namespace Gtk { +class Window; +class Entry; +} typedef struct { GtkWidget *win; @@ -35,6 +40,10 @@ gboolean sp_dialog_event_handler ( GtkWindow *win, GdkEvent *event, gpointer data ); +void sp_dialog_defocus_cpp (Gtk::Window *win); +void sp_dialog_defocus_callback_cpp(Gtk::Entry *e); +void sp_dialog_defocus_on_enter_cpp(Gtk::Entry *e); + void sp_dialog_defocus ( GtkWindow *win ); void sp_dialog_defocus_callback ( GtkWindow *win, gpointer data ); void sp_dialog_defocus_on_enter ( GtkWidget *w ); diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp index 373ee5832..fe23516ba 100644 --- a/src/dialogs/stroke-style.cpp +++ b/src/dialogs/stroke-style.cpp @@ -7,10 +7,12 @@ * Lauris Kaplinski * Bryce Harrington * bulia byak + * Maximilian Albert * * Copyright (C) 2001-2005 authors * Copyright (C) 2001 Ximian, Inc. * Copyright (C) 2004 John Cliff + * Copyright (C) 2008 Maximilian Albert (gtkmm-ification) * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -63,7 +65,6 @@ /* Paint */ -static void sp_stroke_style_paint_construct(SPWidget *spw, SPPaintSelector *psel); static void sp_stroke_style_paint_selection_modified (SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel); static void sp_stroke_style_paint_selection_changed (SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel); static void sp_stroke_style_paint_update(SPWidget *spw); @@ -78,12 +79,16 @@ static void sp_stroke_style_widget_transientize_callback(Inkscape::Application * SPWidget *spw ); /** Marker selection option menus */ -static GtkWidget * marker_start_menu = NULL; -static GtkWidget * marker_mid_menu = NULL; -static GtkWidget * marker_end_menu = NULL; +static Gtk::OptionMenu * marker_start_menu = NULL; +static Gtk::OptionMenu * marker_mid_menu = NULL; +static Gtk::OptionMenu * marker_end_menu = NULL; -static SPObject *ink_extract_marker_name(gchar const *n); -static void ink_markers_menu_update(SPWidget* spw); +sigc::connection marker_start_menu_connection; +sigc::connection marker_mid_menu_connection; +sigc::connection marker_end_menu_connection; + +static SPObject *ink_extract_marker_name(gchar const *n, SPDocument *doc); +static void ink_markers_menu_update(Gtk::Container* spw, SPMarkerLoc const which); static Inkscape::UI::Cache::SvgPreview svg_preview_cache; @@ -102,9 +107,6 @@ sp_stroke_style_paint_widget_new(void) gtk_container_add(GTK_CONTAINER(spw), psel); gtk_object_set_data(GTK_OBJECT(spw), "paint-selector", psel); - gtk_signal_connect(GTK_OBJECT(spw), "construct", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_construct), - psel); gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_modified), psel); @@ -130,21 +132,6 @@ sp_stroke_style_paint_widget_new(void) return spw; } -/** - * On construction, simply does an update of the stroke style paint object. - */ -static void -sp_stroke_style_paint_construct(SPWidget *spw, SPPaintSelector */*psel*/) -{ -#ifdef SP_SS_VERBOSE - g_print( "Stroke style widget constructed: inkscape %p repr %p\n", - spw->inkscape, spw->repr ); -#endif - if (spw->inkscape) { - sp_stroke_style_paint_update (spw); - } -} - /** * On signal modified, invokes an update of the stroke style paint object. */ @@ -499,40 +486,30 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) /* Line */ -static void sp_stroke_style_line_construct(SPWidget *spw, gpointer data); -static void sp_stroke_style_line_selection_modified (SPWidget *spw, - Inkscape::Selection *selection, - guint flags, - gpointer data); - -static void sp_stroke_style_line_selection_changed (SPWidget *spw, - Inkscape::Selection *selection, - gpointer data ); +static void sp_stroke_style_line_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, gpointer data); +static void sp_stroke_style_line_selection_changed(SPWidget *spw, Inkscape::Selection *selection, gpointer data); -static void sp_stroke_style_line_update(SPWidget *spw, Inkscape::Selection *sel); +static void sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel); -static void sp_stroke_style_set_join_buttons(SPWidget *spw, - GtkWidget *active); +static void sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active); -static void sp_stroke_style_set_cap_buttons(SPWidget *spw, - GtkWidget *active); +static void sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active); -static void sp_stroke_style_width_changed(GtkAdjustment *adj, SPWidget *spw); -static void sp_stroke_style_miterlimit_changed(GtkAdjustment *adj, SPWidget *spw); -static void sp_stroke_style_any_toggled(GtkToggleButton *tb, SPWidget *spw); -static void sp_stroke_style_line_dash_changed(SPDashSelector *dsel, - SPWidget *spw); +static void sp_stroke_style_width_changed(Gtk::Container *spw); +static void sp_stroke_style_miterlimit_changed(Gtk::Container *spw); +static void sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw); +static void sp_stroke_style_line_dash_changed(Gtk::Container *spw); -static void sp_stroke_style_update_marker_menus(SPWidget *spw, GSList const *objects); +static void sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects); /** * Helper function for creating radio buttons. This should probably be re-thought out * when reimplementing this with Gtkmm. */ -static GtkWidget * -sp_stroke_radio_button(GtkWidget *tb, char const *icon, - GtkWidget *hb, GtkWidget *spw, +static Gtk::RadioButton * +sp_stroke_radio_button(Gtk::RadioButton *tb, char const *icon, + Gtk::HBox *hb, Gtk::Container *spw, gchar const *key, gchar const *data) { g_assert(icon != NULL); @@ -540,23 +517,23 @@ sp_stroke_radio_button(GtkWidget *tb, char const *icon, g_assert(spw != NULL); if (tb == NULL) { - tb = gtk_radio_button_new(NULL); + tb = new Gtk::RadioButton(); } else { - tb = gtk_radio_button_new(gtk_radio_button_group(GTK_RADIO_BUTTON(tb)) ); + Gtk::RadioButtonGroup grp = tb->get_group(); + tb = new Gtk::RadioButton(grp); } - gtk_widget_show(tb); - gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(tb), FALSE); - gtk_box_pack_start(GTK_BOX(hb), tb, FALSE, FALSE, 0); - gtk_object_set_data(GTK_OBJECT(spw), icon, tb); - gtk_object_set_data(GTK_OBJECT(tb), key, (gpointer*)data); - gtk_signal_connect(GTK_OBJECT(tb), "toggled", - GTK_SIGNAL_FUNC(sp_stroke_style_any_toggled), - spw); - GtkWidget *px = sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon); + tb->show(); + tb->set_mode(false); + hb->pack_start(*tb, false, false, 0); + spw->set_data(icon, tb); + tb->set_data(key, (gpointer*)data); + tb->signal_toggled().connect(sigc::bind( + sigc::ptr_fun(&sp_stroke_style_any_toggled), tb, spw)); + Gtk::Widget *px = manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon))); g_assert(px != NULL); - gtk_widget_show(px); - gtk_container_add(GTK_CONTAINER(tb), px); + px->show(); + tb->add(*px); return tb; @@ -577,7 +554,7 @@ sp_stroke_style_widget_transientize_callback(Inkscape::Application */*inkscape*/ * area in menu_id's bounding box, and then renders it. This allows us to fill in * preview images of each marker in the marker menu. */ -static GtkWidget * +static Gtk::Image * sp_marker_prev_new(unsigned psize, gchar const *mname, SPDocument *source, SPDocument *sandbox, gchar const *menu_id, NRArena const */*arena*/, unsigned /*visionkey*/, NRArenaItem *root) @@ -623,25 +600,24 @@ sp_marker_prev_new(unsigned psize, gchar const *mname, /* Update to renderable state */ double sf = 0.8; - GdkPixbuf* pixbuf = NULL; gchar *cache_name = g_strconcat(menu_id, mname, NULL); Glib::ustring key = svg_preview_cache.cache_key(source->uri, cache_name, psize); g_free (cache_name); - pixbuf = svg_preview_cache.get_preview_from_cache(key); + // TODO: is this correct? + Glib::RefPtr pixbuf = Glib::wrap(svg_preview_cache.get_preview_from_cache(key)); - if (pixbuf == NULL) { - pixbuf = render_pixbuf(root, sf, to_2geom(*dbox), psize); - svg_preview_cache.set_preview_in_cache(key, pixbuf); + if (!pixbuf) { + pixbuf = Glib::wrap(render_pixbuf(root, sf, to_2geom(*dbox), psize)); + svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj()); } // Create widget - GtkWidget *pb = gtk_image_new_from_pixbuf(pixbuf); + Gtk::Image *pb = new Gtk::Image(pixbuf); return pb; } - /** * Returns a list of markers in the defs of the given source document as a GSList object * Returns NULL if there are no markers in the document. @@ -671,46 +647,46 @@ ink_marker_list_get (SPDocument *source) * Adds previews of markers in marker_list to the given menu widget */ static void -sp_marker_menu_build (GtkWidget *m, GSList *marker_list, SPDocument *source, SPDocument *sandbox, gchar const *menu_id) +sp_marker_menu_build (Gtk::Menu *m, GSList *marker_list, SPDocument *source, SPDocument *sandbox, gchar const *menu_id) { // Do this here, outside of loop, to speed up preview generation: NRArena const *arena = NRArena::create(); unsigned const visionkey = sp_item_display_key_new(1); - NRArenaItem *root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY ); + NRArenaItem *root = sp_item_invoke_show(SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY); for (; marker_list != NULL; marker_list = marker_list->next) { Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) marker_list->data); - GtkWidget *i = gtk_menu_item_new(); - gtk_widget_show(i); + Gtk::MenuItem *i = new Gtk::MenuItem(); + i->show(); if (repr->attribute("inkscape:stockid")) - g_object_set_data (G_OBJECT(i), "stockid", (void *) "true"); + i->set_data("stockid", (void *) "true"); else - g_object_set_data (G_OBJECT(i), "stockid", (void *) "false"); + i->set_data("stockid", (void *) "false"); gchar const *markid = repr->attribute("id"); - g_object_set_data (G_OBJECT(i), "marker", (void *) markid); + i->set_data("marker", (void *) markid); - GtkWidget *hb = gtk_hbox_new(FALSE, MARKER_ITEM_MARGIN); - gtk_widget_show(hb); + Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN); + hb->show(); // generate preview - GtkWidget *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root); - gtk_widget_show(prv); - gtk_box_pack_start(GTK_BOX(hb), prv, FALSE, FALSE, 6); + Gtk::Image *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root); + prv->show(); + hb->pack_start(*prv, false, false, 6); // create label - GtkWidget *l = gtk_label_new(repr->attribute("id")); - gtk_widget_show(l); - gtk_misc_set_alignment(GTK_MISC(l), 0.0, 0.5); + Gtk::Label *l = new Gtk::Label(repr->attribute("id")); + l->show(); + l->set_alignment(0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, 0); + hb->pack_start(*l, true, true, 0); - gtk_widget_show(hb); - gtk_container_add(GTK_CONTAINER(i), hb); + hb->show(); + i->add(*hb); - gtk_menu_append(GTK_MENU(m), i); + m->append(*i); } } @@ -722,7 +698,7 @@ sp_marker_menu_build (GtkWidget *m, GSList *marker_list, SPDocument *source, SPD * */ static void -sp_marker_list_from_doc (GtkWidget *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id) +sp_marker_list_from_doc (Gtk::Menu *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id) { GSList *ml = ink_marker_list_get(source); GSList *clean_ml = NULL; @@ -734,13 +710,12 @@ sp_marker_list_from_doc (GtkWidget *m, SPDocument */*current_doc*/, SPDocument * // Add to the list of markers we really do wish to show clean_ml = g_slist_prepend (clean_ml, ml->data); } - sp_marker_menu_build (m, clean_ml, source, sandbox, menu_id); + sp_marker_menu_build(m, clean_ml, source, sandbox, menu_id); g_slist_free (ml); g_slist_free (clean_ml); } - /** * Returns a new document containing default start, mid, and end markers. */ @@ -777,30 +752,30 @@ gchar const *buffer = "show(); - g_object_set_data(G_OBJECT(i), "marker", (void *) "none"); + i->set_data("marker", (void *) "none"); - GtkWidget *hb = gtk_hbox_new(FALSE, MARKER_ITEM_MARGIN); - gtk_widget_show(hb); + Gtk::HBox *hb = new Gtk::HBox(false, MARKER_ITEM_MARGIN); + hb->show(); - GtkWidget *l = gtk_label_new( _("None") ); - gtk_widget_show(l); - gtk_misc_set_alignment(GTK_MISC(l), 0.0, 0.5); + Gtk::Label *l = new Gtk::Label( _("None") ); + l->show(); + l->set_alignment(0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, 0); + hb->pack_start(*l, true, true, 0); - gtk_widget_show(hb); - gtk_container_add(GTK_CONTAINER(i), hb); - gtk_menu_append(GTK_MENU(m), i); + hb->show(); + i->add(*hb); + m->append(*i); - // find and load markers.svg + // find and load markers.svg if (markers_doc == NULL) { char *markers_source = g_build_filename(INKSCAPE_MARKERSDIR, "markers.svg", NULL); if (Inkscape::IO::file_test(markers_source, G_FILE_TEST_IS_REGULAR)) { @@ -810,71 +785,70 @@ ink_marker_menu_create_menu(GtkWidget *m, gchar const *menu_id, SPDocument *doc, } // suck in from current doc - sp_marker_list_from_doc ( m, NULL, doc, markers_doc, sandbox, menu_id ); + sp_marker_list_from_doc(m, NULL, doc, markers_doc, sandbox, menu_id); // add separator { - GtkWidget *i = gtk_separator_menu_item_new(); - gtk_widget_show(i); - gtk_menu_append(GTK_MENU(m), i); + //Gtk::Separator *i = gtk_separator_menu_item_new(); + Gtk::SeparatorMenuItem *i = new Gtk::SeparatorMenuItem(); + i->show(); + m->append(*i); } // suck in from markers.svg if (markers_doc) { sp_document_ensure_up_to_date(doc); - sp_marker_list_from_doc ( m, doc, markers_doc, NULL, sandbox, menu_id ); + sp_marker_list_from_doc(m, doc, markers_doc, NULL, sandbox, menu_id); } } - /** * Creates a menu widget to display markers from markers.svg */ -static GtkWidget * -ink_marker_menu( GtkWidget */*tbl*/, gchar const *menu_id, SPDocument *sandbox) +static Gtk::OptionMenu * +ink_marker_menu(Gtk::Widget */*tbl*/, gchar const *menu_id, SPDocument *sandbox) { SPDesktop *desktop = inkscape_active_desktop(); SPDocument *doc = sp_desktop_document(desktop); - GtkWidget *mnu = gtk_option_menu_new(); + Gtk::OptionMenu *mnu = new Gtk::OptionMenu(); /* Create new menu widget */ - GtkWidget *m = gtk_menu_new(); - gtk_widget_show(m); + Gtk::Menu *m = new Gtk::Menu(); + m->show(); - g_object_set_data(G_OBJECT(mnu), "updating", (gpointer) FALSE); + mnu->set_data("updating", (gpointer) FALSE); if (!doc) { - GtkWidget *i = gtk_menu_item_new_with_label(_("No document selected")); - gtk_widget_show(i); - gtk_menu_append(GTK_MENU(m), i); - gtk_widget_set_sensitive(mnu, FALSE); + Gtk::MenuItem *i = new Gtk::MenuItem(_("No document selected")); + i->show(); + m->append(*i); + mnu->set_sensitive(false); } else { ink_marker_menu_create_menu(m, menu_id, doc, sandbox); - gtk_widget_set_sensitive(mnu, TRUE); + mnu->set_sensitive(true); } - gtk_object_set_data(GTK_OBJECT(mnu), "menu_id", const_cast(menu_id)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(mnu), m); + mnu->set_data("menu_id", const_cast(menu_id)); + mnu->set_menu(*m); /* Set history */ - gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0); + mnu->set_history(0); return mnu; } - /** * Handles when user selects one of the markers from the marker menu. * Defines a uri string to refer to it, then applies it to all selected * items in the current desktop. */ static void -sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw) +sp_marker_select(Gtk::OptionMenu *mnu, Gtk::Container *spw, SPMarkerLoc const which) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } @@ -885,17 +859,14 @@ sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw) } /* Get Marker */ - if (!g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), - "marker")) + if (!mnu->get_menu()->get_active()->get_data("marker")) { return; } - gchar *markid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), - "marker"); + gchar *markid = static_cast(mnu->get_menu()->get_active()->get_data("marker")); gchar const *marker = ""; - if (strcmp(markid, "none")){ - gchar *stockid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), - "stockid"); + if (strcmp(markid, "none")) { + gchar *stockid = static_cast(mnu->get_menu()->get_active()->get_data("stockid")); gchar *markurn = markid; if (!strcmp(stockid,"true")) markurn = g_strconcat("urn:inkscape:marker:",markid,NULL); @@ -907,15 +878,14 @@ sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw) } else { marker = markid; } - SPCSSAttr *css = sp_repr_css_attr_new(); - gchar const *menu_id = (gchar const *) g_object_get_data(G_OBJECT(mnu), "menu_id"); + gchar const *menu_id = static_cast(mnu->get_data("menu_id")); sp_repr_css_set_property(css, menu_id, marker); // Also update the marker dropdown menus, so the document's markers // show up at the top of the menu // sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL); - ink_markers_menu_update(SP_WIDGET(spw)); + ink_markers_menu_update(spw, which); Inkscape::Selection *selection = sp_desktop_selection(desktop); GSList const *items = selection->itemList(); @@ -938,64 +908,76 @@ sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw) }; -static int -ink_marker_menu_get_pos(GtkMenu *mnu, gchar const *markname) +static unsigned int +ink_marker_menu_get_pos(Gtk::Menu *mnu, gchar const *markname) { if (markname == NULL) - markname = (gchar const *) g_object_get_data(G_OBJECT(gtk_menu_get_active(mnu)), "marker"); + markname = static_cast(mnu->get_active()->get_data("marker")); if (markname == NULL) return 0; - GList const *kids = GTK_MENU_SHELL(mnu)->children; - int i = 0; - for (; kids != NULL; kids = kids->next) { - gchar const *mark = (gchar const *) g_object_get_data(G_OBJECT(kids->data), "marker"); - if ( mark && strcmp(mark, markname) == 0 ) { + std::vector kids = mnu->get_children(); + unsigned int i = 0; + for (; i < kids.size();) { + gchar const *mark = static_cast(kids[i]->get_data("marker")); + if (mark && strcmp(mark, markname) == 0) { break; } - i++; + ++i; } + return i; } static void -ink_markers_menu_update(SPWidget* spw) { +ink_markers_menu_update(Gtk::Container* /*spw*/, SPMarkerLoc const which) { SPDesktop *desktop = inkscape_active_desktop(); SPDocument *document = sp_desktop_document(desktop); SPDocument *sandbox = ink_markers_preview_doc (); - GtkWidget *m; + Gtk::Menu *m; int pos; - gtk_signal_handler_block_by_func( GTK_OBJECT(marker_start_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); - pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_start_menu))), NULL); - m = gtk_menu_new(); - gtk_widget_show(m); - ink_marker_menu_create_menu(m, "marker-start", document, sandbox); - gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_start_menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_start_menu), m); - gtk_option_menu_set_history(GTK_OPTION_MENU(marker_start_menu), pos); - gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_start_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); - - gtk_signal_handler_block_by_func( GTK_OBJECT(marker_mid_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); - pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_mid_menu))), NULL); - m = gtk_menu_new(); - gtk_widget_show(m); - ink_marker_menu_create_menu(m, "marker-mid", document, sandbox); - gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_mid_menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_mid_menu), m); - gtk_option_menu_set_history(GTK_OPTION_MENU(marker_mid_menu), pos); - gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_mid_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); - - gtk_signal_handler_block_by_func( GTK_OBJECT(marker_end_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); - pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_end_menu))), NULL); - m = gtk_menu_new(); - gtk_widget_show(m); - ink_marker_menu_create_menu(m, "marker-end", document, sandbox); - gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_end_menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_end_menu), m); - gtk_option_menu_set_history(GTK_OPTION_MENU(marker_end_menu), pos); - gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_end_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw); + // TODO: this code can be shortened by abstracting out marker_(start|mid|end)_... + switch (which) { + case SP_MARKER_LOC_START: + marker_start_menu_connection.block(); + pos = ink_marker_menu_get_pos(marker_start_menu->get_menu(), NULL); + m = new Gtk::Menu(); + m->show(); + ink_marker_menu_create_menu(m, "marker-start", document, sandbox); + marker_start_menu->remove_menu(); + marker_start_menu->set_menu(*m); + marker_start_menu->set_history(pos); + marker_start_menu_connection.unblock(); + break; + + case SP_MARKER_LOC_MID: + marker_mid_menu_connection.block(); + pos = ink_marker_menu_get_pos(marker_mid_menu->get_menu(), NULL); + m = new Gtk::Menu(); + m->show(); + ink_marker_menu_create_menu(m, "marker-mid", document, sandbox); + marker_mid_menu->remove_menu(); + marker_mid_menu->set_menu(*m); + marker_mid_menu->set_history(pos); + marker_mid_menu_connection.unblock(); + break; + + case SP_MARKER_LOC_END: + marker_end_menu_connection.block(); + pos = ink_marker_menu_get_pos(marker_end_menu->get_menu(), NULL); + m = new Gtk::Menu(); + m->show(); + ink_marker_menu_create_menu(m, "marker-end", document, sandbox); + marker_end_menu->remove_menu(); + marker_end_menu->set_menu(*m); + marker_end_menu->set_history(pos); + marker_end_menu_connection.unblock(); + break; + default: + g_assert_not_reached(); + } } /** @@ -1003,9 +985,9 @@ ink_markers_menu_update(SPWidget* spw) { * Also handles absolute and dimensionless units. */ static gboolean stroke_width_set_unit(SPUnitSelector *, - SPUnit const *old, - SPUnit const *new_units, - GObject *spw) + SPUnit const *old, + SPUnit const *new_units, + Gtk::Container *spw) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -1024,34 +1006,34 @@ static gboolean stroke_width_set_unit(SPUnitSelector *, (new_units->base == SP_UNIT_DIMENSIONLESS)) { /* Absolute to percentage */ - g_object_set_data (spw, "update", GUINT_TO_POINTER (TRUE)); + spw->set_data ("update", GUINT_TO_POINTER (TRUE)); - GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data (spw, "width")); - float w = sp_units_get_pixels (a->value, *old); + Gtk::Adjustment *a = static_cast(spw->get_data("width")); + float w = sp_units_get_pixels (a->get_value(), *old); gdouble average = stroke_average_width (objects); if (average == NR_HUGE || average == 0) return FALSE; - gtk_adjustment_set_value (a, 100.0 * w / average); + a->set_value (100.0 * w / average); - g_object_set_data (spw, "update", GUINT_TO_POINTER (FALSE)); + spw->set_data ("update", GUINT_TO_POINTER (FALSE)); return TRUE; } else if ((old->base == SP_UNIT_DIMENSIONLESS) && (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) { /* Percentage to absolute */ - g_object_set_data (spw, "update", GUINT_TO_POINTER (TRUE)); + spw->set_data ("update", GUINT_TO_POINTER (TRUE)); - GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data (spw, "width")); + Gtk::Adjustment *a = static_cast(spw->get_data ("width")); gdouble average = stroke_average_width (objects); - gtk_adjustment_set_value (a, sp_pixels_get_units (0.01 * a->value * average, *new_units)); + a->set_value (sp_pixels_get_units (0.01 * a->get_value() * average, *new_units)); - g_object_set_data (spw, "update", GUINT_TO_POINTER (FALSE)); + spw->set_data ("update", GUINT_TO_POINTER (FALSE)); return TRUE; } @@ -1063,26 +1045,34 @@ static gboolean stroke_width_set_unit(SPUnitSelector *, * \brief Creates a new widget for the line stroke style. * */ -GtkWidget * +Gtk::Container * sp_stroke_style_line_widget_new(void) { - GtkWidget *spw, *f, *t, *hb, *sb, *us, *tb, *ds; - GtkObject *a; - - GtkTooltips *tt = gtk_tooltips_new(); - - spw = sp_widget_new_global(INKSCAPE); - - f = gtk_hbox_new (FALSE, 0); - gtk_widget_show(f); - gtk_container_add(GTK_CONTAINER(spw), f); - - t = gtk_table_new(3, 6, FALSE); - gtk_widget_show(t); - gtk_container_set_border_width(GTK_CONTAINER(t), 4); - gtk_table_set_row_spacings(GTK_TABLE(t), 4); - gtk_container_add(GTK_CONTAINER(f), t); - gtk_object_set_data(GTK_OBJECT(spw), "stroke", t); + Gtk::Widget *us; + SPDashSelector *ds; + GtkWidget *us_old, *spw_old; + Gtk::Container *spw; + Gtk::Table *t; + Gtk::Adjustment *a; + Gtk::SpinButton *sb; + Gtk::RadioButton *tb; + Gtk::HBox *f, *hb; + + Gtk::Tooltips *tt = new Gtk::Tooltips(); + + spw_old = sp_widget_new_global(INKSCAPE); + spw = dynamic_cast(manage(Glib::wrap(spw_old))); + + f = new Gtk::HBox(false, 0); + f->show(); + spw->add(*f); + + t = new Gtk::Table(3, 6, false); + t->show(); + t->set_border_width(4); + t->set_row_spacings(4); + f->add(*t); + spw->set_data("stroke", t); gint i = 0; @@ -1098,27 +1088,28 @@ sp_stroke_style_line_widget_new(void) // with it, the two remaining calls of stroke_average_width, allowing us to get rid of that // function in desktop-style. - a = gtk_adjustment_new(1.0, 0.0, 1000.0, 0.1, 10.0, 10.0); - gtk_object_set_data(GTK_OBJECT(spw), "width", a); - sb = gtk_spin_button_new(GTK_ADJUSTMENT(a), 0.1, 3); - gtk_tooltips_set_tip(tt, sb, _("Stroke width"), NULL); - gtk_widget_show(sb); + a = new Gtk::Adjustment(1.0, 0.0, 1000.0, 0.1, 10.0, 10.0); + spw->set_data("width", a); + sb = new Gtk::SpinButton(*a, 0.1, 3); + tt->set_tip(*sb, _("Stroke width")); + sb->show(); - sp_dialog_defocus_on_enter(sb); + sp_dialog_defocus_on_enter_cpp(sb); - gtk_box_pack_start(GTK_BOX(hb), sb, FALSE, FALSE, 0); - us = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); + hb->pack_start(*sb, false, false, 0); + us_old = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); + us = manage(Glib::wrap(us_old)); SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us), sp_desktop_namedview(desktop)->doc_units); - sp_unit_selector_add_unit(SP_UNIT_SELECTOR(us), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0); - g_signal_connect ( G_OBJECT (us), "set_unit", G_CALLBACK (stroke_width_set_unit), spw ); - gtk_widget_show(us); - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), GTK_ADJUSTMENT(a) ); - gtk_box_pack_start(GTK_BOX(hb), us, FALSE, FALSE, 0); - gtk_object_set_data(GTK_OBJECT(spw), "units", us); - - gtk_signal_connect( GTK_OBJECT(a), "value_changed", GTK_SIGNAL_FUNC(sp_stroke_style_width_changed), spw ); + sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us_old), sp_desktop_namedview(desktop)->doc_units); + sp_unit_selector_add_unit(SP_UNIT_SELECTOR(us_old), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0); + g_signal_connect ( G_OBJECT (us_old), "set_unit", G_CALLBACK (stroke_width_set_unit), spw ); + us->show(); + sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us_old), GTK_ADJUSTMENT(a->gobj()) ); + hb->pack_start(*us, FALSE, FALSE, 0); + spw->set_data("units", us_old); + + a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_width_changed), spw)); i++; /* Join type */ @@ -1136,7 +1127,7 @@ sp_stroke_style_line_widget_new(void) // TRANSLATORS: Miter join: joining lines with a sharp (pointed) corner. // For an example, draw a triangle with a large stroke width and modify the // "Join" option (in the Fill and Stroke dialog). - gtk_tooltips_set_tip(tt, tb, _("Miter join"), NULL); + tt->set_tip(*tb, _("Miter join")); tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_JOIN_ROUND, hb, spw, "join", "round"); @@ -1144,7 +1135,7 @@ sp_stroke_style_line_widget_new(void) // TRANSLATORS: Round join: joining lines with a rounded corner. // For an example, draw a triangle with a large stroke width and modify the // "Join" option (in the Fill and Stroke dialog). - gtk_tooltips_set_tip(tt, tb, _("Round join"), NULL); + tt->set_tip(*tb, _("Round join")); tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_JOIN_BEVEL, hb, spw, "join", "bevel"); @@ -1152,7 +1143,7 @@ sp_stroke_style_line_widget_new(void) // TRANSLATORS: Bevel join: joining lines with a blunted (flattened) corner. // For an example, draw a triangle with a large stroke width and modify the // "Join" option (in the Fill and Stroke dialog). - gtk_tooltips_set_tip(tt, tb, _("Bevel join"), NULL); + tt->set_tip(*tb, _("Bevel join")); i++; @@ -1167,19 +1158,18 @@ sp_stroke_style_line_widget_new(void) hb = spw_hbox(t, 3, 1, i); - a = gtk_adjustment_new(4.0, 0.0, 100.0, 0.1, 10.0, 10.0); - gtk_object_set_data(GTK_OBJECT(spw), "miterlimit", a); + a = new Gtk::Adjustment(4.0, 0.0, 100.0, 0.1, 10.0, 10.0); + spw->set_data("miterlimit", a); - sb = gtk_spin_button_new(GTK_ADJUSTMENT(a), 0.1, 2); - gtk_tooltips_set_tip(tt, sb, _("Maximum length of the miter (in units of stroke width)"), NULL); - gtk_widget_show(sb); - gtk_object_set_data(GTK_OBJECT(spw), "miterlimit_sb", sb); - sp_dialog_defocus_on_enter(sb); + sb = new Gtk::SpinButton(*a, 0.1, 2); + tt->set_tip(*sb, _("Maximum length of the miter (in units of stroke width)")); + sb->show(); + spw->set_data("miterlimit_sb", sb); + sp_dialog_defocus_on_enter_cpp(sb); - gtk_box_pack_start(GTK_BOX(hb), sb, FALSE, FALSE, 0); + hb->pack_start(*sb, false, false, 0); - gtk_signal_connect( GTK_OBJECT(a), "value_changed", - GTK_SIGNAL_FUNC(sp_stroke_style_miterlimit_changed), spw ); + a->signal_value_changed().connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_miterlimit_changed), spw)); i++; /* Cap type */ @@ -1195,41 +1185,37 @@ sp_stroke_style_line_widget_new(void) // TRANSLATORS: Butt cap: the line shape does not extend beyond the end point // of the line; the ends of the line are square - gtk_tooltips_set_tip(tt, tb, _("Butt cap"), NULL); + tt->set_tip(*tb, _("Butt cap")); tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_CAP_ROUND, hb, spw, "cap", "round"); // TRANSLATORS: Round cap: the line shape extends beyond the end point of the // line; the ends of the line are rounded - gtk_tooltips_set_tip(tt, tb, _("Round cap"), NULL); + tt->set_tip(*tb, _("Round cap")); tb = sp_stroke_radio_button(tb, INKSCAPE_STOCK_CAP_SQUARE, hb, spw, "cap", "square"); // TRANSLATORS: Square cap: the line shape extends beyond the end point of the // line; the ends of the line are square - gtk_tooltips_set_tip(tt, tb, _("Square cap"), NULL); + tt->set_tip(*tb, _("Square cap")); i++; /* Dash */ spw_label(t, _("Dashes:"), 0, i); - ds = sp_dash_selector_new( inkscape_get_repr( INKSCAPE, - "palette.dashes") ); - - gtk_widget_show(ds); - gtk_table_attach( GTK_TABLE(t), ds, 1, 4, i, i+1, - (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ), - (GtkAttachOptions)0, 0, 0 ); - gtk_object_set_data(GTK_OBJECT(spw), "dash", ds); - gtk_signal_connect( GTK_OBJECT(ds), "changed", - GTK_SIGNAL_FUNC(sp_stroke_style_line_dash_changed), - spw ); + ds = manage(new SPDashSelector(inkscape_get_repr(INKSCAPE, "palette.dashes"))); + + ds->show(); + t->attach(*ds, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); + spw->set_data("dash", ds); + ds->changed_signal.connect(sigc::bind(sigc::ptr_fun(&sp_stroke_style_line_dash_changed), spw)); i++; /* Drop down marker selectors*/ + // TODO: this code can be shortened by iterating over the possible menus! // doing this here once, instead of for each preview, to speed things up SPDocument *sandbox = ink_markers_preview_doc (); @@ -1237,69 +1223,48 @@ sp_stroke_style_line_widget_new(void) // TRANSLATORS: Path markers are an SVG feature that allows you to attach arbitrary shapes // (arrowheads, bullets, faces, whatever) to the start, end, or middle nodes of a path. spw_label(t, _("Start Markers:"), 0, i); - marker_start_menu = ink_marker_menu( spw ,"marker-start", sandbox); - gtk_signal_connect( GTK_OBJECT(marker_start_menu), "changed", GTK_SIGNAL_FUNC(sp_marker_select), spw ); - gtk_widget_show(marker_start_menu); - gtk_table_attach( GTK_TABLE(t), marker_start_menu, 1, 4, i, i+1, - (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ), - (GtkAttachOptions)0, 0, 0 ); - gtk_object_set_data(GTK_OBJECT(spw), "start_mark_menu", marker_start_menu); + marker_start_menu = ink_marker_menu(spw ,"marker-start", sandbox); + marker_start_menu_connection = marker_start_menu->signal_changed().connect( + sigc::bind( + sigc::ptr_fun(&sp_marker_select), marker_start_menu, spw, SP_MARKER_LOC_START)); + marker_start_menu->show(); + t->attach(*marker_start_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); + spw->set_data("start_mark_menu", marker_start_menu); i++; spw_label(t, _("Mid Markers:"), 0, i); - marker_mid_menu = ink_marker_menu( spw ,"marker-mid", sandbox); - gtk_signal_connect( GTK_OBJECT(marker_mid_menu), "changed", GTK_SIGNAL_FUNC(sp_marker_select), spw ); - gtk_widget_show(marker_mid_menu); - gtk_table_attach( GTK_TABLE(t), marker_mid_menu, 1, 4, i, i+1, - (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ), - (GtkAttachOptions)0, 0, 0 ); - gtk_object_set_data(GTK_OBJECT(spw), "mid_mark_menu", marker_mid_menu); + marker_mid_menu = ink_marker_menu(spw ,"marker-mid", sandbox); + marker_mid_menu_connection = marker_mid_menu->signal_changed().connect( + sigc::bind( + sigc::ptr_fun(&sp_marker_select), marker_mid_menu,spw, SP_MARKER_LOC_MID)); + marker_mid_menu->show(); + t->attach(*marker_mid_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); + spw->set_data("mid_mark_menu", marker_mid_menu); i++; spw_label(t, _("End Markers:"), 0, i); - marker_end_menu = ink_marker_menu( spw ,"marker-end", sandbox); - gtk_signal_connect( GTK_OBJECT(marker_end_menu), "changed", GTK_SIGNAL_FUNC(sp_marker_select), spw ); - gtk_widget_show(marker_end_menu); - gtk_table_attach( GTK_TABLE(t), marker_end_menu, 1, 4, i, i+1, - (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ), - (GtkAttachOptions)0, 0, 0 ); - gtk_object_set_data(GTK_OBJECT(spw), "end_mark_menu", marker_end_menu); + marker_end_menu = ink_marker_menu(spw ,"marker-end", sandbox); + marker_end_menu_connection = marker_end_menu->signal_changed().connect( + sigc::bind( + sigc::ptr_fun(&sp_marker_select), marker_end_menu, spw, SP_MARKER_LOC_END)); + marker_end_menu->show(); + t->attach(*marker_end_menu, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); + spw->set_data("end_mark_menu", marker_end_menu); i++; - gtk_signal_connect( GTK_OBJECT(spw), "construct", - GTK_SIGNAL_FUNC(sp_stroke_style_line_construct), - NULL ); - gtk_signal_connect( GTK_OBJECT(spw), "modify_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified), - NULL ); - gtk_signal_connect( GTK_OBJECT(spw), "change_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed), - NULL ); + // FIXME: we cheat and still use gtk+ signals - sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL); - - return spw; -} + gtk_signal_connect(GTK_OBJECT(spw_old), "modify_selection", + GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified), + spw); + gtk_signal_connect(GTK_OBJECT(spw_old), "change_selection", + GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed), + spw); + sp_stroke_style_line_update(spw, desktop ? sp_desktop_selection(desktop) : NULL); -/** - * Callback for when the stroke style widget is called. It causes - * the stroke line style to be updated. - */ -static void -sp_stroke_style_line_construct(SPWidget *spw, gpointer /*data*/) -{ -#ifdef SP_SS_VERBOSE - g_print( "Stroke style widget constructed: inkscape %p repr %p\n", - spw->inkscape, spw->repr ); -#endif - if (spw->inkscape) { - sp_stroke_style_line_update(spw, - ( SP_ACTIVE_DESKTOP - ? sp_desktop_selection(SP_ACTIVE_DESKTOP) - : NULL )); - } + return spw; } /** @@ -1307,13 +1272,14 @@ sp_stroke_style_line_construct(SPWidget *spw, gpointer /*data*/) * Triggers update action. */ static void -sp_stroke_style_line_selection_modified( SPWidget *spw, - Inkscape::Selection *selection, - guint flags, - gpointer /*data*/ ) +sp_stroke_style_line_selection_modified(SPWidget *, + Inkscape::Selection *selection, + guint flags, + gpointer data) { + Gtk::Container *spw = static_cast(data); if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG)) { - sp_stroke_style_line_update (spw, selection); + sp_stroke_style_line_update(spw, selection); } } @@ -1323,19 +1289,19 @@ sp_stroke_style_line_selection_modified( SPWidget *spw, * Triggers update action. */ static void -sp_stroke_style_line_selection_changed( SPWidget *spw, - Inkscape::Selection *selection, - gpointer /*data*/ ) +sp_stroke_style_line_selection_changed(SPWidget *, + Inkscape::Selection *selection, + gpointer data) { - sp_stroke_style_line_update (spw, selection); + Gtk::Container *spw = static_cast(data); + sp_stroke_style_line_update(spw, selection); } - /** * Sets selector widgets' dash style from an SPStyle object. */ static void -sp_dash_selector_set_from_style (GtkWidget *dsel, SPStyle *style) +sp_dash_selector_set_from_style(SPDashSelector *dsel, SPStyle *style) { if (style->stroke_dash.n_dash > 0) { double d[64]; @@ -1346,12 +1312,11 @@ sp_dash_selector_set_from_style (GtkWidget *dsel, SPStyle *style) else d[i] = style->stroke_dash.dash[i]; // is there a better thing to do for stroke_width==0? } - sp_dash_selector_set_dash(SP_DASH_SELECTOR(dsel), len, d, - style->stroke_width.computed != 0? - style->stroke_dash.offset / style->stroke_width.computed : - style->stroke_dash.offset); + dsel->set_dash(len, d, style->stroke_width.computed != 0 ? + style->stroke_dash.offset / style->stroke_width.computed : + style->stroke_dash.offset); } else { - sp_dash_selector_set_dash(SP_DASH_SELECTOR(dsel), 0, NULL, 0.0); + dsel->set_dash(0, NULL, 0.0); } } @@ -1359,46 +1324,46 @@ sp_dash_selector_set_from_style (GtkWidget *dsel, SPStyle *style) * Sets the join type for a line, and updates the stroke style widget's buttons */ static void -sp_jointype_set (SPWidget *spw, unsigned const jointype) +sp_jointype_set (Gtk::Container *spw, unsigned const jointype) { - GtkWidget *tb = NULL; + Gtk::RadioButton *tb = NULL; switch (jointype) { case SP_STROKE_LINEJOIN_MITER: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_JOIN_MITER)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_MITER)); break; case SP_STROKE_LINEJOIN_ROUND: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_JOIN_ROUND)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_ROUND)); break; case SP_STROKE_LINEJOIN_BEVEL: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_JOIN_BEVEL)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_BEVEL)); break; default: break; } - sp_stroke_style_set_join_buttons (spw, tb); + sp_stroke_style_set_join_buttons(spw, tb); } /** * Sets the cap type for a line, and updates the stroke style widget's buttons */ static void -sp_captype_set (SPWidget *spw, unsigned const captype) +sp_captype_set (Gtk::Container *spw, unsigned const captype) { - GtkWidget *tb = NULL; + Gtk::RadioButton *tb = NULL; switch (captype) { case SP_STROKE_LINECAP_BUTT: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_CAP_BUTT)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_BUTT)); break; case SP_STROKE_LINECAP_ROUND: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_CAP_ROUND)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_ROUND)); break; case SP_STROKE_LINECAP_SQUARE: - tb = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), INKSCAPE_STOCK_CAP_SQUARE)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_SQUARE)); break; default: break; } - sp_stroke_style_set_cap_buttons (spw, tb); + sp_stroke_style_set_cap_buttons(spw, tb); } /** @@ -1406,19 +1371,19 @@ sp_captype_set (SPWidget *spw, unsigned const captype) * join type, etc. */ static void -sp_stroke_style_line_update(SPWidget *spw, Inkscape::Selection *sel) +sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); + spw->set_data("update", GINT_TO_POINTER(TRUE)); - GtkWidget *sset = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "stroke")); - GtkObject *width = GTK_OBJECT(gtk_object_get_data(GTK_OBJECT(spw), "width")); - GtkObject *ml = GTK_OBJECT(gtk_object_get_data(GTK_OBJECT(spw), "miterlimit")); - GtkWidget *us = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "units")); - GtkWidget *dsel = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "dash")); + Gtk::Table *sset = static_cast(spw->get_data("stroke")); + Gtk::Adjustment *width = static_cast(spw->get_data("width")); + Gtk::Adjustment *ml = static_cast(spw->get_data("miterlimit")); + SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units")); + SPDashSelector *dsel = static_cast(spw->get_data("dash")); // create temporary style SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); @@ -1430,39 +1395,39 @@ sp_stroke_style_line_update(SPWidget *spw, Inkscape::Selection *sel) if (result_sw == QUERY_STYLE_NOTHING) { /* No objects stroked, set insensitive */ - gtk_widget_set_sensitive(sset, FALSE); + sset->set_sensitive(false); - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + spw->set_data("update", GINT_TO_POINTER(FALSE)); return; } else { - gtk_widget_set_sensitive(sset, TRUE); + sset->set_sensitive(true); - SPUnit const *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us)); + SPUnit const *unit = sp_unit_selector_get_unit(us); if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(us), &sp_unit_get_by_id(SP_UNIT_PERCENT)); + sp_unit_selector_set_unit(us, &sp_unit_get_by_id(SP_UNIT_PERCENT)); } else { // same width, or only one object; no sense to keep percent, switch to absolute if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(us), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + sp_unit_selector_set_unit(us, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); } } - unit = sp_unit_selector_get_unit (SP_UNIT_SELECTOR (us)); + unit = sp_unit_selector_get_unit(us); if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) { double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit); - gtk_adjustment_set_value(GTK_ADJUSTMENT(width), avgwidth); + width->set_value(avgwidth); } else { - gtk_adjustment_set_value(GTK_ADJUSTMENT(width), 100); + width->set_value(100); } } if (result_ml != QUERY_STYLE_NOTHING) - gtk_adjustment_set_value(GTK_ADJUSTMENT(ml), query->stroke_miterlimit.value); // TODO: reflect averagedness? + ml->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness? if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT) { - sp_jointype_set (spw, query->stroke_linejoin.value); + sp_jointype_set(spw, query->stroke_linejoin.value); } else { sp_stroke_style_set_join_buttons(spw, NULL); } @@ -1486,12 +1451,11 @@ sp_stroke_style_line_update(SPWidget *spw, Inkscape::Selection *sel) sp_stroke_style_update_marker_menus(spw, objects); // FIXME: make this desktop query too /* Dash */ - sp_dash_selector_set_from_style (dsel, style); // FIXME: make this desktop query too + sp_dash_selector_set_from_style(dsel, style); // FIXME: make this desktop query too - gtk_widget_set_sensitive(sset, TRUE); + sset->set_sensitive(true); - gtk_object_set_data(GTK_OBJECT(spw), "update", - GINT_TO_POINTER(FALSE)); + spw->set_data("update", GINT_TO_POINTER(FALSE)); } /** @@ -1525,18 +1489,18 @@ sp_stroke_style_set_scaled_dash(SPCSSAttr *css, * Sets line properties like width, dashes, markers, etc. on all currently selected items. */ static void -sp_stroke_style_scale_line(SPWidget *spw) +sp_stroke_style_scale_line(Gtk::Container *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); + spw->set_data("update", GINT_TO_POINTER(TRUE)); - GtkAdjustment *wadj = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(spw), "width")); - SPUnitSelector *us = SP_UNIT_SELECTOR(gtk_object_get_data(GTK_OBJECT(spw), "units")); - SPDashSelector *dsel = SP_DASH_SELECTOR(gtk_object_get_data(GTK_OBJECT(spw), "dash")); - GtkAdjustment *ml = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(spw), "miterlimit")); + Gtk::Adjustment *wadj = static_cast(spw->get_data("width")); + SPUnitSelector *us = SP_UNIT_SELECTOR(spw->get_data("units")); + SPDashSelector *dsel = static_cast(spw->get_data("dash")); + Gtk::Adjustment *ml = static_cast(spw->get_data("miterlimit")); SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *document = sp_desktop_document (desktop); @@ -1549,14 +1513,14 @@ sp_stroke_style_scale_line(SPWidget *spw) if (items) { - double width_typed = wadj->value; - double const miterlimit = ml->value; + double width_typed = wadj->get_value(); + double const miterlimit = ml->get_value(); SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(us)); double *dash, offset; int ndash; - sp_dash_selector_get_dash(dsel, &ndash, &dash, &offset); + dsel->get_dash(&ndash, &dash, &offset); for (GSList const *i = items; i != NULL; i = i->next) { /* Set stroke width */ @@ -1590,7 +1554,7 @@ sp_stroke_style_scale_line(SPWidget *spw) if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { // reset to 100 percent - gtk_adjustment_set_value (wadj, 100.0); + wadj->set_value(100.0); } } @@ -1604,18 +1568,17 @@ sp_stroke_style_scale_line(SPWidget *spw) sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, _("Set stroke style")); - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + spw->set_data("update", GINT_TO_POINTER(FALSE)); } - /** * Callback for when the stroke style's width changes. * Causes all line styles to be applied to all selected items. */ static void -sp_stroke_style_width_changed(GtkAdjustment */*adj*/, SPWidget *spw) +sp_stroke_style_width_changed(Gtk::Container *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } @@ -1627,9 +1590,9 @@ sp_stroke_style_width_changed(GtkAdjustment */*adj*/, SPWidget *spw) * Causes all line styles to be applied to all selected items. */ static void -sp_stroke_style_miterlimit_changed(GtkAdjustment */*adj*/, SPWidget *spw) +sp_stroke_style_miterlimit_changed(Gtk::Container *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } @@ -1640,18 +1603,17 @@ sp_stroke_style_miterlimit_changed(GtkAdjustment */*adj*/, SPWidget *spw) * Callback for when the stroke style's dash changes. * Causes all line styles to be applied to all selected items. */ + static void -sp_stroke_style_line_dash_changed(SPDashSelector */*dsel*/, SPWidget *spw) +sp_stroke_style_line_dash_changed(Gtk::Container *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } sp_stroke_style_scale_line(spw); } - - /** * \brief This routine handles toggle events for buttons in the stroke style * dialog. @@ -1660,22 +1622,22 @@ sp_stroke_style_line_dash_changed(SPDashSelector */*dsel*/, SPWidget *spw) * */ static void -sp_stroke_style_any_toggled(GtkToggleButton *tb, SPWidget *spw) +sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (spw->get_data("update")) { return; } - if (gtk_toggle_button_get_active(tb)) { + if (tb->get_active()) { gchar const *join - = static_cast(gtk_object_get_data(GTK_OBJECT(tb), "join")); + = static_cast(tb->get_data("join")); gchar const *cap - = static_cast(gtk_object_get_data(GTK_OBJECT(tb), "cap")); + = static_cast(tb->get_data("cap")); if (join) { - GtkWidget *ml = GTK_WIDGET(g_object_get_data(G_OBJECT(spw), "miterlimit_sb")); - gtk_widget_set_sensitive (ml, !strcmp(join, "miter")); + Gtk::SpinButton *ml = static_cast(spw->get_data("miterlimit_sb")); + ml->set_sensitive(!strcmp(join, "miter")); } SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -1688,13 +1650,13 @@ sp_stroke_style_any_toggled(GtkToggleButton *tb, SPWidget *spw) sp_desktop_set_style (desktop, css); - sp_stroke_style_set_join_buttons(spw, GTK_WIDGET(tb)); + sp_stroke_style_set_join_buttons(spw, tb); } else if (cap) { sp_repr_css_set_property(css, "stroke-linecap", cap); sp_desktop_set_style (desktop, css); - sp_stroke_style_set_cap_buttons(spw, GTK_WIDGET(tb)); + sp_stroke_style_set_cap_buttons(spw, tb); } sp_repr_css_attr_unref(css); @@ -1704,60 +1666,52 @@ sp_stroke_style_any_toggled(GtkToggleButton *tb, SPWidget *spw) } } - /** * Updates the join style toggle buttons */ static void -sp_stroke_style_set_join_buttons(SPWidget *spw, GtkWidget *active) +sp_stroke_style_set_join_buttons(Gtk::Container *spw, Gtk::ToggleButton *active) { - GtkWidget *tb; - - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_JOIN_MITER) ); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); + Gtk::RadioButton *tb; - GtkWidget *ml = GTK_WIDGET(g_object_get_data(G_OBJECT(spw), "miterlimit_sb")); - gtk_widget_set_sensitive(ml, (active == tb)); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_MITER)); + tb->set_active(active == tb); - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_JOIN_ROUND) ); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_JOIN_BEVEL) ); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); -} + Gtk::SpinButton *ml = static_cast(spw->get_data("miterlimit_sb")); + ml->set_sensitive(active == tb); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_ROUND)); + tb->set_active(active == tb); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_JOIN_BEVEL)); + tb->set_active(active == tb); +} /** * Updates the cap style toggle buttons */ static void -sp_stroke_style_set_cap_buttons(SPWidget *spw, GtkWidget *active) +sp_stroke_style_set_cap_buttons(Gtk::Container *spw, Gtk::ToggleButton *active) { - GtkWidget *tb; - - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_CAP_BUTT)); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_CAP_ROUND) ); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); - tb = GTK_WIDGET(gtk_object_get_data( GTK_OBJECT(spw), - INKSCAPE_STOCK_CAP_SQUARE) ); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), (active == tb)); + Gtk::RadioButton *tb; + + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_BUTT)); + tb->set_active(active == tb); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_ROUND)); + tb->set_active(active == tb); + tb = static_cast(spw->get_data(INKSCAPE_STOCK_CAP_SQUARE)); + tb->set_active(active == tb); } /** * Sets the current marker in the marker menu. */ static void -ink_marker_menu_set_current(SPObject *marker, GtkOptionMenu *mnu) +ink_marker_menu_set_current(SPObject *marker, Gtk::OptionMenu *mnu) { - gtk_object_set_data(GTK_OBJECT(mnu), "update", GINT_TO_POINTER(TRUE)); + mnu->set_data("update", GINT_TO_POINTER(TRUE)); - GtkMenu *m = GTK_MENU(gtk_option_menu_get_menu(mnu)); + Gtk::Menu *m = mnu->get_menu(); if (marker != NULL) { bool mark_is_stock = false; if (SP_OBJECT_REPR(marker)->attribute("inkscape:stockid")) @@ -1770,14 +1724,14 @@ ink_marker_menu_set_current(SPObject *marker, GtkOptionMenu *mnu) markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("id")); int markpos = ink_marker_menu_get_pos(m, markname); - gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), markpos); + mnu->set_history(markpos); g_free (markname); } else { - gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0); + mnu->set_history(0); } - gtk_object_set_data(GTK_OBJECT(mnu), "update", GINT_TO_POINTER(FALSE)); + mnu->set_data("update", GINT_TO_POINTER(FALSE)); } /** @@ -1785,8 +1739,7 @@ ink_marker_menu_set_current(SPObject *marker, GtkOptionMenu *mnu) * that marker. */ static void -sp_stroke_style_update_marker_menus( SPWidget *spw, - GSList const *objects) +sp_stroke_style_update_marker_menus(Gtk::Container *spw, GSList const *objects) { struct { char const *key; int loc; } const keyloc[] = { { "start_mark_menu", SP_MARKER_LOC_START }, @@ -1802,13 +1755,9 @@ sp_stroke_style_update_marker_menus( SPWidget *spw, } for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { - GtkOptionMenu *mnu = (GtkOptionMenu *) g_object_get_data(G_OBJECT(spw), keyloc[i].key); - if (all_texts) { - // Per SVG spec, text objects cannot have markers; disable menus if only texts are selected - gtk_widget_set_sensitive (GTK_WIDGET(mnu), FALSE); - } else { - gtk_widget_set_sensitive (GTK_WIDGET(mnu), TRUE); - } + Gtk::OptionMenu *mnu = static_cast(spw->get_data(keyloc[i].key)); + // Per SVG spec, text objects cannot have markers; disable menus if only texts are selected + mnu->set_sensitive(!all_texts); } // We show markers of the first object in the list only @@ -1819,10 +1768,10 @@ sp_stroke_style_update_marker_menus( SPWidget *spw, // For all three marker types, // find the corresponding menu - GtkOptionMenu *mnu = (GtkOptionMenu *) g_object_get_data(G_OBJECT(spw), keyloc[i].key); + Gtk::OptionMenu *mnu = static_cast(spw->get_data(keyloc[i].key)); // Quit if we're in update state - if (gtk_object_get_data(GTK_OBJECT(mnu), "update")) { + if (mnu->get_data("update")) { return; } @@ -1830,12 +1779,12 @@ sp_stroke_style_update_marker_menus( SPWidget *spw, // If the object has this type of markers, // Extract the name of the marker that the object uses - SPObject *marker = ink_extract_marker_name(object->style->marker[keyloc[i].loc].value); + SPObject *marker = ink_extract_marker_name(object->style->marker[keyloc[i].loc].value, SP_OBJECT_DOCUMENT(object)); // Scroll the menu to that marker - ink_marker_menu_set_current (marker, mnu); + ink_marker_menu_set_current(marker, mnu); } else { - gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0); + mnu->set_history(0); } } } @@ -1848,7 +1797,7 @@ sp_stroke_style_update_marker_menus( SPWidget *spw, * the caller should free the buffer when they no longer need it. */ static SPObject* -ink_extract_marker_name(gchar const *n) +ink_extract_marker_name(gchar const *n, SPDocument *doc) { gchar const *p = n; while (*p != '\0' && *p != '#') { @@ -1872,8 +1821,7 @@ ink_extract_marker_name(gchar const *n) gchar* b = g_strdup(p); b[c] = '\0'; - SPDesktop *desktop = inkscape_active_desktop(); - SPDocument *doc = sp_desktop_document(desktop); + // FIXME: get the document from the object and let the caller pass it in SPObject *marker = doc->getObjectById(b); return marker; } diff --git a/src/dialogs/stroke-style.h b/src/dialogs/stroke-style.h index 209407b3f..475a2d388 100644 --- a/src/dialogs/stroke-style.h +++ b/src/dialogs/stroke-style.h @@ -19,7 +19,7 @@ #include "display/canvas-bpath.h" GtkWidget *sp_stroke_style_paint_widget_new (void); -GtkWidget *sp_stroke_style_line_widget_new (void); +Gtk::Container *sp_stroke_style_line_widget_new (void); #endif diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index 8b5f63449..50b2a5c79 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -87,7 +87,9 @@ FillAndStroke::_layoutPageStrokePaint() void FillAndStroke::_layoutPageStrokeStyle() { - Gtk::Widget *ssl = manage(Glib::wrap(sp_stroke_style_line_widget_new())); + //Gtk::Widget *ssl = manage(Glib::wrap(sp_stroke_style_line_widget_new())); + //Gtk::Widget *ssl = static_cast(sp_stroke_style_line_widget_new()); + Gtk::Widget *ssl = sp_stroke_style_line_widget_new(); _page_stroke_style.table().attach(*ssl, 0, 1, 0, 1); } diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 6cc3bb1f0..33f589247 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -17,6 +17,8 @@ widgets_libspwidgets_a_SOURCES = \ widgets/calligraphic-profile-rename.h \ widgets/dash-selector.cpp \ widgets/dash-selector.h \ + widgets/dash-selector.cpp \ + widgets/dash-selector.h \ widgets/desktop-widget.cpp \ widgets/desktop-widget.h \ widgets/font-selector.cpp \ diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp index 49bca9a98..57f9259e2 100644 --- a/src/widgets/dash-selector.cpp +++ b/src/widgets/dash-selector.cpp @@ -1,4 +1,4 @@ -#define __SP_DASH_SELECTOR_C__ +#define __SP_DASH_SELECTOR_NEW_C__ /* * Optionmenu for selecting dash patterns @@ -6,6 +6,7 @@ * Author: * Lauris Kaplinski * bulia byak + * Maximilian Albert * * Copyright (C) 2002 Lauris Kaplinski * @@ -25,217 +26,189 @@ #include #include -#include "../style.h" -#include "../dialogs/dialog-events.h" +#include "style.h" +#include "dialogs/dialog-events.h" + +#include +#include +#include + #include "dash-selector.h" -enum {CHANGED, LAST_SIGNAL}; +static double dash_0[] = {-1.0}; +static double dash_1_1[] = {1.0, 1.0, -1.0}; +static double dash_2_1[] = {2.0, 1.0, -1.0}; +static double dash_4_1[] = {4.0, 1.0, -1.0}; +static double dash_1_2[] = {1.0, 2.0, -1.0}; +static double dash_1_4[] = {1.0, 4.0, -1.0}; -struct SPDashSelector { - GtkHBox hbox; +static double *builtin_dashes[] = {dash_0, dash_1_1, dash_2_1, dash_4_1, dash_1_2, dash_1_4, NULL}; - GtkWidget *dash; - GtkObject *offset; -}; +static double **dashes = NULL; -struct SPDashSelectorClass { - GtkHBoxClass parent_class; +static void sp_dash_selector_menu_item_image_realize(Gtk::Image *px, double *pattern); - void (* changed) (SPDashSelector *dsel); -}; +SPDashSelector::SPDashSelector(Inkscape::XML::Node *drepr) { + // TODO: find something more sensible here!! + init_dashes(drepr); -double dash_0[] = {-1.0}; -double dash_1_1[] = {1.0, 1.0, -1.0}; -double dash_2_1[] = {2.0, 1.0, -1.0}; -double dash_4_1[] = {4.0, 1.0, -1.0}; -double dash_1_2[] = {1.0, 2.0, -1.0}; -double dash_1_4[] = {1.0, 4.0, -1.0}; + Gtk::Tooltips *tt = new Gtk::Tooltips(); -double *builtin_dashes[] = {dash_0, dash_1_1, dash_2_1, dash_4_1, dash_1_2, dash_1_4, NULL}; + dash = new Gtk::OptionMenu(); + tt->set_tip(*dash, _("Dash pattern")); + dash->show(); + this->pack_start(*dash, false, false, 0); -static double **dashes = NULL; + Gtk::Menu *m = new Gtk::Menu(); + m->show(); + for (int i = 0; dashes[i]; i++) { + Gtk::MenuItem *mi = menu_item_new(dashes[i]); + mi->show(); + m->append(*mi); + } + dash->set_menu(*m); -static void sp_dash_selector_class_init (SPDashSelectorClass *klass); -static void sp_dash_selector_init (SPDashSelector *dsel); -static GtkWidget *sp_dash_selector_menu_item_new (SPDashSelector *dsel, double *pattern); -static void sp_dash_selector_menu_item_image_realize (GtkWidget *mi, double *pattern); -static void sp_dash_selector_dash_activate (GtkObject *object, SPDashSelector *dsel); -static void sp_dash_selector_offset_value_changed (GtkAdjustment *adj, SPDashSelector *dsel); + offset = new Gtk::Adjustment(0.0, 0.0, 10.0, 0.1, 1.0, 1.0); + Gtk::SpinButton *sb = new Gtk::SpinButton(*offset, 0.1, 2); + tt->set_tip(*sb, _("Pattern offset")); -static GtkHBoxClass *parent_class; -static guint signals[LAST_SIGNAL] = {0}; + sp_dialog_defocus_on_enter_cpp(sb); + sb->show(); + this->pack_start(*sb, false, false, 0); + offset->signal_value_changed().connect(sigc::mem_fun(*this, &SPDashSelector::offset_value_changed)); -GtkType -sp_dash_selector_get_type (void) -{ - static GtkType type = 0; - if (!type) { - GtkTypeInfo info = { - "SPDashSelector", - sizeof (SPDashSelector), - sizeof (SPDashSelectorClass), - (GtkClassInitFunc) sp_dash_selector_class_init, - (GtkObjectInitFunc) sp_dash_selector_init, - NULL, NULL, NULL - }; - type = gtk_type_unique (GTK_TYPE_HBOX, &info); - } - return type; + this->set_data("pattern", dashes[0]); } -static void -sp_dash_selector_class_init (SPDashSelectorClass *klass) -{ - parent_class = (GtkHBoxClass*)gtk_type_class (GTK_TYPE_HBOX); - - signals[CHANGED] = gtk_signal_new ("changed", - (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE), - G_TYPE_FROM_CLASS (klass), - GTK_SIGNAL_OFFSET (SPDashSelectorClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); +SPDashSelector::~SPDashSelector() { + // FIXME: for some reason this doesn't get called; does the call to manage() in + // sp_stroke_style_line_widget_new() not processed correctly? + delete dash; + delete offset; } -static void -sp_dash_selector_init (SPDashSelector *dsel) -{ - GtkTooltips *tt = gtk_tooltips_new(); - - dsel->dash = gtk_option_menu_new (); - gtk_tooltips_set_tip (tt, dsel->dash, _("Dash pattern"), NULL); - gtk_widget_show (dsel->dash); - gtk_box_pack_start (GTK_BOX (dsel), dsel->dash, FALSE, FALSE, 0); - - GtkWidget *m = gtk_menu_new (); - gtk_widget_show (m); - for (int i = 0; dashes[i]; i++) { - GtkWidget *mi = sp_dash_selector_menu_item_new (dsel, dashes[i]); - gtk_widget_show (mi); - gtk_menu_append (GTK_MENU (m), mi); - } - gtk_option_menu_set_menu (GTK_OPTION_MENU (dsel->dash), m); - - dsel->offset = gtk_adjustment_new (0.0, 0.0, 10.0, 0.1, 1.0, 1.0); - GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (dsel->offset), 0.1, 2); - gtk_tooltips_set_tip (tt, sb, _("Pattern offset"), NULL); - - sp_dialog_defocus_on_enter (sb); - gtk_widget_show (sb); - gtk_box_pack_start (GTK_BOX (dsel), sb, FALSE, FALSE, 0); - gtk_signal_connect (dsel->offset, "value_changed", GTK_SIGNAL_FUNC (sp_dash_selector_offset_value_changed), dsel); - - gtk_object_set_data (GTK_OBJECT (dsel), "pattern", dashes[0]); +void +SPDashSelector::init_dashes(Inkscape::XML::Node *drepr) { + if (!dashes) { + int ndashes = 0; + if (drepr) { + for (Inkscape::XML::Node *dr = drepr->firstChild(); dr; dr = dr->next()) { + if (!strcmp (dr->name(), "dash")) + ndashes += 1; + } + } + + if (ndashes > 0) { + int pos = 0; + SPStyle *style = sp_style_new (NULL); + dashes = g_new (double *, ndashes + 1); + for (Inkscape::XML::Node *dr = drepr->firstChild(); dr; dr = dr->next()) { + if (!strcmp (dr->name(), "dash")) { + sp_style_read_from_repr (style, dr); + if (style->stroke_dash.n_dash > 0) { + dashes[pos] = g_new (double, style->stroke_dash.n_dash + 1); + double *d = dashes[pos]; + int i = 0; + for (; i < style->stroke_dash.n_dash; i++) { + d[i] = style->stroke_dash.dash[i]; + } + d[i] = -1; + } else { + dashes[pos] = dash_0; + } + pos += 1; + } + } + sp_style_unref (style); + dashes[pos] = NULL; + } else { + dashes = builtin_dashes; + } + } } -GtkWidget * -sp_dash_selector_new (Inkscape::XML::Node *drepr) +void +SPDashSelector::set_dash (int ndash, double *dash, double o) { - if (!dashes) { - int ndashes = 0; - if (drepr) { - for (Inkscape::XML::Node *dr = drepr->firstChild(); dr; dr = dr->next()) { - if (!strcmp (dr->name(), "dash")) - ndashes += 1; - } - } - - if (ndashes > 0) { - int pos = 0; - SPStyle *style = sp_style_new (NULL); - dashes = g_new (double *, ndashes + 1); - for (Inkscape::XML::Node *dr = drepr->firstChild(); dr; dr = dr->next()) { - if (!strcmp (dr->name(), "dash")) { - sp_style_read_from_repr (style, dr); - if (style->stroke_dash.n_dash > 0) { - dashes[pos] = g_new (double, style->stroke_dash.n_dash + 1); - double *d = dashes[pos]; - int i = 0; - for (; i < style->stroke_dash.n_dash; i++) { - d[i] = style->stroke_dash.dash[i]; - } - d[i] = -1; - } else { - dashes[pos] = dash_0; - } - pos += 1; - } - } - sp_style_unref (style); - dashes[pos] = NULL; - } else { - dashes = builtin_dashes; - } - } - - GtkWidget *dsel = (GtkWidget*)gtk_type_new (SP_TYPE_DASH_SELECTOR); - - return dsel; + int pos = 0; + if (ndash > 0) { + double delta = 0.0; + for (int i = 0; i < ndash; i++) + delta += dash[i]; + delta /= 1000.0; + + for (int i = 0; dashes[i]; i++) { + double *pattern = dashes[i]; + int np = 0; + while (pattern[np] >= 0.0) + np += 1; + if (np == ndash) { + int j; + for (j = 0; j < ndash; j++) { + if (!NR_DF_TEST_CLOSE (dash[j], pattern[j], delta)) + break; + } + if (j == ndash) { + pos = i; + break; + } + } + } + } + + this->set_data("pattern", dashes[pos]); + this->dash->set_history(pos); + this->offset->set_value(o); } void -sp_dash_selector_set_dash (SPDashSelector *dsel, int ndash, double *dash, double offset) +SPDashSelector::get_dash(int *ndash, double **dash, double *off) { - int pos = 0; - if (ndash > 0) { - double delta = 0.0; - for (int i = 0; i < ndash; i++) - delta += dash[i]; - delta /= 1000.0; - - for (int i = 0; dashes[i]; i++) { - double *pattern = dashes[i]; - int np = 0; - while (pattern[np] >= 0.0) - np += 1; - if (np == ndash) { - int j; - for (j = 0; j < ndash; j++) { - if (!NR_DF_TEST_CLOSE (dash[j], pattern[j], delta)) - break; - } - if (j == ndash) { - pos = i; - break; - } - } - } - } - - gtk_object_set_data (GTK_OBJECT (dsel), "pattern", dashes[pos]); - gtk_option_menu_set_history (GTK_OPTION_MENU (dsel->dash), pos); - gtk_adjustment_set_value (GTK_ADJUSTMENT (dsel->offset), offset); + double *pattern = (double*) this->get_data("pattern"); + + int nd = 0; + while (pattern[nd] >= 0.0) + nd += 1; + + if (nd > 0) { + if (ndash) + *ndash = nd; + if (dash) { + *dash = g_new (double, nd); + memcpy (*dash, pattern, nd * sizeof (double)); + } + if (off) + *off = offset->get_value(); + } else { + if (ndash) + *ndash = 0; + if (dash) + *dash = NULL; + if (off) + *off = 0.0; + } } -void -sp_dash_selector_get_dash (SPDashSelector *dsel, int *ndash, double **dash, double *offset) +Gtk::MenuItem * +SPDashSelector::menu_item_new(double *pattern) { - double *pattern = (double*)gtk_object_get_data (GTK_OBJECT (dsel), "pattern"); - - int nd = 0; - while (pattern[nd] >= 0.0) - nd += 1; - - if (nd > 0) { - if (ndash) - *ndash = nd; - if (dash) { - *dash = g_new (double, nd); - memcpy (*dash, pattern, nd * sizeof (double)); - } - if (offset) - *offset = GTK_ADJUSTMENT (dsel->offset)->value; - } else { - if (ndash) - *ndash = 0; - if (dash) - *dash = NULL; - if (offset) - *offset = 0.0; - } + Gtk::MenuItem *mi = new Gtk::MenuItem(); + Gtk::Image *px = new Gtk::Image(); + + px->show(); + mi->add(*px); + + mi->set_data("pattern", pattern); + mi->set_data("px", px); + mi->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &SPDashSelector::dash_activate), mi)); + + px->signal_realize().connect(sigc::bind(sigc::ptr_fun(&sp_dash_selector_menu_item_image_realize), px, pattern)); + + return mi; } -bool +static bool all_even_are_zero (double *pattern, int n) { for (int i = 0; i < n; i += 2) { @@ -245,7 +218,7 @@ all_even_are_zero (double *pattern, int n) return true; } -bool +static bool all_odd_are_zero (double *pattern, int n) { for (int i = 1; i < n; i += 2) { @@ -255,134 +228,125 @@ all_odd_are_zero (double *pattern, int n) return true; } -static GtkWidget * -sp_dash_selector_menu_item_new (SPDashSelector *dsel, double *pattern) -{ - GtkWidget *mi = gtk_menu_item_new (); - GtkWidget *px = gtk_image_new_from_pixmap (NULL, NULL); - - gtk_widget_show (px); - gtk_container_add (GTK_CONTAINER (mi), px); - - gtk_object_set_data (GTK_OBJECT (mi), "pattern", pattern); - gtk_object_set_data (GTK_OBJECT (mi), "px", px); - gtk_signal_connect (GTK_OBJECT (mi), "activate", G_CALLBACK (sp_dash_selector_dash_activate), dsel); - - g_signal_connect_after(G_OBJECT(px), "realize", G_CALLBACK(sp_dash_selector_menu_item_image_realize), pattern); - - return mi; -} - -static void sp_dash_selector_menu_item_image_realize (GtkWidget *px, double *pattern) { - GdkPixmap *pixmap = gdk_pixmap_new(px->window, DASH_PREVIEW_LENGTH + 4, 16, -1); - GdkGC *gc = gdk_gc_new (pixmap); - - gdk_rgb_gc_set_foreground (gc, 0xffffffff); - gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, DASH_PREVIEW_LENGTH + 4, 16); - - // FIXME: all of the below twibblering is due to the limitations of gdk_gc_set_dashes (only integers, no zeroes). - // Perhaps would make sense to rework this with manually drawn dashes. - - // Fill in the integer array of pixel-lengths, for display - gint8 pixels_i[64]; - gdouble pixels_d[64]; - int n_source_dashes = 0; - int n_pixel_dashes = 0; - - signed int i_s, i_p; - for (i_s = 0, i_p = 0; pattern[i_s] >= 0.0; i_s ++, i_p ++) { - pixels_d[i_p] = 0.0; - } - - n_source_dashes = i_s; - - for (i_s = 0, i_p = 0; i_s < n_source_dashes; i_s ++, i_p ++) { - - // calculate the pixel length corresponding to the current dash - gdouble pixels = DASH_PREVIEW_WIDTH * pattern[i_s]; - - if (pixels > 0.0) - pixels_d [i_p] += pixels; - else { - if (i_p >= 1) { - // dash is zero, skip this element in the array, and set pointer backwards so the next dash is added to the previous - i_p -= 2; - } else { - // the first dash is zero; bad luck, gdk cannot start pattern with non-stroke, so we put a 1-pixel stub here - // (it may turn out not shown, though, see special cases below) - pixels_d [i_p] = 1.0; - } - } - } - - n_pixel_dashes = i_p; - - gdouble longest_dash = 0.0; - - // after summation, convert double dash lengths to ints - for (i_p = 0; i_p < n_pixel_dashes; i_p ++) { - pixels_i [i_p] = (gint8) (pixels_d [i_p] + 0.5); - // zero-length dashes are already eliminated, so the <1 dash is short but not zero; - // we approximate it with a one-pixel mark - if (pixels_i [i_p] < 1) - pixels_i [i_p] = 1; - if (i_p % 2 == 0) { // it's a dash - if (pixels_d [i_p] > longest_dash) - longest_dash = pixels_d [i_p]; - } - } - - if (longest_dash > 1e-18 && longest_dash < 0.5) { - // fake "shortening" of one-pixel marks by painting them lighter-than-black - gint rgb = 255 - (gint) (255 * longest_dash / 0.5); - gdk_rgb_gc_set_foreground (gc, SP_RGBA32_U_COMPOSE (rgb, rgb, rgb, rgb)); - } else { - gdk_rgb_gc_set_foreground (gc, 0x00000000); - } - - if (n_source_dashes > 0) { - // special cases: - if (all_even_are_zero (pattern, n_source_dashes)) { - ; // do not draw anything, only gaps are non-zero - } else if (all_odd_are_zero (pattern, n_source_dashes)) { - // draw solid line, only dashes are non-zero - gdk_gc_set_line_attributes (gc, DASH_PREVIEW_WIDTH, - GDK_LINE_SOLID, GDK_CAP_BUTT, - GDK_JOIN_MITER); - gdk_draw_line (pixmap, gc, 4, 8, DASH_PREVIEW_LENGTH, 8); - } else { - // regular pattern with both gaps and dashes non-zero - gdk_gc_set_line_attributes (gc, DASH_PREVIEW_WIDTH, - GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, - GDK_JOIN_MITER); - gdk_gc_set_dashes (gc, 0, pixels_i, n_pixel_dashes); - gdk_draw_line (pixmap, gc, 4, 8, DASH_PREVIEW_LENGTH, 8); - } - } else { - // no pattern, draw solid line - gdk_gc_set_line_attributes (gc, DASH_PREVIEW_WIDTH, - GDK_LINE_SOLID, GDK_CAP_BUTT, - GDK_JOIN_MITER); - gdk_draw_line (pixmap, gc, 4, 8, DASH_PREVIEW_LENGTH, 8); - } - - gdk_gc_unref (gc); - - gtk_image_set_from_pixmap(GTK_IMAGE(px), pixmap, NULL); - gdk_pixmap_unref(pixmap); +static void sp_dash_selector_menu_item_image_realize(Gtk::Image *px, double *pattern) { + Glib::RefPtr pixmap = Gdk::Pixmap::create(px->get_window(), DASH_PREVIEW_LENGTH + 4, 16, -1); + Glib::RefPtr gc = Gdk::GC::create(pixmap); + + gc->set_rgb_fg_color(Gdk::Color("#ffffff")); + pixmap->draw_rectangle(gc, true, 0, 0, DASH_PREVIEW_LENGTH + 4, 16); + + // FIXME: all of the below twibblering is due to the limitations of gdk_gc_set_dashes (only integers, no zeroes). + // Perhaps would make sense to rework this with manually drawn dashes. + + // Fill in the integer array of pixel-lengths, for display + gint8 pixels_i[64]; + gdouble pixels_d[64]; + int n_source_dashes = 0; + int n_pixel_dashes = 0; + + signed int i_s, i_p; + for (i_s = 0, i_p = 0; pattern[i_s] >= 0.0; i_s ++, i_p ++) { + pixels_d[i_p] = 0.0; + } + + n_source_dashes = i_s; + + for (i_s = 0, i_p = 0; i_s < n_source_dashes; i_s ++, i_p ++) { + // calculate the pixel length corresponding to the current dash + gdouble pixels = DASH_PREVIEW_WIDTH * pattern[i_s]; + + if (pixels > 0.0) + pixels_d [i_p] += pixels; + else { + if (i_p >= 1) { + // dash is zero, skip this element in the array, and set pointer backwards + // so the next dash is added to the previous + i_p -= 2; + } else { + // the first dash is zero; bad luck, gdk cannot start pattern with non-stroke, so we + // put a 1-pixel stub here (it may turn out not shown, though, see special cases below) + pixels_d [i_p] = 1.0; + } + } + } + + n_pixel_dashes = i_p; + + gdouble longest_dash = 0.0; + + // after summation, convert double dash lengths to ints + for (i_p = 0; i_p < n_pixel_dashes; i_p ++) { + pixels_i [i_p] = (gint8) (pixels_d [i_p] + 0.5); + // zero-length dashes are already eliminated, so the <1 dash is short but not zero; + // we approximate it with a one-pixel mark + if (pixels_i [i_p] < 1) + pixels_i [i_p] = 1; + if (i_p % 2 == 0) { // it's a dash + if (pixels_d [i_p] > longest_dash) + longest_dash = pixels_d [i_p]; + } + } + + Gdk::Color color; + if (longest_dash > 1e-18 && longest_dash < 0.5) { + // fake "shortening" of one-pixel marks by painting them lighter-than-black + gint rgb = 0xffff - (gint) (0xffff * longest_dash / 0.5); + color.set_rgb(rgb, rgb, rgb); + gc->set_rgb_fg_color(color); + } else { + color.set_rgb(0, 0, 0); + gc->set_rgb_fg_color(color); + } + + if (n_source_dashes > 0) { + // special cases: + if (all_even_are_zero (pattern, n_source_dashes)) { + ; // do not draw anything, only gaps are non-zero + } else if (all_odd_are_zero (pattern, n_source_dashes)) { + // draw solid line, only dashes are non-zero + gc->set_line_attributes(DASH_PREVIEW_WIDTH, + Gdk::LINE_SOLID, Gdk::CAP_BUTT, + Gdk::JOIN_MITER); + pixmap->draw_line(gc, 4, 8, DASH_PREVIEW_LENGTH, 8); + } else { + // regular pattern with both gaps and dashes non-zero + gc->set_line_attributes(DASH_PREVIEW_WIDTH, Gdk::LINE_ON_OFF_DASH, Gdk::CAP_BUTT, Gdk::JOIN_MITER); + gc->set_dashes(0, pixels_i, n_pixel_dashes); + pixmap->draw_line(gc, 4, 8, DASH_PREVIEW_LENGTH, 8); + } + } else { + // no pattern, draw solid line + gc->set_line_attributes(DASH_PREVIEW_WIDTH, Gdk::LINE_SOLID, Gdk::CAP_BUTT, Gdk::JOIN_MITER); + pixmap->draw_line(gc, 4, 8, DASH_PREVIEW_LENGTH, 8); + } + + Glib::RefPtr null_ptr; + px->set(pixmap, null_ptr); } -static void -sp_dash_selector_dash_activate (GtkObject *object, SPDashSelector *dsel) +void +SPDashSelector::dash_activate (Gtk::MenuItem *mi) { - double *pattern = (double*)gtk_object_get_data (object, "pattern"); - gtk_object_set_data (GTK_OBJECT (dsel), "pattern", pattern); + double *pattern = (double*) mi->get_data("pattern"); + this->set_data ("pattern", pattern); - gtk_signal_emit (GTK_OBJECT (dsel), signals[CHANGED]); + changed_signal.emit(); } -static void -sp_dash_selector_offset_value_changed (GtkAdjustment */*adj*/, SPDashSelector *dsel) + +void +SPDashSelector::offset_value_changed() { - gtk_signal_emit (GTK_OBJECT (dsel), signals[CHANGED]); + changed_signal.emit(); } + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/widgets/dash-selector.h b/src/widgets/dash-selector.h index a00834625..97e0b7379 100644 --- a/src/widgets/dash-selector.h +++ b/src/widgets/dash-selector.h @@ -1,38 +1,50 @@ -#ifndef __SP_DASH_SELECTOR_H__ -#define __SP_DASH_SELECTOR_H__ +#ifndef __SP_DASH_SELECTOR_NEW_H__ +#define __SP_DASH_SELECTOR_NEW_H__ /* * Optionmenu for selecting dash patterns * * Author: * Lauris Kaplinski + * Maximilian Albert (gtkmm-ification) * * Copyright (C) 2002 Lauris Kaplinski * * Released under GNU GPL, read the file 'COPYING' for more information */ -struct SPDashSelector; +#include "xml/repr.h" -#include -#include "../xml/repr.h" +#include +#include -#include +namespace Gtk { +class Container; +class OptionMenu; +class MenuItem; +class Adjustment; +} +// TODO: should we rather derive this from OptionMenu and add the spinbutton somehow else? +class SPDashSelector : public Gtk::HBox { +public: + SPDashSelector(Inkscape::XML::Node *drepr); + ~SPDashSelector(); + void set_dash(int ndash, double *dash, double offset); + void get_dash(int *ndash, double **dash, double *offset); -#define SP_TYPE_DASH_SELECTOR (sp_dash_selector_get_type ()) -#define SP_DASH_SELECTOR(o) (GTK_CHECK_CAST ((o), SP_TYPE_DASH_SELECTOR, SPDashSelector)) -#define SP_IS_DASH_SELECTOR(o) (GTK_CHECK_TYPE ((o), SP_TYPE_DASH_SELECTOR)) - -GtkType sp_dash_selector_get_type (void); - -GtkWidget *sp_dash_selector_new (Inkscape::XML::Node *repr); - -void sp_dash_selector_set_dash (SPDashSelector *dsel, int ndash, double *dash, double offset); -void sp_dash_selector_get_dash (SPDashSelector *dsel, int *ndash, double **dash, double *offset); + sigc::signal changed_signal; +private: + static void init_dashes(Inkscape::XML::Node *drepr); + void dash_activate(Gtk::MenuItem *mi); + void offset_value_changed(); + Gtk::MenuItem *menu_item_new(double *pattern); + Gtk::OptionMenu *dash; + Gtk::Adjustment *offset; +}; #endif diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index b9a7ad927..0e191b002 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -24,12 +24,29 @@ #include "helper/unit-menu.h" + +#include +#include +#include + /** * Creates a label widget with the given text, at the given col, row * position in the table. */ +Gtk::Label * +spw_label(Gtk::Table *table, const gchar *label_text, int col, int row) +{ + Gtk::Label *label_widget = new Gtk::Label(label_text); + g_assert(label_widget != NULL); + + label_widget->set_alignment(1.0, 0.5); + label_widget->show(); + table->attach(*label_widget, col, col+1, row, row+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 4, 0); + return label_widget; +} + GtkWidget * -spw_label(GtkWidget * table, const gchar *label_text, int col, int row) +spw_label_old(GtkWidget *table, const gchar *label_text, int col, int row) { GtkWidget *label_widget; @@ -46,16 +63,14 @@ spw_label(GtkWidget * table, const gchar *label_text, int col, int row) * Creates a horizontal layout manager with 4-pixel spacing between children * and space for 'width' columns. */ -GtkWidget * -spw_hbox(GtkWidget * table, int width, int col, int row) +Gtk::HBox * +spw_hbox(Gtk::Table * table, int width, int col, int row) { - GtkWidget *hb; /* Create a new hbox with a 4-pixel spacing between children */ - hb = gtk_hbox_new (FALSE, 4); + Gtk::HBox *hb = new Gtk::HBox(false, 4); g_assert(hb != NULL); - gtk_widget_show (hb); - gtk_table_attach (GTK_TABLE (table), hb, col, col+width, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); + hb->show(); + table->attach(*hb, col, col+width, row, row+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); return hb; } @@ -130,7 +145,7 @@ spw_dropdown(GtkWidget * dialog, GtkWidget * table, g_assert(table != NULL); g_assert(selector != NULL); - spw_label(table, label_text, 0, row); + spw_label_old(table, label_text, 0, row); gtk_widget_show (selector); gtk_table_attach (GTK_TABLE (table), selector, 1, 2, row, row+1, @@ -156,7 +171,7 @@ spw_unit_selector(GtkWidget * dialog, GtkWidget * table, g_assert(table != NULL); g_assert(us != NULL); - spw_label(table, label_text, 0, row); + spw_label_old(table, label_text, 0, row); a = gtk_adjustment_new (0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0); g_assert(a != NULL); @@ -254,3 +269,13 @@ sp_search_by_value_recursive (GtkWidget *w, gchar *key, gchar *value) return NULL; } +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index 7df08a2ce..5c4018199 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -21,11 +21,19 @@ #include #include /* GtkWidget */ -GtkWidget * -spw_label(GtkWidget *table, gchar const *label_text, int col, int row); +namespace Gtk { + class Label; + class Table; + class HBox; +} +Gtk::Label * +spw_label(Gtk::Table *table, gchar const *label_text, int col, int row); GtkWidget * -spw_hbox(GtkWidget *table, int width, int col, int row); +spw_label_old(GtkWidget *table, gchar const *label_text, int col, int row); + +Gtk::HBox * +spw_hbox(Gtk::Table *table, int width, int col, int row); GtkWidget * spw_vbox_checkbutton(GtkWidget *dialog, GtkWidget *table, @@ -54,3 +62,14 @@ gpointer sp_search_by_data_recursive(GtkWidget *w, gpointer data); GtkWidget *sp_search_by_value_recursive(GtkWidget *w, gchar *key, gchar *value); #endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -- 2.30.2