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

Contents of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 3544 byte(s)
WinPT initial checkin.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26