1 |
werner |
36 |
/* wptTextInputDlg.cpp - Dialog for getting text |
2 |
twoaday |
225 |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
werner |
36 |
* |
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 |
werner |
47 |
#include "resource.h" |
27 |
werner |
36 |
#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 |
twoaday |
225 |
} |
64 |
werner |
36 |
|
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 |
twoaday |
225 |
const char *file; |
71 |
werner |
36 |
char *p; |
72 |
twoaday |
225 |
DWORD n; |
73 |
werner |
36 |
|
74 |
|
|
switch (msg) { |
75 |
|
|
case WM_INITDIALOG: |
76 |
|
|
ctx = (text_input_s *)lparam; |
77 |
twoaday |
225 |
if (!ctx) |
78 |
|
|
BUG (0); |
79 |
werner |
36 |
SetWindowText (dlg, _("Text Input")); |
80 |
|
|
switch (ctx->type) { |
81 |
|
|
case 0: |
82 |
twoaday |
225 |
SetDlgItemText (dlg, IDC_TEXT_INFO, |
83 |
|
|
_("Enter the text that was signed")); |
84 |
werner |
36 |
break; |
85 |
|
|
} |
86 |
|
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
87 |
|
|
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
88 |
|
|
SetForegroundWindow (dlg); |
89 |
|
|
return TRUE; |
90 |
|
|
|
91 |
|
|
case WM_COMMAND: |
92 |
twoaday |
225 |
switch (LOWORD (wparam)) { |
93 |
werner |
36 |
case IDC_TEXT_FILE: |
94 |
twoaday |
225 |
file = get_fileopen_dlg (dlg, _("Text Input from File"), NULL, NULL); |
95 |
|
|
if (file) |
96 |
|
|
load_file_contents (dlg, file); |
97 |
werner |
36 |
break; |
98 |
|
|
|
99 |
|
|
case IDOK: |
100 |
twoaday |
225 |
n = item_get_text_length (dlg, IDC_TEXT_INPUT); |
101 |
|
|
if (n < 1) { |
102 |
|
|
ctx->length = 0; |
103 |
|
|
ctx->data = NULL; |
104 |
|
|
} |
105 |
|
|
else { |
106 |
|
|
p = new char[n+2]; |
107 |
|
|
if (!p) |
108 |
|
|
BUG (0); |
109 |
|
|
n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, n+1); |
110 |
werner |
36 |
ctx->length = n; |
111 |
twoaday |
225 |
ctx->data = p; |
112 |
werner |
36 |
} |
113 |
|
|
EndDialog (dlg, TRUE); |
114 |
|
|
return TRUE; |
115 |
|
|
|
116 |
|
|
case IDCANCEL: |
117 |
|
|
ctx->length = 0; |
118 |
|
|
ctx->data = NULL; |
119 |
|
|
EndDialog (dlg, FALSE); |
120 |
|
|
return FALSE; |
121 |
|
|
} |
122 |
|
|
break; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
return FALSE; |
126 |
twoaday |
225 |
} |