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

Annotation of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 231 - (hide annotations)
Tue Jun 20 09:18:44 2006 UTC (18 years, 8 months ago) by twoaday
File size: 3856 byte(s)
Some more patches and fixed typos.


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     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 twoaday 231 case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B)");
69 werner 36 default: return _("Unknown Hotkey");
70     }
71     return NULL;
72     }
73    
74    
75 twoaday 180 /* Register all enabled hotkeys. */
76 werner 36 int
77     hotkeys_register (HWND wnd)
78     {
79     int j = 0, rc = 0;
80    
81     err_hotkey = 0; /* reset */
82     for (j=0; wpt_hotkeys[j].id != 0; j++) {
83     if (wpt_hotkeys[j].enabled) {
84     rc = hotkey_register_single (wnd, &wpt_hotkeys[j]);
85     if (rc) {
86     err_hotkey = j+1;
87     break;
88     }
89     }
90     }
91    
92     return rc;
93 twoaday 180 }
94 werner 36
95    
96 twoaday 180 /* Unregister all hotkeys. */
97 werner 36 int
98     hotkeys_unregister (HWND wnd)
99     {
100 twoaday 180 int j = 0;
101 werner 36
102 twoaday 180 for (j=0; wpt_hotkeys[j].id != 0; j++)
103     hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
104 werner 36
105 twoaday 180 return 0;
106     }
107 werner 36
108    
109 twoaday 180 /* Register a single hotkey @hk. */
110 werner 36 int
111     hotkey_register_single (HWND wnd, hotkey_t hk)
112     {
113 twoaday 69 int rc;
114 twoaday 180 int keymod = 0;
115 werner 36
116     if (!hk->enabled)
117     return 0;
118     if (hk->alt_ctrl)
119     keymod = MOD_CONTROL | MOD_ALT;
120     else if (hk->alt_shift)
121     keymod = MOD_ALT | MOD_SHIFT;
122    
123     rc = RegisterHotKey (wnd, hk->id, keymod, hk->key);
124     if (!rc)
125     return WPTERR_HOTKEY;
126     return 0;
127 twoaday 180 }
128 werner 36
129 twoaday 180
130     /* Unregister a single hotkey @hk. */
131 werner 36 int
132     hotkey_unregister_single (HWND wnd, hotkey_t hk)
133     {
134 twoaday 180 int rc = 0;
135    
136     rc = UnregisterHotKey (wnd, hk->id);
137 werner 36 return rc==0? WPTERR_HOTKEY: 0;
138 twoaday 180 }
139 werner 36
140    
141     void
142 twoaday 180 hotkey_disable (hotkey_t hk)
143 werner 36 {
144 twoaday 180 hk->enabled = 0;
145     }
146 werner 36
147    
148     void
149 twoaday 180 hotkey_enable (hotkey_t hk, const char *key)
150 werner 36 {
151     if (strlen (key) > 2)
152     BUG (0);
153 twoaday 180 hk->key = *key;
154     hk->enabled = 1;
155     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26