3 * @brief Defines the scim::HotkeyMatcher and scim::IMEngineHotkeyMatcher classes.
6 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
9 * Smart Common Input Method
11 * Copyright (c) 2005 James Su <suzhe@tsinghua.org.cn>
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this program; if not, write to the
26 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
27 * Boston, MA 02111-1307 USA
29 * $Id: scim_hotkey.h,v 1.5 2005/10/06 18:02:06 liuspider Exp $
32 #ifndef __SCIM_HOTKEY_H
33 #define __SCIM_HOTKEY_H
37 * @addtogroup Accessories
38 * @ingroup InputServiceFramework
43 * @brief This class is used to match a KeyEvent among a set of hotkeys.
45 * This class keeps the key event history so that it can match any kind of
46 * key events, including key release events, correctly.
48 * If there are large amount of hotkeys to be matched, this class can provide
49 * very good performance.
53 class HotkeyMatcherImpl;
55 HotkeyMatcherImpl *m_impl;
57 HotkeyMatcher (const HotkeyMatcher &);
58 const HotkeyMatcher & operator = (const HotkeyMatcher &);
72 * @brief Add a Hotkey into this HotkeyMatcher.
74 * If a same Hotkey was already added, then it'll be replaced by this new one.
76 * @param key A Hotkey to be added.
77 * @param id An id to be binded to this Hotkey.
79 void add_hotkey (const KeyEvent &key, int id);
82 * @brief Add a set of Hotkeys into this HotkeyMatcher.
84 * If a same Hotkey in the list was already added, then it'll be replaced by the new one.
86 * @param keys A set of Hotkeys to be added.
87 * @param id An id to be binded to these Hotkeys.
89 void add_hotkeys (const KeyEventList &keys, int id);
92 * @brief Find all Hotkeys binded to a specific id.
94 * @param id The id to be found.
95 * @param keys A KeyEventList object to hold all KeyEvents binded to the id.
96 * @return The number of Hotkeys found.
98 size_t find_hotkeys (int id, KeyEventList &keys) const;
101 * @brief Get all Hotkeys added into this HotkeyMatcher.
103 * @param keys A KeyEventList object to hold all KeyEvents.
104 * @param ids A int list to hold all corresponding IDs.
106 * @return The number of available Hotkeys.
108 size_t get_all_hotkeys (KeyEventList &keys, std::vector <int> &ids) const;
111 * @brief Reset the HotkeyMatcher.
113 * The KeyEvent queue will be cleared, all state will be reset.
114 * The Hotkeys which were already added will not be touched.
119 * @brief Clear all Hotkeys.
124 * @brief Push a KeyEvent into the queue.
126 * This KeyEvent will be matched against the available Hotkeys immediately.
128 * @param key The key to be pushed into.
130 void push_key_event (const KeyEvent &key);
133 * @brief Check if the last KeyEvent pushed by push_key_event () matched with any Hotkey.
135 * @return true If the KeyEvent matched with a Hotkey.
137 bool is_matched (void) const;
140 * @brief Get the match result.
142 * @return The corresponding id of the matched Hotkey. If no Hotkey was matched, return -1.
144 int get_match_result (void) const;
160 * @brief This class hold all Hotkeys for each IMEngines.
162 class IMEngineHotkeyMatcher
164 class IMEngineHotkeyMatcherImpl;
166 IMEngineHotkeyMatcherImpl *m_impl;
168 IMEngineHotkeyMatcher (const IMEngineHotkeyMatcher &);
169 const IMEngineHotkeyMatcher & operator = (const IMEngineHotkeyMatcher &);
172 IMEngineHotkeyMatcher ();
173 ~IMEngineHotkeyMatcher ();
176 * @brief Load all Hotkeys for IMEngines from Config.
178 * @param config The Config object in which the Hotkeys are stored.
180 void load_hotkeys (const ConfigPointer &config);
183 * @brief Save all Hotkeys for IMEngines to Config.
185 * @param config Store all Hotkeys to this Config object.
187 void save_hotkeys (const ConfigPointer &config) const;
190 * @brief Add a Hotkey for an IMEngine into this IMEngineHotkeyMatcher.
192 * @param key The Hotkey.
193 * @param uuid The UUID of the corresponding IMEngine.
195 void add_hotkey (const KeyEvent &key, const String &uuid, const ISE_TYPE &type);
198 * @brief Add a set of Hotkeys for an IMEngine into this IMEngineHotkeyMatcher.
200 * @param keys The Hotkeys.
201 * @param uuid The UUID of the corresponding IMEngine.
203 void add_hotkeys (const KeyEventList &keys, const String &uuid, const ISE_TYPE &type);
206 * @brief Find all Hotkeys binded to a specific IMEngine UUID.
208 * @param uuid The IMEngine uuid to be found.
209 * @param keys A KeyEventList object to hold all KeyEvents binded to the uuid.
210 * @return The number of Hotkeys found.
212 size_t find_hotkeys (const String &uuid, KeyEventList &keys) const;
215 * @brief Get all hotkeys in this IMEngineHotkeyMatcher.
217 * @param keys A list of all Hotkeys.
218 * @param uuids A list of all corresponding IMEngine UUIDs.
219 * @return the number of hotkeys found.
221 size_t get_all_hotkeys (KeyEventList &keys, std::vector <String> &uuids) const;
224 * @brief Reset the IMEngineHotkeyMatcher.
226 * The KeyEvent queue will be cleared, all state will be reset.
227 * The Hotkeys which were already added will not be touched.
232 * @brief Clear all Hotkeys and reset the IMEngineHotkeyMatcher.
237 * @brief Push a KeyEvent into the queue.
239 * This KeyEvent will be matched against the available Hotkeys immediately.
241 * @param key The key to be pushed into.
243 void push_key_event (const KeyEvent &key);
246 * @brief Check if the last KeyEvent pushed by push_key_event () matched with any Hotkey.
248 * @return true If the KeyEvent matched with a Hotkey.
250 bool is_matched (void) const;
253 * @brief Get the match result.
255 * @return The corresponding UUID of the matched Hotkey. If no Hotkey was matched, return null string.
257 ISEInfo get_match_result (void) const;
261 * @brief FrontEnd actions which could be binded with Hotkeys.
263 enum FrontEndHotkeyAction
265 SCIM_FRONTEND_HOTKEY_NOOP = 0, /**< No action */
266 SCIM_FRONTEND_HOTKEY_TRIGGER = 1, /**< Turn on/off the input method. */
267 SCIM_FRONTEND_HOTKEY_ON = 2, /**< Turn on the input method. */
268 SCIM_FRONTEND_HOTKEY_OFF = 3, /**< Turn off the input method. */
269 SCIM_FRONTEND_HOTKEY_NEXT_FACTORY = 4, /**< Switch current Input Context to use the next available IMEngine Factory. */
270 SCIM_FRONTEND_HOTKEY_PREVIOUS_FACTORY = 5, /**< Switch current Input Context to use the previous available IMEngine Factory. */
271 SCIM_FRONTEND_HOTKEY_SHOW_FACTORY_MENU = 6 /**< Show a menu of all available IMEngine Factories. */
275 * @brief This class hold all FrontEnd specific Hotkeys, such as trigger keys, on/off keys, etc.
277 class FrontEndHotkeyMatcher
279 class FrontEndHotkeyMatcherImpl;
281 FrontEndHotkeyMatcherImpl *m_impl;
283 FrontEndHotkeyMatcher (const FrontEndHotkeyMatcher &);
284 const FrontEndHotkeyMatcher & operator = (const FrontEndHotkeyMatcher &);
287 FrontEndHotkeyMatcher ();
288 ~FrontEndHotkeyMatcher ();
291 * @brief Load all FrontEnd specific Hotkeys from Config.
293 * @param config The Config object in which the Hotkeys are stored.
295 void load_hotkeys (const ConfigPointer &config);
298 * @brief Save all FrontEnd specific Hotkeys to Config.
300 * @param config Store all Hotkeys to this Config object.
302 void save_hotkeys (const ConfigPointer &config) const;
305 * @brief Add a Hotkey for an FrontEnd into this FrontEndHotkeyMatcher.
307 * @param key The Hotkey.
308 * @param action The action to do when the hotkey is matched.
310 void add_hotkey (const KeyEvent &key, FrontEndHotkeyAction action);
313 * @brief Add a set of Hotkeys for an FrontEnd into this FrontEndHotkeyMatcher.
315 * @param keys The Hotkeys.
316 * @param action The action to do when the hotkey is matched.
318 void add_hotkeys (const KeyEventList &keys, FrontEndHotkeyAction action);
321 * @brief Find all Hotkeys binded to a specific action.
323 * @param action The action to be found.
324 * @param keys A KeyEventList object to hold all KeyEvents binded to the action.
325 * @return The number of Hotkeys found.
327 size_t find_hotkeys (FrontEndHotkeyAction action, KeyEventList &keys) const;
330 * @brief Get all hotkeys in this FrontEndHotkeyMatcher.
332 * @param keys A list of all Hotkeys.
333 * @param actions A list of all corresponding actions
335 size_t get_all_hotkeys (KeyEventList &keys, std::vector <FrontEndHotkeyAction> &actions) const;
338 * @brief Reset the FrontEndHotkeyMatcher.
340 * The KeyEvent queue will be cleared, all state will be reset.
341 * The Hotkeys which were already added will not be touched.
346 * @brief Clear all Hotkeys and reset the FrontEndHotkeyMatcher.
351 * @brief Push a KeyEvent into the queue.
353 * This KeyEvent will be matched against the available Hotkeys immediately.
355 * @param key The key to be pushed into.
357 void push_key_event (const KeyEvent &key);
360 * @brief Check if the last KeyEvent pushed by push_key_event () matched with any Hotkey.
362 * @return true If the KeyEvent matched with a Hotkey.
364 bool is_matched (void) const;
367 * @brief Get the match result.
369 * @return The corresponding action of the matched Hotkey.
371 FrontEndHotkeyAction get_match_result (void) const;
378 #endif //__SCIM_HOTKEY_H
381 vi:ts=4:nowrap:ai:expandtab