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

Annotation of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (hide annotations)
Sun Nov 5 08:57:45 2006 UTC (18 years, 3 months ago) by twoaday
File size: 3944 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26