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(( child_param_desc.get_is_distance() || 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:
248 String child_param_hint(child_param_desc.get_hint());
249 String param_hint(param_desc.get_hint());
250 if(child_param_hint!="enum" && param_hint!="enum")
252 integer_widget->set_value(value.get(int()));
253 integer_widget->show();
257 if(child_param_hint=="enum")
258 enum_widget->set_param_desc(child_param_desc);
260 enum_widget->set_param_desc(param_desc);
261 enum_widget->set_value(value.get(int()));
266 case ValueBase::TYPE_CANVAS:
268 canvas_widget->set_parent_canvas(canvas);
269 canvas_widget->set_value(value.get(etl::loose_handle<synfig::Canvas>()));
270 canvas_widget->show();
272 case ValueBase::TYPE_BOOL:
273 bool_widget->set_active(value.get(bool()));
276 case ValueBase::TYPE_STRING:
277 if(child_param_desc.get_hint()!="filename" && param_desc.get_hint()!="filename")
279 string_widget->set_text(value.get(string()));
280 string_widget->show();
284 filename_widget->set_value(value.get(string()));
285 filename_widget->show();
288 case ValueBase::TYPE_COLOR:
290 color_widget->set_value(value.get(synfig::Color()));
291 color_widget->show();
294 synfig::Color color=value.get(synfig::Color());
295 gdkcolor.set_rgb_p(color.get_r(),color.get_g(),color.get_b());
296 color_widget->set_current_color(gdkcolor);
297 color_widget->set_has_opacity_control(true);
298 color_widget->set_current_alpha((unsigned short)(color.get_a()*65535.0));
299 color_widget->show();
307 }catch(...) { synfig::error(__FILE__":%d: Caught something that was thrown",__LINE__); }
310 const synfig::ValueBase &
311 Widget_ValueBase::get_value()
313 switch(value.get_type())
315 case ValueBase::TYPE_VECTOR:
316 value=vector_widget->get_value();
318 case ValueBase::TYPE_REAL:
319 if(param_desc.get_is_distance() && canvas)
320 value=distance_widget->get_value().units(canvas->rend_desc());
322 value=real_widget->get_value();
324 case ValueBase::TYPE_TIME:
325 value=time_widget->get_value();
327 case ValueBase::TYPE_ANGLE:
328 value=Angle::deg(angle_widget->get_value());
330 case ValueBase::TYPE_CANVAS:
331 value=canvas_widget->get_value();
333 case ValueBase::TYPE_INTEGER:
334 if(child_param_desc.get_hint()!="enum" && param_desc.get_hint()!="enum")
336 value=integer_widget->get_value_as_int();
340 value=enum_widget->get_value();
344 case ValueBase::TYPE_BOOL:
345 value=bool_widget->get_active();
347 case ValueBase::TYPE_STRING:
348 if(param_desc.get_hint()!="filename")
350 value=string(string_widget->get_text());
354 value=string(filename_widget->get_value());
357 case ValueBase::TYPE_COLOR:
359 value=color_widget->get_value();
363 gdkcolor=color_widget->get_current_color();
364 color.set_r(gdkcolor.get_red_p());
365 color.set_g(gdkcolor.get_green_p());
366 color.set_b(gdkcolor.get_blue_p());
367 color.set_a(color_widget->get_current_alpha()/65535.0);
382 Widget_ValueBase::on_grab_focus()
384 switch(value.get_type())
386 case ValueBase::TYPE_VECTOR:
387 vector_widget->grab_focus();
389 case ValueBase::TYPE_REAL:
390 if(param_desc.get_is_distance()&& canvas)
391 distance_widget->grab_focus();
393 real_widget->grab_focus();
395 case ValueBase::TYPE_TIME:
396 time_widget->grab_focus();
398 case ValueBase::TYPE_ANGLE:
399 angle_widget->grab_focus();
401 case ValueBase::TYPE_CANVAS:
402 canvas_widget->grab_focus();
404 case ValueBase::TYPE_INTEGER:
405 if(child_param_desc.get_hint()!="enum" && param_desc.get_hint()!="enum")
407 integer_widget->grab_focus();
411 enum_widget->grab_focus();
415 case ValueBase::TYPE_BOOL:
416 bool_widget->grab_focus();
418 case ValueBase::TYPE_STRING:
419 if(param_desc.get_hint()!="filename")
421 string_widget->grab_focus();
425 filename_widget->grab_focus();
428 case ValueBase::TYPE_COLOR:
430 color_widget->grab_focus();
439 Glib::SignalProxy0<void>
440 Widget_ValueBase::signal_activate()
442 switch(value.get_type())
444 case ValueBase::TYPE_VECTOR:
445 return vector_widget->signal_activate();
447 case ValueBase::TYPE_REAL:
448 if(param_desc.get_is_distance()&& canvas)
449 return distance_widget->signal_activate();
451 return real_widget->signal_activate();
454 case ValueBase::TYPE_TIME:
455 return time_widget->signal_activate();
457 case ValueBase::TYPE_ANGLE:
458 return angle_widget->signal_activate();
460 case ValueBase::TYPE_CANVAS:
461 return canvas_widget->signal_activate();
463 case ValueBase::TYPE_INTEGER:
464 if(param_desc.get_hint()!="enum")
465 return integer_widget->signal_activate();
467 return enum_widget->signal_activate();
470 case ValueBase::TYPE_BOOL:
471 return string_widget->signal_activate();
473 case ValueBase::TYPE_STRING:
474 if(param_desc.get_hint()!="filename")
476 return string_widget->signal_activate();
480 return filename_widget->signal_activate();
483 case ValueBase::TYPE_COLOR:
485 return color_widget->signal_activate();
489 return string_widget->signal_activate();