diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 17b7b6b8276..d119850ee78 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -83,5 +83,20 @@ void tcontainer_::draw(surface& surface, const bool force, grid_.draw(surface, force, redraw_background); } +void tcontainer_::set_active(const bool active) +{ + // Not all our children might have the proper state so let them run + // unconditionally. + grid_.set_active(active); + + if(active == get_active()) { + return; + } + + set_dirty(); + + set_self_active(active); +} + } // namespace gui2 diff --git a/src/gui/widgets/container.hpp b/src/gui/widgets/container.hpp index 77e38b0e985..e1d15d2dd03 100644 --- a/src/gui/widgets/container.hpp +++ b/src/gui/widgets/container.hpp @@ -98,6 +98,9 @@ public: set_client_size(get_client_rect()); } + /** Inherited from tcontrol. */ + void set_active(const bool active); + /***** **** ***** ***** wrappers to the grid **** ********* *****/ tgrid::iterator begin() { return grid_.begin(); } @@ -147,6 +150,15 @@ private: /** Returns the space used by the border. */ virtual tpoint border_space() const { return tpoint(0, 0); } + /** + * Helper for set_active. + * + * This function should set the control itself active. It's called by + * set_active if the state needs to change. The widget is set to dirty() by + * set_active so we only need to change the state. + */ + virtual void set_self_active(const bool active) = 0; + /** * If the background has been changed the next draw cycle needs to do a full * redraw and also tell the child items to invalidate their background. This diff --git a/src/gui/widgets/listbox.hpp b/src/gui/widgets/listbox.hpp index 0e621412f9c..a8c52f93fa0 100644 --- a/src/gui/widgets/listbox.hpp +++ b/src/gui/widgets/listbox.hpp @@ -37,8 +37,6 @@ public: tlistbox(); - // FIXME this might not the right thing to do. - void set_active(const bool active) { set_state(active ? ENABLED : DISABLED); }; bool get_active() const { return state_ != DISABLED; } unsigned get_state() const { return state_; } @@ -263,6 +261,10 @@ private: const std::string& get_control_type() const { static const std::string type = "listbox"; return type; } + /** Inherited from tcontainer_. */ + void set_self_active(const bool active) + { state_ = active ? ENABLED : DISABLED; } + /** The (lastly) selected row */ unsigned selected_row_; diff --git a/src/gui/widgets/menubar.hpp b/src/gui/widgets/menubar.hpp index 90a139683e8..e5912947961 100644 --- a/src/gui/widgets/menubar.hpp +++ b/src/gui/widgets/menubar.hpp @@ -48,9 +48,6 @@ public: /***** ***** ***** ***** Inherited ***** ***** ***** *****/ - /** Inherited from tcontrol. */ - void set_active(const bool active) {} ; // FIXME implement - /** Inherited from tcontrol. */ bool get_active() const { return state_ != DISABLED; } @@ -114,6 +111,10 @@ private: /** The builder needs to call us so we can wire in the proper callbacks. */ void finalize_setup(); + /** Inherited from tcontainer_. */ + void set_self_active(const bool active) + { state_ = active ? ENABLED : DISABLED; } + /** Inherited from tcontrol. */ const std::string& get_control_type() const { static const std::string type = "menubar"; return type; } diff --git a/src/gui/widgets/panel.hpp b/src/gui/widgets/panel.hpp index f4a5fad2203..d5d0fb99900 100644 --- a/src/gui/widgets/panel.hpp +++ b/src/gui/widgets/panel.hpp @@ -50,9 +50,6 @@ public: */ virtual SDL_Rect get_client_rect() const; - /** Inherited from tcontrol. */ - void set_active(const bool /*active*/) {} - /** Inherited from tcontrol. */ bool get_active() const { return true; } @@ -75,6 +72,9 @@ private: /** Inherited from tcontainer_. */ tpoint border_space() const; + /** Inherited from tcontainer_. */ + void set_self_active(const bool /*active*/) {} + }; } // namespace gui2 diff --git a/src/gui/widgets/window.hpp b/src/gui/widgets/window.hpp index 5003fd0a4de..09420dbf9a6 100644 --- a/src/gui/widgets/window.hpp +++ b/src/gui/widgets/window.hpp @@ -117,8 +117,7 @@ public: void window_resize(tevent_handler&, const unsigned new_width, const unsigned new_height); - //! A window is always active atm so ignore the request. - void set_active(const bool /*active*/) {} + //! At the moment a window is always active. bool get_active() const { return true; } unsigned get_state() const { return 0; } bool needs_full_redraw() const { return false; /* FIXME IMPLEMENT */ }