From: knutux Date: Fri, 28 Apr 2006 19:32:07 +0000 (+0000) Subject: Converting guideline properties dialog to gtkmm (first step - straightforward conversion) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=703bff6ff66a4eacb659a2edc2d4394290e459b4;p=inkscape.git Converting guideline properties dialog to gtkmm (first step - straightforward conversion) --- diff --git a/po/POTFILES.in b/po/POTFILES.in index ea368ce0f..d097555e5 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -6,6 +6,7 @@ src/application/editor.cpp src/arc-context.cpp src/attributes.cpp src/color.cpp +src/conditions.cpp src/connector-context.cpp src/context-fns.cpp src/desktop-affine.cpp @@ -21,6 +22,7 @@ src/dialogs/filedialog-win32.cpp src/dialogs/filedialog.cpp src/dialogs/fill-style.cpp src/dialogs/find.cpp +src/dialogs/guidelinedialog.cpp src/dialogs/iconpreview.cpp src/dialogs/in-dt-coordsys.cpp src/dialogs/item-properties.cpp @@ -228,6 +230,7 @@ src/sp-shape.cpp src/sp-spiral.cpp src/sp-star.cpp src/sp-symbol.cpp +src/sp-switch.cpp src/sp-text.cpp src/sp-use-reference.cpp src/sp-use.cpp diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 3147fae24..bab39d332 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -14,12 +14,6 @@ #ifdef HAVE_CONFIG_H # include #endif -#include -#include -#include -#include -#include -#include #include "display/guideline.h" #include "helper/unit-menu.h" #include "helper/units.h" @@ -35,9 +29,7 @@ #include "dialogs/dialog-events.h" #include "message-context.h" #include "xml/repr.h" - -static void sp_dt_simple_guide_dialog(SPGuide *guide, SPDesktop *desktop); - +#include "dialogs/guidelinedialog.h" /* Root item handler */ @@ -168,7 +160,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) if (event->button.button == 1) { dragging = false; sp_canvas_item_ungrab(item, event->button.time); - sp_dt_simple_guide_dialog(guide, desktop); + Inkscape::UI::Dialogs::GuidelinePropertiesDialog::showDialog(guide, desktop); ret = TRUE; } break; @@ -245,200 +237,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } - -/* - * simple guideline dialog - */ - -static GtkWidget *d = NULL; -static GtkWidget *l1; -static GtkWidget *l2; -static GtkWidget *e; -static GtkWidget *u; -static GtkWidget *m; -static gdouble oldpos; -static bool mode; -static gpointer g; - - -static void guide_dialog_mode_changed(GtkWidget *widget) -{ - if (mode) { - // TRANSLATORS: This string appears when double-clicking on a guide. - // This is the distance by which the guide is to be moved. - gtk_label_set_text(GTK_LABEL(m), _(" relative by ")); - mode = false; - } else { - // TRANSLATORS: This string appears when double-clicking on a guide. - // This is the target location where the guide is to be moved. - gtk_label_set_text(GTK_LABEL(m), _(" absolute to ")); - mode = true; - } -} - -static void guide_dialog_close(GtkWidget *widget, gpointer data) -{ - gtk_widget_hide(GTK_WIDGET(d)); -} - -static void guide_dialog_apply(SPGuide &guide) -{ - gdouble const raw_dist = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(e)); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const points = sp_units_get_pixels(raw_dist, unit); - gdouble const newpos = ( mode - ? points - : guide.position + points ); - sp_guide_moveto(guide, newpos, true); - sp_document_done(SP_OBJECT_DOCUMENT(&guide)); -} - -static void guide_dialog_ok(GtkWidget *widget, gpointer g) -{ - SPGuide &guide = **static_cast(g); - guide_dialog_apply(guide); - guide_dialog_close(NULL, GTK_DIALOG(widget)); -} - -static void guide_dialog_delete(GtkWidget *widget, SPGuide **guide) -{ - SPDocument *doc = SP_OBJECT_DOCUMENT(*guide); - sp_guide_remove(*guide); - sp_document_done(doc); - guide_dialog_close(NULL, GTK_DIALOG(widget)); -} - -static void guide_dialog_response(GtkDialog *dialog, gint response, gpointer data) -{ - GtkWidget *widget = GTK_WIDGET(dialog); - - switch (response) { - case GTK_RESPONSE_OK: - guide_dialog_ok(widget, data); - break; - case -12: - guide_dialog_delete(widget, (SPGuide**) data); - break; - case GTK_RESPONSE_CLOSE: - guide_dialog_close(widget, (GtkDialog*) data); - break; - case GTK_RESPONSE_DELETE_EVENT: - break; -/* case GTK_RESPONSE_APPLY: - guide_dialog_apply(widget, data); - break; -*/ - default: - g_assert_not_reached(); - } -} - -static void sp_dt_simple_guide_dialog(SPGuide *guide, SPDesktop *desktop) -{ - if (!GTK_IS_WIDGET(d)) { - // create dialog - d = gtk_dialog_new_with_buttons(_("Guideline"), - NULL, - GTK_DIALOG_MODAL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_DELETE, - -12, /* DELETE */ - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - sp_transientize(d); - gtk_widget_hide(d); - - GtkWidget *b1 = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), b1, FALSE, FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(b1), 4); - gtk_widget_show(b1); - - GtkWidget *b2 = gtk_vbox_new(FALSE, 4); - gtk_box_pack_end(GTK_BOX(b1), b2, TRUE, TRUE, 0); - gtk_widget_show(b2); - - //labels - GtkWidget *b3 = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(b2), b3, TRUE, TRUE, 0); - gtk_widget_show(b3); - - l1 = gtk_label_new("foo1"); - gtk_box_pack_start(GTK_BOX(b3), l1, TRUE, TRUE, 0); - gtk_misc_set_alignment(GTK_MISC(l1), 1.0, 0.5); - gtk_widget_show(l1); - - l2 = gtk_label_new("foo2"); - gtk_box_pack_start(GTK_BOX(b3), l2, TRUE, TRUE, 0); - gtk_misc_set_alignment(GTK_MISC(l2), 0.0, 0.5); - gtk_widget_show(l2); - - GtkWidget *b4 = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(b2), b4, FALSE, FALSE, 0); - gtk_widget_show(b4); - // mode button - GtkWidget *but = gtk_button_new(); - gtk_button_set_relief(GTK_BUTTON(but), GTK_RELIEF_NONE); - gtk_box_pack_start(GTK_BOX(b4), but, FALSE, TRUE, 0); - gtk_signal_connect_while_alive(GTK_OBJECT(but), "clicked", GTK_SIGNAL_FUNC(guide_dialog_mode_changed), - NULL , GTK_OBJECT(but)); - gtk_widget_show(but); - m = gtk_label_new(_(" absolute to ")); - mode = true; - gtk_container_add(GTK_CONTAINER(but), m); - gtk_widget_show(m); - - // unitmenu - /* fixme: We should allow percents here too, as percents of the canvas size */ - u = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(u), desktop->namedview->doc_units); - - // spinbutton - GtkObject *a = gtk_adjustment_new(0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0); - sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(u), GTK_ADJUSTMENT(a)); - e = gtk_spin_button_new(GTK_ADJUSTMENT(a), 1.0 , 2); - gtk_widget_show(e); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(e), TRUE); - gtk_box_pack_start(GTK_BOX(b4), e, TRUE, TRUE, 0); - gtk_signal_connect_object(GTK_OBJECT(e), "activate", - GTK_SIGNAL_FUNC(gtk_window_activate_default), - GTK_OBJECT(d)); -/* gnome_dialog_editable_enters(GNOME_DIALOG(d), GTK_EDITABLE(e)); */ - - gtk_widget_show(u); - gtk_box_pack_start(GTK_BOX(b4), u, FALSE, FALSE, 0); - - - // dialog - gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_OK); - gtk_signal_connect(GTK_OBJECT(d), "response", GTK_SIGNAL_FUNC(guide_dialog_response), &g); - gtk_signal_connect(GTK_OBJECT(d), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), GTK_WIDGET(d)); - } - - // initialize dialog - g = guide; - oldpos = guide->position; - { - char *guide_description = sp_guide_description(guide); - char *label = g_strdup_printf(_("Move %s"), guide_description); - g_free(guide_description); - gtk_label_set(GTK_LABEL(l1), label); - g_free(label); - } - - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const val = sp_pixels_get_units(oldpos, unit); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(e), val); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(e), val); - gtk_widget_grab_focus(e); - gtk_editable_select_region(GTK_EDITABLE(e), 0, 20); - gtk_window_set_position(GTK_WINDOW(d), GTK_WIN_POS_MOUSE); - - gtk_widget_show(d); -} - - /* Local Variables: mode:c++ diff --git a/src/dialogs/Makefile_insert b/src/dialogs/Makefile_insert index 4100ec853..3442ef66a 100644 --- a/src/dialogs/Makefile_insert +++ b/src/dialogs/Makefile_insert @@ -30,6 +30,8 @@ dialogs_libspdialogs_a_SOURCES = \ dialogs/filedialog.h \ dialogs/fill-style.cpp \ dialogs/fill-style.h \ + dialogs/guidelinedialog.cpp \ + dialogs/guidelinedialog.h \ dialogs/in-dt-coordsys.cpp \ dialogs/in-dt-coordsys.h \ dialogs/input.cpp \ diff --git a/src/dialogs/guidelinedialog.cpp b/src/dialogs/guidelinedialog.cpp new file mode 100644 index 000000000..6f8639d4c --- /dev/null +++ b/src/dialogs/guidelinedialog.cpp @@ -0,0 +1,220 @@ +#define __GUIDELINE_CPP__ + +/* + * simple guideline dialog + * + * Authors: + * Lauris Kaplinski + * Andrius R. + * + * Copyright (C) 1999-2006 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include "display/guideline.h" +#include "helper/unit-menu.h" +#include "helper/units.h" +#include "desktop.h" +#include "document.h" +#include "sp-guide.h" +#include "sp-namedview.h" +#include "desktop-handles.h" +#include "event-context.h" +#include "widgets/desktop-widget.h" +#include "sp-metrics.h" +#include +#include "dialogs/dialog-events.h" +#include "message-context.h" +#include "xml/repr.h" + +#include "guidelinedialog.h" + +namespace Inkscape { +namespace UI { +namespace Dialogs { + +GuidelinePropertiesDialog::GuidelinePropertiesDialog(SPGuide *guide, SPDesktop *desktop) +: _desktop(desktop), _guide(guide), + _a(0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0), + _u(NULL), _mode(true), _oldpos(0.0) +{ +} + +GuidelinePropertiesDialog::~GuidelinePropertiesDialog() { + if ( NULL != _u) { + //g_free(_u); + } +} + +void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) { + GuidelinePropertiesDialog *dialog = new GuidelinePropertiesDialog(guide, desktop); + dialog->_setup(); + dialog->run(); + delete dialog; +} + +void GuidelinePropertiesDialog::_modeChanged() +{ + if (_mode) { + // TRANSLATORS: This string appears when double-clicking on a guide. + // This is the distance by which the guide is to be moved. + _m.set_label(_(" relative by ")); + _mode = false; + } else { + // TRANSLATORS: This string appears when double-clicking on a guide. + // This is the target location where the guide is to be moved. + _m.set_label(_(" absolute to ")); + _mode = true; + } +} + +void GuidelinePropertiesDialog::_onApply() +{ + gdouble const raw_dist = _e.get_value(); + SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_u)); + gdouble const points = sp_units_get_pixels(raw_dist, unit); + gdouble const newpos = ( _mode + ? points + : _guide->position + points ); + sp_guide_moveto(*_guide, newpos, true); + sp_document_done(SP_OBJECT_DOCUMENT(_guide)); +} + +void GuidelinePropertiesDialog::_onOK() +{ + _onApply(); +} + +void GuidelinePropertiesDialog::_onDelete() +{ + SPDocument *doc = SP_OBJECT_DOCUMENT(_guide); + sp_guide_remove(_guide); + sp_document_done(doc); +} + +void GuidelinePropertiesDialog::_response(gint response) +{ + switch (response) { + case Gtk::RESPONSE_OK: + _onOK(); + break; + case -12: + _onDelete(); + break; + case Gtk::RESPONSE_CLOSE: + break; + case Gtk::RESPONSE_DELETE_EVENT: + break; +/* case GTK_RESPONSE_APPLY: + _onApply(); + break; +*/ + default: + g_assert_not_reached(); + } +} + +void GuidelinePropertiesDialog::_setup() { + set_title(_("Guideline")); + add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); + add_button(Gtk::Stock::DELETE, -12); + add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); + + Gtk::VBox *mainVBox = get_vbox(); + + _b1.set_homogeneous(false); + _b1.set_spacing(4); + mainVBox->pack_start(_b1, false, false, 0); + _b1.set_border_width(4); + + _b2.set_homogeneous(false); + _b2.set_spacing(4); + _b1.pack_start(_b2, true, true, 0); + + //labels + _b3.set_homogeneous(false); + _b3.set_spacing(4); + _b2.pack_start(_b3, true, true, 0); + + _l1.set_label("foo1"); + _b3.pack_start(_l1, true, true, 0); + _l1.set_alignment(1.0, 0.5); + + _l2.set_label("foo2"); + _b3.pack_start(_l2, true, true, 0); + _l2.set_alignment(0.0, 0.5); + + _b4.set_homogeneous(false); + _b4.set_spacing(4); + _b2.pack_start(_b4, false, false, 0); + + // mode button + _but.set_relief(Gtk::RELIEF_NONE); + _b4.pack_start(_but, false, true, 0); + _but.signal_clicked().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged)); + _m.set_label(_(" absolute to ")); + _but.add(_m); + + // unitmenu + /* fixme: We should allow percents here too, as percents of the canvas size */ + _u = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); + sp_unit_selector_set_unit(SP_UNIT_SELECTOR(_u), _desktop->namedview->doc_units); + + // spinbutton + sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(_u), GTK_ADJUSTMENT(_a.gobj())); + _e.configure(_a, 1.0 , 2); + _e.set_numeric(TRUE); + _b4.pack_start(_e, true, true, 0); + gtk_signal_connect_object(GTK_OBJECT(_e.gobj()), "activate", + GTK_SIGNAL_FUNC(gtk_window_activate_default), + gobj()); + + gtk_box_pack_start(GTK_BOX(_b4.gobj()), _u, FALSE, FALSE, 0); + + + // dialog + set_default_response(Gtk::RESPONSE_OK); + signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response)); + + // initialize dialog + _oldpos = _guide->position; + { + gchar *guide_description = sp_guide_description(_guide); + gchar *label = g_strdup_printf(_("Move %s"), guide_description); + g_free(guide_description); + _l1.set_label(label); + g_free(label); + } + + SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_u)); + gdouble const val = sp_pixels_get_units(_oldpos, unit); + _e.set_value(val); + _e.grab_focus(); + _e.select_region(0, 20); + set_position(Gtk::WIN_POS_MOUSE); + + show_all_children(); + set_modal(true); + _desktop->setWindowTransient (gobj()); + property_destroy_with_parent() = true; +} + +} +} +} + +/* + 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/dialogs/guidelinedialog.h b/src/dialogs/guidelinedialog.h new file mode 100644 index 000000000..091528786 --- /dev/null +++ b/src/dialogs/guidelinedialog.h @@ -0,0 +1,83 @@ +/** + * + * \brief Dialog for modifying guidelines + * + * Author: + * Andrius R. + * + * Copyright (C) 2006 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_DIALOG_GUIDELINE_H +#define INKSCAPE_DIALOG_GUIDELINE_H + +#include +#include +#include +#include +#include + +namespace Inkscape { +namespace UI { +namespace Dialogs { + +class GuidelinePropertiesDialog : public Gtk::Dialog { +public: + GuidelinePropertiesDialog(SPGuide *guide, SPDesktop *desktop); + virtual ~GuidelinePropertiesDialog(); + + Glib::ustring getName() const { return "LayerPropertiesDialog"; } + + static void showDialog(SPGuide *guide, SPDesktop *desktop); + +protected: + void _setup(); + + void _onApply(); + void _onOK(); + void _onDelete(); + + void _response(gint response); + void _modeChanged(); + +private: + GuidelinePropertiesDialog(GuidelinePropertiesDialog const &); // no copy + GuidelinePropertiesDialog &operator=(GuidelinePropertiesDialog const &); // no assign + + SPDesktop *_desktop; + SPGuide *_guide; + Gtk::HBox _b1; + Gtk::VBox _b2; + Gtk::HBox _b3; + Gtk::HBox _b4; + Gtk::Label _l1; + Gtk::Label _l2; + Gtk::Button _but; + Gtk::Label _m; + Gtk::Adjustment _a; + Gtk::SpinButton _e; + + GtkWidget *_u; + bool _mode; + gdouble _oldpos; +}; + +} // namespace +} // namespace +} // namespace + + +#endif // INKSCAPE_DIALOG_GUIDELINE_H + +/* + 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/dialogs/layer-properties.cpp b/src/dialogs/layer-properties.cpp index 2b39155b0..6a88597be 100644 --- a/src/dialogs/layer-properties.cpp +++ b/src/dialogs/layer-properties.cpp @@ -36,9 +36,6 @@ namespace Dialogs { LayerPropertiesDialog::LayerPropertiesDialog() : _strategy(NULL), _desktop(NULL), _layer(NULL), _position_visible(false) { - GtkWidget *dlg = GTK_WIDGET(gobj()); - g_assert(dlg); - Gtk::VBox *mainVBox = get_vbox(); _layout_table.set_spacings(4);