appwiz.cpl: Check to see if buttons should be enabled.
[wine/gsoc_dplay.git] / dlls / appwiz.cpl / appwiz.c
blob4bf86a9e1ed256fb722c41806def4b48fd93a17e
1 /*
2 * Add/Remove Programs applet
3 * Partially based on Wine Uninstaller
5 * Copyright 2000 Andreas Mohr
6 * Copyright 2004 Hannu Valtonen
7 * Copyright 2005 Jonathan Ernst
8 * Copyright 2001-2002, 2008 Owen Rudge
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wine/port.h"
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <windef.h>
36 #include <winbase.h>
37 #include <winuser.h>
38 #include <wingdi.h>
39 #include <winreg.h>
40 #include <shellapi.h>
41 #include <commctrl.h>
42 #include <cpl.h>
44 #include "res.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
48 /* define a maximum length for various buffers we use */
49 #define MAX_STRING_LEN 1024
51 static HINSTANCE hInst;
53 /******************************************************************************
54 * Name : DllMain
55 * Description: Entry point for DLL file
57 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
58 LPVOID lpvReserved)
60 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
62 switch (fdwReason)
64 case DLL_PROCESS_ATTACH:
65 hInst = hinstDLL;
66 break;
68 return TRUE;
71 /******************************************************************************
72 * Name : UpdateButtons
73 * Description: Enables/disables the Add/Remove button depending on current
74 * selection in list box.
75 * Parameters : hWnd - Handle of the dialog box
77 static void UpdateButtons(HWND hWnd)
79 BOOL sel = ListView_GetSelectedCount(GetDlgItem(hWnd, IDL_PROGRAMS)) != 0;
81 EnableWindow(GetDlgItem(hWnd, IDC_ADDREMOVE), sel);
82 EnableWindow(GetDlgItem(hWnd, IDC_SUPPORT_INFO), sel);
85 /* Definition of column headers for AddListViewColumns function */
86 typedef struct AppWizColumn {
87 int width;
88 int fmt;
89 int title;
90 } AppWizColumn;
92 AppWizColumn columns[] = {
93 {200, LVCFMT_LEFT, IDS_COLUMN_NAME},
94 {150, LVCFMT_LEFT, IDS_COLUMN_PUBLISHER},
95 {100, LVCFMT_LEFT, IDS_COLUMN_VERSION},
98 /******************************************************************************
99 * Name : AddListViewColumns
100 * Description: Adds column headers to the list view control.
101 * Parameters : hWnd - Handle of the list view control.
102 * Returns : TRUE if completed successfully, FALSE otherwise.
104 static BOOL AddListViewColumns(HWND hWnd)
106 WCHAR buf[MAX_STRING_LEN];
107 LVCOLUMNW lvc;
108 int i;
110 lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
112 /* Add the columns */
113 for (i = 0; i < sizeof(columns) / sizeof(columns[0]); i++)
115 lvc.iSubItem = i;
116 lvc.pszText = buf;
118 /* set width and format */
119 lvc.cx = columns[i].width;
120 lvc.fmt = columns[i].fmt;
122 LoadStringW(hInst, columns[i].title, buf, sizeof(buf) / sizeof(buf[0]));
124 if (ListView_InsertColumnW(hWnd, i, &lvc) == -1)
125 return FALSE;
128 return TRUE;
131 /******************************************************************************
132 * Name : AddListViewImageList
133 * Description: Creates an ImageList for the list view control.
134 * Parameters : hWnd - Handle of the list view control.
135 * Returns : Handle of the image list.
137 static HIMAGELIST AddListViewImageList(HWND hWnd)
139 HIMAGELIST hSmall;
140 HICON hDefaultIcon;
142 hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
143 ILC_MASK, 1, 1);
145 /* Add default icon to image list */
146 hDefaultIcon = LoadIconW(hInst, MAKEINTRESOURCEW(ICO_MAIN));
147 ImageList_AddIcon(hSmall, hDefaultIcon);
148 DestroyIcon(hDefaultIcon);
150 (void) ListView_SetImageList(hWnd, hSmall, LVSIL_SMALL);
152 return hSmall;
155 /******************************************************************************
156 * Name : ResetApplicationList
157 * Description: Empties the app list, if need be, and recreates it.
158 * Parameters : bFirstRun - TRUE if this is the first time this is run, FALSE otherwise
159 * hWnd - handle of the dialog box
160 * hImageList - handle of the image list
161 * Returns : New handle of the image list.
163 static HIMAGELIST ResetApplicationList(BOOL bFirstRun, HWND hWnd, HIMAGELIST hImageList)
165 HWND hWndListView;
167 hWndListView = GetDlgItem(hWnd, IDL_PROGRAMS);
169 /* if first run, create the image list and add the listview columns */
170 if (bFirstRun)
172 if (!AddListViewColumns(hWndListView))
173 return NULL;
175 else /* we need to remove the existing things first */
177 ImageList_Destroy(hImageList);
180 /* now create the image list and add the applications to the listview */
181 hImageList = AddListViewImageList(hWndListView);
183 UpdateButtons(hWnd);
185 return(hImageList);
188 /******************************************************************************
189 * Name : MainDlgProc
190 * Description: Callback procedure for main tab
191 * Parameters : hWnd - hWnd of the window
192 * msg - reason for calling function
193 * wParam - additional parameter
194 * lParam - additional parameter
195 * Returns : Dependant on message
197 static BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
199 static HIMAGELIST hImageList;
201 switch(msg)
203 case WM_INITDIALOG:
204 hImageList = ResetApplicationList(TRUE, hWnd, hImageList);
206 if (!hImageList)
207 return FALSE;
209 return TRUE;
211 case WM_DESTROY:
212 ImageList_Destroy(hImageList);
214 return 0;
217 return FALSE;
220 /******************************************************************************
221 * Name : StartApplet
222 * Description: Main routine for applet
223 * Parameters : hWnd - hWnd of the Control Panel
225 static void StartApplet(HWND hWnd)
227 PROPSHEETPAGEW psp;
228 PROPSHEETHEADERW psh;
229 WCHAR tab_title[MAX_STRING_LEN], app_title[MAX_STRING_LEN];
231 /* Load the strings we will use */
232 LoadStringW(hInst, IDS_TAB1_TITLE, tab_title, sizeof(tab_title) / sizeof(tab_title[0]));
233 LoadStringW(hInst, IDS_CPL_TITLE, app_title, sizeof(app_title) / sizeof(app_title[0]));
235 /* Fill out the PROPSHEETPAGE */
236 psp.dwSize = sizeof (PROPSHEETPAGEW);
237 psp.dwFlags = PSP_USETITLE;
238 psp.hInstance = hInst;
239 psp.pszTemplate = MAKEINTRESOURCEW (IDD_MAIN);
240 psp.pszIcon = NULL;
241 psp.pfnDlgProc = (DLGPROC) MainDlgProc;
242 psp.pszTitle = tab_title;
243 psp.lParam = 0;
245 /* Fill out the PROPSHEETHEADER */
246 psh.dwSize = sizeof (PROPSHEETHEADERW);
247 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID;
248 psh.hwndParent = hWnd;
249 psh.hInstance = hInst;
250 psh.pszIcon = NULL;
251 psh.pszCaption = app_title;
252 psh.nPages = 1;
253 psh.ppsp = &psp;
254 psh.pfnCallback = NULL;
255 psh.nStartPage = 0;
257 /* Display the property sheet */
258 PropertySheetW (&psh);
261 /******************************************************************************
262 * Name : CPlApplet
263 * Description: Entry point for Control Panel applets
264 * Parameters : hwndCPL - hWnd of the Control Panel
265 * message - reason for calling function
266 * lParam1 - additional parameter
267 * lParam2 - additional parameter
268 * Returns : Dependant on message
270 LONG CALLBACK CPlApplet(HWND hwndCPL, UINT message, LPARAM lParam1, LPARAM lParam2)
272 INITCOMMONCONTROLSEX iccEx;
274 switch (message)
276 case CPL_INIT:
277 iccEx.dwSize = sizeof(iccEx);
278 iccEx.dwICC = ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES;
280 InitCommonControlsEx(&iccEx);
282 return TRUE;
284 case CPL_GETCOUNT:
285 return 1;
287 case CPL_INQUIRE:
289 CPLINFO *appletInfo = (CPLINFO *) lParam2;
291 appletInfo->idIcon = ICO_MAIN;
292 appletInfo->idName = IDS_CPL_TITLE;
293 appletInfo->idInfo = IDS_CPL_DESC;
294 appletInfo->lData = 0;
296 break;
299 case CPL_DBLCLK:
300 StartApplet(hwndCPL);
301 break;
304 return FALSE;