blob: c46a531b254bc1efc41b90ac3b2ca4c91604ac4c [file] [log] [blame]
Alexandre Julliard3db78b82003-08-30 00:40:46 +00001/*
2 * X11DRV configuration code
3 *
4 * Copyright 2003 Mark Westcott
5 * Copyright 2003 Mike Hearn
6 *
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.
11 *
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.
16 *
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
20 *
21 */
22
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000023#include <stdarg.h>
Alexandre Julliard3db78b82003-08-30 00:40:46 +000024#include <stdlib.h>
25#include <stdio.h>
26
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000027#include <windef.h>
28#include <winbase.h>
29#include <winreg.h>
30#include <wine/debug.h>
31
Alexandre Julliard3db78b82003-08-30 00:40:46 +000032#include "resource.h"
33#include "winecfg.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
36
Mike Hearncd0b7892003-09-08 18:58:07 +000037#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? */
Mike Hearn498e1ce2003-09-30 00:27:55 +000038#define section (appSettings == EDITING_GLOBAL ? "x11drv" : (getSectionForApp("x11drv")))
Mike Hearncd0b7892003-09-08 18:58:07 +000039
40int updatingUI;
41
Mike Hearn498e1ce2003-09-30 00:27:55 +000042void updateGUIForDesktopMode(HWND dialog) {
Mike Hearncd0b7892003-09-08 18:58:07 +000043 WINE_TRACE("\n");
44
45 updatingUI = TRUE;
46
47 /* do we have desktop mode enabled? */
Mike Hearnf3889772003-10-22 00:01:46 +000048 if (doesConfigValueExist(section, "Desktop") == S_OK) {
Mike Hearn498e1ce2003-09-30 00:27:55 +000049 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
Mike Hearncd0b7892003-09-08 18:58:07 +000050 /* enable the controls */
Mike Hearn498e1ce2003-09-30 00:27:55 +000051 enable(IDC_DESKTOP_WIDTH);
52 enable(IDC_DESKTOP_HEIGHT);
53 enable(IDC_DESKTOP_SIZE);
54 enable(IDC_DESKTOP_BY);
55
56 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
57 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
Mike Hearncd0b7892003-09-08 18:58:07 +000058 }
59 else {
Mike Hearn498e1ce2003-09-30 00:27:55 +000060 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
Mike Hearncd0b7892003-09-08 18:58:07 +000061 /* disable the controls */
Mike Hearn498e1ce2003-09-30 00:27:55 +000062 disable(IDC_DESKTOP_WIDTH);
63 disable(IDC_DESKTOP_HEIGHT);
64 disable(IDC_DESKTOP_SIZE);
65 disable(IDC_DESKTOP_BY);
Mike Hearncd0b7892003-09-08 18:58:07 +000066
Mike Hearn498e1ce2003-09-30 00:27:55 +000067 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
68 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
Mike Hearncd0b7892003-09-08 18:58:07 +000069 }
70
71 updatingUI = FALSE;
72}
73
Alexandre Julliard3db78b82003-08-30 00:40:46 +000074/* pokes the win32 api to setup the dialog from the config struct */
75void initX11DrvDlg (HWND hDlg)
76{
Mike Hearncd0b7892003-09-08 18:58:07 +000077 char *buf;
Mike Hearn81be7f72003-09-22 19:26:10 +000078 char *bufindex;
Alexandre Julliard3db78b82003-08-30 00:40:46 +000079
Mike Hearnf3889772003-10-22 00:01:46 +000080 updateGUIForDesktopMode(hDlg);
81
Mike Hearncd0b7892003-09-08 18:58:07 +000082 updatingUI = TRUE;
83
Alexandre Julliard3db78b82003-08-30 00:40:46 +000084 /* desktop size */
Mike Hearnf3889772003-10-22 00:01:46 +000085 buf = getConfigValue(section, "Desktop", "640x480");
Mike Hearn81be7f72003-09-22 19:26:10 +000086 bufindex = strchr(buf, 'x');
87 *bufindex = '\0';
88 bufindex++;
Mike Hearncd0b7892003-09-08 18:58:07 +000089 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
Mike Hearn81be7f72003-09-22 19:26:10 +000090 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex);
91 free(buf);
Mike Hearnf3889772003-10-22 00:01:46 +000092
93 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
Mike Hearn81be7f72003-09-22 19:26:10 +000094 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
95 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
96 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
97 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
98
Mike Hearnf3889772003-10-22 00:01:46 +000099 buf = getConfigValue(section, "ScreenDepth", "24");
Mike Hearn81be7f72003-09-22 19:26:10 +0000100 if (strcmp(buf, "8") == 0)
101 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
102 else if (strcmp(buf, "16") == 0)
103 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
104 else if (strcmp(buf, "24") == 0)
105 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
106 else if (strcmp(buf, "32") == 0)
107 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
108 else
109 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
Mike Hearncd0b7892003-09-08 18:58:07 +0000110 free(buf);
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000111
Mike Hearncd0b7892003-09-08 18:58:07 +0000112 SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
Mike Hearn5d249cb2003-09-18 04:32:01 +0000113 SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
114
Mike Hearnf3889772003-10-22 00:01:46 +0000115 buf = getConfigValue(section, "DXGrab", "Y");
Mike Hearn5d249cb2003-09-18 04:32:01 +0000116 if (IS_OPTION_TRUE(*buf))
Mike Hearnfae915f2003-09-22 21:13:51 +0000117 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED);
Mike Hearn5d249cb2003-09-18 04:32:01 +0000118 else
Mike Hearnfae915f2003-09-22 21:13:51 +0000119 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
120 free(buf);
121
Mike Hearnf3889772003-10-22 00:01:46 +0000122 buf = getConfigValue(section, "DesktopDoubleBuffered", "Y");
Mike Hearnfae915f2003-09-22 21:13:51 +0000123 if (IS_OPTION_TRUE(*buf))
124 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED);
125 else
126 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
127 free(buf);
128
Mike Hearnf3889772003-10-22 00:01:46 +0000129 buf = getConfigValue(section, "UseTakeFocus", "N");
Mike Hearnfae915f2003-09-22 21:13:51 +0000130 if (IS_OPTION_TRUE(*buf))
131 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_CHECKED);
132 else
133 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_UNCHECKED);
134 free(buf);
Mike Hearncd0b7892003-09-08 18:58:07 +0000135
136 updatingUI = FALSE;
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000137}
138
Mike Hearncd0b7892003-09-08 18:58:07 +0000139
140
141void setFromDesktopSizeEdits(HWND hDlg) {
142 char *width = malloc(RES_MAXLEN+1);
143 char *height = malloc(RES_MAXLEN+1);
144 char *newStr = malloc((RES_MAXLEN*2) + 2);
145
146 if (updatingUI) return;
147
148 WINE_TRACE("\n");
149
150 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1);
151 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1);
152
153 if (strcmp(width, "") == 0) strcpy(width, "640");
154 if (strcmp(height, "") == 0) strcpy(height, "480");
155
156 sprintf(newStr, "%sx%s", width, height);
Mike Hearnf3889772003-10-22 00:01:46 +0000157 addTransaction(section, "Desktop", ACTION_SET, newStr);
Mike Hearncd0b7892003-09-08 18:58:07 +0000158
159 free(width);
160 free(height);
161 free(newStr);
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000162}
163
Mike Hearncd0b7892003-09-08 18:58:07 +0000164void onEnableDesktopClicked(HWND hDlg) {
165 WINE_TRACE("\n");
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);
169 } else {
170 /* it was just checked, so remove the config values */
Mike Hearnf3889772003-10-22 00:01:46 +0000171 addTransaction(section, "Desktop", ACTION_REMOVE, NULL);
Mike Hearncd0b7892003-09-08 18:58:07 +0000172 }
173 updateGUIForDesktopMode(hDlg);
174}
Mike Hearn5d249cb2003-09-18 04:32:01 +0000175
Mike Hearn81be7f72003-09-22 19:26:10 +0000176void onScreenDepthChanged(HWND hDlg) {
177 char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH);
178 char *spaceIndex = strchr(newvalue, ' ');
Mike Hearncd0b7892003-09-08 18:58:07 +0000179
Mike Hearn81be7f72003-09-22 19:26:10 +0000180 WINE_TRACE("newvalue=%s\n", newvalue);
Mike Hearn5d249cb2003-09-18 04:32:01 +0000181 if (updatingUI) return;
Mike Hearn5d249cb2003-09-18 04:32:01 +0000182
Mike Hearn81be7f72003-09-22 19:26:10 +0000183 *spaceIndex = '\0';
Mike Hearnf3889772003-10-22 00:01:46 +0000184 addTransaction(section, "ScreenDepth", ACTION_SET, newvalue);
Mike Hearn5d249cb2003-09-18 04:32:01 +0000185 free(newvalue);
186}
187
Mike Hearnfae915f2003-09-22 21:13:51 +0000188void onDXMouseGrabClicked(HWND hDlg) {
189 if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
Mike Hearnf3889772003-10-22 00:01:46 +0000190 addTransaction(section, "DXGrab", ACTION_SET, "Y");
Mike Hearn5d249cb2003-09-18 04:32:01 +0000191 else
Mike Hearnf3889772003-10-22 00:01:46 +0000192 addTransaction(section, "DXGrab", ACTION_SET, "N");
Mike Hearn5d249cb2003-09-18 04:32:01 +0000193}
194
Mike Hearnfae915f2003-09-22 21:13:51 +0000195
196void onDoubleBufferClicked(HWND hDlg) {
197 if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED)
Mike Hearnf3889772003-10-22 00:01:46 +0000198 addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "Y");
Mike Hearnfae915f2003-09-22 21:13:51 +0000199 else
Mike Hearnf3889772003-10-22 00:01:46 +0000200 addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "N");
Mike Hearnfae915f2003-09-22 21:13:51 +0000201}
202
203void onUseTakeFocusClicked(HWND hDlg) {
204 if (IsDlgButtonChecked(hDlg, IDC_USE_TAKE_FOCUS) == BST_CHECKED)
Mike Hearnf3889772003-10-22 00:01:46 +0000205 addTransaction(section, "UseTakeFocus", ACTION_SET, "Y");
Mike Hearnfae915f2003-09-22 21:13:51 +0000206 else
Mike Hearnf3889772003-10-22 00:01:46 +0000207 addTransaction(section, "UseTakeFocus", ACTION_SET, "N");
Mike Hearnfae915f2003-09-22 21:13:51 +0000208}
209
210
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000211INT_PTR CALLBACK
212X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
213{
214 switch (uMsg) {
215 case WM_INITDIALOG:
216 break;
Mike Hearncd0b7892003-09-08 18:58:07 +0000217
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000218 case WM_COMMAND:
219 switch(HIWORD(wParam)) {
220 case EN_CHANGE: {
221 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
Mike Hearnf3889772003-10-22 00:01:46 +0000222 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updatingUI )
223 setFromDesktopSizeEdits(hDlg);
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000224 break;
225 }
Mike Hearncd0b7892003-09-08 18:58:07 +0000226 case BN_CLICKED: {
Mike Hearnf3889772003-10-22 00:01:46 +0000227 if (updatingUI) break;
Mike Hearncd0b7892003-09-08 18:58:07 +0000228 switch(LOWORD(wParam)) {
229 case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
Mike Hearnfae915f2003-09-22 21:13:51 +0000230 case IDC_DX_MOUSE_GRAB: onDXMouseGrabClicked(hDlg); break;
231 case IDC_USE_TAKE_FOCUS: onUseTakeFocusClicked(hDlg); break;
232 case IDC_DOUBLE_BUFFER: onDoubleBufferClicked(hDlg); break;
Mike Hearncd0b7892003-09-08 18:58:07 +0000233 };
234 break;
235 }
Mike Hearn81be7f72003-09-22 19:26:10 +0000236 case CBN_SELCHANGE: {
237 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg);
238 break;
239 }
Mike Hearncd0b7892003-09-08 18:58:07 +0000240
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000241 default:
242 break;
243 }
244 break;
Mike Hearncd0b7892003-09-08 18:58:07 +0000245
246
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000247 case WM_NOTIFY:
248 switch (((LPNMHDR)lParam)->code) {
249 case PSN_KILLACTIVE: {
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000250 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
251 break;
252 }
253 case PSN_APPLY: {
Alexandre Julliard3db78b82003-08-30 00:40:46 +0000254 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
255 break;
256 }
257 case PSN_SETACTIVE: {
258 initX11DrvDlg (hDlg);
259 break;
260 }
261 }
262 break;
263
264 default:
265 break;
266 }
267 return FALSE;
268}