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

Contents of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 433 - (show annotations)
Mon Apr 9 14:52:01 2012 UTC (12 years, 10 months ago) by twoaday
File size: 3911 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 /* FIXME: error messages should not contain the key combinations
56 because they are only valid for the default hot keys #6329 */
57 switch (winpt_hotkey_err) {
58 case 0: return NULL;
59 case 1: return _("Clipboard Encrypt (ALT+CTRL+E)");
60 case 2: return _("Clipboard Decrypt/Verify (ALT+CTRL+D)");
61 case 3: return _("Clipboard Sign (ALT+CTRL+S)");
62 case 4: return _("Clipboard Sign Encrypt (ALT+CTRL+B)");
63 case 5: return _("Current Window Encrypt (ALT+SHIFT+E)");
64 case 6: return _("Current Window Decrypt/Verify (ALT+SHIFT+D)");
65 case 7: return _("Current Window Sign (ALT+SHIFT+S)");
66 case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B)");
67 default:return _("Unknown Hotkey");
68 }
69 return _("Unknown Hotkey");
70 }
71
72
73 /* Register all enabled hotkeys. */
74 int
75 hotkeys_register (HWND wnd)
76 {
77 int rc = 0;
78
79 winpt_hotkey_err = 0; /* reset */
80 for (int j=0; wpt_hotkeys[j].id != 0; j++) {
81 if (wpt_hotkeys[j].enabled) {
82 rc = hotkey_register_single (wnd, &wpt_hotkeys[j]);
83 if (rc) {
84 winpt_hotkey_err = j+1;
85 break;
86 }
87 }
88 }
89
90 return rc;
91 }
92
93
94 /* Unregister all hotkeys. */
95 int
96 hotkeys_unregister (HWND wnd)
97 {
98 for (int j=0; wpt_hotkeys[j].id != 0; j++)
99 hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
100
101 return 0;
102 }
103
104
105 /* Register a single hotkey @hk. */
106 int
107 hotkey_register_single (HWND wnd, hotkey_t hk)
108 {
109 int rc;
110 int keymod = 0;
111
112 if (!hk->enabled)
113 return 0;
114 if (hk->alt_ctrl)
115 keymod = MOD_CONTROL | MOD_ALT;
116 else if (hk->alt_shift)
117 keymod = MOD_ALT | MOD_SHIFT;
118
119 rc = RegisterHotKey (wnd, hk->id, keymod, hk->key);
120 return rc == 0? WPTERR_HOTKEY : 0;
121 }
122
123
124 /* Unregister a single hotkey @hk. */
125 int
126 hotkey_unregister_single (HWND wnd, hotkey_t hk)
127 {
128 int rc;
129
130 rc = UnregisterHotKey (wnd, hk->id);
131 return rc==0? WPTERR_HOTKEY: 0;
132 }
133
134
135 /* Disable the given hotkey in @hk. */
136 void
137 hotkey_disable (hotkey_t hk)
138 {
139 hk->enabled = 0;
140 }
141
142
143 /* Enable the given hotkey in @hk.
144 Set the hotkey sequence to @key. */
145 void
146 hotkey_enable (hotkey_t hk, const char *key)
147 {
148 if (strlen (key) > 2)
149 BUG (0);
150 hk->key = *key;
151 hk->enabled = 1;
152 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26