25 |
#include <ctype.h> |
#include <ctype.h> |
26 |
|
|
27 |
#include "resource.h" |
#include "resource.h" |
|
|
|
28 |
#include "wptTypes.h" |
#include "wptTypes.h" |
29 |
#include "wptW32API.h" |
#include "wptW32API.h" |
30 |
#include "wptVersion.h" |
#include "wptVersion.h" |
31 |
#include "wptGPG.h" |
#include "wptGPG.h" |
32 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
33 |
#include "wptContext.h" |
#include "wptContext.h" |
34 |
|
#include "wptRegistry.h" |
35 |
|
|
36 |
|
|
37 |
/* check if the given buf contains a valid URL. */ |
/* check if the given buf contains a valid URL. */ |
41 |
size_t i; |
size_t i; |
42 |
const char *allowed = "-./#_:"; |
const char *allowed = "-./#_:"; |
43 |
|
|
|
if (strncmp (buf, "http://", 7)) |
|
|
return -1; |
|
44 |
if (!strchr (buf, ':')) |
if (!strchr (buf, ':')) |
45 |
return -1; |
return -1; |
46 |
if (!strstr (buf, "//")) |
if (!strstr (buf, "//")) |
156 |
return m_strdup (ctx.url); |
return m_strdup (ctx.url); |
157 |
} |
} |
158 |
|
|
|
#if 0 |
|
|
struct infodlg_s { |
|
|
const char *title; |
|
|
const char *button_1; |
|
|
const char *button_2; |
|
|
const char *text; |
|
|
HICON ico; |
|
|
int retval; |
|
|
}; |
|
159 |
|
|
160 |
/* Dialog box procedure for the info dialog. */ |
/* Initialize the language list based on the .mo files |
161 |
|
found in the dirctory @modpath. */ |
162 |
|
static int |
163 |
|
nls_load_langlist (HWND dlg, const char *modpath) |
164 |
|
{ |
165 |
|
WIN32_FIND_DATA fnd; |
166 |
|
HWND cb; |
167 |
|
HANDLE hd; |
168 |
|
char *pattern = NULL; |
169 |
|
int i; |
170 |
|
|
171 |
|
cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST); |
172 |
|
combox_add_string (cb, lang_list[0].name); |
173 |
|
SendMessage (cb, CB_SETCURSEL, 0, 0); |
174 |
|
|
175 |
|
memset (&fnd, 0, sizeof (fnd)); |
176 |
|
pattern = make_filename (modpath, "*.mo", NULL); |
177 |
|
hd = FindFirstFile (pattern, &fnd); |
178 |
|
if (hd == INVALID_HANDLE_VALUE) { |
179 |
|
free_if_alloc (pattern); |
180 |
|
return -1; |
181 |
|
} |
182 |
|
|
183 |
|
do { |
184 |
|
for (i=0; lang_list[i].id != NULL; i++) { |
185 |
|
if (!strnicmp (fnd.cFileName, lang_list[i].id, 2)) |
186 |
|
combox_add_string (cb, lang_list[i].name); |
187 |
|
} |
188 |
|
memset (&fnd, 0, sizeof (fnd)); |
189 |
|
} while (FindNextFile (hd, &fnd) != FALSE); |
190 |
|
FindClose (hd); |
191 |
|
free_if_alloc (pattern); |
192 |
|
return 0; |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
/* Set the default language for the program. |
197 |
|
The $lang.mo file is copied either to the selected |
198 |
|
folder or the directory specified by @modpath. |
199 |
|
The output name of the file is winpt.mo (example: de.mo -> winpt.mo). */ |
200 |
|
static int |
201 |
|
nls_set_language (HWND dlg, const char *modpath) |
202 |
|
{ |
203 |
|
HWND cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST); |
204 |
|
int pos = SendMessage (cb, CB_GETCURSEL, 0, 0); |
205 |
|
const char *folder; |
206 |
|
char *src, *dst; |
207 |
|
|
208 |
|
/* default langauge is English. */ |
209 |
|
if (pos == 0 || pos == CB_ERR) |
210 |
|
return 0; |
211 |
|
|
212 |
|
folder = get_folder_dlg (dlg, _("Choose Locale Directory"), modpath); |
213 |
|
if (!folder) |
214 |
|
return 0; |
215 |
|
|
216 |
|
src = make_filename (modpath, lang_list[pos].id, "mo"); |
217 |
|
dst = make_filename (folder, "winpt", "mo"); |
218 |
|
|
219 |
|
if (!CopyFile (src, dst, FALSE)) { |
220 |
|
msg_box (dlg, _("Could not create winpt.mo file"), |
221 |
|
_("WinPT Error"), MB_ERR); |
222 |
|
pos = -1; |
223 |
|
} |
224 |
|
else |
225 |
|
set_reg_entry_mo (folder); |
226 |
|
free_if_alloc (src); |
227 |
|
free_if_alloc (dst); |
228 |
|
return pos; |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
static BOOL CALLBACK |
static BOOL CALLBACK |
233 |
infodlg_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
nls_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
234 |
{ |
{ |
235 |
static struct infodlg_s *ctx; |
static char modpath[MAX_PATH+1]; |
236 |
|
int langid = 0, n; |
237 |
|
|
238 |
switch (msg) { |
switch (msg) { |
239 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
240 |
ctx = (struct infodlg_s *)lparam; |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
241 |
if (!ctx) |
while (n-- > 0) { |
242 |
EndDialog (dlg, FALSE); |
if (modpath[n] == '\\') { |
243 |
if (ctx->title) |
modpath[n] = 0; |
244 |
SetWindowText (dlg, ctx->title); |
break; |
245 |
if (ctx->text) |
} |
246 |
SetDlgItemText (dlg, IDC_INFODLG_TEXT, ctx->text); |
} |
|
if (ctx->button_1) |
|
|
SetDlgItemText (dlg, IDOK, ctx->button_1); |
|
|
if (ctx->button_2) |
|
|
SetDlgItemText (dlg, IDCANCEL, ctx->button_2); |
|
|
if (ctx->ico != NULL) { |
|
|
SendMessage (GetDlgItem (dlg, IDC_INFODLG_ICO), STM_SETICON, |
|
|
(WPARAM)(HICON)ctx->ico, 0); |
|
247 |
} |
} |
248 |
|
n = nls_load_langlist (dlg, modpath); |
249 |
|
if (n == -1) |
250 |
|
EndDialog (dlg, -1); |
251 |
|
SetWindowText (dlg, _("Native Language Support")); |
252 |
|
SetDlgItemText (dlg, IDC_LANGUAGE_INFO, _("Please select a language")); |
253 |
|
SetDlgItemText (dlg, IDOK, _("&OK")); |
254 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
255 |
|
center_window (dlg, NULL); |
256 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
257 |
return TRUE; |
break; |
258 |
|
|
259 |
case WM_COMMAND: |
case WM_COMMAND: |
260 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
261 |
case IDOK: |
case IDOK: |
262 |
ctx->retval = IDOK; |
langid = nls_set_language (dlg, modpath); |
263 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, langid); |
264 |
break; |
break; |
265 |
|
|
266 |
case IDCANCEL: |
case IDCANCEL: |
267 |
ctx->retval = IDCANCEL; |
EndDialog (dlg, -1); |
|
EndDialog (dlg, FALSE); |
|
268 |
break; |
break; |
269 |
} |
} |
270 |
break; |
break; |
271 |
} |
} |
272 |
|
|
273 |
return FALSE; |
return FALSE; |
274 |
} |
} |
275 |
|
|
276 |
|
|
277 |
int |
int |
278 |
InfoBox (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type) |
select_language (void) |
279 |
{ |
{ |
280 |
struct infodlg_s inf; |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_LANGUAGE, GetDesktopWindow (), |
281 |
|
nls_dlg_proc, 0); |
282 |
memset (&inf, 0, sizeof (inf)); |
return 0; |
|
inf.text = text; |
|
|
inf.title = title; |
|
|
if (type & MB_YESNO) { |
|
|
inf.button_1 = _("Yes"); |
|
|
inf.button_2 = _("No"); |
|
|
} |
|
|
else { |
|
|
inf.button_1 = _("OK"); |
|
|
inf.button_2 = _("Cancel"); |
|
|
} |
|
|
if (type & MB_ICONERROR) |
|
|
inf.ico = LoadIcon (NULL, IDI_ERROR); |
|
|
else if (type & MB_ICONWARNING) |
|
|
inf.ico = LoadIcon (NULL, IDI_EXCLAMATION); |
|
|
else if (type & MB_ICONINFORMATION) |
|
|
inf.ico = LoadIcon (NULL, IDI_INFORMATION); |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_INFODLG, hwnd, |
|
|
infodlg_dlg_proc, (LPARAM)&inf); |
|
|
return inf.retval; |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
InfoBoxEx (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type, ...) |
|
|
{ |
|
|
va_list arg_ptr; |
|
|
char buf[2048]; |
|
|
int id; |
|
|
|
|
|
va_start (arg_ptr, type); |
|
|
_vsnprintf (buf, sizeof (buf)-1, text, arg_ptr); |
|
|
id = InfoBox (hwnd, buf, title, type); |
|
|
va_end (arg_ptr); |
|
|
return id; |
|
283 |
} |
} |
|
#endif |
|
284 |
|
|