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
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? */
38 #define section (appSettings == EDITING_GLOBAL ? "x11drv" : (getSectionForApp("x11drv")))
42 void updateGUIForDesktopMode(HWND dialog
) {
47 /* do we have desktop mode enabled? */
48 if (doesConfigValueExist(section
, "Desktop") == S_OK
) {
49 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_CHECKED
);
50 /* enable the controls */
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");
60 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_UNCHECKED
);
61 /* disable the controls */
62 disable(IDC_DESKTOP_WIDTH
);
63 disable(IDC_DESKTOP_HEIGHT
);
64 disable(IDC_DESKTOP_SIZE
);
65 disable(IDC_DESKTOP_BY
);
67 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), "");
68 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), "");
74 /* pokes the win32 api to setup the dialog from the config struct */
75 void initX11DrvDlg (HWND hDlg
)
80 updateGUIForDesktopMode(hDlg
);
85 buf
= getConfigValue(section
, "Desktop", "640x480");
86 bufindex
= strchr(buf
, 'x');
89 SetWindowText(GetDlgItem(hDlg
, IDC_DESKTOP_WIDTH
), buf
);
90 SetWindowText(GetDlgItem(hDlg
, IDC_DESKTOP_HEIGHT
), bufindex
);
93 SendDlgItemMessage(hDlg
, IDC_SCREEN_DEPTH
, CB_RESETCONTENT
, 0, 0);
94 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? */
99 buf
= getConfigValue(section
, "ScreenDepth", "24");
100 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);
109 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf
);
112 SendDlgItemMessage(hDlg
, IDC_DESKTOP_WIDTH
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
113 SendDlgItemMessage(hDlg
, IDC_DESKTOP_HEIGHT
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
115 buf
= getConfigValue(section
, "DXGrab", "Y");
116 if (IS_OPTION_TRUE(*buf
))
117 CheckDlgButton(hDlg
, IDC_DX_MOUSE_GRAB
, BST_CHECKED
);
119 CheckDlgButton(hDlg
, IDC_DX_MOUSE_GRAB
, BST_UNCHECKED
);
122 buf
= getConfigValue(section
, "DesktopDoubleBuffered", "Y");
123 if (IS_OPTION_TRUE(*buf
))
124 CheckDlgButton(hDlg
, IDC_DOUBLE_BUFFER
, BST_CHECKED
);
126 CheckDlgButton(hDlg
, IDC_DOUBLE_BUFFER
, BST_UNCHECKED
);
129 buf
= getConfigValue(section
, "UseTakeFocus", "N");
130 if (IS_OPTION_TRUE(*buf
))
131 CheckDlgButton(hDlg
, IDC_USE_TAKE_FOCUS
, BST_CHECKED
);
133 CheckDlgButton(hDlg
, IDC_USE_TAKE_FOCUS
, BST_UNCHECKED
);
141 void 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);
146 if (updatingUI
) return;
150 GetWindowText(GetDlgItem(hDlg
, IDC_DESKTOP_WIDTH
), width
, RES_MAXLEN
+1);
151 GetWindowText(GetDlgItem(hDlg
, IDC_DESKTOP_HEIGHT
), height
, RES_MAXLEN
+1);
153 if (strcmp(width
, "") == 0) strcpy(width
, "640");
154 if (strcmp(height
, "") == 0) strcpy(height
, "480");
156 sprintf(newStr
, "%sx%s", width
, height
);
157 addTransaction(section
, "Desktop", ACTION_SET
, newStr
);
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 addTransaction(section
, "Desktop", ACTION_REMOVE
, NULL
);
173 updateGUIForDesktopMode(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 (updatingUI
) return;
184 addTransaction(section
, "ScreenDepth", ACTION_SET
, newvalue
);
188 void onDXMouseGrabClicked(HWND hDlg
) {
189 if (IsDlgButtonChecked(hDlg
, IDC_DX_MOUSE_GRAB
) == BST_CHECKED
)
190 addTransaction(section
, "DXGrab", ACTION_SET
, "Y");
192 addTransaction(section
, "DXGrab", ACTION_SET
, "N");
196 void onDoubleBufferClicked(HWND hDlg
) {
197 if (IsDlgButtonChecked(hDlg
, IDC_DOUBLE_BUFFER
) == BST_CHECKED
)
198 addTransaction(section
, "DesktopDoubleBuffered", ACTION_SET
, "Y");
200 addTransaction(section
, "DesktopDoubleBuffered", ACTION_SET
, "N");
203 void onUseTakeFocusClicked(HWND hDlg
) {
204 if (IsDlgButtonChecked(hDlg
, IDC_USE_TAKE_FOCUS
) == BST_CHECKED
)
205 addTransaction(section
, "UseTakeFocus", ACTION_SET
, "Y");
207 addTransaction(section
, "UseTakeFocus", ACTION_SET
, "N");
212 X11DrvDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
219 switch(HIWORD(wParam
)) {
221 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
222 if ( ((LOWORD(wParam
) == IDC_DESKTOP_WIDTH
) || (LOWORD(wParam
) == IDC_DESKTOP_HEIGHT
)) && !updatingUI
)
223 setFromDesktopSizeEdits(hDlg
);
227 if (updatingUI
) break;
228 switch(LOWORD(wParam
)) {
229 case IDC_ENABLE_DESKTOP
: onEnableDesktopClicked(hDlg
); break;
230 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;
236 case CBN_SELCHANGE
: {
237 if (LOWORD(wParam
) == IDC_SCREEN_DEPTH
) onScreenDepthChanged(hDlg
);
248 switch (((LPNMHDR
)lParam
)->code
) {
249 case PSN_KILLACTIVE
: {
250 SetWindowLong(hDlg
, DWL_MSGRESULT
, FALSE
);
254 SetWindowLong(hDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
257 case PSN_SETACTIVE
: {
258 initX11DrvDlg (hDlg
);