ntdll: Mac OS support for saving and restoring the extended FPU context on exceptions.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  */
23
24 #define WIN32_LEAN_AND_MEAN
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <objbase.h>
32 #include <wine/debug.h>
33
34 #include "properties.h"
35 #include "resource.h"
36 #include "winecfg.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
39
40 static INT CALLBACK
41 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
42 {
43     switch (uMsg)
44     {
45         /*
46          * hWnd = NULL, lParam == dialog resource
47          */
48     case PSCB_PRECREATE:
49         break;
50
51     case PSCB_INITIALIZED:
52         break;
53
54     default:
55         break;
56     }
57     return 0;
58 }
59
60 static INT_PTR CALLBACK
61 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
62 {
63     switch (uMsg) {
64
65         case WM_NOTIFY:
66             if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
67             /* otherwise fall through, we want to refresh the page as well */
68         case WM_INITDIALOG:
69             break;
70
71         case WM_COMMAND:
72             break;
73             
74         default:
75             break;
76             
77     }
78     return FALSE;
79 }
80
81 #define NUM_PROPERTY_PAGES 7
82
83 static INT_PTR
84 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
85 {
86     PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
87     PROPSHEETHEADERW psh;
88     int pg = 0; /* start with page 0 */
89
90     /*
91      * Fill out the (Applications) PROPSHEETPAGE data structure 
92      * for the property sheet
93      */
94     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
95     psp[pg].dwFlags = PSP_USETITLE;
96     psp[pg].hInstance = hInstance;
97     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
98     psp[pg].u2.pszIcon = NULL;
99     psp[pg].pfnDlgProc = AppDlgProc;
100     psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
101     psp[pg].lParam = 0;
102     pg++;
103
104     /*
105      * Fill out the (Libraries) PROPSHEETPAGE data structure 
106      * for the property sheet
107      */
108     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
109     psp[pg].dwFlags = PSP_USETITLE;
110     psp[pg].hInstance = hInstance;
111     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
112     psp[pg].u2.pszIcon = NULL;
113     psp[pg].pfnDlgProc = LibrariesDlgProc;
114     psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
115     psp[pg].lParam = 0;
116     pg++;
117     
118     /*
119      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
120      * for the property sheet
121      */
122     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
123     psp[pg].dwFlags = PSP_USETITLE;
124     psp[pg].hInstance = hInstance;
125     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
126     psp[pg].u2.pszIcon = NULL;
127     psp[pg].pfnDlgProc = GraphDlgProc;
128     psp[pg].pszTitle =  load_string (IDS_TAB_GRAPHICS);
129     psp[pg].lParam = 0;
130     pg++;
131
132     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
133     psp[pg].dwFlags = PSP_USETITLE;
134     psp[pg].hInstance = hInstance;
135     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
136     psp[pg].u2.pszIcon = NULL;
137     psp[pg].pfnDlgProc = ThemeDlgProc;
138     psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
139     psp[pg].lParam = 0;
140     pg++;
141
142     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
143     psp[pg].dwFlags = PSP_USETITLE;
144     psp[pg].hInstance = hInstance;
145     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
146     psp[pg].u2.pszIcon = NULL;
147     psp[pg].pfnDlgProc = DriveDlgProc;
148     psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
149     psp[pg].lParam = 0;
150     pg++;
151
152     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
153     psp[pg].dwFlags = PSP_USETITLE;
154     psp[pg].hInstance = hInstance;
155     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
156     psp[pg].u2.pszIcon = NULL;
157     psp[pg].pfnDlgProc = AudioDlgProc;
158     psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
159     psp[pg].lParam = 0;
160     pg++;
161
162     /*
163      * Fill out the (General) PROPSHEETPAGE data structure 
164      * for the property sheet
165      */
166     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
167     psp[pg].dwFlags = PSP_USETITLE;
168     psp[pg].hInstance = hInstance;
169     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
170     psp[pg].u2.pszIcon = NULL;
171     psp[pg].pfnDlgProc = AboutDlgProc;
172     psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
173     psp[pg].lParam = 0;
174     pg++;
175
176     /*
177      * Fill out the PROPSHEETHEADER
178      */
179     psh.dwSize = sizeof (PROPSHEETHEADERW);
180     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
181     psh.hwndParent = hOwner;
182     psh.hInstance = hInstance;
183     psh.u.pszIcon = NULL;
184     psh.pszCaption =  load_string (IDS_WINECFG_TITLE);
185     psh.nPages = NUM_PROPERTY_PAGES;
186     psh.u3.ppsp = psp;
187     psh.pfnCallback = PropSheetCallback;
188     psh.u2.nStartPage = 0;
189
190     /*
191      * Display the modal property sheet
192      */
193     return PropertySheetW (&psh);
194 }
195
196 /******************************************************************************
197  * Name       : ProcessCmdLine
198  * Description: Checks command line parameters for 'autodetect drives' option
199  * Parameters : lpCmdLine - the command line
200  * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
201  *              FALSE - no '/D' option found in command line
202  * Notes      : This is a very simple implementation, which only works 
203  *              correctly if the one and only cmd line option is '/D' or
204  *              no option at all. Has to be reworked, if more options are to
205  *              be supported.
206  */
207 static BOOL
208 ProcessCmdLine(LPSTR lpCmdLine)
209 {
210     if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
211         (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
212     {
213         gui_mode = FALSE;
214         if (autodetect_drives()) {
215             apply_drive_changes();
216         }
217         return TRUE;
218     }
219
220     return FALSE;
221 }
222
223 /*****************************************************************************
224  * Name       : WinMain
225  * Description: Main windows entry point
226  * Parameters : hInstance
227  *              hPrev
228  *              szCmdLine
229  *              nShow
230  * Returns    : Program exit code
231  */
232 int WINAPI
233 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
234 {
235     if (ProcessCmdLine(szCmdLine)) {
236         return 0;
237     }
238
239     if (initialize(hInstance) != 0) {
240         WINE_ERR("initialization failed, aborting\n");
241         ExitProcess(1);
242     }
243     
244     /*
245      * The next 9 lines should be all that is needed
246      * for the Wine Configuration property sheet
247      */
248     InitCommonControls ();
249     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
250     if (doPropertySheet (hInstance, NULL) > 0) {
251         WINE_TRACE("OK\n");
252     } else {
253         WINE_TRACE("Cancel\n");
254     }
255     CoUninitialize(); 
256     ExitProcess (0);
257
258     return 0;
259 }