2 * Graphics configuration code
4 * Copyright 2003 Mark Westcott
5 * Copyright 2003-2004 Mike Hearn
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <wine/debug.h>
35 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
37 #define RES_MAXLEN 5 /* the maximum number of characters in a screen dimension. 5 digits should be plenty, what kind of crazy person runs their screen >10,000 pixels across? */
41 static void update_gui_for_desktop_mode(HWND dialog) {
46 /* do we have desktop mode enabled? */
47 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
50 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
52 enable(IDC_DESKTOP_WIDTH);
53 enable(IDC_DESKTOP_HEIGHT);
54 enable(IDC_DESKTOP_SIZE);
55 enable(IDC_DESKTOP_BY);
57 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
58 bufindex = strchr(buf, 'x');
62 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
63 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
65 WINE_TRACE("Desktop registry entry is malformed");
66 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
67 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
70 HeapFree(GetProcessHeap(), 0, buf);
74 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
76 disable(IDC_DESKTOP_WIDTH);
77 disable(IDC_DESKTOP_HEIGHT);
78 disable(IDC_DESKTOP_SIZE);
79 disable(IDC_DESKTOP_BY);
81 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
82 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
88 static void init_dialog (HWND dialog)
92 update_gui_for_desktop_mode(dialog);
96 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
97 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
98 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
99 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
100 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
102 buf = get_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", "24");
103 if (strcmp(buf, "8") == 0)
104 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
105 else if (strcmp(buf, "16") == 0)
106 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
107 else if (strcmp(buf, "24") == 0)
108 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
109 else if (strcmp(buf, "32") == 0)
110 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
112 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
113 HeapFree(GetProcessHeap(), 0, buf);
115 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
116 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
118 buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
119 if (IS_OPTION_TRUE(*buf))
120 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
122 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
123 HeapFree(GetProcessHeap(), 0, buf);
125 buf = get_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
126 if (IS_OPTION_TRUE(*buf))
127 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
129 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
130 HeapFree(GetProcessHeap(), 0, buf);
135 static void set_from_desktop_edits(HWND dialog) {
136 char *width, *height, *new;
138 if (updating_ui) return;
142 width = get_text(dialog, IDC_DESKTOP_WIDTH);
143 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
145 if (width == NULL || strcmp(width, "") == 0) {
146 HeapFree(GetProcessHeap(), 0, width);
147 width = strdupA("640");
150 if (height == NULL || strcmp(height, "") == 0) {
151 HeapFree(GetProcessHeap(), 0, height);
152 height = strdupA("480");
155 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
156 sprintf(new, "%sx%s", width, height);
157 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
159 HeapFree(GetProcessHeap(), 0, width);
160 HeapFree(GetProcessHeap(), 0, height);
161 HeapFree(GetProcessHeap(), 0, new);
164 static void on_enable_desktop_clicked(HWND dialog) {
167 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
168 set_from_desktop_edits(dialog);
170 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
173 update_gui_for_desktop_mode(dialog);
176 static void on_screen_depth_changed(HWND dialog) {
177 char *newvalue = get_text(dialog, IDC_SCREEN_DEPTH);
178 char *spaceIndex = strchr(newvalue, ' ');
180 WINE_TRACE("newvalue=%s\n", newvalue);
181 if (updating_ui) return;
184 set_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", newvalue);
185 HeapFree(GetProcessHeap(), 0, newvalue);
188 static void on_dx_mouse_grab_clicked(HWND dialog) {
189 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
190 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
192 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
196 static void on_double_buffer_clicked(HWND dialog) {
197 if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED)
198 set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
200 set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "N");
204 GraphDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
211 set_window_title(hDlg);
215 switch(HIWORD(wParam)) {
217 if (updating_ui) break;
218 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
219 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
220 set_from_desktop_edits(hDlg);
224 if (updating_ui) break;
225 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
226 switch(LOWORD(wParam)) {
227 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
228 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
229 case IDC_DOUBLE_BUFFER: on_double_buffer_clicked(hDlg); break;
233 case CBN_SELCHANGE: {
234 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
235 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) on_screen_depth_changed(hDlg);
246 switch (((LPNMHDR)lParam)->code) {
247 case PSN_KILLACTIVE: {
248 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
253 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
256 case PSN_SETACTIVE: {