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

Contents of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26