Move Applications tab before Libraries tab.
[wine/wine64.git] / programs / winecfg / x11drvdlg.c
blobd256c7348ee1b63d96220975754a1a09fa5741d5
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 void updateGUIForDesktopMode(HWND dialog) {
43 WINE_TRACE("\n");
45 updatingUI = TRUE;
47 /* do we have desktop mode enabled? */
48 if (doesConfigValueExist("x11drv", "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");
59 else {
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), "");
71 updatingUI = FALSE;
74 /* pokes the win32 api to setup the dialog from the config struct */
75 void initX11DrvDlg (HWND hDlg)
77 char *buf;
78 char *bufindex;
80 updatingUI = TRUE;
82 updateGUIForDesktopMode(hDlg);
84 /* desktop size */
85 buf = getConfigValue("x11drv", "Desktop", "640x480");
86 bufindex = strchr(buf, 'x');
87 *bufindex = '\0';
88 bufindex++;
89 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
90 SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex);
91 free(buf);
93 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
94 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
95 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
96 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
98 buf = getConfigValue("x11drv", "ScreenDepth", "24");
99 if (strcmp(buf, "8") == 0)
100 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
101 else if (strcmp(buf, "16") == 0)
102 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
103 else if (strcmp(buf, "24") == 0)
104 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
105 else if (strcmp(buf, "32") == 0)
106 SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
107 else
108 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
109 free(buf);
111 SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
112 SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
114 buf = getConfigValue("x11drv", "DXGrab", "Y");
115 if (IS_OPTION_TRUE(*buf))
116 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED);
117 else
118 CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
119 free(buf);
121 buf = getConfigValue("x11drv", "DesktopDoubleBuffered", "Y");
122 if (IS_OPTION_TRUE(*buf))
123 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED);
124 else
125 CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
126 free(buf);
128 buf = getConfigValue("x11drv", "UseTakeFocus", "N");
129 if (IS_OPTION_TRUE(*buf))
130 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_CHECKED);
131 else
132 CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_UNCHECKED);
133 free(buf);
135 updatingUI = FALSE;
140 void setFromDesktopSizeEdits(HWND hDlg) {
141 char *width = malloc(RES_MAXLEN+1);
142 char *height = malloc(RES_MAXLEN+1);
143 char *newStr = malloc((RES_MAXLEN*2) + 2);
145 if (updatingUI) return;
147 WINE_TRACE("\n");
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(newStr, "%sx%s", width, height);
156 addTransaction("x11drv", "Desktop", ACTION_SET, newStr);
158 free(width);
159 free(height);
160 free(newStr);
163 void onEnableDesktopClicked(HWND hDlg) {
164 WINE_TRACE("\n");
165 if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
166 /* it was just unchecked, so read the values of the edit boxes, set the config value */
167 setFromDesktopSizeEdits(hDlg);
168 } else {
169 /* it was just checked, so remove the config values */
170 addTransaction("x11drv", "Desktop", ACTION_REMOVE, NULL);
172 updateGUIForDesktopMode(hDlg);
175 void onScreenDepthChanged(HWND hDlg) {
176 char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH);
177 char *spaceIndex = strchr(newvalue, ' ');
179 WINE_TRACE("newvalue=%s\n", newvalue);
180 if (updatingUI) return;
182 *spaceIndex = '\0';
183 addTransaction("x11drv", "ScreenDepth", ACTION_SET, newvalue);
184 free(newvalue);
187 void onDXMouseGrabClicked(HWND hDlg) {
188 if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
189 addTransaction("x11drv", "DXGrab", ACTION_SET, "Y");
190 else
191 addTransaction("x11drv", "DXGrab", ACTION_SET, "N");
195 void onDoubleBufferClicked(HWND hDlg) {
196 if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED)
197 addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "Y");
198 else
199 addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "N");
202 void onUseTakeFocusClicked(HWND hDlg) {
203 if (IsDlgButtonChecked(hDlg, IDC_USE_TAKE_FOCUS) == BST_CHECKED)
204 addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "Y");
205 else
206 addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "N");
210 INT_PTR CALLBACK
211 X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
213 switch (uMsg) {
214 case WM_INITDIALOG:
215 break;
217 case WM_COMMAND:
218 switch(HIWORD(wParam)) {
219 case EN_CHANGE: {
220 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
221 if ( (LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT) ) setFromDesktopSizeEdits(hDlg);
222 break;
224 case BN_CLICKED: {
225 WINE_TRACE("%d\n", LOWORD(wParam));
226 switch(LOWORD(wParam)) {
227 case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
228 case IDC_DX_MOUSE_GRAB: onDXMouseGrabClicked(hDlg); break;
229 case IDC_USE_TAKE_FOCUS: onUseTakeFocusClicked(hDlg); break;
230 case IDC_DOUBLE_BUFFER: onDoubleBufferClicked(hDlg); break;
232 break;
234 case CBN_SELCHANGE: {
235 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg);
236 break;
239 default:
240 break;
242 break;
245 case WM_NOTIFY:
246 switch (((LPNMHDR)lParam)->code) {
247 case PSN_KILLACTIVE: {
248 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
249 break;
251 case PSN_APPLY: {
252 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
253 break;
255 case PSN_SETACTIVE: {
256 initX11DrvDlg (hDlg);
257 break;
260 break;
262 default:
263 break;
265 return FALSE;