1 |
/* wptTextInputDlg.cpp - Dialog for getting text |
/* wptTextInputDlg.cpp - Dialog for getting text |
2 |
* Copyright (C) 2001-2004 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 |
|
#ifdef HAVE_CONFIG_H |
21 |
#include <windows.h> |
#include <config.h> |
22 |
|
#endif |
23 |
#include "../resource.h" |
|
24 |
#include "wptTypes.h" |
#include <windows.h> |
25 |
#include "wptGPG.h" |
#include <windows.h> |
26 |
#include "wptCommonCtl.h" |
|
27 |
#include "wptContext.h" |
#include "../resource.h" |
28 |
#include "wptDlgs.h" |
#include "wptTypes.h" |
29 |
#include "wptW32API.h" |
#include "wptGPG.h" |
30 |
#include "wptNLS.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptErrors.h" |
#include "wptContext.h" |
32 |
|
#include "wptDlgs.h" |
33 |
#define MAX_FILESIZE 15000000 |
#include "wptW32API.h" |
34 |
|
#include "wptNLS.h" |
35 |
|
#include "wptErrors.h" |
36 |
void |
|
37 |
load_file_contents (HWND dlg, const char * file) |
#define MAX_FILESIZE 8388608 /* 8MB */ |
38 |
{ |
|
39 |
size_t size = 0; |
void |
40 |
char *buf = NULL; |
load_file_contents (HWND dlg, const char * file) |
41 |
FILE *fp; |
{ |
42 |
|
size_t size = 0; |
43 |
size = get_file_size (file); |
char *buf = NULL; |
44 |
if (!size) |
FILE *fp; |
45 |
return; |
|
46 |
if (size > MAX_FILESIZE) |
size = get_file_size (file); |
47 |
{ |
if (!size) |
48 |
msg_box (dlg, _("Data is too large for copying."), _("Info"), MB_ERR); |
return; |
49 |
return; |
if (size > MAX_FILESIZE) { |
50 |
} |
msg_box (dlg, _("Data is too large for copying."), _("Info"), MB_ERR); |
51 |
buf = new char[size+1]; |
return; |
52 |
if (!buf) |
} |
53 |
BUG (0); |
buf = new char[size+1]; |
54 |
fp = fopen (file, "rb"); |
if (!buf) |
55 |
if (fp) |
BUG (0); |
56 |
{ |
memset (buf, 0, size+1); |
57 |
fread (buf, 1, size, fp); |
fp = fopen (file, "rb"); |
58 |
fclose (fp); |
if (fp) { |
59 |
SetDlgItemText (dlg, IDC_TEXT_INPUT, buf); |
fread (buf, 1, size, fp); |
60 |
} |
fclose (fp); |
61 |
free_if_alloc (buf); |
SetDlgItemText (dlg, IDC_TEXT_INPUT, buf); |
62 |
} /* load_file_contents */ |
} |
63 |
|
free_if_alloc (buf); |
64 |
|
} /* load_file_contents */ |
65 |
BOOL CALLBACK |
|
66 |
text_input_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
|
67 |
{ |
BOOL CALLBACK |
68 |
static text_input_s *ctx; |
text_input_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
69 |
char *p; |
{ |
70 |
size_t n; |
static text_input_s *ctx; |
71 |
|
char *p; |
72 |
switch( msg ) { |
size_t n; |
73 |
case WM_INITDIALOG: |
|
74 |
ctx = (text_input_s *)lparam; |
switch (msg) { |
75 |
if( ctx == NULL ) |
case WM_INITDIALOG: |
76 |
dlg_fatal_error(dlg, "Could not get dialog param."); |
ctx = (text_input_s *)lparam; |
77 |
#ifndef LANG_DE |
if (ctx == NULL) |
78 |
SetWindowText( dlg, _("Text Input") ); |
dlg_fatal_error (dlg, "Could not get dialog param."); |
79 |
#endif |
#ifndef LANG_DE |
80 |
switch ( ctx->type ) { |
SetWindowText (dlg, _("Text Input")); |
81 |
case 0: |
#endif |
82 |
SetDlgItemText( dlg, IDC_TEXT_INFO, _("Enter the text that was signed") ); |
switch (ctx->type) { |
83 |
break; |
case 0: |
84 |
} |
SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed")); |
85 |
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
break; |
86 |
SetForegroundWindow( dlg ); |
} |
87 |
return TRUE; |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
88 |
|
SetDlgItemText (dlg, IDC_TEXT_FILE, _("&Load")); |
89 |
case WM_COMMAND: |
SetForegroundWindow (dlg); |
90 |
switch( LOWORD(wparam) ) { |
return TRUE; |
91 |
case IDC_TEXT_FILE: |
|
92 |
const char *file; |
case WM_COMMAND: |
93 |
|
switch( LOWORD(wparam) ) { |
94 |
file = get_filename_dlg( dlg, 0, _("Text Input from File"), NULL, NULL ); |
case IDC_TEXT_FILE: |
95 |
if( file ) |
const char *file; |
96 |
load_file_contents( dlg, file ); |
|
97 |
break; |
file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL ); |
98 |
|
if( file ) |
99 |
case IDOK: |
load_file_contents( dlg, file ); |
100 |
p = new char[100*1024+1]; |
break; |
101 |
if( !p ) |
|
102 |
BUG( NULL ); |
case IDOK: |
103 |
n = GetDlgItemText(dlg, IDC_TEXT_INPUT, p, 100*1024 ); |
p = new char[100*1024+1]; |
104 |
if( n ) { |
if (!p) |
105 |
ctx->length = n; |
BUG (0); |
106 |
ctx->data = new char[n+1]; |
n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024); |
107 |
if( !ctx->data ) |
if (n > 0) { |
108 |
BUG( NULL ); |
ctx->length = n; |
109 |
strcpy( ctx->data, p ); |
ctx->data = new char[n+1]; |
110 |
} |
if (!ctx->data) |
111 |
else { |
BUG (0); |
112 |
ctx->length = 0; |
memset (ctx->data, 0, n+1); |
113 |
ctx->data = NULL; |
strcpy (ctx->data, p); |
114 |
} |
} |
115 |
free_if_alloc( p ); |
else { |
116 |
EndDialog( dlg, TRUE ); |
ctx->length = 0; |
117 |
return TRUE; |
ctx->data = NULL; |
118 |
|
} |
119 |
case IDCANCEL: |
free_if_alloc (p); |
120 |
ctx->length = 0; |
EndDialog (dlg, TRUE); |
121 |
ctx->data = NULL; |
return TRUE; |
122 |
EndDialog( dlg, FALSE ); |
|
123 |
return FALSE; |
case IDCANCEL: |
124 |
} |
ctx->length = 0; |
125 |
break; |
ctx->data = NULL; |
126 |
} |
EndDialog (dlg, FALSE); |
127 |
|
return FALSE; |
128 |
return FALSE; |
} |
129 |
|
break; |
130 |
|
} |
131 |
|
|
132 |
|
return FALSE; |
133 |
} /* text_input_dlg_proc */ |
} /* text_input_dlg_proc */ |