]> git.tdb.fi Git - libs/gltk.git/blob - source/container.h
Remove unnecessary Container::create_child
[libs/gltk.git] / source / container.h
1 #ifndef MSP_GLTK_CONTAINER_H_
2 #define MSP_GLTK_CONTAINER_H_
3
4 #include <stdexcept>
5 #include <vector>
6 #include <sigc++/trackable.h>
7 #include "mspgltk_api.h"
8 #include "widget.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 class MSPGLTK_API hierarchy_error: public std::logic_error
14 {
15 public:
16         hierarchy_error(const std::string &);
17 };
18
19
20 class MSPGLTK_API Container: virtual public Widget
21 {
22 protected:
23         struct Child: public sigc::trackable
24         {
25                 Container &container;
26                 Widget *widget = nullptr;
27                 Time::TimeDelta time_since_animate;
28
29                 Child(Container &, Widget *);
30                 virtual ~Child();
31
32                 void visibility_changed(bool);
33                 void request_focus();
34                 void grab_pointer();
35                 void ungrab_pointer();
36                 void request_animation(const Time::TimeDelta &);
37                 void rebuild_needed();
38         };
39
40         std::vector<Child *> children;
41         Widget *click_focus = nullptr;
42         unsigned click_button = 0;
43         Widget *pointer_focus = nullptr;
44         bool pointer_grabbed = false;
45         Widget *input_focus = nullptr;
46         Widget *saved_input_focus = nullptr;
47         Widget *touch_focus = nullptr;
48         bool children_rebuild_needed = false;
49
50         Container() = default;
51 public:
52         virtual ~Container();
53
54         void add(Widget &);
55         void remove(Widget &);
56 protected:
57         Geometry determine_child_geometry(const Widget &, const Part &) const;
58         void autosize_child(const Widget &, const Part &, Geometry &) const;
59         void reposition_child(Widget &, const Part &) const;
60 public:
61         std::vector<Widget *> get_children() const;
62         Widget *find_child_at(int, int) const;
63         Widget *find_descendant_at(int, int) const;
64         void raise(Widget &);
65
66 protected:
67         void set_pointer_focus(Widget *, bool = false);
68         void set_input_focus(Widget *);
69 public:
70         Widget *get_input_focus() const { return input_focus; }
71         Widget *get_final_input_focus() const;
72
73 private:
74         void check_animation_interval();
75
76 protected:
77         void rebuild_hierarchy() override;
78
79 public:
80         void button_press(int, int, unsigned) override;
81         void button_release(int, int, unsigned) override;
82         void pointer_motion(int, int) override;
83 private:
84         Widget *get_pointer_target(int, int, bool) const;
85 public:
86         void pointer_leave() override;
87         void touch_press(int, int, unsigned) override;
88         void touch_release(int, int, unsigned) override;
89         void touch_motion(int, int, unsigned) override;
90         bool key_press(unsigned, unsigned) override;
91         bool key_release(unsigned, unsigned) override;
92         bool character(wchar_t) override;
93         void focus_in() override;
94         void focus_out() override;
95         bool navigate(Navigation) override;
96         void animate(const Time::TimeDelta &) override;
97 protected:
98         void on_reparent() override;
99         virtual void on_child_added(Widget &) { }
100         virtual void on_child_removed(Widget &) { }
101         virtual void on_input_focus_changed(Widget *);
102 };
103
104 } // namespace GLtk
105 } // namespace Msp
106
107 #endif