TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / programs / wineconsole / dialog.c
blob4f73a3acb0951d330f46876cdc9d413df93b385c
1 /* dialog management for wineconsole
2 * USER32 backend
3 * Copyright (c) 2001, 2002 Eric Pouech
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "commctrl.h"
32 #include "prsht.h"
33 #include "winecon_user.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
39 struct dialog_info
41 struct config_data config; /* configuration used for dialog box */
42 struct inner_data* data; /* pointer to current winecon info */
43 HWND hDlg; /* handle to active propsheet */
44 int nFont; /* number of font size in size LB */
45 struct font_info
47 UINT height;
48 UINT weight;
49 WCHAR faceName[LF_FACESIZE];
50 } *font; /* array of nFont. index sync'ed with SIZE LB */
53 /******************************************************************
54 * WCUSER_OptionDlgProc
56 * Dialog prop for the option property sheet
58 static INT_PTR WINAPI WCUSER_OptionDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
60 struct dialog_info* di;
61 unsigned idc;
63 switch (msg)
65 case WM_INITDIALOG:
66 di = (struct dialog_info*)((PROPSHEETPAGEA*)lParam)->lParam;
67 di->hDlg = hDlg;
68 SetWindowLongPtrW(hDlg, DWLP_USER, (LONG_PTR)di);
70 SendMessageW(GetDlgItem(hDlg,IDC_OPT_HIST_SIZE_UD), UDM_SETRANGE, 0, MAKELPARAM(500, 0));
72 if (di->config.cursor_size <= 25) idc = IDC_OPT_CURSOR_SMALL;
73 else if (di->config.cursor_size <= 50) idc = IDC_OPT_CURSOR_MEDIUM;
74 else idc = IDC_OPT_CURSOR_LARGE;
75 SendDlgItemMessageW(hDlg, idc, BM_SETCHECK, BST_CHECKED, 0);
76 SetDlgItemInt(hDlg, IDC_OPT_HIST_SIZE, di->config.history_size, FALSE);
77 SendDlgItemMessageW(hDlg, IDC_OPT_HIST_NODOUBLE, BM_SETCHECK,
78 (di->config.history_nodup) ? BST_CHECKED : BST_UNCHECKED, 0);
79 SendDlgItemMessageW(hDlg, IDC_OPT_INSERT_MODE, BM_SETCHECK,
80 (di->config.insert_mode) ? BST_CHECKED : BST_UNCHECKED, 0);
81 SendDlgItemMessageW(hDlg, IDC_OPT_CONF_CTRL, BM_SETCHECK,
82 (di->config.menu_mask & MK_CONTROL) ? BST_CHECKED : BST_UNCHECKED, 0);
83 SendDlgItemMessageW(hDlg, IDC_OPT_CONF_SHIFT, BM_SETCHECK,
84 (di->config.menu_mask & MK_SHIFT) ? BST_CHECKED : BST_UNCHECKED, 0);
85 SendDlgItemMessageW(hDlg, IDC_OPT_QUICK_EDIT, BM_SETCHECK,
86 (di->config.quick_edit) ? BST_CHECKED : BST_UNCHECKED, 0);
87 return FALSE; /* because we set the focus */
88 case WM_COMMAND:
89 break;
90 case WM_NOTIFY:
92 NMHDR* nmhdr = (NMHDR*)lParam;
93 DWORD val;
94 BOOL done;
96 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
98 switch (nmhdr->code)
100 case PSN_SETACTIVE:
101 /* needed in propsheet to keep properly the selected radio button
102 * otherwise, the focus would be set to the first tab stop in the
103 * propsheet, which would always activate the first radio button
105 if (IsDlgButtonChecked(hDlg, IDC_OPT_CURSOR_SMALL) == BST_CHECKED)
106 idc = IDC_OPT_CURSOR_SMALL;
107 else if (IsDlgButtonChecked(hDlg, IDC_OPT_CURSOR_MEDIUM) == BST_CHECKED)
108 idc = IDC_OPT_CURSOR_MEDIUM;
109 else
110 idc = IDC_OPT_CURSOR_LARGE;
111 PostMessageW(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, idc), TRUE);
112 di->hDlg = hDlg;
113 break;
114 case PSN_APPLY:
115 if (IsDlgButtonChecked(hDlg, IDC_OPT_CURSOR_SMALL) == BST_CHECKED) val = 25;
116 else if (IsDlgButtonChecked(hDlg, IDC_OPT_CURSOR_MEDIUM) == BST_CHECKED) val = 50;
117 else val = 100;
118 di->config.cursor_size = val;
120 val = GetDlgItemInt(hDlg, IDC_OPT_HIST_SIZE, &done, FALSE);
121 if (done) di->config.history_size = val;
123 val = (IsDlgButtonChecked(hDlg, IDC_OPT_HIST_NODOUBLE) & BST_CHECKED) != 0;
124 di->config.history_nodup = val;
126 val = (IsDlgButtonChecked(hDlg, IDC_OPT_INSERT_MODE) & BST_CHECKED) != 0;
127 di->config.insert_mode = val;
129 val = 0;
130 if (IsDlgButtonChecked(hDlg, IDC_OPT_CONF_CTRL) & BST_CHECKED) val |= MK_CONTROL;
131 if (IsDlgButtonChecked(hDlg, IDC_OPT_CONF_SHIFT) & BST_CHECKED) val |= MK_SHIFT;
132 di->config.menu_mask = val;
134 val = (IsDlgButtonChecked(hDlg, IDC_OPT_QUICK_EDIT) & BST_CHECKED) != 0;
135 di->config.quick_edit = val;
137 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
138 return TRUE;
139 default:
140 return FALSE;
142 break;
144 default:
145 return FALSE;
147 return TRUE;
150 /******************************************************************
151 * WCUSER_FontPreviewProc
153 * Window proc for font previewer in font property sheet
155 static LRESULT WINAPI WCUSER_FontPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
157 switch (msg)
159 case WM_CREATE:
160 SetWindowLongPtrW(hWnd, 0, 0);
161 break;
162 case WM_GETFONT:
163 return GetWindowLongPtrW(hWnd, 0);
164 case WM_SETFONT:
165 SetWindowLongPtrW(hWnd, 0, wParam);
166 if (LOWORD(lParam))
168 InvalidateRect(hWnd, NULL, TRUE);
169 UpdateWindow(hWnd);
171 break;
172 case WM_DESTROY:
174 HFONT hFont = (HFONT)GetWindowLongPtrW(hWnd, 0);
175 if (hFont) DeleteObject(hFont);
177 break;
178 case WM_PAINT:
180 PAINTSTRUCT ps;
181 int size_idx;
182 struct dialog_info* di;
183 HFONT hFont, hOldFont;
185 di = (struct dialog_info*)GetWindowLongPtrW(GetParent(hWnd), DWLP_USER);
186 BeginPaint(hWnd, &ps);
188 size_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
190 hFont = (HFONT)GetWindowLongPtrW(hWnd, 0);
191 if (hFont)
193 WCHAR ascii[] = {'A','S','C','I','I',':',' ','a','b','c','X','Y','Z','\0'};
194 WCHAR buf[256];
195 int len;
197 hOldFont = SelectObject(ps.hdc, hFont);
198 SetBkColor(ps.hdc, WCUSER_ColorMap[GetWindowLongW(GetDlgItem(di->hDlg, IDC_FNT_COLOR_BK), 0)]);
199 SetTextColor(ps.hdc, WCUSER_ColorMap[GetWindowLongW(GetDlgItem(di->hDlg, IDC_FNT_COLOR_FG), 0)]);
200 len = LoadStringW(GetModuleHandleW(NULL), IDS_FNT_PREVIEW,
201 buf, sizeof(buf) / sizeof(buf[0]));
202 if (len)
203 TextOutW(ps.hdc, 0, 0, buf, len);
204 TextOutW(ps.hdc, 0, di->font[size_idx].height, ascii,
205 sizeof(ascii)/sizeof(ascii[0]) - 1);
206 SelectObject(ps.hdc, hOldFont);
208 EndPaint(hWnd, &ps);
210 break;
211 default:
212 return DefWindowProcW(hWnd, msg, wParam, lParam);
214 return 0L;
217 /******************************************************************
218 * WCUSER_ColorPreviewProc
220 * Window proc for color previewer in font property sheet
222 static LRESULT WINAPI WCUSER_ColorPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
224 switch (msg)
226 case WM_PAINT:
228 PAINTSTRUCT ps;
229 int i, step;
230 RECT client, r;
231 HBRUSH hbr;
233 BeginPaint(hWnd, &ps);
234 GetClientRect(hWnd, &client);
235 step = client.right / 8;
237 for (i = 0; i < 16; i++)
239 r.top = (i / 8) * (client.bottom / 2);
240 r.bottom = r.top + client.bottom / 2;
241 r.left = (i & 7) * step;
242 r.right = r.left + step;
243 hbr = CreateSolidBrush(WCUSER_ColorMap[i]);
244 FillRect(ps.hdc, &r, hbr);
245 DeleteObject(hbr);
246 if (GetWindowLongW(hWnd, 0) == i)
248 HPEN hOldPen;
249 int i = 2;
251 hOldPen = SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
252 r.right--; r.bottom--;
253 for (;;)
255 MoveToEx(ps.hdc, r.left, r.bottom, NULL);
256 LineTo(ps.hdc, r.left, r.top);
257 LineTo(ps.hdc, r.right, r.top);
258 SelectObject(ps.hdc, GetStockObject(BLACK_PEN));
259 LineTo(ps.hdc, r.right, r.bottom);
260 LineTo(ps.hdc, r.left, r.bottom);
262 if (--i == 0) break;
263 r.left++; r.top++; r.right--; r.bottom--;
264 SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
266 SelectObject(ps.hdc, hOldPen);
269 EndPaint(hWnd, &ps);
270 break;
272 case WM_LBUTTONDOWN:
274 int i, step;
275 RECT client;
277 GetClientRect(hWnd, &client);
278 step = client.right / 8;
279 i = (HIWORD(lParam) >= client.bottom / 2) ? 8 : 0;
280 i += LOWORD(lParam) / step;
281 SetWindowLongW(hWnd, 0, i);
282 InvalidateRect(GetDlgItem(GetParent(hWnd), IDC_FNT_PREVIEW), NULL, FALSE);
283 InvalidateRect(hWnd, NULL, FALSE);
285 break;
286 default:
287 return DefWindowProcW(hWnd, msg, wParam, lParam);
289 return 0L;
292 /******************************************************************
293 * font_enum
295 * enumerates all the font names with at least one valid font
297 static int CALLBACK font_enum_size2(const LOGFONTW* lf, const TEXTMETRICW* tm,
298 DWORD FontType, LPARAM lParam)
300 struct dialog_info* di = (struct dialog_info*)lParam;
302 WCUSER_DumpTextMetric(tm, FontType);
303 if (WCUSER_ValidateFontMetric(di->data, tm, FontType, TRUE))
305 di->nFont++;
308 return 1;
311 static int CALLBACK font_enum(const LOGFONTW* lf, const TEXTMETRICW* tm,
312 DWORD FontType, LPARAM lParam)
314 struct dialog_info* di = (struct dialog_info*)lParam;
316 WCUSER_DumpLogFont("DlgFamily: ", lf, FontType);
317 if (WCUSER_ValidateFont(di->data, lf))
319 if (FontType & RASTER_FONTTYPE)
321 di->nFont = 0;
322 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, lf->lfFaceName, font_enum_size2, (LPARAM)di);
324 else
325 di->nFont = 1;
327 if (di->nFont)
329 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_ADDSTRING,
330 0, (LPARAM)lf->lfFaceName);
334 return 1;
337 /******************************************************************
338 * font_enum_size
342 static int CALLBACK font_enum_size(const LOGFONTW* lf, const TEXTMETRICW* tm,
343 DWORD FontType, LPARAM lParam)
345 struct dialog_info* di = (struct dialog_info*)lParam;
346 WCHAR buf[32];
347 static const WCHAR fmt[] = {'%','l','d',0};
349 WCUSER_DumpTextMetric(tm, FontType);
350 if (di->nFont == 0 && !(FontType & RASTER_FONTTYPE))
352 static const int sizes[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
353 int i;
355 di->nFont = sizeof(sizes) / sizeof(sizes[0]);
356 di->font = HeapAlloc(GetProcessHeap(), 0, di->nFont * sizeof(di->font[0]));
357 for (i = 0; i < di->nFont; i++)
359 /* drop sizes where window size wouldn't fit on screen */
360 if (sizes[i] * di->data->curcfg.win_height > GetSystemMetrics(SM_CYSCREEN))
362 di->nFont = i;
363 break;
365 di->font[i].height = sizes[i];
366 di->font[i].weight = 400;
367 lstrcpyW(di->font[i].faceName, lf->lfFaceName);
368 wsprintfW(buf, fmt, sizes[i]);
369 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_INSERTSTRING, i, (LPARAM)buf);
371 /* don't need to enumerate other */
372 return 0;
375 if (WCUSER_ValidateFontMetric(di->data, tm, FontType, TRUE))
377 int idx = 0;
379 /* we want the string to be sorted with a numeric order, not a lexicographic...
380 * do the job by hand... get where to insert the new string
382 while (idx < di->nFont && tm->tmHeight > di->font[idx].height)
383 idx++;
384 while (idx < di->nFont &&
385 tm->tmHeight == di->font[idx].height &&
386 tm->tmWeight > di->font[idx].weight)
387 idx++;
388 if (idx == di->nFont ||
389 tm->tmHeight != di->font[idx].height ||
390 tm->tmWeight < di->font[idx].weight)
392 /* here we need to add the new entry */
393 wsprintfW(buf, fmt, tm->tmHeight);
394 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_INSERTSTRING, idx, (LPARAM)buf);
396 /* now grow our arrays and insert the values at the same index than in the list box */
397 if (di->nFont)
399 di->font = HeapReAlloc(GetProcessHeap(), 0, di->font, sizeof(*di->font) * (di->nFont + 1));
400 if (idx != di->nFont)
401 memmove(&di->font[idx + 1], &di->font[idx], (di->nFont - idx) * sizeof(*di->font));
403 else
404 di->font = HeapAlloc(GetProcessHeap(), 0, sizeof(*di->font));
405 di->font[idx].height = tm->tmHeight;
406 di->font[idx].weight = tm->tmWeight;
407 lstrcpyW(di->font[idx].faceName, lf->lfFaceName);
408 di->nFont++;
411 return 1;
414 /******************************************************************
415 * select_font
419 static BOOL select_font(struct dialog_info* di)
421 int font_idx, size_idx;
422 WCHAR buf[256];
423 WCHAR fmt[128];
424 DWORD_PTR args[2];
425 LOGFONTW lf;
426 HFONT hFont, hOldFont;
427 struct config_data config;
429 font_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0, 0);
430 size_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
432 if (font_idx < 0 || size_idx < 0 || size_idx >= di->nFont)
433 return FALSE;
435 WCUSER_FillLogFont(&lf, di->font[size_idx].faceName,
436 di->font[size_idx].height, di->font[size_idx].weight);
437 hFont = WCUSER_CopyFont(&config, di->data->hWnd, &lf, NULL);
438 if (!hFont) return FALSE;
440 if (config.cell_height != di->font[size_idx].height)
441 WINE_TRACE("mismatched heights (%u<>%u)\n",
442 config.cell_height, di->font[size_idx].height);
443 hOldFont = (HFONT)SendDlgItemMessageW(di->hDlg, IDC_FNT_PREVIEW, WM_GETFONT, 0, 0);
445 SendDlgItemMessageW(di->hDlg, IDC_FNT_PREVIEW, WM_SETFONT, (WPARAM)hFont, TRUE);
446 if (hOldFont) DeleteObject(hOldFont);
448 LoadStringW(GetModuleHandleW(NULL), IDS_FNT_DISPLAY, fmt, sizeof(fmt) / sizeof(fmt[0]));
449 args[0] = config.cell_width;
450 args[1] = config.cell_height;
451 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
452 fmt, 0, 0, buf, sizeof(buf)/sizeof(*buf), (__ms_va_list*)args);
454 SendDlgItemMessageW(di->hDlg, IDC_FNT_FONT_INFO, WM_SETTEXT, 0, (LPARAM)buf);
456 return TRUE;
459 /******************************************************************
460 * fill_list_size
462 * fills the size list box according to selected family in font LB
464 static BOOL fill_list_size(struct dialog_info* di, BOOL doInit)
466 int idx;
467 WCHAR lfFaceName[LF_FACESIZE];
469 idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0, 0);
470 if (idx < 0) return FALSE;
472 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETTEXT, idx, (LPARAM)lfFaceName);
473 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_RESETCONTENT, 0, 0);
474 HeapFree(GetProcessHeap(), 0, di->font);
475 di->nFont = 0;
476 di->font = NULL;
478 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, lfFaceName, font_enum_size, (LPARAM)di);
480 if (doInit)
482 int ref = -1;
484 for (idx = 0; idx < di->nFont; idx++)
486 if (!lstrcmpW(di->font[idx].faceName, di->config.face_name) &&
487 di->font[idx].height == di->config.cell_height &&
488 di->font[idx].weight == di->config.font_weight)
490 if (ref == -1) ref = idx;
491 else WINE_TRACE("Several matches found: ref=%d idx=%d\n", ref, idx);
494 idx = (ref == -1) ? 0 : ref;
496 else
497 idx = 0;
498 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_SETCURSEL, idx, 0);
499 select_font(di);
500 return TRUE;
503 /******************************************************************
504 * fill_list_font
506 * Fills the font LB
508 static BOOL fill_list_font(struct dialog_info* di)
510 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_RESETCONTENT, 0, 0);
511 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, NULL, font_enum, (LPARAM)di);
512 if (SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_SELECTSTRING,
513 -1, (LPARAM)di->config.face_name) == LB_ERR)
514 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_SETCURSEL, 0, 0);
515 fill_list_size(di, TRUE);
516 return TRUE;
519 /******************************************************************
520 * WCUSER_FontDlgProc
522 * Dialog proc for the Font property sheet
524 static INT_PTR WINAPI WCUSER_FontDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
526 struct dialog_info* di;
528 switch (msg)
530 case WM_INITDIALOG:
531 di = (struct dialog_info*)((PROPSHEETPAGEA*)lParam)->lParam;
532 di->hDlg = hDlg;
533 SetWindowLongPtrW(hDlg, DWLP_USER, (DWORD_PTR)di);
534 /* remove dialog from this control, font will be reset when listboxes are filled */
535 SendDlgItemMessageW(hDlg, IDC_FNT_PREVIEW, WM_SETFONT, 0, 0);
536 fill_list_font(di);
537 SetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_BK), 0, (di->config.def_attr >> 4) & 0x0F);
538 SetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_FG), 0, di->config.def_attr & 0x0F);
539 break;
540 case WM_COMMAND:
541 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
542 switch (LOWORD(wParam))
544 case IDC_FNT_LIST_FONT:
545 if (HIWORD(wParam) == LBN_SELCHANGE)
547 fill_list_size(di, FALSE);
549 break;
550 case IDC_FNT_LIST_SIZE:
551 if (HIWORD(wParam) == LBN_SELCHANGE)
553 select_font(di);
555 break;
557 break;
558 case WM_NOTIFY:
560 NMHDR* nmhdr = (NMHDR*)lParam;
561 DWORD val;
563 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
564 switch (nmhdr->code)
566 case PSN_SETACTIVE:
567 di->hDlg = hDlg;
568 break;
569 case PSN_APPLY:
570 val = SendDlgItemMessageW(hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
572 if (val < di->nFont)
574 LOGFONTW lf;
576 WCUSER_FillLogFont(&lf, di->font[val].faceName,
577 di->font[val].height, di->font[val].weight);
578 DeleteObject(WCUSER_CopyFont(&di->config,
579 di->data->hWnd, &lf, NULL));
582 val = (GetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_BK), 0) << 4) |
583 GetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_FG), 0);
584 di->config.def_attr = val;
586 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
587 return TRUE;
588 default:
589 return FALSE;
591 break;
593 default:
594 return FALSE;
596 return TRUE;
599 /******************************************************************
600 * WCUSER_ConfigDlgProc
602 * Dialog proc for the config property sheet
604 static INT_PTR WINAPI WCUSER_ConfigDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
606 struct dialog_info* di;
607 int nMaxUD = 2000;
609 switch (msg)
611 case WM_INITDIALOG:
612 di = (struct dialog_info*)((PROPSHEETPAGEA*)lParam)->lParam;
613 di->hDlg = hDlg;
615 SetWindowLongPtrW(hDlg, DWLP_USER, (DWORD_PTR)di);
616 SetDlgItemInt(hDlg, IDC_CNF_SB_WIDTH, di->config.sb_width, FALSE);
617 SetDlgItemInt(hDlg, IDC_CNF_SB_HEIGHT, di->config.sb_height, FALSE);
618 SetDlgItemInt(hDlg, IDC_CNF_WIN_WIDTH, di->config.win_width, FALSE);
619 SetDlgItemInt(hDlg, IDC_CNF_WIN_HEIGHT, di->config.win_height, FALSE);
621 SendMessageW(GetDlgItem(hDlg,IDC_CNF_WIN_HEIGHT_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
622 SendMessageW(GetDlgItem(hDlg,IDC_CNF_WIN_WIDTH_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
623 SendMessageW(GetDlgItem(hDlg,IDC_CNF_SB_HEIGHT_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
624 SendMessageW(GetDlgItem(hDlg,IDC_CNF_SB_WIDTH_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
626 SendDlgItemMessageW(hDlg, IDC_CNF_CLOSE_EXIT, BM_SETCHECK,
627 (di->config.exit_on_die) ? BST_CHECKED : BST_UNCHECKED, 0);
629 static const WCHAR s1[] = {'W','i','n','3','2',0};
630 static const WCHAR s2[] = {'E','m','a','c','s',0};
632 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_ADDSTRING, 0, (LPARAM)s1);
633 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_ADDSTRING, 0, (LPARAM)s2);
634 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_SETCURSEL, di->config.edition_mode, 0);
637 break;
638 case WM_COMMAND:
639 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
640 switch (LOWORD(wParam))
643 break;
644 case WM_NOTIFY:
646 NMHDR* nmhdr = (NMHDR*)lParam;
647 int win_w, win_h, sb_w, sb_h;
648 BOOL st1, st2;
650 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
651 switch (nmhdr->code)
653 case PSN_SETACTIVE:
654 di->hDlg = hDlg;
655 break;
656 case PSN_APPLY:
657 sb_w = GetDlgItemInt(hDlg, IDC_CNF_SB_WIDTH, &st1, FALSE);
658 sb_h = GetDlgItemInt(hDlg, IDC_CNF_SB_HEIGHT, &st2, FALSE);
659 if (!st1 || ! st2)
661 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
662 return TRUE;
664 win_w = GetDlgItemInt(hDlg, IDC_CNF_WIN_WIDTH, &st1, FALSE);
665 win_h = GetDlgItemInt(hDlg, IDC_CNF_WIN_HEIGHT, &st2, FALSE);
666 if (!st1 || !st2)
668 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
669 return TRUE;
671 if (win_w > sb_w || win_h > sb_h)
673 WCHAR cap[256];
674 WCHAR txt[256];
676 LoadStringW(GetModuleHandleW(NULL), IDS_DLG_TIT_ERROR,
677 cap, sizeof(cap) / sizeof(cap[0]));
678 LoadStringW(GetModuleHandleW(NULL), IDS_DLG_ERR_SBWINSIZE,
679 txt, sizeof(txt) / sizeof(cap[0]));
681 MessageBoxW(hDlg, txt, cap, MB_OK);
682 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
683 return TRUE;
685 di->config.win_width = win_w;
686 di->config.win_height = win_h;
687 di->config.sb_width = sb_w;
688 di->config.sb_height = sb_h;
690 di->config.exit_on_die = IsDlgButtonChecked(hDlg, IDC_CNF_CLOSE_EXIT) ? 1 : 0;
691 di->config.edition_mode = SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE,
692 CB_GETCURSEL, 0, 0);
693 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
694 return TRUE;
695 default:
696 return FALSE;
698 break;
700 default:
701 return FALSE;
703 return TRUE;
706 /******************************************************************
707 * WCUSER_SaveDlgProc
709 * Dialog Procedure for choosing how to handle modification to the
710 * console settings.
712 static INT_PTR WINAPI WCUSER_SaveDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
714 switch (msg)
716 case WM_INITDIALOG:
717 SendDlgItemMessageW(hDlg, IDC_SAV_SESSION, BM_SETCHECK, BST_CHECKED, 0);
718 break;
719 case WM_COMMAND:
720 switch (LOWORD(wParam))
722 case IDOK:
723 EndDialog(hDlg,
724 (IsDlgButtonChecked(hDlg, IDC_SAV_SAVE) == BST_CHECKED) ?
725 IDC_SAV_SAVE : IDC_SAV_SESSION);
726 break;
727 case IDCANCEL:
728 EndDialog(hDlg, IDCANCEL); break;
730 break;
731 default:
732 return FALSE;
734 return TRUE;
737 /******************************************************************
738 * WCUSER_GetProperties
740 * Runs the dialog box to set up the wineconsole options
742 BOOL WCUSER_GetProperties(struct inner_data* data, BOOL current)
744 HPROPSHEETPAGE psPage[3];
745 PROPSHEETPAGEW psp;
746 PROPSHEETHEADERW psHead;
747 WCHAR buff[256];
748 WNDCLASSW wndclass;
749 static const WCHAR szFntPreview[] = {'W','i','n','e','C','o','n','F','o','n','t','P','r','e','v','i','e','w',0};
750 static const WCHAR szColorPreview[] = {'W','i','n','e','C','o','n','C','o','l','o','r','P','r','e','v','i','e','w',0};
751 struct dialog_info di;
752 struct config_data defcfg;
753 struct config_data* refcfg;
754 BOOL save, modify_session;
756 InitCommonControls();
758 di.data = data;
759 if (current)
761 refcfg = &data->curcfg;
762 save = FALSE;
764 else
766 WINECON_RegLoad(NULL, refcfg = &defcfg);
767 save = TRUE;
769 di.config = *refcfg;
770 di.nFont = 0;
771 di.font = NULL;
773 modify_session = FALSE;
775 wndclass.style = 0;
776 wndclass.lpfnWndProc = WCUSER_FontPreviewProc;
777 wndclass.cbClsExtra = 0;
778 wndclass.cbWndExtra = sizeof (DWORD_PTR); /* for hFont */
779 wndclass.hInstance = GetModuleHandleW(NULL);
780 wndclass.hIcon = 0;
781 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
782 wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
783 wndclass.lpszMenuName = NULL;
784 wndclass.lpszClassName = szFntPreview;
785 RegisterClassW(&wndclass);
787 wndclass.style = 0;
788 wndclass.lpfnWndProc = WCUSER_ColorPreviewProc;
789 wndclass.cbClsExtra = 0;
790 wndclass.cbWndExtra = sizeof(DWORD);
791 wndclass.hInstance = GetModuleHandleW(NULL);
792 wndclass.hIcon = 0;
793 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
794 wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
795 wndclass.lpszMenuName = NULL;
796 wndclass.lpszClassName = szColorPreview;
797 RegisterClassW(&wndclass);
799 memset(&psp, 0, sizeof(psp));
800 psp.dwSize = sizeof(psp);
801 psp.dwFlags = 0;
802 psp.hInstance = wndclass.hInstance;
803 psp.lParam = (LPARAM)&di;
805 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_OPTION);
806 psp.pfnDlgProc = WCUSER_OptionDlgProc;
807 psPage[0] = CreatePropertySheetPageW(&psp);
809 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_FONT);
810 psp.pfnDlgProc = WCUSER_FontDlgProc;
811 psPage[1] = CreatePropertySheetPageW(&psp);
813 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_CONFIG);
814 psp.pfnDlgProc = WCUSER_ConfigDlgProc;
815 psPage[2] = CreatePropertySheetPageW(&psp);
817 memset(&psHead, 0, sizeof(psHead));
818 psHead.dwSize = sizeof(psHead);
820 if (!LoadStringW(GetModuleHandleW(NULL),
821 (current) ? IDS_DLG_TIT_CURRENT : IDS_DLG_TIT_DEFAULT,
822 buff, sizeof(buff) / sizeof(buff[0])))
824 buff[0] = 'S';
825 buff[1] = 'e';
826 buff[2] = 't';
827 buff[3] = 'u';
828 buff[4] = 'p';
829 buff[5] = '\0';
832 psHead.pszCaption = buff;
833 psHead.nPages = 3;
834 psHead.hwndParent = data->hWnd;
835 psHead.u3.phpage = psPage;
836 psHead.dwFlags = PSH_NOAPPLYNOW;
838 WINECON_DumpConfig("init", refcfg);
840 PropertySheetW(&psHead);
842 if (memcmp(refcfg, &di.config, sizeof(*refcfg)) == 0)
843 return TRUE;
845 WINECON_DumpConfig("ref", refcfg);
846 WINECON_DumpConfig("cur", &di.config);
847 if (refcfg == &data->curcfg)
849 switch (DialogBoxW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDD_SAVE_SETTINGS),
850 data->hWnd, WCUSER_SaveDlgProc))
852 case IDC_SAV_SAVE: save = TRUE; modify_session = TRUE; break;
853 case IDC_SAV_SESSION: modify_session = TRUE; break;
854 case IDCANCEL: break;
855 default: WINE_ERR("ooch\n");
859 if (modify_session) WINECON_SetConfig(data, &di.config);
860 if (save) WINECON_RegSave(&di.config);
862 return TRUE;