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

Contents of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3588 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


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, IDC_TEXT_FILE, _("&Load"));
83 SetForegroundWindow (dlg);
84 return TRUE;
85
86 case WM_COMMAND:
87 switch( LOWORD(wparam) ) {
88 case IDC_TEXT_FILE:
89 const char *file;
90
91 file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL );
92 if( file )
93 load_file_contents( dlg, file );
94 break;
95
96 case IDOK:
97 p = new char[100*1024+1];
98 if (!p)
99 BUG (0);
100 n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024);
101 if (n > 0) {
102 ctx->length = n;
103 ctx->data = new char[n+1];
104 if (!ctx->data)
105 BUG (0);
106 memset (ctx->data, 0, n+1);
107 strcpy (ctx->data, p);
108 }
109 else {
110 ctx->length = 0;
111 ctx->data = NULL;
112 }
113 free_if_alloc (p);
114 EndDialog (dlg, TRUE);
115 return TRUE;
116
117 case IDCANCEL:
118 ctx->length = 0;
119 ctx->data = NULL;
120 EndDialog (dlg, FALSE);
121 return FALSE;
122 }
123 break;
124 }
125
126 return FALSE;
127 } /* text_input_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26