3 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
13 #include <l4/mag-gfx/geometry>
15 #include <l4/scout-gfx/widget>
16 #include <l4/scout-gfx/layout>
17 #include <l4/mag-gfx/clip_guard>
21 /**********************
22 ** Basic_window interface **
23 **********************/
29 virtual Rect geometry() const = 0;
30 virtual Rect set_geometry(Rect const &, bool redraw = false) = 0;
31 virtual void top() = 0;
32 virtual void redraw(Rect const &r) = 0;
33 virtual Mag_gfx::Pixel_info const *pixel_info() const = 0;
38 class Basic_window : public Scout_gfx::Parent_widget
50 View *view() { return _view; }
54 Area preferred_size() const
55 { return child_layout() ? child_layout()->preferred_size() : _max_sz; }
57 { return child_layout() ? _min_sz.max(child_layout()->min_size()) : _min_sz; }
58 Area max_size() const { return _max_sz; }
60 void child_invalidate()
65 Area s = _size.min(child_layout()->max_size()).max(child_layout()->min_size());
66 int h = child_layout()->min_height_for_width(s.w());
68 s.h(std::max(s.h(), h));
70 child_layout()->set_geometry(Rect(Point(0, 0), s));
74 Orientations expanding() const { return Orientations(); }
75 bool empty() const { return false; }
77 void set_geometry(Rect const &r, bool force)
79 bool need_redraw = false;
80 Area s = r.area().min(max_size());
82 if (child_layout() && (force || s != _size))
85 child_layout()->set_geometry(Rect(s));
92 //_pos = r.p1(); _size = s;
93 Rect ng = _view->set_geometry(Rect(r.p1(), _size), need_redraw);
94 _pos = ng.p1(); _size = ng.area();
97 void set_geometry(Rect const &r)
98 { set_geometry(r, false); }
100 Rect geometry() const { return Rect(_pos, _size); }
102 Basic_window(View *view, Area const &max_sz)
103 : _view(view), _max_sz(max_sz)
105 /* init element attributes */
106 _size = view->geometry().area();
109 virtual ~Basic_window() { }
112 * Return current window position
114 virtual Rect view_pos() const { return _view->geometry(); }
119 //Platform *pf() const { return _pf; }
120 Area max() const { return _max_sz; }
123 * Bring window to front
125 virtual void top() { _view->top(); }
130 * This function just collects the specified regions to be
131 * redrawn but does not perform any immediate drawing
132 * operation. The actual drawing must be initiated by
133 * calling the process_redraw function.
135 void redraw_area(Rect const &r) const
136 { _view->redraw(r + _pos); }
138 void draw(Mag_gfx::Canvas *c, Point const &p)
140 Mag_gfx::Clip_guard g(c, Rect(p, size()));
141 Parent_widget::draw(c, p);
144 Widget *handle_event(Event const &ev);
147 void _assign_mfocus(Widget *e, int force = 0);
151 /********************
153 ********************/
155 class Drag_event_handler : public Scout_gfx::Event_handler
158 Point _cm; /* original mouse position */
159 Point _om; /* current mouse positon */
161 virtual void start_drag() = 0;
162 virtual void do_drag() = 0;
164 Point diff() const { return _cm - _om; }
168 * Event handler interface
170 bool handle(Scout_gfx::Event const &ev)
175 /* first click starts dragging */
176 if ((ev.type == Scout_gfx::Event::PRESS) && (ev.key_cnt == 1))
183 /* check if mouse was moved */
187 /* remember current mouse position */
194 virtual ~Drag_event_handler() {}
198 class Sizer_event_handler : public Drag_event_handler
202 Basic_window *_window;
203 Area _osz; /* original window size */
206 * Event handler interface
209 { _osz = _window->view_pos().area(); }
213 /* calculate new window size */
214 Area nsz = _osz.grow(diff());
216 _window->set_geometry(Rect(_window->geometry().p1(), nsz));
224 Sizer_event_handler(Basic_window *window)
231 class Mover_event_handler : public Drag_event_handler
235 Basic_window *_window;
236 Point _ob; /* original launchpad position */
241 _ob = _window->view_pos().p1();
247 Point nb = _ob + diff();
249 _window->set_geometry(Rect(nb, _window->geometry().area()));
257 Mover_event_handler(Basic_window *window)