gtkmm 2.14 keeps warning "GtkSpinButton: setting an adjustment with non-zero page...
[synfig.git] / synfig-studio / trunk / src / gtkmm / widget_vector.cpp
blobad826834206d5ebcd03c72366927c4c745adabc5
1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_vector.cpp
3 ** \brief Template File
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
19 ** \endlegal
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #ifdef USING_PCH
26 # include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
32 #include <gtkmm/spinbutton.h>
33 #include "widget_vector.h"
34 #include "widget_distance.h"
35 #include "app.h"
37 #include "general.h"
39 #endif
41 /* === U S I N G =========================================================== */
43 using namespace std;
44 using namespace synfig;
45 using namespace studio;
47 /* === M A C R O S ========================================================= */
49 #define DIGITS 10
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 Widget_Vector::Widget_Vector():
58 Gtk::HBox(false, 5),
59 x_adjustment(0,-100000000,100000000,0.05,0.05,0),
60 y_adjustment(0,-100000000,100000000,0.05,0.05,0)
62 Gtk::Label *label;
64 label=manage(new class Gtk::Label("X:"));
65 label->set_alignment(0, 0.5);
66 label->show();
67 pack_start(*label, Gtk::PACK_SHRINK);
69 spinbutton_x=manage(new class Gtk::SpinButton(x_adjustment,0.05,DIGITS));
70 spinbutton_x->set_alignment(1);
71 spinbutton_x->set_update_policy(Gtk::UPDATE_ALWAYS);
72 spinbutton_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
73 pack_start(*spinbutton_x, Gtk::PACK_EXPAND_WIDGET);
75 distance_x=manage(new Widget_Distance());
76 distance_x->set_digits(4);
77 distance_x->set_update_policy(Gtk::UPDATE_ALWAYS);
78 distance_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
79 pack_start(*distance_x, Gtk::PACK_EXPAND_WIDGET);
81 label=manage(new class Gtk::Label("Y:"));
82 label->set_alignment(0, 0.5);
83 label->show();
84 pack_start(*label, Gtk::PACK_SHRINK);
86 spinbutton_y=manage(new class Gtk::SpinButton(y_adjustment,0.05,DIGITS));
87 spinbutton_y->set_alignment(1);
88 spinbutton_y->set_update_policy(Gtk::UPDATE_ALWAYS);
89 spinbutton_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
90 spinbutton_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
91 pack_start(*spinbutton_y, Gtk::PACK_EXPAND_WIDGET);
93 distance_y=manage(new Widget_Distance());
94 distance_y->set_digits(4);
95 distance_y->set_update_policy(Gtk::UPDATE_ALWAYS);
96 distance_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
97 distance_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
98 pack_start(*distance_y, Gtk::PACK_EXPAND_WIDGET);
100 spinbutton_x->show();
101 spinbutton_y->show();
103 spinbutton_x->signal_activate().connect(sigc::mem_fun(*spinbutton_y,&Gtk::SpinButton::grab_focus));
104 distance_x->signal_activate().connect(sigc::mem_fun(*distance_y,&Gtk::SpinButton::grab_focus));
107 Widget_Vector::~Widget_Vector()
111 void
112 Widget_Vector::on_grab_focus()
114 if(canvas_)
115 distance_x->grab_focus();
116 else
117 spinbutton_x->grab_focus();
120 void
121 Widget_Vector::set_has_frame(bool x)
123 if(spinbutton_x)
125 spinbutton_x->set_has_frame(x);
126 spinbutton_y->set_has_frame(x);
127 spinbutton_x->set_size_request(48,-1);
128 spinbutton_y->set_size_request(48,-1);
131 distance_x->set_has_frame(x);
132 distance_y->set_has_frame(x);
133 distance_x->set_size_request(48,-1);
134 distance_y->set_size_request(48,-1);
137 void
138 Widget_Vector::set_digits(int x)
140 if(spinbutton_x)
142 spinbutton_x->set_digits(x);
143 spinbutton_y->set_digits(x);
144 spinbutton_x->set_size_request(48,-1);
145 spinbutton_y->set_size_request(48,-1);
148 distance_x->set_digits(x);
149 distance_y->set_digits(x);
150 distance_x->set_size_request(48,-1);
151 distance_y->set_size_request(48,-1);
154 void
155 Widget_Vector::set_value(const synfig::Vector &data)
157 vector=data;
159 if(canvas_){try
161 Distance distx(vector[0],Distance::SYSTEM_UNITS),disty(vector[1],Distance::SYSTEM_UNITS);
162 distx.convert(App::distance_system,canvas_->rend_desc());
163 disty.convert(App::distance_system,canvas_->rend_desc());
164 distance_x->set_value(distx);
165 distance_y->set_value(disty);
166 spinbutton_x->hide();
167 spinbutton_y->hide();
168 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }}
169 else
171 spinbutton_x->set_value(vector[0]);
172 spinbutton_y->set_value(vector[1]);
173 distance_x->hide();
174 distance_y->hide();
178 const synfig::Vector &
179 Widget_Vector::get_value()
181 if(!canvas_ && spinbutton_x)
183 vector[0]=spinbutton_x->get_value();
184 vector[1]=spinbutton_y->get_value();
185 distance_x->hide();
186 distance_y->hide();
188 else try
190 vector[0]=distance_x->get_value().units(canvas_->rend_desc());
191 vector[1]=distance_y->get_value().units(canvas_->rend_desc());
192 spinbutton_x->hide();
193 spinbutton_y->hide();
194 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }
195 return vector;
198 void
199 Widget_Vector::on_value_changed()
201 signal_value_changed()();
204 void
205 Widget_Vector::set_canvas(synfig::Canvas::LooseHandle x)
207 canvas_=x;
208 if(x)
210 if(spinbutton_x)
212 spinbutton_x->hide();
213 spinbutton_y->hide();
214 // delete spinbutton_x;
215 // delete spinbutton_y;
217 distance_x->show();
218 distance_y->show();
220 else
222 if(spinbutton_x)
224 spinbutton_x->show();
225 spinbutton_y->show();
227 distance_x->hide();
228 distance_y->hide();
232 void
233 Widget_Vector::show_all_vfunc()
235 if(canvas_)
237 distance_x->show();
238 distance_y->show();
240 else
242 spinbutton_x->show();
243 spinbutton_y->show();
245 show();