hidclass.sys: Use IoRegisterDeviceInterface.
[wine.git] / programs / wineconsole / dialog.c
blob898812553a7768b04e81bc05de161cf92a0b35f2
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 static COLORREF get_color(struct dialog_info *di, unsigned int idc)
152 LONG_PTR index;
154 index = GetWindowLongPtrW(GetDlgItem(di->hDlg, idc), 0);
155 return di->config.color_map[index];
158 /******************************************************************
159 * WCUSER_FontPreviewProc
161 * Window proc for font previewer in font property sheet
163 static LRESULT WINAPI WCUSER_FontPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
165 switch (msg)
167 case WM_CREATE:
168 SetWindowLongPtrW(hWnd, 0, 0);
169 break;
170 case WM_GETFONT:
171 return GetWindowLongPtrW(hWnd, 0);
172 case WM_SETFONT:
173 SetWindowLongPtrW(hWnd, 0, wParam);
174 if (LOWORD(lParam))
176 InvalidateRect(hWnd, NULL, TRUE);
177 UpdateWindow(hWnd);
179 break;
180 case WM_DESTROY:
182 HFONT hFont = (HFONT)GetWindowLongPtrW(hWnd, 0);
183 if (hFont) DeleteObject(hFont);
185 break;
186 case WM_PAINT:
188 PAINTSTRUCT ps;
189 int size_idx;
190 struct dialog_info* di;
191 HFONT hFont, hOldFont;
193 di = (struct dialog_info*)GetWindowLongPtrW(GetParent(hWnd), DWLP_USER);
194 BeginPaint(hWnd, &ps);
196 size_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
198 hFont = (HFONT)GetWindowLongPtrW(hWnd, 0);
199 if (hFont)
201 COLORREF bkcolor;
202 WCHAR ascii[] = {'A','S','C','I','I',':',' ','a','b','c','X','Y','Z','\0'};
203 WCHAR buf[256];
204 int len;
206 hOldFont = SelectObject(ps.hdc, hFont);
207 bkcolor = get_color(di, IDC_FNT_COLOR_BK);
208 FillRect(ps.hdc, &ps.rcPaint, CreateSolidBrush(bkcolor));
209 SetBkColor(ps.hdc, bkcolor);
210 SetTextColor(ps.hdc, get_color(di, IDC_FNT_COLOR_FG));
211 len = LoadStringW(GetModuleHandleW(NULL), IDS_FNT_PREVIEW, buf, ARRAY_SIZE(buf));
212 if (len)
213 TextOutW(ps.hdc, 0, 0, buf, len);
214 TextOutW(ps.hdc, 0, di->font[size_idx].height, ascii, ARRAY_SIZE(ascii) - 1);
215 SelectObject(ps.hdc, hOldFont);
217 EndPaint(hWnd, &ps);
219 break;
220 default:
221 return DefWindowProcW(hWnd, msg, wParam, lParam);
223 return 0L;
226 /******************************************************************
227 * WCUSER_ColorPreviewProc
229 * Window proc for color previewer in font property sheet
231 static LRESULT WINAPI WCUSER_ColorPreviewProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
233 switch (msg)
235 case WM_PAINT:
237 PAINTSTRUCT ps;
238 int i, step;
239 RECT client, r;
240 struct dialog_info *di;
241 HBRUSH hbr;
243 BeginPaint(hWnd, &ps);
244 GetClientRect(hWnd, &client);
245 step = client.right / 8;
247 di = (struct dialog_info *)GetWindowLongPtrW(GetParent(hWnd), DWLP_USER);
249 for (i = 0; i < 16; i++)
251 r.top = (i / 8) * (client.bottom / 2);
252 r.bottom = r.top + client.bottom / 2;
253 r.left = (i & 7) * step;
254 r.right = r.left + step;
255 hbr = CreateSolidBrush(di->config.color_map[i]);
256 FillRect(ps.hdc, &r, hbr);
257 DeleteObject(hbr);
258 if (GetWindowLongW(hWnd, 0) == i)
260 HPEN hOldPen;
261 int i = 2;
263 hOldPen = SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
264 r.right--; r.bottom--;
265 for (;;)
267 MoveToEx(ps.hdc, r.left, r.bottom, NULL);
268 LineTo(ps.hdc, r.left, r.top);
269 LineTo(ps.hdc, r.right, r.top);
270 SelectObject(ps.hdc, GetStockObject(BLACK_PEN));
271 LineTo(ps.hdc, r.right, r.bottom);
272 LineTo(ps.hdc, r.left, r.bottom);
274 if (--i == 0) break;
275 r.left++; r.top++; r.right--; r.bottom--;
276 SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
278 SelectObject(ps.hdc, hOldPen);
281 EndPaint(hWnd, &ps);
282 break;
284 case WM_LBUTTONDOWN:
286 int i, step;
287 RECT client;
289 GetClientRect(hWnd, &client);
290 step = client.right / 8;
291 i = (HIWORD(lParam) >= client.bottom / 2) ? 8 : 0;
292 i += LOWORD(lParam) / step;
293 SetWindowLongW(hWnd, 0, i);
294 InvalidateRect(GetDlgItem(GetParent(hWnd), IDC_FNT_PREVIEW), NULL, FALSE);
295 InvalidateRect(hWnd, NULL, FALSE);
297 break;
298 default:
299 return DefWindowProcW(hWnd, msg, wParam, lParam);
301 return 0L;
304 /******************************************************************
305 * font_enum
307 * enumerates all the font names with at least one valid font
309 static int CALLBACK font_enum_size2(const LOGFONTW* lf, const TEXTMETRICW* tm,
310 DWORD FontType, LPARAM lParam)
312 struct dialog_info* di = (struct dialog_info*)lParam;
314 WCUSER_DumpTextMetric(tm, FontType);
315 if (WCUSER_ValidateFontMetric(di->data, tm, FontType, 0))
317 di->nFont++;
320 return 1;
323 static int CALLBACK font_enum(const LOGFONTW* lf, const TEXTMETRICW* tm,
324 DWORD FontType, LPARAM lParam)
326 struct dialog_info* di = (struct dialog_info*)lParam;
328 WCUSER_DumpLogFont("DlgFamily: ", lf, FontType);
329 if (WCUSER_ValidateFont(di->data, lf, 0))
331 if (FontType & RASTER_FONTTYPE)
333 di->nFont = 0;
334 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, lf->lfFaceName, font_enum_size2, (LPARAM)di);
336 else
337 di->nFont = 1;
339 if (di->nFont)
341 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_ADDSTRING,
342 0, (LPARAM)lf->lfFaceName);
346 return 1;
349 /******************************************************************
350 * font_enum_size
354 static int CALLBACK font_enum_size(const LOGFONTW* lf, const TEXTMETRICW* tm,
355 DWORD FontType, LPARAM lParam)
357 struct dialog_info* di = (struct dialog_info*)lParam;
358 WCHAR buf[32];
359 static const WCHAR fmt[] = {'%','l','d',0};
361 WCUSER_DumpTextMetric(tm, FontType);
362 if (di->nFont == 0 && !(FontType & RASTER_FONTTYPE))
364 static const int sizes[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
365 int i;
367 di->nFont = ARRAY_SIZE(sizes);
368 di->font = HeapAlloc(GetProcessHeap(), 0, di->nFont * sizeof(di->font[0]));
369 for (i = 0; i < di->nFont; i++)
371 /* drop sizes where window size wouldn't fit on screen */
372 if (sizes[i] * di->data->curcfg.win_height > GetSystemMetrics(SM_CYSCREEN))
374 di->nFont = i;
375 break;
377 di->font[i].height = sizes[i];
378 di->font[i].weight = 400;
379 lstrcpyW(di->font[i].faceName, lf->lfFaceName);
380 wsprintfW(buf, fmt, sizes[i]);
381 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_INSERTSTRING, i, (LPARAM)buf);
383 /* don't need to enumerate other */
384 return 0;
387 if (WCUSER_ValidateFontMetric(di->data, tm, FontType, 0))
389 int idx = 0;
391 /* we want the string to be sorted with a numeric order, not a lexicographic...
392 * do the job by hand... get where to insert the new string
394 while (idx < di->nFont && tm->tmHeight > di->font[idx].height)
395 idx++;
396 while (idx < di->nFont &&
397 tm->tmHeight == di->font[idx].height &&
398 tm->tmWeight > di->font[idx].weight)
399 idx++;
400 if (idx == di->nFont ||
401 tm->tmHeight != di->font[idx].height ||
402 tm->tmWeight < di->font[idx].weight)
404 /* here we need to add the new entry */
405 wsprintfW(buf, fmt, tm->tmHeight);
406 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_INSERTSTRING, idx, (LPARAM)buf);
408 /* now grow our arrays and insert the values at the same index than in the list box */
409 if (di->nFont)
411 di->font = HeapReAlloc(GetProcessHeap(), 0, di->font, sizeof(*di->font) * (di->nFont + 1));
412 if (idx != di->nFont)
413 memmove(&di->font[idx + 1], &di->font[idx], (di->nFont - idx) * sizeof(*di->font));
415 else
416 di->font = HeapAlloc(GetProcessHeap(), 0, sizeof(*di->font));
417 di->font[idx].height = tm->tmHeight;
418 di->font[idx].weight = tm->tmWeight;
419 lstrcpyW(di->font[idx].faceName, lf->lfFaceName);
420 di->nFont++;
423 return 1;
426 /******************************************************************
427 * select_font
431 static BOOL select_font(struct dialog_info* di)
433 int font_idx, size_idx;
434 WCHAR buf[256];
435 WCHAR fmt[128];
436 DWORD_PTR args[2];
437 LOGFONTW lf;
438 HFONT hFont, hOldFont;
439 struct config_data config;
441 font_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0, 0);
442 size_idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
444 if (font_idx < 0 || size_idx < 0 || size_idx >= di->nFont)
445 return FALSE;
447 WCUSER_FillLogFont(&lf, di->font[size_idx].faceName,
448 di->font[size_idx].height, di->font[size_idx].weight);
449 hFont = WCUSER_CopyFont(&config, di->data->hWnd, &lf, NULL);
450 if (!hFont) return FALSE;
452 if (config.cell_height != di->font[size_idx].height)
453 WINE_TRACE("mismatched heights (%u<>%u)\n",
454 config.cell_height, di->font[size_idx].height);
455 hOldFont = (HFONT)SendDlgItemMessageW(di->hDlg, IDC_FNT_PREVIEW, WM_GETFONT, 0, 0);
457 SendDlgItemMessageW(di->hDlg, IDC_FNT_PREVIEW, WM_SETFONT, (WPARAM)hFont, TRUE);
458 if (hOldFont) DeleteObject(hOldFont);
460 LoadStringW(GetModuleHandleW(NULL), IDS_FNT_DISPLAY, fmt, ARRAY_SIZE(fmt));
461 args[0] = config.cell_width;
462 args[1] = config.cell_height;
463 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
464 fmt, 0, 0, buf, ARRAY_SIZE(buf), (__ms_va_list*)args);
466 SendDlgItemMessageW(di->hDlg, IDC_FNT_FONT_INFO, WM_SETTEXT, 0, (LPARAM)buf);
468 return TRUE;
471 /******************************************************************
472 * fill_list_size
474 * fills the size list box according to selected family in font LB
476 static BOOL fill_list_size(struct dialog_info* di, BOOL doInit)
478 int idx;
479 WCHAR lfFaceName[LF_FACESIZE];
481 idx = SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETCURSEL, 0, 0);
482 if (idx < 0) return FALSE;
484 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_GETTEXT, idx, (LPARAM)lfFaceName);
485 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_RESETCONTENT, 0, 0);
486 HeapFree(GetProcessHeap(), 0, di->font);
487 di->nFont = 0;
488 di->font = NULL;
490 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, lfFaceName, font_enum_size, (LPARAM)di);
492 if (doInit)
494 int ref = -1;
496 for (idx = 0; idx < di->nFont; idx++)
498 if (!lstrcmpW(di->font[idx].faceName, di->config.face_name) &&
499 di->font[idx].height == di->config.cell_height &&
500 di->font[idx].weight == di->config.font_weight)
502 if (ref == -1) ref = idx;
503 else WINE_TRACE("Several matches found: ref=%d idx=%d\n", ref, idx);
506 idx = (ref == -1) ? 0 : ref;
508 else
509 idx = 0;
510 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_SIZE, LB_SETCURSEL, idx, 0);
511 select_font(di);
512 return TRUE;
515 /******************************************************************
516 * fill_list_font
518 * Fills the font LB
520 static BOOL fill_list_font(struct dialog_info* di)
522 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_RESETCONTENT, 0, 0);
523 EnumFontFamiliesW(PRIVATE(di->data)->hMemDC, NULL, font_enum, (LPARAM)di);
524 if (SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_SELECTSTRING,
525 -1, (LPARAM)di->config.face_name) == LB_ERR)
526 SendDlgItemMessageW(di->hDlg, IDC_FNT_LIST_FONT, LB_SETCURSEL, 0, 0);
527 fill_list_size(di, TRUE);
528 return TRUE;
531 /******************************************************************
532 * WCUSER_FontDlgProc
534 * Dialog proc for the Font property sheet
536 static INT_PTR WINAPI WCUSER_FontDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
538 struct dialog_info* di;
540 switch (msg)
542 case WM_INITDIALOG:
543 di = (struct dialog_info*)((PROPSHEETPAGEA*)lParam)->lParam;
544 di->hDlg = hDlg;
545 SetWindowLongPtrW(hDlg, DWLP_USER, (DWORD_PTR)di);
546 /* remove dialog from this control, font will be reset when listboxes are filled */
547 SendDlgItemMessageW(hDlg, IDC_FNT_PREVIEW, WM_SETFONT, 0, 0);
548 fill_list_font(di);
549 SetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_BK), 0, (di->config.def_attr >> 4) & 0x0F);
550 SetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_FG), 0, di->config.def_attr & 0x0F);
551 break;
552 case WM_COMMAND:
553 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
554 switch (LOWORD(wParam))
556 case IDC_FNT_LIST_FONT:
557 if (HIWORD(wParam) == LBN_SELCHANGE)
559 fill_list_size(di, FALSE);
561 break;
562 case IDC_FNT_LIST_SIZE:
563 if (HIWORD(wParam) == LBN_SELCHANGE)
565 select_font(di);
567 break;
569 break;
570 case WM_NOTIFY:
572 NMHDR* nmhdr = (NMHDR*)lParam;
573 DWORD val;
575 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
576 switch (nmhdr->code)
578 case PSN_SETACTIVE:
579 di->hDlg = hDlg;
580 break;
581 case PSN_APPLY:
582 val = SendDlgItemMessageW(hDlg, IDC_FNT_LIST_SIZE, LB_GETCURSEL, 0, 0);
584 if (val < di->nFont)
586 LOGFONTW lf;
588 WCUSER_FillLogFont(&lf, di->font[val].faceName,
589 di->font[val].height, di->font[val].weight);
590 DeleteObject(WCUSER_CopyFont(&di->config,
591 di->data->hWnd, &lf, NULL));
594 val = (GetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_BK), 0) << 4) |
595 GetWindowLongW(GetDlgItem(hDlg, IDC_FNT_COLOR_FG), 0);
596 di->config.def_attr = val;
598 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
599 return TRUE;
600 default:
601 return FALSE;
603 break;
605 default:
606 return FALSE;
608 return TRUE;
611 /******************************************************************
612 * WCUSER_ConfigDlgProc
614 * Dialog proc for the config property sheet
616 static INT_PTR WINAPI WCUSER_ConfigDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
618 struct dialog_info* di;
619 int nMaxUD = 2000;
621 switch (msg)
623 case WM_INITDIALOG:
624 di = (struct dialog_info*)((PROPSHEETPAGEA*)lParam)->lParam;
625 di->hDlg = hDlg;
627 SetWindowLongPtrW(hDlg, DWLP_USER, (DWORD_PTR)di);
628 SetDlgItemInt(hDlg, IDC_CNF_SB_WIDTH, di->config.sb_width, FALSE);
629 SetDlgItemInt(hDlg, IDC_CNF_SB_HEIGHT, di->config.sb_height, FALSE);
630 SetDlgItemInt(hDlg, IDC_CNF_WIN_WIDTH, di->config.win_width, FALSE);
631 SetDlgItemInt(hDlg, IDC_CNF_WIN_HEIGHT, di->config.win_height, FALSE);
633 SendMessageW(GetDlgItem(hDlg,IDC_CNF_WIN_HEIGHT_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
634 SendMessageW(GetDlgItem(hDlg,IDC_CNF_WIN_WIDTH_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
635 SendMessageW(GetDlgItem(hDlg,IDC_CNF_SB_HEIGHT_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
636 SendMessageW(GetDlgItem(hDlg,IDC_CNF_SB_WIDTH_UD), UDM_SETRANGE, 0, MAKELPARAM(nMaxUD, 0));
638 SendDlgItemMessageW(hDlg, IDC_CNF_CLOSE_EXIT, BM_SETCHECK,
639 (di->config.exit_on_die) ? BST_CHECKED : BST_UNCHECKED, 0);
641 static const WCHAR s1[] = {'W','i','n','3','2',0};
642 static const WCHAR s2[] = {'E','m','a','c','s',0};
644 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_ADDSTRING, 0, (LPARAM)s1);
645 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_ADDSTRING, 0, (LPARAM)s2);
646 SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE, CB_SETCURSEL, di->config.edition_mode, 0);
649 break;
650 case WM_COMMAND:
651 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
652 switch (LOWORD(wParam))
655 break;
656 case WM_NOTIFY:
658 NMHDR* nmhdr = (NMHDR*)lParam;
659 int win_w, win_h, sb_w, sb_h;
660 BOOL st1, st2;
662 di = (struct dialog_info*)GetWindowLongPtrW(hDlg, DWLP_USER);
663 switch (nmhdr->code)
665 case PSN_SETACTIVE:
666 di->hDlg = hDlg;
667 break;
668 case PSN_APPLY:
669 sb_w = GetDlgItemInt(hDlg, IDC_CNF_SB_WIDTH, &st1, FALSE);
670 sb_h = GetDlgItemInt(hDlg, IDC_CNF_SB_HEIGHT, &st2, FALSE);
671 if (!st1 || ! st2)
673 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
674 return TRUE;
676 win_w = GetDlgItemInt(hDlg, IDC_CNF_WIN_WIDTH, &st1, FALSE);
677 win_h = GetDlgItemInt(hDlg, IDC_CNF_WIN_HEIGHT, &st2, FALSE);
678 if (!st1 || !st2)
680 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
681 return TRUE;
683 if (win_w > sb_w || win_h > sb_h)
685 WCHAR cap[256];
686 WCHAR txt[256];
688 LoadStringW(GetModuleHandleW(NULL), IDS_DLG_TIT_ERROR, cap, ARRAY_SIZE(cap));
689 LoadStringW(GetModuleHandleW(NULL), IDS_DLG_ERR_SBWINSIZE, txt, ARRAY_SIZE(txt));
691 MessageBoxW(hDlg, txt, cap, MB_OK);
692 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
693 return TRUE;
695 di->config.win_width = win_w;
696 di->config.win_height = win_h;
697 di->config.sb_width = sb_w;
698 di->config.sb_height = sb_h;
700 di->config.exit_on_die = IsDlgButtonChecked(hDlg, IDC_CNF_CLOSE_EXIT) ? 1 : 0;
701 di->config.edition_mode = SendDlgItemMessageW(hDlg, IDC_CNF_EDITION_MODE,
702 CB_GETCURSEL, 0, 0);
703 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
704 return TRUE;
705 default:
706 return FALSE;
708 break;
710 default:
711 return FALSE;
713 return TRUE;
716 /******************************************************************
717 * WCUSER_SaveDlgProc
719 * Dialog Procedure for choosing how to handle modification to the
720 * console settings.
722 static INT_PTR WINAPI WCUSER_SaveDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
724 switch (msg)
726 case WM_INITDIALOG:
727 SendDlgItemMessageW(hDlg, IDC_SAV_SESSION, BM_SETCHECK, BST_CHECKED, 0);
728 break;
729 case WM_COMMAND:
730 switch (LOWORD(wParam))
732 case IDOK:
733 EndDialog(hDlg,
734 (IsDlgButtonChecked(hDlg, IDC_SAV_SAVE) == BST_CHECKED) ?
735 IDC_SAV_SAVE : IDC_SAV_SESSION);
736 break;
737 case IDCANCEL:
738 EndDialog(hDlg, IDCANCEL); break;
740 break;
741 default:
742 return FALSE;
744 return TRUE;
747 /******************************************************************
748 * WCUSER_GetProperties
750 * Runs the dialog box to set up the wineconsole options
752 BOOL WCUSER_GetProperties(struct inner_data* data, BOOL current)
754 HPROPSHEETPAGE psPage[3];
755 PROPSHEETPAGEW psp;
756 PROPSHEETHEADERW psHead;
757 WCHAR buff[256];
758 WNDCLASSW wndclass;
759 static const WCHAR szFntPreview[] = {'W','i','n','e','C','o','n','F','o','n','t','P','r','e','v','i','e','w',0};
760 static const WCHAR szColorPreview[] = {'W','i','n','e','C','o','n','C','o','l','o','r','P','r','e','v','i','e','w',0};
761 struct dialog_info di;
762 struct config_data defcfg;
763 struct config_data* refcfg;
764 BOOL save, modify_session;
766 InitCommonControls();
768 di.data = data;
769 if (current)
771 refcfg = &data->curcfg;
772 save = FALSE;
774 else
776 WINECON_RegLoad(NULL, refcfg = &defcfg);
777 save = TRUE;
779 di.config = *refcfg;
780 di.nFont = 0;
781 di.font = NULL;
783 modify_session = FALSE;
785 wndclass.style = 0;
786 wndclass.lpfnWndProc = WCUSER_FontPreviewProc;
787 wndclass.cbClsExtra = 0;
788 wndclass.cbWndExtra = sizeof (DWORD_PTR); /* for hFont */
789 wndclass.hInstance = GetModuleHandleW(NULL);
790 wndclass.hIcon = 0;
791 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
792 wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
793 wndclass.lpszMenuName = NULL;
794 wndclass.lpszClassName = szFntPreview;
795 RegisterClassW(&wndclass);
797 wndclass.style = 0;
798 wndclass.lpfnWndProc = WCUSER_ColorPreviewProc;
799 wndclass.cbClsExtra = 0;
800 wndclass.cbWndExtra = sizeof(DWORD);
801 wndclass.hInstance = GetModuleHandleW(NULL);
802 wndclass.hIcon = 0;
803 wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
804 wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
805 wndclass.lpszMenuName = NULL;
806 wndclass.lpszClassName = szColorPreview;
807 RegisterClassW(&wndclass);
809 memset(&psp, 0, sizeof(psp));
810 psp.dwSize = sizeof(psp);
811 psp.dwFlags = 0;
812 psp.hInstance = wndclass.hInstance;
813 psp.lParam = (LPARAM)&di;
815 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_OPTION);
816 psp.pfnDlgProc = WCUSER_OptionDlgProc;
817 psPage[0] = CreatePropertySheetPageW(&psp);
819 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_FONT);
820 psp.pfnDlgProc = WCUSER_FontDlgProc;
821 psPage[1] = CreatePropertySheetPageW(&psp);
823 psp.u.pszTemplate = MAKEINTRESOURCEW(IDD_CONFIG);
824 psp.pfnDlgProc = WCUSER_ConfigDlgProc;
825 psPage[2] = CreatePropertySheetPageW(&psp);
827 memset(&psHead, 0, sizeof(psHead));
828 psHead.dwSize = sizeof(psHead);
830 if (!LoadStringW(GetModuleHandleW(NULL), (current) ? IDS_DLG_TIT_CURRENT : IDS_DLG_TIT_DEFAULT,
831 buff, ARRAY_SIZE(buff)))
833 buff[0] = 'S';
834 buff[1] = 'e';
835 buff[2] = 't';
836 buff[3] = 'u';
837 buff[4] = 'p';
838 buff[5] = '\0';
841 psHead.pszCaption = buff;
842 psHead.nPages = 3;
843 psHead.hwndParent = data->hWnd;
844 psHead.u3.phpage = psPage;
845 psHead.dwFlags = PSH_NOAPPLYNOW;
847 WINECON_DumpConfig("init", refcfg);
849 PropertySheetW(&psHead);
851 if (memcmp(refcfg, &di.config, sizeof(*refcfg)) == 0)
852 return TRUE;
854 WINECON_DumpConfig("ref", refcfg);
855 WINECON_DumpConfig("cur", &di.config);
856 if (refcfg == &data->curcfg)
858 switch (DialogBoxW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDD_SAVE_SETTINGS),
859 data->hWnd, WCUSER_SaveDlgProc))
861 case IDC_SAV_SAVE: save = TRUE; modify_session = TRUE; break;
862 case IDC_SAV_SESSION: modify_session = TRUE; break;
863 case IDCANCEL: break;
864 default: WINE_ERR("ooch\n");
868 if (modify_session) WINECON_SetConfig(data, &di.config);
869 if (save) WINECON_RegSave(&di.config);
871 return TRUE;