From 5f258ee935a34b7a606e9f3a878952d9ef304830 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 24 Sep 2009 09:41:58 +0000 Subject: [PATCH] CtrlCore: Ctrl::[Un]RegisterSystemHotKey git-svn-id: svn://ultimatepp.org/upp/trunk@1589 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/Ctrl.cpp | 2 ++ uppsrc/CtrlCore/CtrlCore.h | 6 ++++++ uppsrc/CtrlCore/Win32Wnd.cpp | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/uppsrc/CtrlCore/Ctrl.cpp b/uppsrc/CtrlCore/Ctrl.cpp index a93214717..2ca61b00d 100644 --- a/uppsrc/CtrlCore/Ctrl.cpp +++ b/uppsrc/CtrlCore/Ctrl.cpp @@ -35,6 +35,8 @@ bool (*&DisplayErrorFn())(const Value& v) Ctrl *Ctrl::LoopCtrl; int Ctrl::LoopLevel; +Vector Ctrl::hotkey; + bool Ctrl::MemoryCheck; void Ctrl::SetData(const Value&) {} diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index 203c4d2ee..7e8c61415 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -579,6 +579,8 @@ private: String GetInfoPart(int i) const; static Callback CtrlCall; + + static Vector hotkey; static bool DoCall(); @@ -693,6 +695,7 @@ protected: void Create0(CreateBox *cr); void Create(HWND parent, DWORD style, DWORD exstyle, bool savebits, int show, bool dropshadow); Image DoMouse(int e, Point p, int zd = 0); + static void sProcessMSG(MSG& msg); friend void sSetCursor(Ctrl *ctrl, const Image& m); @@ -898,6 +901,9 @@ public: static void InstallStateHook(StateHook hook); static void DeinstallStateHook(StateHook hook); + + static int RegisterSystemHotKey(dword key, Callback cb); + static void UnregisterSystemHotKey(int id); virtual bool Accept(); virtual void Reject(); diff --git a/uppsrc/CtrlCore/Win32Wnd.cpp b/uppsrc/CtrlCore/Win32Wnd.cpp index c8b376d13..a7eefa425 100644 --- a/uppsrc/CtrlCore/Win32Wnd.cpp +++ b/uppsrc/CtrlCore/Win32Wnd.cpp @@ -307,6 +307,11 @@ void Ctrl::ExitWin32() OleUninitialize(); sFinished = true; + + for(int i = 0; i < hotkey.GetCount(); i++) + if(hotkey[i]) + UnregisterHotKey(NULL, i); + for(int i = 0; i < Windows().GetCount(); i++) { HWND hwnd = Windows().GetKey(i); if(hwnd) @@ -670,8 +675,42 @@ bool PassWindowsKey(int wParam) || wParam >= 0x90; // OEM keys } -static void sProcessMSG(MSG& msg) +int Ctrl::RegisterSystemHotKey(dword key, Callback cb) { + ASSERT(key >= K_DELTA); + int q = hotkey.GetCount(); + for(int i = 0; i < hotkey.GetCount(); i++) + if(!hotkey[i]) { + q = i; + break; + } + hotkey.At(q) = cb; + dword mod = 0; + if(key & K_ALT) + mod |= MOD_ALT; + if(key & K_SHIFT) + mod |= MOD_SHIFT; + if(key & K_CTRL) + mod |= MOD_CONTROL; + + RegisterHotKey(NULL, q, mod, key & 0xffff); + return q; +} + +void Ctrl::UnregisterSystemHotKey(int id) +{ + ASSERT(id >= 0 && id < hotkey.GetCount()); + UnregisterHotKey(NULL, id); + hotkey[id].Clear(); +} + +void Ctrl::sProcessMSG(MSG& msg) +{ + if (msg.message == WM_HOTKEY) { + if(msg.wParam >= 0 && (int)msg.wParam < Ctrl::hotkey.GetCount()) + Ctrl::hotkey[msg.wParam](); + return; + } if(msg.message != WM_SYSKEYDOWN && msg.message != WM_SYSKEYUP || PassWindowsKey((dword)msg.wParam) || msg.wParam == VK_MENU) //17.11 Mirek - fix to get windows menu invoked on Alt+Space TranslateMessage(&msg); // 04/09/07: TRC fix to make barcode reader going better