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 "widgets/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 "widgets/widget_vector.h"
44 #include "widgets/widget_filename.h"
45 #include "widgets/widget_enum.h"
46 #include "widgets/widget_coloredit.h"
47 #include "widgets/widget_canvaschooser.h"
48 #include "widgets/widget_time.h"
50 #include "widgets/widget_distance.h"
56 using namespace synfig;
59 using namespace studio;
61 /* === M A C R O S ========================================================= */
65 /* === G L O B A L S ======================================================= */
67 /* === P R O C E D U R E S ================================================= */
69 /* === M E T H O D S ======================================================= */
71 Widget_ValueBase::Widget_ValueBase():
72 Glib::ObjectBase (typeid(Widget_ValueBase)),
74 real_adjustment(0,-2000000000,2000000000,0.05,0.05,0),
75 integer_adjustment(0,-2000000000,2000000000,1,1,0),
76 angle_adjustment(0,-2000000000,2000000000,1,1,0)
80 label=manage(new class Gtk::Label("Unknown Datatype"));
84 vector_widget=manage(new class Widget_Vector());
85 pack_start(*vector_widget);
87 color_widget=manage(new class Widget_ColorEdit());
88 pack_start(*color_widget);
90 enum_widget=manage(new class Widget_Enum());
91 pack_start(*enum_widget);
93 real_widget=manage(new class Gtk::SpinButton(real_adjustment,0.05,DIGITS));
94 pack_start(*real_widget);
96 integer_widget=manage(new class Gtk::SpinButton(integer_adjustment,1,0));
97 pack_start(*integer_widget);
99 angle_widget=manage(new class Gtk::SpinButton(angle_adjustment,15,2));
100 pack_start(*angle_widget);
102 bool_widget=manage(new class Gtk::CheckButton());
103 pack_start(*bool_widget);
105 //color_widget=manage(new class Gtk::ColorSelection());
106 //pack_start(*color_widget);
108 string_widget=manage(new class Gtk::Entry());
109 pack_start(*string_widget);
111 canvas_widget=manage(new class Widget_CanvasChooser());
112 pack_start(*canvas_widget);
114 filename_widget=manage(new class Widget_Filename());
115 pack_start(*filename_widget);
117 time_widget=manage(new class Widget_Time());
118 pack_start(*time_widget);
120 distance_widget=manage(new class Widget_Distance());
121 pack_start(*distance_widget);
124 vector_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
125 color_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
126 enum_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
127 real_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
128 integer_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
129 angle_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
130 string_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
131 canvas_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
132 filename_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
133 time_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
134 distance_widget->signal_activate().connect(sigc::mem_fun(*this,&Widget_ValueBase::activate));
136 /*signal_focus_in_event().connect(
139 sigc::mem_fun(*this,&Widget_ValueBase::grab_focus)
145 Widget_ValueBase::~Widget_ValueBase()
150 Widget_ValueBase::activate()
156 Widget_ValueBase::inside_cellrenderer()
158 string_widget->set_has_frame(false);
159 string_widget->gobj()->is_cell_renderer = true; // XXX
161 real_widget->set_has_frame(false);
162 //static_cast<Gtk::Entry*>(real_widget)->gobj()->is_cell_renderer = true; // XXX
164 distance_widget->set_has_frame(false);
165 //static_cast<Gtk::Entry*>(distance_widget)->gobj()->is_cell_renderer = true; // XXX
167 integer_widget->set_has_frame(false);
168 //static_cast<Gtk::Entry*>(integer_widget)->gobj()->is_cell_renderer = true; // XXX
169 vector_widget->set_has_frame(false);
170 //vector_widget->set_digits(10);
172 color_widget->set_has_frame(false);
173 //color_widget->set_digits(10);
174 filename_widget->set_has_frame(false);
175 time_widget->set_has_frame(false);
179 Widget_ValueBase::set_sensitive(bool x)
181 Gtk::HBox::set_sensitive(x);
182 label->set_sensitive(x);
183 vector_widget->set_sensitive(x);
184 real_widget->set_sensitive(x);
185 integer_widget->set_sensitive(x);
186 bool_widget->set_sensitive(x);
187 color_widget->set_sensitive(x);
188 string_widget->set_sensitive(x);
189 canvas_widget->set_sensitive(x);
190 enum_widget->set_sensitive(x);
191 angle_widget->set_sensitive(x);
192 filename_widget->set_sensitive(x);
193 time_widget->set_sensitive(x);
194 distance_widget->set_sensitive(x);
198 Widget_ValueBase::set_value(const synfig::ValueBase &data)
201 vector_widget->hide();
203 integer_widget->hide();
205 color_widget->hide();
206 string_widget->hide();
207 canvas_widget->hide();
209 angle_widget->hide();
210 filename_widget->hide();
212 distance_widget->hide();
216 switch(value.get_type())
218 case ValueBase::TYPE_VECTOR:
219 vector_widget->set_canvas(canvas);
220 vector_widget->set_value(value.get(Vector()));
221 vector_widget->show();
223 case ValueBase::TYPE_REAL:
224 if(param_desc.get_is_distance() && canvas)
226 Distance dist(value.get(Real()),Distance::SYSTEM_UNITS);
227 dist.convert(App::distance_system,canvas->rend_desc());
228 distance_widget->set_value(dist);
229 distance_widget->show();
233 real_widget->set_value(value.get(Real()));
237 case ValueBase::TYPE_TIME:
238 if(canvas)time_widget->set_fps(canvas->rend_desc().get_frame_rate());
239 time_widget->set_value(value.get(Time()));
242 case ValueBase::TYPE_ANGLE:
243 angle_widget->set_value(Angle::deg(value.get(Angle())).get());
244 angle_widget->show();
246 case ValueBase::TYPE_INTEGER:
247 if(param_desc.get_hint()!="enum")
249 integer_widget->set_value(value.get(int()));
250 integer_widget->show();
254 enum_widget->set_param_desc(param_desc);
255 enum_widget->set_value(value.get(int()));
259 case ValueBase::TYPE_CANVAS:
261 canvas_widget->set_parent_canvas(canvas);
262 canvas_widget->set_value(value.get(etl::loose_handle<synfig::Canvas>()));
263 canvas_widget->show();
265 case ValueBase::TYPE_BOOL:
266 bool_widget->set_active(value.get(bool()));
269 case ValueBase::TYPE_STRING:
270 if(param_desc.get_hint()!="filename")
272 string_widget->set_text(value.get(string()));
273 string_widget->show();
277 filename_widget->set_value(value.get(string()));
278 filename_widget->show();
281 case ValueBase::TYPE_COLOR:
283 color_widget->set_value(value.get(synfig::Color()));
284 color_widget->show();
287 synfig::Color color=value.get(synfig::Color());
288 gdkcolor.set_rgb_p(color.get_r(),color.get_g(),color.get_b());
289 color_widget->set_current_color(gdkcolor);
290 color_widget->set_has_opacity_control(true);
291 color_widget->set_current_alpha((unsigned short)(color.get_a()*65535.0));
292 color_widget->show();
300 }catch(...) { synfig::error(__FILE__":%d: Caught something that was thrown",__LINE__); }
303 const synfig::ValueBase &
304 Widget_ValueBase::get_value()
306 switch(value.get_type())
308 case ValueBase::TYPE_VECTOR:
309 value=vector_widget->get_value();
311 case ValueBase::TYPE_REAL:
312 if(param_desc.get_is_distance() && canvas)
313 value=distance_widget->get_value().units(canvas->rend_desc());
315 value=real_widget->get_value();
317 case ValueBase::TYPE_TIME:
318 value=time_widget->get_value();
320 case ValueBase::TYPE_ANGLE:
321 value=Angle::deg(angle_widget->get_value());
323 case ValueBase::TYPE_CANVAS:
324 value=canvas_widget->get_value();
326 case ValueBase::TYPE_INTEGER:
327 if(param_desc.get_hint()!="enum")
329 value=integer_widget->get_value_as_int();
333 value=enum_widget->get_value();
337 case ValueBase::TYPE_BOOL:
338 value=bool_widget->get_active();
340 case ValueBase::TYPE_STRING:
341 if(param_desc.get_hint()!="filename")
343 value=string(string_widget->get_text());
347 value=string(filename_widget->get_value());
350 case ValueBase::TYPE_COLOR:
352 value=color_widget->get_value();
356 gdkcolor=color_widget->get_current_color();
357 color.set_r(gdkcolor.get_red_p());
358 color.set_g(gdkcolor.get_green_p());
359 color.set_b(gdkcolor.get_blue_p());
360 color.set_a(color_widget->get_current_alpha()/65535.0);
375 Widget_ValueBase::on_grab_focus()
377 switch(value.get_type())
379 case ValueBase::TYPE_VECTOR:
380 vector_widget->grab_focus();
382 case ValueBase::TYPE_REAL:
383 if(param_desc.get_is_distance()&& canvas)
384 distance_widget->grab_focus();
386 real_widget->grab_focus();
388 case ValueBase::TYPE_TIME:
389 time_widget->grab_focus();
391 case ValueBase::TYPE_ANGLE:
392 angle_widget->grab_focus();
394 case ValueBase::TYPE_CANVAS:
395 canvas_widget->grab_focus();
397 case ValueBase::TYPE_INTEGER:
398 if(param_desc.get_hint()!="enum")
400 integer_widget->grab_focus();
404 enum_widget->grab_focus();
408 case ValueBase::TYPE_BOOL:
409 bool_widget->grab_focus();
411 case ValueBase::TYPE_STRING:
412 if(param_desc.get_hint()!="filename")
414 string_widget->grab_focus();
418 filename_widget->grab_focus();
421 case ValueBase::TYPE_COLOR:
423 color_widget->grab_focus();
432 Glib::SignalProxy0<void>
433 Widget_ValueBase::signal_activate()
435 switch(value.get_type())
437 case ValueBase::TYPE_VECTOR:
438 return vector_widget->signal_activate();
440 case ValueBase::TYPE_REAL:
441 if(param_desc.get_is_distance()&& canvas)
442 return distance_widget->signal_activate();
444 return real_widget->signal_activate();
447 case ValueBase::TYPE_TIME:
448 return time_widget->signal_activate();
450 case ValueBase::TYPE_ANGLE:
451 return angle_widget->signal_activate();
453 case ValueBase::TYPE_CANVAS:
454 return canvas_widget->signal_activate();
456 case ValueBase::TYPE_INTEGER:
457 if(param_desc.get_hint()!="enum")
458 return integer_widget->signal_activate();
460 return enum_widget->signal_activate();
463 case ValueBase::TYPE_BOOL:
464 return string_widget->signal_activate();
466 case ValueBase::TYPE_STRING:
467 if(param_desc.get_hint()!="filename")
469 return string_widget->signal_activate();
473 return filename_widget->signal_activate();
476 case ValueBase::TYPE_COLOR:
478 return color_widget->signal_activate();
482 return string_widget->signal_activate();