1 |
twoaday |
2 |
/* wptTextInputDlg.cpp - Dialog for getting text |
2 |
twoaday |
22 |
* Copyright (C) 2001-2005 Timo Schulz |
3 |
twoaday |
2 |
* |
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 |
twoaday |
22 |
#define MAX_FILESIZE 8388608 /* 8MB */ |
33 |
twoaday |
2 |
|
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 |
twoaday |
22 |
if (size > MAX_FILESIZE) { |
45 |
twoaday |
2 |
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 |
twoaday |
22 |
memset (buf, 0, size+1); |
52 |
twoaday |
2 |
fp = fopen (file, "rb"); |
53 |
twoaday |
22 |
if (fp) { |
54 |
twoaday |
2 |
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 |
twoaday |
22 |
text_input_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
64 |
twoaday |
2 |
{ |
65 |
|
|
static text_input_s *ctx; |
66 |
|
|
char *p; |
67 |
|
|
size_t n; |
68 |
|
|
|
69 |
twoaday |
22 |
switch (msg) { |
70 |
twoaday |
2 |
case WM_INITDIALOG: |
71 |
|
|
ctx = (text_input_s *)lparam; |
72 |
twoaday |
22 |
if (ctx == NULL) |
73 |
|
|
dlg_fatal_error (dlg, "Could not get dialog param."); |
74 |
twoaday |
2 |
#ifndef LANG_DE |
75 |
twoaday |
22 |
SetWindowText (dlg, _("Text Input")); |
76 |
twoaday |
2 |
#endif |
77 |
twoaday |
22 |
switch (ctx->type) { |
78 |
twoaday |
2 |
case 0: |
79 |
twoaday |
22 |
SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed")); |
80 |
twoaday |
2 |
break; |
81 |
|
|
} |
82 |
|
|
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
83 |
twoaday |
22 |
SetForegroundWindow (dlg); |
84 |
twoaday |
2 |
return TRUE; |
85 |
|
|
|
86 |
|
|
case WM_COMMAND: |
87 |
|
|
switch( LOWORD(wparam) ) { |
88 |
|
|
case IDC_TEXT_FILE: |
89 |
|
|
const char *file; |
90 |
|
|
|
91 |
twoaday |
23 |
file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL ); |
92 |
twoaday |
2 |
if( file ) |
93 |
|
|
load_file_contents( dlg, file ); |
94 |
|
|
break; |
95 |
|
|
|
96 |
|
|
case IDOK: |
97 |
|
|
p = new char[100*1024+1]; |
98 |
twoaday |
22 |
if (!p) |
99 |
|
|
BUG (0); |
100 |
|
|
n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024); |
101 |
|
|
if (n > 0) { |
102 |
twoaday |
2 |
ctx->length = n; |
103 |
|
|
ctx->data = new char[n+1]; |
104 |
twoaday |
22 |
if (!ctx->data) |
105 |
|
|
BUG (0); |
106 |
|
|
memset (ctx->data, 0, n+1); |
107 |
|
|
strcpy (ctx->data, p); |
108 |
twoaday |
2 |
} |
109 |
|
|
else { |
110 |
|
|
ctx->length = 0; |
111 |
|
|
ctx->data = NULL; |
112 |
|
|
} |
113 |
twoaday |
22 |
free_if_alloc (p); |
114 |
|
|
EndDialog (dlg, TRUE); |
115 |
twoaday |
2 |
return TRUE; |
116 |
|
|
|
117 |
|
|
case IDCANCEL: |
118 |
|
|
ctx->length = 0; |
119 |
|
|
ctx->data = NULL; |
120 |
twoaday |
22 |
EndDialog (dlg, FALSE); |
121 |
twoaday |
2 |
return FALSE; |
122 |
|
|
} |
123 |
|
|
break; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
return FALSE; |
127 |
|
|
} /* text_input_dlg_proc */ |