Always reset AUTO_RESIZE flag on exit from REBAR_ForceResize.
[wine/multimedia.git] / programs / winecfg / x11drvdlg.c
blob4a67112df0b84259530c5a3e8db3113a19676538
1 /*
2 * X11DRV configuration code
4 * Copyright 2003 Mark Westcott
5 * Copyright 2003 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
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <stdio.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winreg.h>
30 #include <wine/debug.h>
32 #include "resource.h"
33 #include "winecfg.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? */
38 #define section (appSettings == EDITING_GLOBAL ? "x11drv" : (getSectionForApp("x11drv")))
40 int updatingUI;
42 int appSettings = EDITING_GLOBAL; /* start by editing global */
43 char *currentApp; /* the app we are currently editing, or NULL if editing global */
45 char *getSectionForApp(char *pSection)
47 static char *lastResult = NULL;
48 if (lastResult) HeapFree(GetProcessHeap(), 0, lastResult);
49 lastResult = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(currentApp) + 2 /* \\ */ + strlen(pSection) + 1 /* terminator */);
50 sprintf(lastResult, "AppDefaults\\%s\\%s", currentApp, pSection);
51 return lastResult;
54 void updateGUIForDesktopMode(HWND dialog) {
55 WINE_TRACE("\n");
57 updatingUI = TRUE;
59 /* do we have desktop mode enabled? */
60 if (doesConfigValueExist(section, "Desktop") == S_OK) {
61 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
62 /* enable the controls */
63 enable(IDC_DESKTOP_WIDTH);
64 enable(IDC_DESKTOP_HEIGHT);
65 enable(IDC_DESKTOP_SIZE);
66 enable(IDC_DESKTOP_BY);
68 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
69 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
71 else {
72 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
73 /* disable the controls */
74 disable(IDC_DESKTOP_WIDTH);
75 disable(IDC_DESKTOP_HEIGHT);
76 disable(IDC_DESKTOP_SIZE);
77 disable(IDC_DESKTOP_BY);
79 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
80 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
83 updatingUI = FALSE;
86 /* pokes the win32 api to setup the dialog from the config struct */
87 void initX11DrvDlg (HWND hDlg)
89 static const char default_desktop[] = "640x480";
90 char *buf;
91 char *bufindex;
93 updateGUIForDesktopMode(hDlg);
95 updatingUI = TRUE;
97 /* desktop size */
98 buf = getConfigValue(section, "Desktop", default_desktop);
99 bufindex = strchr(buf, 'x');
100 if(!bufindex) /* handle invalid "Desktop" values */
102 free(buf);
103 buf = strdup(default_desktop);
104 bufindex = strchr(buf, 'x');
106 *bufindex = '\0';
107 bufindex++;
108 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
109 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex);
110 free(buf);
112 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
113 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
114 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
115 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
116 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
118 buf = getConfigValue(section, "ScreenDepth", "24");
119 if (strcmp(buf, "8") == 0)
120 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
121 else if (strcmp(buf, "16") == 0)
122 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
123 else if (strcmp(buf, "24") == 0)
124 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
125 else if (strcmp(buf, "32") == 0)
126 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
127 else
128 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
129 free(buf);
131 SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
132 SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
134 buf = getConfigValue(section, "DXGrab", "Y");
135 if (IS_OPTION_TRUE(*buf))
136 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED);
137 else
138 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
139 free(buf);
141 buf = getConfigValue(section, "DesktopDoubleBuffered", "Y");
142 if (IS_OPTION_TRUE(*buf))
143 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED);
144 else
145 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
146 free(buf);
148 buf = getConfigValue(section, "UseTakeFocus", "N");
149 if (IS_OPTION_TRUE(*buf))
150 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_CHECKED);
151 else
152 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_UNCHECKED);
153 free(buf);
155 updatingUI = FALSE;
160 void setFromDesktopSizeEdits(HWND hDlg) {
161 char *width = malloc(RES_MAXLEN+1);
162 char *height = malloc(RES_MAXLEN+1);
163 char *newStr = malloc((RES_MAXLEN*2) + 2);
165 if (updatingUI) return;
167 WINE_TRACE("\n");
169 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1);
170 GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1);
172 if (strcmp(width, "") == 0) strcpy(width, "640");
173 if (strcmp(height, "") == 0) strcpy(height, "480");
175 sprintf(newStr, "%sx%s", width, height);
176 addTransaction(section, "Desktop", ACTION_SET, newStr);
178 free(width);
179 free(height);
180 free(newStr);
183 void onEnableDesktopClicked(HWND hDlg) {
184 WINE_TRACE("\n");
185 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
186 /* it was just unchecked, so read the values of the edit boxes, set the config value */
187 setFromDesktopSizeEdits(hDlg);
188 } else {
189 /* it was just checked, so remove the config values */
190 addTransaction(section, "Desktop", ACTION_REMOVE, NULL);
192 updateGUIForDesktopMode(hDlg);
195 void onScreenDepthChanged(HWND hDlg) {
196 char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH);
197 char *spaceIndex = strchr(newvalue, ' ');
199 WINE_TRACE("newvalue=%s\n", newvalue);
200 if (updatingUI) return;
202 *spaceIndex = '\0';
203 addTransaction(section, "ScreenDepth", ACTION_SET, newvalue);
204 free(newvalue);
207 void onDXMouseGrabClicked(HWND hDlg) {
208 if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
209 addTransaction(section, "DXGrab", ACTION_SET, "Y");
210 else
211 addTransaction(section, "DXGrab", ACTION_SET, "N");
215 void onDoubleBufferClicked(HWND hDlg) {
216 if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED)
217 addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "Y");
218 else
219 addTransaction(section, "DesktopDoubleBuffered", ACTION_SET, "N");
222 void onUseTakeFocusClicked(HWND hDlg) {
223 if (IsDlgButtonChecked(hDlg, IDC_USE_TAKE_FOCUS) == BST_CHECKED)
224 addTransaction(section, "UseTakeFocus", ACTION_SET, "Y");
225 else
226 addTransaction(section, "UseTakeFocus", ACTION_SET, "N");
230 INT_PTR CALLBACK
231 X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
233 switch (uMsg) {
234 case WM_INITDIALOG:
235 break;
237 case WM_COMMAND:
238 switch(HIWORD(wParam)) {
239 case EN_CHANGE: {
240 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
241 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updatingUI )
242 setFromDesktopSizeEdits(hDlg);
243 break;
245 case BN_CLICKED: {
246 if (updatingUI) break;
247 switch(LOWORD(wParam)) {
248 case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
249 case IDC_DX_MOUSE_GRAB: onDXMouseGrabClicked(hDlg); break;
250 case IDC_USE_TAKE_FOCUS: onUseTakeFocusClicked(hDlg); break;
251 case IDC_DOUBLE_BUFFER: onDoubleBufferClicked(hDlg); break;
253 break;
255 case CBN_SELCHANGE: {
256 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg);
257 break;
260 default:
261 break;
263 break;
266 case WM_NOTIFY:
267 switch (((LPNMHDR)lParam)->code) {
268 case PSN_KILLACTIVE: {
269 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
270 break;
272 case PSN_APPLY: {
273 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
274 break;
276 case PSN_SETACTIVE: {
277 initX11DrvDlg (hDlg);
278 break;
281 break;
283 default:
284 break;
286 return FALSE;