/[winpt]/trunk/Src/wptHotkey.cpp
ViewVC logotype

Contents of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 328 - (show annotations)
Fri Sep 25 16:07:38 2009 UTC (15 years, 5 months ago) by twoaday
File size: 3773 byte(s)


1 /* wptHotkey.cpp - Systemwide hotkeys
2 * Copyright (C) 2001-2003, 2006, 2008, 2009 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
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20
21 #include <windows.h>
22
23 #include "wptHotkey.h"
24 #include "wptGPG.h"
25 #include "wptRegistry.h"
26 #include "wptErrors.h"
27 #include "wptNLS.h"
28 #include "wptTypes.h"
29
30
31 /* List of all predefined hotkeys. */
32 hotkey_s wpt_hotkeys[] = {
33 /* ALT+CTRL+ */
34 {"ClipEncrypt", 1, WPT_CLIP_ENCRYPT_ID, 1, 0, 0x45}, /* E */
35 {"ClipDecrypt", 1, WPT_CLIP_DECRYPT_VERIFY_ID, 1, 0, 0x44}, /* D */
36 {"ClipSign", 1, WPT_CLIP_SIGN_ID, 1, 0, 0x53}, /* S */
37 {"ClipSignEnc", 1, WPT_CLIP_SIGN_ENCRYPT_ID, 1, 0, 0x42}, /* B */
38 /* ALT+SHIFT+ */
39 {"CwsEncrypt", 1, WPT_CURRWND_ENCRYPT_ID, 0, 1, 0x45}, /* E */
40 {"CwsDecrypt", 1, WPT_CURRWND_DECRYPT_VERIFY_ID, 0, 1, 0x44}, /* D */
41 {"CwsSign", 1, WPT_CURRWND_SIGN_ID, 0, 1, 0x53}, /* S */
42 {"CwsSignEnc", 1, WPT_CURRWND_SIGN_ENCRYPT_ID, 0, 1, 0x42}, /* B */
43 /* Agent ALT+CTRL+ */
44 {"AgentForget", 1, WPT_AGENT_FORGET_ID, 1, 0, 0x46}, /* F */
45 {0}
46 };
47
48
49 /* Global error variable. */
50 static int winpt_hotkey_err = 0;
51
52 const char*
53 hotkeys_strerror (void)
54 {
55 switch (winpt_hotkey_err) {
56 case 0: return NULL;
57 case 1: return _("Clipboard Encrypt (ALT+CTRL+E)");
58 case 2: return _("Clipboard Decrypt/Verify (ALT+CTRL+D)");
59 case 3: return _("Clipboard Sign (ALT+CTRL+S)");
60 case 4: return _("Clipboard Sign Encrypt (ALT+CTRL+B)");
61 case 5: return _("Current Window Encrypt (ALT+SHIFT+E)");
62 case 6: return _("Current Window Decrypt/Verify (ALT+SHIFT+D)");
63 case 7: return _("Current Window Sign (ALT+SHIFT+S)");
64 case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B)");
65 default:return _("Unknown Hotkey");
66 }
67 return _("Unknown Hotkey");
68 }
69
70
71 /* Register all enabled hotkeys. */
72 int
73 hotkeys_register (HWND wnd)
74 {
75 int rc = 0;
76
77 winpt_hotkey_err = 0; /* reset */
78 for (int j=0; wpt_hotkeys[j].id != 0; j++) {
79 if (wpt_hotkeys[j].enabled) {
80 rc = hotkey_register_single (wnd, &wpt_hotkeys[j]);
81 if (rc) {
82 winpt_hotkey_err = j+1;
83 break;
84 }
85 }
86 }
87
88 return rc;
89 }
90
91
92 /* Unregister all hotkeys. */
93 int
94 hotkeys_unregister (HWND wnd)
95 {
96 for (int j=0; wpt_hotkeys[j].id != 0; j++)
97 hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
98
99 return 0;
100 }
101
102
103 /* Register a single hotkey @hk. */
104 int
105 hotkey_register_single (HWND wnd, hotkey_t hk)
106 {
107 int rc;
108 int keymod = 0;
109
110 if (!hk->enabled)
111 return 0;
112 if (hk->alt_ctrl)
113 keymod = MOD_CONTROL | MOD_ALT;
114 else if (hk->alt_shift)
115 keymod = MOD_ALT | MOD_SHIFT;
116
117 rc = RegisterHotKey (wnd, hk->id, keymod, hk->key);
118 return rc == 0? WPTERR_HOTKEY : 0;
119 }
120
121
122 /* Unregister a single hotkey @hk. */
123 int
124 hotkey_unregister_single (HWND wnd, hotkey_t hk)
125 {
126 int rc;
127
128 rc = UnregisterHotKey (wnd, hk->id);
129 return rc==0? WPTERR_HOTKEY: 0;
130 }
131
132
133 /* Disable the given hotkey in @hk. */
134 void
135 hotkey_disable (hotkey_t hk)
136 {
137 hk->enabled = 0;
138 }
139
140
141 /* Enable the given hotkey in @hk.
142 Set the hotkey sequence to @key. */
143 void
144 hotkey_enable (hotkey_t hk, const char *key)
145 {
146 if (strlen (key) > 2)
147 BUG (0);
148 hk->key = *key;
149 hk->enabled = 1;
150 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26