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