CtrlCore: Ctrl::[Un]RegisterSystemHotKey

git-svn-id: svn://ultimatepp.org/upp/trunk@1589 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-09-24 09:41:58 +00:00
parent 0351e4aa2b
commit 5f258ee935
3 changed files with 48 additions and 1 deletions

View file

@ -35,6 +35,8 @@ bool (*&DisplayErrorFn())(const Value& v)
Ctrl *Ctrl::LoopCtrl; Ctrl *Ctrl::LoopCtrl;
int Ctrl::LoopLevel; int Ctrl::LoopLevel;
Vector<Callback> Ctrl::hotkey;
bool Ctrl::MemoryCheck; bool Ctrl::MemoryCheck;
void Ctrl::SetData(const Value&) {} void Ctrl::SetData(const Value&) {}

View file

@ -580,6 +580,8 @@ private:
static Callback CtrlCall; static Callback CtrlCall;
static Vector<Callback> hotkey;
static bool DoCall(); static bool DoCall();
#ifdef PLATFORM_WIN32 #ifdef PLATFORM_WIN32
@ -693,6 +695,7 @@ protected:
void Create0(CreateBox *cr); void Create0(CreateBox *cr);
void Create(HWND parent, DWORD style, DWORD exstyle, bool savebits, int show, bool dropshadow); void Create(HWND parent, DWORD style, DWORD exstyle, bool savebits, int show, bool dropshadow);
Image DoMouse(int e, Point p, int zd = 0); Image DoMouse(int e, Point p, int zd = 0);
static void sProcessMSG(MSG& msg);
friend void sSetCursor(Ctrl *ctrl, const Image& m); friend void sSetCursor(Ctrl *ctrl, const Image& m);
@ -899,6 +902,9 @@ public:
static void InstallStateHook(StateHook hook); static void InstallStateHook(StateHook hook);
static void DeinstallStateHook(StateHook hook); static void DeinstallStateHook(StateHook hook);
static int RegisterSystemHotKey(dword key, Callback cb);
static void UnregisterSystemHotKey(int id);
virtual bool Accept(); virtual bool Accept();
virtual void Reject(); virtual void Reject();
virtual void SetData(const Value& data); virtual void SetData(const Value& data);

View file

@ -307,6 +307,11 @@ void Ctrl::ExitWin32()
OleUninitialize(); OleUninitialize();
sFinished = true; sFinished = true;
for(int i = 0; i < hotkey.GetCount(); i++)
if(hotkey[i])
UnregisterHotKey(NULL, i);
for(int i = 0; i < Windows().GetCount(); i++) { for(int i = 0; i < Windows().GetCount(); i++) {
HWND hwnd = Windows().GetKey(i); HWND hwnd = Windows().GetKey(i);
if(hwnd) if(hwnd)
@ -670,8 +675,42 @@ bool PassWindowsKey(int wParam)
|| wParam >= 0x90; // OEM keys || 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 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 || 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 TranslateMessage(&msg); // 04/09/07: TRC fix to make barcode reader going better