2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * INCLUDES _________________________________________________________________
18 #include <afsconfig.h>
19 #include <afs/param.h>
27 #include "volume_utils.h"
31 * DEFINITIONS _________________________________________________________________
35 static HWND hDriveList = 0;
36 static BOOL bCantCreate = FALSE;
37 static HLISTITEM hSelectedItem = 0;
39 // The idea for this var is that if the user clicks on a drive and the vice name
40 // hasn't been set by the user, then we will set the vice name to the drive letter
41 // selected. However, if the user sets the vice name, then clicking on a drive
42 // letter doesn't change the vice name. This var tells us whether it is ok to set
43 // the vice name or not.
44 static BOOL bAutoSetPartitionName = TRUE;
48 * PROTOTYPES _________________________________________________________________
51 static void OnInitDialog(HWND hwndDlg);
52 static void EnableDriveListCtrls(BOOL bEnable = TRUE);
53 static BOOL SavePartitionInfo(BOOL bValidate);
54 static void ShowPartitionInfo();
55 static void CheckEnableButtons();
56 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms);
57 static void CantMakePartition(UINT nMsgID);
58 static void MustMakePartition();
59 static void OnPartitionName();
63 * EXPORTED FUNCTIONS _________________________________________________________________
68 * Dialog Proc _________________________________________________________________
72 * WndProc for our subclass of the wizard's dialog. We do this to detect
73 * the WM_ACTIVATEAPP message, which we use as a trigger to refresh the
74 * partition info that we display.
76 static BOOL CALLBACK WizardDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
78 if ((g_pWiz->GetState() == sidSTEP_EIGHT) && (uMsg == WM_ACTIVATEAPP) && wParam) {
83 return CallWindowProc((WNDPROC)Subclass_FindNextHook(hwndDlg, WizardDlgProc), hwndDlg, uMsg, wParam, lParam);
86 BOOL CALLBACK PartitionPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
88 if (WizStep_Common_DlgProc (hwndDlg, msg, wp, lp))
93 OnInitDialog(hwndDlg);
97 case WM_DESTROY_SHEET:
98 Subclass_RemoveHook(g_pWiz->GetWindow(), WizardDlgProc);
102 switch (LOWORD(wp)) {
104 if (SavePartitionInfo(TRUE))
105 g_pWiz->SetState(sidSTEP_NINE);
109 if (SavePartitionInfo(FALSE))
110 g_pWiz->SetState(sidSTEP_SEVEN);
113 case IDC_CREATE_PARTITION:
114 g_CfgData.configPartition = CS_CONFIGURE;
115 CheckEnableButtons();
116 EnableDriveListCtrls();
119 case IDC_DONT_CREATE_PARTITION:
120 g_CfgData.configPartition = CS_DONT_CONFIGURE;
121 CheckEnableButtons();
122 EnableDriveListCtrls(FALSE);
125 case IDC_PARTITION_NAME:
126 if (HIWORD(wp) == EN_CHANGE) {
135 switch (((LPNMHDR)lp)->code) {
136 case FLN_ITEMSELECT: OnListSelection((LPFLN_ITEMSELECT_PARAMS)lp);
148 * STATIC FUNCTIONS _________________________________________________________________
153 * Event Handler Functions _________________________________________________________________
156 static void OnInitDialog(HWND hwndDlg)
162 hDriveList = GetDlgItem(hDlg, IDC_DRIVE_LIST);
164 g_pWiz->SetButtonText(IDNEXT, IDS_NEXT);
165 g_pWiz->SetDefaultControl(IDNEXT);
167 if (g_CfgData.configPartition == CS_ALREADY_CONFIGURED) {
168 CantMakePartition(IDS_PARTITION_ALREADY_CREATED);
172 // Should this step be disabled? Yes, if this machine is
173 // not configured as a file server.
174 if (!ConfiguredOrConfiguring(g_CfgData.configFS)) {
175 CantMakePartition(IDS_NOT_A_FS_SERVER);
176 EnableStep(g_CfgData.configPartition, FALSE);
180 // Do this in case it was disabled the last time
181 EnableStep(g_CfgData.configPartition);
183 switch (g_CfgData.configPartition) {
184 case CS_DONT_CONFIGURE:
185 SetCheck(hDlg, IDC_DONT_CREATE_PARTITION);
186 EnableDriveListCtrls(FALSE);
191 SetCheck(hDlg, IDC_CREATE_PARTITION);
192 EnableDriveListCtrls();
196 Subclass_AddHook(g_pWiz->GetWindow(), WizardDlgProc);
198 SetupDriveList(hDriveList);
202 if (g_CfgData.bFirstServer)
206 static void OnPartitionName()
208 TCHAR szBuf[MAX_PARTITION_NAME_LEN];
209 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
211 bAutoSetPartitionName = szBuf[0] == 0;
213 CheckEnableButtons();
216 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms)
222 if (pItemParms->hItem) {
223 LPARAM lParam = FastList_GetItemParam(hDriveList, pItemParms->hItem);
225 hSelectedItem = pItemParms->hItem;
227 if (bAutoSetPartitionName) {
228 LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
229 g_CfgData.szPartitionName[0] = _totlower(pDrive[0]);
230 g_CfgData.szPartitionName[1] = 0;
231 SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
233 // Must set this to true because the call to SetWndText will cause
234 // a call to OnPartitionName, which would incorrectly think that the
235 // Partition Name had been set by the user rather than by us, thus
236 // setting bAutoSetPartitionName to false.
237 bAutoSetPartitionName = TRUE;
242 CheckEnableButtons();
247 * Utility Functions _________________________________________________________________
250 static void CantMakePartition(UINT nMsgID)
252 TCHAR szMsg[cchRESOURCE];
254 GetString(szMsg, nMsgID);
256 ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
257 ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
258 ShowWnd(hDlg, IDC_ASK_CREATE_PARTITION, FALSE);
259 ShowWnd(hDlg, IDC_SELECT_DRIVE, FALSE);
260 ShowWnd(hDlg, IDC_DRIVE_LIST, FALSE);
261 ShowWnd(hDlg, IDC_NAME_LABEL, FALSE);
262 ShowWnd(hDlg, IDC_PARTITION_NAME, FALSE);
264 ShowWnd(hDlg, IDC_PARTITION_COVER);
265 HWND hMsg = GetDlgItem(hDlg, IDC_PARTITION_MSG);
266 ShowWindow(hMsg, SW_SHOW);
267 SetWindowText(hMsg, szMsg);
272 static void MustMakePartition()
274 TCHAR szMsg[cchRESOURCE];
276 GetString(szMsg, IDS_MUST_MAKE_PARTITION);
278 ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
279 ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
281 SetWndText(hDlg, IDC_ASK_CREATE_PARTITION, szMsg);
284 static void EnableDriveListCtrls(BOOL bEnable)
286 EnableWnd(hDlg, IDC_SELECT_DRIVE, bEnable);
287 EnableWnd(hDlg, IDC_DRIVE_LIST, bEnable);
288 EnableWnd(hDlg, IDC_NAME_LABEL, bEnable);
289 EnableWnd(hDlg, IDC_PARTITION_NAME, bEnable);
292 static BOOL SavePartitionInfo(BOOL bValidate)
297 if (GetButtonState(hDlg, IDC_CREATE_PARTITION) != BST_CHECKED) {
298 g_CfgData.szPartitionName[0] = 0;
299 bAutoSetPartitionName = TRUE;
301 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), g_CfgData.szPartitionName, MAX_PARTITION_NAME_LEN);
302 if (bValidate && !Validation_IsValid(g_CfgData.szPartitionName, VALID_AFS_PARTITION_NAME))
306 if (hSelectedItem == 0)
307 g_CfgData.chDeviceName = 0;
309 LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
310 g_CfgData.chDeviceName = pDrive[0];
316 static void ShowPartitionInfo()
318 // The SetWndText call below will mess up our bAutoSetPartitionName variable.
319 // It will trigger the change event on the partition name field causing our
320 // OnPartitionName function to get called, and making it look to us like the
321 // user set the partition name. Therefore, we will save the current value,
322 // make the call, then restore the value.
323 BOOL bAutoSet = bAutoSetPartitionName;
324 SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
325 bAutoSetPartitionName = bAutoSet;
327 if (g_CfgData.chDeviceName != 0) {
328 HLISTITEM hItem = NULL;
329 while ((hItem = FastList_FindNext(hDriveList, hItem)) != NULL) {
330 LPCTSTR pDrive = FastList_GetItemText(hDriveList, hItem, 0);
331 if (pDrive[0] == g_CfgData.chDeviceName) {
332 FastList_SelectItem(hDriveList, hItem, TRUE);
333 hSelectedItem = hItem;
340 static void CheckEnableButtons()
342 if (IsButtonChecked(hDlg, IDC_CREATE_PARTITION)) {
343 TCHAR szBuf[MAX_PARTITION_NAME_LEN];
345 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
346 if ((hSelectedItem == 0) || (szBuf[0] == 0)) {
347 g_pWiz->EnableButtons(BACK_BUTTON);
348 g_pWiz->SetDefaultControl(IDBACK);
353 g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);