1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_value.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include <gtkmm/label.h>
33 #include "widget_value.h"
34 #include <ETL/stringf>
35 #include <gtkmm/celleditable.h>
36 #include <gtkmm/editable.h>
37 #include <gtkmm/entry.h>
38 #include <gtkmm/eventbox.h>
39 #include <gtk/gtkentry.h> /* see XXX below */
43 #include "widget_vector.h"
44 #include "widget_filename.h"
45 #include "widget_enum.h"
46 #include "widget_coloredit.h"
47 #include "widget_canvaschooser.h"
48 #include "widget_time.h"
50 #include "widget_distance.h"
54 using namespace synfig;
57 using namespace studio;
59 /* === M A C R O S ========================================================= */
63 /* === G L O B A L S ======================================================= */
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
69 Widget_ValueBase::Widget_ValueBase():
70 Glib::ObjectBase (typeid(Widget_ValueBase)),
72 real_adjustment(0,-2000000000,2000000000,0.05,0.05,0.05),
73 integer_adjustment(0,-2000000000,2000000000,1,1,1),
74 angle_adjustment(0,-2000000000,2000000000,1,1,1)
78 label=manage(new class Gtk::Label("Unknown Datatype"));
82 vector_widget=manage(new class Widget_Vector());
83 pack_start(*vector_widget);
85 color_widget=manage(new class Widget_ColorEdit());
86 pack_start(*color_widget);
88 enum_widget=manage(new class Widget_Enum());
89 pack_start(*enum_widget);
91 real_widget=manage(new class Gtk::SpinButton(real_adjustment,0.05,DIGITS));
92 pack_start(*real_widget);
94 integer_widget=manage(new class Gtk::SpinButton(integer_adjustment,1,0));
95 pack_start(*integer_widget);
97 angle_widget=manage(new class Gtk::SpinButton(angle_adjustment,15,2));
98 pack_start(*angle_widget);
100 bool_widget=manage(new class Gtk::CheckButton());
101 pack_start(*bool_widget);
103 //color_widget=manage(new class Gtk::ColorSelection());
104 //pack_start(*color_widget);
106 string_widget=manage(new class Gtk::Entry());
107 pack_start(*string_widget);
109 canvas_widget=manage(new class Widget_CanvasChooser());
110 pack_start(*canvas_widget);
112 filename_widget=manage(new class Widget_Filename());
113 pack_start(*filename_widget);
115 time_widget=manage(new class Widget_Time());
116 pack_start(*time_widget);
118 distance_widget=manage(new class Widget_Distance());
119 pack_start(*distance_widget);
122 vector_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
123 color_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
124 enum_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
125 real_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
126 integer_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
127 angle_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
128 string_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
129 canvas_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
130 filename_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
131 time_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
132 distance_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
134 /*signal_focus_in_event().connect(
137 sigc::mem_fun(*this,&Widget_ValueBase::grab_focus)
143 Widget_ValueBase::~Widget_ValueBase()
148 Widget_ValueBase::activate()
155 Widget_ValueBase::inside_cellrenderer()
157 string_widget->set_has_frame(false);
158 string_widget->gobj()->is_cell_renderer = true; // XXX
160 real_widget->set_has_frame(false);
161 //static_cast<Gtk::Entry*>(real_widget)->gobj()->is_cell_renderer = true; // XXX
163 distance_widget->set_has_frame(false);
164 //static_cast<Gtk::Entry*>(distance_widget)->gobj()->is_cell_renderer = true; // XXX
166 integer_widget->set_has_frame(false);
167 //static_cast<Gtk::Entry*>(integer_widget)->gobj()->is_cell_renderer = true; // XXX
168 vector_widget->set_has_frame(false);
169 //vector_widget->set_digits(10);
171 color_widget->set_has_frame(false);
172 //color_widget->set_digits(10);
173 filename_widget->set_has_frame(false);
174 time_widget->set_has_frame(false);
178 Widget_ValueBase::set_sensitive(bool x)
180 Gtk::HBox::set_sensitive(x);
181 label->set_sensitive(x);
182 vector_widget->set_sensitive(x);
183 real_widget->set_sensitive(x);
184 integer_widget->set_sensitive(x);
185 bool_widget->set_sensitive(x);
186 color_widget->set_sensitive(x);
187 string_widget->set_sensitive(x);
188 canvas_widget->set_sensitive(x);
189 enum_widget->set_sensitive(x);
190 angle_widget->set_sensitive(x);
191 filename_widget->set_sensitive(x);
192 time_widget->set_sensitive(x);
193 distance_widget->set_sensitive(x);
197 Widget_ValueBase::set_value(const synfig::ValueBase &data)
200 vector_widget->hide();
202 integer_widget->hide();
204 color_widget->hide();
205 string_widget->hide();
206 canvas_widget->hide();
208 angle_widget->hide();
209 filename_widget->hide();
211 distance_widget->hide();
215 switch(value.get_type())
217 case ValueBase::TYPE_VECTOR:
218 vector_widget->set_canvas(canvas);
219 vector_widget->set_value(value.get(Vector()));
220 vector_widget->show();
222 case ValueBase::TYPE_REAL:
223 if(param_desc.get_is_distance() && canvas)
225 Distance dist(value.get(Real()),Distance::SYSTEM_UNITS);
226 dist.convert(App::distance_system,canvas->rend_desc());
227 distance_widget->set_value(dist);
228 distance_widget->show();
232 real_widget->set_value(value.get(Real()));
236 case ValueBase::TYPE_TIME:
237 if(canvas)time_widget->set_fps(canvas->rend_desc().get_frame_rate());
238 time_widget->set_value(value.get(Time()));
241 case ValueBase::TYPE_ANGLE:
242 angle_widget->set_value(Angle::deg(value.get(Angle())).get());
243 angle_widget->show();
245 case ValueBase::TYPE_INTEGER:
246 if(param_desc.get_hint()!="enum")
248 integer_widget->set_value(value.get(int()));
249 integer_widget->show();
253 enum_widget->set_param_desc(param_desc);
254 enum_widget->set_value(value.get(int()));
258 case ValueBase::TYPE_CANVAS:
260 canvas_widget->set_parent_canvas(canvas);
261 canvas_widget->set_value(value.get(etl::loose_handle<synfig::Canvas>()));
262 canvas_widget->show();
264 case ValueBase::TYPE_BOOL:
265 bool_widget->set_active(value.get(bool()));
268 case ValueBase::TYPE_STRING:
269 if(param_desc.get_hint()!="filename")
271 string_widget->set_text(value.get(string()));
272 string_widget->show();
276 filename_widget->set_value(value.get(string()));
277 filename_widget->show();
280 case ValueBase::TYPE_COLOR:
282 color_widget->set_value(value.get(synfig::Color()));
283 color_widget->show();
286 synfig::Color color=value.get(synfig::Color());
287 gdkcolor.set_rgb_p(color.get_r(),color.get_g(),color.get_b());
288 color_widget->set_current_color(gdkcolor);
289 color_widget->set_has_opacity_control(true);
290 color_widget->set_current_alpha((unsigned short)(color.get_a()*65535.0));
291 color_widget->show();
299 }catch(...) { synfig::error(__FILE__":%d: Caught something that was thrown",__LINE__); }
302 const synfig::ValueBase &
303 Widget_ValueBase::get_value()
305 switch(value.get_type())
307 case ValueBase::TYPE_VECTOR:
308 value=vector_widget->get_value();
310 case ValueBase::TYPE_REAL:
311 if(param_desc.get_is_distance() && canvas)
312 value=distance_widget->get_value().units(canvas->rend_desc());
314 value=real_widget->get_value();
316 case ValueBase::TYPE_TIME:
317 value=time_widget->get_value();
319 case ValueBase::TYPE_ANGLE:
320 value=Angle::deg(angle_widget->get_value());
322 case ValueBase::TYPE_CANVAS:
323 value=canvas_widget->get_value();
325 case ValueBase::TYPE_INTEGER:
326 if(param_desc.get_hint()!="enum")
328 value=integer_widget->get_value_as_int();
332 value=enum_widget->get_value();
336 case ValueBase::TYPE_BOOL:
337 value=bool_widget->get_active();
339 case ValueBase::TYPE_STRING:
340 if(param_desc.get_hint()!="filename")
342 value=string(string_widget->get_text());
346 value=string(filename_widget->get_value());
349 case ValueBase::TYPE_COLOR:
351 value=color_widget->get_value();
355 gdkcolor=color_widget->get_current_color();
356 color.set_r(gdkcolor.get_red_p());
357 color.set_g(gdkcolor.get_green_p());
358 color.set_b(gdkcolor.get_blue_p());
359 color.set_a(color_widget->get_current_alpha()/65535.0);
374 Widget_ValueBase::on_grab_focus()
376 switch(value.get_type())
378 case ValueBase::TYPE_VECTOR:
379 vector_widget->grab_focus();
381 case ValueBase::TYPE_REAL:
382 if(param_desc.get_is_distance()&& canvas)
383 distance_widget->grab_focus();
385 real_widget->grab_focus();
387 case ValueBase::TYPE_TIME:
388 time_widget->grab_focus();
390 case ValueBase::TYPE_ANGLE:
391 angle_widget->grab_focus();
393 case ValueBase::TYPE_CANVAS:
394 canvas_widget->grab_focus();
396 case ValueBase::TYPE_INTEGER:
397 if(param_desc.get_hint()!="enum")
399 integer_widget->grab_focus();
403 enum_widget->grab_focus();
407 case ValueBase::TYPE_BOOL:
408 bool_widget->grab_focus();
410 case ValueBase::TYPE_STRING:
411 if(param_desc.get_hint()!="filename")
413 string_widget->grab_focus();
417 filename_widget->grab_focus();
420 case ValueBase::TYPE_COLOR:
422 color_widget->grab_focus();
431 Glib::SignalProxy0<void>
432 Widget_ValueBase::signal_activate()
434 switch(value.get_type())
436 case ValueBase::TYPE_VECTOR:
437 return vector_widget->signal_activate();
439 case ValueBase::TYPE_REAL:
440 if(param_desc.get_is_distance()&& canvas)
441 return distance_widget->signal_activate();
443 return real_widget->signal_activate();
446 case ValueBase::TYPE_TIME:
447 return time_widget->signal_activate();
449 case ValueBase::TYPE_ANGLE:
450 return angle_widget->signal_activate();
452 case ValueBase::TYPE_CANVAS:
453 return canvas_widget->signal_activate();
455 case ValueBase::TYPE_INTEGER:
456 if(param_desc.get_hint()!="enum")
457 return integer_widget->signal_activate();
459 return enum_widget->signal_activate();
462 case ValueBase::TYPE_BOOL:
463 return string_widget->signal_activate();
465 case ValueBase::TYPE_STRING:
466 if(param_desc.get_hint()!="filename")
468 return string_widget->signal_activate();
472 return filename_widget->signal_activate();
475 case ValueBase::TYPE_COLOR:
477 return color_widget->signal_activate();
481 return string_widget->signal_activate();