5130a2983c5640867b3ef662948ca2620a102645
[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 MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
33 static const UINT column_ids[MAX_LIST_COLUMNS] = {IDS_LIST_COLUMN_FIRST, IDS_LIST_COLUMN_FIRST + 1, IDS_LIST_COLUMN_FIRST + 2};
34 static const INT column_widths[MAX_LIST_COLUMNS] = {200, 150, 150};
35 static const INT column_alignment[MAX_LIST_COLUMNS] = {LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT};
36
37 /* FUNCTIONS ****************************************************************/
38
39 static INT_PTR CALLBACK
40 MoreOptDlgProc(HWND hwndDlg,
41 UINT uMsg,
42 WPARAM wParam,
43 LPARAM lParam)
44 {
45 PSETUPDATA pSetupData;
46
47 /* Retrieve pointer to the global setup data */
48 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
49
50 switch (uMsg)
51 {
52 case WM_INITDIALOG:
53 /* Save pointer to the global setup data */
54 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
55 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
56
57 CheckDlgButton(hwndDlg, IDC_INSTFREELDR, BST_CHECKED);
58 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
59 WM_SETTEXT,
60 (WPARAM)0,
61 (LPARAM)pSetupData->USetupData.InstallationDirectory);
62 break;
63
64 case WM_COMMAND:
65 switch(LOWORD(wParam))
66 {
67 case IDOK:
68 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
69 WM_GETTEXT,
70 (WPARAM)sizeof(pSetupData->USetupData.InstallationDirectory) / sizeof(TCHAR),
71 (LPARAM)pSetupData->USetupData.InstallationDirectory);
72
73 EndDialog(hwndDlg, IDOK);
74 return TRUE;
75
76 case IDCANCEL:
77 EndDialog(hwndDlg, IDCANCEL);
78 return TRUE;
79 }
80 break;
81 }
82
83 return FALSE;
84 }
85
86 static INT_PTR CALLBACK
87 PartitionDlgProc(HWND hwndDlg,
88 UINT uMsg,
89 WPARAM wParam,
90 LPARAM lParam)
91 {
92 switch (uMsg)
93 {
94 case WM_INITDIALOG:
95 break;
96 case WM_COMMAND:
97 {
98 switch(LOWORD(wParam))
99 {
100 case IDOK:
101 EndDialog(hwndDlg, IDOK);
102 return TRUE;
103 case IDCANCEL:
104 EndDialog(hwndDlg, IDCANCEL);
105 return TRUE;
106 }
107 }
108 }
109 return FALSE;
110 }
111
112
113 BOOL
114 CreateListViewColumns(
115 IN HINSTANCE hInstance,
116 IN HWND hWndListView,
117 IN const UINT* pIDs,
118 IN const INT* pColsWidth,
119 IN const INT* pColsAlign,
120 IN UINT nNumOfColumns)
121 {
122 UINT i;
123 LVCOLUMN lvC;
124 WCHAR szText[50];
125
126 /* Create the columns */
127 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
128 lvC.pszText = szText;
129
130 /* Load the column labels from the resource file */
131 for (i = 0; i < nNumOfColumns; i++)
132 {
133 lvC.iSubItem = i;
134 lvC.cx = pColsWidth[i];
135 lvC.fmt = pColsAlign[i];
136
137 LoadStringW(hInstance, pIDs[i], szText, ARRAYSIZE(szText));
138
139 if (ListView_InsertColumn(hWndListView, i, &lvC) == -1)
140 return FALSE;
141 }
142
143 return TRUE;
144 }
145
146
147 INT_PTR
148 CALLBACK
149 DriveDlgProc(
150 HWND hwndDlg,
151 UINT uMsg,
152 WPARAM wParam,
153 LPARAM lParam)
154 {
155 PSETUPDATA pSetupData;
156 #if 1
157 HDEVINFO h;
158 HWND hList;
159 SP_DEVINFO_DATA DevInfoData;
160 DWORD i;
161 #endif
162
163 /* Retrieve pointer to the global setup data */
164 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
165
166 switch (uMsg)
167 {
168 case WM_INITDIALOG:
169 {
170 /* Save pointer to the global setup data */
171 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
172 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
173
174 CreateListViewColumns(pSetupData->hInstance,
175 GetDlgItem(hwndDlg, IDC_PARTITION),
176 column_ids,
177 column_widths,
178 column_alignment,
179 MAX_LIST_COLUMNS);
180
181 #if 1
182 h = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE, NULL, NULL, DIGCF_PRESENT);
183 if (h != INVALID_HANDLE_VALUE)
184 {
185 hList =GetDlgItem(hwndDlg, IDC_PARTITION);
186 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
187 for (i=0; SetupDiEnumDeviceInfo(h, i, &DevInfoData); i++)
188 {
189 DWORD DataT;
190 LPTSTR buffer = NULL;
191 DWORD buffersize = 0;
192
193 while (!SetupDiGetDeviceRegistryProperty(h,
194 &DevInfoData,
195 SPDRP_DEVICEDESC,
196 &DataT,
197 (PBYTE)buffer,
198 buffersize,
199 &buffersize))
200 {
201 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
202 {
203 if (buffer) LocalFree(buffer);
204 buffer = LocalAlloc(LPTR, buffersize * 2);
205 }
206 else
207 break;
208 }
209 if (buffer)
210 {
211 SendMessage(hList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
212 LocalFree(buffer);
213 }
214 }
215 SetupDiDestroyDeviceInfoList(h);
216 }
217 #endif
218 }
219 break;
220
221 case WM_COMMAND:
222 {
223 switch(LOWORD(wParam))
224 {
225 case IDC_PARTMOREOPTS:
226 DialogBoxParam(pSetupData->hInstance,
227 MAKEINTRESOURCE(IDD_BOOTOPTIONS),
228 hwndDlg,
229 MoreOptDlgProc,
230 (LPARAM)pSetupData);
231 break;
232 case IDC_PARTCREATE:
233 DialogBox(pSetupData->hInstance,
234 MAKEINTRESOURCE(IDD_PARTITION),
235 hwndDlg,
236 PartitionDlgProc);
237 break;
238 case IDC_PARTDELETE:
239 break;
240 }
241 break;
242 }
243
244 case WM_NOTIFY:
245 {
246 LPNMHDR lpnm = (LPNMHDR)lParam;
247
248 switch (lpnm->code)
249 {
250 case PSN_SETACTIVE:
251 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
252 break;
253
254 case PSN_QUERYCANCEL:
255 SetWindowLongPtr(hwndDlg,
256 DWLP_MSGRESULT,
257 MessageBox(GetParent(hwndDlg),
258 pSetupData->szAbortMessage,
259 pSetupData->szAbortTitle,
260 MB_YESNO | MB_ICONQUESTION) != IDYES);
261 return TRUE;
262
263 default:
264 break;
265 }
266 }
267 break;
268
269 default:
270 break;
271
272 }
273
274 return FALSE;
275 }
276
277 /* EOF */