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

Contents of /trunk/Src/wptClipEditDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6120 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26