1 |
/* wptClipEditDlg.cpp - Clipboard Editor dialog |
/* wptClipEditDlg.cpp - Clipboard Editor dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
31 |
#include "wptGPG.h" |
#include "wptGPG.h" |
32 |
#include "wptNLS.h" |
#include "wptNLS.h" |
33 |
#include "resource.h" |
#include "resource.h" |
34 |
|
#include "wptCommonCtl.h" |
35 |
|
#include "wptContext.h" |
36 |
|
#include "wptKeylist.h" |
37 |
|
|
38 |
#ifdef _MSC_VER |
#ifdef _MSC_VER |
39 |
#include "winpt_header.h" |
#include "winpt_header.h" |
47 |
0, 0}; |
0, 0}; |
48 |
#endif |
#endif |
49 |
|
|
50 |
|
|
51 |
/* Load the clipboard contents into the text field in @dlg. |
/* Load the clipboard contents into the text field in @dlg. |
52 |
|
Optinally @header and @footer can be used to set a header and footer. |
53 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
54 |
static int |
static int |
55 |
load_clipboard (HWND dlg) |
load_clipboard (HWND dlg, |
56 |
|
const char *header, const char *footer) |
57 |
{ |
{ |
58 |
HANDLE clipmem; |
HANDLE clipmem; |
59 |
char *cliptext; |
char *cliptext; |
60 |
char *p; |
char *p, *pp; |
61 |
|
|
62 |
CloseClipboard (); /* make sure it is closed. */ |
CloseClipboard (); /* make sure it is closed. */ |
63 |
if (OpenClipboard (NULL) == FALSE) { |
if (OpenClipboard (NULL) == FALSE) { |
82 |
strcpy (p, cliptext); |
strcpy (p, cliptext); |
83 |
|
|
84 |
GlobalUnlock (clipmem); |
GlobalUnlock (clipmem); |
85 |
CloseClipboard (); |
CloseClipboard (); |
86 |
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p); |
|
87 |
|
if (header && footer) { |
88 |
|
const char *fmt = "%s\r\n%s\r\n%s"; |
89 |
|
int len = strlen (header) + strlen (footer) + strlen (fmt) + strlen (p); |
90 |
|
|
91 |
|
pp = new char[len + 1]; |
92 |
|
if (!pp) |
93 |
|
BUG (0); |
94 |
|
_snprintf (pp, len, fmt, header, p, footer); |
95 |
|
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, pp); |
96 |
|
free_if_alloc (pp); |
97 |
|
} |
98 |
|
else |
99 |
|
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p); |
100 |
free_if_alloc (p); |
free_if_alloc (p); |
|
|
|
101 |
return 0; |
return 0; |
102 |
} |
} |
103 |
|
|
114 |
int id; |
int id; |
115 |
|
|
116 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
117 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
118 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
119 |
open.lpstrTitle = _("File Open"); |
open.lpstrTitle = _("File Open"); |
120 |
open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0"); |
open.lpstrFilter = "All Files (*.*)\0*.*\0\0"; |
121 |
open.hwndOwner = dlg; |
open.hwndOwner = dlg; |
122 |
open.lpstrFile = file; |
open.lpstrFile = file; |
123 |
open.nMaxFile = sizeof (file)-1; |
open.nMaxFile = sizeof (file)-1; |
124 |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
125 |
|
|
126 |
if (GetOpenFileName (&open)) { |
if (GetOpenFileName (&open)) { |
127 |
if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) { |
if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) { |
128 |
id = msg_box (dlg, _("The file you want to add is very large.\n" |
id = msg_box (dlg, _("The file you want to add is very large.\n" |
129 |
"Still proceed?"), _("Clipboard"), |
"Still proceed?"), _("Clipboard"), |
130 |
MB_INFO|MB_YESNO); |
MB_INFO|MB_YESNO); |
140 |
p = new char[size+1]; |
p = new char[size+1]; |
141 |
if (!p) |
if (!p) |
142 |
BUG (0); |
BUG (0); |
143 |
fread (p, 1, size, fp); |
memset (p, 0, size+1); |
144 |
p[size] = '\0'; |
size = fread (p, 1, size, fp); |
145 |
fclose (fp); |
fclose (fp); |
146 |
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p); |
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p); |
147 |
free_if_alloc (p); |
free_if_alloc (p); |
165 |
save.lStructSize = sizeof (OPENFILENAME); |
save.lStructSize = sizeof (OPENFILENAME); |
166 |
save.hInstance = glob_hinst; |
save.hInstance = glob_hinst; |
167 |
save.lpstrTitle = _("File Save"); |
save.lpstrTitle = _("File Save"); |
168 |
save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0"); |
save.lpstrFile = (char *)"All Files (*.*)\0*.*\0\0"; |
169 |
save.hwndOwner = dlg; |
save.hwndOwner = dlg; |
170 |
save.lpstrFile = file; |
save.lpstrFile = file; |
171 |
save.nMaxFile = sizeof (file) - 1; |
save.nMaxFile = sizeof (file) - 1; |
172 |
save.Flags = OFN_OVERWRITEPROMPT; |
save.Flags = OFN_OVERWRITEPROMPT; |
173 |
|
|
174 |
if( GetSaveFileName( &save ) ) { |
if (GetSaveFileName (&save)) { |
175 |
if( file_exist_check( file ) == 0 ) { |
if (file_exist_check (file) == 0) { |
176 |
id = log_box (_("Clipboard"), MB_YESNO, |
id = log_box (_("Clipboard"), MB_YESNO, |
177 |
_("\"%s\" already exists.\n" |
_("\"%s\" already exists.\n" |
178 |
"Replace existing file?"), file); |
"Replace existing file?"), file); |
203 |
} |
} |
204 |
|
|
205 |
|
|
206 |
|
void verify_get_clip_info (gpgme_signature_t sig, |
207 |
|
char **r_header, char **r_footer); |
208 |
|
|
209 |
/* Dialog box procedure for the clipboard editor. */ |
/* Dialog box procedure for the clipboard editor. */ |
210 |
BOOL CALLBACK |
BOOL CALLBACK |
211 |
clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
212 |
{ |
{ |
213 |
static DWORD cookie = 0; |
char *head=NULL, *foot=NULL; |
214 |
|
|
215 |
switch (msg) { |
switch (msg) { |
216 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
221 |
SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save")); |
SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save")); |
222 |
SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes")); |
SetDlgItemText (dlg, IDC_CLIPEDIT_QUOTE, _("Add quotes")); |
223 |
SetDlgItemText (dlg, IDOK, _("&Close")); |
SetDlgItemText (dlg, IDOK, _("&Close")); |
224 |
|
/* If there is a param, we expect a signature and initialize |
225 |
html_help_init (&cookie); |
the header and footer variable accordingly. */ |
226 |
load_clipboard (dlg); |
if (lparam) |
227 |
|
verify_get_clip_info ((gpgme_signature_t)lparam, &head, &foot); |
228 |
|
load_clipboard (dlg, head, foot); |
229 |
|
free_if_alloc (head); |
230 |
|
free_if_alloc (foot); |
231 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
232 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
233 |
return TRUE; |
return TRUE; |
|
|
|
|
case WM_DESTROY: |
|
|
html_help_deinit (); |
|
|
break; |
|
234 |
|
|
235 |
case WM_HELP: |
case WM_HELP: |
236 |
html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr); |
html_help_dispatch (lparam, "winpt.chm::winpt_texts.txt", help_arr); |
237 |
break; |
break; |
|
|
|
|
case WM_SYSCOMMAND: |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
|
|
EndDialog (dlg, TRUE); |
|
|
return TRUE; |
|
238 |
|
|
239 |
case WM_COMMAND: |
case WM_COMMAND: |
240 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
241 |
|
case IDCANCEL: |
242 |
|
EndDialog (dlg, FALSE); |
243 |
|
return TRUE; |
244 |
|
|
245 |
case IDOK: |
case IDOK: |
246 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
247 |
return TRUE; |
return TRUE; |
275 |
|
|
276 |
case IDC_CLIPEDIT_LOAD: |
case IDC_CLIPEDIT_LOAD: |
277 |
if (!load_clipboard_from_file (dlg)) { |
if (!load_clipboard_from_file (dlg)) { |
278 |
/* XXX: for some files the code produces a crash! */ |
CheckDlgButton (dlg, IDC_CLIPEDIT_QUOTE, BST_UNCHECKED); |
279 |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), 0); |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDC_CLIPEDIT_SEND, 0), 0); |
280 |
} |
} |
281 |
return TRUE; |
return TRUE; |
282 |
|
|