]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/include/server/view
update
[l4.git] / l4 / pkg / mag / include / server / view
1 // vi:ft=cpp
2 /*
3  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
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.
9  */
10 #pragma once
11
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>
19
20 namespace Mag_gfx {
21 class Canvas;
22 }
23
24
25 namespace Mag_server {
26
27 using namespace Mag_gfx;
28
29 class View_stack;
30 class Session;
31
32 class View : public cxx::D_list_item<View>, public Rect
33 {
34 private:
35   friend class View_stack;
36
37   View(View const &);
38   void operator = (View const &);
39
40   unsigned _flags;
41   Point _label_pos;
42   Area _label_sz;
43
44 protected:
45   explicit View(Rect const &size, unsigned flags = 0)
46   : Rect(size), _flags(flags)
47   {}
48
49 public:
50   enum Consts
51   {
52     Label_sep = 8  // space between session label and view title
53   };
54
55   static Rgb32::Color frame_color() { return Rgb32::Color(255, 200, 127); }
56   static Rgb32::Color kill_color() { return Rgb32::Color(255, 0, 0); }
57   enum
58   {
59     F_transparent = 0x01,
60     F_need_frame  = 0x02,
61     F_ignore      = 0x04,
62     F_focused     = 0x08,
63     F_background  = 0x10,
64     F_above       = 0x20,
65     F_no_label    = 0x40,
66     F_super_view  = 0x80,
67   };
68
69   void set_geometry(Rect const &p)
70   { this->Rect::operator = (p); }
71
72   Area size() const { return Area(w(), h()); }
73
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; }
81
82   void set_as_background() { _flags |= F_background; }
83   void set_above(bool on)
84   {
85     if (on)
86       _flags |= F_above;
87     else
88       _flags &= ~F_above;
89   }
90
91   void set_focus(bool on)
92   {
93     if (on)
94       _flags |= F_focused;
95     else
96       _flags &= ~F_focused;
97   }
98
99   virtual void draw(Canvas *, View_stack const *, Mode) const = 0;
100   virtual void handle_event(L4Re::Event_buffer::Event const &, Point const &) {}
101   virtual ~View() {}
102
103   virtual Session *session() const { return 0; }
104
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; }
110
111   int frame_width() const { return 4; }
112 };
113
114
115 inline
116 Area
117 View::calc_label_sz(Font const *font)
118 {
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);
122   return _label_sz;
123 }
124
125 }