summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2017-12-18 14:50:42 +0000
committerTavmjong Bah <tavmjong@free.fr>2017-12-18 14:50:42 +0000
commit9ceb238f8a4f5527c3621740e75713ea79eceebc (patch)
tree03e36e1ee30ed0b311c3d60db07ab73c42f23c57 /src
parentReduce with of +/- buttons. Reduce width of Fill and Stroke dialog. (diff)
downloadinkscape-9ceb238f8a4f5527c3621740e75713ea79eceebc.tar.gz
inkscape-9ceb238f8a4f5527c3621740e75713ea79eceebc.zip
Replace GimpSpinScale by InkSpinScale.
Diffstat (limited to 'src')
-rw-r--r--src/extension/param/float.cpp5
-rw-r--r--src/extension/param/int.cpp5
-rw-r--r--src/ui/CMakeLists.txt6
-rw-r--r--src/ui/dialog/filter-effects-dialog.cpp11
-rw-r--r--src/ui/widget/filter-effect-chooser.cpp2
-rw-r--r--src/ui/widget/ink-spinscale.cpp245
-rw-r--r--src/ui/widget/ink-spinscale.h78
-rw-r--r--src/ui/widget/object-composite-settings.cpp2
-rw-r--r--src/ui/widget/object-composite-settings.h2
-rw-r--r--src/ui/widget/spin-scale.cpp85
-rw-r--r--src/ui/widget/spin-scale.h30
-rw-r--r--src/widgets/ege-adjustment-action.cpp10
-rw-r--r--src/widgets/gimp/CMakeLists.txt2
-rw-r--r--src/widgets/gimp/gimpspinscale.c969
-rw-r--r--src/widgets/gimp/gimpspinscale.h82
15 files changed, 408 insertions, 1126 deletions
diff --git a/src/extension/param/float.cpp b/src/extension/param/float.cpp
index 69283a572..1dd3f073b 100644
--- a/src/extension/param/float.cpp
+++ b/src/extension/param/float.cpp
@@ -178,7 +178,10 @@ Gtk::Widget * ParamFloat::get_widget(SPDocument * doc, Inkscape::XML::Node * nod
if (_mode == FULL) {
- UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(_text, fadjust, _precision);
+ Glib::ustring text;
+ if (_text != NULL)
+ text = _text;
+ UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, _precision);
scale->set_size_request(400, -1);
scale->show();
hbox->pack_start(*scale, true, true);
diff --git a/src/extension/param/int.cpp b/src/extension/param/int.cpp
index 357f98590..9ad9b591c 100644
--- a/src/extension/param/int.cpp
+++ b/src/extension/param/int.cpp
@@ -159,7 +159,10 @@ ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal
if (_mode == FULL) {
- UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(_text, fadjust, 0);
+ Glib::ustring text;
+ if (_text != NULL)
+ text = _text;
+ UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, 0);
scale->set_size_request(400, -1);
scale->show();
hbox->pack_start(*scale, true, true);
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index be13d9b1b..fecb14a91 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -140,6 +140,8 @@ set(ui_SRC
widget/highlight-picker.cpp
widget/imageicon.cpp
widget/imagetoggler.cpp
+ widget/ink-select-one-action.cpp
+ widget/ink-spinscale.cpp
widget/insertordericon.cpp
widget/labelled.cpp
widget/layer-selector.cpp
@@ -147,7 +149,6 @@ set(ui_SRC
widget/licensor.cpp
widget/notebook-page.cpp
widget/object-composite-settings.cpp
- widget/ink-select-one-action.cpp
widget/page-sizer.cpp
widget/panel.cpp
widget/point.cpp
@@ -333,13 +334,14 @@ set(ui_SRC
widget/insertordericon.h
widget/imageicon.h
widget/imagetoggler.h
+ widget/ink-select-one-action.h
+ widget/ink-spinscale.h
widget/labelled.h
widget/layer-selector.h
widget/layertypeicon.h
widget/licensor.h
widget/notebook-page.h
widget/object-composite-settings.h
- widget/ink-select-one-action.h
widget/page-sizer.h
widget/panel.h
widget/point.h
diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp
index e60785f57..9764618ec 100644
--- a/src/ui/dialog/filter-effects-dialog.cpp
+++ b/src/ui/dialog/filter-effects-dialog.cpp
@@ -842,7 +842,10 @@ public:
SpinScale* add_spinscale(double def, const SPAttributeEnum attr, const Glib::ustring& label,
const double lo, const double hi, const double step_inc, const double climb, const int digits, char* tip_text = NULL)
{
- SpinScale* spinslider = new SpinScale("", def, lo, hi, step_inc, climb, digits, attr, tip_text);
+ Glib::ustring tip_text2;
+ if (tip_text)
+ tip_text2 = tip_text;
+ SpinScale* spinslider = new SpinScale("", def, lo, hi, step_inc, climb, digits, attr, tip_text2);
add_widget(spinslider, label);
add_attr_widget(spinslider);
return spinslider;
@@ -850,8 +853,10 @@ public:
// DualSpinScale
DualSpinScale* add_dualspinscale(const SPAttributeEnum attr, const Glib::ustring& label,
- const double lo, const double hi, const double step_inc,
- const double climb, const int digits, char* tip_text1 = NULL, char* tip_text2 = NULL)
+ const double lo, const double hi, const double step_inc,
+ const double climb, const int digits,
+ const Glib::ustring tip_text1 = "",
+ const Glib::ustring tip_text2 = "")
{
DualSpinScale* dss = new DualSpinScale("", "", lo, lo, hi, step_inc, climb, digits, attr, tip_text1, tip_text2);
add_widget(dss, label);
diff --git a/src/ui/widget/filter-effect-chooser.cpp b/src/ui/widget/filter-effect-chooser.cpp
index 7a9d512ac..30506851c 100644
--- a/src/ui/widget/filter-effect-chooser.cpp
+++ b/src/ui/widget/filter-effect-chooser.cpp
@@ -22,7 +22,7 @@ SimpleFilterModifier::SimpleFilterModifier(int flags)
_lb_blur(_("_Blur:")),
_lb_blur_unit(_("%")),
_blend(BlendModeConverter, SP_ATTR_INVALID, false),
- _blur(_("Blur (%)"), 0, 0, 100, 1, 0.01, 1)
+ _blur(_("Blur (%)"), 0, 0, 100, 1, 1, 1)
{
set_name("SimpleFilterModifier");
diff --git a/src/ui/widget/ink-spinscale.cpp b/src/ui/widget/ink-spinscale.cpp
new file mode 100644
index 000000000..4fe69633f
--- /dev/null
+++ b/src/ui/widget/ink-spinscale.cpp
@@ -0,0 +1,245 @@
+
+#include "ink-spinscale.h"
+#include <gdkmm/general.h>
+#include <gdkmm/cursor.h>
+#include <gdkmm/event.h>
+
+#include <gtkmm/spinbutton.h>
+
+#include <gdk/gdk.h>
+
+#include <iostream>
+
+// Constructor for Gtk::Range is protected... must derive a new class.
+InkRange::InkRange(Glib::RefPtr<Gtk::Adjustment> adjustment, Gtk::SpinButton* spinbutton)
+ : Glib::ObjectBase("InkRange")
+ , Gtk::Range()
+ , _spinbutton(spinbutton)
+ , _dragging(false)
+ , _drag_start(0)
+ , _drag_offset(0)
+{
+ set_name("InkRange");
+ set_adjustment(adjustment);
+ // std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;
+}
+
+void
+InkRange::set_label(Glib::ustring label) {
+ _label = label;
+}
+
+bool
+InkRange::on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr) {
+
+ // std::cout << "\nInkRange::on_draw" << std::endl;
+
+ // Get our own style info...
+ // auto style = get_style_context();
+ // auto state = style->get_state();
+ // std::cout << "color: " << style->get_color( state ).to_string() << std::endl;
+ // std::cout << "background: " << style->get_background_color( state ).to_string() << std::endl;
+ // std::cout << "border: " << style->get_border_color( state ).to_string() << std::endl;
+
+ // Get SpinButton style info...
+ auto style_spin = _spinbutton->get_style_context();
+ auto state_spin = style_spin->get_state();
+ Gdk::RGBA text_color = style_spin->get_color( state_spin );
+
+ // Create Pango layout.
+ auto layout_label = create_pango_layout(_label);
+ layout_label->set_ellipsize( Pango::ELLIPSIZE_END );
+ layout_label->set_width(PANGO_SCALE * get_width());
+
+ // Get y location of SpinButton text (to match vertical position of SpinButton text).
+ int x, y;
+ _spinbutton->get_layout_offsets(x, y);
+
+ // Render text in normal text color.
+ cr->save();
+ Gdk::Cairo::set_source_rgba(cr, text_color);
+ cr->set_source_rgba(0, 0, 0, 1);
+ cr->move_to(5, y );
+ layout_label->show_in_cairo_context(cr);
+ cr->restore();
+
+ // Fill widget proportional to value.
+ double fraction = get_fraction();
+
+ // Render bar (over normal text to reduce blurriness).
+ Gdk::RGBA fill_color("rgba(74,144,217,1.0)");
+ Gdk::Cairo::set_source_rgba(cr, fill_color);
+ cr->rectangle(0, 0, get_width() * fraction, get_height());
+ cr->fill_preserve(); // Save rectangle for clipping text.
+
+ // Render text, clipped, in white over bar (TODO: use same color as SpinButton progress bar).
+ cr->save();
+ cr->clip();
+ cr->set_source_rgba(1, 1, 1, 1);
+ cr->move_to(5, y);
+ layout_label->show_in_cairo_context(cr);
+ cr->restore();
+
+ return false;
+}
+
+bool
+InkRange::on_button_press_event(GdkEventButton* button_event) {
+
+ _dragging = true;
+
+ if (! (button_event->state & GDK_MOD1_MASK) ) {
+ set_adjustment_value(button_event->x);
+ }
+
+ // Dragging must be initialized after any adjustment due to button press.
+ _dragging = true;
+ _drag_start = button_event->x;
+ _drag_offset = get_width() * get_fraction();
+
+ return true;
+}
+
+bool
+InkRange::on_button_release_event(GdkEventButton* button_event) {
+
+ _dragging = false;
+ return true;
+}
+
+bool
+InkRange::on_motion_notify_event(GdkEventMotion* motion_event) {
+
+ double x = motion_event->x;
+ double y = motion_event->y;
+
+ if (_dragging) {
+
+ if (! (motion_event->state & GDK_MOD1_MASK) ) {
+ // Absolute change
+ set_adjustment_value(x);
+ } else {
+ // Relative change
+ double xx = (_drag_offset + (x - _drag_start) * 0.1);
+ set_adjustment_value(xx);
+ }
+ return true;
+ }
+
+ if (! (motion_event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) {
+
+ auto display = get_display();
+ auto cursor = Gdk::Cursor::create(display, Gdk::SB_DOWN_ARROW);
+ // Get Gdk::window (not Gtk::window).. set cursor for entire window.
+ // Would need to unset with leave event.
+ // get_window()->set_cursor( cursor );
+
+ // Can't see how to do this the C++ way since GdkEventMotion
+ // is a structure with a C window member. There is a gdkmm
+ // wrapping function for Gdk::EventMotion but only in unstable.
+ gdk_window_set_cursor( motion_event->window, cursor->gobj() );
+ }
+
+ return false;
+}
+
+double
+InkRange::get_fraction() {
+
+ Glib::RefPtr<Gtk::Adjustment> adjustment = get_adjustment();
+ double upper = adjustment->get_upper();
+ double lower = adjustment->get_lower();
+ double value = adjustment->get_value();
+ double fraction = (value - lower)/(upper - lower);
+
+ return fraction;
+}
+
+void
+InkRange::set_adjustment_value(double x) {
+
+ Glib::RefPtr<Gtk::Adjustment> adjustment = get_adjustment();
+ double upper = adjustment->get_upper();
+ double lower = adjustment->get_lower();
+ double fraction = x / (double)get_width();
+ double value = fraction * (upper - lower) + lower;
+ adjustment->set_value( value );
+}
+
+/*******************************************************************/
+
+InkSpinScale::InkSpinScale(double value, double lower,
+ double upper, double step_increment,
+ double page_increment, double page_size)
+{
+ set_name("InkSpinScale");
+
+ g_assert (upper - lower > 0);
+
+ _adjustment = Gtk::Adjustment::create(value,
+ lower,
+ upper,
+ step_increment,
+ page_increment,
+ page_size);
+
+ _spinbutton = Gtk::manage(new Gtk::SpinButton(_adjustment));
+ _spinbutton->set_numeric();
+ _spinbutton->signal_key_release_event().connect(sigc::mem_fun(*this,&InkSpinScale::on_key_release_event),false);
+ _range = Gtk::manage(new InkRange(_adjustment, _spinbutton));
+ pack_end( *_spinbutton, Gtk::PACK_SHRINK );
+ pack_end( *_range, Gtk::PACK_EXPAND_WIDGET );
+}
+
+InkSpinScale::InkSpinScale(Glib::RefPtr<Gtk::Adjustment> adjustment)
+ : _adjustment(adjustment)
+{
+ set_name("InkSpinScale");
+
+ g_assert (_adjustment->get_upper() - _adjustment->get_lower() > 0);
+
+ _spinbutton = Gtk::manage(new Gtk::SpinButton(_adjustment));
+ _spinbutton->set_numeric();
+ _range = Gtk::manage(new InkRange(_adjustment, _spinbutton));
+ pack_end( *_spinbutton, Gtk::PACK_SHRINK );
+ pack_end( *_range, Gtk::PACK_EXPAND_WIDGET );
+}
+
+void
+InkSpinScale::set_label(Glib::ustring label) {
+ _range->set_label(label);
+}
+
+void
+InkSpinScale::set_digits(int digits) {
+ _spinbutton->set_digits(digits);
+}
+
+int
+InkSpinScale::get_digits() const {
+ return _spinbutton->get_digits();
+}
+
+void
+InkSpinScale::set_focus_widget(GtkWidget * focus_widget) {
+ _focus_widget = focus_widget;
+}
+
+// Return focus to canvas.
+bool
+InkSpinScale::on_key_release_event(GdkEventKey* key_event) {
+
+ switch (key_event->keyval) {
+ case GDK_KEY_Escape:
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ {
+ if (_focus_widget) {
+ gtk_widget_grab_focus( _focus_widget );
+ }
+ }
+ break;
+ }
+
+ return false;
+}
diff --git a/src/ui/widget/ink-spinscale.h b/src/ui/widget/ink-spinscale.h
new file mode 100644
index 000000000..9b67d3891
--- /dev/null
+++ b/src/ui/widget/ink-spinscale.h
@@ -0,0 +1,78 @@
+#ifndef INK_SPINSCALE_H
+#define INK_SPINSCALE_H
+
+#include <glibmm/ustring.h>
+
+#include <gtkmm/box.h>
+#include <gtkmm/range.h>
+
+namespace Gtk {
+ class SpinButton;
+}
+
+class InkRange : public Gtk::Range
+{
+ public:
+ InkRange(Glib::RefPtr<Gtk::Adjustment>, Gtk::SpinButton* spinbutton);
+ ~InkRange() {};
+
+ void set_label(Glib::ustring label);
+
+ bool on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr) override;
+
+ protected:
+
+ bool on_button_press_event(GdkEventButton* button_event) override;
+ bool on_button_release_event(GdkEventButton* button_event) override;
+ bool on_motion_notify_event(GdkEventMotion* motion_event) override;
+
+ private:
+
+ double get_fraction();
+ void set_adjustment_value(double x);
+
+ Gtk::SpinButton * _spinbutton; // Needed to get placement/text color.
+ Glib::ustring _label;
+
+ bool _dragging;
+ double _drag_start;
+ double _drag_offset;
+};
+
+class InkSpinScale : public Gtk::Box
+{
+ public:
+
+ // Create an InkSpinScale with a new adjustment.
+ InkSpinScale(double value,
+ double lower,
+ double upper,
+ double step_increment = 1,
+ double page_increment = 10,
+ double page_size = 0);
+
+ // Create an InkSpinScale with a preexisting adjustment.
+ InkSpinScale(Glib::RefPtr<Gtk::Adjustment>);
+
+ virtual ~InkSpinScale() {};
+
+ void set_label(Glib::ustring label);
+ void set_digits(int digits);
+ int get_digits() const;
+ void set_focus_widget(GtkWidget *focus_widget);
+ Glib::RefPtr<Gtk::Adjustment> get_adjustment() { return _adjustment; };
+
+ protected:
+
+ InkRange* _range;
+ Gtk::SpinButton* _spinbutton;
+ Glib::RefPtr<Gtk::Adjustment> _adjustment;
+ GtkWidget* _focus_widget;
+
+ bool on_key_release_event(GdkEventKey* key_event) override;
+
+ private:
+
+};
+
+#endif // INK_SPINSCALE_H
diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp
index fa3f6e905..ae01c049b 100644
--- a/src/ui/widget/object-composite-settings.cpp
+++ b/src/ui/widget/object-composite-settings.cpp
@@ -52,8 +52,6 @@ ObjectCompositeSettings::ObjectCompositeSettings(unsigned int verb_code, char co
pack_start(_opacity_vbox, false, false, 2);
_opacity_vbox.pack_start(_opacity_scale);
- _opacity_scale.set_appearance("compact");
-
_opacity_scale.signal_value_changed().connect(sigc::mem_fun(*this, &ObjectCompositeSettings::_opacityValueChanged));
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h
index d7525093f..eff1ba800 100644
--- a/src/ui/widget/object-composite-settings.h
+++ b/src/ui/widget/object-composite-settings.h
@@ -46,7 +46,7 @@ private:
Glib::ustring _opacity_tag;
Gtk::VBox _opacity_vbox;
- Inkscape::UI::Widget::SpinScale _opacity_scale;
+ SpinScale _opacity_scale;
StyleSubject *_subject;
diff --git a/src/ui/widget/spin-scale.cpp b/src/ui/widget/spin-scale.cpp
index c658b4756..94b178a43 100644
--- a/src/ui/widget/spin-scale.cpp
+++ b/src/ui/widget/spin-scale.cpp
@@ -2,6 +2,7 @@
* Author:
*
* Copyright (C) 2012 Author
+ * 2017 Tavmjong Bah
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
@@ -11,50 +12,49 @@
#include <glibmm/i18n.h>
#include <glibmm/stringutils.h>
-#include "widgets/gimp/gimpspinscale.h"
-
namespace Inkscape {
namespace UI {
namespace Widget {
-SpinScale::SpinScale(const char* label, double value, double lower, double upper, double step_inc,
- double /*climb_rate*/, int digits, const SPAttributeEnum a, const char* tip_text)
+SpinScale::SpinScale(const Glib::ustring label, double value,
+ double lower, double upper,
+ double step_increment, double page_increment, int digits,
+ const SPAttributeEnum a, const Glib::ustring tip_text)
: AttrWidget(a, value)
+ , _inkspinscale(value, lower, upper, step_increment, page_increment, 0)
{
set_name("SpinScale");
- _adjustment = Gtk::Adjustment::create(value, lower, upper, step_inc);
- _spinscale = gimp_spin_scale_new (_adjustment->gobj(), label, digits);
- signal_value_changed().connect(signal_attr_changed().make_slot());
+ _inkspinscale.set_label (label);
+ _inkspinscale.set_digits (digits);
+ _inkspinscale.set_tooltip_text (tip_text);
- pack_start(*Gtk::manage(Glib::wrap(_spinscale)));
+ _adjustment = _inkspinscale.get_adjustment();
- if (tip_text){
- gtk_widget_set_tooltip_text( _spinscale, tip_text );
- }
+ signal_value_changed().connect(signal_attr_changed().make_slot());
+
+ pack_start(_inkspinscale);
show_all_children();
}
-SpinScale::SpinScale(const char* label,
- Glib::RefPtr<Gtk::Adjustment> adj,
- int digits,
- const SPAttributeEnum a,
- const char* tip_text)
- : AttrWidget(a, 0.0),
- _adjustment(adj)
-
+SpinScale::SpinScale(const Glib::ustring label,
+ Glib::RefPtr<Gtk::Adjustment> adjustment, int digits,
+ const SPAttributeEnum a, const Glib::ustring tip_text)
+ : AttrWidget(a, 0.0)
+ , _inkspinscale(adjustment)
{
+ set_name("SpinScale");
- _spinscale = gimp_spin_scale_new (_adjustment->gobj(), label, digits);
+ _inkspinscale.set_label (label);
+ _inkspinscale.set_digits (digits);
+ _inkspinscale.set_tooltip_text (tip_text);
+
+ _adjustment = _inkspinscale.get_adjustment();
signal_value_changed().connect(signal_attr_changed().make_slot());
- pack_start(*Gtk::manage(Glib::wrap(_spinscale)));
-
- if (tip_text){
- gtk_widget_set_tooltip_text( _spinscale, tip_text );
- }
+ pack_start(_inkspinscale);
show_all_children();
}
@@ -63,16 +63,16 @@ Glib::ustring SpinScale::get_as_attribute() const
{
const double val = _adjustment->get_value();
- //if(_spin.get_digits() == 0)
- // return Glib::Ascii::dtostr((int)val);
- //else
+ if( _inkspinscale.get_digits() == 0)
+ return Glib::Ascii::dtostr((int)val);
+ else
return Glib::Ascii::dtostr(val);
}
void SpinScale::set_from_attribute(SPObject* o)
{
const gchar* val = attribute_value(o);
- if(val)
+ if (val)
_adjustment->set_value(Glib::Ascii::strtod(val));
else
_adjustment->set_value(get_default()->as_double());
@@ -95,13 +95,7 @@ void SpinScale::set_value(const double val)
void SpinScale::set_focuswidget(GtkWidget *widget)
{
- gimp_spin_scale_set_focuswidget(_spinscale, widget);
-}
-
-
-void SpinScale::set_appearance(const gchar* appearance)
-{
- gimp_spin_scale_set_appearance(_spinscale, appearance);
+ _inkspinscale.set_focus_widget(widget);
}
const decltype(SpinScale::_adjustment) SpinScale::get_adjustment() const
@@ -115,11 +109,14 @@ decltype(SpinScale::_adjustment) SpinScale::get_adjustment()
}
-DualSpinScale::DualSpinScale(const char* label1, const char* label2, double value, double lower, double upper, double step_inc,
- double climb_rate, int digits, const SPAttributeEnum a, char* tip_text1, char* tip_text2)
+DualSpinScale::DualSpinScale(const Glib::ustring label1, const Glib::ustring label2,
+ double value, double lower, double upper,
+ double step_increment, double page_increment, int digits,
+ const SPAttributeEnum a,
+ const Glib::ustring tip_text1, const Glib::ustring tip_text2)
: AttrWidget(a),
- _s1(label1, value, lower, upper, step_inc, climb_rate, digits, SP_ATTR_INVALID, tip_text1),
- _s2(label2, value, lower, upper, step_inc, climb_rate, digits, SP_ATTR_INVALID, tip_text2),
+ _s1(label1, value, lower, upper, step_increment, page_increment, digits, SP_ATTR_INVALID, tip_text1),
+ _s2(label2, value, lower, upper, step_increment, page_increment, digits, SP_ATTR_INVALID, tip_text2),
//TRANSLATORS: "Link" means to _link_ two sliders together
_link(C_("Sliders", "Link"))
{
@@ -132,7 +129,7 @@ DualSpinScale::DualSpinScale(const char* label1, const char* label2, double valu
_link.signal_toggled().connect(sigc::mem_fun(*this, &DualSpinScale::link_toggled));
- Gtk::VBox* vb = Gtk::manage(new Gtk::VBox);
+ Gtk::Box* vb = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
vb->add(_s1);
vb->add(_s2);
pack_start(*vb);
@@ -199,12 +196,6 @@ SpinScale& DualSpinScale::get_SpinScale2()
return _s2;
}
-/*void DualSpinScale::remove_scale()
-{
- _s1.remove_scale();
- _s2.remove_scale();
-}*/
-
void DualSpinScale::link_toggled()
{
_s2.set_sensitive(!_link.get_active());
diff --git a/src/ui/widget/spin-scale.h b/src/ui/widget/spin-scale.h
index 33731f256..123f527bb 100644
--- a/src/ui/widget/spin-scale.h
+++ b/src/ui/widget/spin-scale.h
@@ -2,6 +2,7 @@
* Author:
*
* Copyright (C) 2012 Author
+ * 2017 Tavmjong Bah
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
@@ -16,27 +17,30 @@
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/togglebutton.h>
-#include "spinbutton.h"
#include "attr-widget.h"
+#include "ink-spinscale.h"
namespace Inkscape {
namespace UI {
namespace Widget {
/**
- * Wrap the gimpspinscale class
- * A combo widget with label, scale slider, spinbutton, and adjustment
+ * Wrap the InkSpinScale class and attach an attribute.
+ * A combo widget with label, scale slider, spinbutton, and adjustment;
*/
class SpinScale : public Gtk::Box, public AttrWidget
{
public:
- SpinScale(const char* label, double value, double lower, double upper, double step_inc, double climb_rate,
- int digits, const SPAttributeEnum a = SP_ATTR_INVALID, const char* tip_text = NULL);
+ SpinScale(const Glib::ustring label, double value,
+ double lower, double upper,
+ double step_increment, double page_increment, int digits,
+ const SPAttributeEnum a = SP_ATTR_INVALID, const Glib::ustring tip_text = "");
- SpinScale(const char* label,
- Glib::RefPtr<Gtk::Adjustment> adj,
- int digits, const SPAttributeEnum a = SP_ATTR_INVALID, const char* tip_text = NULL);
+ // Used by extensions
+ SpinScale(const Glib::ustring label,
+ Glib::RefPtr<Gtk::Adjustment> adjustment, int digits,
+ const SPAttributeEnum a = SP_ATTR_INVALID, const Glib::ustring tip_text = "");
virtual Glib::ustring get_as_attribute() const;
virtual void set_from_attribute(SPObject*);
@@ -46,11 +50,10 @@ public:
double get_value() const;
void set_value(const double);
void set_focuswidget(GtkWidget *widget);
- void set_appearance(const gchar* appearance);
private:
Glib::RefPtr<Gtk::Adjustment> _adjustment;
- GtkWidget *_spinscale;
+ InkSpinScale _inkspinscale;
public:
const decltype(_adjustment) get_adjustment() const;
@@ -66,8 +69,11 @@ public:
class DualSpinScale : public Gtk::Box, public AttrWidget
{
public:
- DualSpinScale(const char* label1, const char* label2, double value, double lower, double upper, double step_inc,
- double climb_rate, int digits, const SPAttributeEnum, char* tip_text1, char* tip_text2);
+ DualSpinScale(const Glib::ustring label1, const Glib::ustring label2,
+ double value, double lower, double upper,
+ double step_increment, double page_increment, int digits,
+ const SPAttributeEnum a,
+ const Glib::ustring tip_text1, const Glib::ustring tip_text2);
virtual Glib::ustring get_as_attribute() const;
virtual void set_from_attribute(SPObject*);
diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp
index 3d46fd81d..0f0d205e2 100644
--- a/src/widgets/ege-adjustment-action.cpp
+++ b/src/widgets/ege-adjustment-action.cpp
@@ -46,12 +46,12 @@
#include <gtkmm/container.h>
#include <gtkmm/radiomenuitem.h>
+#include <gtkmm/adjustment.h>
#include <gdk/gdkkeysyms.h>
#include "widgets/ege-adjustment-action.h"
-#include "gimp/gimpspinscale.h"
#include "ui/icon-names.h"
-
+#include "ui/widget/ink-spinscale.h"
static void ege_adjustment_action_finalize( GObject* object );
static void ege_adjustment_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec );
@@ -820,7 +820,11 @@ static GtkWidget* create_tool_item( GtkAction* action )
if ( act->private_data->appearanceMode == APPEARANCE_FULL ) {
/* Slider */
- spinbutton = gimp_spin_scale_new (act->private_data->adj, g_value_get_string( &value ), 0);
+ InkSpinScale* inkspinscale =
+ new InkSpinScale(Glib::wrap(act->private_data->adj));
+ inkspinscale->set_label( g_value_get_string( &value ));
+ inkspinscale->set_digits(0);
+ spinbutton = (GtkWidget*)inkspinscale->gobj();
gtk_widget_set_size_request(spinbutton, 100, -1);
} else if ( act->private_data->appearanceMode == APPEARANCE_MINIMAL ) {
diff --git a/src/widgets/gimp/CMakeLists.txt b/src/widgets/gimp/CMakeLists.txt
index 7b3e834e3..aa886cc67 100644
--- a/src/widgets/gimp/CMakeLists.txt
+++ b/src/widgets/gimp/CMakeLists.txt
@@ -1,12 +1,10 @@
set(gimpwidgets_SRC
gimpcolorwheel.c
- gimpspinscale.c
ruler.cpp
# -------
# Headers
gimpcolorwheel.h
- gimpspinscale.h
ruler.h
)
diff --git a/src/widgets/gimp/gimpspinscale.c b/src/widgets/gimp/gimpspinscale.c
deleted file mode 100644
index 8d8c6c935..000000000
--- a/src/widgets/gimp/gimpspinscale.c
+++ /dev/null
@@ -1,969 +0,0 @@
-/* GIMP - The GNU Image Manipulation Program
- * Copyright (C) 1995 Spencer Kimball and Peter Mattis
- *
- * gimpspinscale.c
- * Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
- * 2012 Øyvind Kolås <pippin@gimp.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <math.h>
-#include <string.h>
-#include <gdk/gdkkeysyms.h>
-
-#include "gimpspinscale.h"
-
-
-enum
-{
- PROP_0,
- PROP_LABEL,
- PROP_FOCUS_WIDGET
-};
-
-typedef enum
-{
- TARGET_NUMBER,
- TARGET_UPPER,
- TARGET_LOWER,
- TARGET_NONE
-} SpinScaleTarget;
-
-typedef enum
-{
- APPEARANCE_FULL = 1, /* Full size suitable for tablets */
- APPEARANCE_COMPACT, /* Compact, suitable for desktops with mouse control */
-} SpinScaleAppearance;
-
-typedef struct _GimpSpinScalePrivate GimpSpinScalePrivate;
-
-struct _GimpSpinScalePrivate
-{
- gchar *label;
-
- gboolean scale_limits_set;
- gdouble scale_lower;
- gdouble scale_upper;
- gdouble gamma;
-
- PangoLayout *layout;
- gboolean changing_value;
- gboolean relative_change;
- gdouble start_x;
- gdouble start_value;
-
- GtkWidget* focusWidget;
- gboolean transferFocus;
- SpinScaleAppearance appearanceMode;
-};
-
-#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- GIMP_TYPE_SPIN_SCALE, \
- GimpSpinScalePrivate))
-
-
-static void gimp_spin_scale_dispose (GObject *object);
-static void gimp_spin_scale_finalize (GObject *object);
-static void gimp_spin_scale_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_spin_scale_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void gimp_spin_scale_style_set (GtkWidget *widget,
- GtkStyle *prev_style);
-
-static void gimp_spin_scale_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width);
-static void gimp_spin_scale_get_preferred_height (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width);
-static gboolean gimp_spin_scale_draw (GtkWidget *widget,
- cairo_t *cr);
-
-static gboolean gimp_spin_scale_button_press (GtkWidget *widget,
- GdkEventButton *event);
-static gboolean gimp_spin_scale_button_release (GtkWidget *widget,
- GdkEventButton *event);
-static gboolean gimp_spin_scale_motion_notify (GtkWidget *widget,
- GdkEventMotion *event);
-static gboolean gimp_spin_scale_leave_notify (GtkWidget *widget,
- GdkEventCrossing *event);
-static gboolean gimp_spin_scale_keypress( GtkWidget *widget,
- GdkEventKey *event);
-
-static void gimp_spin_scale_defocus( GtkSpinButton *spin_button );
-
-static void gimp_spin_scale_value_changed (GtkSpinButton *spin_button);
-
-
-G_DEFINE_TYPE (GimpSpinScale, gimp_spin_scale, GTK_TYPE_SPIN_BUTTON);
-
-#define parent_class gimp_spin_scale_parent_class
-
-
-static void
-gimp_spin_scale_class_init (GimpSpinScaleClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkSpinButtonClass *spin_button_class = GTK_SPIN_BUTTON_CLASS (klass);
-
- object_class->dispose = gimp_spin_scale_dispose;
- object_class->finalize = gimp_spin_scale_finalize;
- object_class->set_property = gimp_spin_scale_set_property;
- object_class->get_property = gimp_spin_scale_get_property;
-
- widget_class->style_set = gimp_spin_scale_style_set;
- widget_class->get_preferred_width = gimp_spin_scale_get_preferred_width;
- widget_class->get_preferred_height = gimp_spin_scale_get_preferred_height;
- widget_class->draw = gimp_spin_scale_draw;
- widget_class->button_press_event = gimp_spin_scale_button_press;
- widget_class->button_release_event = gimp_spin_scale_button_release;
- widget_class->motion_notify_event = gimp_spin_scale_motion_notify;
- widget_class->leave_notify_event = gimp_spin_scale_leave_notify;
- widget_class->key_press_event = gimp_spin_scale_keypress;
-
- spin_button_class->value_changed = gimp_spin_scale_value_changed;
-
- g_object_class_install_property (object_class, PROP_LABEL,
- g_param_spec_string ("label", NULL, NULL,
- NULL,
- G_PARAM_READWRITE));
-
- g_type_class_add_private (klass, sizeof (GimpSpinScalePrivate));
-}
-
-static void
-gimp_spin_scale_init (GimpSpinScale *scale)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (scale);
-
- gtk_widget_add_events (GTK_WIDGET (scale),
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON1_MOTION_MASK |
- GDK_LEAVE_NOTIFY_MASK);
-
- gtk_entry_set_alignment (GTK_ENTRY (scale), 1.0);
- gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (scale), TRUE);
-
- private->gamma = 1.0;
- private->focusWidget = NULL;
- private->transferFocus = FALSE;
- private->appearanceMode = APPEARANCE_COMPACT;
-}
-
-static void
-gimp_spin_scale_dispose (GObject *object)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (object);
-
- if (private->layout)
- {
- g_object_unref (private->layout);
- private->layout = NULL;
- }
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-static void
-gimp_spin_scale_finalize (GObject *object)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (object);
-
- if (private->label)
- {
- g_free (private->label);
- private->label = NULL;
- }
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-gimp_spin_scale_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (object);
- GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
-
- switch (property_id)
- {
- case PROP_LABEL:
- gimp_spin_scale_set_label (scale, g_value_get_string (value));
- break;
-
- case PROP_FOCUS_WIDGET:
- {
- /* TODO unhook prior */
- private->focusWidget = GTK_WIDGET (g_value_get_pointer (value));
- }
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-static void
-gimp_spin_scale_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (object);
- GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
-
- switch (property_id)
- {
- case PROP_LABEL:
- g_value_set_string (value, gimp_spin_scale_get_label (scale));
- break;
-
- case PROP_FOCUS_WIDGET:
- g_value_set_pointer (value, private->focusWidget);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-
-void
-gimp_spin_scale_set_focuswidget( GtkWidget *scale, GtkWidget* widget )
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (scale);
-
- /* TODO unhook prior */
-
- private->focusWidget = widget;
-}
-
-void
-gimp_spin_scale_set_appearance( GtkWidget *widget, const gchar *appearance)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
-
- if ( strcmp("full", appearance) == 0 ) {
- private->appearanceMode = APPEARANCE_FULL;
- } else if ( strcmp("compact", appearance) == 0 ) {
- private->appearanceMode = APPEARANCE_COMPACT;
- }
-}
-
-static void
-gimp_spin_scale_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
- PangoContext *context = gtk_widget_get_pango_context (widget);
- PangoFontMetrics *metrics;
-
- GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget,
- minimum_width,
- natural_width);
-
- metrics = pango_context_get_metrics (context,
- pango_context_get_font_description (context),
- pango_context_get_language (context));
-
- if (private->label)
- {
- gint char_width;
- gint digit_width;
- gint char_pixels;
-
- char_width = pango_font_metrics_get_approximate_char_width (metrics);
- digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
- char_pixels = PANGO_PIXELS (MAX (char_width, digit_width));
-
- /* ~3 chars for the ellipse */
- *minimum_width += char_pixels * 3;
- *natural_width += char_pixels * 3;
- }
-
- pango_font_metrics_unref (metrics);
-}
-
-static void
-gimp_spin_scale_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- PangoContext *context = gtk_widget_get_pango_context (widget);
- PangoFontMetrics *metrics;
- //gint height;
-
- GTK_WIDGET_CLASS (parent_class)->get_preferred_height (widget,
- minimum_height,
- natural_height);
-
- metrics = pango_context_get_metrics (context,
- pango_context_get_font_description (context),
- pango_context_get_language (context));
-
- //height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
- // pango_font_metrics_get_descent (metrics));
-
- *minimum_height += 1;
- *natural_height += 1;
-
- pango_font_metrics_unref (metrics);
-}
-
-static void
-gimp_spin_scale_style_set (GtkWidget *widget,
- GtkStyle *prev_style)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
-
- GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
-
- if (private->layout)
- {
- g_object_unref (private->layout);
- private->layout = NULL;
- }
-}
-
-
-static gboolean
- gimp_spin_scale_draw (GtkWidget *widget,
- cairo_t *cr)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
- GtkStyleContext *style = gtk_widget_get_style_context(widget);
- GtkAllocation allocation;
- GdkRGBA color;
-
- cairo_save (cr);
- GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
- cairo_restore (cr);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- cairo_set_line_width (cr, 1.0);
-
- if (private->label)
- {
- GdkRectangle text_area;
- gint minimum_width;
- gint natural_width;
- PangoRectangle logical;
- gint layout_offset_x;
- gint layout_offset_y;
- GtkStateFlags state;
- GdkRGBA text_color;
- GdkRGBA bar_text_color;
- gdouble progress_fraction;
- gint progress_x;
- gint progress_y;
- gint progress_width;
- gint progress_height;
-
- gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
-
- GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget,
- &minimum_width,
- &natural_width);
-
- if (! private->layout)
- {
- private->layout = gtk_widget_create_pango_layout (widget,
- private->label);
- pango_layout_set_ellipsize (private->layout, PANGO_ELLIPSIZE_END);
- }
-
- pango_layout_set_width (private->layout,
- PANGO_SCALE *
- (allocation.width - minimum_width));
- pango_layout_get_pixel_extents (private->layout, NULL, &logical);
-
- gtk_entry_get_layout_offsets (GTK_ENTRY (widget), NULL, &layout_offset_y);
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- layout_offset_x = text_area.x + text_area.width - logical.width - 4;
- else
- layout_offset_x = 4;
-
- layout_offset_x -= logical.x;
-
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_get_color (style, state, &text_color);
-
- gtk_style_context_save (style);
- gtk_style_context_add_class (style, GTK_STYLE_CLASS_PROGRESSBAR);
- gtk_style_context_get_color (style, state, &bar_text_color);
- gtk_style_context_restore (style);
-
- progress_fraction = gtk_entry_get_progress_fraction (GTK_ENTRY (widget));
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- {
- progress_fraction = 1.0 - progress_fraction;
-
- progress_x = text_area.width * progress_fraction;
- progress_y = 0;
- progress_width = text_area.width - progress_x;
- progress_height = text_area.height;
- }
- else
- {
- progress_x = 0;
- progress_y = 0;
- progress_width = text_area.width * progress_fraction;
- progress_height = text_area.height;
- }
-
- cairo_save (cr);
-
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_rectangle (cr, 0, 0, text_area.width, text_area.height);
- cairo_rectangle (cr, progress_x, progress_y,
- progress_width, progress_height);
- cairo_clip (cr);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
-
- cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y-3);
- gdk_cairo_set_source_rgba (cr, &text_color);
- pango_cairo_show_layout (cr, private->layout);
- cairo_restore (cr);
-
- cairo_rectangle (cr, progress_x, progress_y,
- progress_width, progress_height);
- cairo_clip (cr);
-
- cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y-3);
- gdk_cairo_set_source_rgba (cr, &bar_text_color);
- pango_cairo_show_layout (cr, private->layout);
- }
-
- return FALSE;
-}
-
-/* Returns TRUE if a translation should be done */
-static gboolean
-gtk_widget_get_translation_to_window (GtkWidget *widget,
- GdkWindow *window,
- int *x,
- int *y)
-{
- GdkWindow *w, *widget_window;
-
- if (!gtk_widget_get_has_window (widget))
- {
- GtkAllocation allocation;
-
- gtk_widget_get_allocation (widget, &allocation);
-
- *x = -allocation.x;
- *y = -allocation.y;
- }
- else
- {
- *x = 0;
- *y = 0;
- }
-
- widget_window = gtk_widget_get_window (widget);
-
- for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
- {
- int wx, wy;
- gdk_window_get_position (w, &wx, &wy);
- *x += wx;
- *y += wy;
- }
-
- if (w == NULL)
- {
- *x = 0;
- *y = 0;
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-gimp_spin_scale_event_to_widget_coords (GtkWidget *widget,
- GdkWindow *window,
- gdouble event_x,
- gdouble event_y,
- gint *widget_x,
- gint *widget_y)
-{
- gint tx, ty;
-
- if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty))
- {
- event_x += tx;
- event_y += ty;
- }
-
- *widget_x = event_x;
- *widget_y = event_y;
-}
-
-static SpinScaleTarget
-gimp_spin_scale_get_target (GtkWidget *widget,
- gdouble x,
- gdouble y)
-{
- GtkAllocation allocation;
- PangoRectangle logical;
- gint layout_x;
- gint layout_y;
-
- gtk_widget_get_allocation (widget, &allocation);
- gtk_entry_get_layout_offsets (GTK_ENTRY (widget), &layout_x, &layout_y);
- pango_layout_get_pixel_extents (gtk_entry_get_layout (GTK_ENTRY (widget)),
- NULL, &logical);
-
- GdkRectangle text_area;
- gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
-
- if (x >= text_area.x && x < text_area.width &&
- y >= text_area.y && y < text_area.height)
- {
- x -= text_area.x;
- y -= text_area.y;
-
- if (x > layout_x && x < layout_x + logical.width &&
- y > layout_y && y < layout_y + logical.height)
- {
- return TARGET_NUMBER;
- }
- else if (y > text_area.height / 2)
- {
- return TARGET_LOWER;
- }
-
- return TARGET_UPPER;
- }
-
- return TARGET_NONE;
-}
-
-static void
-gimp_spin_scale_get_limits (GimpSpinScale *scale,
- gdouble *lower,
- gdouble *upper)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (scale);
-
- if (private->scale_limits_set)
- {
- *lower = private->scale_lower;
- *upper = private->scale_upper;
- }
- else
- {
- GtkSpinButton *spin_button = GTK_SPIN_BUTTON (scale);
- GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
-
- *lower = gtk_adjustment_get_lower (adjustment);
- *upper = gtk_adjustment_get_upper (adjustment);
- }
-}
-
-static void
-gimp_spin_scale_change_value (GtkWidget *widget,
- gdouble x)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
- GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
- GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
- gdouble lower;
- gdouble upper;
- gdouble value;
- GdkRectangle text_area;
- gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
- gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (widget), &lower, &upper);
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- x = text_area.width - x;
-
- if (private->relative_change)
- {
- gdouble diff;
- gdouble step;
-
- step = (upper - lower) / text_area.width / 10.0;
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- diff = x - (text_area.width - private->start_x);
- else
- diff = x - private->start_x;
-
- value = (private->start_value + diff * step);
- }
- else
- {
- gdouble fraction;
-
- fraction = x / (gdouble) text_area.width;
- if (fraction > 0.0)
- fraction = pow (fraction, private->gamma);
-
- value = fraction * (upper - lower) + lower;
- }
-
- gtk_adjustment_set_value (adjustment, value);
-}
-
-static gboolean
-gimp_spin_scale_button_press (GtkWidget *widget,
- GdkEventButton *event)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
-
- private->changing_value = FALSE;
- private->relative_change = FALSE;
-
- gint x, y;
- gimp_spin_scale_event_to_widget_coords (widget, event->window,
- event->x, event->y,
- &x, &y);
- switch (gimp_spin_scale_get_target (widget, x, y))
- {
- case TARGET_UPPER:
- private->changing_value = TRUE;
-
- gtk_widget_grab_focus (widget);
-
- gimp_spin_scale_change_value (widget, x);
-
- return TRUE;
-
- case TARGET_LOWER:
- private->changing_value = TRUE;
-
- gtk_widget_grab_focus (widget);
-
- private->relative_change = TRUE;
- private->start_x = x;
- private->start_value = gtk_adjustment_get_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)));
-
- return TRUE;
-
- default:
- break;
- }
-
- return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
-}
-
-static gboolean
-gimp_spin_scale_button_release (GtkWidget *widget,
- GdkEventButton *event)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
- gint x, y;
-
- gimp_spin_scale_event_to_widget_coords (widget, event->window,
- event->x, event->y,
- &x, &y);
-
- if (private->changing_value)
- {
- private->changing_value = FALSE;
- gimp_spin_scale_change_value (widget, x);
- return TRUE;
- }
-
- return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
-}
-
-static gboolean
-gimp_spin_scale_motion_notify (GtkWidget *widget,
- GdkEventMotion *event)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
-
- gdk_event_request_motions (event);
-
- gint x, y;
-
- gimp_spin_scale_event_to_widget_coords (widget, event->window,
- event->x, event->y,
- &x, &y);
-
- if (private->changing_value)
- {
- gimp_spin_scale_change_value (widget, x);
-
- return TRUE;
- }
-
- GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, event);
-
- if (! (event->state &
- (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))
- )
- {
- GdkDisplay *display = gtk_widget_get_display (widget);
- GdkCursor *cursor = NULL;
-
- switch (gimp_spin_scale_get_target (widget, x, y))
- {
- case TARGET_NUMBER:
- cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
- break;
-
- case TARGET_UPPER:
- cursor = gdk_cursor_new_for_display (display, GDK_SB_UP_ARROW);
- break;
-
- case TARGET_LOWER:
- cursor = gdk_cursor_new_for_display (display, GDK_SB_H_DOUBLE_ARROW);
- break;
-
- default:
- break;
- }
-
- if (cursor)
- {
- gdk_window_set_cursor (event->window, cursor);
- g_object_unref (cursor);
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-gimp_spin_scale_leave_notify (GtkWidget *widget,
- GdkEventCrossing *event)
-{
- gdk_window_set_cursor (event->window, NULL);
-
- return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event);
-}
-
-gboolean gimp_spin_scale_keypress( GtkWidget *widget, GdkEventKey *event)
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (widget);
- guint key = 0;
- gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ),
- event->hardware_keycode, (GdkModifierType)event->state,
- 0, &key, 0, 0, 0 );
-
- switch ( key ) {
-
- case GDK_KEY_Escape:
- case GDK_KEY_Return:
- case GDK_KEY_KP_Enter:
- {
- private->transferFocus = TRUE;
- gimp_spin_scale_defocus( GTK_SPIN_BUTTON(widget) );
- }
- break;
-
- }
-
- return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
-}
-
-static void
-gimp_spin_scale_defocus( GtkSpinButton *spin_button )
-{
- GimpSpinScalePrivate *private = GET_PRIVATE (spin_button);
-
- if ( private->transferFocus ) {
- if ( private->focusWidget ) {
- gtk_widget_grab_focus( private->focusWidget );
- }
- }
-}
-
-static void
-gimp_spin_scale_value_changed (GtkSpinButton *spin_button)
-{
- GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
- GimpSpinScalePrivate *private = GET_PRIVATE (spin_button);
- gdouble lower;
- gdouble upper;
- gdouble value;
-
- gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (spin_button), &lower, &upper);
-
- value = CLAMP (gtk_adjustment_get_value (adjustment), lower, upper);
-
- gtk_entry_set_progress_fraction (GTK_ENTRY (spin_button),
- pow ((value - lower) / (upper - lower),
- 1.0 / private->gamma));
-
- // TODO - Allow scrollwheel to change value then return focus,
- // but clicks/keypress should keep focus in the control
- //if ( gtk_widget_has_focus( GTK_WIDGET(spin_button) ) ) {
- // gimp_spin_scale_defocus( spin_button );
- //}
-}
-
-
-/* public functions */
-
-GtkWidget *
-gimp_spin_scale_new (GtkAdjustment *adjustment,
- const gchar *label,
- gint digits)
-{
- g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
-
- return g_object_new (GIMP_TYPE_SPIN_SCALE,
- "adjustment", adjustment,
- "label", label,
- "digits", digits,
- NULL);
-}
-
-void
-gimp_spin_scale_set_label (GimpSpinScale *scale,
- const gchar *label)
-{
- GimpSpinScalePrivate *private;
-
- g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
-
- private = GET_PRIVATE (scale);
-
- if (label == private->label)
- return;
-
- g_free (private->label);
- private->label = g_strdup (label);
-
- if (private->layout)
- {
- g_object_unref (private->layout);
- private->layout = NULL;
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (scale));
-
- g_object_notify (G_OBJECT (scale), "label");
-}
-
-const gchar *
-gimp_spin_scale_get_label (GimpSpinScale *scale)
-{
- g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), NULL);
-
- return GET_PRIVATE (scale)->label;
-}
-
-void
-gimp_spin_scale_set_scale_limits (GimpSpinScale *scale,
- gdouble lower,
- gdouble upper)
-{
- GimpSpinScalePrivate *private;
- GtkSpinButton *spin_button;
- GtkAdjustment *adjustment;
-
- g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
-
- private = GET_PRIVATE (scale);
- spin_button = GTK_SPIN_BUTTON (scale);
- adjustment = gtk_spin_button_get_adjustment (spin_button);
-
- g_return_if_fail (lower >= gtk_adjustment_get_lower (adjustment));
- g_return_if_fail (upper <= gtk_adjustment_get_upper (adjustment));
-
- private->scale_limits_set = TRUE;
- private->scale_lower = lower;
- private->scale_upper = upper;
- private->gamma = 1.0;
-
- gimp_spin_scale_value_changed (spin_button);
-}
-
-void
-gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale)
-{
- GimpSpinScalePrivate *private;
-
- g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
-
- private = GET_PRIVATE (scale);
-
- private->scale_limits_set = FALSE;
- private->scale_lower = 0.0;
- private->scale_upper = 0.0;
-
- gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale));
-}
-
-gboolean
-gimp_spin_scale_get_scale_limits (GimpSpinScale *scale,
- gdouble *lower,
- gdouble *upper)
-{
- GimpSpinScalePrivate *private;
-
- g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), FALSE);
-
- private = GET_PRIVATE (scale);
-
- if (lower)
- *lower = private->scale_lower;
-
- if (upper)
- *upper = private->scale_upper;
-
- return private->scale_limits_set;
-}
-
-void
-gimp_spin_scale_set_gamma (GimpSpinScale *scale,
- gdouble gamma)
-{
- GimpSpinScalePrivate *private;
-
- g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
-
- private = GET_PRIVATE (scale);
-
- private->gamma = gamma;
-
- gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale));
-}
-
-gdouble
-gimp_spin_scale_get_gamma (GimpSpinScale *scale)
-{
- g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), 1.0);
-
- return GET_PRIVATE(scale)->gamma;
-}
diff --git a/src/widgets/gimp/gimpspinscale.h b/src/widgets/gimp/gimpspinscale.h
deleted file mode 100644
index b42a0faf8..000000000
--- a/src/widgets/gimp/gimpspinscale.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* GIMP - The GNU Image Manipulation Program
- * Copyright (C) 1995 Spencer Kimball and Peter Mattis
- *
- * gimpspinscale.h
- * Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GIMP_SPIN_SCALE_H__
-#define __GIMP_SPIN_SCALE_H__
-
-#ifndef WITH_GIMP
-#include <gtk/gtk.h>
-#endif
-
-G_BEGIN_DECLS
-
-#define GIMP_TYPE_SPIN_SCALE (gimp_spin_scale_get_type ())
-#define GIMP_SPIN_SCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SPIN_SCALE, GimpSpinScale))
-#define GIMP_SPIN_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_SPIN_SCALE, GimpSpinScaleClass))
-#define GIMP_IS_SPIN_SCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SPIN_SCALE))
-#define GIMP_IS_SPIN_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_SPIN_SCALE))
-#define GIMP_SPIN_SCALE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_SPIN_SCALE, GimpSpinScaleClass))
-
-
-typedef struct _GimpSpinScale GimpSpinScale;
-typedef struct _GimpSpinScaleClass GimpSpinScaleClass;
-
-struct _GimpSpinScale
-{
- GtkSpinButton parent_instance;
-};
-
-struct _GimpSpinScaleClass
-{
- GtkSpinButtonClass parent_class;
-};
-
-
-GType gimp_spin_scale_get_type (void) G_GNUC_CONST;
-
-GtkWidget * gimp_spin_scale_new (GtkAdjustment *adjustment,
- const gchar *label,
- gint digits);
-
-void gimp_spin_scale_set_label (GimpSpinScale *scale,
- const gchar *label);
-const gchar * gimp_spin_scale_get_label (GimpSpinScale *scale);
-
-void gimp_spin_scale_set_scale_limits (GimpSpinScale *scale,
- gdouble lower,
- gdouble upper);
-void gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale);
-gboolean gimp_spin_scale_get_scale_limits (GimpSpinScale *scale,
- gdouble *lower,
- gdouble *upper);
-
-void gimp_spin_scale_set_gamma (GimpSpinScale *scale,
- gdouble gamma);
-gdouble gimp_spin_scale_get_gamma (GimpSpinScale *scale);
-
-void gimp_spin_scale_set_focuswidget (GtkWidget *scale,
- GtkWidget *widget);
-
-void gimp_spin_scale_set_appearance (GtkWidget *scale,
- const gchar *appearance);
-
-G_END_DECLS
-
-#endif /* __GIMP_SPIN_SCALE_H__ */