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

Annotation of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 433 - (hide annotations)
Mon Apr 9 14:52:01 2012 UTC (12 years, 10 months ago) by twoaday
File size: 3911 byte(s)


1 werner 36 /* wptHotkey.cpp - Systemwide hotkeys
2 twoaday 328 * Copyright (C) 2001-2003, 2006, 2008, 2009 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    
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 twoaday 180
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 twoaday 328 {"ClipSign", 1, WPT_CLIP_SIGN_ID, 1, 0, 0x53}, /* S */
37 twoaday 180 {"ClipSignEnc", 1, WPT_CLIP_SIGN_ENCRYPT_ID, 1, 0, 0x42}, /* B */
38     /* ALT+SHIFT+ */
39 twoaday 328 {"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 twoaday 180 /* Agent ALT+CTRL+ */
44     {"AgentForget", 1, WPT_AGENT_FORGET_ID, 1, 0, 0x46}, /* F */
45     {0}
46     };
47    
48    
49     /* Global error variable. */
50 twoaday 328 static int winpt_hotkey_err = 0;
51 werner 36
52 twoaday 180 const char*
53 werner 36 hotkeys_strerror (void)
54     {
55 twoaday 433 /* FIXME: error messages should not contain the key combinations
56     because they are only valid for the default hot keys #6329 */
57 twoaday 328 switch (winpt_hotkey_err) {
58 twoaday 271 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 werner 36 }
69 twoaday 328 return _("Unknown Hotkey");
70 werner 36 }
71    
72    
73 twoaday 180 /* Register all enabled hotkeys. */
74 werner 36 int
75     hotkeys_register (HWND wnd)
76     {
77 twoaday 271 int rc = 0;
78 werner 36
79 twoaday 328 winpt_hotkey_err = 0; /* reset */
80     for (int j=0; wpt_hotkeys[j].id != 0; j++) {
81 werner 36 if (wpt_hotkeys[j].enabled) {
82     rc = hotkey_register_single (wnd, &wpt_hotkeys[j]);
83     if (rc) {
84 twoaday 328 winpt_hotkey_err = j+1;
85 werner 36 break;
86     }
87     }
88     }
89    
90     return rc;
91 twoaday 180 }
92 werner 36
93    
94 twoaday 180 /* Unregister all hotkeys. */
95 werner 36 int
96     hotkeys_unregister (HWND wnd)
97     {
98 twoaday 328 for (int j=0; wpt_hotkeys[j].id != 0; j++)
99 twoaday 180 hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
100 werner 36
101 twoaday 180 return 0;
102     }
103 werner 36
104    
105 twoaday 180 /* Register a single hotkey @hk. */
106 werner 36 int
107     hotkey_register_single (HWND wnd, hotkey_t hk)
108     {
109 twoaday 69 int rc;
110 twoaday 180 int keymod = 0;
111 werner 36
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 twoaday 271 return rc == 0? WPTERR_HOTKEY : 0;
121 twoaday 180 }
122 werner 36
123 twoaday 180
124     /* Unregister a single hotkey @hk. */
125 werner 36 int
126     hotkey_unregister_single (HWND wnd, hotkey_t hk)
127     {
128 twoaday 271 int rc;
129 twoaday 180
130     rc = UnregisterHotKey (wnd, hk->id);
131 werner 36 return rc==0? WPTERR_HOTKEY: 0;
132 twoaday 180 }
133 werner 36
134    
135 twoaday 271 /* Disable the given hotkey in @hk. */
136 werner 36 void
137 twoaday 180 hotkey_disable (hotkey_t hk)
138 werner 36 {
139 twoaday 180 hk->enabled = 0;
140     }
141 werner 36
142    
143 twoaday 271 /* Enable the given hotkey in @hk.
144     Set the hotkey sequence to @key. */
145 werner 36 void
146 twoaday 180 hotkey_enable (hotkey_t hk, const char *key)
147 werner 36 {
148     if (strlen (key) > 2)
149     BUG (0);
150 twoaday 180 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