Updated Spanish resource.
[wine/multimedia.git] / programs / winecfg / x11drvdlg.c
blob0ac863feaf982481d74c2ad9ebf06e96dd06f226
1 /*
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
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? */
39 int updating_ui;
41 void update_gui_for_desktop_mode(HWND dialog) {
42 WINE_TRACE("\n");
44 updating_ui = TRUE;
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");
59 else
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), "");
72 updating_ui = FALSE;
75 static void init_dialog (HWND dialog)
77 static char *default_desktop = "640x480";
78 char *buf;
79 char *bufindex;
81 update_gui_for_desktop_mode(dialog);
83 updating_ui = TRUE;
85 /* desktop size */
86 buf = get(keypath("x11drv"), "Desktop", default_desktop);
87 bufindex = strchr(buf, 'x');
89 if(!bufindex) /* handle invalid "Desktop" values */
91 HeapFree(GetProcessHeap(), 0, buf);
92 buf = strdupA(default_desktop);
93 bufindex = strchr(buf, 'x');
96 *bufindex = '\0';
97 bufindex++;
98 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
99 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
100 HeapFree(GetProcessHeap(), 0, buf);
102 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
103 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
104 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
105 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
106 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
108 buf = get(keypath("x11drv"), "ScreenDepth", "24");
109 if (strcmp(buf, "8") == 0)
110 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
111 else if (strcmp(buf, "16") == 0)
112 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
113 else if (strcmp(buf, "24") == 0)
114 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
115 else if (strcmp(buf, "32") == 0)
116 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
117 else
118 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
119 HeapFree(GetProcessHeap(), 0, buf);
121 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
122 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
124 buf = get(keypath("x11drv"), "DXGrab", "Y");
125 if (IS_OPTION_TRUE(*buf))
126 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
127 else
128 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
129 HeapFree(GetProcessHeap(), 0, buf);
131 buf = get(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
132 if (IS_OPTION_TRUE(*buf))
133 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
134 else
135 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
136 HeapFree(GetProcessHeap(), 0, buf);
138 updating_ui = FALSE;
141 static void set_from_desktop_edits(HWND dialog) {
142 char *width, *height, *new;
144 if (updating_ui) return;
146 WINE_TRACE("\n");
148 width = get_text(dialog, IDC_DESKTOP_WIDTH);
149 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
151 if (strcmp(width, "") == 0)
153 HeapFree(GetProcessHeap(), 0, width);
154 width = strdupA("640");
157 if (strcmp(height, "") == 0)
159 HeapFree(GetProcessHeap(), 0, height);
160 height = strdupA("480");
163 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
164 sprintf(new, "%sx%s", width, height);
165 set(keypath("x11drv"), "Desktop", new);
167 HeapFree(GetProcessHeap(), 0, width);
168 HeapFree(GetProcessHeap(), 0, height);
169 HeapFree(GetProcessHeap(), 0, new);
172 void on_enable_desktop_clicked(HWND dialog) {
173 WINE_TRACE("\n");
175 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
176 /* it was just unchecked, so read the values of the edit boxes, set the config value */
177 set_from_desktop_edits(dialog);
178 } else {
179 /* it was just checked, so remove the config values */
180 set(keypath("x11drv"), "Desktop", NULL);
183 update_gui_for_desktop_mode(dialog);
186 static void on_screen_depth_changed(HWND dialog) {
187 char *newvalue = get_text(dialog, IDC_SCREEN_DEPTH);
188 char *spaceIndex = strchr(newvalue, ' ');
190 WINE_TRACE("newvalue=%s\n", newvalue);
191 if (updating_ui) return;
193 *spaceIndex = '\0';
194 set(keypath("x11drv"), "ScreenDepth", newvalue);
195 HeapFree(GetProcessHeap(), 0, newvalue);
198 static void on_dx_mouse_grab_clicked(HWND dialog) {
199 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
200 set(keypath("x11drv"), "DXGrab", "Y");
201 else
202 set(keypath("x11drv"), "DXGrab", "N");
206 static void on_double_buffer_clicked(HWND dialog) {
207 if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED)
208 set(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
209 else
210 set(keypath("x11drv"), "DesktopDoubleBuffered", "N");
213 INT_PTR CALLBACK
214 GraphDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
216 switch (uMsg) {
217 case WM_INITDIALOG:
218 break;
220 case WM_SHOWWINDOW:
221 set_window_title(hDlg);
222 break;
224 case WM_COMMAND:
225 switch(HIWORD(wParam)) {
226 case EN_CHANGE: {
227 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
228 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
229 set_from_desktop_edits(hDlg);
230 break;
232 case BN_CLICKED: {
233 if (updating_ui) break;
234 switch(LOWORD(wParam)) {
235 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
236 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
237 case IDC_DOUBLE_BUFFER: on_double_buffer_clicked(hDlg); break;
239 break;
241 case CBN_SELCHANGE: {
242 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) on_screen_depth_changed(hDlg);
243 break;
246 default:
247 break;
249 break;
252 case WM_NOTIFY:
253 switch (((LPNMHDR)lParam)->code) {
254 case PSN_KILLACTIVE: {
255 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
256 break;
258 case PSN_APPLY: {
259 apply();
260 SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
261 break;
263 case PSN_SETACTIVE: {
264 init_dialog (hDlg);
265 break;
268 break;
270 default:
271 break;
273 return FALSE;