Skip to content

Commit

Permalink
GUI2: added a public static type getter to all widgets implementing g…
Browse files Browse the repository at this point in the history
…et_control_type

Fixes #2400. See comment in styled_widget.hpp for details.
  • Loading branch information
Vultraz authored and gfgtdf committed Oct 7, 2018
1 parent f637283 commit 90518b6
Show file tree
Hide file tree
Showing 64 changed files with 221 additions and 38 deletions.
10 changes: 8 additions & 2 deletions src/gui/core/register_widget.hpp
Expand Up @@ -57,10 +57,16 @@
*
* "Calls" REGISTER_WIDGET3(id_definition, id, nullptr)
*/
#define REGISTER_WIDGET(id) REGISTER_WIDGET3(id##_definition, id, nullptr) \
#define REGISTER_WIDGET(id) \
REGISTER_WIDGET3(id##_definition, id, nullptr) \
\
const std::string& id::get_control_type() const \
const std::string& id::type() \
{ \
static const std::string result(#id); \
return result; \
} \
\
const std::string& id::get_control_type() const \
{ \
return id::type(); \
}
2 changes: 1 addition & 1 deletion src/gui/widgets/addon_list.cpp
Expand Up @@ -50,7 +50,7 @@ const unsigned CONTROL_STACK_LAYER_PUBLISH = 2;
REGISTER_WIDGET(addon_list)

addon_list::addon_list(const implementation::builder_addon_list& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, addon_vector_()
, install_status_visibility_(visibility::visible)
, install_buttons_visibility_(visibility::invisible)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/addon_list.hpp
Expand Up @@ -177,6 +177,11 @@ class addon_list : public container_base
/** Needed because otherwise the add-on with the first ID would be initially selected. */
void select_first_addon();

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/button.cpp
Expand Up @@ -41,7 +41,7 @@ namespace gui2
REGISTER_WIDGET(button)

button::button(const implementation::builder_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, clickable_item()
, state_(ENABLED)
, retval_(retval::NONE)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/button.hpp
Expand Up @@ -97,6 +97,11 @@ class button : public styled_widget, public clickable_item
*/
int retval_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/chatbox.cpp
Expand Up @@ -55,7 +55,7 @@ namespace gui2
REGISTER_WIDGET(chatbox)

chatbox::chatbox(const implementation::builder_chatbox& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, roomlistbox_(nullptr)
, chat_log_container_(nullptr)
, chat_input_(nullptr)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/chatbox.hpp
Expand Up @@ -150,6 +150,11 @@ class chatbox : public container_base, public events::chat_handler

std::map<std::string, chatroom_log>* log_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/drawing.cpp
Expand Up @@ -32,7 +32,7 @@ namespace gui2
REGISTER_WIDGET(drawing)

drawing::drawing(const implementation::builder_drawing& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, best_size_(0, 0)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/drawing.hpp
Expand Up @@ -103,6 +103,11 @@ class drawing : public styled_widget
/** When we're used as a fixed size item, this holds the best size. */
point best_size_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/horizontal_scrollbar.cpp
Expand Up @@ -34,7 +34,7 @@ namespace gui2
REGISTER_WIDGET(horizontal_scrollbar)

horizontal_scrollbar::horizontal_scrollbar(const implementation::builder_horizontal_scrollbar& builder)
: scrollbar_base(builder, get_control_type())
: scrollbar_base(builder, type())
{
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/horizontal_scrollbar.hpp
Expand Up @@ -70,6 +70,11 @@ class horizontal_scrollbar : public scrollbar_base
return current.x - original.x;
}

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/image.cpp
Expand Up @@ -37,7 +37,7 @@ namespace gui2
REGISTER_WIDGET(image)

image::image(const implementation::builder_image& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
{
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/image.hpp
Expand Up @@ -93,6 +93,11 @@ class image : public styled_widget
ENABLED,
};

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/label.cpp
Expand Up @@ -41,7 +41,7 @@ namespace gui2
REGISTER_WIDGET(label)

label::label(const implementation::builder_label& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, state_(ENABLED)
, can_wrap_(false)
, characters_per_line_(0)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/label.hpp
Expand Up @@ -134,6 +134,11 @@ class label : public styled_widget
return can_shrink_;
}

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/list.hpp
Expand Up @@ -271,6 +271,11 @@ class list_view : public container_base
/** See @ref container_base::set_self_active. */
virtual void set_self_active(const bool active) override;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/listbox.cpp
Expand Up @@ -55,7 +55,7 @@ listbox::listbox(const implementation::builder_styled_widget& builder,
const bool has_minimum,
const bool has_maximum,
const bool select)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
, generator_(generator_base::build(has_minimum, has_maximum, placement, select))
, is_horizontal_(placement == generator_base::horizontal_list)
, list_builder_(list_builder)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/listbox.hpp
Expand Up @@ -417,6 +417,11 @@ class listbox : public scrollbar_container
/** Inherited from scrollbar_container. */
virtual void set_content_size(const point& origin, const point& size) override;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/matrix.hpp
Expand Up @@ -224,6 +224,11 @@ class matrix : public tbase
*/
pane* pane_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/menu_button.cpp
Expand Up @@ -38,7 +38,7 @@ namespace gui2
REGISTER_WIDGET(menu_button)

menu_button::menu_button(const implementation::builder_menu_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, selectable_item()
, state_(ENABLED)
, values_()
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/menu_button.hpp
Expand Up @@ -115,6 +115,11 @@ class menu_button : public styled_widget, public selectable_item

bool keep_open_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/minimap.cpp
Expand Up @@ -48,7 +48,7 @@ namespace gui2
REGISTER_WIDGET(minimap)

minimap::minimap(const implementation::builder_minimap& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, map_data_()
, terrain_(nullptr)
{
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/minimap.hpp
Expand Up @@ -106,6 +106,11 @@ class minimap : public styled_widget
int x_offset,
int y_offset) override;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/multi_page.cpp
Expand Up @@ -34,7 +34,7 @@ namespace gui2
REGISTER_WIDGET(multi_page)

multi_page::multi_page(const implementation::builder_multi_page& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, generator_(generator_base::build(true, true, generator_base::independent, false))
, page_builders_()
{
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/multi_page.hpp
Expand Up @@ -205,6 +205,11 @@ class multi_page : public container_base
int x_offset,
int y_offset) override;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/multimenu_button.cpp
Expand Up @@ -40,7 +40,7 @@ namespace gui2
REGISTER_WIDGET(multimenu_button)

multimenu_button::multimenu_button(const implementation::builder_multimenu_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, state_(ENABLED)
, max_shown_(1)
, values_()
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/multimenu_button.hpp
Expand Up @@ -161,6 +161,11 @@ class multimenu_button : public styled_widget
void update_config_from_toggle_states();
void update_label();

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/panel.cpp
Expand Up @@ -36,7 +36,7 @@ namespace gui2
REGISTER_WIDGET(panel)

panel::panel(const implementation::builder_styled_widget& builder, const std::string& control_type)
: container_base(builder, control_type.empty() ? get_control_type() : control_type)
: container_base(builder, control_type.empty() ? type() : control_type)
{
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/panel.hpp
Expand Up @@ -62,6 +62,11 @@ class panel : public container_base
int x_offset,
int y_offset) override;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
7 changes: 6 additions & 1 deletion src/gui/widgets/password_box.cpp
Expand Up @@ -101,12 +101,17 @@ void password_box::paste_selection(const bool mouse)
insert_char(text);
}

const std::string& password_box::get_control_type() const
const std::string& password_box::type() \
{
static const std::string type = "password_box";
return type;
}

const std::string& password_box::get_control_type() const
{
return type();
}

// }---------- BUILDER -----------{

namespace implementation
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/password_box.hpp
Expand Up @@ -60,6 +60,11 @@ class password_box : public text_box

std::string real_value_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** See @ref styled_widget::get_control_type. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/progress_bar.cpp
Expand Up @@ -33,7 +33,7 @@ namespace gui2
REGISTER_WIDGET(progress_bar)

progress_bar::progress_bar(const implementation::builder_progress_bar& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, percentage_(static_cast<unsigned>(-1))
{
// Force canvas update
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/progress_bar.hpp
Expand Up @@ -69,6 +69,11 @@ class progress_bar : public styled_widget
/** The percentage done. */
unsigned percentage_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/repeating_button.cpp
Expand Up @@ -36,7 +36,7 @@ namespace gui2
REGISTER_WIDGET(repeating_button)

repeating_button::repeating_button(const implementation::builder_repeating_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, clickable_item()
, state_(ENABLED)
, repeat_timer_(0)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/repeating_button.hpp
Expand Up @@ -102,6 +102,11 @@ class repeating_button : public styled_widget, public clickable_item
/** The timer for the repeating events. */
size_t repeat_timer_;

public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();

private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/scroll_label.cpp
Expand Up @@ -40,7 +40,7 @@ namespace gui2
REGISTER_WIDGET(scroll_label)

scroll_label::scroll_label(const implementation::builder_scroll_label& builder)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
, state_(ENABLED)
, wrap_on_(builder.wrap_on)
, text_alignment_(builder.text_alignment)
Expand Down

0 comments on commit 90518b6

Please sign in to comment.