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

Annotation of /trunk/Src/wptHotkey.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 3454 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptHotkey.cpp - Systemwide hotkeys
2     * Copyright (C) 2001, 2002, 2003 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     * 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     #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     static int err_hotkey = 0;
31    
32     const char *
33     hotkeys_strerror (void)
34     {
35     switch (err_hotkey) {
36     case 0: return NULL;
37     case 1: return _("Clipboard Encrypt (ALT+CTRL+E)");
38     case 2: return _("Clipboard Decrypt/Verify (ALT+CTRL+D)");
39     case 3: return _("Clipboard Sign (ALT+CTRL+S)");
40     case 4: return _("Clipboard Sign Encrypt (ALT+CTRL+B)");
41     case 5: return _("Current Window Encrypt (ALT+SHIFT+E)");
42     case 6: return _("Current Window Decrypt/Verify (ALT+SHIFT+D)");
43     case 7: return _("Current Window Sign (ALT+SHIFT+S)");
44     case 8: return _("Current Window Sign Encrypt (ALT+SHIFT+B");
45     default: return _("Unknown Hotkey");
46     }
47     return NULL;
48     }
49    
50    
51     int
52     hotkeys_register (HWND wnd)
53     {
54     int j = 0, rc = 0;
55    
56     err_hotkey = 0; /* reset */
57     for (j=0; wpt_hotkeys[j].id != 0; j++) {
58     if (wpt_hotkeys[j].enabled) {
59     rc = hotkey_register_single (wnd, &wpt_hotkeys[j]);
60     if (rc) {
61     err_hotkey = j+1;
62     break;
63     }
64     }
65     }
66    
67     return rc;
68     } /* hotkeys_register */
69    
70    
71     int
72     hotkeys_unregister (HWND wnd)
73     {
74     int j = 0, rc = 0;
75    
76     for (j=0; wpt_hotkeys[j].id != 0; j++) {
77     if (wpt_hotkeys[j].enabled) {
78     rc = hotkey_unregister_single (wnd, &wpt_hotkeys[j]);
79     if (rc)
80     break;
81     }
82     }
83    
84     return rc;
85     } /* hotkeys_unregister */
86    
87    
88     int
89     hotkey_register_single (HWND wnd, hotkey_t hk)
90     {
91     int rc, keymod;
92    
93     if (!hk->enabled)
94     return 0;
95    
96     if (hk->alt_ctrl)
97     keymod = MOD_CONTROL | MOD_ALT;
98     else if (hk->alt_shift)
99     keymod = MOD_ALT | MOD_SHIFT;
100    
101     rc = RegisterHotKey (wnd, hk->id, keymod, hk->key);
102     if (!rc)
103     return WPTERR_HOTKEY;
104     return 0;
105     } /* hotkey_register_single */
106    
107     int
108     hotkey_unregister_single (HWND wnd, hotkey_t hk)
109     {
110     int rc = UnregisterHotKey (wnd, hk->id);
111     return rc==0? WPTERR_HOTKEY: 0;
112     } /* hotkey_unregister_single */
113    
114    
115     void
116     hotkeys_modify (void)
117     {
118     int i;
119    
120     for (i = 0; wpt_hotkeys[i].id; i++) {
121     if( reg_hotkeys[i].enabled ) {
122     wpt_hotkeys[i].key = reg_hotkeys[i].key[0];
123     wpt_hotkeys[i].enabled = 1;
124     }
125     }
126     } /* hotkeys_modify */
127    
128    
129     void
130     hotkey_disable (reg_hotkey_t rhk)
131     {
132     strcpy (rhk->key, " ");
133     rhk->enabled = 0;
134     } /* hotkey_disable */
135    
136    
137     void
138     hotkey_enable (reg_hotkey_t rhk, const char * key)
139     {
140     if (strlen (key) > 2)
141     BUG (0);
142     strcpy (rhk->key, key);
143     rhk->enabled = 1;
144     } /* hotkey_enable */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26