]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/lib/window.cc
update
[l4.git] / l4 / pkg / scout-gfx / lib / window.cc
1 #include <l4/scout-gfx/window>
2
3 #include <l4/re/event_enums.h>
4 namespace Scout_gfx {
5
6 using namespace Mag_gfx;
7
8 namespace {
9
10 class Win_layout : public Layout
11 {
12 private:
13   Window::Deco_policy::Insets _inset;
14
15   Layout_item *_child;
16
17 public:
18   Win_layout(Layout_item *child, Window::Deco_policy::Insets **insets)
19   : _inset(), _child(child)
20   {
21     _inset.tl = Area(0,0);
22     _inset.br = Area(0,0);
23     _child->set_parent_layout_item(this);
24     *insets = &_inset;
25   }
26
27   virtual ~Win_layout() {}
28
29   Area preferred_size() const
30   { return _child->preferred_size() + _inset.tl + _inset.br; }
31
32   Area min_size() const
33   { return _child->min_size() + _inset.tl + _inset.br; }
34
35   Area max_size() const
36   { return _child->max_size() + _inset.tl + _inset.br; }
37
38   Orientations expanding() const { return _child->expanding(); }
39   bool empty() const  { return false; }
40   bool has_height_for_width() const
41   { return _child->has_height_for_width(); }
42
43   int height_for_width(int w) const
44   { return _child->height_for_width(w); }
45
46   int min_height_for_width(int w) const
47   { return _child->min_height_for_width(w); }
48
49   //void child_invalidate() { _child->invalidate(); }
50   //void invalidate() { _child->invalidate(); }
51
52   void set_geometry(Rect const &r)
53   {
54     Rect x
55       = r.offset(_inset.tl.w(), _inset.tl.h(), -_inset.br.w(), -_inset.br.h());
56
57     _child->set_geometry(x);
58   }
59
60   Rect geometry() const
61   {
62     return _child->geometry().offset(-_inset.tl.w(), -_inset.tl.h(),
63                                      _inset.br.w(), _inset.br.h());
64   }
65
66   void add_item(Layout_item *) {}
67   Layout_item *remove_item(int) { return 0; }
68   Layout_item *item(int) const { return _child; }
69 };
70
71 }
72
73 Window::Window(Window::Deco_policy *dp, View *v,
74                Area const &max_size)
75 : Basic_window(v, max_size),
76   // this is some stupid hack, needs to be defined by the app
77   _normal_pos(Point(100, 100), Area(300, 200)),
78   _deco_policy(dp)
79 {
80   _deco = _deco_policy->create_deco(this);
81   Basic_window::set_child_layout(new Win_layout(&_content, &_insets));
82   _deco_policy->set_deco_mode(Window::Fullscreen, _deco, _insets);
83
84   Basic_window::append(&_content);
85   Basic_window::append(_deco);
86 }
87
88
89 void
90 Window::set_window_mode(Mode mode)
91 {
92   _deco_policy->set_deco_mode(mode, _deco, _insets);
93   if (mode == Normal)
94     set_geometry(_normal_pos);
95   else
96     {
97       _normal_pos = geometry();
98       switch (mode)
99         {
100         case Fullscreen:
101         case Maximized:
102           set_geometry(Rect(Point(0,0), max_size()));
103           break;
104         case Minimized:
105           set_geometry(Rect(pos(), min_size()));
106           break;
107         default:
108           break;
109         }
110     }
111   redraw_area(Rect(Point(0, 0), size()));
112 }
113
114 }