- Remove "PerfectGraphics", "Use XSHM extension", and "Use a private
[wine] / programs / winecfg / x11drvdlg.c
1 /*
2  * X11DRV configuration code
3  *
4  * Copyright 2003 Mark Westcott
5  * Copyright 2003 Mike Hearn
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winreg.h>
30 #include <wine/debug.h>
31
32 #include "resource.h"
33 #include "winecfg.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
36
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
39 int updatingUI;
40
41 void updateGUIForDesktopMode(HWND hDlg) {
42     WINE_TRACE("\n");
43
44     updatingUI = TRUE;
45     
46     /* do we have desktop mode enabled? */
47     if (doesConfigValueExist("x11drv", "Desktop") == S_OK) {
48         CheckDlgButton(hDlg, IDC_ENABLE_DESKTOP, BST_CHECKED);
49         /* enable the controls */
50         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), 1);
51         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), 1);
52         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_SIZE), 1);
53         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_BY), 1);
54         SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), "640");
55         SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), "480");     
56     }
57     else {
58         CheckDlgButton(hDlg, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
59         /* disable the controls */
60         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), 0);
61         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), 0);
62         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_SIZE), 0);
63         EnableWindow(GetDlgItem(hDlg, IDC_DESKTOP_BY), 0);
64
65         SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), "");
66         SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), "");
67     }
68
69     updatingUI = FALSE;
70 }
71
72 /* pokes the win32 api to setup the dialog from the config struct */
73 void initX11DrvDlg (HWND hDlg)
74 {
75     char *buf;
76     int x, y;
77     char *i;
78
79     updatingUI = TRUE;
80     
81     updateGUIForDesktopMode(hDlg);
82     
83     /* desktop size */
84     buf = getConfigValue("x11drv", "Desktop", "640x480");
85     i = strchr(buf, 'x');
86     *i = '\0';
87     i++;
88     SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
89     SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), i);
90     free(buf);
91
92     SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
93     SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);    
94     
95     updatingUI = FALSE;
96 }
97
98
99
100 void setFromDesktopSizeEdits(HWND hDlg) {
101     char *width = malloc(RES_MAXLEN+1);
102     char *height = malloc(RES_MAXLEN+1);
103     char *newStr = malloc((RES_MAXLEN*2) + 2);
104
105     if (updatingUI) return;
106     
107     WINE_TRACE("\n");
108     
109     GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1);
110     GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1);
111
112     if (strcmp(width, "") == 0) strcpy(width, "640");
113     if (strcmp(height, "") == 0) strcpy(height, "480");
114     
115     sprintf(newStr, "%sx%s", width, height);
116     addTransaction("x11drv", "Desktop", ACTION_SET, newStr);
117
118     free(width);
119     free(height);
120     free(newStr);
121 }
122
123 void onEnableDesktopClicked(HWND hDlg) {
124     WINE_TRACE("\n");
125     if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
126         /* it was just unchecked, so read the values of the edit boxes, set the config value */
127         setFromDesktopSizeEdits(hDlg);
128     } else {
129         /* it was just checked, so remove the config values */
130         addTransaction("x11drv", "Desktop", ACTION_REMOVE, NULL);
131     }
132     updateGUIForDesktopMode(hDlg);
133 }
134     
135 INT_PTR CALLBACK
136 X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
137 {
138     switch (uMsg) {
139         case WM_INITDIALOG:
140             break;
141             
142         case WM_COMMAND:
143             switch(HIWORD(wParam)) {
144                 case EN_CHANGE: {
145                     SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
146                     if ( (LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT) ) setFromDesktopSizeEdits(hDlg);
147                     break;
148                 }
149                 case BN_CLICKED: {
150                     WINE_TRACE("%ld\n", LOWORD(wParam));
151                     switch(LOWORD(wParam)) {
152                         case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
153                     };
154                     break;
155                 }
156                     
157                 default:
158                     break;
159             }
160             break;
161         
162         
163         case WM_NOTIFY:
164             switch (((LPNMHDR)lParam)->code) {
165                 case PSN_KILLACTIVE: {
166                     SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
167                     break;
168                 }
169                 case PSN_APPLY: {
170                     SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
171                     break;
172                 }
173                 case PSN_SETACTIVE: {
174                     initX11DrvDlg (hDlg);
175                     break;
176                 }
177             }
178             break;
179
180         default:
181             break;
182     }
183     return FALSE;
184 }