OSDN Git Service

use boost_1_56_0 and build by VS2013
[yamy/yamy.git] / engine.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
2 // engine.h\r
3 \r
4 \r
5 #ifndef _ENGINE_H\r
6 #  define _ENGINE_H\r
7 \r
8 #  include "multithread.h"\r
9 #  include "setting.h"\r
10 #  include "msgstream.h"\r
11 #  include "hook.h"\r
12 #  include <set>\r
13 #  include <queue>\r
14 \r
15 \r
16 enum {\r
17         ///\r
18         WM_APP_engineNotify = WM_APP + 110,\r
19 };\r
20 \r
21 \r
22 ///\r
23 enum EngineNotify {\r
24         EngineNotify_shellExecute,                      ///\r
25         EngineNotify_loadSetting,                       ///\r
26         EngineNotify_showDlg,                           ///\r
27         EngineNotify_helpMessage,                       ///\r
28         EngineNotify_setForegroundWindow,               ///\r
29         EngineNotify_clearLog,                  ///\r
30 };\r
31 \r
32 \r
33 ///\r
34 class Engine\r
35 {\r
36 private:\r
37         enum {\r
38                 MAX_GENERATE_KEYBOARD_EVENTS_RECURSION_COUNT = 64, ///\r
39                 MAX_KEYMAP_PREFIX_HISTORY = 64, ///\r
40         };\r
41 \r
42         typedef Keymaps::KeymapPtrList KeymapPtrList;   ///\r
43 \r
44         /// focus of a thread\r
45         class FocusOfThread\r
46         {\r
47         public:\r
48                 DWORD m_threadId;                               /// thread id\r
49                 HWND m_hwndFocus;                               /** window that has focus on\r
50                                                     the thread */\r
51                 tstringi m_className;                   /// class name of hwndFocus\r
52                 tstringi m_titleName;                   /// title name of hwndFocus\r
53                 bool m_isConsole;                               /// is hwndFocus console ?\r
54                 KeymapPtrList m_keymaps;                        /// keymaps\r
55 \r
56         public:\r
57                 ///\r
58                 FocusOfThread() : m_threadId(0), m_hwndFocus(NULL), m_isConsole(false) { }\r
59         };\r
60         typedef std::map<DWORD /*ThreadId*/, FocusOfThread> FocusOfThreads;     ///\r
61 \r
62         typedef std::list<DWORD /*ThreadId*/> ThreadIds;        ///\r
63 \r
64         /// current status in generateKeyboardEvents\r
65         class Current\r
66         {\r
67         public:\r
68                 const Keymap *m_keymap;                 /// current keymap\r
69                 ModifiedKey m_mkey;             /// current processing key that user inputed\r
70                 /// index in currentFocusOfThread-&gt;keymaps\r
71                 Keymaps::KeymapPtrList::iterator m_i;\r
72 \r
73         public:\r
74                 ///\r
75                 bool isPressed() const {\r
76                         return m_mkey.m_modifier.isOn(Modifier::Type_Down);\r
77                 }\r
78         };\r
79 \r
80         friend class FunctionParam;\r
81 \r
82         /// part of keySeq\r
83         enum Part {\r
84                 Part_all,                                       ///\r
85                 Part_up,                                        ///\r
86                 Part_down,                                      ///\r
87         };\r
88 \r
89         ///\r
90         class EmacsEditKillLine\r
91         {\r
92                 tstring m_buf;  /// previous kill-line contents\r
93 \r
94         public:\r
95                 bool m_doForceReset;    ///\r
96 \r
97         private:\r
98                 ///\r
99                 HGLOBAL makeNewKillLineBuf(const _TCHAR *i_data, int *i_retval);\r
100 \r
101         public:\r
102                 ///\r
103                 void reset() {\r
104                         m_buf.resize(0);\r
105                 }\r
106                 /** EmacsEditKillLineFunc.\r
107                 clear the contents of the clopboard\r
108                 at that time, confirm if it is the result of the previous kill-line\r
109                 */\r
110                 void func();\r
111                 /// EmacsEditKillLinePred\r
112                 int pred();\r
113         };\r
114 \r
115         /// window positon for &amp;WindowHMaximize, &amp;WindowVMaximize\r
116         class WindowPosition\r
117         {\r
118         public:\r
119                 ///\r
120                 enum Mode {\r
121                         Mode_normal,                            ///\r
122                         Mode_H,                                 ///\r
123                         Mode_V,                                 ///\r
124                         Mode_HV,                                        ///\r
125                 };\r
126 \r
127         public:\r
128                 HWND m_hwnd;                            ///\r
129                 RECT m_rc;                                      ///\r
130                 Mode m_mode;                            ///\r
131 \r
132         public:\r
133                 ///\r
134                 WindowPosition(HWND i_hwnd, const RECT &i_rc, Mode i_mode)\r
135                                 : m_hwnd(i_hwnd), m_rc(i_rc), m_mode(i_mode) { }\r
136         };\r
137         typedef std::list<WindowPosition> WindowPositions;\r
138 \r
139         typedef std::list<HWND> WindowsWithAlpha; /// windows for &amp;WindowSetAlpha\r
140 \r
141         enum InterruptThreadReason {\r
142                 InterruptThreadReason_Terminate,\r
143                 InterruptThreadReason_Pause,\r
144                 InterruptThreadReason_Resume,\r
145         };\r
146 \r
147         ///\r
148         class InputHandler {\r
149         public:\r
150                 typedef int (*INSTALL_HOOK)(INPUT_DETOUR i_keyboardDetour, Engine *i_engine, bool i_install);\r
151 \r
152                 static unsigned int WINAPI run(void *i_this);\r
153 \r
154                 InputHandler(INSTALL_HOOK i_installHook, INPUT_DETOUR i_inputDetour);\r
155 \r
156                 ~InputHandler();\r
157 \r
158                 void run();\r
159 \r
160                 int start(Engine *i_engine);\r
161 \r
162                 int stop();\r
163 \r
164         private:\r
165                 unsigned m_threadId;\r
166                 HANDLE m_hThread;\r
167                 HANDLE m_hEvent; \r
168                 INSTALL_HOOK m_installHook;\r
169                 INPUT_DETOUR m_inputDetour;\r
170                 Engine *m_engine;\r
171         };\r
172 \r
173 private:\r
174         CriticalSection m_cs;                           /// criticalSection\r
175 \r
176         // setting\r
177         HWND m_hwndAssocWindow;                 /** associated window (we post\r
178                                                     message to it) */\r
179         Setting * volatile m_setting;                   /// setting\r
180 \r
181         // engine thread state\r
182         HANDLE m_threadHandle;\r
183         unsigned m_threadId;\r
184         std::deque<KEYBOARD_INPUT_DATA> *m_inputQueue;\r
185         HANDLE m_queueMutex;\r
186         MSLLHOOKSTRUCT m_msllHookCurrent;\r
187         bool m_buttonPressed;\r
188         bool m_dragging;\r
189         InputHandler m_keyboardHandler;\r
190         InputHandler m_mouseHandler;\r
191         HANDLE m_readEvent;                             /** reading from mayu device\r
192                                                     has been completed */\r
193         OVERLAPPED m_ol;                                /** for async read/write of\r
194                                                     mayu device */\r
195         HANDLE m_hookPipe;                              /// named pipe for &SetImeString\r
196         HMODULE m_sts4mayu;                             /// DLL module for ThumbSense\r
197         HMODULE m_cts4mayu;                             /// DLL module for ThumbSense\r
198         bool volatile m_isLogMode;                      /// is logging mode ?\r
199         bool volatile m_isEnabled;                      /// is enabled  ?\r
200         bool volatile m_isSynchronizing;                /// is synchronizing ?\r
201         HANDLE m_eSync;                         /// event for synchronization\r
202         int m_generateKeyboardEventsRecursionGuard;     /** guard against too many\r
203                                                     recursion */\r
204 \r
205         // current key state\r
206         Modifier m_currentLock;                 /// current lock key's state\r
207         int m_currentKeyPressCount;                     /** how many keys are pressed\r
208                                                     phisically ? */\r
209         int m_currentKeyPressCountOnWin32;              /** how many keys are pressed\r
210                                                     on win32 ? */\r
211         Key *m_lastGeneratedKey;                        /// last generated key\r
212         Key *m_lastPressedKey[2];                       /// last pressed key\r
213         ModifiedKey m_oneShotKey;                       /// one shot key\r
214         unsigned int m_oneShotRepeatableRepeatCount; /// repeat count of one shot key\r
215         bool m_isPrefix;                                /// is prefix ?\r
216         bool m_doesIgnoreModifierForPrefix;             /** does ignore modifier key\r
217                                                     when prefixed ? */\r
218         bool m_doesEditNextModifier;                    /** does edit next user input\r
219                                                     key's modifier ? */\r
220         Modifier m_modifierForNextKey;          /** modifier for next key if\r
221                                                     above is true */\r
222 \r
223         /** current keymaps.\r
224             <dl>\r
225             <dt>when &amp;OtherWindowClass\r
226             <dd>currentKeymap becoms currentKeymaps[++ Current::i]\r
227             <dt>when &amp;KeymapParent\r
228             <dd>currentKeymap becoms currentKeyamp-&gt;parentKeymap\r
229             <dt>other\r
230             <dd>currentKeyamp becoms *Current::i\r
231             </dl>\r
232         */\r
233         const Keymap * volatile m_currentKeymap;        /// current keymap\r
234         FocusOfThreads /*volatile*/ m_focusOfThreads;   ///\r
235         FocusOfThread * volatile m_currentFocusOfThread; ///\r
236         FocusOfThread m_globalFocus;                    ///\r
237         HWND m_hwndFocus;                               /// current focus window\r
238         ThreadIds m_attachedThreadIds;  ///\r
239         ThreadIds m_detachedThreadIds;  ///\r
240 \r
241         // for functions\r
242         KeymapPtrList m_keymapPrefixHistory;            /// for &amp;KeymapPrevPrefix\r
243         EmacsEditKillLine m_emacsEditKillLine;  /// for &amp;EmacsEditKillLine\r
244         const ActionFunction *m_afShellExecute; /// for &amp;ShellExecute\r
245 \r
246         WindowPositions m_windowPositions;              ///\r
247         WindowsWithAlpha m_windowsWithAlpha;            ///\r
248 \r
249         tstring m_helpMessage;                  /// for &amp;HelpMessage\r
250         tstring m_helpTitle;                            /// for &amp;HelpMessage\r
251         int m_variable;                         /// for &amp;Variable,\r
252         ///  &amp;Repeat\r
253 \r
254 public:\r
255         tomsgstream &m_log;                             /** log stream (output to log\r
256                                                     dialog's edit) */\r
257 \r
258 public:\r
259         /// keyboard handler thread\r
260         static unsigned int WINAPI keyboardDetour(Engine *i_this, WPARAM i_wParam, LPARAM i_lParam);\r
261         /// mouse handler thread\r
262         static unsigned int WINAPI mouseDetour(Engine *i_this, WPARAM i_wParam, LPARAM i_lParam);\r
263 private:\r
264         ///\r
265         unsigned int keyboardDetour(KBDLLHOOKSTRUCT *i_kid);\r
266         ///\r
267         unsigned int mouseDetour(WPARAM i_message, MSLLHOOKSTRUCT *i_mid);\r
268         ///\r
269         unsigned int injectInput(const KEYBOARD_INPUT_DATA *i_kid, const KBDLLHOOKSTRUCT *i_kidRaw);\r
270 \r
271 private:\r
272         /// keyboard handler thread\r
273         static unsigned int WINAPI keyboardHandler(void *i_this);\r
274         ///\r
275         void keyboardHandler();\r
276 \r
277         /// check focus window\r
278         void checkFocusWindow();\r
279         /// is modifier pressed ?\r
280         bool isPressed(Modifier::Type i_mt);\r
281         /// fix modifier key\r
282         bool fixModifierKey(ModifiedKey *io_mkey, Keymap::AssignMode *o_am);\r
283 \r
284         /// output to log\r
285         void outputToLog(const Key *i_key, const ModifiedKey &i_mkey,\r
286                                          int i_debugLevel);\r
287 \r
288         /// genete modifier events\r
289         void generateModifierEvents(const Modifier &i_mod);\r
290 \r
291         /// genete event\r
292         void generateEvents(Current i_c, const Keymap *i_keymap, Key *i_event);\r
293 \r
294         /// generate keyboard event\r
295         void generateKeyEvent(Key *i_key, bool i_doPress, bool i_isByAssign);\r
296         ///\r
297         void generateActionEvents(const Current &i_c, const Action *i_a,\r
298                                                           bool i_doPress);\r
299         ///\r
300         void generateKeySeqEvents(const Current &i_c, const KeySeq *i_keySeq,\r
301                                                           Part i_part);\r
302         ///\r
303         void generateKeyboardEvents(const Current &i_c);\r
304         ///\r
305         void beginGeneratingKeyboardEvents(const Current &i_c, bool i_isModifier);\r
306 \r
307         /// pop all pressed key on win32\r
308         void keyboardResetOnWin32();\r
309 \r
310         /// get current modifiers\r
311         Modifier getCurrentModifiers(Key *i_key, bool i_isPressed);\r
312 \r
313         /// describe bindings\r
314         void describeBindings();\r
315 \r
316         /// update m_lastPressedKey\r
317         void updateLastPressedKey(Key *i_key);\r
318 \r
319         /// set current keymap\r
320         void setCurrentKeymap(const Keymap *i_keymap,\r
321                                                   bool i_doesAddToHistory = false);\r
322         /** open mayu device\r
323             @return true if mayu device successfully is opened\r
324         */\r
325         bool open();\r
326 \r
327         /// close mayu device\r
328         void close();\r
329 \r
330         /// load/unload [sc]ts4mayu.dll\r
331         void manageTs4mayu(TCHAR *i_ts4mayuDllName, TCHAR *i_dependDllName,\r
332                                            bool i_load, HMODULE *i_pTs4mayu);\r
333 \r
334 private:\r
335         // BEGINING OF FUNCTION DEFINITION\r
336         /// send a default key to Windows\r
337         void funcDefault(FunctionParam *i_param);\r
338         /// use a corresponding key of a parent keymap\r
339         void funcKeymapParent(FunctionParam *i_param);\r
340         /// use a corresponding key of a current window\r
341         void funcKeymapWindow(FunctionParam *i_param);\r
342         /// use a corresponding key of the previous prefixed keymap\r
343         void funcKeymapPrevPrefix(FunctionParam *i_param, int i_previous);\r
344         /// use a corresponding key of an other window class, or use a default key\r
345         void funcOtherWindowClass(FunctionParam *i_param);\r
346         /// prefix key\r
347         void funcPrefix(FunctionParam *i_param, const Keymap *i_keymap,\r
348                                         BooleanType i_doesIgnoreModifiers = BooleanType_true);\r
349         /// other keymap's key\r
350         void funcKeymap(FunctionParam *i_param, const Keymap *i_keymap);\r
351         /// sync\r
352         void funcSync(FunctionParam *i_param);\r
353         /// toggle lock\r
354         void funcToggle(FunctionParam *i_param, ModifierLockType i_lock,\r
355                                         ToggleType i_toggle = ToggleType_toggle);\r
356         /// edit next user input key's modifier\r
357         void funcEditNextModifier(FunctionParam *i_param,\r
358                                                           const Modifier &i_modifier);\r
359         /// variable\r
360         void funcVariable(FunctionParam *i_param, int i_mag, int i_inc);\r
361         /// repeat N times\r
362         void funcRepeat(FunctionParam *i_param, const KeySeq *i_keySeq,\r
363                                         int i_max = 10);\r
364         /// undefined (bell)\r
365         void funcUndefined(FunctionParam *i_param);\r
366         /// ignore\r
367         void funcIgnore(FunctionParam *i_param);\r
368         /// post message\r
369         void funcPostMessage(FunctionParam *i_param, ToWindowType i_window,\r
370                                                  UINT i_message, WPARAM i_wParam, LPARAM i_lParam);\r
371         /// ShellExecute\r
372         void funcShellExecute(FunctionParam *i_param, const StrExprArg &i_operation,\r
373                                                   const StrExprArg &i_file, const StrExprArg &i_parameters,\r
374                                                   const StrExprArg &i_directory,\r
375                                                   ShowCommandType i_showCommand);\r
376         /// SetForegroundWindow\r
377         void funcSetForegroundWindow(FunctionParam *i_param,\r
378                                                                  const tregex &i_windowClassName,\r
379                                                                  LogicalOperatorType i_logicalOp\r
380                                                                  = LogicalOperatorType_and,\r
381                                                                  const tregex &i_windowTitleName\r
382                                                                  = tregex(_T(".*")));\r
383         /// load setting\r
384         void funcLoadSetting(FunctionParam *i_param,\r
385                                                  const StrExprArg &i_name = StrExprArg());\r
386         /// virtual key\r
387         void funcVK(FunctionParam *i_param, VKey i_vkey);\r
388         /// wait\r
389         void funcWait(FunctionParam *i_param, int i_milliSecond);\r
390         /// investigate WM_COMMAND, WM_SYSCOMMAND\r
391         void funcInvestigateCommand(FunctionParam *i_param);\r
392         /// show mayu dialog box\r
393         void funcMayuDialog(FunctionParam *i_param, MayuDialogType i_dialog,\r
394                                                 ShowCommandType i_showCommand);\r
395         /// describe bindings\r
396         void funcDescribeBindings(FunctionParam *i_param);\r
397         /// show help message\r
398         void funcHelpMessage(FunctionParam *i_param,\r
399                                                  const StrExprArg &i_title = StrExprArg(),\r
400                                                  const StrExprArg &i_message = StrExprArg());\r
401         /// show variable\r
402         void funcHelpVariable(FunctionParam *i_param, const StrExprArg &i_title);\r
403         /// raise window\r
404         void funcWindowRaise(FunctionParam *i_param,\r
405                                                  TargetWindowType i_twt = TargetWindowType_overlapped);\r
406         /// lower window\r
407         void funcWindowLower(FunctionParam *i_param,\r
408                                                  TargetWindowType i_twt = TargetWindowType_overlapped);\r
409         /// minimize window\r
410         void funcWindowMinimize(FunctionParam *i_param, TargetWindowType i_twt\r
411                                                         = TargetWindowType_overlapped);\r
412         /// maximize window\r
413         void funcWindowMaximize(FunctionParam *i_param, TargetWindowType i_twt\r
414                                                         = TargetWindowType_overlapped);\r
415         /// maximize window horizontally\r
416         void funcWindowHMaximize(FunctionParam *i_param, TargetWindowType i_twt\r
417                                                          = TargetWindowType_overlapped);\r
418         /// maximize window virtically\r
419         void funcWindowVMaximize(FunctionParam *i_param, TargetWindowType i_twt\r
420                                                          = TargetWindowType_overlapped);\r
421         /// maximize window virtically or horizontally\r
422         void funcWindowHVMaximize(FunctionParam *i_param, BooleanType i_isHorizontal,\r
423                                                           TargetWindowType i_twt\r
424                                                           = TargetWindowType_overlapped);\r
425         /// move window\r
426         void funcWindowMove(FunctionParam *i_param, int i_dx, int i_dy,\r
427                                                 TargetWindowType i_twt\r
428                                                 = TargetWindowType_overlapped);\r
429         /// move window to ...\r
430         void funcWindowMoveTo(FunctionParam *i_param, GravityType i_gravityType,\r
431                                                   int i_dx, int i_dy, TargetWindowType i_twt\r
432                                                   = TargetWindowType_overlapped);\r
433         /// move window visibly\r
434         void funcWindowMoveVisibly(FunctionParam *i_param,\r
435                                                            TargetWindowType i_twt\r
436                                                            = TargetWindowType_overlapped);\r
437         /// move window to other monitor\r
438         void funcWindowMonitorTo(FunctionParam *i_param,\r
439                                                          WindowMonitorFromType i_fromType, int i_monitor,\r
440                                                          BooleanType i_adjustPos = BooleanType_true,\r
441                                                          BooleanType i_adjustSize = BooleanType_false);\r
442         /// move window to other monitor\r
443         void funcWindowMonitor(FunctionParam *i_param, int i_monitor,\r
444                                                    BooleanType i_adjustPos = BooleanType_true,\r
445                                                    BooleanType i_adjustSize = BooleanType_false);\r
446         ///\r
447         void funcWindowClingToLeft(FunctionParam *i_param,\r
448                                                            TargetWindowType i_twt\r
449                                                            = TargetWindowType_overlapped);\r
450         ///\r
451         void funcWindowClingToRight(FunctionParam *i_param,\r
452                                                                 TargetWindowType i_twt\r
453                                                                 = TargetWindowType_overlapped);\r
454         ///\r
455         void funcWindowClingToTop(FunctionParam *i_param,\r
456                                                           TargetWindowType i_twt\r
457                                                           = TargetWindowType_overlapped);\r
458         ///\r
459         void funcWindowClingToBottom(FunctionParam *i_param,\r
460                                                                  TargetWindowType i_twt\r
461                                                                  = TargetWindowType_overlapped);\r
462         /// close window\r
463         void funcWindowClose(FunctionParam *i_param,\r
464                                                  TargetWindowType i_twt = TargetWindowType_overlapped);\r
465         /// toggle top-most flag of the window\r
466         void funcWindowToggleTopMost(FunctionParam *i_param);\r
467         /// identify the window\r
468         void funcWindowIdentify(FunctionParam *i_param);\r
469         /// set alpha blending parameter to the window\r
470         void funcWindowSetAlpha(FunctionParam *i_param, int i_alpha);\r
471         /// redraw the window\r
472         void funcWindowRedraw(FunctionParam *i_param);\r
473         /// resize window to\r
474         void funcWindowResizeTo(FunctionParam *i_param, int i_width, int i_height,\r
475                                                         TargetWindowType i_twt\r
476                                                         = TargetWindowType_overlapped);\r
477         /// move the mouse cursor\r
478         void funcMouseMove(FunctionParam *i_param, int i_dx, int i_dy);\r
479         /// send a mouse-wheel-message to Windows\r
480         void funcMouseWheel(FunctionParam *i_param, int i_delta);\r
481         /// convert the contents of the Clipboard to upper case or lower case\r
482         void funcClipboardChangeCase(FunctionParam *i_param,\r
483                                                                  BooleanType i_doesConvertToUpperCase);\r
484         /// convert the contents of the Clipboard to upper case\r
485         void funcClipboardUpcaseWord(FunctionParam *i_param);\r
486         /// convert the contents of the Clipboard to lower case\r
487         void funcClipboardDowncaseWord(FunctionParam *i_param);\r
488         /// set the contents of the Clipboard to the string\r
489         void funcClipboardCopy(FunctionParam *i_param, const StrExprArg &i_text);\r
490         ///\r
491         void funcEmacsEditKillLinePred(FunctionParam *i_param,\r
492                                                                    const KeySeq *i_keySeq1,\r
493                                                                    const KeySeq *i_keySeq2);\r
494         ///\r
495         void funcEmacsEditKillLineFunc(FunctionParam *i_param);\r
496         /// clear log\r
497         void funcLogClear(FunctionParam *i_param);\r
498         /// recenter\r
499         void funcRecenter(FunctionParam *i_param);\r
500         /// Direct SSTP\r
501         void funcDirectSSTP(FunctionParam *i_param,\r
502                                                 const tregex &i_name,\r
503                                                 const StrExprArg &i_protocol,\r
504                                                 const std::list<tstringq> &i_headers);\r
505         /// PlugIn\r
506         void funcPlugIn(FunctionParam *i_param,\r
507                                         const StrExprArg &i_dllName,\r
508                                         const StrExprArg &i_funcName = StrExprArg(),\r
509                                         const StrExprArg &i_funcParam = StrExprArg(),\r
510                                         BooleanType i_doesCreateThread = BooleanType_false);\r
511         /// set IME open status\r
512         void funcSetImeStatus(FunctionParam *i_param, ToggleType i_toggle = ToggleType_toggle);\r
513         /// set string to IME\r
514         void funcSetImeString(FunctionParam *i_param, const StrExprArg &i_data);\r
515         /// enter to mouse event hook mode\r
516         void funcMouseHook(FunctionParam *i_param, MouseHookType i_hookType, int i_hookParam);\r
517         /// cancel prefix\r
518         void funcCancelPrefix(FunctionParam *i_param);\r
519 \r
520         // END OF FUNCTION DEFINITION\r
521 #  define FUNCTION_FRIEND\r
522 #  include "functions.h"\r
523 #  undef FUNCTION_FRIEND\r
524 \r
525 public:\r
526         ///\r
527         Engine(tomsgstream &i_log);\r
528         ///\r
529         ~Engine();\r
530 \r
531         /// start/stop keyboard handler thread\r
532         void start();\r
533         ///\r
534         void stop();\r
535 \r
536         /// pause keyboard handler thread and close device\r
537         bool pause();\r
538 \r
539         /// resume keyboard handler thread and re-open device\r
540         bool resume();\r
541 \r
542         /// do some procedure before quit which must be done synchronously\r
543         /// (i.e. not on WM_QUIT)\r
544         bool prepairQuit();\r
545 \r
546         /// logging mode\r
547         void enableLogMode(bool i_isLogMode = true) {\r
548                 m_isLogMode = i_isLogMode;\r
549         }\r
550         ///\r
551         void disableLogMode() {\r
552                 m_isLogMode = false;\r
553         }\r
554 \r
555         /// enable/disable engine\r
556         void enable(bool i_isEnabled = true) {\r
557                 m_isEnabled = i_isEnabled;\r
558         }\r
559         ///\r
560         void disable() {\r
561                 m_isEnabled = false;\r
562         }\r
563         ///\r
564         bool getIsEnabled() const {\r
565                 return m_isEnabled;\r
566         }\r
567 \r
568         /// associated window\r
569         void setAssociatedWndow(HWND i_hwnd) {\r
570                 m_hwndAssocWindow = i_hwnd;\r
571         }\r
572 \r
573         /// associated window\r
574         HWND getAssociatedWndow() const {\r
575                 return m_hwndAssocWindow;\r
576         }\r
577 \r
578         /// setting\r
579         bool setSetting(Setting *i_setting);\r
580 \r
581         /// focus\r
582         bool setFocus(HWND i_hwndFocus, DWORD i_threadId,\r
583                                   const tstringi &i_className,\r
584                                   const tstringi &i_titleName, bool i_isConsole);\r
585 \r
586         /// lock state\r
587         bool setLockState(bool i_isNumLockToggled, bool i_isCapsLockToggled,\r
588                                           bool i_isScrollLockToggled, bool i_isKanaLockToggled,\r
589                                           bool i_isImeLockToggled, bool i_isImeCompToggled);\r
590 \r
591         /// show\r
592         void checkShow(HWND i_hwnd);\r
593         bool setShow(bool i_isMaximized, bool i_isMinimized, bool i_isMDI);\r
594 \r
595         /// sync\r
596         bool syncNotify();\r
597 \r
598         /// thread attach notify\r
599         bool threadAttachNotify(DWORD i_threadId);\r
600 \r
601         /// thread detach notify\r
602         bool threadDetachNotify(DWORD i_threadId);\r
603 \r
604         /// shell execute\r
605         void shellExecute();\r
606 \r
607         /// get help message\r
608         void getHelpMessages(tstring *o_helpMessage, tstring *o_helpTitle);\r
609 \r
610         /// command notify\r
611         template <typename WPARAM_T, typename LPARAM_T>\r
612         void commandNotify(HWND i_hwnd, UINT i_message, WPARAM_T i_wParam,\r
613                                            LPARAM_T i_lParam)\r
614         {\r
615                 Acquire b(&m_log, 0);\r
616                 HWND hf = m_hwndFocus;\r
617                 if (!hf)\r
618                         return;\r
619 \r
620                 if (GetWindowThreadProcessId(hf, NULL) ==\r
621                                 GetWindowThreadProcessId(m_hwndAssocWindow, NULL))\r
622                         return; // inhibit the investigation of MADO TSUKAI NO YUUTSU\r
623 \r
624                 const _TCHAR *target = NULL;\r
625                 int number_target = 0;\r
626 \r
627                 if (i_hwnd == hf)\r
628                         target = _T("ToItself");\r
629                 else if (i_hwnd == GetParent(hf))\r
630                         target = _T("ToParentWindow");\r
631                 else {\r
632                         // Function::toMainWindow\r
633                         HWND h = hf;\r
634                         while (true) {\r
635                                 HWND p = GetParent(h);\r
636                                 if (!p)\r
637                                         break;\r
638                                 h = p;\r
639                         }\r
640                         if (i_hwnd == h)\r
641                                 target = _T("ToMainWindow");\r
642                         else {\r
643                                 // Function::toOverlappedWindow\r
644                                 HWND h = hf;\r
645                                 while (h) {\r
646 #ifdef MAYU64\r
647                                         LONG_PTR style = GetWindowLongPtr(h, GWL_STYLE);\r
648 #else\r
649                                         LONG style = GetWindowLong(h, GWL_STYLE);\r
650 #endif\r
651                                         if ((style & WS_CHILD) == 0)\r
652                                                 break;\r
653                                         h = GetParent(h);\r
654                                 }\r
655                                 if (i_hwnd == h)\r
656                                         target = _T("ToOverlappedWindow");\r
657                                 else {\r
658                                         // number\r
659                                         HWND h = hf;\r
660                                         for (number_target = 0; h; number_target ++, h = GetParent(h))\r
661                                                 if (i_hwnd == h)\r
662                                                         break;\r
663                                         return;\r
664                                 }\r
665                         }\r
666                 }\r
667 \r
668                 m_log << _T("&PostMessage(");\r
669                 if (target)\r
670                         m_log << target;\r
671                 else\r
672                         m_log << number_target;\r
673                 m_log << _T(", ") << i_message\r
674                 << _T(", 0x") << std::hex << i_wParam\r
675                 << _T(", 0x") << i_lParam << _T(") # hwnd = ")\r
676                 << reinterpret_cast<int>(i_hwnd) << _T(", ")\r
677                 << _T("message = ") << std::dec;\r
678                 if (i_message == WM_COMMAND)\r
679                         m_log << _T("WM_COMMAND, ");\r
680                 else if (i_message == WM_SYSCOMMAND)\r
681                         m_log << _T("WM_SYSCOMMAND, ");\r
682                 else\r
683                         m_log << i_message << _T(", ");\r
684                 m_log << _T("wNotifyCode = ") << HIWORD(i_wParam) << _T(", ")\r
685                 << _T("wID = ") << LOWORD(i_wParam) << _T(", ")\r
686                 << _T("hwndCtrl = 0x") << std::hex << i_lParam << std::dec << std::endl;\r
687         }\r
688 \r
689         /// get current window class name\r
690         const tstringi &getCurrentWindowClassName() const {\r
691                 return m_currentFocusOfThread->m_className;\r
692         }\r
693 \r
694         /// get current window title name\r
695         const tstringi &getCurrentWindowTitleName() const {\r
696                 return m_currentFocusOfThread->m_titleName;\r
697         }\r
698 };\r
699 \r
700 \r
701 ///\r
702 class FunctionParam\r
703 {\r
704 public:\r
705         bool m_isPressed;                               /// is key pressed ?\r
706         HWND m_hwnd;                                    ///\r
707         Engine::Current m_c;                            /// new context\r
708         bool m_doesNeedEndl;                            /// need endl ?\r
709         const ActionFunction *m_af;                     ///\r
710 };\r
711 \r
712 \r
713 #endif // !_ENGINE_H\r