summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-08-14 20:54:48 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-08-14 20:54:48 +0000
commit55d43e4e27e0ba58a47fad70957dfa989aa173ad (patch)
tree2ccfbac1c50023d08ae32975c876fa2478c1ad2a /src/ui
parentFix for bug #1752113; added set_preview_widget_active(false) to FileSaveDialo... (diff)
downloadinkscape-55d43e4e27e0ba58a47fad70957dfa989aa173ad.tar.gz
inkscape-55d43e4e27e0ba58a47fad70957dfa989aa173ad.zip
Commit LivePathEffect branch to trunk!
(disabled extension/internal/bitmap/*.* in build.xml to fix compilation) (bzr r3472)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/Makefile_insert2
-rw-r--r--src/ui/dialog/dialog-manager.cpp2
-rw-r--r--src/ui/dialog/livepatheffect-editor.cpp290
-rw-r--r--src/ui/dialog/livepatheffect-editor.h85
-rw-r--r--src/ui/widget/Makefile_insert3
-rw-r--r--src/ui/widget/combo-enums.h36
-rw-r--r--src/ui/widget/point.cpp237
-rw-r--r--src/ui/widget/point.h96
-rw-r--r--src/ui/widget/registered-enums.h110
-rw-r--r--src/ui/widget/registered-widget.cpp323
-rw-r--r--src/ui/widget/registered-widget.h187
11 files changed, 1191 insertions, 180 deletions
diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert
index 60be61678..11011d0c5 100644
--- a/src/ui/dialog/Makefile_insert
+++ b/src/ui/dialog/Makefile_insert
@@ -34,6 +34,8 @@ ui_dialog_libuidialog_a_SOURCES = \
ui/dialog/inkscape-preferences.h \
ui/dialog/layer-editor.cpp \
ui/dialog/layer-editor.h \
+ ui/dialog/livepatheffect-editor.cpp \
+ ui/dialog/livepatheffect-editor.h \
ui/dialog/memory.cpp \
ui/dialog/memory.h \
ui/dialog/messages.cpp \
diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp
index 6b0277610..23c64f1d5 100644
--- a/src/ui/dialog/dialog-manager.cpp
+++ b/src/ui/dialog/dialog-manager.cpp
@@ -27,6 +27,7 @@
#include "ui/dialog/find.h"
#include "ui/dialog/inkscape-preferences.h"
#include "ui/dialog/layer-editor.h"
+#include "ui/dialog/livepatheffect-editor.h"
#include "ui/dialog/memory.h"
#include "ui/dialog/messages.h"
#include "ui/dialog/scriptdialog.h"
@@ -80,6 +81,7 @@ DialogManager::DialogManager() {
registerFactory("Find", &create<Find>);
registerFactory("InkscapePreferences", &create<InkscapePreferences>);
registerFactory("LayerEditor", &create<LayerEditor>);
+ registerFactory("LivePathEffect", &create<LivePathEffectEditor>);
registerFactory("Memory", &create<Memory>);
registerFactory("Messages", &create<Messages>);
registerFactory("Script", &create<ScriptDialog>);
diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp
new file mode 100644
index 000000000..5f765b420
--- /dev/null
+++ b/src/ui/dialog/livepatheffect-editor.cpp
@@ -0,0 +1,290 @@
+/**
+ * \brief LivePathEffect dialog
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glibmm/i18n.h>
+#include "livepatheffect-editor.h"
+#include "verbs.h"
+#include "selection.h"
+#include "sp-shape.h"
+#include "sp-path.h"
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject.h"
+#include "gtkmm/widget.h"
+#include <vector>
+#include "inkscape.h"
+#include "desktop-handles.h"
+#include "desktop.h"
+#include "document-private.h"
+#include "xml/node.h"
+#include "xml/document.h"
+
+namespace Inkscape {
+class Application;
+
+namespace UI {
+namespace Dialog {
+
+
+/*####################
+ * Callback functions
+ */
+static void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)
+{
+ LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);
+ lpeeditor->onSelectionChanged(selection);
+}
+
+static void lpeeditor_selection_modified (Inkscape::Selection *selection, guint flags, gpointer data)
+{
+ lpeeditor_selection_changed (selection, data);
+}
+
+
+static void lpeeditor_desktop_change(Inkscape::Application*, SPDesktop* desktop, void *data)
+{
+ if (!desktop) {
+ return;
+ }
+ LivePathEffectEditor* editor = reinterpret_cast<LivePathEffectEditor*>(data);
+ editor->setDesktop(desktop);
+}
+
+
+
+/*#######################
+ * LivePathEffectEditor
+ */
+LivePathEffectEditor::LivePathEffectEditor()
+ : Dialog ("dialogs.livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
+ combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter),
+ button_apply(_("_Apply"), _("Apply chosen effect to selection")),
+ button_remove(_("_Remove"), _("Remove effect from selection")),
+ effectwidget(NULL),
+ explain_label("", Gtk::ALIGN_CENTER),
+ effectapplication_frame(_("Apply new effect")),
+ effectcontrol_frame(_("Current effect")),
+ current_desktop(NULL)
+{
+ // Top level vbox
+ Gtk::VBox *vbox = get_vbox();
+ vbox->set_spacing(4);
+
+ effectapplication_vbox.set_spacing(4);
+ effectcontrol_vbox.set_spacing(4);
+
+ effectapplication_vbox.pack_start(combo_effecttype, true, true);
+ effectapplication_vbox.pack_start(button_apply, true, true);
+ effectapplication_vbox.pack_start(button_remove, true, true);
+ effectapplication_frame.add(effectapplication_vbox);
+
+ effectcontrol_vbox.pack_start(explain_label, true, true);
+ effectcontrol_frame.add(effectcontrol_vbox);
+
+ vbox->pack_start(effectapplication_frame, true, true);
+ vbox->pack_start(effectcontrol_frame, true, true);
+
+ // connect callback functions to buttons
+ button_apply.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onApply));
+ button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));
+
+ // connect callback functions to changes in selected desktop.
+ g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop",
+ G_CALLBACK(lpeeditor_desktop_change), this);
+
+ g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop",
+ G_CALLBACK(lpeeditor_desktop_change), this);
+
+ setDesktop(SP_ACTIVE_DESKTOP);
+ show_all_children();
+}
+
+LivePathEffectEditor::~LivePathEffectEditor()
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ if (current_desktop) {
+ selection_changed_connection.disconnect();
+ selection_modified_connection.disconnect();
+ }
+}
+
+void
+LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ explain_label.set_markup("<b>" + effect->getName() + "</b>");
+ effectwidget = effect->getWidget();
+ if (effectwidget) {
+ effectcontrol_vbox.pack_start(*effectwidget, true, true);
+ }
+
+ effectcontrol_vbox.show_all_children();
+ // fixme: do resizing of dialog
+}
+
+void
+LivePathEffectEditor::showText(Glib::ustring const &str)
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ explain_label.set_label(str);
+
+ // fixme: do resizing of dialog ?
+}
+
+void
+LivePathEffectEditor::set_sensitize_all(bool sensitive)
+{
+ combo_effecttype.set_sensitive(sensitive);
+ button_apply.set_sensitive(sensitive);
+ button_remove.set_sensitive(sensitive);
+}
+
+void
+LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
+{
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item ) {
+ if ( SP_IS_SHAPE(item) ) {
+ SPShape *shape = SP_SHAPE(item);
+ LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape);
+ set_sensitize_all(true);
+ if (lpeobj) {
+ if (lpeobj->lpe) {
+ showParams(lpeobj->lpe);
+ } else {
+ showText(_("Unknown effect is applied"));
+ }
+ } else {
+ showText(_("No effect applied"));
+ button_remove.set_sensitive(false);
+ }
+ } else {
+ showText(_("Item is not a shape"));
+ set_sensitize_all(false);
+ }
+ } else {
+ showText(_("Only one item can be selected"));
+ set_sensitize_all(false);
+ }
+ } else {
+ showText(_("Empty selection"));
+ set_sensitize_all(false);
+ }
+}
+
+void
+LivePathEffectEditor::setDesktop(SPDesktop *desktop)
+{
+
+ if ( desktop == current_desktop ) {
+ return;
+ }
+
+ if (current_desktop) {
+ selection_changed_connection.disconnect();
+ selection_modified_connection.disconnect();
+ }
+
+ current_desktop = desktop;
+ if (desktop) {
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+ selection_changed_connection = selection->connectChanged(
+ sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) );
+ selection_modified_connection = selection->connectModified(
+ sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) );
+
+ onSelectionChanged(selection);
+ } else {
+ onSelectionChanged(NULL);
+ }
+}
+
+
+
+
+/*########################################################################
+# BUTTON CLICK HANDLERS (callbacks)
+########################################################################*/
+
+void
+LivePathEffectEditor::onApply()
+{
+ Inkscape::Selection *sel = _getSelection();
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item && SP_IS_SHAPE(item) ) {
+ SPDocument *doc = current_desktop->doc();
+
+ const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data();
+ if (!data) return;
+
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+ Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");
+ repr->setAttribute("effect", data->key.c_str() );
+
+ SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute
+ const gchar * repr_id = repr->attribute("id");
+ Inkscape::GC::release(repr);
+
+ gchar *href = g_strdup_printf("#%s", repr_id);
+ sp_shape_set_path_effect(SP_SHAPE(item), href);
+ g_free(href);
+
+ // make sure there is an original-d for paths!!!
+ if ( SP_IS_PATH(item) ) {
+ Inkscape::XML::Node *pathrepr = SP_OBJECT_REPR(item);
+ if ( ! pathrepr->attribute("inkscape:original-d") ) {
+ pathrepr->setAttribute("inkscape:original-d", pathrepr->attribute("d"));
+ }
+ }
+
+ sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ _("Create and apply live effect"));
+ }
+ }
+}
+
+void
+LivePathEffectEditor::onRemove()
+{
+ Inkscape::Selection *sel = _getSelection();
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item && SP_IS_SHAPE(item) ) {
+ sp_shape_remove_path_effect(SP_SHAPE(item));
+ sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ _("Remove live path effect") );
+ }
+ }
+}
+
+
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h
new file mode 100644
index 000000000..5476f8a1d
--- /dev/null
+++ b/src/ui/dialog/livepatheffect-editor.h
@@ -0,0 +1,85 @@
+/**
+ * \brief LivePathEffect dialog
+ *
+ * Author:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H
+#define INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H
+
+#include "dialog.h"
+#include "ui/widget/button.h"
+
+#include <gtkmm/label.h>
+#include <gtkmm/comboboxtext.h>
+#include <gtkmm/frame.h>
+#include "ui/widget/combo-enums.h"
+#include "live_effects/effect.h"
+
+class SPDesktop;
+
+namespace Inkscape {
+
+namespace UI {
+namespace Dialog {
+
+class LivePathEffectEditor : public Dialog {
+public:
+ LivePathEffectEditor();
+ virtual ~LivePathEffectEditor();
+
+ static LivePathEffectEditor *create() { return new LivePathEffectEditor(); }
+
+ void onSelectionChanged(Inkscape::Selection *sel);
+ void setDesktop(SPDesktop *desktop);
+
+private:
+ sigc::connection selection_changed_connection;
+ sigc::connection selection_modified_connection;
+
+ void set_sensitize_all(bool sensitive);
+
+ void showParams(LivePathEffect::Effect* effect);
+ void showText(Glib::ustring const &str);
+
+ // callback methods for buttons on grids page.
+ void onApply();
+ void onRemove();
+
+ Inkscape::UI::Widget::ComboBoxEnum<LivePathEffect::EffectType> combo_effecttype;
+ Inkscape::UI::Widget::Button button_apply;
+ Inkscape::UI::Widget::Button button_remove;
+ Gtk::Widget * effectwidget;
+ Gtk::Label explain_label;
+ Gtk::Frame effectapplication_frame;
+ Gtk::Frame effectcontrol_frame;
+ Gtk::VBox effectapplication_vbox;
+ Gtk::VBox effectcontrol_vbox;
+
+ SPDesktop * current_desktop;
+
+ LivePathEffectEditor(LivePathEffectEditor const &d);
+ LivePathEffectEditor& operator=(LivePathEffectEditor const &d);
+};
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_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/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index 11c18738c..178e954a4 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -37,10 +37,13 @@ ui_widget_libuiwidget_a_SOURCES = \
ui/widget/page-sizer.h \
ui/widget/panel.cpp \
ui/widget/panel.h \
+ ui/widget/point.cpp \
+ ui/widget/point.h \
ui/widget/preferences-widget.cpp \
ui/widget/preferences-widget.h \
ui/widget/registered-widget.cpp \
ui/widget/registered-widget.h \
+ ui/widget/registered-enums.h \
ui/widget/registry.cpp \
ui/widget/registry.h \
ui/widget/ruler.cpp \
diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h
index b384ca474..22aa55dab 100644
--- a/src/ui/widget/combo-enums.h
+++ b/src/ui/widget/combo-enums.h
@@ -17,6 +17,7 @@
#include <gtkmm/liststore.h>
#include "attr-widget.h"
#include "util/enums.h"
+#include "ui/widget/labelled.h"
namespace Inkscape {
namespace UI {
@@ -74,6 +75,23 @@ public:
row[_columns.data] = 0;
row[_columns.label] = s;
}
+
+ void set_active_by_id(E id) {
+ for(Gtk::TreeModel::iterator i = _model->children().begin();
+ i != _model->children().end(); ++i)
+ {
+ const Util::EnumData<E>* data = (*i)[_columns.data];
+ if(data->id == id) {
+ set_active(i);
+ break;
+ }
+ }
+ };
+
+ void set_active_by_key(const Glib::ustring& key) {
+ set_active_by_id( _converter.get_id_from_key(key) );
+ };
+
private:
class Columns : public Gtk::TreeModel::ColumnRecord
{
@@ -93,6 +111,24 @@ private:
const Util::EnumDataConverter<E>& _converter;
};
+
+template<typename E> class LabelledComboBoxEnum : public Labelled
+{
+public:
+ LabelledComboBoxEnum( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ const Util::EnumDataConverter<E>& c,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true)
+ : Labelled(label, tooltip, new ComboBoxEnum<E>(c), suffix, icon, mnemonic)
+ { }
+
+ ComboBoxEnum<E>* getCombobox() {
+ return static_cast< ComboBoxEnum<E>* > (_widget);
+ }
+};
+
}
}
}
diff --git a/src/ui/widget/point.cpp b/src/ui/widget/point.cpp
new file mode 100644
index 000000000..cfaa4303d
--- /dev/null
+++ b/src/ui/widget/point.cpp
@@ -0,0 +1,237 @@
+/**
+ * \brief Point Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary coordinate values.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2007 Authors
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "ui/widget/point.h"
+#include "ui/widget/labelled.h"
+#include "ui/widget/scalar.h"
+#include <gtkmm/box.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ setProgrammatically(false),
+ xwidget("X:",""),
+ ywidget("Y:","")
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param digits Number of decimal digits to display.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ setProgrammatically(false),
+ xwidget("X:","", digits),
+ ywidget("Y:","", digits)
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param adjust Adjustment to use for the SpinButton.
+ * \param digits Number of decimal digits to display (defaults to 0).
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to true).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ setProgrammatically(false),
+ xwidget("X:","", adjust, digits),
+ ywidget("Y:","", adjust, digits)
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/** Fetches the precision of the spin buton */
+unsigned
+Point::getDigits() const
+{
+ return xwidget.getDigits();
+}
+
+/** Gets the current step ingrement used by the spin button */
+double
+Point::getStep() const
+{
+ return xwidget.getStep();
+}
+
+/** Gets the current page increment used by the spin button */
+double
+Point::getPage() const
+{
+ return xwidget.getPage();
+}
+
+/** Gets the minimum range value allowed for the spin button */
+double
+Point::getRangeMin() const
+{
+ return xwidget.getRangeMin();
+}
+
+/** Gets the maximum range value allowed for the spin button */
+double
+Point::getRangeMax() const
+{
+ return xwidget.getRangeMax();
+}
+
+/** Get the value in the spin_button . */
+double
+Point::getXValue() const
+{
+ return xwidget.getValue();
+}
+double
+Point::getYValue() const
+{
+ return ywidget.getValue();
+}
+
+/** Get the value spin_button represented as an integer. */
+int
+Point::getXValueAsInt() const
+{
+ return xwidget.getValueAsInt();
+}
+int
+Point::getYValueAsInt() const
+{
+ return ywidget.getValueAsInt();
+}
+
+
+/** Sets the precision to be displayed by the spin button */
+void
+Point::setDigits(unsigned digits)
+{
+ xwidget.setDigits(digits);
+ ywidget.setDigits(digits);
+}
+
+/** Sets the step and page increments for the spin button */
+void
+Point::setIncrements(double step, double page)
+{
+ xwidget.setIncrements(step, page);
+ ywidget.setIncrements(step, page);
+}
+
+/** Sets the minimum and maximum range allowed for the spin button */
+void
+Point::setRange(double min, double max)
+{
+ xwidget.setRange(min, max);
+ ywidget.setRange(min, max);
+}
+
+/** Sets the value of the spin button */
+void
+Point::setValue(double xvalue, double yvalue)
+{
+ setProgrammatically = true; // callback is supposed to reset back, if it cares
+ xwidget.setValue(xvalue);
+ ywidget.setValue(yvalue);
+}
+
+/** Manually forces an update of the spin button */
+void
+Point::update() {
+ xwidget.update();
+ ywidget.update();
+}
+
+
+
+/** Signal raised when the spin button's value changes */
+Glib::SignalProxy0<void>
+Point::signal_x_value_changed()
+{
+ return xwidget.signal_value_changed();
+}
+Glib::SignalProxy0<void>
+Point::signal_y_value_changed()
+{
+ return ywidget.signal_value_changed();
+}
+
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ 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/ui/widget/point.h b/src/ui/widget/point.h
new file mode 100644
index 000000000..291ae131e
--- /dev/null
+++ b/src/ui/widget/point.h
@@ -0,0 +1,96 @@
+/**
+ * \brief Point Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary coordinate values.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2007 Authors
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_POINT_H
+#define INKSCAPE_UI_WIDGET_POINT_H
+
+#include <gtkmm/adjustment.h>
+#include <gtkmm/spinbutton.h>
+
+#include "ui/widget/labelled.h"
+#include "ui/widget/scalar.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class Point : public Labelled
+{
+public:
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits = 0,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+
+ unsigned getDigits() const;
+ double getStep() const;
+ double getPage() const;
+ double getRangeMin() const;
+ double getRangeMax() const;
+ bool getSnapToTicks() const;
+ double getXValue() const;
+ double getYValue() const;
+ int getXValueAsInt() const;
+ int getYValueAsInt() const;
+
+ void setDigits(unsigned digits);
+ void setIncrements(double step, double page);
+ void setRange(double min, double max);
+ void setValue(double xvalue, double yvalue);
+
+ void update();
+
+ Glib::SignalProxy0<void> signal_x_value_changed();
+ Glib::SignalProxy0<void> signal_y_value_changed();
+
+ bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
+ // if a callback checks it, it must reset it back to false
+
+protected:
+ Scalar xwidget, ywidget;
+
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_POINT_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/ui/widget/registered-enums.h b/src/ui/widget/registered-enums.h
new file mode 100644
index 000000000..bfa866e29
--- /dev/null
+++ b/src/ui/widget/registered-enums.h
@@ -0,0 +1,110 @@
+/**
+ * \brief Simplified management of enumerations in the UI as combobox.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
+#define INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
+
+#include "ui/widget/combo-enums.h"
+#include "ui/widget/registered-widget.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+template<typename E> class RegisteredEnum : public RegisteredWidget
+{
+public:
+ RegisteredEnum() {
+ labelled = NULL;
+ }
+
+ ~RegisteredEnum() {
+ _changed_connection.disconnect();
+ if (labelled)
+ delete labelled;
+ }
+
+ void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ const Util::EnumDataConverter<E>& c,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in)
+ {
+ init_parent(key, wr, repr_in, doc_in);
+
+ labelled = new LabelledComboBoxEnum<E> (label, tip, c);
+
+ _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed));
+ }
+
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& key,
+ Registry& wr)
+ {
+ init(label, key, wr, NULL, NULL);
+ }
+
+ void set_active_by_id (E id) {
+ combobox()->set_active_by_id(id);
+ };
+
+ void set_active_by_key (const Glib::ustring& key) {
+ combobox()->set_active_by_key(key);
+ }
+
+ inline const Util::EnumData<E>* get_active_data() {
+ return combobox()->get_active_data();
+ }
+
+ ComboBoxEnum<E> * combobox() {
+ if (labelled) {
+ return labelled->getCombobox();
+ } else {
+ return NULL;
+ }
+ }
+
+ LabelledComboBoxEnum<E> * labelled;
+ sigc::connection _changed_connection;
+
+protected:
+ void on_changed() {
+ if (_wr->isUpdating())
+ return;
+ _wr->setUpdating (true);
+
+ const Util::EnumData<E>* data = combobox()->get_active_data();
+ if (data) {
+ write_to_xml(data->key.c_str());
+ }
+
+ _wr->setUpdating (false);
+ }
+};
+
+}
+}
+}
+
+#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 :
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index 6ef264b0d..8a569bc32 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -2,13 +2,14 @@
*
*
* Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
* bulia byak <buliabyak@users.sf.net>
* Bryce W. Harrington <bryce@bryceharrington.org>
* Lauris Kaplinski <lauris@kaplinski.com>
* Jon Phillips <jon@rejon.org>
* Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
*
- * Copyright (C) 2000 - 2005 Authors
+ * Copyright (C) 2000 - 2007 Authors
*
* Released under GNU GPL. Read the file 'COPYING' for more information
*/
@@ -21,6 +22,8 @@
#include "ui/widget/color-picker.h"
#include "ui/widget/registry.h"
#include "ui/widget/scalar-unit.h"
+#include "ui/widget/point.h"
+#include "widgets/spinbutton-events.h"
#include "helper/units.h"
#include "xml/repr.h"
@@ -35,6 +38,9 @@
#include "registered-widget.h"
#include "verbs.h"
+// for interruptability bug:
+#include "display/sp-canvas.h"
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -44,6 +50,31 @@ namespace Widget {
//---------------------------------------------------
+void
+RegisteredWidget::write_to_xml(const char * svgstr)
+{
+ // Use local repr here. When repr is specified, use that one, but
+ // if repr==NULL, get the repr of namedview of active desktop.
+ Inkscape::XML::Node *local_repr = repr;
+ SPDocument *local_doc = doc;
+ if (!local_repr) {
+ // no repr specified, use active desktop's namedview's repr
+ SPDesktop* dt = SP_ACTIVE_DESKTOP;
+ local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
+ local_doc = sp_desktop_document(dt);
+ }
+
+ bool saved = sp_document_get_undo_sensitive (local_doc);
+ sp_document_set_undo_sensitive (local_doc, false);
+ if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr);
+ local_doc->rroot->setAttribute("sodipodi:modified", "true");
+ sp_document_set_undo_sensitive (local_doc, saved);
+ if (write_undo) {
+ local_repr->setAttribute(_key.c_str(), svgstr);
+ sp_document_done (local_doc, event_type, event_description);
+ }
+}
+
//====================================================
@@ -61,20 +92,15 @@ RegisteredCheckButton::~RegisteredCheckButton()
void
RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
+ init_parent(key, wr, repr_in, doc_in);
+
_button = new Gtk::CheckButton;
_tt.set_tip (*_button, tip);
Gtk::Label *l = new Gtk::Label (label);
l->set_use_underline (true);
_button->add (*manage (l));
_button->set_alignment (right? 1.0 : 0.0, 0.5);
- _key = key;
- _wr = &wr;
_toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled));
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_error("Initialization of registered widget using defined repr but with doc==NULL");
}
void
@@ -93,33 +119,15 @@ RegisteredCheckButton::on_toggled()
if (_wr->isUpdating())
return;
- // Use local repr here. When repr is specified, use that one, but
- // if repr==NULL, get the repr of namedview of active desktop.
- Inkscape::XML::Node *local_repr = repr;
- SPDocument *local_doc = doc;
- if (!local_repr) {
- // no repr specified, use active desktop's namedview's repr
- SPDesktop *dt = SP_ACTIVE_DESKTOP;
- if (!dt)
- return;
- local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
- local_doc = sp_desktop_document(dt);
- }
-
_wr->setUpdating (true);
- //The slave button is greyed out if the master button is unchecked
- for (std::list<Gtk::ToggleButton*>::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) {
- (*i)->set_sensitive(_button->get_active());
- }
-
- bool saved = sp_document_get_undo_sensitive (local_doc);
- sp_document_set_undo_sensitive (local_doc, false);
- sp_repr_set_boolean(local_repr, _key.c_str(), _button->get_active());
- local_doc->rroot->setAttribute("sodipodi:modified", "true");
- sp_document_set_undo_sensitive (local_doc, saved);
- sp_document_done (local_doc, SP_VERB_NONE,
- /* TODO: annotate */ "registered-widget.cpp: RegisteredCheckButton::on_toggled");
+ write_to_xml(_button->get_active() ? "true" : "false");
+ //The slave button is greyed out if the master button is unchecked
+ for (std::list<Gtk::ToggleButton*>::const_iterator i = _slavebuttons.begin(); i != _slavebuttons.end(); i++) {
+ (*i)->set_sensitive(_button->get_active());
+ }
+
+ write_to_xml(_button->get_active() ? "true" : "false");
_wr->setUpdating (false);
}
@@ -139,19 +147,14 @@ RegisteredUnitMenu::~RegisteredUnitMenu()
void
RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
+ init_parent(key, wr, repr_in, doc_in);
+
_label = new Gtk::Label (label, 1.0, 0.5);
_label->set_use_underline (true);
_sel = new UnitMenu ();
_label->set_mnemonic_widget (*_sel);
_sel->setUnitType (UNIT_TYPE_LINEAR);
- _wr = &wr;
- _key = key;
_changed_connection = _sel->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed));
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_warning("Initialization of registered widget using defined repr but with doc==NULL");
}
void
@@ -166,31 +169,12 @@ RegisteredUnitMenu::on_changed()
if (_wr->isUpdating())
return;
- // Use local repr here. When repr is specified, use that one, but
- // if repr==NULL, get the repr of namedview of active desktop.
- Inkscape::XML::Node *local_repr = repr;
- SPDocument *local_doc = doc;
- if (!local_repr) {
- // no repr specified, use active desktop's namedview's repr
- SPDesktop *dt = SP_ACTIVE_DESKTOP;
- if (!dt)
- return;
- local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
- local_doc = sp_desktop_document(dt);
- }
-
Inkscape::SVGOStringStream os;
os << _sel->getUnitAbbr();
_wr->setUpdating (true);
- bool saved = sp_document_get_undo_sensitive (local_doc);
- sp_document_set_undo_sensitive (local_doc, false);
- local_repr->setAttribute(_key.c_str(), os.str().c_str());
- local_doc->rroot->setAttribute("sodipodi:modified", "true");
- sp_document_set_undo_sensitive (local_doc, saved);
- sp_document_done (local_doc, SP_VERB_NONE,
- /* TODO: annotate */ "registered-widget.cpp: RegisteredUnitMenu::on_changed");
+ write_to_xml(os.str().c_str());
_wr->setUpdating (false);
}
@@ -210,19 +194,14 @@ RegisteredScalarUnit::~RegisteredScalarUnit()
void
RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
+ init_parent(key, wr, repr_in, doc_in);
+
_widget = new ScalarUnit (label, tip, UNIT_TYPE_LINEAR, "", "", rum._sel);
_widget->initScalar (-1e6, 1e6);
_widget->setUnit (rum._sel->getUnitAbbr());
_widget->setDigits (2);
- _key = key;
_um = rum._sel;
_value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed));
- _wr = &wr;
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_warning("Initialization of registered widget using defined repr but with doc==NULL");
}
ScalarUnit*
@@ -244,37 +223,83 @@ RegisteredScalarUnit::on_value_changed()
if (_wr->isUpdating())
return;
- // Use local repr here. When repr is specified, use that one, but
- // if repr==NULL, get the repr of namedview of active desktop.
- Inkscape::XML::Node *local_repr = repr;
- SPDocument *local_doc = doc;
- if (!local_repr) {
- // no repr specified, use active desktop's namedview's repr
- SPDesktop *dt = SP_ACTIVE_DESKTOP;
- if (!dt)
- return;
- local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
- local_doc = sp_desktop_document(dt);
- }
+ _wr->setUpdating (true);
Inkscape::SVGOStringStream os;
os << _widget->getValue("");
if (_um)
os << _um->getUnitAbbr();
+ write_to_xml(os.str().c_str());
+
+ _wr->setUpdating (false);
+}
+
+
+RegisteredScalar::RegisteredScalar()
+{
+ _widget = NULL;
+}
+
+RegisteredScalar::~RegisteredScalar()
+{
+ if (_widget)
+ delete _widget;
+
+ _value_changed_connection.disconnect();
+}
+
+void
+RegisteredScalar::init ( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
+ SPDocument * doc_in )
+{
+ init_parent(key, wr, repr_in, doc_in);
+
+ _widget = new Scalar (label, tip);
+ _widget->setRange (-1e6, 1e6);
+ _widget->setDigits (2);
+ _widget->setIncrements(0.1, 1.0);
+ _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalar::on_value_changed));
+}
+
+Scalar*
+RegisteredScalar::getS()
+{
+ return _widget;
+}
+
+void
+RegisteredScalar::setValue (double val)
+{
+ _widget->setValue (val);
+ on_value_changed();
+}
+
+void
+RegisteredScalar::on_value_changed()
+{
+ if (_wr->isUpdating())
+ return;
_wr->setUpdating (true);
- bool saved = sp_document_get_undo_sensitive (local_doc);
- sp_document_set_undo_sensitive (local_doc, false);
- local_repr->setAttribute(_key.c_str(), os.str().c_str());
- local_doc->rroot->setAttribute("sodipodi:modified", "true");
- sp_document_set_undo_sensitive (local_doc, saved);
- sp_document_done (local_doc, SP_VERB_NONE,
- /* TODO: annotate */ "registered-widget.cpp: RegisteredScalarUnit::on_value_changed");
+ // FIXME: gtk bug?
+ // disable interruptibility: see http://inkscape.svn.sourceforge.net/viewvc/inkscape/inkscape/trunk/src/ui/widget/selected-style.cpp?r1=13149&r2=13257&sortby=date
+ SPDesktop* dt = SP_ACTIVE_DESKTOP;
+ sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(dt), 0);
+
+ Inkscape::SVGOStringStream os;
+ os << _widget->getValue();
+
+ write_to_xml(os.str().c_str());
+
+ // resume interruptibility
+ sp_canvas_end_forced_full_redraws(sp_desktop_canvas(dt));
_wr->setUpdating (false);
}
+
RegisteredColorPicker::RegisteredColorPicker()
: _label(0), _cp(0)
{
@@ -290,19 +315,15 @@ RegisteredColorPicker::~RegisteredColorPicker()
void
RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& title, const Glib::ustring& tip, const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
+ init_parent("", wr, repr_in, doc_in);
+
_label = new Gtk::Label (label, 1.0, 0.5);
_label->set_use_underline (true);
_cp = new ColorPicker (title,tip,0,true);
_label->set_mnemonic_widget (*_cp);
_ckey = ckey;
_akey = akey;
- _wr = &wr;
_changed_connection = _cp->connectChanged (sigc::mem_fun (*this, &RegisteredColorPicker::on_changed));
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_warning("Initialization of registered widget using defined repr but with doc==NULL");
}
void
@@ -370,7 +391,8 @@ RegisteredSuffixedInteger::~RegisteredSuffixedInteger()
void
RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
- _key = key;
+ init_parent(key, wr, repr_in, doc_in);
+
_label = new Gtk::Label (label);
_label->set_alignment (1.0, 0.5);
_label->set_use_underline();
@@ -381,12 +403,6 @@ RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring
_hbox.pack_start (*_suffix, false, false, 0);
_changed_connection = _adj.signal_value_changed().connect (sigc::mem_fun(*this, &RegisteredSuffixedInteger::on_value_changed));
- _wr = &wr;
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_warning("Initialization of registered widget using defined repr but with doc==NULL");
}
void
@@ -403,26 +419,11 @@ RegisteredSuffixedInteger::on_value_changed()
_wr->setUpdating (true);
- // Use local repr here. When repr is specified, use that one, but
- // if repr==NULL, get the repr of namedview of active desktop.
- Inkscape::XML::Node *local_repr = repr;
- SPDocument *local_doc = doc;
- if (!local_repr) {
- // no repr specified, use active desktop's namedview's repr
- SPDesktop *dt = SP_ACTIVE_DESKTOP;
- if (!dt)
- return;
- local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
- local_doc = sp_desktop_document(dt);
- }
-
Inkscape::SVGOStringStream os;
int value = int(_adj.get_value());
os << value;
- local_repr->setAttribute(_key.c_str(), os.str().c_str());
- sp_document_done(local_doc, SP_VERB_NONE,
- /* TODO: annotate */ "registered-widget.cpp: RegisteredSuffixedInteger::on_value_changed");
+ write_to_xml(os.str().c_str());
_wr->setUpdating (false);
}
@@ -443,6 +444,8 @@ const Glib::ustring& label1, const Glib::ustring& label2,
const Glib::ustring& tip1, const Glib::ustring& tip2,
const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
{
+ init_parent(key, wr, repr_in, doc_in);
+
_hbox = new Gtk::HBox;
_hbox->add (*manage (new Gtk::Label (label)));
_rb1 = manage (new Gtk::RadioButton (label1, true));
@@ -453,14 +456,7 @@ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument
_rb2->set_active();
_tt.set_tip (*_rb1, tip1);
_tt.set_tip (*_rb2, tip2);
- _key = key;
- _wr = &wr;
_changed_connection = _rb1->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredRadioButtonPair::on_value_changed));
-
- repr = repr_in;
- doc = doc_in;
- if (repr && !doc) // doc cannot be NULL when repr is not NULL
- g_error("Initialization of registered widget using defined repr but with doc==NULL");
}
void
@@ -476,29 +472,72 @@ RegisteredRadioButtonPair::on_value_changed()
if (_wr->isUpdating())
return;
- // Use local repr here. When repr is specified, use that one, but
- // if repr==NULL, get the repr of namedview of active desktop.
- Inkscape::XML::Node *local_repr = repr;
- SPDocument *local_doc = doc;
- if (!local_repr) {
- // no repr specified, use active desktop's namedview's repr
- SPDesktop *dt = SP_ACTIVE_DESKTOP;
- if (!dt)
- return;
- local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
- local_doc = sp_desktop_document(dt);
- }
-
_wr->setUpdating (true);
bool second = _rb2->get_active();
- bool saved = sp_document_get_undo_sensitive (local_doc);
- sp_document_set_undo_sensitive (local_doc, false);
- local_repr->setAttribute(_key.c_str(), second ? "true" : "false");
- local_doc->rroot->setAttribute("sodipodi:modified", "true");
- sp_document_set_undo_sensitive (local_doc, saved);
- sp_document_done (local_doc, SP_VERB_NONE,
- /* TODO: annotate */ "registered-widget.cpp: RegisteredRadioButtonPair::on_value_changed");
+ write_to_xml(second ? "true" : "false");
+
+ _wr->setUpdating (false);
+}
+
+/*#########################################
+ * Registered POINT
+ */
+
+RegisteredPoint::RegisteredPoint()
+{
+ _widget = NULL;
+}
+
+RegisteredPoint::~RegisteredPoint()
+{
+ if (_widget)
+ delete _widget;
+
+ _value_x_changed_connection.disconnect();
+ _value_y_changed_connection.disconnect();
+}
+
+void
+RegisteredPoint::init ( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
+ SPDocument* doc_in )
+{
+ init_parent(key, wr, repr_in, doc_in);
+
+ _widget = new Point (label, tip);
+ _widget->setRange (-1e6, 1e6);
+ _widget->setDigits (2);
+ _widget->setIncrements(0.1, 1.0);
+ _value_x_changed_connection = _widget->signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed));
+ _value_y_changed_connection = _widget->signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredPoint::on_value_changed));
+}
+
+Point*
+RegisteredPoint::getPoint()
+{
+ return _widget;
+}
+
+void
+RegisteredPoint::setValue (double xval, double yval)
+{
+ _widget->setValue(xval, yval);
+ on_value_changed();
+}
+
+void
+RegisteredPoint::on_value_changed()
+{
+ if (_wr->isUpdating())
+ return;
+
+ _wr->setUpdating (true);
+
+ Inkscape::SVGOStringStream os;
+ os << _widget->getXValue() << "," << _widget->getYValue();
+
+ write_to_xml(os.str().c_str());
_wr->setUpdating (false);
}
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index 8e54e1bbd..008ca0077 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -14,6 +14,9 @@
#include <gtkmm/box.h>
#include <gtkmm/adjustment.h>
+#include <gtkmm/tooltips.h>
+
+#include "xml/node.h"
class SPUnit;
class SPDocument;
@@ -31,10 +34,53 @@ namespace Widget {
class ColorPicker;
class Registry;
+class Scalar;
class ScalarUnit;
class UnitMenu;
+class Point;
+
+class RegisteredWidget {
+public:
+ void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
+ {
+ event_type = _event_type;
+ event_description = _event_description;
+ write_undo = true;
+ }
+
+protected:
+ RegisteredWidget()
+ {
+ _wr = NULL;
+ repr = NULL;
+ doc = NULL;
+ write_undo = false;
+ }
+
+ void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
+ {
+ _wr = &wr;
+ _key = key;
+ repr = repr_in;
+ doc = doc_in;
+ if (repr && !doc) // doc cannot be NULL when repr is not NULL
+ g_warning("Initialization of registered widget using defined repr but with doc==NULL");
+ }
+
+ void write_to_xml(const char * svgstr);
-class RegisteredCheckButton {
+ Registry * _wr;
+ Glib::ustring _key;
+ Inkscape::XML::Node * repr;
+ SPDocument * doc;
+ unsigned int event_type;
+ Glib::ustring event_description;
+ bool write_undo;
+};
+
+//#######################################################
+
+class RegisteredCheckButton : public RegisteredWidget {
public:
RegisteredCheckButton();
~RegisteredCheckButton();
@@ -55,18 +101,23 @@ public:
protected:
Gtk::Tooltips _tt;
sigc::connection _toggled_connection;
- Registry *_wr;
- Glib::ustring _key;
void on_toggled();
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
-class RegisteredUnitMenu {
+class RegisteredUnitMenu : public RegisteredWidget {
public:
RegisteredUnitMenu();
~RegisteredUnitMenu();
- void init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL);
+ void init ( const Glib::ustring& label,
+ const Glib::ustring& key,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label, key, wr, NULL, NULL); };
+
void setUnit (const SPUnit*);
Gtk::Label *_label;
UnitMenu *_sel;
@@ -74,13 +125,9 @@ public:
protected:
void on_changed();
- Registry *_wr;
- Glib::ustring _key;
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
-class RegisteredScalarUnit {
+class RegisteredScalarUnit : public RegisteredWidget {
public:
RegisteredScalarUnit();
~RegisteredScalarUnit();
@@ -89,8 +136,15 @@ public:
const Glib::ustring& key,
const RegisteredUnitMenu &rum,
Registry& wr,
- Inkscape::XML::Node* repr_in=NULL,
- SPDocument *doc_in=NULL);
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ const RegisteredUnitMenu &rum,
+ Registry& wr)
+ { init(label, tip, key, rum, wr, NULL, NULL); };
+
ScalarUnit* getSU();
void setValue (double);
@@ -98,14 +152,35 @@ protected:
ScalarUnit *_widget;
sigc::connection _value_changed_connection;
UnitMenu *_um;
- Registry *_wr;
- Glib::ustring _key;
void on_value_changed();
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
-class RegisteredColorPicker {
+class RegisteredScalar : public RegisteredWidget {
+public:
+ RegisteredScalar();
+ ~RegisteredScalar();
+ void init (const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label, tip, key, wr, NULL, NULL); };
+
+ Scalar* getS();
+ void setValue (double);
+
+protected:
+ Scalar *_widget;
+ sigc::connection _value_changed_connection;
+ void on_value_changed();
+};
+
+class RegisteredColorPicker : public RegisteredWidget {
public:
RegisteredColorPicker();
~RegisteredColorPicker();
@@ -115,8 +190,16 @@ public:
const Glib::ustring& ckey,
const Glib::ustring& akey,
Registry& wr,
- Inkscape::XML::Node* repr_in=NULL,
- SPDocument *doc_in=NULL);
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& title,
+ const Glib::ustring& tip,
+ const Glib::ustring& ckey,
+ const Glib::ustring& akey,
+ Registry& wr)
+ { init(label, title, tip, ckey, akey, wr, NULL, NULL); };
+
void setRgba32 (guint32);
void closeWindow();
@@ -125,14 +208,11 @@ public:
protected:
Glib::ustring _ckey, _akey;
- Registry *_wr;
void on_changed (guint32);
sigc::connection _changed_connection;
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
-class RegisteredSuffixedInteger {
+class RegisteredSuffixedInteger : public RegisteredWidget {
public:
RegisteredSuffixedInteger();
~RegisteredSuffixedInteger();
@@ -140,8 +220,14 @@ public:
const Glib::ustring& label2,
const Glib::ustring& key,
Registry& wr,
- Inkscape::XML::Node* repr_in=NULL,
- SPDocument *doc_in=NULL);
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label1,
+ const Glib::ustring& label2,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label1, label2, key, wr, NULL, NULL); };
+
void setValue (int);
Gtk::Label *_label;
Gtk::HBox _hbox;
@@ -150,15 +236,11 @@ protected:
Gtk::SpinButton *_sb;
Gtk::Adjustment _adj;
Gtk::Label *_suffix;
- Glib::ustring _key;
- Registry *_wr;
sigc::connection _changed_connection;
void on_value_changed();
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
-class RegisteredRadioButtonPair {
+class RegisteredRadioButtonPair : public RegisteredWidget {
public:
RegisteredRadioButtonPair();
~RegisteredRadioButtonPair();
@@ -169,23 +251,52 @@ public:
const Glib::ustring& tip2,
const Glib::ustring& key,
Registry& wr,
- Inkscape::XML::Node* repr_in=NULL,
- SPDocument *doc_in=NULL);
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& label1,
+ const Glib::ustring& label2,
+ const Glib::ustring& tip1,
+ const Glib::ustring& tip2,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label, label1, label2, tip1, tip2, key, wr, NULL, NULL); };
+
void setValue (bool second);
Gtk::HBox *_hbox;
protected:
Gtk::RadioButton *_rb1, *_rb2;
Gtk::Tooltips _tt;
- Glib::ustring _key;
- Registry *_wr;
sigc::connection _changed_connection;
void on_value_changed();
- Inkscape::XML::Node *repr;
- SPDocument *doc;
};
+class RegisteredPoint : public RegisteredWidget {
+public:
+ RegisteredPoint();
+ ~RegisteredPoint();
+ void init (const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label, tip, key, wr, NULL, NULL); };
+
+ Point* getPoint();
+ void setValue (double xval, double yval);
+protected:
+ Point *_widget;
+ sigc::connection _value_x_changed_connection;
+ sigc::connection _value_y_changed_connection;
+ void on_value_changed();
+};
} // namespace Widget
} // namespace UI