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-04 18:20:33 -05:00
|
|
|
//std::ofstream dbg_out("/users/WavesUILog.txt");
|
2014-03-29 18:56:09 -05:00
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
void
|
|
|
|
|
WavesUI::get_styles(const XMLTree& layout, WavesUI::XMLNodeMap &styles)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
XMLNode* root = layout.root();
|
|
|
|
|
if (root != NULL) {
|
|
|
|
|
|
|
|
|
|
for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) {
|
|
|
|
|
if ( !strcasecmp((*i)->name().c_str(), "style")) {
|
|
|
|
|
std::string style_name = ((*i)->property("name") ? (*i)->property("name")->value() : std::string(""));
|
|
|
|
|
if (!style_name.empty()) {
|
|
|
|
|
styles[style_name] = *i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
WavesUI::xml_property (const XMLNode &node, const char *prop_name, const XMLNodeMap& styles, double default_value)
|
|
|
|
|
{
|
|
|
|
|
std::string property = xml_property(node, prop_name, styles, "");
|
|
|
|
|
if (property.empty()) {
|
|
|
|
|
return default_value;
|
|
|
|
|
}
|
|
|
|
|
return atof(property.c_str());
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::xml_property (const XMLNode &node, const char *prop_name, const XMLNodeMap& styles, int default_value)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
std::string property = xml_property(node, prop_name, styles, "");
|
|
|
|
|
if (property.empty()) {
|
|
|
|
|
return default_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return atoi(property.c_str());
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::xml_property (const XMLNode &node, const char *prop_name, const XMLNodeMap& styles, bool default_value)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
std::string property = xml_property(node, prop_name, styles, "");
|
|
|
|
|
if (property.empty()) {
|
2014-03-29 18:56:09 -05:00
|
|
|
return default_value;
|
2014-04-01 16:03:54 -05:00
|
|
|
}
|
2014-03-29 18:56:09 -05:00
|
|
|
std::transform(property.begin(), property.end(), property.begin(), ::toupper);
|
|
|
|
|
return property == "TRUE";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::xml_property (const XMLNode &node, const char *prop_name, const XMLNodeMap& styles, const std::string default_value)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
std::string property = node.property (prop_name) ? node.property(prop_name)->value() : "";
|
|
|
|
|
if (property.empty()) {
|
|
|
|
|
std::string style_name = node.property ("style") ? node.property("style")->value() : "";
|
|
|
|
|
if (!style_name.empty()) {
|
|
|
|
|
XMLNodeMap::const_iterator style = styles.find(style_name);
|
|
|
|
|
if (style != styles.end()) {
|
|
|
|
|
return WavesUI::xml_property (*style->second, prop_name, styles, default_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (property.empty()) {
|
|
|
|
|
return default_value;
|
|
|
|
|
}
|
|
|
|
|
return property;
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-04-01 16:03:54 -05:00
|
|
|
WavesUI::xml_property (const XMLNode& node, const char* prop_name, const XMLNodeMap& styles, const char* default_value)
|
2014-03-29 18:56:09 -05:00
|
|
|
{
|
2014-04-01 16:03:54 -05:00
|
|
|
return xml_property (node, prop_name, styles, std::string(default_value));
|
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-01 16:03:54 -05:00
|
|
|
std::string widget_id = WavesUI::xml_property (definition, "id", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
std::string text = WavesUI::xml_property (definition, "text", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
boost::replace_all(text, "\\n", "\n");
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
int height = WavesUI::xml_property (definition, "height", styles, -1);
|
|
|
|
|
int width = WavesUI::xml_property (definition, "width", styles, -1);
|
2014-03-29 18:56:09 -05:00
|
|
|
|
|
|
|
|
std::transform(widget_type.begin(), widget_type.end(), widget_type.begin(), ::toupper);
|
|
|
|
|
if (widget_type == "BUTTON") {
|
|
|
|
|
child = manage (new WavesButton(text));
|
2014-04-01 16:03:54 -05:00
|
|
|
((WavesButton*)child)->set_border_width (WavesUI::xml_property (definition, "borderwidth", styles, "0").c_str());
|
|
|
|
|
((WavesButton*)child)->set_border_color (WavesUI::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (child != NULL) {
|
|
|
|
|
child->set_size_request (width, height);
|
|
|
|
|
if (!widget_id.empty())
|
|
|
|
|
{
|
|
|
|
|
named_widgets[widget_id] = child;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
std::string property = WavesUI::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-04 18:20:33 -05:00
|
|
|
property = WavesUI::xml_property (definition, "bgdisabled", styles, property);
|
|
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_bg(Gtk::STATE_INSENSITIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
property = WavesUI::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-01 16:03:54 -05:00
|
|
|
property = WavesUI::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-01 16:03:54 -05:00
|
|
|
property = WavesUI::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-04 18:20:33 -05:00
|
|
|
property = WavesUI::xml_property (definition, "fgdisabled", styles, property);
|
|
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_fg(Gtk::STATE_INSENSITIVE, Gdk::Color(property));
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 16:03:54 -05:00
|
|
|
property = WavesUI::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-01 16:03:54 -05:00
|
|
|
property = WavesUI::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-01 16:03:54 -05:00
|
|
|
property = WavesUI::xml_property (definition, "font", styles, "");
|
2014-03-29 18:56:09 -05:00
|
|
|
if (!property.empty()) {
|
|
|
|
|
child->modify_font(Pango::FontDescription(property));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-01 16:03:54 -05:00
|
|
|
WavesUI::xml_property (definition, "x", styles, 0),
|
|
|
|
|
WavesUI::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-03-29 18:56:09 -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-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;
|
|
|
|
|
WavesUI::get_styles(layout, styles);
|
|
|
|
|
const XMLNodeList& definition = layout.root()->children();
|
|
|
|
|
WavesUI::create_ui (definition, styles, root, named_widgets);
|
2014-03-29 18:56:09 -05:00
|
|
|
}
|