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);
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);
152 gtk_widget_set_size_request (widget
, 200, -1);
157 void hscale_param_control::init_xml(const char *element
)
159 if (attribs
.count("width"))
160 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
161 if (attribs
.count("position"))
163 string v
= attribs
["position"];
164 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
165 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
169 void hscale_param_control::set()
172 parameter_properties
&props
= get_props();
173 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
174 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
177 void hscale_param_control::get()
179 parameter_properties
&props
= get_props();
180 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
181 gui
->set_param_value(param_no
, cvalue
, this);
184 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
186 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
190 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
192 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
193 const parameter_properties
&props
= jhp
->get_props();
194 float cvalue
= props
.from_01 (arg1
);
197 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
198 return g_strdup (props
.to_string (cvalue
).c_str());
203 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
206 param_no
= _param_no
;
208 widget
= gtk_vscale_new_with_range (0, 1, get_props().get_increment());
209 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
210 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
211 gtk_widget_set_size_request (widget
, -1, 200);
216 void vscale_param_control::init_xml(const char *element
)
218 if (attribs
.count("height"))
219 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
222 void vscale_param_control::set()
225 parameter_properties
&props
= get_props();
226 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
227 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
230 void vscale_param_control::get()
232 parameter_properties
&props
= get_props();
233 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
234 gui
->set_param_value(param_no
, cvalue
, this);
237 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
239 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
245 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
247 gui
= _gui
, param_no
= _param_no
;
250 text
= get_props().name
;
252 text
= attribs
["text"];
253 widget
= gtk_label_new(text
.c_str());
254 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
260 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
263 param_no
= _param_no
;
265 widget
= gtk_label_new ("");
268 parameter_properties
&props
= get_props();
269 gtk_label_set_width_chars (GTK_LABEL (widget
), props
.get_char_count());
273 require_attribute("key");
274 require_int_attribute("width");
275 param_variable
= attribs
["key"];
276 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
278 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
282 void value_param_control::set()
287 parameter_properties
&props
= get_props();
288 gtk_label_set_text (GTK_LABEL (widget
), props
.to_string(gui
->plugin
->get_param_value(param_no
)).c_str());
291 void value_param_control::send_status(const char *key
, const char *value
)
293 if (key
== param_variable
)
295 gtk_label_set_text (GTK_LABEL (widget
), value
);
301 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
303 gui
= _gui
, param_no
= _param_no
;
304 // parameter_properties &props = get_props();
305 widget
= calf_vumeter_new ();
306 calf_vumeter_set_mode (CALF_VUMETER (widget
), (CalfVUMeterMode
)get_int("mode", 0));
310 void vumeter_param_control::set()
313 parameter_properties
&props
= get_props();
314 calf_vumeter_set_value (CALF_VUMETER (widget
), props
.to_01(gui
->plugin
->get_param_value(param_no
)));
321 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
323 gui
= _gui
, param_no
= _param_no
;
324 // parameter_properties &props = get_props();
325 widget
= calf_led_new ();
329 void led_param_control::set()
332 // parameter_properties &props = get_props();
333 calf_led_set_state (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
) > 0);
340 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
343 param_no
= _param_no
;
345 widget
= gtk_check_button_new ();
346 gtk_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
350 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
352 param_control
*jhp
= (param_control
*)value
;
356 void check_param_control::get()
358 const parameter_properties
&props
= get_props();
359 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
362 void check_param_control::set()
365 const parameter_properties
&props
= get_props();
366 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
371 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
374 param_no
= _param_no
;
376 const parameter_properties
&props
= get_props();
378 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
380 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
382 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
383 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
384 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
388 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
390 param_control
*jhp
= (param_control
*)value
;
394 void spin_param_control::get()
396 // const parameter_properties &props = get_props();
397 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
400 void spin_param_control::set()
403 // const parameter_properties &props = get_props();
404 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
409 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
412 param_no
= _param_no
;
414 widget
= gtk_button_new_with_label (get_props().name
);
415 gtk_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (button_clicked
), (gpointer
)this);
419 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
421 param_control
*jhp
= (param_control
*)value
;
426 void button_param_control::get()
428 const parameter_properties
&props
= get_props();
429 gui
->set_param_value(param_no
, props
.max
, this);
432 void button_param_control::set()
435 const parameter_properties
&props
= get_props();
436 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
437 gtk_button_clicked (GTK_BUTTON (widget
));
442 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
445 param_no
= _param_no
;
446 const parameter_properties
&props
= get_props();
448 //widget = calf_knob_new_with_range (props.to_01 (gui->plugin->get_param_value(param_no)), 0, 1, 0.01);
449 widget
= calf_knob_new();
450 float increment
= props
.get_increment();
451 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
452 CALF_KNOB(widget
)->knob_type
= get_int("type");
453 CALF_KNOB(widget
)->knob_size
= get_int("size", 2);
454 if(CALF_KNOB(widget
)->knob_size
> 4) {
455 CALF_KNOB(widget
)->knob_size
= 4;
456 } else if (CALF_KNOB(widget
)->knob_size
< 1) {
457 CALF_KNOB(widget
)->knob_size
= 1;
459 gtk_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
463 void knob_param_control::get()
465 const parameter_properties
&props
= get_props();
466 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
467 gui
->set_param_value(param_no
, value
, this);
472 void knob_param_control::set()
475 const parameter_properties
&props
= get_props();
476 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
481 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
483 param_control
*jhp
= (param_control
*)value
;
489 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
492 param_no
= _param_no
;
493 widget
= calf_toggle_new ();
495 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
496 if(CALF_TOGGLE(widget
)->size
> 2) {
497 CALF_TOGGLE(widget
)->size
= 2;
498 } else if (CALF_TOGGLE(widget
)->size
< 1) {
499 CALF_TOGGLE(widget
)->size
= 1;
502 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
506 void toggle_param_control::get()
508 const parameter_properties
&props
= get_props();
509 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
510 gui
->set_param_value(param_no
, value
, this);
515 void toggle_param_control::set()
518 const parameter_properties
&props
= get_props();
519 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
524 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
526 param_control
*jhp
= (param_control
*)value
;
532 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
535 param_no
= _param_no
;
536 // const parameter_properties &props = get_props();
538 widget
= calf_keyboard_new();
539 kb
= CALF_KEYBOARD(widget
);
540 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
541 kb
->sink
= new CalfKeyboard::EventAdapter
;
547 struct curve_param_control_callback
: public CalfCurve::EventAdapter
549 curve_param_control
*ctl
;
551 curve_param_control_callback(curve_param_control
*_ctl
)
554 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
556 ss
<< data
.size() << endl
;
557 for (size_t i
= 0; i
< data
.size(); i
++)
558 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
559 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
561 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
563 // int gridpt = floor(x * 71 * 2);
564 // clip to the middle of the nearest white key
565 x
= (floor(x
* 71) + 0.5)/ 71.0;
569 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
572 param_no
= _param_no
;
573 require_attribute("key");
575 widget
= calf_curve_new(get_int("maxpoints", -1));
576 curve
= CALF_CURVE(widget
);
577 curve
->sink
= new curve_param_control_callback(this);
578 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
582 void curve_param_control::send_configure(const char *key
, const char *value
)
584 // cout << "send conf " << key << endl;
585 if (attribs
["key"] == key
)
587 stringstream
ss(value
);
588 CalfCurve::point_vector pts
;
591 unsigned int npoints
= 0;
595 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
598 pts
.push_back(CalfCurve::point(x
, y
));
600 calf_curve_set_points(widget
, pts
);
607 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
610 param_no
= _param_no
;
611 require_attribute("key");
613 widget
= gtk_entry_new();
614 entry
= GTK_ENTRY(widget
);
615 gtk_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
616 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
620 void entry_param_control::send_configure(const char *key
, const char *value
)
622 // cout << "send conf " << key << endl;
623 if (attribs
["key"] == key
)
625 gtk_entry_set_text(entry
, value
);
629 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
631 entry_param_control
*ctl
= (entry_param_control
*)value
;
632 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
637 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
640 param_no
= _param_no
;
641 require_attribute("key");
642 require_attribute("title");
644 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
645 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
646 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
647 gtk_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
648 if (attribs
.count("width"))
649 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
650 if (attribs
.count("width_chars"))
651 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
655 void filechooser_param_control::send_configure(const char *key
, const char *value
)
657 // cout << "send conf " << key << endl;
658 if (attribs
["key"] == key
)
660 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
664 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
666 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
667 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
669 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
674 void line_graph_param_control::on_idle()
676 if (get_int("refresh", 0))
680 GtkWidget
*line_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
683 param_no
= _param_no
;
684 last_generation
= -1;
685 // const parameter_properties &props = get_props();
687 widget
= calf_line_graph_new ();
688 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
689 widget
->requisition
.width
= get_int("width", 40);
690 widget
->requisition
.height
= get_int("height", 40);
691 calf_line_graph_set_square(clg
, get_int("square", 0));
692 clg
->source
= gui
->plugin
->get_line_graph_iface();
693 clg
->source_id
= param_no
;
698 void line_graph_param_control::set()
700 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
701 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
703 int ws
= gdk_window_get_state(widget
->window
);
704 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
706 last_generation
= calf_line_graph_update_if(CALF_LINE_GRAPH(widget
), last_generation
);
710 line_graph_param_control::~line_graph_param_control()
716 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
719 param_no
= _param_no
;
721 teif
= gui
->plugin
->get_table_edit_iface();
722 const table_column_info
*tci
= teif
->get_table_columns(param_no
);
725 while (tci
[cols
].name
!= NULL
)
728 GType
*p
= new GType
[cols
];
729 for (int i
= 0; i
< cols
; i
++)
730 p
[i
] = G_TYPE_STRING
;
731 lstore
= gtk_list_store_newv(cols
, p
);
733 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
735 tree
= GTK_TREE_VIEW (widget
);
737 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
739 for (int i
= 0; i
< cols
; i
++)
741 GtkCellRenderer
*cr
= NULL
;
743 if (tci
[i
].type
== TCT_ENUM
) {
744 cr
= gtk_cell_renderer_combo_new ();
745 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
746 for (int j
= 0; tci
[i
].values
[j
]; j
++)
747 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
748 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
751 bool editable
= tci
[i
].type
!= TCT_LABEL
;
752 cr
= gtk_cell_renderer_text_new ();
754 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
756 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
757 gtk_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
758 gtk_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
759 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
761 gtk_tree_view_set_headers_visible(tree
, TRUE
);
766 void listview_param_control::update_store()
768 gtk_list_store_clear(lstore
);
769 uint32_t rows
= teif
->get_table_rows(param_no
);
770 for (uint32_t i
= 0; i
< rows
; i
++)
773 gtk_list_store_insert(lstore
, &iter
, i
);
774 for (int j
= 0; j
< cols
; j
++)
776 gtk_list_store_set(lstore
, &iter
, j
, teif
->get_cell(param_no
, i
, j
).c_str(), -1);
778 positions
.push_back(iter
);
782 void listview_param_control::send_configure(const char *key
, const char *value
)
784 if (attribs
["key"] == key
)
790 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
792 const table_column_info
*tci
= pThis
->teif
->get_table_columns(pThis
->param_no
);
793 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
795 pThis
->teif
->set_cell(pThis
->param_no
, atoi(path
), column
, new_text
, error
);
797 pThis
->update_store();
798 gtk_widget_grab_focus(pThis
->widget
);
799 if (atoi(path
) < (int)pThis
->teif
->get_table_rows(pThis
->param_no
))
801 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
802 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
803 gtk_tree_path_free (gpath
);
808 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
809 "%s", error
.c_str());
810 gtk_dialog_run(GTK_DIALOG(dialog
));
811 gtk_widget_destroy(dialog
);
812 gtk_widget_grab_focus(pThis
->widget
);
816 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
818 gtk_widget_grab_focus(pThis
->widget
);
821 /******************************** GtkTable container ********************************/
823 GtkWidget
*table_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
825 require_int_attribute("rows");
826 require_int_attribute("cols");
827 int homog
= get_int("homogeneous", 0);
828 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
830 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
832 container
= GTK_CONTAINER(table
);
836 void table_container::add(GtkWidget
*widget
, control_base
*base
)
838 base
->require_int_attribute("attach-x");
839 base
->require_int_attribute("attach-y");
840 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
841 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
842 int shrinkx
= base
->get_int("shrink-x", 0);
843 int shrinky
= base
->get_int("shrink-y", 0);
844 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
845 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);
846 int padx
= base
->get_int("pad-x", 2);
847 int pady
= base
->get_int("pad-y", 2);
848 gtk_table_attach(GTK_TABLE(container
), widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
851 /******************************** alignment contaner ********************************/
853 GtkWidget
*alignment_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
855 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));
856 container
= GTK_CONTAINER(align
);
860 /******************************** GtkFrame contaner ********************************/
862 GtkWidget
*frame_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
864 GtkWidget
*frame
= gtk_frame_new(attribs
["label"].c_str());
865 container
= GTK_CONTAINER(frame
);
869 /******************************** GtkBox type of containers ********************************/
871 void box_container::add(GtkWidget
*w
, control_base
*base
)
873 gtk_container_add_with_properties(container
, w
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
876 /******************************** GtkHBox container ********************************/
878 GtkWidget
*hbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
880 GtkWidget
*hbox
= gtk_hbox_new(false, get_int("spacing", 2));
881 container
= GTK_CONTAINER(hbox
);
885 /******************************** GtkVBox container ********************************/
887 GtkWidget
*vbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
889 GtkWidget
*vbox
= gtk_vbox_new(false, get_int("spacing", 2));
890 container
= GTK_CONTAINER(vbox
);
894 /******************************** GtkNotebook container ********************************/
896 GtkWidget
*notebook_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
898 GtkWidget
*nb
= gtk_notebook_new();
899 container
= GTK_CONTAINER(nb
);
903 void notebook_container::add(GtkWidget
*w
, control_base
*base
)
905 gtk_notebook_append_page(GTK_NOTEBOOK(container
), w
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
908 /******************************** GtkNotebook container ********************************/
910 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
912 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
913 int width
= get_int("width", 0), height
= get_int("height", 0);
915 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
917 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
918 GtkWidget
*sw
= gtk_scrolled_window_new(horiz
, vert
);
919 gtk_widget_set_size_request(sw
, get_int("req-x", -1), get_int("req-y", -1));
920 container
= GTK_CONTAINER(sw
);
924 void scrolled_container::add(GtkWidget
*w
, control_base
*base
)
926 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container
), w
);