Add audio tab with first pass at autodetection of audio driver.
[wine] / programs / winecfg / main.c
1 /*
2  * WineCfg main entry point
3  *
4  * Copyright 2002 Jaco Greeff
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2003 Mike Hearn
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <wine/debug.h>
32
33 #include "properties.h"
34 #include "resource.h"
35 #include "winecfg.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
38
39
40 #define versionSection (appSettings == EDITING_GLOBAL ? "Version" : (getSectionForApp("Version")))
41 #define tweakSection (appSettings == EDITING_GLOBAL ? "Tweak.Layout" : (getSectionForApp("Tweak.Layout")))
42
43 void CALLBACK
44 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
45 {
46     switch (uMsg)
47     {
48         /*
49          * hWnd = NULL, lParam == dialog resource
50          */
51     case PSCB_PRECREATE:
52         break;
53
54     case PSCB_INITIALIZED:
55         break;
56
57     default:
58         break;
59     }
60 }
61
62 void
63 initGeneralDlg (HWND hDlg)
64 {
65     int i;
66     const VERSION_DESC *pVer = NULL;
67     char *curWinVer = getConfigValue(versionSection, "Windows", "win98");
68     char *curDOSVer = getConfigValue(versionSection, "DOS", "6.22");
69     char *curWineLook = getConfigValue(tweakSection, "WineLook", "win95");
70
71     /* normalize the version strings */
72     if (!strcmp(curWinVer, "win2000") || !strcmp(curWinVer, "nt2k") || !strcmp(curWinVer, "nt2000")) {
73         free(curWinVer);
74         curWinVer = strdup("win2k");
75     }
76
77     if (!strcmp(curWinVer, "win2k3")) {
78         free(curWinVer);
79         curWinVer = strdup("win2003");
80     }
81     
82     if ((pVer = getWinVersions ()))
83     {
84         for (i = 0; *pVer->szVersion; i++, pVer++)
85         {
86             SendDlgItemMessage (hDlg, IDC_WINVER, CB_ADDSTRING,
87                                 0, (LPARAM) pVer->szDescription);
88             if (!strcmp (pVer->szVersion, curWinVer))
89                 SendDlgItemMessage (hDlg, IDC_WINVER, CB_SETCURSEL,
90                                     (WPARAM) i, 0);
91         }
92     }
93     if ((pVer = getDOSVersions ()))
94     {
95         for (i = 0; *pVer->szVersion; i++, pVer++)
96         {
97             SendDlgItemMessage (hDlg, IDC_DOSVER, CB_ADDSTRING,
98                                 0, (LPARAM) pVer->szDescription);
99             if (!strcmp (pVer->szVersion, curDOSVer))
100                 SendDlgItemMessage (hDlg, IDC_DOSVER, CB_SETCURSEL,
101                                     (WPARAM) i, 0);
102         }
103     }
104     if ((pVer = getWinelook ()))
105     {
106         for (i = 0; *pVer->szVersion; i++, pVer++)
107         {
108             SendDlgItemMessage (hDlg, IDC_WINELOOK, CB_ADDSTRING,
109                                 0, (LPARAM) pVer->szDescription);
110             if (!strcmp (pVer->szVersion, curWineLook))
111                 SendDlgItemMessage (hDlg, IDC_WINELOOK, CB_SETCURSEL,
112                                     (WPARAM) i, 0);
113         }
114     }
115
116     free(curWinVer);
117     free(curDOSVer);
118     free(curWineLook);
119 }
120
121 INT_PTR CALLBACK
122 GeneralDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
123 {
124     switch (uMsg) {
125
126         case WM_NOTIFY:
127             if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
128             /* otherwise fall through, we want to refresh the page as well */
129         case WM_INITDIALOG:
130             initGeneralDlg (hDlg);
131             break;
132
133         case WM_COMMAND:
134             switch (LOWORD(wParam)) {
135                 case IDC_WINVER: if (HIWORD(wParam) == CBN_SELCHANGE) {
136                     /* user changed the wine version combobox */
137                     int selection = SendDlgItemMessage( hDlg, IDC_WINVER, CB_GETCURSEL, 0, 0);
138                     VERSION_DESC *desc = getWinVersions();
139
140                     while (selection > 0) {
141                         desc++; selection--;
142                     }
143                     addTransaction(versionSection, "Windows", ACTION_SET, desc->szVersion);
144                 }
145                 break;
146
147                 case IDC_WINELOOK: if (HIWORD(wParam) == CBN_SELCHANGE) {
148                     /* user changed the wine look combo box */
149                     int selection = SendDlgItemMessage( hDlg, IDC_WINELOOK, CB_GETCURSEL, 0, 0);
150                     VERSION_DESC *desc = getWinelook();
151
152                     while (selection > 0) {
153                         desc++; selection--;
154                     }
155                     addTransaction(tweakSection, "WineLook", ACTION_SET, desc->szVersion);
156                 }
157                 break;
158
159                 case IDC_DOSVER: if (HIWORD(wParam) == CBN_SELCHANGE) {
160                     /* user changed the dos version combo box */
161                     int selection = SendDlgItemMessage( hDlg, IDC_WINELOOK, CB_GETCURSEL, 0, 0);
162                     VERSION_DESC *desc = getDOSVersions();
163
164                     while (selection > 0) {
165                         desc++; selection--;
166                     }
167                     addTransaction(versionSection, "DOS", ACTION_SET, desc->szVersion);
168                     
169                 }
170             }
171             break;
172             
173         default:
174             break;
175             
176     }
177     return FALSE;
178 }
179
180 #define NUM_PROPERTY_PAGES 6
181
182 INT_PTR
183 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
184 {
185     PROPSHEETPAGE psp[NUM_PROPERTY_PAGES];
186     PROPSHEETHEADER psh;
187
188     /*
189      * Fill out the (General) PROPSHEETPAGE data structure 
190      * for the property sheet
191      */
192     psp[0].dwSize = sizeof (PROPSHEETPAGE);
193     psp[0].dwFlags = PSP_USETITLE;
194     psp[0].hInstance = hInstance;
195     psp[0].u.pszTemplate = MAKEINTRESOURCE (IDD_GENERALCFG);
196     psp[0].u2.pszIcon = NULL;
197     psp[0].pfnDlgProc = GeneralDlgProc;
198     psp[0].pszTitle = "General";
199     psp[0].lParam = 0;
200
201     /*
202      * Fill out the (Applications) PROPSHEETPAGE data structure 
203      * for the property sheet
204      */
205     psp[1].dwSize = sizeof (PROPSHEETPAGE);
206     psp[1].dwFlags = PSP_USETITLE;
207     psp[1].hInstance = hInstance;
208     psp[1].u.pszTemplate = MAKEINTRESOURCE (IDD_APPCFG);
209     psp[1].u2.pszIcon = NULL;
210     psp[1].pfnDlgProc = AppDlgProc;
211     psp[1].pszTitle = "Applications";
212     psp[1].lParam = 0;
213
214     /*
215      * Fill out the (Libraries) PROPSHEETPAGE data structure 
216      * for the property sheet
217      */
218     psp[2].dwSize = sizeof (PROPSHEETPAGE);
219     psp[2].dwFlags = PSP_USETITLE;
220     psp[2].hInstance = hInstance;
221     psp[2].u.pszTemplate = MAKEINTRESOURCE (IDD_DLLCFG);
222     psp[2].u2.pszIcon = NULL;
223     psp[2].pfnDlgProc = LibrariesDlgProc;
224     psp[2].pszTitle = "Libraries";
225     psp[2].lParam = 0;
226     
227     /*
228      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
229      * for the property sheet
230      */
231     psp[3].dwSize = sizeof (PROPSHEETPAGE);
232     psp[3].dwFlags = PSP_USETITLE;
233     psp[3].hInstance = hInstance;
234     psp[3].u.pszTemplate = MAKEINTRESOURCE (IDD_X11DRVCFG);
235     psp[3].u2.pszIcon = NULL;
236     psp[3].pfnDlgProc = X11DrvDlgProc;
237     psp[3].pszTitle = "X11 Driver";
238     psp[3].lParam = 0;
239
240     psp[4].dwSize = sizeof (PROPSHEETPAGE);
241     psp[4].dwFlags = PSP_USETITLE;
242     psp[4].hInstance = hInstance;
243     psp[4].u.pszTemplate = MAKEINTRESOURCE (IDD_DRIVECFG);
244     psp[4].u2.pszIcon = NULL;
245     psp[4].pfnDlgProc = DriveDlgProc;
246     psp[4].pszTitle = "Drives";
247     psp[4].lParam = 0;
248
249     psp[5].dwSize = sizeof (PROPSHEETPAGE);
250     psp[5].dwFlags = PSP_USETITLE;
251     psp[5].hInstance = hInstance;
252     psp[5].u.pszTemplate = MAKEINTRESOURCE (IDD_AUDIOCFG);
253     psp[5].u2.pszIcon = NULL;
254     psp[5].pfnDlgProc = AudioDlgProc;
255     psp[5].pszTitle = "Audio";
256     psp[5].lParam = 0;
257     
258     /*
259      * Fill out the PROPSHEETHEADER
260      */
261     psh.dwSize = sizeof (PROPSHEETHEADER);
262     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
263     psh.hwndParent = hOwner;
264     psh.hInstance = hInstance;
265     psh.u.pszIcon = NULL;
266     psh.pszCaption = "Wine Configuration";
267     psh.nPages = NUM_PROPERTY_PAGES;
268     psh.u3.ppsp = (LPCPROPSHEETPAGE) & psp;
269     psh.pfnCallback = (PFNPROPSHEETCALLBACK) PropSheetCallback;
270     psh.u2.nStartPage = 0;
271
272     /*
273      * Display the modal property sheet
274      */
275     return PropertySheet (&psh);
276 }
277
278
279 /*****************************************************************************
280  * Name       : WinMain
281  * Description: Main windows entry point
282  * Parameters : hInstance
283  *              hPrev
284  *              szCmdLine
285  *              nShow
286  * Returns    : Program exit code
287  */
288 int WINAPI
289 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
290 {
291
292     /* Until winecfg is fully functional, warn users that it is incomplete and doesn't do anything */
293     WINE_FIXME("The winecfg tool is not yet complete, and does not actually alter your configuration.\n");
294     WINE_FIXME("If you want to alter the way Wine works, look in the ~/.wine/config file for more information.\n");
295
296     if (initialize() != 0) {
297         WINE_ERR("initialization failed, aborting\n");
298         ExitProcess(1);
299     }
300     
301     /*
302      * The next 3 lines should be all that is needed
303      * for the Wine Configuration property sheet
304      */
305     InitCommonControls ();
306     if (doPropertySheet (hInstance, NULL) > 0) {
307         WINE_TRACE("OK\n");
308     } else {
309         WINE_TRACE("Cancel\n");
310     }
311     
312     ExitProcess (0);
313
314     return 0;
315 }