NetSurf
prefs.c
Go to the documentation of this file.
1/*
2 * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf 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; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * win32 preferences dialog implementation.
22 */
23
24#include "utils/config.h"
25
26#include <windows.h>
27#include <commctrl.h>
28
29#include "utils/nsoption.h"
30#include "utils/log.h"
31#include "utils/messages.h"
32#include "utils/file.h"
33
34#include "windows/gui.h"
35#include "windows/prefs.h"
36#include "windows/resourceid.h"
37#include "windows/windbg.h"
38
39/** Preferences dialog width */
40#define NSWS_PREFS_WINDOW_WIDTH 600
41/** Preferences dialog height */
42#define NSWS_PREFS_WINDOW_HEIGHT 400
43
44
45/**
46 * Prepare preferences dialog font tab
47 *
48 * \param fontfamily The font family
49 * \param parent The parent window win32 handle
50 * \return The selected font or NULL on error
51 */
52static CHOOSEFONT *nsws_prefs_font_prepare(int fontfamily, HWND parent)
53{
54 CHOOSEFONT *cf = malloc(sizeof(CHOOSEFONT));
55 if (cf == NULL) {
56 win32_warning(messages_get("NoMemory"),0);
57 return NULL;
58 }
59 LOGFONT *lf = malloc(sizeof(LOGFONT));
60 if (lf == NULL) {
61 win32_warning(messages_get("NoMemory"),0);
62 free(cf);
63 return NULL;
64 }
65 switch(fontfamily) {
66 case FF_ROMAN:
67 snprintf(lf->lfFaceName, LF_FACESIZE, "%s",
68 nsoption_charp(font_serif));
69 break;
70 case FF_MODERN:
71 snprintf(lf->lfFaceName, LF_FACESIZE, "%s",
72 nsoption_charp(font_mono));
73 break;
74 case FF_SCRIPT:
75 snprintf(lf->lfFaceName, LF_FACESIZE, "%s",
76 nsoption_charp(font_cursive));
77 break;
78 case FF_DECORATIVE:
79 snprintf(lf->lfFaceName, LF_FACESIZE, "%s",
80 nsoption_charp(font_fantasy));
81 break;
82 case FF_SWISS:
83 default:
84 snprintf(lf->lfFaceName, LF_FACESIZE, "%s",
85 nsoption_charp(font_sans));
86 break;
87 }
88
89 cf->lStructSize = sizeof(CHOOSEFONT);
90 cf->hwndOwner = parent;
91 cf->lpLogFont = lf;
92 cf->Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE;
93 cf->nSizeMin = 16;
94 cf->nSizeMax = 24;
95
96 return cf;
97}
98
99
100/**
101 * Update value in spinner control when it is changed
102 *
103 * \param sub The window handle of the spinner control
104 * \param change The amount the control changed by
105 * \param minval The minimum allowed value of the control
106 * \param maxval The maximum allowed value of the control
107 */
108static void change_spinner(HWND sub, double change, double minval, double maxval)
109{
110 char *temp, number[6];
111 int len;
112 double value = 0;
113
114 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
115 temp = malloc(len + 1);
116
117 if (temp == NULL) {
118 return;
119 }
120
121 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1), (LPARAM) temp);
122
123 value = strtod(temp, NULL) - change;
124
125 free(temp);
126 value = max(value, minval);
127 value = min(value, maxval);
128
129 if ((change == 1.0) || (change == -1.0)) {
130 snprintf(number, 6, "%.0f", value);
131 } else {
132 snprintf(number, 6, "%.1f", value);
133 }
134
135 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
136}
137
138
139/**
140 * Handle messages to the appearance preference dialog
141 *
142 * \param hwnd The win32 handle of the appearance dialog
143 * \param msg The message code
144 * \param wparam The message w parameter
145 * \param lParam The message l parameter
146 * \return result appropriate for message
147 */
148static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd,
149 UINT msg,
150 WPARAM wparam,
151 LPARAM lParam)
152{
153 int len;
154 char *temp, number[6];
155 HWND sub;
156
157 LOG_WIN_MSG(hwnd, msg, wparam, lParam);
158
159 switch (msg) {
160 case WM_INITDIALOG:
161 sub = GetDlgItem(hwnd, IDC_PREFS_FONTDEF);
162 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Sans serif");
163 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Serif");
164 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Monospace");
165 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Cursive");
166 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Fantasy");
167 SendMessage(sub, CB_SETCURSEL,
168 (WPARAM) (nsoption_int(font_default) - 1), 0);
169
170 if ((nsoption_charp(font_sans) != NULL) &&
171 (nsoption_charp(font_sans)[0] != '\0')) {
172 sub = GetDlgItem(hwnd, IDC_PREFS_SANS);
173 SendMessage(sub, WM_SETTEXT, 0,
174 (LPARAM)nsoption_charp(font_sans));
175 }
176 if ((nsoption_charp(font_serif) != NULL) &&
177 (nsoption_charp(font_serif)[0] != '\0')) {
178 sub = GetDlgItem(hwnd, IDC_PREFS_SERIF);
179 SendMessage(sub, WM_SETTEXT, 0,
180 (LPARAM)nsoption_charp(font_serif));
181 }
182 if ((nsoption_charp(font_mono) != NULL) &&
183 (nsoption_charp(font_mono)[0] != '\0')) {
184 sub = GetDlgItem(hwnd, IDC_PREFS_MONO);
185 SendMessage(sub, WM_SETTEXT, 0,
186 (LPARAM)nsoption_charp(font_mono));
187 }
188 if ((nsoption_charp(font_cursive) != NULL) &&
189 (nsoption_charp(font_cursive)[0] != '\0')) {
190 sub = GetDlgItem(hwnd, IDC_PREFS_CURSIVE);
191 SendMessage(sub, WM_SETTEXT, 0,
192 (LPARAM)nsoption_charp(font_cursive));
193 }
194 if ((nsoption_charp(font_fantasy) != NULL) &&
195 (nsoption_charp(font_fantasy)[0] != '\0')) {
196 sub = GetDlgItem(hwnd, IDC_PREFS_FANTASY);
197 SendMessage(sub, WM_SETTEXT, 0,
198 (LPARAM)nsoption_charp(font_fantasy));
199 }
200 if (nsoption_int(font_min_size) != 0) {
201 sub = GetDlgItem(hwnd, IDC_PREFS_FONT_MINSIZE);
202 snprintf(number, 6, "%.1f", nsoption_int(font_min_size) / 10.0);
203 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
204 }
205 if (nsoption_int(font_size) != 0) {
206 sub = GetDlgItem(hwnd, IDC_PREFS_FONT_SIZE);
207 snprintf(number, 6, "%.1f", nsoption_int(font_size) / 10.0);
208 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
209 }
210 if (nsoption_int(max_fetchers) != 0) {
211 sub = GetDlgItem(hwnd, IDC_PREFS_FETCHERS);
212 snprintf(number, 6, "%d", nsoption_int(max_fetchers));
213 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
214 }
215 if (nsoption_int(max_fetchers_per_host) != 0) {
216 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HOST);
217 snprintf(number, 6, "%d",
218 nsoption_int(max_fetchers_per_host));
219 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
220 }
221 if (nsoption_int(max_cached_fetch_handles) != 0) {
222 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HANDLES);
223 snprintf(number, 6, "%d",
224 nsoption_int(max_cached_fetch_handles));
225 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
226 }
227
228
229 /* animation */
230 sub = GetDlgItem(hwnd, IDC_PREFS_NOANIMATION);
231 SendMessage(sub, BM_SETCHECK, (WPARAM)((nsoption_bool(animate_images))
232 ? BST_UNCHECKED : BST_CHECKED), 0);
233 break;
234
235 case WM_NOTIFY:
236 switch (((NMHDR FAR *)lParam)->code) {
237 case PSN_APPLY:
238 sub = GetDlgItem(hwnd, IDC_PREFS_FONT_SIZE);
239 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
240 temp = malloc(len + 1);
241 if (temp != NULL) {
242 SendMessage(sub, WM_GETTEXT, (WPARAM)
243 (len + 1), (LPARAM) temp);
244 nsoption_int(font_size) = (int)
245 (10 * strtod(temp, NULL));
246 free(temp);
247 }
248
249 sub = GetDlgItem(hwnd, IDC_PREFS_FONT_MINSIZE);
250 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
251 temp = malloc(len + 1);
252 if (temp != NULL) {
253 SendMessage(sub, WM_GETTEXT, (WPARAM)
254 (len + 1), (LPARAM) temp);
255 nsoption_set_int(font_min_size,
256 (int)(10 * strtod(temp, NULL)));
257 free(temp);
258 }
259
260 /* animation */
261 nsoption_set_bool(animate_images,
262 (IsDlgButtonChecked(hwnd, IDC_PREFS_NOANIMATION) == BST_CHECKED) ? true : false);
263
264 break;
265
266 case UDN_DELTAPOS: {
267 NMUPDOWN *ud = (NMUPDOWN *)lParam;
268 switch(((NMHDR *)lParam)->idFrom) {
270 change_spinner(GetDlgItem(hwnd, IDC_PREFS_FONT_SIZE), 0.1 * ud->iDelta, 1.0, 50.0);
271 return TRUE;
272
274 change_spinner(GetDlgItem(hwnd, IDC_PREFS_FONT_MINSIZE), 0.1 * ud->iDelta, 1.0, 50.0);
275 return TRUE;
276 }
277 }
278 break;
279 }
280 break;
281
282
283 case WM_COMMAND:
284 NSLOG(netsurf, INFO, "WM_COMMAND Identifier 0x%x",
285 LOWORD(wparam));
286
287 switch(LOWORD(wparam)) {
289 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYTYPE);
290 nsoption_set_int(http_proxy_auth,
291 SendMessage(sub, CB_GETCURSEL, 0, 0) - 1);
292 nsoption_set_bool(http_proxy,
293 (nsoption_int(http_proxy_auth) != -1));
294 nsoption_set_int(http_proxy_auth,
295 nsoption_int(http_proxy_auth) +
296 (nsoption_bool(http_proxy)) ? 0 : 1);
297 break;
298
299 case IDC_PREFS_SANS: {
300 CHOOSEFONT *cf = nsws_prefs_font_prepare(FF_SWISS, hwnd);
301 if (cf == NULL) {
302 break;
303 }
304
305 if (ChooseFont(cf) == TRUE) {
306 nsoption_set_charp(font_sans,
307 strdup(cf->lpLogFont->lfFaceName));
308 }
309
310 free(cf->lpLogFont);
311 free(cf);
312 if ((nsoption_charp(font_sans) != NULL) &&
313 (nsoption_charp(font_sans)[0] != '\0')) {
314 sub = GetDlgItem(hwnd, IDC_PREFS_SANS);
315 SendMessage(sub, WM_SETTEXT, 0,
316 (LPARAM)nsoption_charp(font_sans));
317 }
318 break;
319 }
320
321 case IDC_PREFS_SERIF: {
322 CHOOSEFONT *cf = nsws_prefs_font_prepare(FF_ROMAN, hwnd);
323 if (cf == NULL) {
324 break;
325 }
326
327 if (ChooseFont(cf) == TRUE) {
328 nsoption_set_charp(font_serif,
329 strdup(cf->lpLogFont->lfFaceName));
330 }
331
332 free(cf->lpLogFont);
333 free(cf);
334 if ((nsoption_charp(font_serif) != NULL) &&
335 (nsoption_charp(font_serif)[0] != '\0')) {
336 sub = GetDlgItem(hwnd, IDC_PREFS_SERIF);
337 SendMessage(sub, WM_SETTEXT, 0,
338 (LPARAM)nsoption_charp(font_serif));
339 }
340 break;
341 }
342
343 case IDC_PREFS_MONO: {
344 CHOOSEFONT *cf = nsws_prefs_font_prepare(FF_MODERN, hwnd);
345 if (cf == NULL) {
346 break;
347 }
348
349 if (ChooseFont(cf) == TRUE) {
350 nsoption_set_charp(font_mono,
351 strdup(cf->lpLogFont->lfFaceName));
352 }
353
354 free(cf->lpLogFont);
355 free(cf);
356
357 if ((nsoption_charp(font_mono) != NULL) &&
358 (nsoption_charp(font_mono)[0] != '\0')) {
359 sub = GetDlgItem(hwnd, IDC_PREFS_MONO);
360 SendMessage(sub, WM_SETTEXT, 0,
361 (LPARAM)nsoption_charp(font_mono));
362 }
363 break;
364 }
365
366 case IDC_PREFS_CURSIVE: {
367 CHOOSEFONT *cf = nsws_prefs_font_prepare(FF_SCRIPT, hwnd);
368 if (cf == NULL) {
369 break;
370 }
371
372 if (ChooseFont(cf) == TRUE) {
373 nsoption_set_charp(font_cursive,
374 strdup(cf->lpLogFont->lfFaceName));
375 }
376 free(cf->lpLogFont);
377 free(cf);
378 if ((nsoption_charp(font_cursive) != NULL) &&
379 (nsoption_charp(font_cursive)[0] != '\0')) {
380 sub = GetDlgItem(hwnd, IDC_PREFS_CURSIVE);
381 SendMessage(sub, WM_SETTEXT, 0,
382 (LPARAM)nsoption_charp(font_cursive));
383 }
384 break;
385 }
386
387 case IDC_PREFS_FANTASY: {
388 CHOOSEFONT *cf = nsws_prefs_font_prepare(FF_DECORATIVE, hwnd);
389 if (cf == NULL) {
390 break;
391 }
392
393 if (ChooseFont(cf) == TRUE) {
394 nsoption_set_charp(font_fantasy,
395 strdup(cf->lpLogFont->lfFaceName));
396 }
397 free(cf->lpLogFont);
398 free(cf);
399 if ((nsoption_charp(font_fantasy) != NULL) &&
400 (nsoption_charp(font_fantasy)[0] != '\0')) {
401 sub = GetDlgItem(hwnd, IDC_PREFS_FANTASY);
402 SendMessage(sub, WM_SETTEXT, 0,
403 (LPARAM)nsoption_charp(font_fantasy));
404 }
405 break;
406 }
407
409 sub = GetDlgItem(hwnd, IDC_PREFS_FONTDEF);
410 nsoption_set_int(font_default,
411 SendMessage(sub, CB_GETCURSEL, 0, 0) + 1);
412 break;
413
414 }
415 break;
416
417 }
418 return FALSE;
419}
420
421
422/**
423 * Handle messages to the connections preference dialog
424 *
425 * \param hwnd The win32 handle of the connections dialog
426 * \param msg The message code
427 * \param wparam The message w parameter
428 * \param lParam The message l parameter
429 * \return result appropriate for message
430 */
431static BOOL CALLBACK options_connections_dialog_handler(HWND hwnd,
432 UINT msg,
433 WPARAM wparam,
434 LPARAM lParam)
435{
436 int len;
437 char *temp, number[6];
438 HWND sub;
439
440 LOG_WIN_MSG(hwnd, msg, wparam, lParam);
441
442 switch (msg) {
443 case WM_INITDIALOG:
444 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYTYPE);
445 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"None");
446 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Simple");
447 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"Basic Auth");
448 SendMessage(sub, CB_ADDSTRING, 0, (LPARAM)"NTLM Auth");
449 if (nsoption_bool(http_proxy)) {
450 SendMessage(sub, CB_SETCURSEL, (WPARAM)
451 (nsoption_int(http_proxy_auth) + 1), 0);
452 } else {
453 SendMessage(sub, CB_SETCURSEL, 0, 0);
454 }
455
456 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYHOST);
457 if ((nsoption_charp(http_proxy_host) != NULL) &&
458 (nsoption_charp(http_proxy_host)[0] != '\0'))
459 SendMessage(sub, WM_SETTEXT, 0,
460 (LPARAM)nsoption_charp(http_proxy_host));
461
462 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYPORT);
463 if (nsoption_int(http_proxy_port) != 0) {
464 snprintf(number, 6, "%d", nsoption_int(http_proxy_port));
465 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
466 }
467
468 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYNAME);
469 if ((nsoption_charp(http_proxy_auth_user) != NULL) &&
470 (nsoption_charp(http_proxy_auth_user)[0] != '\0'))
471 SendMessage(sub, WM_SETTEXT, 0,
472 (LPARAM)nsoption_charp(http_proxy_auth_user));
473
474 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYPASS);
475 if ((nsoption_charp(http_proxy_auth_pass) != NULL) &&
476 (nsoption_charp(http_proxy_auth_pass)[0] != '\0'))
477 SendMessage(sub, WM_SETTEXT, 0,
478 (LPARAM)nsoption_charp(http_proxy_auth_pass));
479
480 sub = GetDlgItem(hwnd, IDC_PREFS_FETCHERS);
481 snprintf(number, 6, "%d", nsoption_int(max_fetchers));
482 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
483
484 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HOST);
485 snprintf(number, 6, "%d", nsoption_int(max_fetchers_per_host));
486 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
487
488 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HANDLES);
489 snprintf(number, 6, "%d", nsoption_int(max_cached_fetch_handles));
490 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number);
491
492 break;
493
494 case WM_NOTIFY:
495 switch (((NMHDR FAR *)lParam)->code) {
496 case PSN_APPLY:
497 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYHOST);
498 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
499 temp = malloc(len + 1);
500 if (temp != NULL) {
501 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
502 (LPARAM)temp);
503 nsoption_set_charp(http_proxy_host, strdup(temp));
504 free(temp);
505 }
506
507 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYPORT);
508 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
509 temp = malloc(len + 1);
510 if (temp != NULL) {
511 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
512 (LPARAM)temp);
513 nsoption_set_int(http_proxy_port, atoi(temp));
514 free(temp);
515 }
516
517 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYNAME);
518 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
519 temp = malloc(len + 1);
520 if (temp != NULL) {
521 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
522 (LPARAM)temp);
523 nsoption_set_charp(http_proxy_auth_user, strdup(temp));
524 free(temp);
525 }
526
527 sub = GetDlgItem(hwnd, IDC_PREFS_PROXYPASS);
528 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
529 temp = malloc(len + 1);
530 if (temp != NULL) {
531 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
532 (LPARAM)temp);
533 nsoption_set_charp(http_proxy_auth_pass, strdup(temp));
534 free(temp);
535 }
536
537 /* fetchers */
538 sub = GetDlgItem(hwnd, IDC_PREFS_FETCHERS);
539 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
540 temp = malloc(len + 1);
541 if (temp != NULL) {
542 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
543 (LPARAM)temp);
544 nsoption_set_int(max_fetchers, atoi(temp));
545 free(temp);
546 }
547
548 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HOST);
549 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
550 temp = malloc(len + 1);
551 if (temp != NULL) {
552 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
553 (LPARAM)temp);
554 nsoption_set_int(max_fetchers_per_host, atoi(temp));
555 free(temp);
556 }
557
558 sub = GetDlgItem(hwnd, IDC_PREFS_FETCH_HANDLES);
559 len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0);
560 temp = malloc(len + 1);
561 if (temp != NULL) {
562 SendMessage(sub, WM_GETTEXT, (WPARAM)(len + 1),
563 (LPARAM)temp);
564 nsoption_set_int(max_cached_fetch_handles, atoi(temp));
565 free(temp);
566 }
567 break;
568
569 case UDN_DELTAPOS: {
570 NMUPDOWN *ud = (NMUPDOWN *)lParam;
571 switch(((NMHDR *)lParam)->idFrom) {
573 change_spinner(GetDlgItem(hwnd, IDC_PREFS_FETCHERS), 1.0 * ud->iDelta, 1.0, 100.0);
574 return TRUE;
575
577 change_spinner(GetDlgItem(hwnd, IDC_PREFS_FETCH_HOST), 1.0 * ud->iDelta, 1.0, 100.0);
578 return TRUE;
579
581 change_spinner(GetDlgItem(hwnd, IDC_PREFS_FETCH_HANDLES), 1.0 * ud->iDelta, 1.0, 100.0);
582 return TRUE;
583
584 }
585 }
586 break;
587 }
588 }
589 return FALSE;
590}
591
592
593/**
594 * Handle messages to the general preference dialog
595 *
596 * \param hwnd The win32 handle of the general dialog
597 * \param msg The message code
598 * \param wparam The message w parameter
599 * \param lParam The message l parameter
600 * \return result appropriate for message
601 */
602static BOOL CALLBACK options_general_dialog_handler(HWND hwnd,
603 UINT msg,
604 WPARAM wparam,
605 LPARAM lParam)
606{
607 HWND sub;
608
609 LOG_WIN_MSG(hwnd, msg, wparam, lParam);
610
611 switch (msg) {
612 case WM_INITDIALOG:
613 /* homepage url */
614 sub = GetDlgItem(hwnd, IDC_PREFS_HOMEPAGE);
615 SendMessage(sub, WM_SETTEXT, 0, (LPARAM)nsoption_charp(homepage_url));
616
617 /* Display images */
618 sub = GetDlgItem(hwnd, IDC_PREFS_IMAGES);
619 SendMessage(sub, BM_SETCHECK,
620 (WPARAM) ((nsoption_bool(suppress_images)) ?
621 BST_CHECKED : BST_UNCHECKED), 0);
622
623 /* advert blocking */
624 sub = GetDlgItem(hwnd, IDC_PREFS_ADVERTS);
625 SendMessage(sub, BM_SETCHECK,
626 (WPARAM) ((nsoption_bool(block_advertisements)) ?
627 BST_CHECKED : BST_UNCHECKED), 0);
628
629 /* Referrer sending */
630 sub = GetDlgItem(hwnd, IDC_PREFS_REFERER);
631 SendMessage(sub, BM_SETCHECK,
632 (WPARAM)((nsoption_bool(send_referer)) ?
633 BST_CHECKED : BST_UNCHECKED), 0);
634 break;
635
636 case WM_NOTIFY:
637 switch (((NMHDR FAR *)lParam)->code) {
638 case PSN_APPLY:
639 /* homepage */
640 sub = GetDlgItem(hwnd, IDC_PREFS_HOMEPAGE);
641 if (sub != NULL) {
642 int text_length;
643 char *text;
644 text_length = SendMessage(sub,
645 WM_GETTEXTLENGTH, 0, 0);
646 text = malloc(text_length + 1);
647 if (text != NULL) {
648 SendMessage(sub, WM_GETTEXT,
649 (WPARAM)text_length + 1,
650 (LPARAM)text);
651 nsoption_set_charp(homepage_url, text);
652 }
653 }
654
655 nsoption_set_bool(suppress_images,
656 (IsDlgButtonChecked(hwnd, IDC_PREFS_IMAGES) == BST_CHECKED) ? true : false);
657
658 nsoption_set_bool(block_advertisements,
659 (IsDlgButtonChecked(hwnd, IDC_PREFS_ADVERTS) == BST_CHECKED) ? true : false);
660
661 nsoption_set_bool(send_referer,
662 (IsDlgButtonChecked(hwnd, IDC_PREFS_REFERER) == BST_CHECKED) ? true : false);
663
664 break;
665
666 }
667 }
668 return FALSE;
669}
670
671
672/* exported interface documented in windows/prefs.h */
674{
675 /* user saved changes */
676 char *choices = NULL;
677 nserror res;
678
679 res = netsurf_mkpath(&choices, NULL, 2, G_config_path, "Choices");
680 if (res == NSERROR_OK) {
681 nsoption_write(choices, NULL, NULL);
682 free(choices);
683 }
684 return res;
685}
686
687
688/* exported interface documented in windows/prefs.h */
690{
691 int ret;
692 PROPSHEETPAGE psp[3];
693 PROPSHEETHEADER psh;
694
695 psp[0].dwSize = sizeof(PROPSHEETPAGE);
696 psp[0].dwFlags = 0;/*PSP_USEICONID*/
697 psp[0].hInstance = hinst;
698 psp[0].pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS_GENERAL);
699 psp[0].pfnDlgProc = options_general_dialog_handler;
700 psp[0].lParam = 0;
701 psp[0].pfnCallback = NULL;
702
703 psp[1].dwSize = sizeof(PROPSHEETPAGE);
704 psp[1].dwFlags = 0;/*PSP_USEICONID*/
705 psp[1].hInstance = hinst;
706 psp[1].pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS_CONNECTIONS);
707 psp[1].pfnDlgProc = options_connections_dialog_handler;
708 psp[1].lParam = 0;
709 psp[1].pfnCallback = NULL;
710
711 psp[2].dwSize = sizeof(PROPSHEETPAGE);
712 psp[2].dwFlags = 0;/*PSP_USEICONID*/
713 psp[2].hInstance = hinst;
714 psp[2].pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS_APPERANCE);
715 psp[2].pfnDlgProc = options_appearance_dialog_handler;
716 psp[2].lParam = 0;
717 psp[2].pfnCallback = NULL;
718
719
720 psh.dwSize = sizeof(PROPSHEETHEADER);
721 psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID | PSH_PROPSHEETPAGE;
722 psh.hwndParent = parent;
723 psh.hInstance = hinst;
724 psh.pszIcon = MAKEINTRESOURCE(IDR_NETSURF_ICON);
725 psh.pszCaption = (LPSTR) "NetSurf Options";
726 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
727 psh.nStartPage = 0;
728 psh.ppsp = (LPCPROPSHEETPAGE) &psp;
729 psh.pfnCallback = NULL;
730
731 ret = PropertySheet(&psh);
732 if (ret == -1) {
733 win_perror("PropertySheet");
734 } else if (ret > 0) {
736 }
737}
wimp_w parent
Definition: dialog.c:88
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
nserror nsws_prefs_save(void)
Save the users preferances.
Definition: prefs.c:673
static BOOL CALLBACK options_general_dialog_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lParam)
Handle messages to the general preference dialog.
Definition: prefs.c:602
void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent)
open the preferences dialog and respond to user.
Definition: prefs.c:689
static BOOL CALLBACK options_connections_dialog_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lParam)
Handle messages to the connections preference dialog.
Definition: prefs.c:431
static CHOOSEFONT * nsws_prefs_font_prepare(int fontfamily, HWND parent)
Prepare preferences dialog font tab.
Definition: prefs.c:52
static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lParam)
Handle messages to the appearance preference dialog.
Definition: prefs.c:148
static void change_spinner(HWND sub, double change, double minval, double maxval)
Update value in spinner control when it is changed.
Definition: prefs.c:108
#define IDC_PREFS_PROXYPORT
Definition: resourceid.h:77
#define IDC_PREFS_FETCHERS
Definition: resourceid.h:67
#define IDC_PREFS_ADVERTS
Definition: resourceid.h:63
#define IDC_PREFS_PROXYHOST
Definition: resourceid.h:76
#define IDC_PREFS_PROXYTYPE
Definition: resourceid.h:75
#define IDC_PREFS_FONT_SIZE
Definition: resourceid.h:80
#define IDC_PREFS_FETCH_HOST
Definition: resourceid.h:69
#define IDC_PREFS_PROXYPASS
Definition: resourceid.h:79
#define IDC_PREFS_CURSIVE
Definition: resourceid.h:87
#define IDD_OPTIONS_GENERAL
Definition: resourceid.h:60
#define IDD_OPTIONS_CONNECTIONS
Definition: resourceid.h:66
#define IDC_PREFS_FETCH_HANDLES
Definition: resourceid.h:71
#define IDC_PREFS_FONT_MINSIZE
Definition: resourceid.h:81
#define IDC_PREFS_NOANIMATION
Definition: resourceid.h:90
#define IDC_PREFS_FONT_SIZE_SPIN
Definition: resourceid.h:85
#define IDC_PREFS_SERIF
Definition: resourceid.h:84
#define IDC_PREFS_MONO
Definition: resourceid.h:86
#define IDC_PREFS_PROXYNAME
Definition: resourceid.h:78
#define IDD_OPTIONS_APPERANCE
Definition: resourceid.h:74
#define IDC_PREFS_FANTASY
Definition: resourceid.h:88
#define IDC_PREFS_FETCHERS_SPIN
Definition: resourceid.h:68
#define IDC_PREFS_FETCH_HOST_SPIN
Definition: resourceid.h:70
#define IDC_PREFS_IMAGES
Definition: resourceid.h:62
#define IDR_NETSURF_ICON
Definition: resourceid.h:26
#define IDC_PREFS_SANS
Definition: resourceid.h:83
#define IDC_PREFS_FETCH_HANDLES_SPIN
Definition: resourceid.h:72
#define IDC_PREFS_FONT_MINSIZE_SPIN
Definition: resourceid.h:82
#define IDC_PREFS_FONTDEF
Definition: resourceid.h:89
#define IDC_PREFS_REFERER
Definition: resourceid.h:64
#define IDC_PREFS_HOMEPAGE
Definition: resourceid.h:61
nserror netsurf_mkpath(char **str, size_t *size, size_t nelm,...)
Generate a path from one or more component elemnts.
Definition: file.c:288
Default operations table for files.
nserror nsoption_write(const char *path, struct nsoption_s *opts, struct nsoption_s *defs)
Write options that have changed from the defaults to a file.
Definition: nsoption.c:786
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:348
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Definition: nsoption.h:372
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
#define min(x, y)
Definition: utils.h:46
#define max(x, y)
Definition: utils.h:50
void win_perror(const char *lpszFunction)
Definition: windbg.c:633
#define LOG_WIN_MSG(h, m, w, l)
log windows message
Definition: windbg.h:32
char * G_config_path
path to where all user config files are held.
Definition: gui.c:51
nserror win32_warning(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:173
HINSTANCE hinst
win32 application instance handle.
Definition: gui.c:45
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978