2014-03-29 18:56:09 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (C) 2014 Valeriy Kamyshniy
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
#include "waves_ui.h"
|
2014-04-14 12:37:20 -05:00
|
|
|
#include "canvas/canvas.h"
|
|
|
|
|
#include "waves_button.h"
|
2014-03-29 18:56:09 -05:00
|
|
|
|
2014-04-04 18:20:33 -05:00
|
|
|
//std::ofstream dbg_out("/users/WavesUILog.txt");
|
2014-03-29 18:56:09 -05:00
|
|
|
|
|
|
|
|
Gtk::Widget*
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::create_widget (const XMLNode& definition, const XMLNodeMap& styles, std::map<std::string, Gtk::Widget*> &named_widgets)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
|
|
|
|
Gtk::Widget* child = NULL;
|
|
|
|
|
std::string widget_type = definition.name();
|
2014-04-14 12:37:20 -05:00
|
|
|
std::string widget_id = xml_property (definition, "id", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
std::string text = xml_property (definition, "text", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
boost::replace_all(text, "\\n", "\n");
|
|
|
|
|
|
|
|
|
|
std::transform(widget_type.begin(), widget_type.end(), widget_type.begin(), ::toupper);
|
|
|
|
|
if (widget_type == "BUTTON") {
|
|
|
|
|
child = manage (new WavesButton(text));
|
2014-04-14 12:37:20 -05:00
|
|
|
((WavesButton*)child)->set_border_width (xml_property (definition, "borderwidth", styles, "0").c_str());
|
|
|
|
|
((WavesButton*)child)->set_border_color (xml_property (definition, "bordercolor", styles, "#000000").c_str());
|
2014-03-29 18:56:09 -05:00
|
|
|
} else if (widget_type == "COMBOBOXTEXT") {
|
|
|
|
|
child = manage (new Gtk::ComboBoxText);
|
|
|
|
|
} else if (widget_type == "LABEL") {
|
|
|
|
|
child = manage (new Gtk::Label(text));
|
|
|
|
|
} else if (widget_type == "LAYOUT") {
|
|
|
|
|
child = manage (new Gtk::Layout);
|
2014-04-14 12:37:20 -05:00
|
|
|
} else if (widget_type == "CANVAS") {
|
|
|
|
|
std::map<std::string, ArdourCanvas::Item*> named_items;
|
2014-04-29 01:07:37 -05:00
|
|
|
child = manage (new ArdourCanvas::GtkCanvas(definition, styles, named_items));
|
|
|
|
|
} else if (widget_type == "SCROLLEDWINDOW") {
|
|
|
|
|
child = manage (new Gtk::ScrolledWindow);
|
|
|
|
|
} else if (widget_type == "VBOX") {
|
|
|
|
|
child = manage (new Gtk::VBox);
|
|
|
|
|
} else if (widget_type == "HBOX") {
|
|
|
|
|
child = manage (new Gtk::HBox);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (child != NULL) {
|
2014-04-14 12:37:20 -05:00
|
|
|
int height = xml_property (definition, "height", styles, -1);
|
|
|
|
|
int width = xml_property (definition, "width", styles, -1);
|
2014-03-29 18:56:09 -05:00
|
|
|
child->set_size_request (width, height);
|
|
|
|
|
if (!widget_id.empty())
|
|
|
|
|
{
|
|
|
|
|
named_widgets[widget_id] = child;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
std::string property = xml_property (definition, "bgnormal", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_bg(Gtk::STATE_NORMAL, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "bgdisabled", styles, property);
|
2014-04-04 18:20:33 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_bg(Gtk::STATE_INSENSITIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "bgactive", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_bg(Gtk::STATE_ACTIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "bghover", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_bg(Gtk::STATE_PRELIGHT, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "fgnormal", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_fg(Gtk::STATE_NORMAL, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "fgdisabled", styles, property);
|
2014-04-04 18:20:33 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_fg(Gtk::STATE_INSENSITIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "fgactive", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_fg(Gtk::STATE_ACTIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "fghover", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_fg(Gtk::STATE_PRELIGHT, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:37:20 -05:00
|
|
|
property = xml_property (definition, "font", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_font(Pango::FontDescription(property));
|
|
|
|
|
}
|
2014-04-17 05:37:15 -05:00
|
|
|
|
|
|
|
|
if (xml_property (definition, "visible", styles, true)) {
|
|
|
|
|
child->show();
|
|
|
|
|
} else {
|
|
|
|
|
child->hide();
|
|
|
|
|
}
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gtk::Widget*
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::add_widget (Gtk::Box& parent, const XMLNode& definition, const XMLNodeMap& styles, std::map<std::string, Gtk::Widget*> &named_widgets)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
Gtk::Widget* child = create_widget(definition, styles, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
|
|
|
|
|
if (child != NULL)
|
|
|
|
|
{
|
|
|
|
|
parent.pack_start(*child, false, false);
|
|
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-04-29 01:07:37 -05:00
|
|
|
Gtk::Widget*
|
|
|
|
|
WavesUI::add_widget (Gtk::ScrolledWindow& parent, const XMLNode& definition, const XMLNodeMap& styles, std::map<std::string, Gtk::Widget*> &named_widgets)
|
|
|
|
|
{
|
|
|
|
|
Gtk::Widget* child = create_widget(definition, styles, named_widgets);
|
|
|
|
|
|
|
|
|
|
if (child != NULL)
|
|
|
|
|
{
|
|
|
|
|
parent.add(*child);
|
|
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-03-29 18:56:09 -05:00
|
|
|
Gtk::Widget*
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::add_widget (Gtk::Layout& parent, const XMLNode& definition, const XMLNodeMap& styles, std::map<std::string, Gtk::Widget*> &named_widgets)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
Gtk::Widget* child = create_widget(definition, styles, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
|
|
|
|
|
if (child != NULL)
|
|
|
|
|
{
|
|
|
|
|
parent.put (*child,
|
2014-04-14 12:37:20 -05:00
|
|
|
xml_property (definition, "x", styles, 0),
|
|
|
|
|
xml_property (definition, "y", styles, 0));
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gtk::Widget*
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::add_widget (Gtk::Widget& parent, const XMLNode &definition, const XMLNodeMap& styles, std::map<std::string, Gtk::Widget*> &named_widgets)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
|
|
|
|
Gtk::Widget* child = NULL;
|
|
|
|
|
if(dynamic_cast<Gtk::Layout*> (&parent)) {
|
2014-04-01 16:03:54 -05:00
|
|
|
child = WavesUI::add_widget (*dynamic_cast<Gtk::Layout*> (&parent), definition, styles, named_widgets);
|
2014-04-29 01:07:37 -05:00
|
|
|
} else if(dynamic_cast<Gtk::Box*> (&parent)) {
|
2014-04-01 16:03:54 -05:00
|
|
|
child = WavesUI::add_widget (*dynamic_cast<Gtk::Box*> (&parent), definition, styles, named_widgets);
|
2014-04-29 01:07:37 -05:00
|
|
|
} else if(dynamic_cast<Gtk::ScrolledWindow*> (&parent)) {
|
|
|
|
|
child = WavesUI::add_widget (*dynamic_cast<Gtk::ScrolledWindow*> (&parent), definition, styles, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
if (child != NULL) {
|
|
|
|
|
WavesUI::create_ui (definition.children(), styles, *child, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
void
|
|
|
|
|
WavesUI::create_ui (const XMLNodeList& definition, const XMLNodeMap& styles, Gtk::Widget& root, std::map<std::string, Gtk::Widget*> &named_widgets)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
|
|
|
|
for (XMLNodeList::const_iterator i = definition.begin(); i != definition.end(); ++i) {
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::add_widget ((Gtk::Widget&)root, **i, styles, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
2014-04-01 16:03:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
WavesUI::create_ui (const XMLTree& layout, Gtk::Widget& root, std::map<std::string, Gtk::Widget*> &named_widgets)
|
|
|
|
|
{
|
|
|
|
|
XMLNodeMap styles;
|
2014-04-14 12:37:20 -05:00
|
|
|
get_styles(layout, styles);
|
2014-04-01 16:03:54 -05:00
|
|
|
const XMLNodeList& definition = layout.root()->children();
|
|
|
|
|
WavesUI::create_ui (definition, styles, root, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|