diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-06-19 10:00:24 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2011-06-19 10:00:24 +0000 |
| commit | 06dfaa02d7a80bcdff717d579a48f81643f53f31 (patch) | |
| tree | 49b8e67ad9051f1507b0959cac986383ab4001e2 /src/ui/widget | |
| parent | Fix rendering of control points (diff) | |
| parent | fix bug 796451: Measure tools should support rotation constraint (diff) | |
| download | inkscape-06dfaa02d7a80bcdff717d579a48f81643f53f31.tar.gz inkscape-06dfaa02d7a80bcdff717d579a48f81643f53f31.zip | |
Merge from trunk
(bzr r9508.1.89)
Diffstat (limited to 'src/ui/widget')
26 files changed, 423 insertions, 90 deletions
diff --git a/src/ui/widget/CMakeLists.txt b/src/ui/widget/CMakeLists.txt deleted file mode 100644 index ffc94c299..000000000 --- a/src/ui/widget/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -SET(ui_widget_SRC -button.cpp -color-picker.cpp -color-preview.cpp -combo-text.cpp -dock.cpp -dock-item.cpp -entity-entry.cpp -entry.cpp -filter-effect-chooser.cpp -handlebox.cpp -icon-widget.cpp -imageicon.cpp -imagetoggler.cpp -labelled.cpp -licensor.cpp -notebook-page.cpp -object-composite-settings.cpp -page-sizer.cpp -panel.cpp -point.cpp -preferences-widget.cpp -random.cpp -registered-widget.cpp -registry.cpp -rendering-options.cpp -rotateable.cpp -ruler.cpp -scalar.cpp -scalar-unit.cpp -selected-style.cpp -spin-slider.cpp -style-subject.cpp -style-swatch.cpp -svg-canvas.cpp -tolerance-slider.cpp -toolbox.cpp -unit-menu.cpp -zoom-status.cpp -) diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index b6069631b..bd23b6782 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -66,6 +66,8 @@ ink_common_sources += \ ui/widget/scalar.h \ ui/widget/selected-style.h \ ui/widget/selected-style.cpp \ + ui/widget/spinbutton.h \ + ui/widget/spinbutton.cpp \ ui/widget/spin-slider.h \ ui/widget/spin-slider.cpp \ ui/widget/style-subject.h \ diff --git a/src/ui/widget/combo-text.cpp b/src/ui/widget/combo-text.cpp index 7706f7c29..43428adb8 100644 --- a/src/ui/widget/combo-text.cpp +++ b/src/ui/widget/combo-text.cpp @@ -23,7 +23,7 @@ #endif #include "combo-text.h" -#include <gtk/gtkcombobox.h> +#include <gtk/gtk.h> ComboText::ComboText() : Gtk::ComboBox() diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index 72a20c385..87f4d0840 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -262,7 +262,7 @@ DockItem::present() void DockItem::grab_focus() { - if (GTK_WIDGET_REALIZED (_gdl_dock_item)) { + if (gtk_widget_get_realized (_gdl_dock_item)) { // make sure the window we're in is present Gtk::Widget *toplevel = getWidget().get_toplevel(); diff --git a/src/ui/widget/entity-entry.cpp b/src/ui/widget/entity-entry.cpp index e191a9360..e62eb009c 100644 --- a/src/ui/widget/entity-entry.cpp +++ b/src/ui/widget/entity-entry.cpp @@ -25,6 +25,7 @@ #include "sp-object.h" #include "rdf.h" #include "ui/widget/registry.h" +#include "sp-root.h" #include "entity-entry.h" @@ -87,8 +88,8 @@ void EntityLineEntry::update(SPDocument *doc) { const char *text = rdf_get_work_entity (doc, _entity); // If RDF title is not set, get the document's <title> and set the RDF: - if ( !text && !strcmp(_entity->name, "title") && doc->root ) { - text = doc->root->title(); + if ( !text && !strcmp(_entity->name, "title") && doc->getRoot() ) { + text = doc->getRoot()->title(); rdf_set_work_entity(doc, _entity, text); } static_cast<Gtk::Entry*>(_packable)->set_text (text ? text : ""); @@ -133,8 +134,8 @@ void EntityMultiLineEntry::update(SPDocument *doc) { const char *text = rdf_get_work_entity (doc, _entity); // If RDF title is not set, get the document's <title> and set the RDF: - if ( !text && !strcmp(_entity->name, "title") && doc->root ) { - text = doc->root->title(); + if ( !text && !strcmp(_entity->name, "title") && doc->getRoot() ) { + text = doc->getRoot()->title(); rdf_set_work_entity(doc, _entity, text); } Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable); diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h index 76538d6a7..8ef31a889 100644 --- a/src/ui/widget/object-composite-settings.h +++ b/src/ui/widget/object-composite-settings.h @@ -17,7 +17,7 @@ #include <gtkmm/alignment.h> #include <gtkmm/adjustment.h> #include <gtkmm/label.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <gtkmm/scale.h> #include <glibmm/ustring.h> @@ -47,7 +47,7 @@ private: Gtk::Label _opacity_label; Gtk::Adjustment _opacity_adjustment; Gtk::HScale _opacity_hscale; - Gtk::SpinButton _opacity_spin_button; + Inkscape::UI::Widget::SpinButton _opacity_spin_button; StyleSubject *_subject; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index f306b9eea..672e1415b 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -422,7 +422,7 @@ PageSizer::setDim (double w, double h, bool changeList) // The origin for the user is in the lower left corner; this point should remain stationary when // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this Geom::Translate const vert_offset(Geom::Point(0, (old_height - h))); - SP_GROUP(SP_ROOT(doc->root))->translateChildItems(vert_offset); + doc->getRoot()->translateChildItems(vert_offset); DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size")); } diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index b3c8ce376..3e0c27587 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -22,7 +22,7 @@ #include <gtkmm/dialog.h> // for Gtk::RESPONSE_* #include <gtkmm/stock.h> -#include <gtk/gtkiconfactory.h> +#include <gtk/gtk.h> #include "panel.h" #include "icon-size.h" diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index afcaa338e..68faa3c66 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -227,7 +227,6 @@ void PrefSpinButton::init(Glib::ustring const &prefs_path, this->set_range (lower, upper); this->set_increments (step_increment, 0); - this->set_numeric(); this->set_value (value); this->set_width_chars(6); if (is_int) @@ -256,6 +255,45 @@ void PrefSpinButton::on_value_changed() } } +void PrefSpinUnit::init(Glib::ustring const &prefs_path, + double lower, double upper, double step_increment, + double default_value, UnitType unit_type, Glib::ustring const &default_unit) +{ + _prefs_path = prefs_path; + _is_percent = (unit_type == UNIT_TYPE_DIMENSIONLESS); + + resetUnitType(unit_type); + setUnit(default_unit); + setRange (lower, upper); /// @fixme this disregards changes of units + setIncrements (step_increment, 0); + if (step_increment < 0.1) { + setDigits(4); + } else { + setDigits(2); + } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper); + Glib::ustring unitstr = prefs->getUnit(prefs_path); + if (unitstr.length() == 0) { + unitstr = default_unit; + // write the assumed unit to preferences: + prefs->setDoubleUnit(_prefs_path, value, unitstr); + } + setValue(value, unitstr); + + signal_value_changed().connect_notify(sigc::mem_fun(*this, &PrefSpinUnit::on_my_value_changed)); +} + +void PrefSpinUnit::on_my_value_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (getWidget()->is_visible()) //only take action if user changed value + { + prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr); + } +} + const double ZoomCorrRuler::textsize = 7; const double ZoomCorrRuler::textpadding = 5; diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 6c7f9ce4a..6caab11ae 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -17,7 +17,7 @@ #include <vector> #include <gtkmm/table.h> #include <gtkmm/comboboxtext.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <gtkmm/tooltips.h> #include <gtkmm/treeview.h> #include <gtkmm/radiobutton.h> @@ -32,6 +32,8 @@ #include "ui/widget/color-picker.h" #include "ui/widget/unit-menu.h" +#include "ui/widget/spinbutton.h" +#include "ui/widget/scalar-unit.h" namespace Inkscape { namespace UI { @@ -68,7 +70,7 @@ protected: void on_toggled(); }; -class PrefSpinButton : public Gtk::SpinButton +class PrefSpinButton : public SpinButton { public: void init(Glib::ustring const &prefs_path, @@ -81,6 +83,21 @@ protected: void on_value_changed(); }; +class PrefSpinUnit : public ScalarUnit +{ +public: + PrefSpinUnit() : ScalarUnit("", "") {}; + + void init(Glib::ustring const &prefs_path, + double lower, double upper, double step_increment, + double default_value, + UnitType unit_type, Glib::ustring const &default_unit); +protected: + Glib::ustring _prefs_path; + bool _is_percent; + void on_my_value_changed(); +}; + class ZoomCorrRuler : public Gtk::DrawingArea { public: ZoomCorrRuler(int width = 100, int height = 20); @@ -116,7 +133,7 @@ private: void on_spinbutton_value_changed(); void on_unit_changed(); - Gtk::SpinButton _sb; + Inkscape::UI::Widget::SpinButton _sb; UnitMenu _unit; Gtk::HScale _slider; ZoomCorrRuler _ruler; @@ -134,7 +151,7 @@ private: void on_spinbutton_value_changed(); Glib::ustring _prefs_path; - Gtk::SpinButton _sb; + Inkscape::UI::Widget::SpinButton _sb; Gtk::HScale _slider; bool freeze; // used to block recursive updates of slider and spinbutton }; diff --git a/src/ui/widget/random.cpp b/src/ui/widget/random.cpp index 02201be12..3dcf09cb5 100644 --- a/src/ui/widget/random.cpp +++ b/src/ui/widget/random.cpp @@ -25,6 +25,8 @@ #include <glibmm/i18n.h> +#include <gtkmm/button.h> + namespace Inkscape { namespace UI { namespace Widget { diff --git a/src/ui/widget/ruler.cpp b/src/ui/widget/ruler.cpp index a220a54ad..c6ac3a381 100644 --- a/src/ui/widget/ruler.cpp +++ b/src/ui/widget/ruler.cpp @@ -108,7 +108,7 @@ Ruler::on_button_press_event(GdkEventButton *evb) _dragging = true; sp_repr_set_boolean(repr, "showguides", TRUE); sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE); - _guide = sp_guideline_new(_dt->guides, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); + _guide = sp_guideline_new(_dt->guides, NULL, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); sp_guideline_set_color(SP_GUIDELINE(_guide), _dt->namedview->guidehicolor); (void) get_window()->pointer_grab(false, Gdk::BUTTON_RELEASE_MASK | diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 6209d40e0..1c0fdff68 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -27,6 +27,7 @@ #endif #include "scalar-unit.h" +#include "spinbutton.h" namespace Inkscape { namespace UI { @@ -65,9 +66,45 @@ ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, } _unit_menu->signal_changed() .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); + + static_cast<SpinButton*>(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); } /** + * Construct a ScalarUnit + * + * \param label Label. + * \param tooltip Tooltip text. + * \param take_unitmenu Use the unitmenu from this parameter. + * \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). + */ +ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + : Scalar(label, tooltip, suffix, icon, mnemonic), + _unit_menu(take_unitmenu._unit_menu), + _hundred_percent(0), + _absolute_is_increment(false), + _percentage_is_increment(false) +{ + _unit_menu->signal_changed() + .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); + + static_cast<SpinButton*>(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); +} + + +/** * Initializes the scalar based on the settings in _unit_menu. * Requires that _unit_menu has already been initialized. */ @@ -93,6 +130,22 @@ ScalarUnit::setUnit(Glib::ustring const &unit) { return true; } +/** Adds the unit type to the ScalarUnit widget */ +void +ScalarUnit::setUnitType(UnitType unit_type) { + g_assert(_unit_menu != NULL); + _unit_menu->setUnitType(unit_type); + lastUnits = _unit_menu->getUnitAbbr(); +} + +/** Resets the unit type for the ScalarUnit widget */ +void +ScalarUnit::resetUnitType(UnitType unit_type) { + g_assert(_unit_menu != NULL); + _unit_menu->resetUnitType(unit_type); + lastUnits = _unit_menu->getUnitAbbr(); +} + /** Gets the object for the currently selected unit */ Unit ScalarUnit::getUnit() const { @@ -115,6 +168,19 @@ ScalarUnit::setValue(double number, Glib::ustring const &units) { Scalar::setValue(number); } +/** Convert and sets the number only and keeps the current unit. */ +void +ScalarUnit::setValueKeepUnit(double number, Glib::ustring const &units) { + g_assert(_unit_menu != NULL); + if (units == "") { + // set the value in the default units + Scalar::setValue(number); + } else { + double conversion = _unit_menu->getConversion(units); + Scalar::setValue(number / conversion); + } +} + /** Sets the number only */ void ScalarUnit::setValue(double number) { @@ -134,6 +200,15 @@ ScalarUnit::getValue(Glib::ustring const &unit_name) const { } } +/** Grab focus, and select the text that is in the entry field. + */ +void +ScalarUnit::grabFocusAndSelectEntry() { + _widget->grab_focus(); + static_cast<SpinButton*>(_widget)->select_region(0, 20); +} + + void ScalarUnit::setHundredPercent(double number) { diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index d8b2edbd5..ed3728e69 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -32,6 +32,11 @@ public: Glib::ustring const &icon = "", UnitMenu *unit_menu = NULL, bool mnemonic = true); + ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); void initScalar(double min_value, double max_value); @@ -40,9 +45,14 @@ public: double getValue(Glib::ustring const &units) const; bool setUnit(Glib::ustring const &units); + void setUnitType(UnitType unit_type); + void resetUnitType(UnitType unit_type); void setValue(double number, Glib::ustring const &units); + void setValueKeepUnit(double number, Glib::ustring const &units); void setValue(double number); + void grabFocusAndSelectEntry(); + void setHundredPercent(double number); void setAbsoluteIsIncrement(bool value); void setPercentageIsIncrement(bool value); diff --git a/src/ui/widget/scalar.cpp b/src/ui/widget/scalar.cpp index 26a1f6541..6ada379fb 100644 --- a/src/ui/widget/scalar.cpp +++ b/src/ui/widget/scalar.cpp @@ -18,6 +18,7 @@ #include "scalar.h" +#include "spinbutton.h" namespace Inkscape { namespace UI { @@ -37,10 +38,9 @@ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } /** @@ -59,10 +59,9 @@ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(0.0, digits), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(0.0, digits), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } /** @@ -83,10 +82,9 @@ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } /** Fetches the precision of the spin buton */ @@ -94,7 +92,7 @@ unsigned Scalar::getDigits() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_digits(); + return static_cast<SpinButton*>(_widget)->get_digits(); } /** Gets the current step ingrement used by the spin button */ @@ -103,7 +101,7 @@ Scalar::getStep() const { g_assert(_widget != NULL); double step, page; - static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page); + static_cast<SpinButton*>(_widget)->get_increments(step, page); return step; } @@ -113,7 +111,7 @@ Scalar::getPage() const { g_assert(_widget != NULL); double step, page; - static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page); + static_cast<SpinButton*>(_widget)->get_increments(step, page); return page; } @@ -123,7 +121,7 @@ Scalar::getRangeMin() const { g_assert(_widget != NULL); double min, max; - static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max); + static_cast<SpinButton*>(_widget)->get_range(min, max); return min; } @@ -133,7 +131,7 @@ Scalar::getRangeMax() const { g_assert(_widget != NULL); double min, max; - static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max); + static_cast<SpinButton*>(_widget)->get_range(min, max); return max; } @@ -142,7 +140,7 @@ double Scalar::getValue() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_value(); + return static_cast<SpinButton*>(_widget)->get_value(); } /** Get the value spin_button represented as an integer. */ @@ -150,7 +148,7 @@ int Scalar::getValueAsInt() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_value_as_int(); + return static_cast<SpinButton*>(_widget)->get_value_as_int(); } @@ -159,7 +157,7 @@ void Scalar::setDigits(unsigned digits) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_digits(digits); + static_cast<SpinButton*>(_widget)->set_digits(digits); } /** Sets the step and page increments for the spin button @@ -169,7 +167,7 @@ void Scalar::setIncrements(double step, double /*page*/) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_increments(step, 0); + static_cast<SpinButton*>(_widget)->set_increments(step, 0); } /** Sets the minimum and maximum range allowed for the spin button */ @@ -177,7 +175,7 @@ void Scalar::setRange(double min, double max) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_range(min, max); + static_cast<SpinButton*>(_widget)->set_range(min, max); } /** Sets the value of the spin button */ @@ -186,14 +184,14 @@ Scalar::setValue(double value) { g_assert(_widget != NULL); setProgrammatically = true; // callback is supposed to reset back, if it cares - static_cast<Gtk::SpinButton*>(_widget)->set_value(value); + static_cast<SpinButton*>(_widget)->set_value(value); } /** Manually forces an update of the spin button */ void Scalar::update() { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->update(); + static_cast<SpinButton*>(_widget)->update(); } @@ -202,7 +200,7 @@ Scalar::update() { Glib::SignalProxy0<void> Scalar::signal_value_changed() { - return static_cast<Gtk::SpinButton*>(_widget)->signal_value_changed(); + return static_cast<SpinButton*>(_widget)->signal_value_changed(); } diff --git a/src/ui/widget/scalar.h b/src/ui/widget/scalar.h index 6de128edb..7142ba93f 100644 --- a/src/ui/widget/scalar.h +++ b/src/ui/widget/scalar.h @@ -15,9 +15,6 @@ #ifndef INKSCAPE_UI_WIDGET_SCALAR_H #define INKSCAPE_UI_WIDGET_SCALAR_H -#include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> - #include "labelled.h" namespace Inkscape { diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 50476dc65..ae8cd564e 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -14,7 +14,7 @@ # include <config.h> #endif -#include <gtk/gtkdnd.h> +#include <gtk/gtk.h> #include "selected-style.h" diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index e74d5b1ae..0caa7fe4c 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -21,7 +21,7 @@ #include <gtkmm/menu.h> #include <gtkmm/menuitem.h> #include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <stddef.h> #include <sigc++/sigc++.h> @@ -138,7 +138,7 @@ protected: Gtk::EventBox _opacity_place; Gtk::Adjustment _opacity_adjustment; - Gtk::SpinButton _opacity_sb; + Inkscape::UI::Widget::SpinButton _opacity_sb; Gtk::Label _na[2]; Glib::ustring __na[2]; diff --git a/src/ui/widget/spin-slider.cpp b/src/ui/widget/spin-slider.cpp index faafc63b4..259b057aa 100644 --- a/src/ui/widget/spin-slider.cpp +++ b/src/ui/widget/spin-slider.cpp @@ -90,11 +90,11 @@ Gtk::HScale& SpinSlider::get_scale() return _scale; } -const Gtk::SpinButton& SpinSlider::get_spin_button() const +const Inkscape::UI::Widget::SpinButton& SpinSlider::get_spin_button() const { return _spin; } -Gtk::SpinButton& SpinSlider::get_spin_button() +Inkscape::UI::Widget::SpinButton& SpinSlider::get_spin_button() { return _spin; } diff --git a/src/ui/widget/spin-slider.h b/src/ui/widget/spin-slider.h index a4d0aa9d6..703c5d896 100644 --- a/src/ui/widget/spin-slider.h +++ b/src/ui/widget/spin-slider.h @@ -15,7 +15,7 @@ #include <gtkmm/adjustment.h> #include <gtkmm/box.h> #include <gtkmm/scale.h> -#include <gtkmm/spinbutton.h> +#include "spinbutton.h" #include "attr-widget.h" namespace Inkscape { @@ -42,8 +42,8 @@ public: const Gtk::HScale& get_scale() const; Gtk::HScale& get_scale(); - const Gtk::SpinButton& get_spin_button() const; - Gtk::SpinButton& get_spin_button(); + const Inkscape::UI::Widget::SpinButton& get_spin_button() const; + Inkscape::UI::Widget::SpinButton& get_spin_button(); void set_update_policy(const Gtk::UpdateType); @@ -52,7 +52,7 @@ public: private: Gtk::Adjustment _adjustment; Gtk::HScale _scale; - Gtk::SpinButton _spin; + Inkscape::UI::Widget::SpinButton _spin; }; // Contains two SpinSliders for controlling number-opt-number attributes diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp new file mode 100644 index 000000000..32090f96c --- /dev/null +++ b/src/ui/widget/spinbutton.cpp @@ -0,0 +1,129 @@ +/** + * \brief SpinButton widget, that allows entry of both '.' and ',' for the decimal, even when in numeric mode. + */ +/* + * Author: + * Johan B. C. Engelen + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "spinbutton.h" + +#include "unit-menu.h" +#include "util/expression-evaluator.h" +#include "event-context.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + + +void +SpinButton::connect_signals() { + signal_input().connect(sigc::mem_fun(*this, &SpinButton::on_input)); + signal_focus_in_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_focus_in_event)); + signal_key_press_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_key_press_event)); +}; + +/** + * This callback function should try to convert the entered text to a number and write it to newvalue. + * It calls a method to evaluate the (potential) mathematical expression. + * + * @retval false No conversion done, continue with default handler. + * @retval true Conversion successful, don't call default handler. + */ +int +SpinButton::on_input(double* newvalue) +{ + try { + Inkscape::Util::GimpEevlQuantity result; + if (_unit_menu) { + Unit unit = _unit_menu->getUnit(); + result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), &unit); + // check if output dimension corresponds to input unit + if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) { + throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.",""); + } + } else { + result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), NULL); + } + + *newvalue = result.value; + } + catch(Inkscape::Util::EvaluatorException &e) { + g_message ("%s", e.what()); + + return false; + } + + return true; +} + +/** When focus is obtained, save the value to enable undo later. + * @retval false continue with default handler. + * @retval true don't call default handler. +*/ +bool +SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/) +{ + on_focus_in_value = get_value(); + return false; // do not consume the event +} + +/** Handle specific keypress events, like Ctrl+Z + * @retval false continue with default handler. + * @retval true don't call default handler. +*/ +bool +SpinButton::on_my_key_press_event(GdkEventKey* event) +{ + switch (get_group0_keyval (event)) { + case GDK_Escape: + undo(); + return true; // I consumed the event + break; + case GDK_z: + case GDK_Z: + if (event->state & GDK_CONTROL_MASK) { + undo(); + return true; // I consumed the event + } + break; + default: + break; + } + + return false; // do not consume the event +} + +/** + * Undo the editing, by resetting the value upon when the spinbutton got focus. + */ +void +SpinButton::undo() +{ + set_value(on_focus_in_value); +} + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h new file mode 100644 index 000000000..df913553d --- /dev/null +++ b/src/ui/widget/spinbutton.h @@ -0,0 +1,81 @@ +/** + * \brief SpinButton widget, that allows entry of both '.' and ',' for the decimal, even when in numeric mode. + */ +/* + * Author: + * Johan B. C. Engelen + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_SPINBUTTON_H +#define INKSCAPE_UI_WIDGET_SPINBUTTON_H + +#include <gtkmm/spinbutton.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +class UnitMenu; + +/** + * SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu). + * + * Calling "set_numeric()" effectively disables the expression parsing. If no unit menu is linked, all unitlike characters are ignored. + */ +class SpinButton : public Gtk::SpinButton +{ +public: + SpinButton(double climb_rate = 0.0, guint digits = 0) + : Gtk::SpinButton(climb_rate, digits), + _unit_menu(NULL) + { + connect_signals(); + }; + explicit SpinButton(Gtk::Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0) + : Gtk::SpinButton(adjustment, climb_rate, digits), + _unit_menu(NULL) + { + connect_signals(); + }; + + virtual ~SpinButton() {}; + + void setUnitMenu(UnitMenu* unit_menu) { _unit_menu = unit_menu; }; + +protected: + UnitMenu *_unit_menu; /// Linked unit menu for unit conversion in entered expressions. + + void connect_signals(); + int on_input(double* newvalue); + bool on_my_focus_in_event(GdkEventFocus* event); + bool on_my_key_press_event(GdkEventKey* event); + void undo(); + + double on_focus_in_value; + +private: + // noncopyable + SpinButton(const SpinButton&); + SpinButton& operator=(const SpinButton&); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_SPINBUTTON_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/toolbox.cpp b/src/ui/widget/toolbox.cpp index e90a58b6e..5e5f43263 100644 --- a/src/ui/widget/toolbox.cpp +++ b/src/ui/widget/toolbox.cpp @@ -14,7 +14,7 @@ #endif #include <gtkmm/radioaction.h> -#include <gtk/gtkmain.h> +#include <gtk/gtk.h> #include "ui/widget/toolbox.h" #include "path-prefix.h" diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp index b4271762c..362f5d90f 100644 --- a/src/ui/widget/unit-menu.cpp +++ b/src/ui/widget/unit-menu.cpp @@ -54,6 +54,27 @@ UnitMenu::setUnitType(UnitType unit_type) return true; } +/** Removes all unit entries, then adds the unit type to the widget. + This extracts the corresponding + units from the unit map matching the given type, and appends them + to the dropdown widget. It causes the primary unit for the given + unit_type to be selected. */ +bool +UnitMenu::resetUnitType(UnitType unit_type) +{ + clear_text(); + + return setUnitType(unit_type); +} + +/** Adds a unit, possibly user-defined, to the menu. */ +void +UnitMenu::addUnit(Unit const& u) +{ + _unit_table.addUnit(u, false); + append_text(u.abbr); +} + /** Returns the Unit object corresponding to the current selection in the dropdown widget */ Unit diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 60a9702b4..cf42231ba 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -28,6 +28,8 @@ public: virtual ~UnitMenu(); bool setUnitType(UnitType unit_type); + bool resetUnitType(UnitType unit_type); + void addUnit(Unit const& u); bool setUnit(Glib::ustring const &unit); diff --git a/src/ui/widget/zoom-status.h b/src/ui/widget/zoom-status.h index 58d595329..85c3eeee1 100644 --- a/src/ui/widget/zoom-status.h +++ b/src/ui/widget/zoom-status.h @@ -13,7 +13,7 @@ */ #include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" struct SPDesktop; @@ -22,7 +22,7 @@ namespace Inkscape { namespace UI { namespace Widget { -class ZoomStatus : public Gtk::SpinButton +class ZoomStatus : public Inkscape::UI::Widget::SpinButton { public: ZoomStatus(); |
