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.
12 #include <l4/cxx/dlist>
13 #include <l4/mag-gfx/geometry>
14 #include <l4/mag-gfx/font>
15 #include <l4/mag-gfx/gfx_colors>
16 #include <l4/mag/server/mode>
17 #include <l4/mag/server/session>
18 #include <l4/re/event>
25 namespace Mag_server {
27 using namespace Mag_gfx;
32 class View : public cxx::D_list_item<View>, public Rect
35 friend class View_stack;
38 void operator = (View const &);
45 explicit View(Rect const &size, unsigned flags = 0)
46 : Rect(size), _flags(flags)
52 Label_sep = 8 // space between session label and view title
55 static Rgb32::Color frame_color() { return Rgb32::Color(255, 200, 127); }
56 static Rgb32::Color kill_color() { return Rgb32::Color(255, 0, 0); }
69 void set_geometry(Rect const &p)
70 { this->Rect::operator = (p); }
72 Area size() const { return Area(w(), h()); }
74 bool transparent() const { return _flags & F_transparent; }
75 bool need_frame() const { return _flags & F_need_frame; }
76 bool ignore() const { return _flags & F_ignore; }
77 bool focused() const { return _flags & F_focused; }
78 bool background() const { return _flags & F_background; }
79 bool above() const { return _flags & F_above; }
80 bool super_view() const { return _flags & F_super_view; }
82 void set_as_background() { _flags |= F_background; }
83 void set_above(bool on)
91 void set_focus(bool on)
99 virtual void draw(Canvas *, View_stack const *, Mode) const = 0;
100 virtual void handle_event(L4Re::Event_buffer::Event const &, Point const &) {}
103 virtual Session *session() const { return 0; }
105 char const *title() const { return 0; }
106 Area calc_label_sz(Font const *font);
107 Point label_pos() const { return _label_pos; }
108 void label_pos(Point const &pos) { _label_pos = pos; }
109 Area label_sz() const { return _label_sz; }
111 int frame_width() const { return 4; }
117 View::calc_label_sz(Font const *font)
119 char const *const l1 = session()->label();
120 char const *const l2 = title();
121 _label_sz = Area(font->str_w(l1) + (l2 ? (Label_sep + font->str_w(l2) + 2) : 2), font->str_h(l1) + 2);