Move gui2::tbuilder_listbox to its own file.

This commit is contained in:
Mark de Wever 2009-07-04 12:04:37 +00:00
parent 7ab1272200
commit 78a18c071a
9 changed files with 222 additions and 152 deletions

View file

@ -12,6 +12,7 @@ src/gui/auxiliary/window_builder/helper.cpp
src/gui/auxiliary/window_builder/horizontal_scrollbar.cpp
src/gui/auxiliary/window_builder/image.cpp
src/gui/auxiliary/window_builder/label.cpp
src/gui/auxiliary/window_builder/listbox.cpp
src/gui/auxiliary/window_builder/minimap.cpp
src/gui/auxiliary/window_builder/menubar.cpp
src/gui/auxiliary/window_builder/spacer.cpp

View file

@ -270,6 +270,7 @@ SET(wesnoth-main_SRC
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
gui/auxiliary/window_builder/image.cpp
gui/auxiliary/window_builder/label.cpp
gui/auxiliary/window_builder/listbox.cpp
gui/auxiliary/window_builder/minimap.cpp
gui/auxiliary/window_builder/menubar.cpp
gui/auxiliary/window_builder/spacer.cpp

View file

@ -95,6 +95,7 @@ wesnoth_source = \
gui/auxiliary/window_builder/horizontal_scrollbar.cpp \
gui/auxiliary/window_builder/image.cpp \
gui/auxiliary/window_builder/label.cpp \
gui/auxiliary/window_builder/listbox.cpp \
gui/auxiliary/window_builder/minimap.cpp \
gui/auxiliary/window_builder/menubar.cpp \
gui/auxiliary/window_builder/spacer.cpp \

View file

@ -251,6 +251,7 @@ wesnoth_sources = Split("""
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
gui/auxiliary/window_builder/image.cpp
gui/auxiliary/window_builder/label.cpp
gui/auxiliary/window_builder/listbox.cpp
gui/auxiliary/window_builder/minimap.cpp
gui/auxiliary/window_builder/menubar.cpp
gui/auxiliary/window_builder/spacer.cpp

View file

@ -25,6 +25,7 @@
#include "gui/auxiliary/window_builder/horizontal_scrollbar.hpp"
#include "gui/auxiliary/window_builder/image.hpp"
#include "gui/auxiliary/window_builder/label.hpp"
#include "gui/auxiliary/window_builder/listbox.hpp"
#include "gui/auxiliary/window_builder/minimap.hpp"
#include "gui/auxiliary/window_builder/menubar.hpp"
#include "gui/auxiliary/window_builder/spacer.hpp"
@ -401,128 +402,6 @@ tbuilder_gridcell::tbuilder_gridcell(const config& cfg) :
{
}
tbuilder_listbox::tbuilder_listbox(const config& cfg) :
implementation::tbuilder_control(cfg),
vertical_scrollbar_mode(
get_scrollbar_mode(cfg["vertical_scrollbar_mode"])),
horizontal_scrollbar_mode(
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"])),
header(0),
footer(0),
list_builder(0),
list_data()
{
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_listbox
*
* == Listbox ==
*
* Instance of a listbox.
*
* List with the listbox specific variables:
* @start_table = config
* vertical_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* auto.
* horizontal_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* initial_auto.
*
* header (grid = []) Defines the grid for the optional
* header. (This grid will automatically
* get the id _header_grid.)
* footer (grid = []) Defines the grid for the optional
* footer. (This grid will automatically
* get the id _footer_grid.)
*
* list_definition (section) This defines how a listbox item
* looks. It must contain the grid
* definition for 1 row of the list.
*
* list_data(section = []) A grid alike section which stores the
* initial data for the listbox. Every row
* must have the same number of columns as
* the 'list_definition'.
* @end_table
*
*
* Inside the list section there are only the following widgets allowed
* * grid (to nest)
* * selectable widgets which are
* ** toggle_button
* ** toggle_panel
*
*/
if (const config &h = cfg.child("header"))
header = new tbuilder_grid(h);
if (const config &f = cfg.child("footer"))
footer = new tbuilder_grid(f);
const config &l = cfg.child("list_definition");
VALIDATE(l, _("No list defined."));
list_builder = new tbuilder_grid(l);
assert(list_builder);
VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row."));
const config &data = cfg.child("list_data");
if (!data) return;
foreach (const config &row, data.child_range("row"))
{
unsigned col = 0;
foreach (const config &c, row.child_range("column"))
{
list_data.push_back(string_map());
foreach (const config::attribute &i, c.attribute_range()) {
list_data.back()[i.first] = i.second;
}
++col;
}
VALIDATE(col == list_builder->cols, _("'list_data' must have "
"the same number of columns as the 'list_definition'."));
}
}
twidget* tbuilder_listbox::build() const
{
tlistbox *listbox = new tlistbox(
true, true, tgenerator_::vertical_list, true);
init_control(listbox);
listbox->set_list_builder(list_builder); // FIXME in finalize???
listbox->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
listbox->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
DBG_GUI_G << "Window builder: placed listbox '" << id << "' with defintion '"
<< definition << "'.\n";
boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const tlistbox_definition::tresolution>(listbox->config());
assert(conf);
listbox->init_grid(conf->grid);
listbox->finalize(header, footer, list_data);
return listbox;
}
tbuilder_multi_page::tbuilder_multi_page(const config& cfg) :
implementation::tbuilder_control(cfg),
builder(0),

View file

@ -0,0 +1,156 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2009 by Mark de Wever <koraq@xs4all.nl>
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/listbox.hpp"
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/auxiliary/window_builder/helper.hpp"
#include "gui/widgets/listbox.hpp"
#include "wml_exception.hpp"
namespace gui2 {
namespace implementation {
tbuilder_listbox::tbuilder_listbox(const config& cfg)
: tbuilder_control(cfg)
, vertical_scrollbar_mode(
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
, horizontal_scrollbar_mode(
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, header(NULL)
, footer(NULL)
, list_builder(NULL)
, list_data()
{
if(const config &h = cfg.child("header")) {
header = new tbuilder_grid(h);
}
if(const config &f = cfg.child("footer")) {
footer = new tbuilder_grid(f);
}
const config &l = cfg.child("list_definition");
VALIDATE(l, _("No list defined."));
list_builder = new tbuilder_grid(l);
assert(list_builder);
VALIDATE(list_builder->rows == 1
, _("A 'list_definition' should contain one row."));
const config &data = cfg.child("list_data");
if (!data) return;
foreach(const config &row, data.child_range("row")) {
unsigned col = 0;
foreach(const config &c, row.child_range("column")) {
list_data.push_back(string_map());
foreach (const config::attribute &i, c.attribute_range()) {
list_data.back()[i.first] = i.second;
}
++col;
}
VALIDATE(col == list_builder->cols, _("'list_data' must have "
"the same number of columns as the 'list_definition'."));
}
}
twidget* tbuilder_listbox::build() const
{
tlistbox *widget = new tlistbox(
true, true, tgenerator_::vertical_list, true);
init_control(widget);
widget->set_list_builder(list_builder); // FIXME in finalize???
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
DBG_GUI_G << "Window builder: placed listbox '"
<< id << "' with defintion '"
<< definition << "'.\n";
boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const tlistbox_definition::tresolution>(widget->config());
assert(conf);
widget->init_grid(conf->grid);
widget->finalize(header, footer, list_data);
return widget;
}
} // namespace implementation
} // namespace gui2
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_listbox
*
* == Listbox ==
*
* Instance of a listbox.
*
* List with the listbox specific variables:
* @start_table = config
* vertical_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* auto.
* horizontal_scrollbar_mode (scrollbar_mode = auto | initial_auto)
* Determines whether or not to show the
* scrollbar. The default of initial_auto
* is used when --new-widgets is used.
* In the future the default will be
* initial_auto.
*
* header (grid = []) Defines the grid for the optional
* header. (This grid will automatically
* get the id _header_grid.)
* footer (grid = []) Defines the grid for the optional
* footer. (This grid will automatically
* get the id _footer_grid.)
*
* list_definition (section) This defines how a listbox item
* looks. It must contain the grid
* definition for 1 row of the list.
*
* list_data(section = []) A grid alike section which stores the
* initial data for the listbox. Every row
* must have the same number of columns as
* the 'list_definition'.
* @end_table
*
*
* Inside the list section there are only the following widgets allowed
* * grid (to nest)
* * selectable widgets which are
* ** toggle_button
* ** toggle_panel
*
*/

View file

@ -0,0 +1,56 @@
/* $Id$ */
/*
Copyright (C) 2008 - 2009 by Mark de Wever <koraq@xs4all.nl>
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_LISTBOX_HPP_INCLUDED
#define GUI_AUXILIARY_WINDOW_BUILDER_LISTBOX_HPP_INCLUDED
#include "gui/auxiliary/window_builder/control.hpp"
#include "gui/widgets/scrollbar_container.hpp"
namespace gui2 {
namespace implementation {
struct tbuilder_listbox
: public tbuilder_control
{
tbuilder_listbox(const config& cfg);
twidget* build () const;
tscrollbar_container::tscrollbar_mode
vertical_scrollbar_mode,
horizontal_scrollbar_mode;
tbuilder_grid_ptr header;
tbuilder_grid_ptr footer;
tbuilder_grid_ptr list_builder;
/**
* Listbox data.
*
* Contains a vector with the data to set in every cell, it's used to
* serialize the data in the config, so the config is no longer required.
*/
std::vector<string_map>list_data;
};
} // namespace implementation
} // namespace gui2
#endif

View file

@ -52,35 +52,6 @@ struct tbuilder_gridcell : public tbuilder_widget
twidget* build () const { return NULL; }
};
struct tbuilder_listbox : public implementation::tbuilder_control
{
private:
tbuilder_listbox();
public:
tbuilder_listbox(const config& cfg);
twidget* build () const;
tscrollbar_container::tscrollbar_mode
vertical_scrollbar_mode,
horizontal_scrollbar_mode;
tbuilder_grid_ptr header;
tbuilder_grid_ptr footer;
tbuilder_grid_ptr list_builder;
/**
* Listbox data.
*
* Contains a vector with the data to set in every cell, it's used to
* serialize the data in the config, so the config is no longer required.
*/
std::vector<string_map>list_data;
};
struct tbuilder_multi_page
: public implementation::tbuilder_control
{

View file

@ -21,11 +21,15 @@
namespace gui2 {
namespace implementation {
struct tbuilder_listbox;
}
/** The listbox class. */
class tlistbox
: public tscrollbar_container
{
friend struct tbuilder_listbox;
friend struct implementation::tbuilder_listbox;
friend class tdebug_layout_graph;
public:
/**