luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Event.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef EVENT_H
23 #define EVENT_H
24 
25 #include "Common.h"
26 
27 #include <stdint.h>
28 #include <glib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <qnamespace.h>
32 
33 #include <SysMgrEvent.h>
34 
35 #include "sptr.h"
36 
37 class Event : public SysMgrEvent,
38  public RefCounted
39 {
40 public:
41 
42  Event() {
43  // The following is needed so that we can initialize all
44  // of the member variables to zero. if Event is created on
45  // the stack, the operator new will not get called
46  //
47  // SysmgEvent is guaranteed to
48  // be a data only, no virtual functions class
49  SysMgrEvent* base = static_cast<SysMgrEvent*>(this);
50  ::memset(base, 0, sizeof(SysMgrEvent));
51  }
52 
53  void* operator new(size_t size) {
54  Event* e = (Event*) g_slice_alloc0(size);
55  e->m_blockSize = size;
56  return e;
57  }
58 
59  void operator delete(void* p) {
60  Event* e = (Event*) p;
61  g_slice_free1(e->m_blockSize, p);
62  }
63 
64  static inline bool isPenEvent(Event* e) {
65  return (e->type & PenMask);
66  }
67 
68  static inline bool isKeyEvent(Event* e) {
69  return (e->type & KeyMask);
70  }
71 
72  static inline bool isGestureEvent(Event* e) {
73  return (e->type & GestureMask);
74  }
75 
76  static inline bool isPenOffEvent(Event* e) {
77  return ((e->type & PenMask) &&
78  ((e->type == PenUp) ||
79  (e->type == PenCancel) ||
80  (e->type == PenCancelAll)));
81  }
82 
83  inline void setClicked(bool val) {
84  if (val)
85  attributes |= Clicked;
86  else if (attributes & Clicked)
87  attributes ^= Clicked;
88  }
89 
90  inline bool clicked() const {
91  return (attributes & Clicked);
92  }
93 
94  inline void setRejected(bool val) {
95  if (val)
96  attributes |= Rejected;
97  else if (attributes & Rejected)
98  attributes ^= Rejected;
99  }
100 
101  inline bool rejected() const {
102  return (attributes & Rejected);
103  }
104 
105  inline void setMainFinger(bool val) {
106  if (val)
107  attributes |= MainFinger;
108  else if (attributes & MainFinger)
109  attributes ^= MainFinger;
110  }
111 
112  inline bool mainFinger() const {
113  return (attributes & MainFinger);
114  }
115 
116  inline void setGestureKey(bool val) {
117  if (val)
118  attributes |= GestureKey;
119  else if (attributes & GestureKey)
120  attributes ^= GestureKey;
121  }
122 
123  inline bool gestureKey() const {
124  return (attributes & GestureKey);
125  }
126 
127  static uint16_t modifiersFromQt(const Qt::KeyboardModifiers& m) {
128  return (m & Qt::ShiftModifier ? Event::Shift : 0) |
129  (m & Qt::ControlModifier ? Event::Control : 0) |
130  (m & Qt::AltModifier ? Event::Alt : 0) |
131  (m & Qt::MetaModifier ? Event::Meta : 0);
132  }
133 
134 private:
135 
136  Event(const Event&);
137  Event& operator=(const Event&);
138  int m_blockSize;
139 };
140 
141 
142 #endif /* EVENT_H */