74907d61c49de14bb89a8dfbda7e3c4eae9e3a89
1 /** @file
2 * Collection of shorthands to deal with GDK events.
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 #ifndef SEEN_UI_TOOL_EVENT_UTILS_H
12 #define SEEN_UI_TOOL_EVENT_UTILS_H
14 #include <gdk/gdk.h>
15 #include <2geom/point.h>
17 namespace Inkscape {
18 namespace UI {
20 inline bool state_held_shift(unsigned state) {
21 return state & GDK_SHIFT_MASK;
22 }
23 inline bool state_held_control(unsigned state) {
24 return state & GDK_CONTROL_MASK;
25 }
26 inline bool state_held_alt(unsigned state) {
27 return state & GDK_MOD1_MASK;
28 }
29 inline bool state_held_only_shift(unsigned state) {
30 return (state & GDK_SHIFT_MASK) && !(state & (GDK_CONTROL_MASK | GDK_MOD1_MASK));
31 }
32 inline bool state_held_only_control(unsigned state) {
33 return (state & GDK_CONTROL_MASK) && !(state & (GDK_SHIFT_MASK | GDK_MOD1_MASK));
34 }
35 inline bool state_held_only_alt(unsigned state) {
36 return (state & GDK_MOD1_MASK) && !(state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK));
37 }
38 inline bool state_held_any_modifiers(unsigned state) {
39 return state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK);
40 }
41 inline bool state_held_no_modifiers(unsigned state) {
42 return !state_held_any_modifiers(state);
43 }
44 template <unsigned button>
45 inline bool state_held_button(unsigned state) {
46 return (button == 0 || button > 5) ? false : state & (GDK_BUTTON1_MASK << (button-1));
47 }
50 /** Checks whether Shift was held when the event was generated. */
51 template <typename E>
52 inline bool held_shift(E const &event) {
53 return state_held_shift(event.state);
54 }
56 /** Checks whether Control was held when the event was generated. */
57 template <typename E>
58 inline bool held_control(E const &event) {
59 return state_held_control(event.state);
60 }
62 /** Checks whether Alt was held when the event was generated. */
63 template <typename E>
64 inline bool held_alt(E const &event) {
65 return state_held_alt(event.state);
66 }
68 /** True if from the set of Ctrl, Shift and Alt only Ctrl was held when the event
69 * was generated. */
70 template <typename E>
71 inline bool held_only_control(E const &event) {
72 return state_held_only_control(event.state);
73 }
75 /** True if from the set of Ctrl, Shift and Alt only Shift was held when the event
76 * was generated. */
77 template <typename E>
78 inline bool held_only_shift(E const &event) {
79 return state_held_only_shift(event.state);
80 }
82 /** True if from the set of Ctrl, Shift and Alt only Alt was held when the event
83 * was generated. */
84 template <typename E>
85 inline bool held_only_alt(E const &event) {
86 return state_held_only_alt(event.state);
87 }
89 template <typename E>
90 inline bool held_no_modifiers(E const &event) {
91 return state_held_no_modifiers(event.state);
92 }
94 template <typename E>
95 inline bool held_any_modifiers(E const &event) {
96 return state_held_any_modifiers(event.state);
97 }
99 template <typename E>
100 inline Geom::Point event_point(E const &event) {
101 return Geom::Point(event.x, event.y);
102 }
104 /** Use like this:
105 * @code if (held_button<2>(event->motion)) { ... @endcode */
106 template <unsigned button, typename E>
107 inline bool held_button(E const &event) {
108 return state_held_button<button>(event.state);
109 }
111 guint shortcut_key(GdkEventKey const &event);
112 unsigned consume_same_key_events(guint keyval, gint mask);
113 unsigned state_after_event(GdkEvent *event);
115 } // namespace UI
116 } // namespace Inkscape
118 #endif
120 /*
121 Local Variables:
122 mode:c++
123 c-file-style:"stroustrup"
124 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
125 indent-tabs-mode:nil
126 fill-column:99
127 End:
128 */
129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :