comctl32: A couple fixes for tab icon offsets.
[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 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 void 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 }
58
59 static INT_PTR CALLBACK
60 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
61 {
62     switch (uMsg) {
63
64         case WM_NOTIFY:
65             if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
66             /* otherwise fall through, we want to refresh the page as well */
67         case WM_INITDIALOG:
68             break;
69
70         case WM_COMMAND:
71             break;
72             
73         default:
74             break;
75             
76     }
77     return FALSE;
78 }
79
80 static WCHAR* load_string (UINT id)
81 {
82     WCHAR buf[100];
83     int len;
84     WCHAR* newStr;
85
86     LoadStringW (GetModuleHandle (NULL), id, buf, sizeof(buf)/sizeof(buf[0]));
87
88     len = lstrlenW (buf);
89     newStr = HeapAlloc (GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR));
90     memcpy (newStr, buf, len * sizeof (WCHAR));
91     newStr[len] = 0;
92     return newStr;
93 }
94
95 #define NUM_PROPERTY_PAGES 7
96
97 static INT_PTR
98 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
99 {
100     PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
101     PROPSHEETHEADERW psh;
102     int pg = 0; /* start with page 0 */
103
104     /*
105      * Fill out the (Applications) 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_APPCFG);
112     psp[pg].u2.pszIcon = NULL;
113     psp[pg].pfnDlgProc = AppDlgProc;
114     psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
115     psp[pg].lParam = 0;
116     pg++;
117
118     /*
119      * Fill out the (Libraries) 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_DLLCFG);
126     psp[pg].u2.pszIcon = NULL;
127     psp[pg].pfnDlgProc = LibrariesDlgProc;
128     psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
129     psp[pg].lParam = 0;
130     pg++;
131     
132     /*
133      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
134      * for the property sheet
135      */
136     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
137     psp[pg].dwFlags = PSP_USETITLE;
138     psp[pg].hInstance = hInstance;
139     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
140     psp[pg].u2.pszIcon = NULL;
141     psp[pg].pfnDlgProc = GraphDlgProc;
142     psp[pg].pszTitle =  load_string (IDS_TAB_GRAPHICS);
143     psp[pg].lParam = 0;
144     pg++;
145
146     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
147     psp[pg].dwFlags = PSP_USETITLE;
148     psp[pg].hInstance = hInstance;
149     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
150     psp[pg].u2.pszIcon = NULL;
151     psp[pg].pfnDlgProc = ThemeDlgProc;
152     psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
153     psp[pg].lParam = 0;
154     pg++;
155
156     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
157     psp[pg].dwFlags = PSP_USETITLE;
158     psp[pg].hInstance = hInstance;
159     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
160     psp[pg].u2.pszIcon = NULL;
161     psp[pg].pfnDlgProc = DriveDlgProc;
162     psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
163     psp[pg].lParam = 0;
164     pg++;
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_AUDIOCFG);
170     psp[pg].u2.pszIcon = NULL;
171     psp[pg].pfnDlgProc = AudioDlgProc;
172     psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
173     psp[pg].lParam = 0;
174     pg++;
175
176     /*
177      * Fill out the (General) PROPSHEETPAGE data structure 
178      * for the property sheet
179      */
180     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
181     psp[pg].dwFlags = PSP_USETITLE;
182     psp[pg].hInstance = hInstance;
183     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
184     psp[pg].u2.pszIcon = NULL;
185     psp[pg].pfnDlgProc = AboutDlgProc;
186     psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
187     psp[pg].lParam = 0;
188     pg++;
189
190     /*
191      * Fill out the PROPSHEETHEADER
192      */
193     psh.dwSize = sizeof (PROPSHEETHEADERW);
194     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
195     psh.hwndParent = hOwner;
196     psh.hInstance = hInstance;
197     psh.u.pszIcon = NULL;
198     psh.pszCaption =  load_string (IDS_WINECFG_TITLE);
199     psh.nPages = NUM_PROPERTY_PAGES;
200     psh.u3.ppsp = (LPCPROPSHEETPAGEW) & psp;
201     psh.pfnCallback = (PFNPROPSHEETCALLBACK) PropSheetCallback;
202     psh.u2.nStartPage = 0;
203
204     /*
205      * Display the modal property sheet
206      */
207     return PropertySheetW (&psh);
208 }
209
210 /******************************************************************************
211  * Name       : ProcessCmdLine
212  * Description: Checks command line parameters for 'autodetect drives' option
213  * Parameters : lpCmdLine - the command line
214  * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
215  *              FALSE - no '/D' option found in command line
216  * Notes      : This is a very simple implementation, which only works 
217  *              correctly if the one and only cmd line option is '/D' or
218  *              no option at all. Has to be reworked, if more options are to
219  *              be supported.
220  */
221 static BOOL
222 ProcessCmdLine(LPSTR lpCmdLine)
223 {
224     if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
225         (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
226     {
227         gui_mode = FALSE;
228         if (autodetect_drives()) {
229             apply_drive_changes();
230         }
231         return TRUE;
232     }
233
234     return FALSE;
235 }
236
237 /*****************************************************************************
238  * Name       : WinMain
239  * Description: Main windows entry point
240  * Parameters : hInstance
241  *              hPrev
242  *              szCmdLine
243  *              nShow
244  * Returns    : Program exit code
245  */
246 int WINAPI
247 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
248 {
249     if (ProcessCmdLine(szCmdLine)) {
250         return 0;
251     }
252
253     if (initialize(hInstance) != 0) {
254         WINE_ERR("initialization failed, aborting\n");
255         ExitProcess(1);
256     }
257     
258     /*
259      * The next 9 lines should be all that is needed
260      * for the Wine Configuration property sheet
261      */
262     InitCommonControls ();
263     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
264     if (doPropertySheet (hInstance, NULL) > 0) {
265         WINE_TRACE("OK\n");
266     } else {
267         WINE_TRACE("Cancel\n");
268     }
269     CoUninitialize(); 
270     ExitProcess (0);
271
272     return 0;
273 }