1 |
werner |
36 |
/* wptMainProc.cpp - Main window procedure |
2 |
twoaday |
150 |
* Copyright (C) 2000-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 modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (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 |
14 |
|
|
* GNU 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 |
|
|
#include <commctrl.h> |
27 |
|
|
#include <io.h> |
28 |
|
|
|
29 |
werner |
47 |
#include "resource.h" |
30 |
werner |
36 |
#include "wptTypes.h" |
31 |
|
|
#include "wptGPG.h" |
32 |
|
|
#include "wptW32API.h" |
33 |
|
|
#include "wptVersion.h" |
34 |
|
|
#include "wptCommonCtl.h" |
35 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
36 |
|
|
#include "wptDlgs.h" |
37 |
|
|
#include "wptErrors.h" |
38 |
|
|
#include "wptNLS.h" |
39 |
|
|
#include "wptHotkey.h" |
40 |
|
|
#include "wptRegistry.h" |
41 |
|
|
#include "wptKeyserver.h" |
42 |
|
|
#include "wptAgent.h" |
43 |
|
|
#include "wptKeyManager.h" |
44 |
|
|
#include "wptCard.h" |
45 |
|
|
#include "wptCryptdisk.h" |
46 |
|
|
#include "wptCardEdit.h" |
47 |
|
|
|
48 |
twoaday |
190 |
|
49 |
|
|
void update_keycache (HWND hwnd); |
50 |
|
|
|
51 |
werner |
36 |
static int cmd = 0; |
52 |
|
|
static int wipe_contents = 0; |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
/* Dialog box procedure to display all insecure all ElGamal keys. */ |
56 |
|
|
BOOL CALLBACK |
57 |
|
|
elgamal_warn_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
58 |
|
|
{ |
59 |
|
|
gpg_keycache_t pc; |
60 |
|
|
gpgme_key_t key; |
61 |
|
|
char tmp[128+64+1]; |
62 |
|
|
|
63 |
twoaday |
72 |
switch (msg) { |
64 |
werner |
36 |
case WM_INITDIALOG: |
65 |
|
|
pc = keycache_get_ctx (1); |
66 |
|
|
while (!gpg_keycache_next_key (pc, 0, &key)) { |
67 |
|
|
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
68 |
|
|
_snprintf (tmp, sizeof (tmp)-1, "(0x%s) %s", |
69 |
|
|
key->subkeys->keyid+8, key->uids->uid); |
70 |
|
|
SendDlgItemMessage (dlg, IDC_ELGWARN_LIST, LB_ADDSTRING, |
71 |
|
|
0, (LPARAM)(const char *) tmp); |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
gpg_keycache_rewind (pc); |
75 |
|
|
center_window (dlg, NULL); |
76 |
|
|
SetForegroundWindow (dlg); |
77 |
|
|
break; |
78 |
|
|
|
79 |
|
|
case WM_COMMAND: |
80 |
|
|
switch (LOWORD (wparam)) { |
81 |
|
|
case IDOK: |
82 |
|
|
EndDialog (dlg, TRUE); |
83 |
|
|
break; |
84 |
|
|
} |
85 |
|
|
break; |
86 |
|
|
} |
87 |
|
|
return FALSE; |
88 |
twoaday |
32 |
} |
89 |
werner |
36 |
|
90 |
|
|
|
91 |
|
|
/* Dialog box procedure to confirm to delete the clipboard contents. */ |
92 |
|
|
static BOOL CALLBACK |
93 |
|
|
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
94 |
|
|
{ |
95 |
|
|
switch (msg) { |
96 |
|
|
case WM_INITDIALOG: |
97 |
|
|
SetWindowText (dlg, _("Delete Clipboard Contents")); |
98 |
twoaday |
226 |
SetDlgItemText (dlg, IDC_CONFDELCLIP_BRAIN, |
99 |
|
|
_("&Remember the answer")); |
100 |
|
|
SetDlgItemText (dlg, IDC_CONFDELCLIP_INFO, |
101 |
|
|
_("Do you want to delete the contents from the clipboard?")); |
102 |
twoaday |
105 |
SetDlgItemText (dlg, IDYES, _("&Yes")); |
103 |
twoaday |
121 |
SetDlgItemText (dlg, IDNO, _("&No")); |
104 |
werner |
36 |
center_window (dlg, NULL); |
105 |
|
|
SetForegroundWindow (dlg); |
106 |
|
|
break; |
107 |
|
|
|
108 |
|
|
case WM_COMMAND: |
109 |
|
|
switch (LOWORD (wparam)) { |
110 |
|
|
case IDYES: |
111 |
|
|
wipe_contents = 1; |
112 |
|
|
if (IsDlgButtonChecked (dlg, IDC_CONFDELCLIP_BRAIN)) |
113 |
|
|
set_reg_winpt_flag ("WipeClipboard", 1); |
114 |
|
|
EndDialog (dlg, TRUE); |
115 |
|
|
break; |
116 |
|
|
|
117 |
|
|
case IDNO: |
118 |
|
|
wipe_contents = 0; |
119 |
|
|
if (IsDlgButtonChecked (dlg, IDC_CONFDELCLIP_BRAIN)) |
120 |
|
|
set_reg_winpt_flag ("WipeClipboard", 0); |
121 |
|
|
EndDialog (dlg, FALSE); |
122 |
|
|
break; |
123 |
|
|
} |
124 |
|
|
break; |
125 |
|
|
} |
126 |
|
|
return FALSE; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
static gpgme_error_t |
131 |
|
|
currwnd_gpg_dlg (HWND hwnd, UINT id, int *ret_set) |
132 |
|
|
{ |
133 |
twoaday |
68 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
134 |
werner |
36 |
int type; |
135 |
|
|
|
136 |
|
|
if (ret_set) |
137 |
|
|
*ret_set = 1; |
138 |
|
|
switch (id) { |
139 |
|
|
case ID_WINPT_CURRWND_SYMENC: |
140 |
twoaday |
226 |
gpg_clip_sym_encrypt (); |
141 |
werner |
36 |
break; |
142 |
|
|
|
143 |
|
|
case ID_WINPT_CURRWND_ENCRYPT: |
144 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ENCRYPT, hwnd, |
145 |
twoaday |
68 |
clip_encrypt_dlg_proc, 0, |
146 |
werner |
36 |
_("Encryption"), IDS_WINPT_ENCRYPT ); |
147 |
|
|
break; |
148 |
|
|
|
149 |
|
|
case ID_WINPT_CURRWND_SIGNENCRYPT: |
150 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGNENC, hwnd, |
151 |
twoaday |
68 |
clip_signenc_dlg_proc, 0, |
152 |
werner |
36 |
_("Sign & Encrypt"), IDS_WINPT_SIGNENC ); |
153 |
|
|
break; |
154 |
|
|
|
155 |
|
|
case ID_WINPT_CURRWND_SIGN: |
156 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGN, hwnd, |
157 |
twoaday |
68 |
clip_sign_dlg_proc, 0, |
158 |
werner |
36 |
_("Signing"), IDS_WINPT_SIGN ); |
159 |
|
|
break; |
160 |
|
|
|
161 |
|
|
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
162 |
|
|
err = gpg_clip_get_pgptype (&type); |
163 |
|
|
if (err) { |
164 |
|
|
msg_box (hwnd, gpgme_strerror (err), _("Clipboard"), MB_ERR); |
165 |
|
|
break; |
166 |
|
|
} |
167 |
twoaday |
229 |
if ((type & PGP_MESSAGE) && !(type & PGP_CLEARSIG)) { |
168 |
werner |
36 |
/* It makes only sense to insert the data in the window if it's |
169 |
|
|
really a ciphertext. Verfied data doesn't need this. */ |
170 |
twoaday |
229 |
err = clip_decrypt_dlg (hwnd, reg_prefs.use_viewer); |
171 |
|
|
if (!err && ret_set) |
172 |
|
|
*ret_set = 0; |
173 |
werner |
36 |
} |
174 |
|
|
else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG)) |
175 |
twoaday |
165 |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
176 |
werner |
36 |
else { |
177 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
178 |
twoaday |
68 |
clip_verify_dlg_proc, 0, |
179 |
werner |
36 |
_("Verify"), IDS_WINPT_VERIFY ); |
180 |
twoaday |
150 |
err = gpg_error (GPG_ERR_EOF); /* make sure window is not updated. */ |
181 |
werner |
36 |
} |
182 |
|
|
break; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
return err; |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
static void |
190 |
|
|
clip_gpg_dlg (HWND hwnd, UINT id) |
191 |
|
|
{ |
192 |
|
|
gpgme_error_t err; |
193 |
|
|
int type; |
194 |
|
|
|
195 |
twoaday |
129 |
if ((id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
196 |
|
|
&& gnupg_access_keyring (0)) { |
197 |
|
|
msg_box (hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR); |
198 |
werner |
36 |
return; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
switch( id ) { |
202 |
|
|
case ID_WINPT_SYMENC: |
203 |
twoaday |
226 |
gpg_clip_sym_encrypt (); |
204 |
werner |
36 |
break; |
205 |
|
|
|
206 |
|
|
case ID_WINPT_ENCRYPT: |
207 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ENCRYPT, hwnd, |
208 |
twoaday |
68 |
clip_encrypt_dlg_proc, 0, |
209 |
werner |
36 |
_("Encryption"), IDS_WINPT_ENCRYPT ); |
210 |
|
|
break; |
211 |
|
|
|
212 |
|
|
case ID_WINPT_SIGN: |
213 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGN, hwnd, |
214 |
twoaday |
68 |
clip_sign_dlg_proc, 0, |
215 |
werner |
36 |
_("Signing"), IDS_WINPT_SIGN ); |
216 |
|
|
break; |
217 |
|
|
|
218 |
|
|
case ID_WINPT_SIGNENCRYPT: |
219 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGNENC, hwnd, |
220 |
twoaday |
68 |
clip_signenc_dlg_proc, 0, |
221 |
werner |
36 |
_("Sign & Encrypt"), IDS_WINPT_SIGNENC ); |
222 |
|
|
break; |
223 |
|
|
|
224 |
|
|
case ID_WINPT_DECRYPT_VERIFY: |
225 |
|
|
err = gpg_clip_get_pgptype (&type); |
226 |
|
|
if (err) { |
227 |
|
|
msg_box( hwnd, gpgme_strerror( err ), _("Clipboard"), MB_ERR ); |
228 |
|
|
break; |
229 |
|
|
} |
230 |
twoaday |
229 |
if((type & PGP_MESSAGE) && !(type & PGP_CLEARSIG)) |
231 |
|
|
err = clip_decrypt_dlg (hwnd, reg_prefs.use_viewer); |
232 |
|
|
else if ((type & PGP_SIG) && !(type & PGP_CLEARSIG)) { |
233 |
werner |
36 |
text_input_s input; |
234 |
|
|
gpgme_data_t sig; |
235 |
|
|
|
236 |
twoaday |
225 |
memset (&input, 0, sizeof (input)); |
237 |
werner |
36 |
err = gpg_data_new_from_clipboard (&sig, 0); |
238 |
twoaday |
225 |
if (err) { |
239 |
|
|
msg_box (hwnd, gpgme_strerror( err ),_("Verify"), MB_ERR); |
240 |
werner |
36 |
return; |
241 |
|
|
} |
242 |
|
|
input.type = 0; |
243 |
twoaday |
225 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_TEXT, hwnd, |
244 |
|
|
text_input_dlg_proc, (LPARAM)&input, |
245 |
|
|
_("Text Input"), IDS_WINPT_TEXT); |
246 |
|
|
|
247 |
|
|
/* the dialog might have changed the clipboard, so we restore |
248 |
|
|
the original state (again). */ |
249 |
|
|
gpg_data_release_and_set_clipboard (sig, 0); |
250 |
|
|
if (input.length > 0) { |
251 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
252 |
|
|
clip_verify_dlg_proc, (LPARAM)&input, |
253 |
|
|
_("Verify"), IDS_WINPT_VERIFY); |
254 |
werner |
36 |
input.length = 0; |
255 |
twoaday |
225 |
free_if_alloc (input.data); |
256 |
werner |
36 |
} |
257 |
|
|
} |
258 |
|
|
else if (type & PGP_CLEARSIG) { |
259 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
260 |
twoaday |
68 |
clip_verify_dlg_proc, 0, |
261 |
werner |
36 |
_("Verify"), IDS_WINPT_VERIFY ); |
262 |
|
|
} |
263 |
|
|
else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY)) |
264 |
twoaday |
165 |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
265 |
werner |
36 |
else |
266 |
|
|
msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR); |
267 |
|
|
} |
268 |
twoaday |
72 |
} |
269 |
werner |
36 |
|
270 |
|
|
|
271 |
|
|
/* Load the Card Manager with the current card. */ |
272 |
|
|
static void |
273 |
twoaday |
121 |
load_card_manager (void) |
274 |
werner |
36 |
{ |
275 |
|
|
gpg_card_t card; |
276 |
|
|
|
277 |
|
|
card = gpg_card_load (); |
278 |
twoaday |
193 |
if (!card) |
279 |
|
|
return; |
280 |
|
|
|
281 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT, |
282 |
|
|
GetDesktopWindow (), card_edit_dlg_proc, |
283 |
|
|
(LPARAM)card, |
284 |
|
|
_("Card Edit"), IDS_WINPT_CARD_EDIT); |
285 |
|
|
gpg_card_release (card); |
286 |
werner |
36 |
} |
287 |
|
|
|
288 |
|
|
|
289 |
|
|
/* Add the winpt symbol to the task bar. */ |
290 |
|
|
static void |
291 |
|
|
add_taskbar_icon (HWND hwnd, NOTIFYICONDATA *nid) |
292 |
|
|
{ |
293 |
|
|
nid->cbSize = sizeof (NOTIFYICONDATA); |
294 |
|
|
nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
295 |
|
|
nid->uCallbackMessage = WM_USER; |
296 |
|
|
nid->hWnd = hwnd; |
297 |
|
|
nid->hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
298 |
|
|
strcpy (nid->szTip, "Windows Privacy Tray v"PGM_VERSION); |
299 |
|
|
Shell_NotifyIcon (NIM_ADD, nid); |
300 |
|
|
DestroyIcon (nid->hIcon); |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
|
304 |
twoaday |
229 |
/* Initialize all needed common controls. */ |
305 |
twoaday |
193 |
static void |
306 |
|
|
init_common_controls (void) |
307 |
|
|
{ |
308 |
|
|
INITCOMMONCONTROLSEX cce; |
309 |
|
|
|
310 |
|
|
/* date control, toolbar, trackbar, ... */ |
311 |
|
|
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
312 |
|
|
cce.dwICC = ICC_DATE_CLASSES|ICC_BAR_CLASSES; |
313 |
|
|
InitCommonControlsEx (&cce); |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
|
317 |
werner |
36 |
/* Main message loop for the tray window. */ |
318 |
|
|
LRESULT CALLBACK |
319 |
|
|
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
320 |
|
|
{ |
321 |
|
|
static NOTIFYICONDATA NID; |
322 |
twoaday |
174 |
static DWORD cookie; |
323 |
twoaday |
139 |
static int use_hotkey = 0; |
324 |
twoaday |
193 |
static int manual_shutdown = 0; |
325 |
twoaday |
139 |
HWND wnd; |
326 |
|
|
gpgme_error_t err; |
327 |
|
|
curr_wnd_ctx currwnd = {0}; |
328 |
|
|
const char *s; |
329 |
werner |
36 |
int rc, set_wc = 0, has_data = 0; |
330 |
|
|
|
331 |
|
|
switch (msg) { |
332 |
|
|
case WM_CREATE: |
333 |
|
|
add_taskbar_icon (hwnd, &NID); |
334 |
|
|
rc = wsock_init (); |
335 |
|
|
if (rc) |
336 |
|
|
msg_box (NULL, winpt_strerror (rc), "Winsock2 DLL", MB_ERR); |
337 |
|
|
if (!reg_prefs.no_hotkeys) { |
338 |
|
|
rc = hotkeys_register (hwnd); |
339 |
|
|
if (rc) |
340 |
|
|
msg_box (hwnd, hotkeys_strerror (), winpt_strerror (rc), MB_ERR); |
341 |
|
|
} |
342 |
|
|
rc = PTD_initialize (); |
343 |
|
|
if (!rc) |
344 |
|
|
msg_box (hwnd, _("Could not set current window mode hooks."), |
345 |
|
|
_("WinPT Error"), MB_OK); |
346 |
|
|
mapi_init (); |
347 |
twoaday |
193 |
init_common_controls (); |
348 |
twoaday |
174 |
html_help_init (&cookie); |
349 |
werner |
36 |
LoadLibrary ("RichEd32.Dll"); |
350 |
twoaday |
193 |
manual_shutdown = 0; |
351 |
werner |
36 |
break; |
352 |
|
|
|
353 |
|
|
case WM_ENDSESSION: |
354 |
|
|
case WM_DESTROY: |
355 |
|
|
case WM_CLOSE: |
356 |
|
|
case WM_QUIT: |
357 |
|
|
mapi_deinit (); |
358 |
|
|
wsock_end (); |
359 |
|
|
keycache_release (1); |
360 |
twoaday |
222 |
gnupg_backup_keyrings (reg_prefs.auto_backup, |
361 |
|
|
reg_prefs.backup.mode, |
362 |
|
|
reg_prefs.backup.include_secr); |
363 |
werner |
36 |
free_reg_prefs (); |
364 |
|
|
free_gnupg_table (); |
365 |
|
|
hotkeys_unregister (hwnd); |
366 |
|
|
PTD_delete (); |
367 |
|
|
agent_flush_cache (); |
368 |
twoaday |
174 |
html_help_deinit (cookie); |
369 |
werner |
36 |
if (!gpg_clip_istext_avail (&has_data) && has_data) { |
370 |
|
|
int chk = get_reg_winpt_flag ("WipeClipboard"); |
371 |
twoaday |
193 |
if (chk == -1 && manual_shutdown) |
372 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP, |
373 |
|
|
GetDesktopWindow (), confirm_delclipboard_dlg, |
374 |
twoaday |
68 |
0); |
375 |
werner |
36 |
if (wipe_contents || chk) |
376 |
|
|
set_clip_text (NULL, " ", 1); |
377 |
|
|
wipe_contents = 0; |
378 |
|
|
} |
379 |
|
|
debug_end (); |
380 |
|
|
Shell_NotifyIcon (NIM_DELETE, &NID); |
381 |
|
|
PostQuitMessage (0); |
382 |
|
|
ExitProcess (0); |
383 |
twoaday |
72 |
break; |
384 |
werner |
36 |
|
385 |
|
|
case WM_USER: |
386 |
|
|
switch (lparam) { |
387 |
|
|
case WM_RBUTTONUP: |
388 |
|
|
HMENU hm, popup; |
389 |
|
|
POINT p; |
390 |
|
|
|
391 |
|
|
gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1; |
392 |
|
|
|
393 |
twoaday |
229 |
wait_for_progress_cb (); |
394 |
werner |
36 |
SetForegroundWindow (hwnd); |
395 |
|
|
GetCursorPos (&p); |
396 |
|
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT)); |
397 |
|
|
popup = GetSubMenu (hm, 0); |
398 |
twoaday |
72 |
|
399 |
twoaday |
193 |
set_menu_text (popup, ID_WINPT_FILE, _("File Manager")); |
400 |
|
|
set_menu_text (popup, ID_WINPT_KEY, _("Key Manager")); |
401 |
|
|
set_menu_text (popup, ID_WINPT_CARD, _("Card Manager")); |
402 |
werner |
36 |
if (!scard_support) |
403 |
|
|
set_menu_state (popup, ID_WINPT_CARD, MF_DISABLED|MF_GRAYED); |
404 |
|
|
set_menu_text (popup, ID_WINPT_EDIT, _("Edit Clipboard")); |
405 |
|
|
set_menu_text (popup, ID_WINPT_ABOUT, _("About...")); |
406 |
|
|
set_menu_text (popup, ID_WINPT_QUIT, _("Exit")); |
407 |
|
|
set_menu_text (popup, ID_WINPT_SYMENC, _("Symmetric")); |
408 |
|
|
set_menu_text (popup, ID_WINPT_ENCRYPT, _("Encrypt")); |
409 |
twoaday |
72 |
set_menu_text (popup, ID_WINPT_SIGN, _("Sign")); |
410 |
werner |
36 |
set_menu_text (popup, ID_WINPT_SIGNENCRYPT, _("Sign && Encrypt")); |
411 |
|
|
set_menu_text (popup, ID_WINPT_DECRYPT, _("Decrypt/Verify")); |
412 |
|
|
set_menu_text (popup, ID_WINPT_VERIFY, _("Verify")); |
413 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_ENCRYPT, _("Encrypt")); |
414 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_SIGNENCRYPT, _("Sign && Encrypt")); |
415 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_DECRYPT_VERIFY, _("Decrypt/Verify")); |
416 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_SIGN, _("Sign")); |
417 |
twoaday |
72 |
if (!secret_key_available ()) { |
418 |
|
|
set_menu_state (popup, ID_WINPT_SIGN, MF_DISABLED|MF_GRAYED); |
419 |
|
|
set_menu_state (popup, ID_WINPT_CURRWND_SIGN, MF_DISABLED|MF_GRAYED); |
420 |
|
|
set_menu_state (popup, ID_WINPT_SIGNENCRYPT, MF_DISABLED|MF_GRAYED); |
421 |
|
|
set_menu_state (popup, ID_WINPT_CURRWND_SIGNENCRYPT, MF_DISABLED|MF_GRAYED); |
422 |
|
|
} |
423 |
werner |
36 |
/* change popup texts */ |
424 |
|
|
set_menu_text_bypos (popup, 6, _("Clipboard")); |
425 |
|
|
set_menu_text_bypos (popup, 7, _("Current Window")); |
426 |
|
|
set_menu_text_bypos (popup, 9, _("Preferences")); |
427 |
|
|
|
428 |
twoaday |
72 |
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, hwnd, NULL); |
429 |
|
|
PostMessage (hwnd, WM_USER, 0, 0); |
430 |
|
|
DestroyMenu (popup); |
431 |
|
|
DestroyMenu (hm); |
432 |
werner |
36 |
break; |
433 |
|
|
|
434 |
|
|
case WM_LBUTTONDBLCLK: |
435 |
twoaday |
229 |
wait_for_progress_cb (); |
436 |
twoaday |
78 |
gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1; |
437 |
|
|
SendMessage (hwnd, WM_COMMAND, ID_WINPT_KEY, 0); |
438 |
werner |
36 |
break; |
439 |
|
|
} |
440 |
|
|
break; |
441 |
|
|
|
442 |
|
|
case WM_HOTKEY: |
443 |
|
|
cmd = 0; |
444 |
twoaday |
229 |
switch (wparam) { |
445 |
werner |
36 |
case WPT_CLIP_ENCRYPT_ID: |
446 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_ENCRYPT, 0 ); |
447 |
|
|
break; |
448 |
|
|
|
449 |
|
|
case WPT_CLIP_DECRYPT_VERIFY_ID: |
450 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_DECRYPT_VERIFY, 0 ); |
451 |
|
|
break; |
452 |
|
|
|
453 |
|
|
case WPT_CLIP_SIGN_ID: |
454 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_SIGN, 0 ); |
455 |
|
|
break; |
456 |
|
|
|
457 |
|
|
case WPT_CLIP_SIGN_ENCRYPT_ID: |
458 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_SIGNENCRYPT, 0 ); |
459 |
|
|
break; |
460 |
|
|
|
461 |
|
|
case WPT_CURRWND_ENCRYPT_ID: |
462 |
|
|
use_hotkey = 1; |
463 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_ENCRYPT, 0 ); |
464 |
|
|
break; |
465 |
|
|
|
466 |
|
|
case WPT_CURRWND_SIGN_ID: |
467 |
|
|
use_hotkey = 1; |
468 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_SIGN, 0 ); |
469 |
|
|
break; |
470 |
|
|
|
471 |
|
|
case WPT_CURRWND_SIGN_ENCRYPT_ID: |
472 |
|
|
use_hotkey = 1; |
473 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_SIGNENCRYPT, 0 ); |
474 |
|
|
break; |
475 |
|
|
|
476 |
|
|
case WPT_CURRWND_DECRYPT_VERIFY_ID: |
477 |
|
|
use_hotkey = 1; |
478 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_DECRYPT_VERIFY, 0 ); |
479 |
|
|
break; |
480 |
|
|
|
481 |
|
|
case WPT_AGENT_FORGET_ID: |
482 |
|
|
rc = msg_box( hwnd, _("Remove all passphrases from cache?"), |
483 |
|
|
_("WinPT"), MB_YESNO|MB_ICONQUESTION ); |
484 |
|
|
if( rc == IDYES ) |
485 |
|
|
agent_flush_cache(); |
486 |
|
|
break; |
487 |
|
|
} |
488 |
|
|
break; |
489 |
|
|
|
490 |
|
|
case WM_COMMAND: |
491 |
|
|
if( gnupg_access_keyring( 1 ) ) { |
492 |
|
|
if( log_box( "WinPT", MB_ERR|MB_YESNO, |
493 |
|
|
_("Could not access public keyring, exit WinPT?") ) == IDYES ) |
494 |
|
|
SendMessage( hwnd, WM_DESTROY, 0, 0 ); |
495 |
|
|
break; |
496 |
|
|
} |
497 |
|
|
switch( wparam ) { |
498 |
|
|
/** Clipboard operations **/ |
499 |
|
|
case ID_WINPT_SYMENC: |
500 |
|
|
case ID_WINPT_ENCRYPT: |
501 |
|
|
case ID_WINPT_SIGN: |
502 |
|
|
case ID_WINPT_SIGNENCRYPT: |
503 |
|
|
case ID_WINPT_DECRYPT_VERIFY: |
504 |
twoaday |
193 |
err = gpg_clip_istext_avail (&has_data); |
505 |
|
|
if (err) { |
506 |
|
|
msg_box (hwnd, gpgme_strerror (err),_("Clipboard"), MB_ERR); |
507 |
werner |
36 |
break; |
508 |
|
|
} |
509 |
twoaday |
193 |
if (!has_data) { |
510 |
|
|
msg_box (hwnd, winpt_strerror (WPTERR_CLIP_EMPTY), |
511 |
|
|
_("Clipboard"), MB_ERR); |
512 |
werner |
36 |
break; |
513 |
|
|
} |
514 |
twoaday |
129 |
clip_gpg_dlg (hwnd, (int)wparam); |
515 |
werner |
36 |
break; |
516 |
twoaday |
193 |
|
517 |
werner |
36 |
/** Current window operations **/ |
518 |
|
|
case ID_WINPT_CURRWND_SYMENC: |
519 |
|
|
case ID_WINPT_CURRWND_ENCRYPT: |
520 |
|
|
case ID_WINPT_CURRWND_SIGNENCRYPT: |
521 |
|
|
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
522 |
|
|
case ID_WINPT_CURRWND_SIGN: |
523 |
|
|
rc = get_window_contents( hwnd, &currwnd, &use_hotkey ); |
524 |
|
|
if( rc ) { |
525 |
|
|
log_box( _("WinPT Error"), MB_ERR, |
526 |
|
|
_("Make sure that the window contains text.\n" |
527 |
|
|
"%s."), |
528 |
|
|
winpt_strerror( WPTERR_CURR_WND ) ); |
529 |
|
|
break; |
530 |
|
|
} |
531 |
twoaday |
129 |
rc = currwnd_gpg_dlg (hwnd, (UINT)wparam, &set_wc); |
532 |
|
|
if (!rc && set_wc) |
533 |
|
|
set_window_contents (hwnd, &currwnd); |
534 |
werner |
36 |
break; |
535 |
|
|
|
536 |
|
|
/** File handling **/ |
537 |
|
|
case ID_WINPT_FILE: |
538 |
twoaday |
139 |
s = _("File Manager (use drag & drop to add files)"); |
539 |
|
|
wnd = FindWindow (NULL, s); |
540 |
|
|
if (wnd && IsIconic (wnd)) |
541 |
|
|
ShowWindow (wnd, SW_RESTORE); |
542 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_FILE, |
543 |
|
|
GetDesktopWindow (), file_manager_dlg_proc, 0, |
544 |
|
|
s, IDS_WINPT_FILE); |
545 |
werner |
36 |
break; |
546 |
|
|
|
547 |
|
|
/** Misc **/ |
548 |
|
|
case ID_WINPT_KEY: |
549 |
twoaday |
139 |
wnd = FindWindow (NULL, _("Key Manager")); |
550 |
|
|
if (wnd && IsIconic (wnd)) |
551 |
|
|
ShowWindow (wnd, SW_RESTORE); |
552 |
twoaday |
180 |
if (wnd) |
553 |
|
|
SetForegroundWindow (wnd); |
554 |
twoaday |
139 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC, |
555 |
twoaday |
193 |
GetDesktopWindow(), keymanager_dlg_proc, |
556 |
|
|
cmd != 0? (LPARAM)cmd : 0, |
557 |
twoaday |
139 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
558 |
werner |
36 |
cmd = 0; |
559 |
|
|
break; |
560 |
|
|
|
561 |
|
|
case ID_WINPT_CARD: |
562 |
twoaday |
121 |
load_card_manager (); |
563 |
werner |
36 |
break; |
564 |
|
|
|
565 |
|
|
case ID_WINPT_EDIT: |
566 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CLIPEDIT, |
567 |
twoaday |
68 |
GetDesktopWindow(), clip_edit_dlg_proc, 0, |
568 |
werner |
36 |
_("Clipboard Editor"), IDS_WINPT_CLIPEDIT ); |
569 |
|
|
break; |
570 |
|
|
|
571 |
|
|
case ID_WINPT_ABOUT: |
572 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, GetDesktopWindow(), |
573 |
twoaday |
68 |
about_winpt_dlg_proc, 0, |
574 |
werner |
36 |
_("About WinPT"), IDS_WINPT_ABOUT ); |
575 |
|
|
break; |
576 |
|
|
|
577 |
|
|
case ID_WINPT_PREFS: |
578 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_PREFS, GetDesktopWindow(), |
579 |
twoaday |
68 |
prefs_dlg_proc, 0, |
580 |
werner |
36 |
_("WinPT Preferences"), IDS_WINPT_PREFS ); |
581 |
|
|
break; |
582 |
|
|
|
583 |
|
|
case ID_WINPT_GPGPREFS: |
584 |
twoaday |
190 |
rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, |
585 |
|
|
GetDesktopWindow(), gpgprefs_dlg_proc, 0, |
586 |
werner |
36 |
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS); |
587 |
twoaday |
190 |
if (rc == TRUE) |
588 |
|
|
update_keycache (GetDesktopWindow ()); |
589 |
werner |
36 |
break; |
590 |
|
|
|
591 |
|
|
case ID_WINPT_QUIT: |
592 |
twoaday |
193 |
manual_shutdown = 1; |
593 |
werner |
36 |
SendMessage (hwnd, WM_DESTROY, 0, 0); |
594 |
|
|
break; |
595 |
|
|
} |
596 |
|
|
break; |
597 |
|
|
} |
598 |
|
|
|
599 |
|
|
return DefWindowProc (hwnd, msg, wparam, lparam); |
600 |
|
|
} |