1 /*
2  * Copyright (C) 2011, 2012 Andreas Degert, Hermann Meyer
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include "guitarix.h"        // NOLINT
20 
21 #include <glibmm/i18n.h>     // NOLINT
22 
23 namespace gx_gui {
24 
25 /****************************************************************/
26 
27 class WidgetStack {
28 private:
29     std::vector<Gtk::Widget*> stack;
top()30     Gtk::Widget *top() { return stack.back(); }
31 public:
WidgetStack()32     WidgetStack(): stack() {}
~WidgetStack()33     ~WidgetStack() {}
empty()34     bool empty() { return stack.empty(); }
push(Gtk::Widget * w)35     void push(Gtk::Widget *w) { stack.push_back(w); }
pop()36     void pop() { return stack.pop_back(); }
37     void container_add(Gtk::Widget *w);
38     void box_pack_start(Gtk::Widget *w, bool expand=true, bool fill=true, int padding=0);
39     void notebook_append_page(Gtk::Widget *w, Gtk::Widget *label);
top_is_notebook()40     bool top_is_notebook() { return dynamic_cast<Gtk::Notebook*>(top()) != 0; }
41     Gtk::Widget *add(Gtk::Widget *w, const Glib::ustring& label = Glib::ustring());
42 };
43 
44 class StackBoxBuilder {
45 private:
46     WidgetStack          fBox;
47     gx_engine::GxMachineBase& machine;
48     Gtk::HBox           *widget;
49     Glib::RefPtr<Gtk::AccelGroup> accels;
50     Glib::RefPtr<Gdk::Pixbuf> window_icon;
51     int next_flags;
52     PluginUI *current_plugin;
53 
54 private:
55     void loadRackFromBuilder(const Glib::RefPtr<GxBuilder>& bld);
56     // functions used in interfaces
57     void create_master_slider(const std::string& id, const char *label);
58 
59     void closeBox();
60     void insertSpacer();
61 
62     void check_set_flags(Gxw::Regler *r);
63     void create_simple_meter(const std::string& id);
64     void create_simple_c_meter(const std::string& id, const std::string& idl, const char *label);
65     void create_mid_rackknob(const std::string& id, const char *label);
66     void create_small_rackknob(const std::string& id, const char *label);
67     void create_small_rackknobr(const std::string& id, const char *label);
68     void create_big_rackknob(const std::string& id, const char *label);
69 
70     void openVerticalBox(const char* label = "");
71     void openFrameBox(const char* label);
72     void openHorizontalBox(const char* label = "");
73     void openHorizontalhideBox(const char* label = "");
74     void openHorizontalTableBox(const char* label);
75     void create_switch_no_caption(const char *sw_type, const std::string& id);
76     void create_v_switch(const char *sw_type, const std::string& id, const char *label);
77     void openpaintampBox(const char* label = "");
78     void create_wheel(const std::string& id, const char *label=0);
79     void create_spin_value(const std::string& id, const char *label);
80     void create_simple_spin_value(const std::string& id);
81     void create_eq_rackslider_no_caption(const std::string& id);
82     void create_port_display(const std::string& id, const char *label);
83     void create_p_display(const std::string& id, const std::string& idl, const std::string& idh);
84     void create_feedback_switch(const char *sw_type, const std::string& id);
85     void create_feedback_slider(const std::string& id, const char *label);
86     void create_fload_switch(const char *sw_type, const char *id, const std::string& idf);
87     void create_selector(const std::string& id, const char *widget_name=0);
88     void create_selector_with_caption(const std::string& id, const char *label);
89     void openFlipLabelBox(const char* = 0);
90     void openVerticalBox1(const char* label = 0);
91     void openVerticalBox2(const char* label = 0);
92     void openTabBox(const char* label = 0);
93     void set_next_flags(int flags);
94 private:
95     // functions used indirectly
96     void addwidget(Gtk::Widget *widget);
97     bool ui_connect(Gtk::Widget *widget, const std::string& id);
98     void add_regler(CpBaseCaption *w, Gxw::Regler *r, const std::string& id, const char *label);
99     void load_file(const std::string& id, const std::string& idf);
100     void on_file_chooser_response(int response_id, Gtk::FileChooserDialog *d,
101                                   const std::string& id, const std::string& idf);
102     void load_file_f(const std::string& id, const std::string& idf);
103     void loadRackFromGladeData(const char *xmldesc);
104     void loadRackFromGladeFile(const char *fname);
105     friend class UiBuilderImpl;
106 
107 public:
108     StackBoxBuilder(
109 	gx_engine::GxMachineBase& machine_, Glib::RefPtr<Gdk::Pixbuf> window_icon);
110     ~StackBoxBuilder();
set_accelgroup(Glib::RefPtr<Gtk::AccelGroup> accels_)111     void set_accelgroup(Glib::RefPtr<Gtk::AccelGroup> accels_) { accels = accels_; }
112     void prepare();
113     void fetch(Gtk::Widget*& mainbox, Gtk::Widget*& minibox);
set_current_plugin(PluginUI * p)114     void set_current_plugin(PluginUI *p) { current_plugin = p; }
115     void connect_signals(Glib::RefPtr<GxBuilder> builder, Glib::RefPtr<Glib::Object> object,
116                          const char *signal_name, const char *handler_name);
117 };
118 
119 } // end namespace gx_gui
120