1/*
2 *
3 * @APPLE_LICENSE_HEADER_START@
4 *
5 * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#include <AssertMacros.h>
26
27#include "IOHITablet.h"
28#include "IOHITabletPointer.h"
29
30OSDefineMetaClassAndStructors(IOHITablet, IOHIPointing);
31
32UInt16 IOHITablet::generateTabletID()
33{
34    static UInt16 _nextTabletID = 0x8000;
35    return _nextTabletID++;
36}
37
38bool IOHITablet::init(OSDictionary *propTable)
39{
40    if (!IOHIPointing::init(propTable)) {
41        return false;
42    }
43
44    _systemTabletID = 0;
45
46    return true;
47}
48
49bool IOHITablet::open(IOService *			client,
50                      IOOptionBits 			options,
51                      RelativePointerEventAction	rpeAction,
52                      AbsolutePointerEventAction	apeAction,
53                      ScrollWheelEventAction		sweAction,
54                      TabletEventAction			tabletAction,
55                      ProximityEventAction		proximityAction)
56{
57
58    if (client == this) return true;
59
60    return open(client,
61                options,
62                0,
63                (RelativePointerEventCallback)rpeAction,
64                (AbsolutePointerEventCallback)apeAction,
65                (ScrollWheelEventCallback)sweAction,
66                (TabletEventCallback)tabletAction,
67                (ProximityEventCallback)proximityAction);
68}
69
70bool IOHITablet::open(IOService *			client,
71                      IOOptionBits			options,
72                      void *				/*refcon*/,
73                      RelativePointerEventCallback	rpeCallback,
74                      AbsolutePointerEventCallback	apeCallback,
75                      ScrollWheelEventCallback		sweCallback,
76                      TabletEventCallback		tabletCallback,
77                      ProximityEventCallback		proximityCallback)
78{
79    if (client == this) return true;
80
81    if (!IOHIPointing::open(client,
82                            options,
83                            0,
84                            rpeCallback,
85                            apeCallback,
86                            sweCallback)) {
87        return false;
88    }
89
90    _tabletEventTarget = client;
91    _tabletEventAction = (TabletEventAction)tabletCallback;
92    _proximityEventTarget = client;
93    _proximityEventAction = (ProximityEventAction)proximityCallback;
94
95    return open(this,
96                options,
97                (RelativePointerEventAction)IOHIPointing::_relativePointerEvent,
98                (AbsolutePointerEventAction)IOHIPointing::_absolutePointerEvent,
99                (ScrollWheelEventAction)IOHIPointing::_scrollWheelEvent,
100                (TabletEventAction)_tabletEvent,
101                (ProximityEventAction)_proximityEvent);
102}
103
104
105void IOHITablet::dispatchTabletEvent(NXEventData *tabletEvent,
106                                     AbsoluteTime ts)
107{
108    _tabletEvent(   this,
109                    tabletEvent,
110                    ts);
111}
112
113void IOHITablet::dispatchProximityEvent(NXEventData *proximityEvent,
114                                        AbsoluteTime ts)
115{
116    _proximityEvent(this,
117                    proximityEvent,
118                    ts);
119}
120
121bool IOHITablet::startTabletPointer(IOHITabletPointer *pointer, OSDictionary *properties)
122{
123    require(pointer, no_attach);
124    require(pointer->init(properties), no_attach);
125    require(pointer->attach(this), no_attach);
126    require(pointer->start(this), no_start);
127
128no_start:
129    pointer->detach(this);
130no_attach:
131    return false;
132}
133
134void IOHITablet::_tabletEvent(IOHITablet *self,
135                           NXEventData *tabletData,
136                           AbsoluteTime ts)
137{
138    TabletEventCallback teCallback;
139
140    if (!(teCallback = (TabletEventCallback)self->_tabletEventAction) ||
141        !tabletData)
142        return;
143
144    (*teCallback)(
145                    self->_tabletEventTarget,
146                    tabletData,
147                    ts,
148                    self,
149                    0);
150}
151
152void IOHITablet::_proximityEvent(IOHITablet *self,
153                              NXEventData *proximityData,
154                              AbsoluteTime ts)
155{
156    ProximityEventCallback peCallback;
157
158    if (!(peCallback = (ProximityEventCallback)self->_proximityEventAction) ||
159        !proximityData)
160        return;
161
162    if (self->_systemTabletID == 0)
163    {
164        self->_systemTabletID = IOHITablet::generateTabletID();
165        self->setProperty(kIOHISystemTabletID, (unsigned long long)self->_systemTabletID, 16);
166    }
167
168    proximityData->proximity.systemTabletID = self->_systemTabletID;
169
170    (*peCallback)(
171                    self->_proximityEventTarget,
172                    proximityData,
173                    ts,
174                    self,
175                    0);
176}
177
178
179
180