b8bc07f3cedf2704aaf10305c5724d9a461041a5
[reactos.git] / base / setup / reactos / drivepage.c
1 /*
2 * ReactOS applications
3 * Copyright (C) 2004-2008 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS GUI first stage setup application
22 * FILE: base/setup/reactos/drivepage.c
23 * PROGRAMMERS: Matthias Kupfer
24 * Dmitry Chapyshev (dmitry@reactos.org)
25 */
26
27 #include "reactos.h"
28 #include "resource.h"
29
30 /* GLOBALS ******************************************************************/
31
32 #define IDS_LIST_COLUMN_FIRST IDS_PARTITION_NAME
33 #define IDS_LIST_COLUMN_LAST IDS_PARTITION_TYPE
34
35 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
36 static const UINT column_ids[MAX_LIST_COLUMNS] = {IDS_LIST_COLUMN_FIRST, IDS_LIST_COLUMN_FIRST + 1, IDS_LIST_COLUMN_FIRST + 2};
37 static const INT column_widths[MAX_LIST_COLUMNS] = {200, 150, 150};
38 static const INT column_alignment[MAX_LIST_COLUMNS] = {LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT};
39
40 /* FUNCTIONS ****************************************************************/
41
42 static INT_PTR CALLBACK
43 MoreOptDlgProc(HWND hwndDlg,
44 UINT uMsg,
45 WPARAM wParam,
46 LPARAM lParam)
47 {
48 PSETUPDATA pSetupData;
49
50 /* Retrieve pointer to the global setup data */
51 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
52
53 switch (uMsg)
54 {
55 case WM_INITDIALOG:
56 /* Save pointer to the global setup data */
57 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
58 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
59
60 CheckDlgButton(hwndDlg, IDC_INSTFREELDR, BST_CHECKED);
61 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
62 WM_SETTEXT,
63 (WPARAM)0,
64 (LPARAM)pSetupData->USetupData.InstallationDirectory);
65 break;
66
67 case WM_COMMAND:
68 switch(LOWORD(wParam))
69 {
70 case IDOK:
71 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
72 WM_GETTEXT,
73 (WPARAM)sizeof(pSetupData->USetupData.InstallationDirectory) / sizeof(TCHAR),
74 (LPARAM)pSetupData->USetupData.InstallationDirectory);
75
76 EndDialog(hwndDlg, IDOK);
77 return TRUE;
78
79 case IDCANCEL:
80 EndDialog(hwndDlg, IDCANCEL);
81 return TRUE;
82 }
83 break;
84 }
85
86 return FALSE;
87 }
88
89 static INT_PTR CALLBACK
90 PartitionDlgProc(HWND hwndDlg,
91 UINT uMsg,
92 WPARAM wParam,
93 LPARAM lParam)
94 {
95 switch (uMsg)
96 {
97 case WM_INITDIALOG:
98 break;
99 case WM_COMMAND:
100 {
101 switch(LOWORD(wParam))
102 {
103 case IDOK:
104 EndDialog(hwndDlg, IDOK);
105 return TRUE;
106 case IDCANCEL:
107 EndDialog(hwndDlg, IDCANCEL);
108 return TRUE;
109 }
110 }
111 }
112 return FALSE;
113 }
114
115
116 BOOL
117 CreateListViewColumns(
118 IN HINSTANCE hInstance,
119 IN HWND hWndListView,
120 IN const UINT* pIDs,
121 IN const INT* pColsWidth,
122 IN const INT* pColsAlign,
123 IN UINT nNumOfColumns)
124 {
125 UINT i;
126 LVCOLUMN lvC;
127 WCHAR szText[50];
128
129 /* Create the columns */
130 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
131 lvC.pszText = szText;
132
133 /* Load the column labels from the resource file */
134 for (i = 0; i < nNumOfColumns; i++)
135 {
136 lvC.iSubItem = i;
137 lvC.cx = pColsWidth[i];
138 lvC.fmt = pColsAlign[i];
139
140 LoadStringW(hInstance, pIDs[i], szText, ARRAYSIZE(szText));
141
142 if (ListView_InsertColumn(hWndListView, i, &lvC) == -1)
143 return FALSE;
144 }
145
146 return TRUE;
147 }
148
149
150 INT_PTR
151 CALLBACK
152 DriveDlgProc(
153 HWND hwndDlg,
154 UINT uMsg,
155 WPARAM wParam,
156 LPARAM lParam)
157 {
158 PSETUPDATA pSetupData;
159 #if 1
160 HDEVINFO h;
161 HWND hList;
162 SP_DEVINFO_DATA DevInfoData;
163 DWORD i;
164 #endif
165
166 /* Retrieve pointer to the global setup data */
167 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
168
169 switch (uMsg)
170 {
171 case WM_INITDIALOG:
172 {
173 /* Save pointer to the global setup data */
174 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
175 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
176
177 CreateListViewColumns(pSetupData->hInstance,
178 GetDlgItem(hwndDlg, IDC_PARTITION),
179 column_ids,
180 column_widths,
181 column_alignment,
182 MAX_LIST_COLUMNS);
183
184 #if 1
185 h = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE, NULL, NULL, DIGCF_PRESENT);
186 if (h != INVALID_HANDLE_VALUE)
187 {
188 hList =GetDlgItem(hwndDlg, IDC_PARTITION);
189 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
190 for (i=0; SetupDiEnumDeviceInfo(h, i, &DevInfoData); i++)
191 {
192 DWORD DataT;
193 LPTSTR buffer = NULL;
194 DWORD buffersize = 0;
195
196 while (!SetupDiGetDeviceRegistryProperty(h,
197 &DevInfoData,
198 SPDRP_DEVICEDESC,
199 &DataT,
200 (PBYTE)buffer,
201 buffersize,
202 &buffersize))
203 {
204 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
205 {
206 if (buffer) LocalFree(buffer);
207 buffer = LocalAlloc(LPTR, buffersize * 2);
208 }
209 else
210 break;
211 }
212 if (buffer)
213 {
214 SendMessage(hList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
215 LocalFree(buffer);
216 }
217 }
218 SetupDiDestroyDeviceInfoList(h);
219 }
220 #endif
221 }
222 break;
223
224 case WM_COMMAND:
225 {
226 switch(LOWORD(wParam))
227 {
228 case IDC_PARTMOREOPTS:
229 DialogBoxParam(pSetupData->hInstance,
230 MAKEINTRESOURCE(IDD_BOOTOPTIONS),
231 hwndDlg,
232 MoreOptDlgProc,
233 (LPARAM)pSetupData);
234 break;
235 case IDC_PARTCREATE:
236 DialogBox(pSetupData->hInstance,
237 MAKEINTRESOURCE(IDD_PARTITION),
238 hwndDlg,
239 PartitionDlgProc);
240 break;
241 case IDC_PARTDELETE:
242 break;
243 }
244 break;
245 }
246
247 case WM_NOTIFY:
248 {
249 LPNMHDR lpnm = (LPNMHDR)lParam;
250
251 switch (lpnm->code)
252 {
253 case PSN_SETACTIVE:
254 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
255 break;
256
257 case PSN_QUERYCANCEL:
258 SetWindowLongPtr(hwndDlg,
259 DWLP_MSGRESULT,
260 MessageBox(GetParent(hwndDlg),
261 pSetupData->szAbortMessage,
262 pSetupData->szAbortTitle,
263 MB_YESNO | MB_ICONQUESTION) != IDYES);
264 return TRUE;
265
266 default:
267 break;
268 }
269 }
270 break;
271
272 default:
273 break;
274
275 }
276
277 return FALSE;
278 }
279
280 /* EOF */