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 <afs/param.h>
25 #include "volume_utils.h"
29 * DEFINITIONS _________________________________________________________________
33 static HWND hDriveList
= 0;
34 static BOOL bCantCreate
= FALSE
;
35 static HLISTITEM hSelectedItem
= 0;
37 // The idea for this var is that if the user clicks on a drive and the vice name
38 // hasn't been set by the user, then we will set the vice name to the drive letter
39 // selected. However, if the user sets the vice name, then clicking on a drive
40 // letter doesn't change the vice name. This var tells us whether it is ok to set
41 // the vice name or not.
42 static BOOL bAutoSetPartitionName
= TRUE
;
46 * PROTOTYPES _________________________________________________________________
49 static void OnInitDialog(HWND hwndDlg
);
50 static void EnableDriveListCtrls(BOOL bEnable
= TRUE
);
51 static BOOL
SavePartitionInfo(BOOL bValidate
);
52 static void ShowPartitionInfo();
53 static void CheckEnableButtons();
54 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms
);
55 static void CantMakePartition(UINT nMsgID
);
56 static void MustMakePartition();
57 static void OnPartitionName();
61 * EXPORTED FUNCTIONS _________________________________________________________________
66 * Dialog Proc _________________________________________________________________
70 * WndProc for our subclass of the wizard's dialog. We do this to detect
71 * the WM_ACTIVATEAPP message, which we use as a trigger to refresh the
72 * partition info that we display.
74 static BOOL CALLBACK
WizardDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
76 if ((g_pWiz
->GetState() == sidSTEP_EIGHT
) && (uMsg
== WM_ACTIVATEAPP
) && wParam
) {
81 return CallWindowProc((WNDPROC
)Subclass_FindNextHook(hwndDlg
, WizardDlgProc
), hwndDlg
, uMsg
, wParam
, lParam
);
84 BOOL CALLBACK
PartitionPageDlgProc(HWND hwndDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
86 if (WizStep_Common_DlgProc (hwndDlg
, msg
, wp
, lp
))
91 OnInitDialog(hwndDlg
);
95 case WM_DESTROY_SHEET
:
96 Subclass_RemoveHook(g_pWiz
->GetWindow(), WizardDlgProc
);
100 switch (LOWORD(wp
)) {
102 if (SavePartitionInfo(TRUE
))
103 g_pWiz
->SetState(sidSTEP_NINE
);
107 if (SavePartitionInfo(FALSE
))
108 g_pWiz
->SetState(sidSTEP_SEVEN
);
111 case IDC_CREATE_PARTITION
:
112 g_CfgData
.configPartition
= CS_CONFIGURE
;
113 CheckEnableButtons();
114 EnableDriveListCtrls();
117 case IDC_DONT_CREATE_PARTITION
:
118 g_CfgData
.configPartition
= CS_DONT_CONFIGURE
;
119 CheckEnableButtons();
120 EnableDriveListCtrls(FALSE
);
123 case IDC_PARTITION_NAME
:
124 if (HIWORD(wp
) == EN_CHANGE
) {
133 switch (((LPNMHDR
)lp
)->code
) {
134 case FLN_ITEMSELECT
: OnListSelection((LPFLN_ITEMSELECT_PARAMS
)lp
);
146 * STATIC FUNCTIONS _________________________________________________________________
151 * Event Handler Functions _________________________________________________________________
154 static void OnInitDialog(HWND hwndDlg
)
160 hDriveList
= GetDlgItem(hDlg
, IDC_DRIVE_LIST
);
162 g_pWiz
->SetButtonText(IDNEXT
, IDS_NEXT
);
163 g_pWiz
->SetDefaultControl(IDNEXT
);
165 if (g_CfgData
.configPartition
== CS_ALREADY_CONFIGURED
) {
166 CantMakePartition(IDS_PARTITION_ALREADY_CREATED
);
170 // Should this step be disabled? Yes, if this machine is
171 // not configured as a file server.
172 if (!ConfiguredOrConfiguring(g_CfgData
.configFS
)) {
173 CantMakePartition(IDS_NOT_A_FS_SERVER
);
174 EnableStep(g_CfgData
.configPartition
, FALSE
);
178 // Do this in case it was disabled the last time
179 EnableStep(g_CfgData
.configPartition
);
181 switch (g_CfgData
.configPartition
) {
182 case CS_DONT_CONFIGURE
:
183 SetCheck(hDlg
, IDC_DONT_CREATE_PARTITION
);
184 EnableDriveListCtrls(FALSE
);
189 SetCheck(hDlg
, IDC_CREATE_PARTITION
);
190 EnableDriveListCtrls();
194 Subclass_AddHook(g_pWiz
->GetWindow(), WizardDlgProc
);
196 SetupDriveList(hDriveList
);
200 if (g_CfgData
.bFirstServer
)
204 static void OnPartitionName()
206 TCHAR szBuf
[MAX_PARTITION_NAME_LEN
];
207 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), szBuf
, MAX_PARTITION_NAME_LEN
);
209 bAutoSetPartitionName
= szBuf
[0] == 0;
211 CheckEnableButtons();
214 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms
)
220 if (pItemParms
->hItem
) {
221 LPARAM lParam
= FastList_GetItemParam(hDriveList
, pItemParms
->hItem
);
223 hSelectedItem
= pItemParms
->hItem
;
225 if (bAutoSetPartitionName
) {
226 LPCTSTR pDrive
= FastList_GetItemText(hDriveList
, hSelectedItem
, 0);
227 g_CfgData
.szPartitionName
[0] = _totlower(pDrive
[0]);
228 g_CfgData
.szPartitionName
[1] = 0;
229 SetWndText(hDlg
, IDC_PARTITION_NAME
, g_CfgData
.szPartitionName
);
231 // Must set this to true because the call to SetWndText will cause
232 // a call to OnPartitionName, which would incorrectly think that the
233 // Partition Name had been set by the user rather than by us, thus
234 // setting bAutoSetPartitionName to false.
235 bAutoSetPartitionName
= TRUE
;
240 CheckEnableButtons();
245 * Utility Functions _________________________________________________________________
248 static void CantMakePartition(UINT nMsgID
)
250 TCHAR szMsg
[cchRESOURCE
];
252 GetString(szMsg
, nMsgID
);
254 ShowWnd(hDlg
, IDC_CREATE_PARTITION
, FALSE
);
255 ShowWnd(hDlg
, IDC_DONT_CREATE_PARTITION
, FALSE
);
256 ShowWnd(hDlg
, IDC_ASK_CREATE_PARTITION
, FALSE
);
257 ShowWnd(hDlg
, IDC_SELECT_DRIVE
, FALSE
);
258 ShowWnd(hDlg
, IDC_DRIVE_LIST
, FALSE
);
259 ShowWnd(hDlg
, IDC_NAME_LABEL
, FALSE
);
260 ShowWnd(hDlg
, IDC_PARTITION_NAME
, FALSE
);
262 ShowWnd(hDlg
, IDC_PARTITION_COVER
);
263 HWND hMsg
= GetDlgItem(hDlg
, IDC_PARTITION_MSG
);
264 ShowWindow(hMsg
, SW_SHOW
);
265 SetWindowText(hMsg
, szMsg
);
270 static void MustMakePartition()
272 TCHAR szMsg
[cchRESOURCE
];
274 GetString(szMsg
, IDS_MUST_MAKE_PARTITION
);
276 ShowWnd(hDlg
, IDC_CREATE_PARTITION
, FALSE
);
277 ShowWnd(hDlg
, IDC_DONT_CREATE_PARTITION
, FALSE
);
279 SetWndText(hDlg
, IDC_ASK_CREATE_PARTITION
, szMsg
);
282 static void EnableDriveListCtrls(BOOL bEnable
)
284 EnableWnd(hDlg
, IDC_SELECT_DRIVE
, bEnable
);
285 EnableWnd(hDlg
, IDC_DRIVE_LIST
, bEnable
);
286 EnableWnd(hDlg
, IDC_NAME_LABEL
, bEnable
);
287 EnableWnd(hDlg
, IDC_PARTITION_NAME
, bEnable
);
290 static BOOL
SavePartitionInfo(BOOL bValidate
)
295 if (GetButtonState(hDlg
, IDC_CREATE_PARTITION
) != BST_CHECKED
) {
296 g_CfgData
.szPartitionName
[0] = 0;
297 bAutoSetPartitionName
= TRUE
;
299 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), g_CfgData
.szPartitionName
, MAX_PARTITION_NAME_LEN
);
300 if (bValidate
&& !Validation_IsValid(g_CfgData
.szPartitionName
, VALID_AFS_PARTITION_NAME
))
304 if (hSelectedItem
== 0)
305 g_CfgData
.chDeviceName
= 0;
307 LPCTSTR pDrive
= FastList_GetItemText(hDriveList
, hSelectedItem
, 0);
308 g_CfgData
.chDeviceName
= pDrive
[0];
314 static void ShowPartitionInfo()
316 // The SetWndText call below will mess up our bAutoSetPartitionName variable.
317 // It will trigger the change event on the partition name field causing our
318 // OnPartitionName function to get called, and making it look to us like the
319 // user set the partition name. Therefore, we will save the current value,
320 // make the call, then restore the value.
321 BOOL bAutoSet
= bAutoSetPartitionName
;
322 SetWndText(hDlg
, IDC_PARTITION_NAME
, g_CfgData
.szPartitionName
);
323 bAutoSetPartitionName
= bAutoSet
;
325 if (g_CfgData
.chDeviceName
!= 0) {
326 HLISTITEM hItem
= NULL
;
327 while ((hItem
= FastList_FindNext(hDriveList
, hItem
)) != NULL
) {
328 LPCTSTR pDrive
= FastList_GetItemText(hDriveList
, hItem
, 0);
329 if (pDrive
[0] == g_CfgData
.chDeviceName
) {
330 FastList_SelectItem(hDriveList
, hItem
, TRUE
);
331 hSelectedItem
= hItem
;
338 static void CheckEnableButtons()
340 if (IsButtonChecked(hDlg
, IDC_CREATE_PARTITION
)) {
341 TCHAR szBuf
[MAX_PARTITION_NAME_LEN
];
343 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), szBuf
, MAX_PARTITION_NAME_LEN
);
344 if ((hSelectedItem
== 0) || (szBuf
[0] == 0)) {
345 g_pWiz
->EnableButtons(BACK_BUTTON
);
346 g_pWiz
->SetDefaultControl(IDBACK
);
351 g_pWiz
->EnableButtons(BACK_BUTTON
| NEXT_BUTTON
);