Guitarix
gx_ui_builder.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3 * Copyright (C) 2011 Pete Shorthose
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * --------------------------------------------------------------------------
19 */
20
21/* ------- This is the GUI namespace ------- */
22
23#pragma once
24
25#ifndef SRC_HEADERS_GX_UI_BUILDER_H_
26#define SRC_HEADERS_GX_UI_BUILDER_H_
27
28#include <gxwmm/controlparameter.h>
29#include <gxwmm/regler.h>
30
31class PluginUI;
32class PluginDict;
33
34namespace gx_gui {
35
37 gx_engine::GxMachineBase& machine, const std::string& id, Gtk::Widget *w);
38
40 gx_engine::GxMachineBase& machine, const std::string& id, Gtk::Widget *w);
41
43 gx_engine::GxMachineBase& machine, Gtk::ToggleButton *b,
44 const string& id, sigc::signal<void(bool)> *out_ctr, bool disable);
45
46bool ui_connect(gx_engine::GxMachineBase& machine, Gtk::Widget *w, const std::string& id,
47 sigc::signal<void(bool)> *out_ctr);
48
49/**************************************************************/
72class GxBuilder: public Gtk::Builder {
73private:
74 static bool show_tooltips;
75 // only implemented for base class, make inaccessible
76 static Glib::RefPtr<GxBuilder> create_from_file(const std::string& filename, const char* object_id);
77 static Glib::RefPtr<GxBuilder> create_from_file(const std::string& filename, const Glib::ustring& object_id);
78 static Glib::RefPtr<GxBuilder> create_from_file(const std::string& filename, const Glib::StringArrayHandle& object_ids);
79 static Glib::RefPtr<GxBuilder> create_from_string(const Glib::ustring& buffer, const char* object_id);
80 static Glib::RefPtr<GxBuilder> create_from_string(const Glib::ustring& buffer, const Glib::ustring& object_id);
81 static Glib::RefPtr<GxBuilder> create_from_string(const Glib::ustring& buffer, const Glib::StringArrayHandle& object_ids);
82 GObject* get_cobject(const Glib::ustring& name);
83public:
84 static inline Glib::RefPtr<GxBuilder> create() { return Glib::RefPtr<GxBuilder>(new GxBuilder()); }
85
86 static Glib::RefPtr<GxBuilder> create_from_file(
87 const std::string& filename, gx_engine::GxMachineBase* pmach = 0, const char* object_id = 0, sigc::signal<void(bool)> *out_ctr = 0);
88
89 static Glib::RefPtr<GxBuilder> create_from_file(
90 const std::string& filename, gx_engine::GxMachineBase* pmach, const Glib::StringArrayHandle& object_ids, sigc::signal<void(bool)> *out_ctr = 0);
91
92 static Glib::RefPtr<GxBuilder> create_from_string(
93 const Glib::ustring& buffer, gx_engine::GxMachineBase* pmach = 0, const char* object_id = 0, sigc::signal<void(bool)> *out_ctr = 0);
94
95 static Glib::RefPtr<GxBuilder> create_from_string(
96 const Glib::ustring& buffer, gx_engine::GxMachineBase* pmach, const Glib::StringArrayHandle& object_ids, sigc::signal<void(bool)> *out_ctr = 0);
97
98 static bool get_show_tooltips() { return show_tooltips; }
99 static void set_show_tooltips(bool v) { show_tooltips = v; }
100 static void connect_gx_tooltip_handler(GtkWidget *widget);
101 static void set_tooltip_text_connect_handler(GtkWidget *widget, const char *text);
102 static void set_tooltip_text_connect_handler(Gtk::Widget& widget, const char *text) {
103 set_tooltip_text_connect_handler(widget.gobj(), text); }
104 static void set_tooltip_text_connect_handler(Gtk::Widget& widget, const Glib::ustring& text) {
105 set_tooltip_text_connect_handler(widget.gobj(), text.c_str()); }
106
107 void fixup_controlparameters(gx_engine::GxMachineBase& machine, sigc::signal<void(bool)> *out_ctr);
108
109 template <class T_Widget> inline
110 void find_widget(const Glib::ustring& name, T_Widget*& widget) {
111 widget = dynamic_cast<T_Widget*>(get_widget_checked(name, T_Widget::get_base_type()));
112 assert(widget);
113 }
114 // pointer set by find_object only have the lifetime of the underlying GxBuilder
115 // if you need a longer lifetime, use get_object()!
116 template <class T_Object> inline
117 void find_object(const Glib::ustring& name, T_Object*& object) {
118 object = dynamic_cast<T_Object*>(get_object(name).get());
119 assert(object);
120 }
121
122 template <class T_Widget, class F> inline
123 void find_widget_derived(const Glib::ustring& name, T_Widget*& widget, F f) {
124 widget = 0;
125 typedef typename T_Widget::BaseObjectType cwidget_type;
126 cwidget_type* pCWidget = (cwidget_type*)get_cobject(name);
127 if(!pCWidget) {
128 return;
129 }
130 Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);
131 if (pObjectBase) {
132 widget = dynamic_cast<T_Widget*>( Glib::wrap((GtkWidget*)pCWidget) );
133 if (!widget) {
134 g_critical("GxBuilder::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");
135 }
136 } else {
137 widget = f(pCWidget);
138 }
139 }
140
141 bool has_object(const Glib::ustring& name) {
142 return gtk_builder_get_object(gobj(), name.c_str()) != 0;
143 }
144
145 template <class T_Widget> inline
146 void get_toplevel(const Glib::ustring& name, T_Widget*& widget) {
147 GType type = T_Widget::get_base_type();
148 widget = dynamic_cast<T_Widget*>(get_widget_checked(name, type));
149 assert(widget);
150 assert(!widget->get_parent());
151 }
152
153 Gtk::Window *get_first_window();
154
155 template <class T_Widget, class F> inline
156 void get_toplevel_derived(const Glib::ustring& name, T_Widget*& widget, F f) {
157 widget = 0;
158 typedef typename T_Widget::BaseObjectType cwidget_type;
159 cwidget_type* pCWidget = (cwidget_type*)get_cobject(name);
160 if(!pCWidget) {
161 return;
162 }
163 if (!g_type_is_a(G_OBJECT_TYPE(pCWidget), GTK_TYPE_WINDOW)) {
164 g_object_ref(pCWidget);
165 }
166 Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);
167 if (pObjectBase) {
168 widget = dynamic_cast<T_Widget*>( Glib::wrap((GtkWidget*)pCWidget) );
169 if (!widget) {
170 g_critical("GxBuilder::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");
171 }
172 } else {
173 widget = f(pCWidget);
174 }
175 assert(!widget->get_parent());
176 }
177};
178
179class StackBoxBuilder;
180
182protected:
184 std::vector<PluginUI*> *pluginlist;
186 static void openTabBox_(const char* label);
187 static void openVerticalBox_(const char* label);
188 static void openVerticalBox1_(const char* label);
189 static void openVerticalBox2_(const char* label);
190 static void openHorizontalBox_(const char* label);
191 //static void openHorizontalBox_(const char* label, int spacing);
192 static void openHorizontalhideBox_(const char* label);
193 static void openHorizontalTableBox_(const char* label);
194 static void openFrameBox_(const char *label);
195 static void openFlipLabelBox_(const char* label);
196 static void openpaintampBox_(const char* label);
197 static void insertSpacer_();
198 static void set_next_flags_(int flags);
199 static void create_mid_rackknob_(const char *id, const char *label);
200 static void create_small_rackknob_(const char *id, const char *label);
201 static void create_small_rackknobr_(const char *id, const char *label);
202 static void create_big_rackknob_(const char *id, const char *label);
203 static void create_master_slider_(const char *id, const char *label);
204 static void create_feedback_slider_(const char *id, const char *label);
205 static void create_selector_no_caption_(const char *id);
206 static void create_selector_(const char *id, const char *label);
207 static void create_simple_meter_(const char *id);
208 static void create_simple_c_meter_(const char *id, const char *idl, const char *label);
209 static void create_spin_value_(const char *id, const char *label);
210 static void create_switch_no_caption_(const char *sw_type,const char * id);
211 static void create_feedback_switch_(const char *sw_type,const char * id);
212 static void create_fload_switch_(const char *sw_type,const char * id,const char * idf);
213 static void create_switch_(const char *sw_type,const char * id, const char *label);
214 static void create_wheel_(const char * id, const char *label);
215 static void create_port_display_(const char *id, const char *label);
216 static void create_p_display_(const char *id, const char *idl, const char *idh);
217 static void create_simple_spin_value_(const char *id);
218 static void create_eq_rackslider_no_caption_(const char *id);
219 static void closeBox_();
220 static void load_glade_(const char *data);
221 static void load_glade_file_(const char *fname);
222 virtual bool load(gx_engine::Plugin *p);
223public:
224 UiBuilderImpl(PluginDict *i, StackBoxBuilder *b, std::vector<PluginUI*> *pl, PluginUI *pluginui);
228};
229
230GtkWidget *load_toplevel(GtkBuilder *builder, const char* filename, const char* windowname);
231
232} /* end of gx_gui namespace */
233#endif // SRC_HEADERS_GX_UI_BUILDER_H_
class GxBuilder
Definition: gx_ui_builder.h:72
static void set_tooltip_text_connect_handler(GtkWidget *widget, const char *text)
void fixup_controlparameters(gx_engine::GxMachineBase &machine, sigc::signal< void(bool)> *out_ctr)
static void connect_gx_tooltip_handler(GtkWidget *widget)
static Glib::RefPtr< GxBuilder > create_from_string(const Glib::ustring &buffer, const Glib::ustring &object_id)
static Glib::RefPtr< GxBuilder > create_from_file(const std::string &filename, const char *object_id)
static void set_show_tooltips(bool v)
Definition: gx_ui_builder.h:99
static Glib::RefPtr< GxBuilder > create_from_file(const std::string &filename, gx_engine::GxMachineBase *pmach=0, const char *object_id=0, sigc::signal< void(bool)> *out_ctr=0)
static Glib::RefPtr< GxBuilder > create_from_file(const std::string &filename, const Glib::ustring &object_id)
static void set_tooltip_text_connect_handler(Gtk::Widget &widget, const Glib::ustring &text)
GObject * get_cobject(const Glib::ustring &name)
static Glib::RefPtr< GxBuilder > create_from_file(const std::string &filename, gx_engine::GxMachineBase *pmach, const Glib::StringArrayHandle &object_ids, sigc::signal< void(bool)> *out_ctr=0)
static bool show_tooltips
Definition: gx_ui_builder.h:74
void get_toplevel_derived(const Glib::ustring &name, T_Widget *&widget, F f)
static Glib::RefPtr< GxBuilder > create_from_string(const Glib::ustring &buffer, const Glib::StringArrayHandle &object_ids)
static bool get_show_tooltips()
Definition: gx_ui_builder.h:98
void get_toplevel(const Glib::ustring &name, T_Widget *&widget)
static Glib::RefPtr< GxBuilder > create_from_file(const std::string &filename, const Glib::StringArrayHandle &object_ids)
void find_widget_derived(const Glib::ustring &name, T_Widget *&widget, F f)
static Glib::RefPtr< GxBuilder > create_from_string(const Glib::ustring &buffer, const char *object_id)
bool has_object(const Glib::ustring &name)
static Glib::RefPtr< GxBuilder > create_from_string(const Glib::ustring &buffer, gx_engine::GxMachineBase *pmach, const Glib::StringArrayHandle &object_ids, sigc::signal< void(bool)> *out_ctr=0)
void find_widget(const Glib::ustring &name, T_Widget *&widget)
Gtk::Window * get_first_window()
static Glib::RefPtr< GxBuilder > create()
Definition: gx_ui_builder.h:84
void find_object(const Glib::ustring &name, T_Object *&object)
static Glib::RefPtr< GxBuilder > create_from_string(const Glib::ustring &buffer, gx_engine::GxMachineBase *pmach=0, const char *object_id=0, sigc::signal< void(bool)> *out_ctr=0)
static void set_tooltip_text_connect_handler(Gtk::Widget &widget, const char *text)
UiBuilderImpl(PluginDict *i, StackBoxBuilder *b, std::vector< PluginUI * > *pl, PluginUI *pluginui)
static void create_feedback_slider_(const char *id, const char *label)
static void create_selector_(const char *id, const char *label)
static void create_eq_rackslider_no_caption_(const char *id)
static void closeBox_()
static void create_p_display_(const char *id, const char *idl, const char *idh)
static void create_mid_rackknob_(const char *id, const char *label)
static void openVerticalBox1_(const char *label)
static void create_simple_spin_value_(const char *id)
static void load_glade_(const char *data)
static StackBoxBuilder * intf
static void openFlipLabelBox_(const char *label)
static void insertSpacer_()
static void create_fload_switch_(const char *sw_type, const char *id, const char *idf)
static void create_port_display_(const char *id, const char *label)
static void openVerticalBox2_(const char *label)
static void create_wheel_(const char *id, const char *label)
static void openVerticalBox_(const char *label)
static void openTabBox_(const char *label)
static void openHorizontalhideBox_(const char *label)
static void create_feedback_switch_(const char *sw_type, const char *id)
PluginDict & plugin_dict
bool load_unit(PluginDef *pl)
static void create_small_rackknobr_(const char *id, const char *label)
static void create_switch_(const char *sw_type, const char *id, const char *label)
static void create_spin_value_(const char *id, const char *label)
static void openHorizontalBox_(const char *label)
virtual bool load(gx_engine::Plugin *p)
static void create_selector_no_caption_(const char *id)
static void load_glade_file_(const char *fname)
static void create_switch_no_caption_(const char *sw_type, const char *id)
static void create_small_rackknob_(const char *id, const char *label)
static void create_master_slider_(const char *id, const char *label)
static void openpaintampBox_(const char *label)
std::vector< PluginUI * > * pluginlist
static void openHorizontalTableBox_(const char *label)
static void create_big_rackknob_(const char *id, const char *label)
static void create_simple_meter_(const char *id)
static void openFrameBox_(const char *label)
static void set_next_flags_(int flags)
static void create_simple_c_meter_(const char *id, const char *idl, const char *label)
gx_engine::Parameter * check_get_parameter(gx_engine::GxMachineBase &machine, const std::string &id, Gtk::Widget *w)
bool ui_connect(gx_engine::GxMachineBase &machine, Gtk::Widget *w, const std::string &id, sigc::signal< void(bool)> *out_ctr)
GtkWidget * load_toplevel(GtkBuilder *builder, const char *filename, const char *windowname)
gx_engine::FloatParameter * check_get_float_parameter(gx_engine::GxMachineBase &machine, const std::string &id, Gtk::Widget *w)
bool ui_connect_switch(gx_engine::GxMachineBase &machine, Gtk::ToggleButton *b, const string &id, sigc::signal< void(bool)> *out_ctr, bool disable)