X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.h;h=d100dacf94aaa80538194fc77e2d95a486c869b3;hb=HEAD;hp=6c75e38e9625f6a17a14d69209358aa69883351a;hpb=18a5af8e80903eb9738cefe03825595877fbf447;p=libs%2Fgltk.git diff --git a/source/container.h b/source/container.h index 6c75e38..d100dac 100644 --- a/source/container.h +++ b/source/container.h @@ -1,91 +1,125 @@ #ifndef MSP_GLTK_CONTAINER_H_ #define MSP_GLTK_CONTAINER_H_ -#include +#include #include +#include #include +#include "mspgltk_api.h" #include "widget.h" namespace Msp { namespace GLtk { -class hierarchy_error: public std::logic_error +class MSPGLTK_API hierarchy_error: public std::logic_error { public: hierarchy_error(const std::string &); - virtual ~hierarchy_error() throw() { } }; -class Container: virtual public Widget +class MSPGLTK_API Container: virtual public Widget { protected: struct Child: public sigc::trackable { Container &container; - Widget *widget; + std::unique_ptr own_widget; + Widget *widget = nullptr; + Time::TimeDelta time_since_animate; Child(Container &, Widget *); + Child(Container &, std::unique_ptr); virtual ~Child(); void visibility_changed(bool); void request_focus(); void grab_pointer(); void ungrab_pointer(); + void request_animation(const Time::TimeDelta &); + void rebuild_needed(); }; - std::list children; - Widget *click_focus; - unsigned click_button; - Widget *pointer_focus; - bool pointer_grabbed; - Widget *input_focus; - Widget *touch_focus; + std::vector> children; + Widget *click_focus = nullptr; + unsigned click_button = 0; + Widget *pointer_focus = nullptr; + bool pointer_grabbed = false; + Widget *input_focus = nullptr; + Widget *saved_input_focus = nullptr; + Widget *touch_focus = nullptr; + bool children_rebuild_needed = false; - Container(); + Container() = default; public: virtual ~Container(); - void add(Widget &); + void add(Widget &w) { add_child(w); } + void add(std::unique_ptr); + + template + T &add_new(Args &&...); + void remove(Widget &); protected: - virtual Child *create_child(Widget *); + Child &add_child(Widget &); Geometry determine_child_geometry(const Widget &, const Part &) const; void autosize_child(const Widget &, const Part &, Geometry &) const; void reposition_child(Widget &, const Part &) const; public: - std::list get_children() const; - Widget *get_child_at(int, int) const; - Widget *get_descendant_at(int, int) const; + std::vector get_children() const; + Widget *find_child_at(int, int) const; + Widget *find_descendant_at(int, int) const; void raise(Widget &); protected: - void set_pointer_focus(Widget *); + void set_pointer_focus(Widget *, bool = false); void set_input_focus(Widget *); public: Widget *get_input_focus() const { return input_focus; } Widget *get_final_input_focus() const; - virtual void button_press(int, int, unsigned); - virtual void button_release(int, int, unsigned); - virtual void pointer_motion(int, int); +private: + void check_animation_interval(); + +protected: + void rebuild_hierarchy() override; + +public: + void button_press(int, int, unsigned) override; + void button_release(int, int, unsigned) override; + void pointer_motion(int, int) override; private: Widget *get_pointer_target(int, int, bool) const; public: - virtual void pointer_leave(); - virtual void touch_press(int, int, unsigned); - virtual void touch_release(int, int, unsigned); - virtual void touch_motion(int, int, unsigned); - virtual void key_press(unsigned, unsigned); - virtual void key_release(unsigned, unsigned); - virtual void character(wchar_t); - virtual void focus_out(); + void pointer_leave() override; + void touch_press(int, int, unsigned) override; + void touch_release(int, int, unsigned) override; + void touch_motion(int, int, unsigned) override; + bool key_press(unsigned, unsigned) override; + bool key_release(unsigned, unsigned) override; + bool character(wchar_t) override; + void focus_in() override; + void focus_out() override; + bool navigate(Navigation) override; + void animate(const Time::TimeDelta &) override; protected: - virtual void on_reparent(); + void on_reparent() override; virtual void on_child_added(Widget &) { } virtual void on_child_removed(Widget &) { } + virtual void on_input_focus_changed(Widget *); }; + +template +T &Container::add_new(Args &&... args) +{ + std::unique_ptr wdg = std::make_unique(std::forward(args)...); + T *ptr = wdg.get(); + add(move(wdg)); + return *ptr; +} + } // namespace GLtk } // namespace Msp