2 * GUI widget object implementations.
3 * Copyright (C) 2007-2009 Krzysztof Foltman
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
23 #include <calf/ctl_curve.h>
24 #include <calf/ctl_keyboard.h>
25 #include <calf/ctl_led.h>
26 #include <calf/giface.h>
28 #include <calf/gui_controls.h>
29 #include <calf/preset.h>
30 #include <calf/preset_gui.h>
31 #include <calf/main_win.h>
34 using namespace calf_plugins
;
37 /******************************** controls ********************************/
41 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
45 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
47 parameter_properties
&props
= get_props();
48 widget
= gtk_combo_box_new_text ();
51 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
52 gtk_list_store_insert_with_values (lstore
, NULL
, j
- (int)props
.min
, 0, props
.choices
[j
- (int)props
.min
], 1, calf_utils::i2s(j
).c_str(), -1);
54 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
55 gtk_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
56 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Combobox");
60 void combo_box_param_control::set()
63 parameter_properties
&props
= get_props();
64 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
67 void combo_box_param_control::get()
69 parameter_properties
&props
= get_props();
70 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
73 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
75 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
76 if (jhp
->attribs
.count("setter-key"))
80 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
82 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
84 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
93 void combo_box_param_control::send_status(const char *key
, const char *value
)
95 if (attribs
.count("key") && key
== attribs
["key"])
97 gtk_list_store_clear (lstore
);
99 std::string v
= value
;
102 while (pos
< v
.length()) {
103 size_t endpos
= v
.find("\n", pos
);
104 if (endpos
== string::npos
)
106 string line
= v
.substr(pos
, endpos
- pos
);
108 size_t tabpos
= line
.find('\t');
109 if (tabpos
== string::npos
)
112 key
= line
.substr(0, tabpos
);
113 label
= line
.substr(tabpos
+ 1);
116 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
123 if (attribs
.count("current-key") && key
== attribs
["current-key"])
130 void combo_box_param_control::set_to_last_key()
132 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
133 if (i
!= key2pos
.end())
135 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
139 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
144 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
147 param_no
= _param_no
;
149 widget
= gtk_hscale_new_with_range (0, 1, get_props().get_increment());
150 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
151 gtk_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
153 if(get_int("inverted", 0) > 0) {
154 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
156 int size
= get_int("size", 2);
161 char *name
= g_strdup_printf("Calf-HScale%i", size
);
162 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
163 gtk_widget_set_size_request (widget
, size
* 100, -1);
168 void hscale_param_control::init_xml(const char *element
)
170 if (attribs
.count("width"))
171 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
172 if (attribs
.count("position"))
174 string v
= attribs
["position"];
175 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
176 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
180 void hscale_param_control::set()
183 parameter_properties
&props
= get_props();
184 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
185 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
188 void hscale_param_control::get()
190 parameter_properties
&props
= get_props();
191 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
192 gui
->set_param_value(param_no
, cvalue
, this);
195 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
197 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
201 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
203 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
204 const parameter_properties
&props
= jhp
->get_props();
205 float cvalue
= props
.from_01 (arg1
);
208 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
209 return g_strdup (props
.to_string (cvalue
).c_str());
214 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
217 param_no
= _param_no
;
218 widget
= gtk_vscale_new_with_range (0, 1, get_props().get_increment());
219 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
220 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
222 if(get_int("inverted", 0) > 0) {
223 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
225 int size
= get_int("size", 2);
230 char *name
= g_strdup_printf("Calf-VScale%i", size
);
231 gtk_widget_set_size_request (widget
, -1, size
* 100);
232 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
237 void vscale_param_control::init_xml(const char *element
)
239 if (attribs
.count("height"))
240 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
243 void vscale_param_control::set()
246 parameter_properties
&props
= get_props();
247 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
248 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
251 void vscale_param_control::get()
253 parameter_properties
&props
= get_props();
254 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
255 gui
->set_param_value(param_no
, cvalue
, this);
258 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
260 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
266 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
268 gui
= _gui
, param_no
= _param_no
;
270 if (param_no
!= -1 && !attribs
.count("text"))
271 text
= get_props().name
;
273 text
= attribs
["text"];
274 widget
= gtk_label_new(text
.c_str());
275 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
276 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Label");
282 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
285 param_no
= _param_no
;
287 widget
= gtk_label_new ("");
290 parameter_properties
&props
= get_props();
291 gtk_label_set_width_chars (GTK_LABEL (widget
), props
.get_char_count());
295 require_attribute("key");
296 require_int_attribute("width");
297 param_variable
= attribs
["key"];
298 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
300 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
301 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Value");
305 void value_param_control::set()
310 parameter_properties
&props
= get_props();
311 gtk_label_set_text (GTK_LABEL (widget
), props
.to_string(gui
->plugin
->get_param_value(param_no
)).c_str());
314 void value_param_control::send_status(const char *key
, const char *value
)
316 if (key
== param_variable
)
318 gtk_label_set_text (GTK_LABEL (widget
), value
);
324 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
326 gui
= _gui
, param_no
= _param_no
;
327 // parameter_properties &props = get_props();
328 widget
= calf_vumeter_new ();
329 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-vumeter");
330 calf_vumeter_set_mode (CALF_VUMETER (widget
), (CalfVUMeterMode
)get_int("mode", 0));
331 CALF_VUMETER(widget
)->vumeter_hold
= get_float("hold", 0);
332 CALF_VUMETER(widget
)->vumeter_falloff
= get_float("falloff", 0.f
);
333 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-VUMeter");
337 void vumeter_param_control::set()
340 parameter_properties
&props
= get_props();
341 calf_vumeter_set_value (CALF_VUMETER (widget
), props
.to_01(gui
->plugin
->get_param_value(param_no
)));
348 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
350 gui
= _gui
, param_no
= _param_no
;
351 // parameter_properties &props = get_props();
352 widget
= calf_led_new ();
353 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-led");
354 CALF_LED(widget
)->led_mode
= get_int("mode", 0);
355 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LED");
359 void led_param_control::set()
362 // parameter_properties &props = get_props();
363 calf_led_set_value (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
));
370 GtkWidget
*tube_param_control::create(plugin_gui
*_gui
, int _param_no
)
372 gui
= _gui
, param_no
= _param_no
;
373 // parameter_properties &props = get_props();
374 widget
= calf_tube_new ();
375 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-tube");
376 CALF_TUBE(widget
)->size
= get_int("size", 2);
377 CALF_TUBE(widget
)->direction
= get_int("direction", 2);
378 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Tube");
382 void tube_param_control::set()
385 // parameter_properties &props = get_props();
386 calf_tube_set_value (CALF_TUBE (widget
), gui
->plugin
->get_param_value(param_no
));
393 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
396 param_no
= _param_no
;
398 widget
= gtk_check_button_new ();
399 gtk_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
400 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Checkbox");
404 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
406 param_control
*jhp
= (param_control
*)value
;
410 void check_param_control::get()
412 const parameter_properties
&props
= get_props();
413 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
416 void check_param_control::set()
419 const parameter_properties
&props
= get_props();
420 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
425 GtkWidget
*radio_param_control::create(plugin_gui
*_gui
, int _param_no
)
428 param_no
= _param_no
;
429 require_attribute("value");
431 string value_name
= attribs
["value"];
432 const parameter_properties
&props
= get_props();
433 if (props
.choices
&& (value_name
< "0" || value_name
> "9"))
435 for (int i
= 0; props
.choices
[i
]; i
++)
437 if (value_name
== props
.choices
[i
])
439 value
= i
+ (int)props
.min
;
445 value
= get_int("value");
447 if (attribs
.count("label"))
448 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), attribs
["label"].c_str());
450 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), props
.choices
[value
- (int)props
.min
]);
451 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget
), FALSE
);
453 gui
->set_radio_group(param_no
, gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget
)));
454 gtk_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (radio_clicked
), (gpointer
)this);
455 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-RadioButton");
459 void radio_param_control::radio_clicked(GtkRadioButton
*widget
, gpointer value
)
461 param_control
*jhp
= (param_control
*)value
;
465 void radio_param_control::get()
467 // const parameter_properties &props = get_props();
468 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)))
469 gui
->set_param_value(param_no
, value
, this);
472 void radio_param_control::set()
475 const parameter_properties
&props
= get_props();
476 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), value
== ((int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
));
481 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
484 param_no
= _param_no
;
486 const parameter_properties
&props
= get_props();
488 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
490 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
492 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
493 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
494 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
495 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-SpinButton");
499 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
501 param_control
*jhp
= (param_control
*)value
;
505 void spin_param_control::get()
507 // const parameter_properties &props = get_props();
508 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
511 void spin_param_control::set()
514 // const parameter_properties &props = get_props();
515 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
520 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
523 param_no
= _param_no
;
525 widget
= gtk_button_new_with_label (get_props().name
);
526 gtk_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (button_clicked
), (gpointer
)this);
527 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Button");
531 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
533 param_control
*jhp
= (param_control
*)value
;
538 void button_param_control::get()
540 const parameter_properties
&props
= get_props();
541 gui
->set_param_value(param_no
, props
.max
, this);
544 void button_param_control::set()
547 const parameter_properties
&props
= get_props();
548 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
549 gtk_button_clicked (GTK_BUTTON (widget
));
554 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
557 param_no
= _param_no
;
558 const parameter_properties
&props
= get_props();
560 //widget = calf_knob_new_with_range (props.to_01 (gui->plugin->get_param_value(param_no)), 0, 1, 0.01);
561 widget
= calf_knob_new();
562 float increment
= props
.get_increment();
563 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
564 CALF_KNOB(widget
)->knob_type
= get_int("type");
565 CALF_KNOB(widget
)->knob_size
= get_int("size", 2);
566 if(CALF_KNOB(widget
)->knob_size
> 5) {
567 CALF_KNOB(widget
)->knob_size
= 5;
568 } else if (CALF_KNOB(widget
)->knob_size
< 1) {
569 CALF_KNOB(widget
)->knob_size
= 1;
571 gtk_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
572 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Knob");
576 void knob_param_control::get()
578 const parameter_properties
&props
= get_props();
579 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
580 gui
->set_param_value(param_no
, value
, this);
585 void knob_param_control::set()
588 const parameter_properties
&props
= get_props();
589 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
594 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
596 param_control
*jhp
= (param_control
*)value
;
602 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
605 param_no
= _param_no
;
606 widget
= calf_toggle_new ();
608 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
609 if(CALF_TOGGLE(widget
)->size
> 2) {
610 CALF_TOGGLE(widget
)->size
= 2;
611 } else if (CALF_TOGGLE(widget
)->size
< 1) {
612 CALF_TOGGLE(widget
)->size
= 1;
615 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
616 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ToggleButton");
620 void toggle_param_control::get()
622 const parameter_properties
&props
= get_props();
623 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
624 gui
->set_param_value(param_no
, value
, this);
629 void toggle_param_control::set()
632 const parameter_properties
&props
= get_props();
633 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
638 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
640 param_control
*jhp
= (param_control
*)value
;
646 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
649 param_no
= _param_no
;
650 // const parameter_properties &props = get_props();
652 widget
= calf_keyboard_new();
653 kb
= CALF_KEYBOARD(widget
);
654 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
655 kb
->sink
= new CalfKeyboard::EventAdapter
;
656 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Keyboard");
662 struct curve_param_control_callback
: public CalfCurve::EventAdapter
664 curve_param_control
*ctl
;
666 curve_param_control_callback(curve_param_control
*_ctl
)
669 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
671 ss
<< data
.size() << endl
;
672 for (size_t i
= 0; i
< data
.size(); i
++)
673 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
674 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
676 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
678 // int gridpt = floor(x * 71 * 2);
679 // clip to the middle of the nearest white key
680 x
= (floor(x
* 71) + 0.5)/ 71.0;
684 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
687 param_no
= _param_no
;
688 require_attribute("key");
690 widget
= calf_curve_new(get_int("maxpoints", -1));
691 curve
= CALF_CURVE(widget
);
692 curve
->sink
= new curve_param_control_callback(this);
693 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
694 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Curve");
698 void curve_param_control::send_configure(const char *key
, const char *value
)
700 // cout << "send conf " << key << endl;
701 if (attribs
["key"] == key
)
703 stringstream
ss(value
);
704 CalfCurve::point_vector pts
;
707 unsigned int npoints
= 0;
711 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
714 pts
.push_back(CalfCurve::point(x
, y
));
716 calf_curve_set_points(widget
, pts
);
723 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
726 param_no
= _param_no
;
727 require_attribute("key");
729 widget
= gtk_entry_new();
730 entry
= GTK_ENTRY(widget
);
731 gtk_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
732 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
733 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Entry");
737 void entry_param_control::send_configure(const char *key
, const char *value
)
739 // cout << "send conf " << key << endl;
740 if (attribs
["key"] == key
)
742 gtk_entry_set_text(entry
, value
);
746 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
748 entry_param_control
*ctl
= (entry_param_control
*)value
;
749 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
754 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
757 param_no
= _param_no
;
758 require_attribute("key");
759 require_attribute("title");
761 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
762 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
763 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
764 gtk_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
765 if (attribs
.count("width"))
766 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
767 if (attribs
.count("width_chars"))
768 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
769 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-FileButton");
773 void filechooser_param_control::send_configure(const char *key
, const char *value
)
775 // cout << "send conf " << key << endl;
776 if (attribs
["key"] == key
)
778 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
782 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
784 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
785 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
787 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
792 void line_graph_param_control::on_idle()
794 if (get_int("refresh", 0))
798 GtkWidget
*line_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
801 param_no
= _param_no
;
802 last_generation
= -1;
803 // const parameter_properties &props = get_props();
805 widget
= calf_line_graph_new ();
806 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-graph");
807 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
808 widget
->requisition
.width
= get_int("width", 40);
809 widget
->requisition
.height
= get_int("height", 40);
810 calf_line_graph_set_square(clg
, get_int("square", 0));
811 clg
->source
= gui
->plugin
->get_line_graph_iface();
812 clg
->source_id
= param_no
;
813 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LineGraph");
817 void line_graph_param_control::set()
819 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
820 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
822 int ws
= gdk_window_get_state(widget
->window
);
823 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
825 last_generation
= calf_line_graph_update_if(CALF_LINE_GRAPH(widget
), last_generation
);
829 line_graph_param_control::~line_graph_param_control()
835 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
838 param_no
= _param_no
;
840 teif
= gui
->plugin
->get_table_edit_iface();
841 const table_column_info
*tci
= teif
->get_table_columns(param_no
);
844 while (tci
[cols
].name
!= NULL
)
847 GType
*p
= new GType
[cols
];
848 for (int i
= 0; i
< cols
; i
++)
849 p
[i
] = G_TYPE_STRING
;
850 lstore
= gtk_list_store_newv(cols
, p
);
852 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
854 tree
= GTK_TREE_VIEW (widget
);
856 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
858 for (int i
= 0; i
< cols
; i
++)
860 GtkCellRenderer
*cr
= NULL
;
862 if (tci
[i
].type
== TCT_ENUM
) {
863 cr
= gtk_cell_renderer_combo_new ();
864 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
865 for (int j
= 0; tci
[i
].values
[j
]; j
++)
866 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
867 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
870 bool editable
= tci
[i
].type
!= TCT_LABEL
;
871 cr
= gtk_cell_renderer_text_new ();
873 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
875 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
876 gtk_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
877 gtk_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
878 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
880 gtk_tree_view_set_headers_visible(tree
, TRUE
);
881 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ListView");
885 void listview_param_control::update_store()
887 gtk_list_store_clear(lstore
);
888 uint32_t rows
= teif
->get_table_rows(param_no
);
889 for (uint32_t i
= 0; i
< rows
; i
++)
892 gtk_list_store_insert(lstore
, &iter
, i
);
893 for (int j
= 0; j
< cols
; j
++)
895 gtk_list_store_set(lstore
, &iter
, j
, teif
->get_cell(param_no
, i
, j
).c_str(), -1);
897 positions
.push_back(iter
);
901 void listview_param_control::send_configure(const char *key
, const char *value
)
903 if (attribs
["key"] == key
)
909 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
911 const table_column_info
*tci
= pThis
->teif
->get_table_columns(pThis
->param_no
);
912 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
914 pThis
->teif
->set_cell(pThis
->param_no
, atoi(path
), column
, new_text
, error
);
916 pThis
->update_store();
917 gtk_widget_grab_focus(pThis
->widget
);
918 if (atoi(path
) < (int)pThis
->teif
->get_table_rows(pThis
->param_no
))
920 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
921 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
922 gtk_tree_path_free (gpath
);
927 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
928 "%s", error
.c_str());
929 gtk_dialog_run(GTK_DIALOG(dialog
));
930 gtk_widget_destroy(dialog
);
931 gtk_widget_grab_focus(pThis
->widget
);
935 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
937 gtk_widget_grab_focus(pThis
->widget
);
940 /******************************** GtkTable container ********************************/
942 GtkWidget
*table_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
944 require_int_attribute("rows");
945 require_int_attribute("cols");
946 int homog
= get_int("homogeneous", 0);
947 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
949 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
951 container
= GTK_CONTAINER(table
);
952 gtk_widget_set_name(GTK_WIDGET(table
), "Calf-Table");
956 void table_container::add(GtkWidget
*widget
, control_base
*base
)
958 base
->require_int_attribute("attach-x");
959 base
->require_int_attribute("attach-y");
960 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
961 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
962 int shrinkx
= base
->get_int("shrink-x", 0);
963 int shrinky
= base
->get_int("shrink-y", 0);
964 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
965 int filly
= (base
->get_int("fill-y", !shrinky
) ? GTK_FILL
: 0) | (base
->get_int("expand-y", !shrinky
) ? GTK_EXPAND
: 0) | (base
->get_int("shrink-y", 0) ? GTK_SHRINK
: 0);
966 int padx
= base
->get_int("pad-x", 2);
967 int pady
= base
->get_int("pad-y", 2);
968 gtk_table_attach(GTK_TABLE(container
), widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
971 /******************************** alignment contaner ********************************/
973 GtkWidget
*alignment_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
975 GtkWidget
*align
= gtk_alignment_new(get_float("align-x", 0.5), get_float("align-y", 0.5), get_float("scale-x", 0), get_float("scale-y", 0));
976 container
= GTK_CONTAINER(align
);
977 gtk_widget_set_name(GTK_WIDGET(align
), "Calf-Align");
981 /******************************** GtkFrame contaner ********************************/
983 GtkWidget
*frame_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
985 GtkWidget
*frame
= gtk_frame_new(attribs
["label"].c_str());
986 container
= GTK_CONTAINER(frame
);
987 gtk_widget_set_name(GTK_WIDGET(frame
), "Calf-Frame");
991 /******************************** GtkBox type of containers ********************************/
993 void box_container::add(GtkWidget
*w
, control_base
*base
)
995 gtk_container_add_with_properties(container
, w
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
998 /******************************** GtkHBox container ********************************/
1000 GtkWidget
*hbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1002 GtkWidget
*hbox
= gtk_hbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1003 container
= GTK_CONTAINER(hbox
);
1004 gtk_widget_set_name(GTK_WIDGET(hbox
), "Calf-HBox");
1008 /******************************** GtkVBox container ********************************/
1010 GtkWidget
*vbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1012 GtkWidget
*vbox
= gtk_vbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1013 container
= GTK_CONTAINER(vbox
);
1014 gtk_widget_set_name(GTK_WIDGET(vbox
), "Calf-VBox");
1018 /******************************** GtkNotebook container ********************************/
1020 GtkWidget
*notebook_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1022 GtkWidget
*nb
= gtk_notebook_new();
1023 container
= GTK_CONTAINER(nb
);
1024 gtk_widget_set_name(GTK_WIDGET(nb
), "Calf-Notebook");
1028 void notebook_container::add(GtkWidget
*w
, control_base
*base
)
1030 gtk_notebook_append_page(GTK_NOTEBOOK(container
), w
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1033 /******************************** GtkNotebook container ********************************/
1035 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1037 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1038 int width
= get_int("width", 0), height
= get_int("height", 0);
1040 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1042 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1043 GtkWidget
*sw
= gtk_scrolled_window_new(horiz
, vert
);
1044 gtk_widget_set_size_request(sw
, get_int("req-x", -1), get_int("req-y", -1));
1045 container
= GTK_CONTAINER(sw
);
1046 gtk_widget_set_name(GTK_WIDGET(sw
), "Calf-ScrolledWindow");
1050 void scrolled_container::add(GtkWidget
*w
, control_base
*base
)
1052 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container
), w
);