1 |
/* wptTextInputDlg.cpp - Dialog for getting text |
/* wptTextInputDlg.cpp - Dialog for getting text |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* 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 |
* 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 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
20 |
#include <windows.h> |
#ifdef HAVE_CONFIG_H |
21 |
|
#include <config.h> |
22 |
#include "../resource.h" |
#endif |
23 |
#include "wptTypes.h" |
|
24 |
#include "wptGPG.h" |
#include <windows.h> |
25 |
#include "wptCommonCtl.h" |
#include <windows.h> |
26 |
#include "wptContext.h" |
|
27 |
#include "wptDlgs.h" |
#include "../resource.h" |
28 |
#include "wptW32API.h" |
#include "wptTypes.h" |
29 |
#include "wptNLS.h" |
#include "wptGPG.h" |
30 |
#include "wptErrors.h" |
#include "wptCommonCtl.h" |
31 |
|
#include "wptContext.h" |
32 |
#define MAX_FILESIZE 8388608 /* 8MB */ |
#include "wptDlgs.h" |
33 |
|
#include "wptW32API.h" |
34 |
void |
#include "wptNLS.h" |
35 |
load_file_contents (HWND dlg, const char * file) |
#include "wptErrors.h" |
36 |
{ |
|
37 |
size_t size = 0; |
#define MAX_FILESIZE 8388608 /* 8MB */ |
38 |
char *buf = NULL; |
|
39 |
FILE *fp; |
void |
40 |
|
load_file_contents (HWND dlg, const char * file) |
41 |
size = get_file_size (file); |
{ |
42 |
if (!size) |
size_t size = 0; |
43 |
return; |
char *buf = NULL; |
44 |
if (size > MAX_FILESIZE) { |
FILE *fp; |
45 |
msg_box (dlg, _("Data is too large for copying."), _("Info"), MB_ERR); |
|
46 |
return; |
size = get_file_size (file); |
47 |
} |
if (!size) |
48 |
buf = new char[size+1]; |
return; |
49 |
if (!buf) |
if (size > MAX_FILESIZE) { |
50 |
BUG (0); |
msg_box (dlg, _("Data is too large for copying."), _("Info"), MB_ERR); |
51 |
memset (buf, 0, size+1); |
return; |
52 |
fp = fopen (file, "rb"); |
} |
53 |
if (fp) { |
buf = new char[size+1]; |
54 |
fread (buf, 1, size, fp); |
if (!buf) |
55 |
fclose (fp); |
BUG (0); |
56 |
SetDlgItemText (dlg, IDC_TEXT_INPUT, buf); |
memset (buf, 0, size+1); |
57 |
} |
fp = fopen (file, "rb"); |
58 |
free_if_alloc (buf); |
if (fp) { |
59 |
} /* load_file_contents */ |
fread (buf, 1, size, fp); |
60 |
|
fclose (fp); |
61 |
|
SetDlgItemText (dlg, IDC_TEXT_INPUT, buf); |
62 |
BOOL CALLBACK |
} |
63 |
text_input_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
free_if_alloc (buf); |
64 |
{ |
} /* load_file_contents */ |
65 |
static text_input_s *ctx; |
|
66 |
char *p; |
|
67 |
size_t n; |
BOOL CALLBACK |
68 |
|
text_input_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
69 |
switch (msg) { |
{ |
70 |
case WM_INITDIALOG: |
static text_input_s *ctx; |
71 |
ctx = (text_input_s *)lparam; |
char *p; |
72 |
if (ctx == NULL) |
size_t n; |
73 |
dlg_fatal_error (dlg, "Could not get dialog param."); |
|
74 |
#ifndef LANG_DE |
switch (msg) { |
75 |
SetWindowText (dlg, _("Text Input")); |
case WM_INITDIALOG: |
76 |
#endif |
ctx = (text_input_s *)lparam; |
77 |
switch (ctx->type) { |
if (ctx == NULL) |
78 |
case 0: |
dlg_fatal_error (dlg, "Could not get dialog param."); |
79 |
SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed")); |
#ifndef LANG_DE |
80 |
break; |
SetWindowText (dlg, _("Text Input")); |
81 |
} |
#endif |
82 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
switch (ctx->type) { |
83 |
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
case 0: |
84 |
SetForegroundWindow (dlg); |
SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed")); |
85 |
return TRUE; |
break; |
86 |
|
} |
87 |
case WM_COMMAND: |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
88 |
switch( LOWORD(wparam) ) { |
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
89 |
case IDC_TEXT_FILE: |
SetForegroundWindow (dlg); |
90 |
const char *file; |
return TRUE; |
91 |
|
|
92 |
file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL ); |
case WM_COMMAND: |
93 |
if( file ) |
switch( LOWORD(wparam) ) { |
94 |
load_file_contents( dlg, file ); |
case IDC_TEXT_FILE: |
95 |
break; |
const char *file; |
96 |
|
|
97 |
case IDOK: |
file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL ); |
98 |
p = new char[100*1024+1]; |
if( file ) |
99 |
if (!p) |
load_file_contents( dlg, file ); |
100 |
BUG (0); |
break; |
101 |
n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024); |
|
102 |
if (n > 0) { |
case IDOK: |
103 |
ctx->length = n; |
p = new char[100*1024+1]; |
104 |
ctx->data = new char[n+1]; |
if (!p) |
105 |
if (!ctx->data) |
BUG (0); |
106 |
BUG (0); |
n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024); |
107 |
memset (ctx->data, 0, n+1); |
if (n > 0) { |
108 |
strcpy (ctx->data, p); |
ctx->length = n; |
109 |
} |
ctx->data = new char[n+1]; |
110 |
else { |
if (!ctx->data) |
111 |
ctx->length = 0; |
BUG (0); |
112 |
ctx->data = NULL; |
memset (ctx->data, 0, n+1); |
113 |
} |
strcpy (ctx->data, p); |
114 |
free_if_alloc (p); |
} |
115 |
EndDialog (dlg, TRUE); |
else { |
116 |
return TRUE; |
ctx->length = 0; |
117 |
|
ctx->data = NULL; |
118 |
case IDCANCEL: |
} |
119 |
ctx->length = 0; |
free_if_alloc (p); |
120 |
ctx->data = NULL; |
EndDialog (dlg, TRUE); |
121 |
EndDialog (dlg, FALSE); |
return TRUE; |
122 |
return FALSE; |
|
123 |
} |
case IDCANCEL: |
124 |
break; |
ctx->length = 0; |
125 |
} |
ctx->data = NULL; |
126 |
|
EndDialog (dlg, FALSE); |
127 |
return FALSE; |
return FALSE; |
128 |
|
} |
129 |
|
break; |
130 |
|
} |
131 |
|
|
132 |
|
return FALSE; |
133 |
} /* text_input_dlg_proc */ |
} /* text_input_dlg_proc */ |