diff --git a/po/wesnoth-lib/POTFILES.in b/po/wesnoth-lib/POTFILES.in index 3feca3a011a..80487398fd0 100644 --- a/po/wesnoth-lib/POTFILES.in +++ b/po/wesnoth-lib/POTFILES.in @@ -6,6 +6,7 @@ src/game_preferences.cpp src/game_preferences_display.cpp src/gui/auxiliary/canvas.cpp src/gui/auxiliary/log.cpp +src/gui/auxiliary/window_builder/control.cpp src/gui/auxiliary/window_builder.cpp src/gui/dialogs/addon_connect.cpp src/gui/dialogs/addon_list.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97f9fcf9a05..e38ebfa4e9b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -263,6 +263,7 @@ SET(wesnoth-main_SRC generic_event.cpp gui/auxiliary/canvas.cpp gui/auxiliary/log.cpp + gui/auxiliary/window_builder/control.cpp gui/auxiliary/window_builder.cpp gui/dialogs/addon_connect.cpp gui/dialogs/addon_list.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c0bf4f2250b..69bcbe9d463 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -88,6 +88,7 @@ wesnoth_source = \ generic_event.cpp \ gui/auxiliary/canvas.cpp \ gui/auxiliary/log.cpp \ + gui/auxiliary/window_builder/control.cpp \ gui/auxiliary/window_builder.cpp \ gui/dialogs/addon_connect.cpp \ gui/dialogs/addon_list.cpp \ diff --git a/src/SConscript b/src/SConscript index 22891c7bc1d..f51f3d14297 100644 --- a/src/SConscript +++ b/src/SConscript @@ -244,6 +244,7 @@ wesnoth_sources = Split(""" widgets/scrollpane.cpp gui/auxiliary/canvas.cpp gui/auxiliary/log.cpp + gui/auxiliary/window_builder/control.cpp gui/auxiliary/window_builder.cpp gui/dialogs/addon_connect.cpp gui/dialogs/addon_list.cpp diff --git a/src/gui/auxiliary/window_builder.cpp b/src/gui/auxiliary/window_builder.cpp index 184ebdcf2e2..556c99c74e4 100644 --- a/src/gui/auxiliary/window_builder.cpp +++ b/src/gui/auxiliary/window_builder.cpp @@ -543,91 +543,8 @@ tbuilder_grid::tbuilder_grid(const config& cfg) : << rows << " rows and " << cols << " columns.\n"; } -tbuilder_control::tbuilder_control(const config& cfg) : - tbuilder_widget(cfg), - id(cfg["id"]), - definition(cfg["definition"]), - label(cfg["label"]), - tooltip(cfg["tooltip"]), - help(cfg["help"]), - use_tooltip_on_label_overflow( - utils::string_bool("use_tooltip_on_label_overflow", true)) -{ -/*WIKI - * @page = GUIWidgetInstanceWML - * @order = 1_widget - * - * = Widget = - * - * All widgets placed in the cell have some values in common: - * @start_table = config - * id (string = "") This value is used for the engine to - * identify 'special' items. This means that - * for example a text_box can get the proper - * initial value. This value should be - * unique or empty. Those special values are - * documented at the window definition that - * uses them. NOTE items starting with an - * underscore are used for composed widgets - * and these should be unique per composed - * widget. - * - * definition (string = "default") The id of the widget definition to use. - * This way it's possible to select a - * specific version of the widget eg a title - * label when the label is used as title. - * - * label (tstring = "") Most widgets have some text associated - * with them, this field contain the value - * of that text. Some widgets use this value - * for other purposes, this is documented - * at the widget. - * - * tooptip (tstring = "") If you hover over a widget a while (the - * time it takes can differ per widget) a - * short help can show up.This defines the - * text of that message. - * - * - * help (tstring = "") If you hover over a widget and press F1 a - * help message can show up. This help - * message might be the same as the tooltip - * but in general (if used) this message - * should show more help. This defines the - * text of that message. - * - * use_tooltip_on_label_overflow (bool = true) - * If the text on the label is truncated and - * the tooltip is empty the label can be - * used for the tooltip. If this variable is - * set to true this will happen. - * @end_table - * - */ - - if(definition.empty()) { - definition = "default"; - } - - - DBG_GUI_P << "Window builder: found control with id '" - << id << "' and definition '" << definition << "'.\n"; -} - -void tbuilder_control::init_control(tcontrol* control) const -{ - assert(control); - - control->set_id(id); - control->set_definition(definition); - control->set_label(label); - control->set_tooltip(tooltip); - control->set_help_message(help); - control->set_use_tooltip_on_label_overflow(use_tooltip_on_label_overflow); -} - tbuilder_button::tbuilder_button(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), retval_id_(cfg["return_value_id"]), retval_(lexical_cast_default(cfg["return_value"])) { @@ -707,7 +624,7 @@ tbuilder_gridcell::tbuilder_gridcell(const config& cfg) : } tbuilder_label::tbuilder_label(const config& cfg) - : tbuilder_control(cfg) + : implementation::tbuilder_control(cfg) , wrap(utils::string_bool("wrap")) { /*WIKI @@ -740,7 +657,7 @@ twidget* tbuilder_label::build() const } tbuilder_listbox::tbuilder_listbox(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), vertical_scrollbar_mode( get_scrollbar_mode(cfg["vertical_scrollbar_mode"])), horizontal_scrollbar_mode( @@ -862,7 +779,7 @@ twidget* tbuilder_listbox::build() const } tbuilder_menubar::tbuilder_menubar(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), must_have_one_item_selected_(utils::string_bool(cfg["must_have_one_item_selected"])), direction_(read_direction(cfg["direction"])), selected_item_(lexical_cast_default( @@ -945,7 +862,7 @@ twidget* tbuilder_minimap::build() const } tbuilder_multi_page::tbuilder_multi_page(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), builder(0), data() { @@ -1025,7 +942,7 @@ twidget* tbuilder_multi_page::build() const } tbuilder_panel::tbuilder_panel(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), grid(0) { /*WIKI @@ -1106,7 +1023,7 @@ twidget* tbuilder_scroll_label::build() const } tbuilder_slider::tbuilder_slider(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), best_slider_length_(lexical_cast_default(cfg["best_slider_length"])), minimum_value_(lexical_cast_default(cfg["minimum_value"])), maximum_value_(lexical_cast_default(cfg["maximum_value"])), @@ -1162,7 +1079,7 @@ tbuilder_slider::tbuilder_slider(const config& cfg) : } tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg) - : tbuilder_control(cfg) + : implementation::tbuilder_control(cfg) , vertical_scrollbar_mode( get_scrollbar_mode(cfg["vertical_scrollbar_mode"])) , horizontal_scrollbar_mode( @@ -1325,7 +1242,7 @@ twidget* tbuilder_toggle_button::build() const } tbuilder_toggle_panel::tbuilder_toggle_panel(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), grid(0), retval_id_(cfg["return_value_id"]), retval_(lexical_cast_default(cfg["return_value"])) diff --git a/src/gui/auxiliary/window_builder/control.cpp b/src/gui/auxiliary/window_builder/control.cpp new file mode 100644 index 00000000000..de82303bf29 --- /dev/null +++ b/src/gui/auxiliary/window_builder/control.cpp @@ -0,0 +1,113 @@ +/* $Id$ */ +/* + Copyright (C) 2008 - 2009 by Mark de Wever + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + or at your option any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/auxiliary/window_builder/control.hpp" + +#include "config.hpp" +#include "gui/auxiliary/log.hpp" +#include "gui/widgets/control.hpp" + +namespace gui2 { + +namespace implementation { + +tbuilder_control::tbuilder_control(const config& cfg) : + tbuilder_widget(cfg), + id(cfg["id"]), + definition(cfg["definition"]), + label(cfg["label"]), + tooltip(cfg["tooltip"]), + help(cfg["help"]), + use_tooltip_on_label_overflow( + utils::string_bool("use_tooltip_on_label_overflow", true)) +{ + if(definition.empty()) { + definition = "default"; + } + + + DBG_GUI_P << "Window builder: found control with id '" + << id << "' and definition '" << definition << "'.\n"; +} + +void tbuilder_control::init_control(tcontrol* control) const +{ + assert(control); + + control->set_id(id); + control->set_definition(definition); + control->set_label(label); + control->set_tooltip(tooltip); + control->set_help_message(help); + control->set_use_tooltip_on_label_overflow(use_tooltip_on_label_overflow); +} + +} // namespace implementation + +} // namespace gui2 + +/*WIKI + * @page = GUIWidgetInstanceWML + * @order = 1_widget + * + * = Widget = + * + * All widgets placed in the cell have some values in common: + * @start_table = config + * id (string = "") This value is used for the engine to + * identify 'special' items. This means that + * for example a text_box can get the proper + * initial value. This value should be + * unique or empty. Those special values are + * documented at the window definition that + * uses them. NOTE items starting with an + * underscore are used for composed widgets + * and these should be unique per composed + * widget. + * + * definition (string = "default") The id of the widget definition to use. + * This way it's possible to select a + * specific version of the widget eg a title + * label when the label is used as title. + * + * label (tstring = "") Most widgets have some text associated + * with them, this field contain the value + * of that text. Some widgets use this value + * for other purposes, this is documented + * at the widget. + * + * tooptip (tstring = "") If you hover over a widget a while (the + * time it takes can differ per widget) a + * short help can show up.This defines the + * text of that message. + * + * + * help (tstring = "") If you hover over a widget and press F1 a + * help message can show up. This help + * message might be the same as the tooltip + * but in general (if used) this message + * should show more help. This defines the + * text of that message. + * + * use_tooltip_on_label_overflow (bool = true) + * If the text on the label is truncated and + * the tooltip is empty the label can be + * used for the tooltip. If this variable is + * set to true this will happen. + * @end_table + * + */ + diff --git a/src/gui/auxiliary/window_builder/control.hpp b/src/gui/auxiliary/window_builder/control.hpp new file mode 100644 index 00000000000..487a6c7264b --- /dev/null +++ b/src/gui/auxiliary/window_builder/control.hpp @@ -0,0 +1,50 @@ +/* $Id$ */ +/* + Copyright (C) 2008 - 2009 by Mark de Wever + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + or at your option any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#ifndef GUI_AUXILIARY_WINDOW_BUILDER_CONTROL_HPP_INCLUDED +#define GUI_AUXILIARY_WINDOW_BUILDER_CONTROL_HPP_INCLUDED + +#include "gui/auxiliary/window_builder.hpp" + +namespace gui2 { + +class tcontrol; + +namespace implementation { + +struct tbuilder_control : public tbuilder_widget +{ +private: + tbuilder_control(); +public: + + tbuilder_control(const config& cfg); + + void init_control(tcontrol* control) const; + + /** Parameters for the control. */ + std::string id; + std::string definition; + t_string label; + t_string tooltip; + t_string help; + bool use_tooltip_on_label_overflow; +}; + +} // namespace implementation + +} // namespace gui2 + +#endif + diff --git a/src/gui/auxiliary/window_builder_private.hpp b/src/gui/auxiliary/window_builder_private.hpp index 97f59e635dd..d0497231549 100644 --- a/src/gui/auxiliary/window_builder_private.hpp +++ b/src/gui/auxiliary/window_builder_private.hpp @@ -24,31 +24,13 @@ #include "gui/auxiliary/window_builder.hpp" #include "config.hpp" +#include "gui/auxiliary/window_builder/control.hpp" #include "gui/widgets/menubar.hpp" #include "gui/widgets/scrollbar_container.hpp" namespace gui2 { -struct tbuilder_control : public tbuilder_widget -{ -private: - tbuilder_control(); -public: - - tbuilder_control(const config& cfg); - - void init_control(tcontrol* control) const; - - /** Parameters for the control. */ - std::string id; - std::string definition; - t_string label; - t_string tooltip; - t_string help; - bool use_tooltip_on_label_overflow; -}; - -struct tbuilder_button : public tbuilder_control +struct tbuilder_button : public implementation::tbuilder_control { private: @@ -63,7 +45,7 @@ private: int retval_; }; -struct tbuilder_image : public tbuilder_control +struct tbuilder_image : public implementation::tbuilder_control { /*WIKI * @page = GUIWidgetInstanceWML @@ -75,7 +57,7 @@ struct tbuilder_image : public tbuilder_control */ tbuilder_image(const config& cfg) - : tbuilder_control(cfg) + : implementation::tbuilder_control(cfg) { } @@ -104,7 +86,7 @@ struct tbuilder_gridcell : public tbuilder_widget twidget* build () const { return NULL; } }; -struct tbuilder_horizontal_scrollbar : public tbuilder_control +struct tbuilder_horizontal_scrollbar : public implementation::tbuilder_control { private: tbuilder_horizontal_scrollbar(); @@ -120,13 +102,13 @@ public: * */ tbuilder_horizontal_scrollbar(const config& cfg) : - tbuilder_control(cfg) + implementation::tbuilder_control(cfg) {} twidget* build () const; }; -struct tbuilder_label : public tbuilder_control +struct tbuilder_label : public implementation::tbuilder_control { private: @@ -139,7 +121,7 @@ public: bool wrap; }; -struct tbuilder_listbox : public tbuilder_control +struct tbuilder_listbox : public implementation::tbuilder_control { private: @@ -168,7 +150,7 @@ public: }; -struct tbuilder_menubar : public tbuilder_control +struct tbuilder_menubar : public implementation::tbuilder_control { tbuilder_menubar(const config& cfg); @@ -185,7 +167,7 @@ private: }; -struct tbuilder_minimap : public tbuilder_control +struct tbuilder_minimap : public implementation::tbuilder_control { /*WIKI * @page = GUIWidgetInstanceWML @@ -196,7 +178,7 @@ struct tbuilder_minimap : public tbuilder_control * A minimap has no extra fields. */ tbuilder_minimap(const config& cfg) : - tbuilder_control(cfg) + implementation::tbuilder_control(cfg) { } @@ -204,7 +186,7 @@ struct tbuilder_minimap : public tbuilder_control }; struct tbuilder_multi_page - : public tbuilder_control + : public implementation::tbuilder_control { private: @@ -225,7 +207,7 @@ public: std::vector data; }; -struct tbuilder_panel : public tbuilder_control +struct tbuilder_panel : public implementation::tbuilder_control { private: @@ -238,7 +220,7 @@ public: tbuilder_grid_ptr grid; }; -struct tbuilder_slider : public tbuilder_control +struct tbuilder_slider : public implementation::tbuilder_control { private: @@ -261,7 +243,7 @@ private: std::vector value_labels_; }; -struct tbuilder_scroll_label : public tbuilder_control +struct tbuilder_scroll_label : public implementation::tbuilder_control { public: /*WIKI @@ -279,7 +261,7 @@ public: * @end_table */ tbuilder_scroll_label(const config& cfg) - : tbuilder_control(cfg) + : implementation::tbuilder_control(cfg) , auto_hide_scrollbar_( utils::string_bool(cfg["auto_hide_scrollbar"], true)) { @@ -293,7 +275,7 @@ private: }; struct tbuilder_scrollbar_panel - : public tbuilder_control + : public implementation::tbuilder_control { private: @@ -310,7 +292,7 @@ public: tbuilder_grid_ptr grid; }; -struct tbuilder_spacer : public tbuilder_control +struct tbuilder_spacer : public implementation::tbuilder_control { private: @@ -336,7 +318,7 @@ public: * items. */ tbuilder_spacer(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), width_(cfg["width"]), height_(cfg["height"]) {} @@ -348,7 +330,7 @@ private: tformula height_; }; -struct tbuilder_text_box : public tbuilder_control +struct tbuilder_text_box : public implementation::tbuilder_control { private: tbuilder_text_box(); @@ -383,7 +365,7 @@ public: // copy & paste from tbuilder_text_box... // does it make more sense to inherit from it? -struct tbuilder_password_box : public tbuilder_control +struct tbuilder_password_box : public implementation::tbuilder_control { private: tbuilder_password_box(); @@ -409,14 +391,14 @@ public: * */ tbuilder_password_box(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), history_(cfg["history"]) {} twidget* build () const; }; -struct tbuilder_toggle_button : public tbuilder_control +struct tbuilder_toggle_button : public implementation::tbuilder_control { private: tbuilder_toggle_button(); @@ -437,7 +419,7 @@ public: * @end_table */ tbuilder_toggle_button(const config& cfg) : - tbuilder_control(cfg), + implementation::tbuilder_control(cfg), icon_name_(cfg["icon"]), retval_id_(cfg["return_value_id"]), retval_(lexical_cast_default(cfg["return_value"])) @@ -451,7 +433,7 @@ private: int retval_; }; -struct tbuilder_toggle_panel : public tbuilder_control +struct tbuilder_toggle_panel : public implementation::tbuilder_control { private: @@ -468,7 +450,7 @@ private: int retval_; }; -struct tbuilder_vertical_scrollbar : public tbuilder_control +struct tbuilder_vertical_scrollbar : public implementation::tbuilder_control { private: tbuilder_vertical_scrollbar(); @@ -484,7 +466,7 @@ public: * */ tbuilder_vertical_scrollbar(const config& cfg) : - tbuilder_control(cfg) + implementation::tbuilder_control(cfg) {} twidget* build () const;