Add a few missing declarations.
[wine.git] / programs / winecfg / x11drvdlg.c
blob9756968f9f8faa36c3b2a39ef45f2d613ca64c95
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 char* buf, *bufindex;
50 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
52 enable(IDC_DESKTOP_WIDTH);
53 enable(IDC_DESKTOP_HEIGHT);
54 enable(IDC_DESKTOP_SIZE);
55 enable(IDC_DESKTOP_BY);
57 buf = get(keypath("x11drv"), "Desktop", "640x480");
58 bufindex = strchr(buf, 'x');
59 if (bufindex) {
60 *bufindex = 0;
61 ++bufindex;
62 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
63 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
64 } else {
65 WINE_TRACE("Desktop registry entry is malformed");
66 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
67 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
70 HeapFree(GetProcessHeap(), 0, buf);
72 else
74 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
76 disable(IDC_DESKTOP_WIDTH);
77 disable(IDC_DESKTOP_HEIGHT);
78 disable(IDC_DESKTOP_SIZE);
79 disable(IDC_DESKTOP_BY);
81 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
82 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
85 updating_ui = FALSE;
88 static void init_dialog (HWND dialog)
90 char* buf;
92 update_gui_for_desktop_mode(dialog);
94 updating_ui = TRUE;
96 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
97 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
98 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
99 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
100 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
102 buf = get(keypath("x11drv"), "ScreenDepth", "24");
103 if (strcmp(buf, "8") == 0)
104 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
105 else if (strcmp(buf, "16") == 0)
106 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
107 else if (strcmp(buf, "24") == 0)
108 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
109 else if (strcmp(buf, "32") == 0)
110 SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
111 else
112 WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
113 HeapFree(GetProcessHeap(), 0, buf);
115 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
116 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
118 buf = get(keypath("x11drv"), "DXGrab", "Y");
119 if (IS_OPTION_TRUE(*buf))
120 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
121 else
122 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
123 HeapFree(GetProcessHeap(), 0, buf);
125 buf = get(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
126 if (IS_OPTION_TRUE(*buf))
127 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
128 else
129 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
130 HeapFree(GetProcessHeap(), 0, buf);
132 updating_ui = FALSE;
135 static void set_from_desktop_edits(HWND dialog) {
136 char *width, *height, *new;
138 if (updating_ui) return;
140 WINE_TRACE("\n");
142 width = get_text(dialog, IDC_DESKTOP_WIDTH);
143 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
145 if (width == NULL || strcmp(width, "") == 0) {
146 HeapFree(GetProcessHeap(), 0, width);
147 width = strdupA("640");
150 if (height == NULL || strcmp(height, "") == 0) {
151 HeapFree(GetProcessHeap(), 0, height);
152 height = strdupA("480");
155 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
156 sprintf(new, "%sx%s", width, height);
157 set(keypath("x11drv"), "Desktop", new);
159 HeapFree(GetProcessHeap(), 0, width);
160 HeapFree(GetProcessHeap(), 0, height);
161 HeapFree(GetProcessHeap(), 0, new);
164 void on_enable_desktop_clicked(HWND dialog) {
165 WINE_TRACE("\n");
167 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
168 set_from_desktop_edits(dialog);
169 } else {
170 set(keypath("x11drv"), "Desktop", NULL);
173 update_gui_for_desktop_mode(dialog);
176 static void on_screen_depth_changed(HWND dialog) {
177 char *newvalue = get_text(dialog, IDC_SCREEN_DEPTH);
178 char *spaceIndex = strchr(newvalue, ' ');
180 WINE_TRACE("newvalue=%s\n", newvalue);
181 if (updating_ui) return;
183 *spaceIndex = '\0';
184 set(keypath("x11drv"), "ScreenDepth", newvalue);
185 HeapFree(GetProcessHeap(), 0, newvalue);
188 static void on_dx_mouse_grab_clicked(HWND dialog) {
189 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
190 set(keypath("x11drv"), "DXGrab", "Y");
191 else
192 set(keypath("x11drv"), "DXGrab", "N");
196 static void on_double_buffer_clicked(HWND dialog) {
197 if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED)
198 set(keypath("x11drv"), "DesktopDoubleBuffered", "Y");
199 else
200 set(keypath("x11drv"), "DesktopDoubleBuffered", "N");
203 INT_PTR CALLBACK
204 GraphDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
206 switch (uMsg) {
207 case WM_INITDIALOG:
208 break;
210 case WM_SHOWWINDOW:
211 set_window_title(hDlg);
212 break;
214 case WM_COMMAND:
215 switch(HIWORD(wParam)) {
216 case EN_CHANGE: {
217 if (updating_ui) break;
218 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
219 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
220 set_from_desktop_edits(hDlg);
221 break;
223 case BN_CLICKED: {
224 if (updating_ui) break;
225 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
226 switch(LOWORD(wParam)) {
227 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
228 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
229 case IDC_DOUBLE_BUFFER: on_double_buffer_clicked(hDlg); break;
231 break;
233 case CBN_SELCHANGE: {
234 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
235 if (LOWORD(wParam) == IDC_SCREEN_DEPTH) on_screen_depth_changed(hDlg);
236 break;
239 default:
240 break;
242 break;
245 case WM_NOTIFY:
246 switch (((LPNMHDR)lParam)->code) {
247 case PSN_KILLACTIVE: {
248 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
249 break;
251 case PSN_APPLY: {
252 apply();
253 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
254 break;
256 case PSN_SETACTIVE: {
257 init_dialog (hDlg);
258 break;
261 break;
263 default:
264 break;
266 return FALSE;