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

Contents of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 3636 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

1 /* wptTextInputDlg.cpp - Dialog for getting text
2 * Copyright (C) 2001-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 #include <windows.h>
21
22 #include "../resource.h"
23 #include "wptTypes.h"
24 #include "wptGPG.h"
25 #include "wptCommonCtl.h"
26 #include "wptContext.h"
27 #include "wptDlgs.h"
28 #include "wptW32API.h"
29 #include "wptNLS.h"
30 #include "wptErrors.h"
31
32 #define MAX_FILESIZE 8388608 /* 8MB */
33
34 void
35 load_file_contents (HWND dlg, const char * file)
36 {
37 size_t size = 0;
38 char *buf = NULL;
39 FILE *fp;
40
41 size = get_file_size (file);
42 if (!size)
43 return;
44 if (size > MAX_FILESIZE) {
45 msg_box (dlg, _("Data is too large for copying."), _("Info"), MB_ERR);
46 return;
47 }
48 buf = new char[size+1];
49 if (!buf)
50 BUG (0);
51 memset (buf, 0, size+1);
52 fp = fopen (file, "rb");
53 if (fp) {
54 fread (buf, 1, size, fp);
55 fclose (fp);
56 SetDlgItemText (dlg, IDC_TEXT_INPUT, buf);
57 }
58 free_if_alloc (buf);
59 } /* load_file_contents */
60
61
62 BOOL CALLBACK
63 text_input_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
64 {
65 static text_input_s *ctx;
66 char *p;
67 size_t n;
68
69 switch (msg) {
70 case WM_INITDIALOG:
71 ctx = (text_input_s *)lparam;
72 if (ctx == NULL)
73 dlg_fatal_error (dlg, "Could not get dialog param.");
74 #ifndef LANG_DE
75 SetWindowText (dlg, _("Text Input"));
76 #endif
77 switch (ctx->type) {
78 case 0:
79 SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed"));
80 break;
81 }
82 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
83 SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load"));
84 SetForegroundWindow (dlg);
85 return TRUE;
86
87 case WM_COMMAND:
88 switch( LOWORD(wparam) ) {
89 case IDC_TEXT_FILE:
90 const char *file;
91
92 file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL );
93 if( file )
94 load_file_contents( dlg, file );
95 break;
96
97 case IDOK:
98 p = new char[100*1024+1];
99 if (!p)
100 BUG (0);
101 n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024);
102 if (n > 0) {
103 ctx->length = n;
104 ctx->data = new char[n+1];
105 if (!ctx->data)
106 BUG (0);
107 memset (ctx->data, 0, n+1);
108 strcpy (ctx->data, p);
109 }
110 else {
111 ctx->length = 0;
112 ctx->data = NULL;
113 }
114 free_if_alloc (p);
115 EndDialog (dlg, TRUE);
116 return TRUE;
117
118 case IDCANCEL:
119 ctx->length = 0;
120 ctx->data = NULL;
121 EndDialog (dlg, FALSE);
122 return FALSE;
123 }
124 break;
125 }
126
127 return FALSE;
128 } /* text_input_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26