|
/* wptHotkey.cpp - Systemwide hotkeys |
|
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
|
|
* |
|
|
* This file is part of WinPT. |
|
|
* |
|
|
* WinPT is free software; you can redistribute it and/or |
|
|
* modify it under the terms of the GNU General Public License |
|
|
* as published by the Free Software Foundation; either version 2 |
|
|
* of the License, or (at your option) any later version. |
|
|
* |
|
|
* WinPT is distributed in the hope that it will be useful, |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
* General Public License for more details. |
|
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
*/ |
|
|
|
|
|
#include <windows.h> |
|
|
|
|
|
#include "wptHotkey.h" |
|
|
#include "wptGPG.h" |
|
|
#include "wptRegistry.h" |
|
|
#include "wptErrors.h" |
|
|
#include "wptNLS.h" |
|
|
#include "wptTypes.h" |
|
|
|
|
|
static int err_hotkey = 0; |
|
|
|
|
|
const char * |
|
|
hotkeys_strerror (void) |
|
|
{ |
|
|
switch (err_hotkey) { |
|
|
case 0: return NULL; |
|
|
case 1: return _("Clipboard Encrypt (ALT+CTRL+E)"); |
|
|
case 2: return _("Clipboard Decrypt/Verify (ALT+CTRL+D)"); |
|
|
case 3: return _("Clipboard Sign (ALT+CTRL+S)"); |
|
|
case 4: return _("Clipboard Sign Encrypt (ALT+CTRL+B)"); |
|
|
case 5: return _("Current Window Encrypt (ALT+SHIFT+E)"); |
|
|
case 6: return _("Current Window Decrypt/Verify (ALT+SHIFT+D)"); |
|
|
case 7: return _("Current Window Sign (ALT+SHIFT+S)"); |
|
|
case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B"); |
|
|
default: return _("Unknown Hotkey"); |
|
|
} |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
hotkeys_register (HWND wnd) |
|
|
{ |
|
|
int j = 0, rc = 0; |
|
|
|
|
|
err_hotkey = 0; /* reset */ |
|
|
for (j=0; wpt_hotkeys[j].id != 0; j++) { |
|
|
if (wpt_hotkeys[j].enabled) { |
|
|
rc = hotkey_register_single (wnd, &wpt_hotkeys[j]); |
|
|
if (rc) { |
|
|
err_hotkey = j+1; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return rc; |
|
|
} /* hotkeys_register */ |
|
|
|
|
|
|
|
|
int |
|
|
hotkeys_unregister (HWND wnd) |
|
|
{ |
|
|
int j = 0, rc = 0; |
|
|
|
|
|
for (j=0; wpt_hotkeys[j].id != 0; j++) { |
|
|
if (wpt_hotkeys[j].enabled) { |
|
|
rc = hotkey_unregister_single (wnd, &wpt_hotkeys[j]); |
|
|
if (rc) |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
return rc; |
|
|
} /* hotkeys_unregister */ |
|
|
|
|
|
|
|
|
int |
|
|
hotkey_register_single (HWND wnd, hotkey_t hk) |
|
|
{ |
|
|
int rc, keymod; |
|
|
|
|
|
if (!hk->enabled) |
|
|
return 0; |
|
|
|
|
|
if (hk->alt_ctrl) |
|
|
keymod = MOD_CONTROL | MOD_ALT; |
|
|
else if (hk->alt_shift) |
|
|
keymod = MOD_ALT | MOD_SHIFT; |
|
|
|
|
|
rc = RegisterHotKey (wnd, hk->id, keymod, hk->key); |
|
|
if (!rc) |
|
|
return WPTERR_HOTKEY; |
|
|
return 0; |
|
|
} /* hotkey_register_single */ |
|
|
|
|
|
int |
|
|
hotkey_unregister_single (HWND wnd, hotkey_t hk) |
|
|
{ |
|
|
int rc = UnregisterHotKey (wnd, hk->id); |
|
|
return rc==0? WPTERR_HOTKEY: 0; |
|
|
} /* hotkey_unregister_single */ |
|
|
|
|
|
|
|
|
void |
|
|
hotkeys_modify (void) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
for (i = 0; wpt_hotkeys[i].id; i++) { |
|
|
if( reg_hotkeys[i].enabled ) { |
|
|
wpt_hotkeys[i].key = reg_hotkeys[i].key[0]; |
|
|
wpt_hotkeys[i].enabled = 1; |
|
|
} |
|
|
} |
|
|
} /* hotkeys_modify */ |
|
|
|
|
|
|
|
|
void |
|
|
hotkey_disable (reg_hotkey_t rhk) |
|
|
{ |
|
|
strcpy (rhk->key, " "); |
|
|
rhk->enabled = 0; |
|
|
} /* hotkey_disable */ |
|
|
|
|
|
|
|
|
void |
|
|
hotkey_enable (reg_hotkey_t rhk, const char * key) |
|
|
{ |
|
|
if (strlen (key) > 2) |
|
|
BUG (0); |
|
|
strcpy (rhk->key, key); |
|
|
rhk->enabled = 1; |
|
|
} /* hotkey_enable */ |
|
1 |
|
/* wptHotkey.cpp - Systemwide hotkeys |
2 |
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
|
* |
4 |
|
* This file is part of WinPT. |
5 |
|
* |
6 |
|
* WinPT is free software; you can redistribute it and/or |
7 |
|
* modify it under the terms of the GNU General Public License |
8 |
|
* as published by the Free Software Foundation; either version 2 |
9 |
|
* of the License, or (at your option) any later version. |
10 |
|
* |
11 |
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
* General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
*/ |
20 |
|
|
21 |
|
#ifdef HAVE_CONFIG_H |
22 |
|
#include <config.h> |
23 |
|
#endif |
24 |
|
|
25 |
|
#include <windows.h> |
26 |
|
#include <windows.h> |
27 |
|
|
28 |
|
#include "wptHotkey.h" |
29 |
|
#include "wptGPG.h" |
30 |
|
#include "wptRegistry.h" |
31 |
|
#include "wptErrors.h" |
32 |
|
#include "wptNLS.h" |
33 |
|
#include "wptTypes.h" |
34 |
|
|
35 |
|
static int err_hotkey = 0; |
36 |
|
|
37 |
|
const char * |
38 |
|
hotkeys_strerror (void) |
39 |
|
{ |
40 |
|
switch (err_hotkey) { |
41 |
|
case 0: return NULL; |
42 |
|
case 1: return _("Clipboard Encrypt (ALT+CTRL+E)"); |
43 |
|
case 2: return _("Clipboard Decrypt/Verify (ALT+CTRL+D)"); |
44 |
|
case 3: return _("Clipboard Sign (ALT+CTRL+S)"); |
45 |
|
case 4: return _("Clipboard Sign Encrypt (ALT+CTRL+B)"); |
46 |
|
case 5: return _("Current Window Encrypt (ALT+SHIFT+E)"); |
47 |
|
case 6: return _("Current Window Decrypt/Verify (ALT+SHIFT+D)"); |
48 |
|
case 7: return _("Current Window Sign (ALT+SHIFT+S)"); |
49 |
|
case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B"); |
50 |
|
default: return _("Unknown Hotkey"); |
51 |
|
} |
52 |
|
return NULL; |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
int |
57 |
|
hotkeys_register (HWND wnd) |
58 |
|
{ |
59 |
|
int j = 0, rc = 0; |
60 |
|
|
61 |
|
err_hotkey = 0; /* reset */ |
62 |
|
for (j=0; wpt_hotkeys[j].id != 0; j++) { |
63 |
|
if (wpt_hotkeys[j].enabled) { |
64 |
|
rc = hotkey_register_single (wnd, &wpt_hotkeys[j]); |
65 |
|
if (rc) { |
66 |
|
err_hotkey = j+1; |
67 |
|
break; |
68 |
|
} |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
|
return rc; |
73 |
|
} /* hotkeys_register */ |
74 |
|
|
75 |
|
|
76 |
|
int |
77 |
|
hotkeys_unregister (HWND wnd) |
78 |
|
{ |
79 |
|
int j = 0, rc = 0; |
80 |
|
|
81 |
|
for (j=0; wpt_hotkeys[j].id != 0; j++) { |
82 |
|
if (wpt_hotkeys[j].enabled) { |
83 |
|
rc = hotkey_unregister_single (wnd, &wpt_hotkeys[j]); |
84 |
|
if (rc) |
85 |
|
break; |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
return rc; |
90 |
|
} /* hotkeys_unregister */ |
91 |
|
|
92 |
|
|
93 |
|
int |
94 |
|
hotkey_register_single (HWND wnd, hotkey_t hk) |
95 |
|
{ |
96 |
|
int rc, keymod; |
97 |
|
|
98 |
|
if (!hk->enabled) |
99 |
|
return 0; |
100 |
|
|
101 |
|
if (hk->alt_ctrl) |
102 |
|
keymod = MOD_CONTROL | MOD_ALT; |
103 |
|
else if (hk->alt_shift) |
104 |
|
keymod = MOD_ALT | MOD_SHIFT; |
105 |
|
|
106 |
|
rc = RegisterHotKey (wnd, hk->id, keymod, hk->key); |
107 |
|
if (!rc) |
108 |
|
return WPTERR_HOTKEY; |
109 |
|
return 0; |
110 |
|
} /* hotkey_register_single */ |
111 |
|
|
112 |
|
int |
113 |
|
hotkey_unregister_single (HWND wnd, hotkey_t hk) |
114 |
|
{ |
115 |
|
int rc = UnregisterHotKey (wnd, hk->id); |
116 |
|
return rc==0? WPTERR_HOTKEY: 0; |
117 |
|
} /* hotkey_unregister_single */ |
118 |
|
|
119 |
|
|
120 |
|
void |
121 |
|
hotkeys_modify (void) |
122 |
|
{ |
123 |
|
int i; |
124 |
|
|
125 |
|
for (i = 0; wpt_hotkeys[i].id; i++) { |
126 |
|
if( reg_hotkeys[i].enabled ) { |
127 |
|
wpt_hotkeys[i].key = reg_hotkeys[i].key[0]; |
128 |
|
wpt_hotkeys[i].enabled = 1; |
129 |
|
} |
130 |
|
} |
131 |
|
} /* hotkeys_modify */ |
132 |
|
|
133 |
|
|
134 |
|
void |
135 |
|
hotkey_disable (reg_hotkey_t rhk) |
136 |
|
{ |
137 |
|
strcpy (rhk->key, " "); |
138 |
|
rhk->enabled = 0; |
139 |
|
} /* hotkey_disable */ |
140 |
|
|
141 |
|
|
142 |
|
void |
143 |
|
hotkey_enable (reg_hotkey_t rhk, const char * key) |
144 |
|
{ |
145 |
|
if (strlen (key) > 2) |
146 |
|
BUG (0); |
147 |
|
strcpy (rhk->key, key); |
148 |
|
rhk->enabled = 1; |
149 |
|
} /* hotkey_enable */ |