1 |
twoaday |
2 |
/* wptClipEditDlg.cpp - Clipboard Editor dialog |
2 |
|
|
* Copyright (C) 2000-2004 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 |
|
|
#include <windows.h> |
22 |
|
|
#include <stdio.h> |
23 |
|
|
|
24 |
|
|
#include "wptTypes.h" |
25 |
|
|
#include "wptW32API.h" |
26 |
|
|
#include "wptVersion.h" |
27 |
|
|
#include "wptErrors.h" |
28 |
|
|
#include "wptGPG.h" |
29 |
|
|
#include "wptNLS.h" |
30 |
|
|
#include "../resource.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
BOOL CALLBACK |
34 |
|
|
clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
35 |
|
|
{ |
36 |
|
|
HANDLE clipmem; |
37 |
|
|
OPENFILENAME open; |
38 |
|
|
FILE * fp; |
39 |
|
|
char * cliptext = NULL, * newtext = NULL, * p; |
40 |
|
|
char file[512] = ""; |
41 |
|
|
int nbytes, id, size; |
42 |
|
|
|
43 |
|
|
switch ( msg ) { |
44 |
|
|
case WM_INITDIALOG: |
45 |
|
|
#ifndef LANG_DE |
46 |
|
|
SetWindowText (dlg, _("Clipboard Editor")); |
47 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy")); |
48 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r")); |
49 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load")); |
50 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save")); |
51 |
|
|
#endif |
52 |
|
|
CloseClipboard (); /* make sure it is closed. */ |
53 |
|
|
if( OpenClipboard( NULL ) == FALSE ) { |
54 |
|
|
msg_box( dlg, winpt_strerror( WPTERR_CLIP_OPEN ), _("Clipboard"), MB_ERR ); |
55 |
|
|
return FALSE; |
56 |
|
|
} |
57 |
|
|
clipmem = GetClipboardData (CF_TEXT); |
58 |
|
|
if (clipmem == NULL) { |
59 |
|
|
center_window (dlg); |
60 |
|
|
SetForegroundWindow (dlg); |
61 |
|
|
CloseClipboard (); |
62 |
|
|
return FALSE; |
63 |
|
|
} |
64 |
|
|
cliptext = (char *) GlobalLock (clipmem); |
65 |
|
|
if (cliptext == NULL || !strlen (cliptext)) { |
66 |
|
|
CloseClipboard (); |
67 |
|
|
return FALSE; |
68 |
|
|
} |
69 |
|
|
p = new char [strlen (cliptext)+2]; |
70 |
|
|
if (!p) |
71 |
|
|
BUG (0); |
72 |
|
|
strcpy (p, cliptext); |
73 |
|
|
GlobalUnlock (clipmem); |
74 |
|
|
CloseClipboard (); |
75 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p); |
76 |
|
|
free_if_alloc (p); |
77 |
|
|
center_window (dlg); |
78 |
|
|
SetForegroundWindow (dlg); |
79 |
|
|
return TRUE; |
80 |
|
|
|
81 |
|
|
case WM_SYSCOMMAND: |
82 |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
83 |
|
|
EndDialog (dlg, TRUE); |
84 |
|
|
return FALSE; |
85 |
|
|
|
86 |
|
|
case WM_COMMAND: |
87 |
|
|
switch (LOWORD (wparam)) { |
88 |
|
|
case IDOK: |
89 |
|
|
EndDialog (dlg, TRUE); |
90 |
|
|
return TRUE; |
91 |
|
|
|
92 |
|
|
case IDC_CLIPEDIT_SEND: |
93 |
|
|
if (IsDlgButtonChecked (dlg, IDC_CLIPEDIT_QUOTE)) { |
94 |
|
|
gpgme_data_t txt; |
95 |
|
|
gpgme_data_new_from_clipboard (&txt); |
96 |
|
|
gpgme_data_mail_quote (&txt); |
97 |
|
|
gpgme_data_release_and_set_clipboard (txt); |
98 |
|
|
SendMessage (dlg, WM_INITDIALOG, 0, 0); |
99 |
|
|
return TRUE; |
100 |
|
|
} |
101 |
|
|
SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1); |
102 |
|
|
SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0); |
103 |
|
|
return TRUE; |
104 |
|
|
|
105 |
|
|
case IDC_CLIPEDIT_CLEAR: |
106 |
|
|
if( OpenClipboard( NULL ) == FALSE ) { |
107 |
|
|
msg_box( dlg, winpt_strerror( WPTERR_CLIP_OPEN ), _("Clipboard"), MB_ERR ); |
108 |
|
|
return FALSE; |
109 |
|
|
} |
110 |
|
|
if (EmptyClipboard () == FALSE) { |
111 |
|
|
CloseClipboard (); |
112 |
|
|
msg_box (dlg, winpt_strerror (WPTERR_CLIP_EMPTY), _("Clipboard"), MB_ERR); |
113 |
|
|
return FALSE; |
114 |
|
|
} |
115 |
|
|
CloseClipboard (); |
116 |
|
|
SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, ""); |
117 |
|
|
return TRUE; |
118 |
|
|
|
119 |
|
|
case IDC_CLIPEDIT_LOAD: |
120 |
|
|
memset (&open, 0, sizeof (open)); |
121 |
|
|
open.lStructSize = sizeof (OPENFILENAME); |
122 |
|
|
open.hInstance = glob_hinst; |
123 |
|
|
open.lpstrTitle = _("File Open"); |
124 |
|
|
open.lpstrFilter = (char *)_("All Files (*.*)\0*.*"); |
125 |
|
|
open.hwndOwner = dlg; |
126 |
|
|
open.lpstrFile = file; |
127 |
|
|
open.nMaxFile = sizeof (file)-1; |
128 |
|
|
open.Flags = 0; |
129 |
|
|
if (GetOpenFileName (&open)) { |
130 |
|
|
if( (size=get_file_size( file )) > MAX_CLIPTEXT_SIZE ) { |
131 |
|
|
id = msg_box( dlg, _("The file you want to add is very large.\n" |
132 |
|
|
"Still proceed?"), _("Clipboard"), MB_INFO|MB_YESNO ); |
133 |
|
|
if( id == IDNO ) |
134 |
|
|
return FALSE; |
135 |
|
|
} |
136 |
|
|
fp = fopen( file, "rb" ); |
137 |
|
|
if (!fp) { |
138 |
|
|
msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN), _("Clipboard"), MB_ERR); |
139 |
|
|
return FALSE; |
140 |
|
|
} |
141 |
|
|
p = new char[size+1]; |
142 |
|
|
if (!p) |
143 |
|
|
BUG (0); |
144 |
|
|
fread( p, 1, size, fp ); |
145 |
|
|
p[size] = '\0'; |
146 |
|
|
fclose( fp ); |
147 |
|
|
SetDlgItemText( dlg, IDC_CLIPEDIT_CLIPTEXT2, p ); |
148 |
|
|
free_if_alloc( p ); |
149 |
|
|
PostMessage( dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), NULL ); |
150 |
|
|
return TRUE; |
151 |
|
|
} |
152 |
|
|
break; |
153 |
|
|
|
154 |
|
|
case IDC_CLIPEDIT_SAVE: |
155 |
|
|
memset (&open, 0, sizeof (open)); |
156 |
|
|
open.lStructSize = sizeof OPENFILENAME; |
157 |
|
|
open.hInstance = glob_hinst; |
158 |
|
|
open.lpstrTitle = _("File Save"); |
159 |
|
|
open.lpstrFile = (char *)_("All Files (*.*)\0*.*"); |
160 |
|
|
open.hwndOwner = dlg; |
161 |
|
|
open.lpstrFile = file; |
162 |
|
|
open.nMaxFile = sizeof (file) - 1; |
163 |
|
|
|
164 |
|
|
if( GetSaveFileName( &open ) ) { |
165 |
|
|
if( file_exist_check( file ) == 0 ) { |
166 |
|
|
id = msg_box( dlg, _("File already exists!\nOverwrite?"), |
167 |
|
|
_("Clipboard"), MB_INFO|MB_YESNO ); |
168 |
|
|
if( id == IDNO ) |
169 |
|
|
return FALSE; |
170 |
|
|
} |
171 |
|
|
fp = fopen( file, "wb" ); |
172 |
|
|
if( !fp ) { |
173 |
|
|
msg_box( dlg, winpt_strerror( WPTERR_FILE_CREAT ), _("Clipboard"), MB_ERR ); |
174 |
|
|
return FALSE; |
175 |
|
|
} |
176 |
|
|
nbytes = SendDlgItemMessage( dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_GETTEXTLENGTH, 0, 0 ); |
177 |
|
|
if( nbytes > 0 ) { |
178 |
|
|
p = new char[nbytes+1]; |
179 |
|
|
if( !p ) |
180 |
|
|
BUG( NULL ); |
181 |
|
|
GetDlgItemText( dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes ); |
182 |
|
|
fwrite( p, 1, nbytes, fp ); |
183 |
|
|
} |
184 |
|
|
fclose( fp ); |
185 |
|
|
free_if_alloc( p ); |
186 |
|
|
} |
187 |
|
|
break; |
188 |
|
|
} |
189 |
|
|
break; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
return FALSE; |
193 |
|
|
} /* clip_edit_dlg_proc */ |