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

Contents of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91 - (show annotations)
Tue Nov 22 09:23:02 2005 UTC (19 years, 3 months ago) by twoaday
File size: 3519 byte(s)
Remove debug output for card code.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26