2
* \brief SpinButton widget, that allows entry of both '.' and ',' for the decimal, even when in numeric mode.
8
* Copyright (C) 2011 Author
10
* Released under GNU GPL. Read the file 'COPYING' for more information.
17
#include "spinbutton.h"
19
#include "unit-menu.h"
20
#include "util/expression-evaluator.h"
21
#include "event-context.h"
29
SpinButton::connect_signals() {
30
signal_input().connect(sigc::mem_fun(*this, &SpinButton::on_input));
31
signal_focus_in_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_focus_in_event));
32
signal_key_press_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_key_press_event));
36
* This callback function should try to convert the entered text to a number and write it to newvalue.
37
* It calls a method to evaluate the (potential) mathematical expression.
39
* @retval false No conversion done, continue with default handler.
40
* @retval true Conversion successful, don't call default handler.
43
SpinButton::on_input(double* newvalue)
46
Inkscape::Util::GimpEevlQuantity result;
48
Unit unit = _unit_menu->getUnit();
49
result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), &unit);
50
// check if output dimension corresponds to input unit
51
if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) {
52
throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.","");
55
result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), NULL);
58
*newvalue = result.value;
60
catch(Inkscape::Util::EvaluatorException &e) {
61
g_message ("%s", e.what());
69
/** When focus is obtained, save the value to enable undo later.
70
* @retval false continue with default handler.
71
* @retval true don't call default handler.
74
SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/)
76
on_focus_in_value = get_value();
77
return false; // do not consume the event
80
/** Handle specific keypress events, like Ctrl+Z
81
* @retval false continue with default handler.
82
* @retval true don't call default handler.
85
SpinButton::on_my_key_press_event(GdkEventKey* event)
87
switch (get_group0_keyval (event)) {
90
return true; // I consumed the event
94
if (event->state & GDK_CONTROL_MASK) {
96
return true; // I consumed the event
103
return false; // do not consume the event
107
* Undo the editing, by resetting the value upon when the spinbutton got focus.
112
set_value(on_focus_in_value);
116
} // namespace Widget
118
} // namespace Inkscape
123
c-file-style:"stroustrup"
124
c-file-offsets:((innamespace . 0)(inline-open . 0))
129
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :