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
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? */
41 void update_gui_for_desktop_mode(HWND dialog
) {
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");
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
), "");
75 static void init_dialog (HWND dialog
)
77 static char *default_desktop
= "640x480";
81 update_gui_for_desktop_mode(dialog
);
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');
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);
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
);
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
);
135 CheckDlgButton(dialog
, IDC_DOUBLE_BUFFER
, BST_UNCHECKED
);
136 HeapFree(GetProcessHeap(), 0, buf
);
141 static void set_from_desktop_edits(HWND dialog
) {
142 char *width
, *height
, *new;
144 if (updating_ui
) return;
148 width
= get_control_text(dialog
, IDC_DESKTOP_WIDTH
);
149 height
= get_control_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
) {
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
);
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_control_text(dialog
, IDC_SCREEN_DEPTH
);
188 char *spaceIndex
= strchr(newvalue
, ' ');
190 WINE_TRACE("newvalue=%s\n", newvalue
);
191 if (updating_ui
) return;
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");
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");
210 set(keypath("x11drv"), "DesktopDoubleBuffered", "N");
214 GraphDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
221 set_window_title(hDlg
);
225 switch(HIWORD(wParam
)) {
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
);
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;
241 case CBN_SELCHANGE
: {
242 if (LOWORD(wParam
) == IDC_SCREEN_DEPTH
) on_screen_depth_changed(hDlg
);
253 switch (((LPNMHDR
)lParam
)->code
) {
254 case PSN_KILLACTIVE
: {
255 SetWindowLong(hDlg
, DWL_MSGRESULT
, FALSE
);
260 SetWindowLong(hDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
263 case PSN_SETACTIVE
: {