]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/lib/user_state.cc
update
[l4.git] / l4 / pkg / scout-gfx / lib / user_state.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/user_state>
10
11
12 namespace Scout_gfx {
13
14 void User_state::_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 void User_state::handle_event(Event const &ev)
48 {
49   Parent_widget::handle_event(ev);
50   if (_active)
51     {
52       Event re = ev;
53       re.m -= _am;
54       _active->handle_event(re);
55     }
56
57   if (ev.type != 4)
58
59     /* find element under the mouse cursor */
60     _m = ev.m;
61
62   Widget *e = find(_m);
63
64   if (e == this)
65     e = 0;
66
67   switch (ev.type)
68     {
69
70     case Event::PRESS:
71       if (ev.key_cnt != 1 || !e)
72         break;
73
74         {
75           Event re = ev;
76           _am = e->map_to_parent(Point(0,0));
77           re.m -= _am;
78
79           _active = e;
80           _active->handle_event(re);
81         }
82
83       _assign_mfocus(e, 1);
84
85       break;
86
87     case Event::RELEASE:
88       if (ev.key_cnt == 0)
89         {
90           _active = 0;
91           _assign_mfocus(e);
92         }
93       break;
94
95     case Event::WHEEL:
96         if (Widget *x = find_child(_m))
97           {
98             Event re = ev;
99             re.m = x->map_from_parent(ev.m);
100             x->handle_event(re);
101           }
102         break;
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 }