/[winpt]/trunk/Src/wptTextInputDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptTextInputDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (hide annotations)
Mon Oct 31 21:14:11 2005 UTC (19 years, 4 months ago) by werner
File size: 3555 byte(s)
More changes.  Compiles again but there are at least gettext issues with
w32-gettext.c.  I can't get a gpg-error build with ENABLE_NLS.

1 werner 36 /* wptTextInputDlg.cpp - Dialog for getting text
2     * Copyright (C) 2001-2005 Timo Schulz
3     *
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     } /* load_file_contents */
64    
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     char *p;
71     size_t n;
72    
73     switch (msg) {
74     case WM_INITDIALOG:
75     ctx = (text_input_s *)lparam;
76     if (ctx == NULL)
77     dlg_fatal_error (dlg, "Could not get dialog param.");
78     #ifndef LANG_DE
79     SetWindowText (dlg, _("Text Input"));
80     #endif
81     switch (ctx->type) {
82     case 0:
83     SetDlgItemText (dlg, IDC_TEXT_INFO, _("Enter the text that was signed"));
84     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     switch( LOWORD(wparam) ) {
93     case IDC_TEXT_FILE:
94     const char *file;
95    
96     file = get_filename_dlg( dlg, FILE_OPEN, _("Text Input from File"), NULL, NULL );
97     if( file )
98     load_file_contents( dlg, file );
99     break;
100    
101     case IDOK:
102     p = new char[100*1024+1];
103     if (!p)
104     BUG (0);
105     n = GetDlgItemText (dlg, IDC_TEXT_INPUT, p, 100*1024);
106     if (n > 0) {
107     ctx->length = n;
108     ctx->data = new char[n+1];
109     if (!ctx->data)
110     BUG (0);
111     memset (ctx->data, 0, n+1);
112     strcpy (ctx->data, p);
113     }
114     else {
115     ctx->length = 0;
116     ctx->data = NULL;
117     }
118     free_if_alloc (p);
119     EndDialog (dlg, TRUE);
120     return TRUE;
121    
122     case IDCANCEL:
123     ctx->length = 0;
124     ctx->data = NULL;
125     EndDialog (dlg, FALSE);
126     return FALSE;
127     }
128     break;
129     }
130    
131     return FALSE;
132 twoaday 2 } /* text_input_dlg_proc */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26