diff --git a/src/gui/core/register_widget.hpp b/src/gui/core/register_widget.hpp index f554cd7497c9..f08c860ad3e8 100644 --- a/src/gui/core/register_widget.hpp +++ b/src/gui/core/register_widget.hpp @@ -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(); \ } diff --git a/src/gui/widgets/addon_list.cpp b/src/gui/widgets/addon_list.cpp index 8e7fd5d5dd07..c3f564cd254f 100644 --- a/src/gui/widgets/addon_list.cpp +++ b/src/gui/widgets/addon_list.cpp @@ -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) diff --git a/src/gui/widgets/addon_list.hpp b/src/gui/widgets/addon_list.hpp index ea5aae91af3f..517cb21a63ca 100644 --- a/src/gui/widgets/addon_list.hpp +++ b/src/gui/widgets/addon_list.hpp @@ -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; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 00a859b6e873..a09784a9de22 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -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) diff --git a/src/gui/widgets/button.hpp b/src/gui/widgets/button.hpp index af000cac4a77..b24fef5f3b62 100644 --- a/src/gui/widgets/button.hpp +++ b/src/gui/widgets/button.hpp @@ -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; diff --git a/src/gui/widgets/chatbox.cpp b/src/gui/widgets/chatbox.cpp index 5bf63d6df5b7..07cee0b42875 100644 --- a/src/gui/widgets/chatbox.cpp +++ b/src/gui/widgets/chatbox.cpp @@ -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) diff --git a/src/gui/widgets/chatbox.hpp b/src/gui/widgets/chatbox.hpp index c9e123cdf4d7..8f1f20db49d8 100644 --- a/src/gui/widgets/chatbox.hpp +++ b/src/gui/widgets/chatbox.hpp @@ -150,6 +150,11 @@ class chatbox : public container_base, public events::chat_handler std::map* 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; diff --git a/src/gui/widgets/drawing.cpp b/src/gui/widgets/drawing.cpp index 121a9aab5a7c..db424a08deba 100644 --- a/src/gui/widgets/drawing.cpp +++ b/src/gui/widgets/drawing.cpp @@ -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) { } diff --git a/src/gui/widgets/drawing.hpp b/src/gui/widgets/drawing.hpp index 77af01473d61..045fdb87ef83 100644 --- a/src/gui/widgets/drawing.hpp +++ b/src/gui/widgets/drawing.hpp @@ -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; }; diff --git a/src/gui/widgets/horizontal_scrollbar.cpp b/src/gui/widgets/horizontal_scrollbar.cpp index 5b4ad06ec6b2..afb40e51264c 100644 --- a/src/gui/widgets/horizontal_scrollbar.cpp +++ b/src/gui/widgets/horizontal_scrollbar.cpp @@ -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()) { } diff --git a/src/gui/widgets/horizontal_scrollbar.hpp b/src/gui/widgets/horizontal_scrollbar.hpp index e992c4e148c7..36b23d6f5ff5 100644 --- a/src/gui/widgets/horizontal_scrollbar.hpp +++ b/src/gui/widgets/horizontal_scrollbar.hpp @@ -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; }; diff --git a/src/gui/widgets/image.cpp b/src/gui/widgets/image.cpp index 840f7b22a43d..44800adbb840 100644 --- a/src/gui/widgets/image.cpp +++ b/src/gui/widgets/image.cpp @@ -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()) { } diff --git a/src/gui/widgets/image.hpp b/src/gui/widgets/image.hpp index efbf1e2cac0e..9f3c160bbc92 100644 --- a/src/gui/widgets/image.hpp +++ b/src/gui/widgets/image.hpp @@ -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; }; diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index ebaef8cdf2ed..b25d1e1829ed 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -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) diff --git a/src/gui/widgets/label.hpp b/src/gui/widgets/label.hpp index eb50f8931b2a..8f168a1c9380 100644 --- a/src/gui/widgets/label.hpp +++ b/src/gui/widgets/label.hpp @@ -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; diff --git a/src/gui/widgets/list.hpp b/src/gui/widgets/list.hpp index 1b4474f3c4fd..756691a9e3ee 100644 --- a/src/gui/widgets/list.hpp +++ b/src/gui/widgets/list.hpp @@ -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; diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index b68f7c6d0a0b..52742993ab24 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -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) diff --git a/src/gui/widgets/listbox.hpp b/src/gui/widgets/listbox.hpp index 6046c35801c5..5ae8b5105045 100644 --- a/src/gui/widgets/listbox.hpp +++ b/src/gui/widgets/listbox.hpp @@ -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; diff --git a/src/gui/widgets/matrix.hpp b/src/gui/widgets/matrix.hpp index dd51e53cd230..7bbc10a1265e 100644 --- a/src/gui/widgets/matrix.hpp +++ b/src/gui/widgets/matrix.hpp @@ -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; }; diff --git a/src/gui/widgets/menu_button.cpp b/src/gui/widgets/menu_button.cpp index cb198f274a81..da0587d72fab 100644 --- a/src/gui/widgets/menu_button.cpp +++ b/src/gui/widgets/menu_button.cpp @@ -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_() diff --git a/src/gui/widgets/menu_button.hpp b/src/gui/widgets/menu_button.hpp index 83fa2d777b19..6611670481d4 100644 --- a/src/gui/widgets/menu_button.hpp +++ b/src/gui/widgets/menu_button.hpp @@ -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; diff --git a/src/gui/widgets/minimap.cpp b/src/gui/widgets/minimap.cpp index d0b756a0cf51..dacb50618b51 100644 --- a/src/gui/widgets/minimap.cpp +++ b/src/gui/widgets/minimap.cpp @@ -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) { diff --git a/src/gui/widgets/minimap.hpp b/src/gui/widgets/minimap.hpp index 9a755f727db0..4d73e8cf7fdd 100644 --- a/src/gui/widgets/minimap.hpp +++ b/src/gui/widgets/minimap.hpp @@ -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; }; diff --git a/src/gui/widgets/multi_page.cpp b/src/gui/widgets/multi_page.cpp index bd853985cb3c..8a23c04624c2 100644 --- a/src/gui/widgets/multi_page.cpp +++ b/src/gui/widgets/multi_page.cpp @@ -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_() { diff --git a/src/gui/widgets/multi_page.hpp b/src/gui/widgets/multi_page.hpp index 75ec7ed71c72..8b73e16a6033 100644 --- a/src/gui/widgets/multi_page.hpp +++ b/src/gui/widgets/multi_page.hpp @@ -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; diff --git a/src/gui/widgets/multimenu_button.cpp b/src/gui/widgets/multimenu_button.cpp index f0a9cfaee593..4df11ee4952a 100644 --- a/src/gui/widgets/multimenu_button.cpp +++ b/src/gui/widgets/multimenu_button.cpp @@ -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_() diff --git a/src/gui/widgets/multimenu_button.hpp b/src/gui/widgets/multimenu_button.hpp index 13a2fbf884c5..899c37bec009 100644 --- a/src/gui/widgets/multimenu_button.hpp +++ b/src/gui/widgets/multimenu_button.hpp @@ -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; diff --git a/src/gui/widgets/panel.cpp b/src/gui/widgets/panel.cpp index 43156f565cce..e3bcb36316c0 100644 --- a/src/gui/widgets/panel.cpp +++ b/src/gui/widgets/panel.cpp @@ -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) { } diff --git a/src/gui/widgets/panel.hpp b/src/gui/widgets/panel.hpp index ec1ace637fe6..87cc352b0926 100644 --- a/src/gui/widgets/panel.hpp +++ b/src/gui/widgets/panel.hpp @@ -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; diff --git a/src/gui/widgets/password_box.cpp b/src/gui/widgets/password_box.cpp index f8d9951ac644..e7b81ccf3acd 100644 --- a/src/gui/widgets/password_box.cpp +++ b/src/gui/widgets/password_box.cpp @@ -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 diff --git a/src/gui/widgets/password_box.hpp b/src/gui/widgets/password_box.hpp index 5619a0ab48e4..e487c2b1f39c 100644 --- a/src/gui/widgets/password_box.hpp +++ b/src/gui/widgets/password_box.hpp @@ -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; }; diff --git a/src/gui/widgets/progress_bar.cpp b/src/gui/widgets/progress_bar.cpp index 74f7d1bb1c9f..3a3a87bcaa44 100644 --- a/src/gui/widgets/progress_bar.cpp +++ b/src/gui/widgets/progress_bar.cpp @@ -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(-1)) { // Force canvas update diff --git a/src/gui/widgets/progress_bar.hpp b/src/gui/widgets/progress_bar.hpp index d037adc9fd81..0823d95d393f 100644 --- a/src/gui/widgets/progress_bar.hpp +++ b/src/gui/widgets/progress_bar.hpp @@ -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; }; diff --git a/src/gui/widgets/repeating_button.cpp b/src/gui/widgets/repeating_button.cpp index 2b4121ae5f17..68aedf5a56d8 100644 --- a/src/gui/widgets/repeating_button.cpp +++ b/src/gui/widgets/repeating_button.cpp @@ -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) diff --git a/src/gui/widgets/repeating_button.hpp b/src/gui/widgets/repeating_button.hpp index 4597e6a4d38f..a7fdbf019f8d 100644 --- a/src/gui/widgets/repeating_button.hpp +++ b/src/gui/widgets/repeating_button.hpp @@ -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; diff --git a/src/gui/widgets/scroll_label.cpp b/src/gui/widgets/scroll_label.cpp index f04395169502..a2cd7ea26ff7 100644 --- a/src/gui/widgets/scroll_label.cpp +++ b/src/gui/widgets/scroll_label.cpp @@ -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) diff --git a/src/gui/widgets/scroll_label.hpp b/src/gui/widgets/scroll_label.hpp index 6b7ec6855e52..22d2bd505ad9 100644 --- a/src/gui/widgets/scroll_label.hpp +++ b/src/gui/widgets/scroll_label.hpp @@ -103,6 +103,11 @@ class scroll_label : public scrollbar_container label* get_internal_label(); +public: + /** Static type getter that does not rely on the widget being constructed. */ + static const std::string& type(); + +private: /***** ***** ***** inherited ****** *****/ /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */ diff --git a/src/gui/widgets/scrollbar_container.cpp b/src/gui/widgets/scrollbar_container.cpp index fa08b0c63e8b..937e6dbc67f9 100644 --- a/src/gui/widgets/scrollbar_container.cpp +++ b/src/gui/widgets/scrollbar_container.cpp @@ -1081,12 +1081,17 @@ void scrollbar_container::scrollbar_moved() set_scrollbar_button_status(); } -const std::string& scrollbar_container::get_control_type() const +const std::string& scrollbar_container::type() { static const std::string type = "scrollbar_container"; return type; } +const std::string& scrollbar_container::get_control_type() const +{ + return type(); +} + void scrollbar_container::signal_handler_sdl_key_down( const event::ui_event event, bool& handled, const SDL_Keycode key, SDL_Keymod modifier) { diff --git a/src/gui/widgets/scrollbar_container.hpp b/src/gui/widgets/scrollbar_container.hpp index b505a0cad9cf..3b47fb7dc450 100644 --- a/src/gui/widgets/scrollbar_container.hpp +++ b/src/gui/widgets/scrollbar_container.hpp @@ -525,6 +525,11 @@ class scrollbar_container : public container_base /** Helper function which needs to be called after the scollbar moved. */ void scrollbar_moved(); +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; diff --git a/src/gui/widgets/scrollbar_panel.cpp b/src/gui/widgets/scrollbar_panel.cpp index 54760222b572..d065dd5b9bd4 100644 --- a/src/gui/widgets/scrollbar_panel.cpp +++ b/src/gui/widgets/scrollbar_panel.cpp @@ -33,7 +33,7 @@ namespace gui2 REGISTER_WIDGET(scrollbar_panel) scrollbar_panel::scrollbar_panel(const implementation::builder_scrollbar_panel& builder) - : scrollbar_container(builder, get_control_type()) + : scrollbar_container(builder, type()) { } diff --git a/src/gui/widgets/scrollbar_panel.hpp b/src/gui/widgets/scrollbar_panel.hpp index 9f5bb8eec8e0..eb5389b13412 100644 --- a/src/gui/widgets/scrollbar_panel.hpp +++ b/src/gui/widgets/scrollbar_panel.hpp @@ -51,6 +51,9 @@ class scrollbar_panel : public scrollbar_container /** See @ref styled_widget::get_state. */ virtual unsigned get_state() const override; + /** 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; diff --git a/src/gui/widgets/size_lock.cpp b/src/gui/widgets/size_lock.cpp index b1bbcb94c0d0..d8ca3a8f5d01 100644 --- a/src/gui/widgets/size_lock.cpp +++ b/src/gui/widgets/size_lock.cpp @@ -28,7 +28,7 @@ namespace gui2 REGISTER_WIDGET(size_lock) size_lock::size_lock(const implementation::builder_size_lock& builder) - : container_base(builder, get_control_type()) + : container_base(builder, type()) , width_(builder.width_) , height_(builder.height_) , widget_(nullptr) diff --git a/src/gui/widgets/size_lock.hpp b/src/gui/widgets/size_lock.hpp index 1947da7f6952..647e0b95c8a7 100644 --- a/src/gui/widgets/size_lock.hpp +++ b/src/gui/widgets/size_lock.hpp @@ -78,6 +78,11 @@ class size_lock : public container_base */ void finalize(builder_widget_const_ptr widget_builder); +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; diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index f74b69964c08..872804efddf4 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -47,7 +47,7 @@ namespace gui2 REGISTER_WIDGET(slider) slider::slider(const implementation::builder_slider& builder) - : slider_base(builder, get_control_type()) + : slider_base(builder, type()) , best_slider_length_(0) , minimum_value_(0) , step_size_(1) diff --git a/src/gui/widgets/slider.hpp b/src/gui/widgets/slider.hpp index f3af2cc3995a..718e5f60c4ca 100644 --- a/src/gui/widgets/slider.hpp +++ b/src/gui/widgets/slider.hpp @@ -196,6 +196,11 @@ class slider : public slider_base, public integer_selector // void update_current_item_mouse_position(); +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; diff --git a/src/gui/widgets/spacer.cpp b/src/gui/widgets/spacer.cpp index 82c44bd9ac13..e328c2ceab74 100644 --- a/src/gui/widgets/spacer.cpp +++ b/src/gui/widgets/spacer.cpp @@ -29,7 +29,7 @@ namespace gui2 REGISTER_WIDGET(spacer) spacer::spacer(const implementation::builder_spacer& builder, const std::string& w, const std::string& h) - : styled_widget(builder, get_control_type()) + : styled_widget(builder, type()) , width_(w) , height_(h) { diff --git a/src/gui/widgets/spacer.hpp b/src/gui/widgets/spacer.hpp index 64b820793819..90c9f33cb572 100644 --- a/src/gui/widgets/spacer.hpp +++ b/src/gui/widgets/spacer.hpp @@ -83,6 +83,11 @@ class spacer : 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; }; diff --git a/src/gui/widgets/stacked_widget.cpp b/src/gui/widgets/stacked_widget.cpp index 4fa526afcd32..52c5d2c62e50 100644 --- a/src/gui/widgets/stacked_widget.cpp +++ b/src/gui/widgets/stacked_widget.cpp @@ -57,7 +57,7 @@ struct stacked_widget_implementation }; stacked_widget::stacked_widget(const implementation::builder_stacked_widget& builder) - : container_base(builder, get_control_type()) + : container_base(builder, type()) , generator_(generator_base::build(false, false, generator_base::independent, false)) , selected_layer_(-1) , find_in_all_layers_(false) diff --git a/src/gui/widgets/stacked_widget.hpp b/src/gui/widgets/stacked_widget.hpp index 8a9cd9f7d98b..5a1db6e0ca51 100644 --- a/src/gui/widgets/stacked_widget.hpp +++ b/src/gui/widgets/stacked_widget.hpp @@ -161,6 +161,11 @@ class stacked_widget : public container_base /** Internal implementation detail for selecting layers. */ void select_layer_impl(std::function display_condition); +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; diff --git a/src/gui/widgets/styled_widget.hpp b/src/gui/widgets/styled_widget.hpp index 8a14a5c2b670..a1a308ac6941 100644 --- a/src/gui/widgets/styled_widget.hpp +++ b/src/gui/widgets/styled_widget.hpp @@ -400,13 +400,22 @@ class styled_widget : public widget public: /** - * Returns the control_type of the styled_widget. + * Returns the type of this styled_widget. * - * The control_type parameter for gui_definition::get_control() To keep the - * code more generic this type is required so the controls need to return - * the proper string here. Might be used at other parts as well the get the - * type of - * styled_widget involved. + * This is used as the control_type parameter for @ref get_control. + * + * Do note that each widget also must have a public static type() function; + * it's use to implement this function. The reason for this system is twofold: + * + * 1) Due to an oddity in C++, one technically may not call a virtual function + * in a derived class's *initializer list*, which we do liberally. Calling + * it in the constructor *body* is fine, but doing so in the initializer list + * is technically undefined behavior and will give "invalid vptr" errors + * under UBSanitizer. + * + * 2) Having a static type getter allows the type string to be fetched without + * constructing an instance of the widget. A good example of this usecase is + * in @ref build_single_widget_and_cast_to. */ virtual const std::string& get_control_type() const = 0; diff --git a/src/gui/widgets/text_box.cpp b/src/gui/widgets/text_box.cpp index 3f57963fe50b..72f089fc5c48 100644 --- a/src/gui/widgets/text_box.cpp +++ b/src/gui/widgets/text_box.cpp @@ -96,7 +96,7 @@ std::string text_history::get_value() const } text_box::text_box(const implementation::builder_styled_widget& builder) - : text_box_base(builder, get_control_type()) + : text_box_base(builder, type()) , history_() , max_input_length_(0) , text_x_offset_(0) diff --git a/src/gui/widgets/text_box.hpp b/src/gui/widgets/text_box.hpp index 07cf9604729c..b6f12f0b6ec1 100644 --- a/src/gui/widgets/text_box.hpp +++ b/src/gui/widgets/text_box.hpp @@ -272,6 +272,11 @@ class text_box : public text_box_base /** Inherited from text_box_base. */ void handle_key_clear_line(SDL_Keymod modifier, bool& handled) 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; diff --git a/src/gui/widgets/toggle_button.cpp b/src/gui/widgets/toggle_button.cpp index b97e0ed2f436..337d63510d2c 100644 --- a/src/gui/widgets/toggle_button.cpp +++ b/src/gui/widgets/toggle_button.cpp @@ -36,7 +36,7 @@ namespace gui2 REGISTER_WIDGET(toggle_button) toggle_button::toggle_button(const implementation::builder_toggle_button& builder) - : styled_widget(builder, get_control_type()) + : styled_widget(builder, type()) , state_(ENABLED) , state_num_(0) , retval_(retval::NONE) diff --git a/src/gui/widgets/toggle_button.hpp b/src/gui/widgets/toggle_button.hpp index 4a749d88518b..770677d90b6e 100644 --- a/src/gui/widgets/toggle_button.hpp +++ b/src/gui/widgets/toggle_button.hpp @@ -125,6 +125,11 @@ class toggle_button : public styled_widget, public selectable_item */ std::string icon_name_; +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; diff --git a/src/gui/widgets/toggle_panel.cpp b/src/gui/widgets/toggle_panel.cpp index 805e175962b8..0cecdbf4c210 100644 --- a/src/gui/widgets/toggle_panel.cpp +++ b/src/gui/widgets/toggle_panel.cpp @@ -38,7 +38,7 @@ namespace gui2 REGISTER_WIDGET(toggle_panel) toggle_panel::toggle_panel(const implementation::builder_toggle_panel& builder) - : panel(builder, get_control_type()) + : panel(builder, type()) , state_(ENABLED) , state_num_(0) , retval_(retval::NONE) diff --git a/src/gui/widgets/toggle_panel.hpp b/src/gui/widgets/toggle_panel.hpp index 3c76c582a442..ee825ce2e263 100644 --- a/src/gui/widgets/toggle_panel.hpp +++ b/src/gui/widgets/toggle_panel.hpp @@ -157,6 +157,11 @@ class toggle_panel : public panel, public selectable_item 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; diff --git a/src/gui/widgets/tree_view.cpp b/src/gui/widgets/tree_view.cpp index 1591fbf60bb6..0895a1ff2340 100644 --- a/src/gui/widgets/tree_view.cpp +++ b/src/gui/widgets/tree_view.cpp @@ -37,7 +37,7 @@ namespace gui2 REGISTER_WIDGET(tree_view) tree_view::tree_view(const implementation::builder_tree_view& builder) - : scrollbar_container(builder, get_control_type()) + : scrollbar_container(builder, type()) , node_definitions_(builder.nodes) , indentation_step_size_(0) , need_layout_(false) diff --git a/src/gui/widgets/tree_view.hpp b/src/gui/widgets/tree_view.hpp index 6ce925acbaaa..7756b3e55a85 100644 --- a/src/gui/widgets/tree_view.hpp +++ b/src/gui/widgets/tree_view.hpp @@ -171,6 +171,11 @@ class tree_view : public scrollbar_container /** Inherited from container_base. */ virtual void finalize_setup(); +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; diff --git a/src/gui/widgets/unit_preview_pane.cpp b/src/gui/widgets/unit_preview_pane.cpp index 8227f3ccfda4..9d38adf3484a 100644 --- a/src/gui/widgets/unit_preview_pane.cpp +++ b/src/gui/widgets/unit_preview_pane.cpp @@ -53,7 +53,7 @@ namespace gui2 REGISTER_WIDGET(unit_preview_pane) unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder) - : container_base(builder, get_control_type()) + : container_base(builder, type()) , current_type_() , icon_type_(nullptr) , icon_race_(nullptr) diff --git a/src/gui/widgets/unit_preview_pane.hpp b/src/gui/widgets/unit_preview_pane.hpp index c3da8b34a61c..16f727b4fe19 100644 --- a/src/gui/widgets/unit_preview_pane.hpp +++ b/src/gui/widgets/unit_preview_pane.hpp @@ -97,6 +97,11 @@ class unit_preview_pane : public container_base 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; diff --git a/src/gui/widgets/vertical_scrollbar.cpp b/src/gui/widgets/vertical_scrollbar.cpp index bd09777e58f1..9eb2d1af3905 100644 --- a/src/gui/widgets/vertical_scrollbar.cpp +++ b/src/gui/widgets/vertical_scrollbar.cpp @@ -29,7 +29,7 @@ namespace gui2 REGISTER_WIDGET(vertical_scrollbar) vertical_scrollbar::vertical_scrollbar(const implementation::builder_vertical_scrollbar& builder) - : scrollbar_base(builder, get_control_type()) + : scrollbar_base(builder, type()) { } diff --git a/src/gui/widgets/vertical_scrollbar.hpp b/src/gui/widgets/vertical_scrollbar.hpp index 3fe2a43fa0d2..47fa8a6c2ed4 100644 --- a/src/gui/widgets/vertical_scrollbar.hpp +++ b/src/gui/widgets/vertical_scrollbar.hpp @@ -67,6 +67,11 @@ class vertical_scrollbar : public scrollbar_base return current.y - original.y; } +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; }; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index bac455993d31..bd01af315c93 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -272,7 +272,7 @@ window* manager::get_window(const unsigned id) } // namespace window::window(const builder_window::window_resolution* definition) - : panel(implementation::builder_window(::config {"definition", definition->definition}), get_control_type()) + : panel(implementation::builder_window(::config {"definition", definition->definition}), type()) , cursor::setter(cursor::NORMAL) , video_(CVideo::get_singleton()) , status_(NEW) diff --git a/src/gui/widgets/window.hpp b/src/gui/widgets/window.hpp index 22222fe14412..f4a96f49d17f 100644 --- a/src/gui/widgets/window.hpp +++ b/src/gui/widgets/window.hpp @@ -635,6 +635,11 @@ class window : public panel, public cursor::setter */ int mouse_button_state_; +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;