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