Add a second constructor to tcontrol.

This constructor sets its state based on the structure send to it
instead of using a second call that sets the fields later.

The code is used to experiment with a different approach of the
implementation of a listbox.
This commit is contained in:
Mark de Wever 2012-05-17 16:22:00 +00:00
parent 75757e52e1
commit 3abebe12f3
3 changed files with 93 additions and 7 deletions

View file

@ -31,6 +31,7 @@ public:
tbuilder_control(const config& cfg);
/** @deprecated The control can initalise itself. */
void init_control(tcontrol* control) const;
/** Parameters for the control. */

View file

@ -26,6 +26,7 @@
#include "gui/dialogs/tip.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "gui/auxiliary/window_builder/control.hpp"
#include "marked-up_text.hpp"
#include <boost/bind.hpp>
@ -73,6 +74,52 @@ tcontrol::tcontrol(const unsigned canvas_count)
, _3));
}
tcontrol::tcontrol(
const implementation::tbuilder_control& builder
, const unsigned canvas_count)
: definition_(builder.definition)
, label_(builder.label)
, use_markup_(false)
, use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
, tooltip_(builder.tooltip)
, help_message_(builder.help)
, canvas_(canvas_count)
, config_(NULL)
, renderer_()
, text_maximum_width_(0)
, text_alignment_(PANGO_ALIGN_LEFT)
, shrunken_(false)
{
set_id(builder.id);
set_linked_group(builder.linked_group);
#ifndef LOW_MEM
set_debug_border_mode(builder.debug_border_mode);
set_debug_border_color(builder.debug_border_color);
#endif
definition_load_configuration();
connect_signal<event::SHOW_TOOLTIP>(boost::bind(
&tcontrol::signal_handler_show_tooltip
, this
, _2
, _3
, _5));
connect_signal<event::SHOW_HELPTIP>(boost::bind(
&tcontrol::signal_handler_show_helptip
, this
, _2
, _3
, _5));
connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(boost::bind(
&tcontrol::signal_handler_notify_remove_tooltip
, this
, _2
, _3));
}
void tcontrol::set_members(const string_map& data)
{
/** @todo document this feature on the wiki. */
@ -240,14 +287,8 @@ void tcontrol::place(const tpoint& origin, const tpoint& size)
void tcontrol::load_config()
{
if(!config()) {
set_config(get_control(get_control_type(), definition_));
assert(canvas().size() == config()->state.size());
for(size_t i = 0; i < canvas().size(); ++i) {
canvas(i) = config()->state[i].canvas;
}
update_canvas();
definition_load_configuration();
load_config_extra();
}
@ -361,6 +402,20 @@ void tcontrol::impl_draw_background(
, calculate_blitting_rectangle(x_offset, y_offset));
}
void tcontrol::definition_load_configuration()
{
assert(!config());
set_config(get_control(get_control_type(), definition_));
assert(canvas().size() == config()->state.size());
for(size_t i = 0; i < canvas().size(); ++i) {
canvas(i) = config()->state[i].canvas;
}
update_canvas();
}
tpoint tcontrol::get_best_text_size(
const tpoint& minimum_size
, const tpoint& maximum_size) const

View file

@ -22,14 +22,31 @@
namespace gui2 {
namespace implementation {
class tbuilder_control;
} // namespace implementation
/** Base class for all visible items. */
class tcontrol : public virtual twidget
{
friend class tdebug_layout_graph;
public:
/** @deprecated Used the second overload. */
explicit tcontrol(const unsigned canvas_count);
/**
* Constructor.
*
* @param builder The builder object with the settings for the
* object.
*
* @param canvas_count The number of canvasses in the control.
*/
tcontrol(
const implementation::tbuilder_control& builder
, const unsigned canvas_count);
/**
* Sets the members of the control.
*
@ -148,6 +165,8 @@ private:
* determine sizes and drawing the widget this definition needs to be
* loaded. The member definition_ contains the name of the definition and
* function load the proper configuration.
*
* @depreciated @ref definition_load_configuration() is the replacement.
*/
void load_config();
@ -332,6 +351,17 @@ private:
* does nothing but classes can override it to implement custom behaviour.
*/
virtual void load_config_extra() {}
/**
* Loads the configuration of the widget.
*
* Controls have their definition stored in a definition object. In order to
* determine sizes and drawing the widget this definition needs to be
* loaded. The member definition_ contains the name of the definition and
* function load the proper configuration.
*/
void definition_load_configuration();
public:
/**
* Returns the control_type of the control.