CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / windows / KeyboardLayout.h
bloba7ad0f09ffc3ac9553304c19ca73eb4878053405
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Dainis Jonitis, <Dainis_Jonitis@exigengroup.lv>.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef KeyboardLayout_h__
39 #define KeyboardLayout_h__
41 #include "nscore.h"
42 #include <windows.h>
44 #define NS_NUM_OF_KEYS 50
46 #define VK_OEM_1 0xBA // ';:' for US
47 #define VK_OEM_PLUS 0xBB // '+' any country
48 #define VK_OEM_MINUS 0xBD // '-' any country
50 namespace mozilla {
51 namespace widget {
53 // 0 - Normal
54 // 1 - Shift
55 // 2 - Control
56 // 3 - Control + Shift
57 // 4 - Alt
58 // 5 - Alt + Shift
59 // 6 - Alt + Control (AltGr)
60 // 7 - Alt + Control + Shift (AltGr + Shift)
61 // 8 - CapsLock
62 // 9 - CapsLock + Shift
63 // 10 - CapsLock + Control
64 // 11 - CapsLock + Control + Shift
65 // 12 - CapsLock + Alt
66 // 13 - CapsLock + Alt + Shift
67 // 14 - CapsLock + Alt + Control (CapsLock + AltGr)
68 // 15 - CapsLock + Alt + Control + Shift (CapsLock + AltGr + Shift)
70 enum eKeyShiftFlags
72 eShift = 0x01,
73 eCtrl = 0x02,
74 eAlt = 0x04,
75 eCapsLock = 0x08
78 struct DeadKeyEntry;
79 class DeadKeyTable;
82 class VirtualKey
84 union KeyShiftState
86 struct
88 PRUnichar Chars[4];
89 } Normal;
90 struct
92 const DeadKeyTable* Table;
93 PRUnichar DeadChar;
94 } DeadKey;
97 KeyShiftState mShiftStates[16];
98 PRUint16 mIsDeadKey;
100 void SetDeadKey(PRUint8 aShiftState, PRBool aIsDeadKey)
102 if (aIsDeadKey) {
103 mIsDeadKey |= 1 << aShiftState;
104 } else {
105 mIsDeadKey &= ~(1 << aShiftState);
109 public:
110 PRBool IsDeadKey(PRUint8 aShiftState) const
112 return (mIsDeadKey & (1 << aShiftState)) != 0;
115 void AttachDeadKeyTable(PRUint8 aShiftState,
116 const DeadKeyTable* aDeadKeyTable)
118 mShiftStates[aShiftState].DeadKey.Table = aDeadKeyTable;
121 void SetNormalChars(PRUint8 aShiftState, const PRUnichar* aChars,
122 PRUint32 aNumOfChars);
123 void SetDeadChar(PRUint8 aShiftState, PRUnichar aDeadChar);
124 const DeadKeyTable* MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
125 PRUint32 aEntries) const;
126 inline PRUnichar GetCompositeChar(PRUint8 aShiftState,
127 PRUnichar aBaseChar) const;
128 PRUint32 GetNativeUniChars(PRUint8 aShiftState,
129 PRUnichar* aUniChars = nsnull) const;
130 PRUint32 GetUniChars(PRUint8 aShiftState, PRUnichar* aUniChars,
131 PRUint8* aFinalShiftState) const;
135 class KeyboardLayout
137 struct DeadKeyTableListEntry
139 DeadKeyTableListEntry* next;
140 PRUint8 data[1];
143 HKL mKeyboardLayout;
145 VirtualKey mVirtualKeys[NS_NUM_OF_KEYS];
146 DeadKeyTableListEntry* mDeadKeyTableListHead;
147 PRInt32 mActiveDeadKey; // -1 = no active dead-key
148 PRUint8 mDeadKeyShiftState;
149 PRInt32 mLastVirtualKeyIndex;
150 PRUint8 mLastShiftState;
151 PRUnichar mChars[5]; // Dead-key + up to 4 characters
152 PRUint8 mShiftStates[5];
153 PRUint8 mNumOfChars;
155 static PRUint8 GetShiftState(const PBYTE aKbdState);
156 static void SetShiftState(PBYTE aKbdState, PRUint8 aShiftState);
157 static inline PRInt32 GetKeyIndex(PRUint8 aVirtualKey);
158 static int CompareDeadKeyEntries(const void* aArg1, const void* aArg2,
159 void* aData);
160 static PRBool AddDeadKeyEntry(PRUnichar aBaseChar, PRUnichar aCompositeChar,
161 DeadKeyEntry* aDeadKeyArray, PRUint32 aEntries);
162 PRBool EnsureDeadKeyActive(PRBool aIsActive, PRUint8 aDeadKey,
163 const PBYTE aDeadKeyKbdState);
164 PRUint32 GetDeadKeyCombinations(PRUint8 aDeadKey,
165 const PBYTE aDeadKeyKbdState,
166 PRUint16 aShiftStatesWithBaseChars,
167 DeadKeyEntry* aDeadKeyArray,
168 PRUint32 aMaxEntries);
169 void DeactivateDeadKeyState();
170 const DeadKeyTable* AddDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
171 PRUint32 aEntries);
172 void ReleaseDeadKeyTables();
174 public:
175 KeyboardLayout();
176 ~KeyboardLayout();
178 static PRBool IsPrintableCharKey(PRUint8 aVirtualKey);
179 static PRBool IsNumpadKey(PRUint8 aVirtualKey);
181 PRBool IsDeadKey() const
183 return (mLastVirtualKeyIndex >= 0) ?
184 mVirtualKeys[mLastVirtualKeyIndex].IsDeadKey(mLastShiftState) : PR_FALSE;
187 void LoadLayout(HKL aLayout);
188 void OnKeyDown(PRUint8 aVirtualKey);
189 PRUint32 GetUniChars(PRUnichar* aUniChars, PRUint8* aShiftStates,
190 PRUint32 aMaxChars) const;
191 PRUint32 GetUniCharsWithShiftState(PRUint8 aVirtualKey, PRUint8 aShiftStates,
192 PRUnichar* aUniChars,
193 PRUint32 aMaxChars) const;
195 HKL GetLayout() { return mKeyboardLayout; }
198 } // namespace widget
199 } // namespace mozilla
201 #endif