2 * GUI functions for a plugin.
3 * Copyright (C) 2007 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/preset.h>
29 #include <calf/preset_gui.h>
30 #include <calf/main_win.h>
35 using namespace calf_plugins
;
38 /******************************** controls ********************************/
40 GtkWidget
*param_control::create_label()
42 label
= gtk_label_new ("");
43 gtk_label_set_width_chars (GTK_LABEL (label
), 12);
44 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
48 void param_control::update_label()
50 parameter_properties
&props
= get_props();
51 gtk_label_set_text (GTK_LABEL (label
), props
.to_string(gui
->plugin
->get_param_value(param_no
)).c_str());
54 void param_control::hook_params()
57 gui
->add_param_ctl(param_no
, this);
59 gui
->params
.push_back(this);
62 param_control::~param_control()
65 gtk_widget_destroy(label
);
67 gtk_widget_destroy(widget
);
72 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
76 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
78 parameter_properties
&props
= get_props();
79 widget
= gtk_combo_box_new_text ();
82 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
83 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);
85 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
86 gtk_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
91 void combo_box_param_control::set()
94 parameter_properties
&props
= get_props();
95 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
98 void combo_box_param_control::get()
100 parameter_properties
&props
= get_props();
101 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
104 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
106 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
107 if (jhp
->attribs
.count("setter-key"))
111 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
113 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
115 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
124 void combo_box_param_control::send_status(const char *key
, const char *value
)
126 if (attribs
.count("key") && key
== attribs
["key"])
128 gtk_list_store_clear (lstore
);
130 std::string v
= value
;
133 while (pos
< v
.length()) {
134 size_t endpos
= v
.find("\n", pos
);
135 if (endpos
== string::npos
)
137 string line
= v
.substr(pos
, endpos
- pos
);
139 size_t tabpos
= line
.find('\t');
140 if (tabpos
== string::npos
)
143 key
= line
.substr(0, tabpos
);
144 label
= line
.substr(tabpos
+ 1);
147 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
154 if (attribs
.count("current-key") && key
== attribs
["current-key"])
161 void combo_box_param_control::set_to_last_key()
163 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
164 if (i
!= key2pos
.end())
166 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
170 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
175 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
178 param_no
= _param_no
;
180 widget
= gtk_hscale_new_with_range (0, 1, get_props().get_increment());
181 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
182 gtk_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
183 gtk_widget_set_size_request (widget
, 200, -1);
188 void hscale_param_control::init_xml(const char *element
)
190 if (attribs
.count("width"))
191 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
192 if (attribs
.count("position"))
194 string v
= attribs
["position"];
195 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
196 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
200 void hscale_param_control::set()
203 parameter_properties
&props
= get_props();
204 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
205 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
208 void hscale_param_control::get()
210 parameter_properties
&props
= get_props();
211 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
212 gui
->set_param_value(param_no
, cvalue
, this);
215 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
217 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
221 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
223 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
224 const parameter_properties
&props
= jhp
->get_props();
225 float cvalue
= props
.from_01 (arg1
);
228 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
229 return g_strdup (props
.to_string (cvalue
).c_str());
234 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
237 param_no
= _param_no
;
239 widget
= gtk_vscale_new_with_range (0, 1, get_props().get_increment());
240 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
241 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
242 gtk_widget_set_size_request (widget
, -1, 200);
247 void vscale_param_control::init_xml(const char *element
)
249 if (attribs
.count("height"))
250 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
253 void vscale_param_control::set()
256 parameter_properties
&props
= get_props();
257 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
258 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
261 void vscale_param_control::get()
263 parameter_properties
&props
= get_props();
264 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
265 gui
->set_param_value(param_no
, cvalue
, this);
268 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
270 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
276 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
278 gui
= _gui
, param_no
= _param_no
;
281 text
= get_props().name
;
283 text
= attribs
["text"];
284 widget
= gtk_label_new(text
.c_str());
285 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
291 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
294 param_no
= _param_no
;
296 widget
= gtk_label_new ("");
299 parameter_properties
&props
= get_props();
300 gtk_label_set_width_chars (GTK_LABEL (widget
), props
.get_char_count());
304 require_attribute("key");
305 require_int_attribute("width");
306 param_variable
= attribs
["key"];
307 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
309 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
313 void value_param_control::set()
318 parameter_properties
&props
= get_props();
319 gtk_label_set_text (GTK_LABEL (widget
), props
.to_string(gui
->plugin
->get_param_value(param_no
)).c_str());
322 void value_param_control::send_status(const char *key
, const char *value
)
324 if (key
== param_variable
)
326 gtk_label_set_text (GTK_LABEL (widget
), value
);
332 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
334 gui
= _gui
, param_no
= _param_no
;
335 // parameter_properties &props = get_props();
336 widget
= calf_vumeter_new ();
337 calf_vumeter_set_mode (CALF_VUMETER (widget
), (CalfVUMeterMode
)get_int("mode", 0));
341 void vumeter_param_control::set()
344 parameter_properties
&props
= get_props();
345 calf_vumeter_set_value (CALF_VUMETER (widget
), props
.to_01(gui
->plugin
->get_param_value(param_no
)));
352 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
354 gui
= _gui
, param_no
= _param_no
;
355 // parameter_properties &props = get_props();
356 widget
= calf_led_new ();
360 void led_param_control::set()
363 // parameter_properties &props = get_props();
364 calf_led_set_state (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
) > 0);
371 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
374 param_no
= _param_no
;
376 widget
= gtk_check_button_new ();
377 gtk_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
381 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
383 param_control
*jhp
= (param_control
*)value
;
387 void check_param_control::get()
389 const parameter_properties
&props
= get_props();
390 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
393 void check_param_control::set()
396 const parameter_properties
&props
= get_props();
397 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
402 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
405 param_no
= _param_no
;
407 const parameter_properties
&props
= get_props();
409 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
411 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
413 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
414 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
415 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
419 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
421 param_control
*jhp
= (param_control
*)value
;
425 void spin_param_control::get()
427 // const parameter_properties &props = get_props();
428 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
431 void spin_param_control::set()
434 // const parameter_properties &props = get_props();
435 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
440 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
443 param_no
= _param_no
;
445 widget
= gtk_button_new_with_label (get_props().name
);
446 gtk_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (button_clicked
), (gpointer
)this);
450 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
452 param_control
*jhp
= (param_control
*)value
;
457 void button_param_control::get()
459 const parameter_properties
&props
= get_props();
460 gui
->set_param_value(param_no
, props
.max
, this);
463 void button_param_control::set()
466 const parameter_properties
&props
= get_props();
467 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
468 gtk_button_clicked (GTK_BUTTON (widget
));
473 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
476 param_no
= _param_no
;
477 const parameter_properties
&props
= get_props();
479 //widget = calf_knob_new_with_range (props.to_01 (gui->plugin->get_param_value(param_no)), 0, 1, 0.01);
480 widget
= calf_knob_new();
481 float increment
= props
.get_increment();
482 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
483 CALF_KNOB(widget
)->knob_type
= get_int("type");
484 CALF_KNOB(widget
)->knob_size
= get_int("size", 2);
485 if(CALF_KNOB(widget
)->knob_size
> 4) {
486 CALF_KNOB(widget
)->knob_size
= 4;
487 } else if (CALF_KNOB(widget
)->knob_size
< 1) {
488 CALF_KNOB(widget
)->knob_size
= 1;
490 gtk_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
494 void knob_param_control::get()
496 const parameter_properties
&props
= get_props();
497 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
498 gui
->set_param_value(param_no
, value
, this);
503 void knob_param_control::set()
506 const parameter_properties
&props
= get_props();
507 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
512 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
514 param_control
*jhp
= (param_control
*)value
;
520 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
523 param_no
= _param_no
;
524 widget
= calf_toggle_new ();
526 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
527 if(CALF_TOGGLE(widget
)->size
> 2) {
528 CALF_TOGGLE(widget
)->size
= 2;
529 } else if (CALF_TOGGLE(widget
)->size
< 1) {
530 CALF_TOGGLE(widget
)->size
= 1;
533 gtk_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
537 void toggle_param_control::get()
539 const parameter_properties
&props
= get_props();
540 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
541 gui
->set_param_value(param_no
, value
, this);
546 void toggle_param_control::set()
549 const parameter_properties
&props
= get_props();
550 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
555 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
557 param_control
*jhp
= (param_control
*)value
;
563 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
566 param_no
= _param_no
;
567 // const parameter_properties &props = get_props();
569 widget
= calf_keyboard_new();
570 kb
= CALF_KEYBOARD(widget
);
571 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
572 kb
->sink
= new CalfKeyboard::EventAdapter
;
578 struct curve_param_control_callback
: public CalfCurve::EventAdapter
580 curve_param_control
*ctl
;
582 curve_param_control_callback(curve_param_control
*_ctl
)
585 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
587 ss
<< data
.size() << endl
;
588 for (size_t i
= 0; i
< data
.size(); i
++)
589 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
590 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
592 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
594 // int gridpt = floor(x * 71 * 2);
595 // clip to the middle of the nearest white key
596 x
= (floor(x
* 71) + 0.5)/ 71.0;
600 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
603 param_no
= _param_no
;
604 require_attribute("key");
606 widget
= calf_curve_new(get_int("maxpoints", -1));
607 curve
= CALF_CURVE(widget
);
608 curve
->sink
= new curve_param_control_callback(this);
609 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
613 void curve_param_control::send_configure(const char *key
, const char *value
)
615 // cout << "send conf " << key << endl;
616 if (attribs
["key"] == key
)
618 stringstream
ss(value
);
619 CalfCurve::point_vector pts
;
622 unsigned int npoints
= 0;
626 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
629 pts
.push_back(CalfCurve::point(x
, y
));
631 calf_curve_set_points(widget
, pts
);
638 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
641 param_no
= _param_no
;
642 require_attribute("key");
644 widget
= gtk_entry_new();
645 entry
= GTK_ENTRY(widget
);
646 gtk_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
647 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
651 void entry_param_control::send_configure(const char *key
, const char *value
)
653 // cout << "send conf " << key << endl;
654 if (attribs
["key"] == key
)
656 gtk_entry_set_text(entry
, value
);
660 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
662 entry_param_control
*ctl
= (entry_param_control
*)value
;
663 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
668 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
671 param_no
= _param_no
;
672 require_attribute("key");
673 require_attribute("title");
675 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
676 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
677 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
678 gtk_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
679 if (attribs
.count("width"))
680 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
681 if (attribs
.count("width_chars"))
682 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
686 void filechooser_param_control::send_configure(const char *key
, const char *value
)
688 // cout << "send conf " << key << endl;
689 if (attribs
["key"] == key
)
691 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
695 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
697 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
698 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
700 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
705 void line_graph_param_control::on_idle()
707 if (get_int("refresh", 0))
711 GtkWidget
*line_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
714 param_no
= _param_no
;
715 last_generation
= -1;
716 // const parameter_properties &props = get_props();
718 widget
= calf_line_graph_new ();
719 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
720 widget
->requisition
.width
= get_int("width", 40);
721 widget
->requisition
.height
= get_int("height", 40);
722 calf_line_graph_set_square(clg
, get_int("square", 0));
723 clg
->source
= gui
->plugin
->get_line_graph_iface();
724 clg
->source_id
= param_no
;
729 void line_graph_param_control::set()
731 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
732 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
734 int ws
= gdk_window_get_state(widget
->window
);
735 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
737 last_generation
= calf_line_graph_update_if(CALF_LINE_GRAPH(widget
), last_generation
);
741 line_graph_param_control::~line_graph_param_control()
747 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
750 param_no
= _param_no
;
752 teif
= gui
->plugin
->get_table_edit_iface();
753 const table_column_info
*tci
= teif
->get_table_columns(param_no
);
756 while (tci
[cols
].name
!= NULL
)
759 GType
*p
= new GType
[cols
];
760 for (int i
= 0; i
< cols
; i
++)
761 p
[i
] = G_TYPE_STRING
;
762 lstore
= gtk_list_store_newv(cols
, p
);
764 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
766 tree
= GTK_TREE_VIEW (widget
);
768 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
770 for (int i
= 0; i
< cols
; i
++)
772 GtkCellRenderer
*cr
= NULL
;
774 if (tci
[i
].type
== TCT_ENUM
) {
775 cr
= gtk_cell_renderer_combo_new ();
776 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
777 for (int j
= 0; tci
[i
].values
[j
]; j
++)
778 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
779 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
782 bool editable
= tci
[i
].type
!= TCT_LABEL
;
783 cr
= gtk_cell_renderer_text_new ();
785 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
787 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
788 gtk_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
789 gtk_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
790 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
792 gtk_tree_view_set_headers_visible(tree
, TRUE
);
797 void listview_param_control::update_store()
799 gtk_list_store_clear(lstore
);
800 uint32_t rows
= teif
->get_table_rows(param_no
);
801 for (uint32_t i
= 0; i
< rows
; i
++)
804 gtk_list_store_insert(lstore
, &iter
, i
);
805 for (int j
= 0; j
< cols
; j
++)
807 gtk_list_store_set(lstore
, &iter
, j
, teif
->get_cell(param_no
, i
, j
).c_str(), -1);
809 positions
.push_back(iter
);
813 void listview_param_control::send_configure(const char *key
, const char *value
)
815 if (attribs
["key"] == key
)
821 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
823 const table_column_info
*tci
= pThis
->teif
->get_table_columns(pThis
->param_no
);
824 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
826 pThis
->teif
->set_cell(pThis
->param_no
, atoi(path
), column
, new_text
, error
);
828 pThis
->update_store();
829 gtk_widget_grab_focus(pThis
->widget
);
830 if (atoi(path
) < (int)pThis
->teif
->get_table_rows(pThis
->param_no
))
832 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
833 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
834 gtk_tree_path_free (gpath
);
839 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
840 "%s", error
.c_str());
841 gtk_dialog_run(GTK_DIALOG(dialog
));
842 gtk_widget_destroy(dialog
);
843 gtk_widget_grab_focus(pThis
->widget
);
847 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
849 gtk_widget_grab_focus(pThis
->widget
);
852 /******************************** GUI proper ********************************/
854 plugin_gui::plugin_gui(plugin_gui_window
*_window
)
855 : last_status_serial_no(0)
859 top_container
= NULL
;
860 current_control
= NULL
;
866 static void window_destroyed(GtkWidget
*window
, gpointer data
)
868 delete (plugin_gui_window
*)data
;
871 static void action_destroy_notify(gpointer data
)
873 delete (activate_preset_params
*)data
;
876 void control_base::require_attribute(const char *name
)
878 if (attribs
.count(name
) == 0) {
879 g_error("Missing attribute: %s", name
);
883 void control_base::require_int_attribute(const char *name
)
885 if (attribs
.count(name
) == 0) {
886 g_error("Missing attribute: %s", name
);
888 if (attribs
[name
].empty() || attribs
[name
].find_first_not_of("0123456789") != string::npos
) {
889 g_error("Wrong data type on attribute: %s (required integer)", name
);
893 int control_base::get_int(const char *name
, int def_value
)
895 if (attribs
.count(name
) == 0)
897 const std::string
&v
= attribs
[name
];
898 if (v
.empty() || v
.find_first_not_of("-+0123456789") != string::npos
)
900 return atoi(v
.c_str());
903 float control_base::get_float(const char *name
, float def_value
)
905 if (attribs
.count(name
) == 0)
907 const std::string
&v
= attribs
[name
];
908 if (v
.empty() || v
.find_first_not_of("-+0123456789.") != string::npos
)
916 /******************************** GtkTable container ********************************/
918 GtkWidget
*table_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
920 require_int_attribute("rows");
921 require_int_attribute("cols");
922 int homog
= get_int("homogeneous", 0);
923 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
925 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
927 container
= GTK_CONTAINER(table
);
931 void table_container::add(GtkWidget
*widget
, control_base
*base
)
933 base
->require_int_attribute("attach-x");
934 base
->require_int_attribute("attach-y");
935 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
936 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
937 int shrinkx
= base
->get_int("shrink-x", 0);
938 int shrinky
= base
->get_int("shrink-y", 0);
939 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
940 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);
941 int padx
= base
->get_int("pad-x", 2);
942 int pady
= base
->get_int("pad-y", 2);
943 gtk_table_attach(GTK_TABLE(container
), widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
946 /******************************** alignment contaner ********************************/
948 GtkWidget
*alignment_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
950 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));
951 container
= GTK_CONTAINER(align
);
955 /******************************** GtkFrame contaner ********************************/
957 GtkWidget
*frame_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
959 GtkWidget
*frame
= gtk_frame_new(attribs
["label"].c_str());
960 container
= GTK_CONTAINER(frame
);
964 /******************************** GtkBox type of containers ********************************/
966 void box_container::add(GtkWidget
*w
, control_base
*base
)
968 gtk_container_add_with_properties(container
, w
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
971 /******************************** GtkHBox container ********************************/
973 GtkWidget
*hbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
975 GtkWidget
*hbox
= gtk_hbox_new(false, get_int("spacing", 2));
976 container
= GTK_CONTAINER(hbox
);
980 /******************************** GtkVBox container ********************************/
982 GtkWidget
*vbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
984 GtkWidget
*vbox
= gtk_vbox_new(false, get_int("spacing", 2));
985 container
= GTK_CONTAINER(vbox
);
989 /******************************** GtkNotebook container ********************************/
991 GtkWidget
*notebook_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
993 GtkWidget
*nb
= gtk_notebook_new();
994 container
= GTK_CONTAINER(nb
);
998 void notebook_container::add(GtkWidget
*w
, control_base
*base
)
1000 gtk_notebook_append_page(GTK_NOTEBOOK(container
), w
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1003 /******************************** GtkNotebook container ********************************/
1005 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1007 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1008 int width
= get_int("width", 0), height
= get_int("height", 0);
1010 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1012 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1013 GtkWidget
*sw
= gtk_scrolled_window_new(horiz
, vert
);
1014 gtk_widget_set_size_request(sw
, get_int("req-x", -1), get_int("req-y", -1));
1015 container
= GTK_CONTAINER(sw
);
1019 void scrolled_container::add(GtkWidget
*w
, control_base
*base
)
1021 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container
), w
);
1024 /******************************** GUI proper ********************************/
1026 param_control
*plugin_gui::create_control_from_xml(const char *element
, const char *attributes
[])
1028 if (!strcmp(element
, "knob"))
1029 return new knob_param_control
;
1030 if (!strcmp(element
, "hscale"))
1031 return new hscale_param_control
;
1032 if (!strcmp(element
, "vscale"))
1033 return new vscale_param_control
;
1034 if (!strcmp(element
, "combo"))
1035 return new combo_box_param_control
;
1036 if (!strcmp(element
, "check"))
1037 return new check_param_control
;
1038 if (!strcmp(element
, "toggle"))
1039 return new toggle_param_control
;
1040 if (!strcmp(element
, "spin"))
1041 return new spin_param_control
;
1042 if (!strcmp(element
, "button"))
1043 return new button_param_control
;
1044 if (!strcmp(element
, "label"))
1045 return new label_param_control
;
1046 if (!strcmp(element
, "value"))
1047 return new value_param_control
;
1048 if (!strcmp(element
, "vumeter"))
1049 return new vumeter_param_control
;
1050 if (!strcmp(element
, "line-graph"))
1051 return new line_graph_param_control
;
1052 if (!strcmp(element
, "keyboard"))
1053 return new keyboard_param_control
;
1054 if (!strcmp(element
, "curve"))
1055 return new curve_param_control
;
1056 if (!strcmp(element
, "led"))
1057 return new led_param_control
;
1058 if (!strcmp(element
, "entry"))
1059 return new entry_param_control
;
1060 if (!strcmp(element
, "filechooser"))
1061 return new filechooser_param_control
;
1062 if (!strcmp(element
, "listview"))
1063 return new listview_param_control
;
1067 control_container
*plugin_gui::create_container_from_xml(const char *element
, const char *attributes
[])
1069 if (!strcmp(element
, "table"))
1070 return new table_container
;
1071 if (!strcmp(element
, "vbox"))
1072 return new vbox_container
;
1073 if (!strcmp(element
, "hbox"))
1074 return new hbox_container
;
1075 if (!strcmp(element
, "align"))
1076 return new alignment_container
;
1077 if (!strcmp(element
, "frame"))
1078 return new frame_container
;
1079 if (!strcmp(element
, "notebook"))
1080 return new notebook_container
;
1081 if (!strcmp(element
, "scrolled"))
1082 return new scrolled_container
;
1086 void plugin_gui::xml_element_start(void *data
, const char *element
, const char *attributes
[])
1088 plugin_gui
*gui
= (plugin_gui
*)data
;
1089 gui
->xml_element_start(element
, attributes
);
1092 void plugin_gui::xml_element_start(const char *element
, const char *attributes
[])
1098 control_base::xml_attribute_map xam
;
1101 xam
[attributes
[0]] = attributes
[1];
1105 if (!strcmp(element
, "if"))
1107 if (!xam
.count("cond") || xam
["cond"].empty())
1109 g_error("Incorrect <if cond=\"[!]symbol\"> element");
1111 string cond
= xam
["cond"];
1113 if (cond
.substr(0, 1) == "!") {
1117 if (window
->main
->check_condition(cond
.c_str()) == state
)
1122 control_container
*cc
= create_container_from_xml(element
, attributes
);
1126 cc
->create(this, element
, xam
);
1127 gtk_container_set_border_width(cc
->container
, cc
->get_int("border"));
1129 container_stack
.push_back(cc
);
1130 current_control
= NULL
;
1133 if (!container_stack
.empty())
1135 current_control
= create_control_from_xml(element
, attributes
);
1136 if (current_control
)
1138 current_control
->attribs
= xam
;
1140 if (xam
.count("param"))
1142 map
<string
, int>::iterator it
= param_name_map
.find(xam
["param"]);
1143 if (it
== param_name_map
.end())
1144 g_error("Unknown parameter %s", xam
["param"].c_str());
1146 param_no
= it
->second
;
1149 current_control
->param_variable
= plugin
->get_param_props(param_no
)->short_name
;
1150 current_control
->create(this, param_no
);
1151 current_control
->init_xml(element
);
1152 current_control
->set();
1153 current_control
->hook_params();
1157 g_error("Unxpected element %s in GUI definition\n", element
);
1160 void plugin_gui::xml_element_end(void *data
, const char *element
)
1162 plugin_gui
*gui
= (plugin_gui
*)data
;
1163 if (gui
->ignore_stack
) {
1164 gui
->ignore_stack
--;
1167 if (!strcmp(element
, "if"))
1171 if (gui
->current_control
)
1173 (*gui
->container_stack
.rbegin())->add(gui
->current_control
->widget
, gui
->current_control
);
1174 gui
->current_control
= NULL
;
1177 unsigned int ss
= gui
->container_stack
.size();
1179 gui
->container_stack
[ss
- 2]->add(GTK_WIDGET(gui
->container_stack
[ss
- 1]->container
), gui
->container_stack
[ss
- 1]);
1182 gui
->top_container
= gui
->container_stack
[0];
1183 gui
->container_stack
.pop_back();
1187 GtkWidget
*plugin_gui::create_from_xml(plugin_ctl_iface
*_plugin
, const char *xml
)
1189 current_control
= NULL
;
1190 top_container
= NULL
;
1191 parser
= XML_ParserCreate("UTF-8");
1193 container_stack
.clear();
1196 param_name_map
.clear();
1197 int size
= plugin
->get_param_count();
1198 for (int i
= 0; i
< size
; i
++)
1199 param_name_map
[plugin
->get_param_props(i
)->short_name
] = i
;
1201 XML_SetUserData(parser
, this);
1202 XML_SetElementHandler(parser
, xml_element_start
, xml_element_end
);
1203 XML_Status status
= XML_Parse(parser
, xml
, strlen(xml
), 1);
1204 if (status
== XML_STATUS_ERROR
)
1206 g_error("Parse error: %s in XML", XML_ErrorString(XML_GetErrorCode(parser
)));
1209 XML_ParserFree(parser
);
1210 last_status_serial_no
= plugin
->send_status_updates(this, 0);
1211 return GTK_WIDGET(top_container
->container
);
1214 void plugin_gui::send_configure(const char *key
, const char *value
)
1216 // XXXKF this should really be replaced by a separate list of SCI-capable param controls
1217 for (unsigned int i
= 0; i
< params
.size(); i
++)
1219 assert(params
[i
] != NULL
);
1220 send_configure_iface
*sci
= dynamic_cast<send_configure_iface
*>(params
[i
]);
1222 sci
->send_configure(key
, value
);
1226 void plugin_gui::send_status(const char *key
, const char *value
)
1228 // XXXKF this should really be replaced by a separate list of SUI-capable param controls
1229 for (unsigned int i
= 0; i
< params
.size(); i
++)
1231 assert(params
[i
] != NULL
);
1232 send_updates_iface
*sui
= dynamic_cast<send_updates_iface
*>(params
[i
]);
1234 sui
->send_status(key
, value
);
1238 void plugin_gui::on_idle()
1240 for (unsigned int i
= 0; i
< params
.size(); i
++)
1242 if (params
[i
]->param_no
!= -1)
1244 parameter_properties
&props
= *plugin
->get_param_props(params
[i
]->param_no
);
1245 bool is_output
= (props
.flags
& PF_PROP_OUTPUT
) != 0;
1250 params
[i
]->on_idle();
1252 last_status_serial_no
= plugin
->send_status_updates(this, last_status_serial_no
);
1253 // XXXKF iterate over par2ctl, too...
1256 void plugin_gui::refresh()
1258 for (unsigned int i
= 0; i
< params
.size(); i
++)
1260 plugin
->send_configures(this);
1261 last_status_serial_no
= plugin
->send_status_updates(this, last_status_serial_no
);
1264 void plugin_gui::refresh(int param_no
, param_control
*originator
)
1266 std::multimap
<int, param_control
*>::iterator it
= par2ctl
.find(param_no
);
1267 while(it
!= par2ctl
.end() && it
->first
== param_no
)
1269 if (it
->second
!= originator
)
1275 void plugin_gui::set_param_value(int param_no
, float value
, param_control
*originator
)
1277 plugin
->set_param_value(param_no
, value
);
1281 plugin_gui::~plugin_gui()
1283 for (std::vector
<param_control
*>::iterator i
= params
.begin(); i
!= params
.end(); i
++)
1290 /******************************* Actions **************************************************/
1292 static void store_preset_action(GtkAction
*action
, plugin_gui_window
*gui_win
)
1294 store_preset(GTK_WINDOW(gui_win
->toplevel
), gui_win
->gui
);
1297 static const GtkActionEntry actions
[] = {
1298 { "PresetMenuAction", NULL
, "_Preset", NULL
, "Preset operations", NULL
},
1299 { "BuiltinPresetMenuAction", NULL
, "_Built-in", NULL
, "Built-in (factory) presets", NULL
},
1300 { "UserPresetMenuAction", NULL
, "_User", NULL
, "User (your) presets", NULL
},
1301 { "CommandMenuAction", NULL
, "_Command", NULL
, "Plugin-related commands", NULL
},
1302 { "store-preset", "gtk-save-as", "Store preset", NULL
, "Store a current setting as preset", (GCallback
)store_preset_action
},
1305 /***************************** GUI window ********************************************/
1307 static const char *ui_xml
=
1310 " <menu action=\"PresetMenuAction\">\n"
1311 " <menuitem action=\"store-preset\"/>\n"
1313 " <placeholder name=\"builtin_presets\"/>\n"
1315 " <placeholder name=\"user_presets\"/>\n"
1317 " <placeholder name=\"commands\"/>\n"
1322 static const char *general_preset_pre_xml
=
1325 " <menu action=\"PresetMenuAction\">\n";
1327 static const char *builtin_preset_pre_xml
=
1328 " <placeholder name=\"builtin_presets\">\n";
1330 static const char *user_preset_pre_xml
=
1331 " <placeholder name=\"user_presets\">\n";
1333 static const char *preset_post_xml
=
1340 static const char *command_pre_xml
=
1343 " <placeholder name=\"commands\">\n"
1344 " <menu action=\"CommandMenuAction\">\n";
1346 static const char *command_post_xml
=
1353 plugin_gui_window::plugin_gui_window(main_window_iface
*_main
)
1358 builtin_preset_actions
= NULL
;
1359 user_preset_actions
= NULL
;
1360 command_actions
= NULL
;
1365 string
plugin_gui_window::make_gui_preset_list(GtkActionGroup
*grp
, bool builtin
, char &ch
)
1367 string preset_xml
= string(general_preset_pre_xml
) + (builtin
? builtin_preset_pre_xml
: user_preset_pre_xml
);
1368 preset_vector
&pvec
= (builtin
? get_builtin_presets() : get_user_presets()).presets
;
1369 GtkActionGroup
*preset_actions
= builtin
? builtin_preset_actions
: user_preset_actions
;
1370 for (unsigned int i
= 0; i
< pvec
.size(); i
++)
1372 if (pvec
[i
].plugin
!= gui
->effect_name
)
1375 ss
<< (builtin
? "builtin_preset" : "user_preset") << i
;
1376 preset_xml
+= " <menuitem name=\"" + pvec
[i
].name
+"\" action=\""+ss
.str()+"\"/>\n";
1377 if (ch
!= ' ' && ++ch
== ':')
1382 string sv
= ss
.str();
1383 string prefix
= ch
== ' ' ? string() : string("_")+ch
+" ";
1384 string name
= prefix
+ pvec
[i
].name
;
1385 GtkActionEntry ae
= { sv
.c_str(), NULL
, name
.c_str(), NULL
, NULL
, (GCallback
)activate_preset
};
1386 gtk_action_group_add_actions_full(preset_actions
, &ae
, 1, (gpointer
)new activate_preset_params(gui
, i
, builtin
), action_destroy_notify
);
1388 preset_xml
+= preset_post_xml
;
1392 string
plugin_gui_window::make_gui_command_list(GtkActionGroup
*grp
)
1394 string command_xml
= command_pre_xml
;
1395 plugin_command_info
*ci
= gui
->plugin
->get_commands();
1398 for(int i
= 0; ci
->name
; i
++, ci
++)
1401 ss
<< " <menuitem name=\"" << ci
->name
<< "\" action=\"" << ci
->label
<< "\"/>\n";
1403 GtkActionEntry ae
= { ci
->label
, NULL
, ci
->name
, NULL
, ci
->description
, (GCallback
)activate_command
};
1404 gtk_action_group_add_actions_full(command_actions
, &ae
, 1, (gpointer
)new activate_command_params(gui
, i
), action_destroy_notify
);
1405 command_xml
+= ss
.str();
1407 command_xml
+= command_post_xml
;
1411 void plugin_gui_window::fill_gui_presets(bool builtin
, char &ch
)
1413 GtkActionGroup
*&preset_actions
= builtin
? builtin_preset_actions
: user_preset_actions
;
1414 if(preset_actions
) {
1415 gtk_ui_manager_remove_action_group(ui_mgr
, preset_actions
);
1416 preset_actions
= NULL
;
1420 builtin_preset_actions
= gtk_action_group_new("builtin_presets");
1422 user_preset_actions
= gtk_action_group_new("user_presets");
1423 string preset_xml
= make_gui_preset_list(preset_actions
, builtin
, ch
);
1424 gtk_ui_manager_insert_action_group(ui_mgr
, preset_actions
, 0);
1425 GError
*error
= NULL
;
1426 gtk_ui_manager_add_ui_from_string(ui_mgr
, preset_xml
.c_str(), -1, &error
);
1429 gboolean
plugin_gui_window::on_idle(void *data
)
1431 plugin_gui_window
*self
= (plugin_gui_window
*)data
;
1432 self
->gui
->on_idle();
1436 void plugin_gui_window::create(plugin_ctl_iface
*_jh
, const char *title
, const char *effect
)
1438 toplevel
= GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL
));
1439 gtk_window_set_default_icon_name("calf");
1440 gtk_window_set_type_hint(toplevel
, GDK_WINDOW_TYPE_HINT_DIALOG
);
1441 GtkVBox
*vbox
= GTK_VBOX(gtk_vbox_new(false, 5));
1443 GtkRequisition req
, req2
;
1444 gtk_window_set_title(GTK_WINDOW (toplevel
), title
);
1445 gtk_container_add(GTK_CONTAINER(toplevel
), GTK_WIDGET(vbox
));
1447 gui
= new plugin_gui(this);
1448 gui
->effect_name
= effect
;
1450 ui_mgr
= gtk_ui_manager_new();
1451 std_actions
= gtk_action_group_new("default");
1452 gtk_action_group_add_actions(std_actions
, actions
, sizeof(actions
)/sizeof(actions
[0]), this);
1453 GError
*error
= NULL
;
1454 gtk_ui_manager_insert_action_group(ui_mgr
, std_actions
, 0);
1455 gtk_ui_manager_add_ui_from_string(ui_mgr
, ui_xml
, -1, &error
);
1457 command_actions
= gtk_action_group_new("commands");
1460 fill_gui_presets(true, ch
);
1461 fill_gui_presets(false, ch
);
1463 gtk_box_pack_start(GTK_BOX(vbox
), gtk_ui_manager_get_widget(ui_mgr
, "/ui/menubar"), false, false, 0);
1465 // determine size without content
1466 gtk_widget_show_all(GTK_WIDGET(vbox
));
1467 gtk_widget_size_request(GTK_WIDGET(vbox
), &req2
);
1468 // printf("size request %dx%d\n", req2.width, req2.height);
1470 GtkWidget
*container
;
1471 const char *xml
= _jh
->get_gui_xml();
1473 container
= gui
->create_from_xml(_jh
, xml
);
1475 string command_xml
= make_gui_command_list(command_actions
);
1476 gtk_ui_manager_insert_action_group(ui_mgr
, command_actions
, 0);
1477 gtk_ui_manager_add_ui_from_string(ui_mgr
, command_xml
.c_str(), -1, &error
);
1479 GtkWidget
*sw
= gtk_scrolled_window_new(NULL
, NULL
);
1480 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
), GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
1481 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
), GTK_SHADOW_NONE
);
1482 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw
), container
);
1484 gtk_box_pack_start(GTK_BOX(vbox
), sw
, true, true, 0);
1486 gtk_widget_show_all(GTK_WIDGET(sw
));
1487 gtk_widget_size_request(container
, &req
);
1488 int wx
= max(req
.width
+ 10, req2
.width
);
1489 int wy
= req
.height
+ req2
.height
+ 10;
1490 // printf("size request %dx%d\n", req.width, req.height);
1491 // printf("resize to %dx%d\n", max(req.width + 10, req2.width), req.height + req2.height + 10);
1492 gtk_window_set_default_size(GTK_WINDOW(toplevel
), wx
, wy
);
1493 gtk_window_resize(GTK_WINDOW(toplevel
), wx
, wy
);
1494 //gtk_widget_set_size_request(GTK_WIDGET(toplevel), max(req.width + 10, req2.width), req.height + req2.height + 10);
1495 // printf("size set %dx%d\n", wx, wy);
1496 // gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(sw), GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, req.height, 20, 100, 100)));
1497 gtk_signal_connect (GTK_OBJECT (toplevel
), "destroy", G_CALLBACK (window_destroyed
), (plugin_gui_window
*)this);
1498 main
->set_window(gui
->plugin
, this);
1500 source_id
= g_timeout_add_full(G_PRIORITY_LOW
, 1000/30, on_idle
, this, NULL
); // 30 fps should be enough for everybody
1501 gtk_ui_manager_ensure_update(ui_mgr
);
1502 gui
->plugin
->send_configures(gui
);
1505 void plugin_gui_window::close()
1508 g_source_remove(source_id
);
1510 gtk_widget_destroy(GTK_WIDGET(toplevel
));
1513 plugin_gui_window::~plugin_gui_window()
1516 g_source_remove(source_id
);
1517 main
->set_window(gui
->plugin
, NULL
);
1521 void calf_plugins::activate_command(GtkAction
*action
, activate_command_params
*params
)
1523 plugin_gui
*gui
= params
->gui
;
1524 gui
->plugin
->execute(params
->function_idx
);