33 #include <nsStringGlue.h>
46 #define GLOBALHOTKEYS_WNDCLASS NS_L("sbGlobalHotkeys")
47 PRInt32 CGlobalHotkeys::m_autoinc = 1;
50 static LRESULT CALLBACK GlobalHotkeysProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
53 return _this->WndProc(hWnd, uMsg, wParam, lParam);
65 memset(&wndClass, 0,
sizeof(wndClass));
66 wndClass.hInstance = GetModuleHandle(NULL);
67 wndClass.lpfnWndProc = GlobalHotkeysProc;
68 wndClass.lpszClassName = GLOBALHOTKEYS_WNDCLASS;
69 RegisterClass(&wndClass);
71 m_window = CreateWindow(GLOBALHOTKEYS_WNDCLASS, NULL, WS_POPUP, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);
72 SetWindowLong(m_window, GWL_USERDATA, (LPARAM)
this);
81 DestroyWindow(m_window);
83 UnregisterClass(GLOBALHOTKEYS_WNDCLASS, GetModuleHandle(NULL));
91 if (handle == NULL)
return NS_ERROR_FAILURE;
104 NS_IMETHODIMP CGlobalHotkeys::RemoveHotkey(
const nsAString &keyid)
107 if (!entry)
return NS_ERROR_FAILURE;
122 NS_IMETHODIMP CGlobalHotkeys::RemoveAllHotkeys()
124 std::list<GlobalHotkeyEntry*>::iterator iter;
136 LRESULT CGlobalHotkeys::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
138 if (uMsg == WM_HOTKEY)
140 int idHotKey = (int) wParam;
146 return DefWindowProc(hWnd, uMsg, wParam, lParam);
155 if (m_autoinc == 0xBFFF)
return NULL;
156 RegisterHotKey(m_window, m_autoinc, makeWin32Mask(altKey, ctrlKey, shiftKey, metaKey), keyCode);
166 UnregisterHotKey(m_window, handle);
173 std::list<GlobalHotkeyEntry*>::iterator iter;
177 if (entry->
m_keyid.Equals(keyid))
return entry;
185 std::list<GlobalHotkeyEntry*>::iterator iter;
196 UINT CGlobalHotkeys::makeWin32Mask(PRBool altKey, PRBool ctrlKey, PRBool shiftKey, PRBool metaKey)
198 return (altKey ? MOD_ALT : 0) |
199 (ctrlKey ? MOD_CONTROL : 0) |
200 (shiftKey ? MOD_SHIFT : 0) |
201 (metaKey ? MOD_WIN : 0);
sbIGlobalHotkeyCallback * m_callback
void removeEntry(GlobalHotkeyEntry *entry)
static std::list< GlobalHotkeyEntry * > m_hotkeys
Global hotkey registration/unregistration interface This interface is used to register or unregister ...
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
Global hotkeys callback interface This interface is used by callback objects to receive a notificatio...
function handle(request, response)
int registerHotkey(PRInt32 keyCode, PRBool altKey, PRBool ctrlKey, PRBool shiftKey, PRBool metaKey)
return e ctrlKey(chr<' '||!chars||chars.indexOf(chr)>-1)
GlobalHotkeyEntry * findHotkeyById(const nsAString &keyid)
GlobalHotkeyEntry * findHotkeyByHandle(int handle)
void unregisterHotkey(int handle)
virtual ~CGlobalHotkeys()