LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PreKeymap.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-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 #ifndef PRE_KEYMAP_H
22 #define PRE_KEYMAP_H
23 
24 #include <palmimedefines.h>
25 
26 #include <qlist.h>
27 #include <qrect.h>
28 #include <qstring.h>
29 
30 class QFile;
31 
32 namespace Pre_Keyboard {
33 
34 // We're back to using Qt::Key definitions. This typedef allows us to change our mind...
35 typedef Qt::Key UKey;
36 
37 // Constants defined to make keyboard definitions more readable (and more stable as we change the values they point to...)
38 // Note that except for the Euro sign, they are only meant to represent a key and are never used as unicode characters for display purposes...
39 
40 const UKey cKey_None = UKey(0); // nothing...
41 const UKey cKey_Euro = UKey(0x20ac); // unicode "EURO SIGN" €
42 const UKey cKey_SymbolPicker = Qt::Key_Control; // not used in virtual keyboard: that's to trigger Webkit's symbol picker
43 const UKey cKey_Symbol = Qt::Key_Alt; // "new" virtual keyboard symbol key
44 
45 // special keys not mapping to already existing Qt keys: use unique value used only internaly.
46 const UKey cKey_ToggleSuggestions = UKey(0x01200200);
47 const UKey cKey_ToggleLanguage = UKey(0x01200201);
48 const UKey cKey_SwitchToQwerty = UKey(0x01200202);
49 const UKey cKey_SwitchToAzerty = UKey(0x01200203);
50 const UKey cKey_SwitchToQwertz = UKey(0x01200204);
51 const UKey cKey_ShowXT9Regions = UKey(0x01200209);
53 const UKey cKey_ClearDefaultKeyboards = UKey(0x0120020E);
54 const UKey cKey_Hide = UKey(0x0120020F);
55 const UKey cKey_ShowKeymapRegions = UKey(0x01200210);
56 const UKey cKey_StartStopRecording = UKey(0x01200211);
57 
58 const UKey cKey_ToggleSoundFeedback = UKey(0x01200216);
59 
60 // Keys that correspond to some text entry (label & entered text are equal)
61 const UKey cKey_DotCom = UKey(0x01200300);
62 const UKey cKey_DotOrg = UKey(0x01200301);
63 const UKey cKey_DotNet = UKey(0x01200302);
64 const UKey cKey_DotEdu = UKey(0x01200303);
65 const UKey cKey_DotGov = UKey(0x01200304);
66 const UKey cKey_DotCoUK = UKey(0x01200305);
67 const UKey cKey_DotDe = UKey(0x01200306);
68 const UKey cKey_DotFr = UKey(0x01200307);
69 const UKey cKey_DotUs = UKey(0x01200308);
70 const UKey cKey_ColonSlashSlash = UKey(0x01200309);
71 const UKey cKey_HTTPColonSlashSlash = UKey(0x0120030A);
72 const UKey cKey_HTTPSColonSlashSlash = UKey(0x0120030B);
73 const UKey cKey_Emoticon_Frown = UKey(0x0120030C);
74 const UKey cKey_Emoticon_Cry = UKey(0x0120030D);
75 const UKey cKey_Emoticon_Smile = UKey(0x0120030E);
76 const UKey cKey_Emoticon_Wink = UKey(0x0120030F);
77 const UKey cKey_Emoticon_Yuck = UKey(0x01200310);
78 const UKey cKey_Emoticon_Gasp = UKey(0x01200311);
79 const UKey cKey_Emoticon_Heart = UKey(0x01200312);
80 const UKey cKey_Emoticon_Options = UKey(0x01200313);
81 
82 // Keys used for keyboard/language selections
85 
86 // helper: can a UKey code be used as a Qt::Key and/or as an acceptable unicode character?
87 inline bool UKeyIsUnicodeQtKey(UKey ukey) { return ukey >= ' ' && ukey < Qt::Key_Escape; }
88 inline bool UKeyIsFunctionKey(UKey ukey) { return ukey >= Qt::Key_Escape; }
89 inline bool UKeyIsTextShortcutKey(UKey ukey) { return ukey >= 0x01200300 && ukey <= 0x012003FF; }
91 inline bool UKeyIsEmoticonKey(UKey ukey) { return ukey >= cKey_Emoticon_Frown && ukey <= cKey_Emoticon_Options; }
92 
93 const QPoint cOutside(-1, -1); // special value meaning representing "outside of keyboard", or "no key".
94 
95 class PreKeymap
96 {
97 public:
98  enum {
101  };
102 
104  {
106 
110  };
111 
113  {
115 
118  };
119 
120  enum ELayoutPage {
123 
125  };
126 
127  enum ETabAction {
131  };
132 
133  typedef const UKey constUKeyArray[];
134 
135  struct WKey {
136  void set(UKey key, float weight = 1, const UKey * extended = NULL)
137  {
138  m_weight = weight, m_key = key, m_altkey = key, m_extended = extended;
139  }
140  void set(UKey key, UKey altkey, float weight = 1, const UKey * extended = NULL)
141  {
142  m_weight = weight, m_key = key, m_altkey = altkey, m_extended = extended;
143  }
144  void hide()
145  {
147  }
148  bool operator !=(const WKey & rhs)
149  {
150  return m_weight != rhs.m_weight || m_key != rhs.m_weight || m_altkey != rhs.m_altkey || m_extended != rhs.m_extended;
151  }
152 
153  float m_weight;
156  const UKey * m_extended;
157  };
158 
161  typedef float VLimits[cKeymapRows];
162 
163  struct LayoutFamily {
164 
165  LayoutFamily(const char * name, const char * defaultLanguage, uint16_t primaryID, uint16_t secondaryID, Layout * layout);
166 
167  const WKey & wkey(int x, int y) const { return (*m_layout)[y][x]; }
168  WKey & writable_wkey(int x, int y) const { return (*m_layout)[y][x]; }
169  UKey key(int x, int y, ELayoutPage page) const { return (page == eLayoutPage_plain) ? wkey(x, y).m_key : wkey(x, y).m_altkey; }
170  float weight(int x, int y) const { return wkey(x, y).m_weight; }
171 
172  const char * m_name;
173  const char * m_defaultLanguage;
174  uint16_t m_primaryID;
175  uint16_t m_secondaryID;
176 
178 
179  // self registration of layout families. Start with first, iterate until nextFamily is null.
181 
182  static const LayoutFamily * findLayoutFamily(const char * name, bool returnNullNotDefaultIfNotFound = true);
183 
184  static const LayoutFamily * s_firstFamily;
185 
186  };
187 
188  PreKeymap();
189 
190  void setRect(int x, int y, int w, int h) { m_rect.setRect(x, y, w, h); m_limitsDirty = true; }
191  const QRect & rect() const { return m_rect; }
192  void setRowHeight(int rowIndex, int height);
193 
194  QPoint pointToKeyboard(const QPoint & location); // convert screen coordinate in keyboard coordinate
195  int keyboardToKeyZone(QPoint keyboardCoordinate, QRect & outZone); // convert keyboard coordinate to rect of the key
196 
197  // The following functions that return a bool return true when the layout effectively changed (and you probably need to update your display)
198  bool setLayoutFamily(const LayoutFamily * layoutFamily);
199  const LayoutFamily* layoutFamily() const { return m_layoutFamily; }
200  bool setLanguageName(const std::string & name); // if empty string, hide language key, otherwise show it.
201  void keyboardCombosChanged(); // called when available keyboard combos change
202  QList<const char *> getLayoutList();
203  const char * getLayoutDefaultLanguage(const char * layoutName);
204 
206  EShiftMode shiftMode() const { return m_shiftMode; }
208  ESymbolMode symbolMode() const { return m_symbolMode; }
209  bool setShiftKeyDown(bool shiftKeyDown);
210  bool setSymbolKeyDown(bool symbolKeyDown);
211  bool setEditorState(const PalmIME::EditorState & editorState);
212  const PalmIME::EditorState & editorState() const { return m_editorState; }
213  bool setAutoCap(bool autoCap);
214 
215  bool isSymbolActive() const { return ((m_symbolMode == eSymbolMode_Lock) ? 1 : 0) + (m_symbolDown ? 1 : 0) == 1; }
216  bool isShiftActive() const { return ((m_shiftMode == eShiftMode_Once) ? 1 : 0) + (m_shiftDown ? 1 : 0) == 1; }
217  bool isShiftDown() const { return m_shiftDown; }
218  bool isSymbolDown() const { return m_symbolDown; }
219  bool isCapActive() const { return (m_shiftDown && m_shiftMode == eShiftMode_Off) || (!m_shiftDown && m_shiftMode != eShiftMode_Off); }
220  bool isCapOrAutoCapActive() const { return m_autoCap || isCapActive(); }
221  bool isAutoCapActive() const { return m_autoCap; }
222 
223  UKey map(QPoint p) { return map(p.x(), p.y()); }
224  UKey map(int x, int y);
225  UKey map(QPoint p, ELayoutPage page) { return map(p.x(), p.y(), page); }
226  UKey map(int x, int y, ELayoutPage page) { return isValidLocation(x, y) ? m_layoutFamily->key(x, y, page) : cKey_None; }
227  quint32 getPage() const { return m_layoutPage; }
228 
229  ETabAction tabAction() const;
230 
231  const char * layoutName() { return m_layoutFamily->m_name; }
232  uint16_t primaryKeyboardID() { return m_layoutFamily->m_primaryID; }
233  uint16_t secondaryKeyboardID() { return m_layoutFamily->m_secondaryID; }
234 
235  bool generateKeyboardLayout(const char * fullPath);
236 
237  static inline bool isValidLocation(int x, int y) { return x >= 0 && x < cKeymapColumns && y >= 0 && y < cKeymapRows; }
238  static inline bool isValidLocation(QPoint location) { return isValidLocation(location.x(), location.y()); }
239 
240  const UKey * getExtendedChars(QPoint keyboardCoordinate); // MAY RETURN NULL!
241  QString getKeyDisplayString(UKey key, bool logging = false); // for display purposes. NOT ALL KEYS can be handled that way! "logging" gives you more...
242  bool showEmoticonsAsGraphics() { return true; /*m_editorState.flags & PalmIME::FieldFlags_Emoticons*/ }
243 
244  int updateLimits();
245 
246 private:
247  EShiftMode m_shiftMode;
248  ESymbolMode m_symbolMode;
249  bool m_shiftDown;
250  bool m_symbolDown;
251  bool m_autoCap;
252  bool m_numLock; // in number & phone fields, when numbers need shift.
253  PalmIME::EditorState m_editorState;
254  const LayoutFamily * m_layoutFamily;
255  ELayoutPage m_layoutPage;
256  QRect m_rect;
257  int m_rowHeight[cKeymapRows];
258  HLimits m_hlimits;
259  VLimits m_vlimits;
260  bool m_limitsDirty;
261  int m_limitsVersion;
262 
263  QString m_languageName;
264 
265  bool updateMapping(); // true if layout changed
266  void updateLanguageKey();
267 
268  int xCenterOfKey(int touchX, int x, int y, float weight);
269  int yCenterOfRow(int y);
270 };
271 
272 }; // namespace Pre_Keyboard
273 
274 #endif // PRE_KEYMAP_H