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 void update_gui_for_desktop_mode(HWND dialog) {
46 /* do we have desktop mode enabled? */
47 if (exists(keypath("x11drv"), "Desktop"))
49 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
51 enable(IDC_DESKTOP_WIDTH);
52 enable(IDC_DESKTOP_HEIGHT);
53 enable(IDC_DESKTOP_SIZE);
54 enable(IDC_DESKTOP_BY);
56 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
57 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
61 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
63 disable(IDC_DESKTOP_WIDTH);
64 disable(IDC_DESKTOP_HEIGHT);
65 disable(IDC_DESKTOP_SIZE);
66 disable(IDC_DESKTOP_BY);
68 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
69 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
75 /* pokes the win32 api to setup the dialog from the config struct */
76 void initGraphDlg (HWND hDlg)
78 static char *default_desktop = "640x480";
82 update_gui_for_desktop_mode(hDlg);
87 buf = get(keypath("x11drv"), "Desktop", default_desktop);
88 bufindex = strchr(buf, 'x');
89 if(!bufindex) /* handle invalid "Desktop" values */
92 buf = strdup(default_desktop);
93 bufindex = strchr(buf, 'x');
97 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
98 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex);
99 HeapFree(GetProcessHeap(), 0, buf);
101 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
102 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
103 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
104 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
105 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
107 buf = get(keypath("x11drv"), "ScreenDepth", "24");
108 if (strcmp(buf, "8") == 0)
109 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
110 else if (strcmp(buf, "16") == 0)
111 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
112 else if (strcmp(buf, "24") == 0)
113 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
114 else if (strcmp(buf, "32") == 0)
115 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
117 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
118 HeapFree(GetProcessHeap(), 0, buf);
120 SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
121 SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
123 buf = get(keypath("x11drv"), "DXGrab", "Y");
124 if (IS_OPTION_TRUE(*buf))
125 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED);
127 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
128 HeapFree(GetProcessHeap(), 0, buf);
130 buf = get(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
131 if (IS_OPTION_TRUE(*buf))
132 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED);
134 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
135 HeapFree(GetProcessHeap(), 0, buf);
140 void setFromDesktopSizeEdits(HWND hDlg) {
141 char *width = HeapAlloc(GetProcessHeap(), 0, RES_MAXLEN+1);
142 char *height = HeapAlloc(GetProcessHeap(), 0, RES_MAXLEN+1);
143 char *new = HeapAlloc(GetProcessHeap(), 0, (RES_MAXLEN*2) + 2);
145 if (updating_ui) goto end;
149 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1);
150 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1);
152 if (strcmp(width, "") == 0) strcpy(width, "640");
153 if (strcmp(height, "") == 0) strcpy(height, "480");
155 sprintf(new, "%sx%s", width, height);
156 set(keypath("x11drv"), "Desktop", new);
159 HeapFree(GetProcessHeap(), 0, width);
160 HeapFree(GetProcessHeap(), 0, height);
161 HeapFree(GetProcessHeap(), 0, new);
164 void onEnableDesktopClicked(HWND hDlg) {
166 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
167 /* it was just unchecked, so read the values of the edit boxes, set the config value */
168 setFromDesktopSizeEdits(hDlg);
170 /* it was just checked, so remove the config values */
171 set(keypath("x11drv"), "Desktop", NULL);
173 update_gui_for_desktop_mode(hDlg);
176 void onScreenDepthChanged(HWND hDlg) {
177 char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH);
178 char *spaceIndex = strchr(newvalue, ' ');
180 WINE_TRACE("newvalue=%s\n", newvalue);
181 if (updating_ui) return;
184 set(keypath("x11drv"), "ScreenDepth", newvalue);
188 void onDXMouseGrabClicked(HWND hDlg) {
189 if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
190 set(keypath("x11drv"), "DXGrab", "Y");
192 set(keypath("x11drv"), "DXGrab", "N");
196 void onDoubleBufferClicked(HWND hDlg) {
197 if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED)
198 set(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
200 set(keypath("x11drv"), "DesktopDoubleBuffered", "N");
204 GraphDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
211 set_window_title(hDlg);
215 switch(HIWORD(wParam)) {
217 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
218 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
219 setFromDesktopSizeEdits(hDlg);
223 if (updating_ui) break;
224 switch(LOWORD(wParam)) {
225 case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
226 case IDC_DX_MOUSE_GRAB: onDXMouseGrabClicked(hDlg); break;
227 case IDC_DOUBLE_BUFFER: onDoubleBufferClicked(hDlg); break;
231 case CBN_SELCHANGE: {
232 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg);
243 switch (((LPNMHDR)lParam)->code) {
244 case PSN_KILLACTIVE: {
245 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
250 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
253 case PSN_SETACTIVE: {