]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | #ifndef _IOHIKEYBOARDMAPPER_H | |
23 | #define _IOHIKEYBOARDMAPPER_H | |
24 | ||
25 | #include <IOKit/hidsystem/ev_keymap.h> | |
26 | ||
27 | class IOHIKeyboard; | |
28 | ||
29 | /* | |
30 | * Key ip/down state is tracked in a bit list. Bits are set | |
31 | * for key-down, and cleared for key-up. The bit vector and macros | |
32 | * for it's manipulation are defined here. | |
33 | */ | |
34 | ||
35 | typedef UInt32 * kbdBitVector; | |
36 | ||
37 | #define EVK_BITS_PER_UNIT 32 | |
38 | #define EVK_BITS_MASK 31 | |
39 | #define EVK_BITS_SHIFT 5 // 1<<5 == 32, for cheap divide | |
40 | ||
41 | #define EVK_KEYDOWN(n, bits) \ | |
42 | (bits)[((n)>>EVK_BITS_SHIFT)] |= (1 << ((n) & EVK_BITS_MASK)) | |
43 | ||
44 | #define EVK_KEYUP(n, bits) \ | |
45 | (bits)[((n)>>EVK_BITS_SHIFT)] &= ~(1 << ((n) & EVK_BITS_MASK)) | |
46 | ||
47 | #define EVK_IS_KEYDOWN(n, bits) \ | |
48 | (((bits)[((n)>>EVK_BITS_SHIFT)] & (1 << ((n) & EVK_BITS_MASK))) != 0) | |
49 | ||
50 | class IOHIKeyboardMapper : public OSObject | |
51 | { | |
52 | OSDeclareDefaultStructors(IOHIKeyboardMapper); | |
53 | ||
54 | private: | |
55 | IOHIKeyboard * _delegate; // KeyMap delegate | |
56 | bool _mappingShouldBeFreed; // true if map can be IOFree'd | |
57 | NXParsedKeyMapping _parsedMapping; // current system-wide keymap | |
58 | ||
59 | public: | |
60 | static IOHIKeyboardMapper * keyboardMapper( | |
61 | IOHIKeyboard * delegate, | |
62 | const UInt8 * mapping, | |
63 | UInt32 mappingLength, | |
64 | bool mappingShouldBeFreed ); | |
65 | ||
66 | virtual bool init(IOHIKeyboard * delegate, | |
67 | const UInt8 * mapping, | |
68 | UInt32 mappingLength, | |
69 | bool mappingShouldBeFreed); | |
70 | virtual void free(); | |
71 | ||
72 | virtual const UInt8 * mapping(); | |
73 | virtual UInt32 mappingLength(); | |
74 | virtual bool serialize(OSSerialize *s) const; | |
75 | ||
76 | virtual void translateKeyCode(UInt8 key, bool keyDown, kbdBitVector keyBits); | |
77 | virtual UInt8 getParsedSpecialKey(UInt8 logical); //retrieve a key from _parsedMapping | |
78 | ||
79 | ||
80 | private: | |
81 | virtual bool parseKeyMapping(const UInt8 * mapping, | |
82 | UInt32 mappingLength, | |
83 | NXParsedKeyMapping * parsedMapping) const; | |
84 | ||
85 | virtual void calcModBit(int bit, kbdBitVector keyBits); | |
86 | virtual void doModCalc(int key, kbdBitVector keyBits); | |
87 | virtual void doCharGen(int keyCode, bool down); | |
88 | }; | |
89 | ||
90 | #endif _IOHIKEYBOARDMAPPER_H | |
91 | ||
92 | /* | |
93 | * HISTORICAL NOTE: | |
94 | * The "delegate" object had to respond to the following protocol; | |
95 | * this protocol has since been merged into the IOHIKeyboard class. | |
96 | * | |
97 | * @protocol KeyMapDelegate | |
98 | * | |
99 | * - keyboardEvent :(unsigned)eventType | |
100 | * flags :(unsigned)flags | |
101 | * keyCode :(unsigned)keyCode | |
102 | * charCode:(unsigned)charCode | |
103 | * charSet :(unsigned)charSet | |
104 | * originalCharCode:(unsigned)origCharCode | |
105 | * originalCharSet:(unsigned)origCharSet; | |
106 | * | |
107 | * - keyboardSpecialEvent:(unsigned)eventType | |
108 | * flags :(unsigned)flags | |
109 | * keyCode :(unsigned)keyCode | |
110 | * specialty:(unsigned)flavor; | |
111 | * | |
112 | * - updateEventFlags:(unsigned)flags; // Does not generate events | |
113 | * | |
114 | * - (unsigned)eventFlags; // Global event flags | |
115 | * - (unsigned)deviceFlags; // per-device event flags | |
116 | * - setDeviceFlags:(unsigned)flags; // Set device event flags | |
117 | * - (bool)alphaLock; // current alpha-lock state | |
118 | * - setAlphaLock:(bool)val; // Set current alpha-lock state | |
119 | * - (bool)charKeyActive; // Is a character gen. key down? | |
120 | * - setCharKeyActive:(bool)val; // Note that a char gen key is down. | |
121 | * | |
122 | * @end | |
123 | */ |