Code

8c6033bc7b084de24a15cf6fd1fdbfc1bb2bb736
[inkscape.git] / src / ui / tool / modifier-tracker.cpp
1 /** @file
2  * Fine-grained modifier tracker for event handling.
3  */
4 /* Authors:
5  *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
6  *
7  * Copyright (C) 2009 Authors
8  * Released under GNU GPL, read the file 'COPYING' for more information
9  */
11 #include <gdk/gdk.h>
12 #include <gdk/gdkkeysyms.h>
13 #include "ui/tool/event-utils.h"
14 #include "ui/tool/modifier-tracker.h"
16 namespace Inkscape {
17 namespace UI {
19 ModifierTracker::ModifierTracker()
20     : _left_shift(false)
21     , _right_shift(false)
22     , _left_ctrl(false)
23     , _right_ctrl(false)
24     , _left_alt(false)
25     , _right_alt(false)
26 {}
28 bool ModifierTracker::event(GdkEvent *event)
29 {
30     switch (event->type) {
31     case GDK_KEY_PRESS:
32         switch (shortcut_key(event->key)) {
33         case GDK_Shift_L:
34             _left_shift = true;
35             break;
36         case GDK_Shift_R:
37             _right_shift = true;
38             break;
39         case GDK_Control_L:
40             _left_ctrl = true;
41             break;
42         case GDK_Control_R:
43             _right_ctrl = true;
44             break;
45         case GDK_Alt_L:
46             _left_alt = true;
47             break;
48         case GDK_Alt_R:
49             _right_alt = true;
50             break;
51         }
52         break;
53     case GDK_KEY_RELEASE:
54         switch (shortcut_key(event->key)) {
55         case GDK_Shift_L:
56             _left_shift = false;
57             break;
58         case GDK_Shift_R:
59             _right_shift = false;
60             break;
61         case GDK_Control_L:
62             _left_ctrl = false;
63             break;
64         case GDK_Control_R:
65             _right_ctrl = false;
66             break;
67         case GDK_Alt_L:
68             _left_alt = false;
69             break;
70         case GDK_Alt_R:
71             _right_alt = false;
72             break;
73         }
74         break;
75     default: break;
76     }
78     return false;
79 }
81 } // namespace UI
82 } // namespace Inkscape
84 /*
85   Local Variables:
86   mode:c++
87   c-file-style:"stroustrup"
88   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
89   indent-tabs-mode:nil
90   fill-column:99
91   End:
92 */
93 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :