]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/lib/basic_window.cc
update
[l4.git] / l4 / pkg / scout-gfx / lib / basic_window.cc
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/scout-gfx/basic_window>
10
11 namespace Scout_gfx {
12
13 void
14 Basic_window::_assign_mfocus(Widget *e, int force)
15 {
16   /* return if mouse focus did not change */
17   if (!force && e == _mfocus)
18     return;
19
20   /* tell old mouse focus to release focus */
21   if (_mfocus)
22     _mfocus->mfocus(0);
23
24   /* assign new current mouse focus */
25   _mfocus = e;
26
27   /* notify new mouse focus */
28   if (_mfocus)
29     _mfocus->mfocus(1);
30
31 #if 0
32   /* determine new current link destination */
33   Widget *old_dst = _dst;
34   Link_token *lt;
35   if (_mfocus && (lt = dynamic_cast<Link_token*>(_mfocus)))
36     {
37       _dst = lt->dst();
38     }
39   else
40     _dst = 0;
41   /* nofify element tree about new link destination */
42   if (_dst != old_dst)
43     _root->curr_link_destination(_dst);
44 #endif
45 }
46
47 Widget *
48 Basic_window::handle_event(Event const &ev)
49 {
50   Parent_widget::handle_event(ev);
51   if (_active)
52     {
53       Event re = ev;
54       re.m -= _active_pos;
55       _active->handle_event(re);
56     }
57
58   Widget *e = 0;
59   if (ev.type != 4)
60     e = find(ev.m);
61
62   if (e == this)
63     e = 0;
64
65   switch (ev.type)
66     {
67
68     case Event::PRESS:
69       if (ev.key_cnt != 1 || !e)
70         break;
71
72         {
73           _active_pos = e->map_to_parent(Point(0,0));
74           _active = e;
75
76           Event re = ev;
77           re.m -= _active_pos;
78           _active->handle_event(re);
79         }
80
81       _assign_mfocus(e, 1);
82
83       break;
84
85     case Event::RELEASE:
86       if (ev.key_cnt == 0)
87         {
88           _active = 0;
89           _assign_mfocus(e);
90         }
91       break;
92
93     case Event::WHEEL:
94 #if 0
95         if (Widget *x = find_child(m))
96           {
97             Event re = ev;
98             re.m = x->map_from_parent(ev.m);
99             x->handle_event(re);
100           }
101         break;
102 #endif
103     case Event::MOTION:
104       if (!_active && e)
105         {
106           Event re = ev;
107           re.m = e->map_from_parent(ev.m);
108           e->handle_event(re);
109         }
110
111       if (ev.key_cnt == 0)
112         _assign_mfocus(e);
113       break;
114
115     default:
116
117       break;
118     }
119
120   return this;
121 }
122 }
123