~ubuntu-branches/ubuntu/warty/openafs/warty

« back to all changes in this revision

Viewing changes to src/WINNT/afssvrcfg/partition_page.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-01-10 16:37:33 UTC
  • Revision ID: james.westby@ubuntu.com-20040110163733-jvr0n1uahshlb1uu
Tags: upstream-1.2.11
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2000, International Business Machines Corporation and others.
 
3
 * All Rights Reserved.
 
4
 * 
 
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
 
8
 */
 
9
 
 
10
/*
 
11
 * INCLUDES _________________________________________________________________
 
12
 *
 
13
 */
 
14
extern "C" {
 
15
#include <afs/param.h>
 
16
#include <afs/stds.h>
 
17
}
 
18
 
 
19
#include "afscfg.h"
 
20
#include <stdlib.h>
 
21
#include "resource.h"
 
22
#include "volume_utils.h"
 
23
 
 
24
 
 
25
/*
 
26
 * DEFINITIONS _________________________________________________________________
 
27
 *
 
28
 */
 
29
static HWND hDlg = 0;
 
30
static HWND hDriveList = 0;
 
31
static BOOL bCantCreate = FALSE;
 
32
static HLISTITEM hSelectedItem = 0;
 
33
 
 
34
//      The idea for this var is that if the user clicks on a drive and the vice name
 
35
//      hasn't been set by the user, then we will set the vice name to the drive letter 
 
36
//      selected.  However, if the user sets the vice name, then clicking on a drive 
 
37
//      letter doesn't change the vice name.  This var tells us whether it is ok to set
 
38
//      the vice name or not.
 
39
static BOOL bAutoSetPartitionName = TRUE;
 
40
 
 
41
 
 
42
/*
 
43
 * PROTOTYPES _________________________________________________________________
 
44
 *
 
45
 */
 
46
static void OnInitDialog(HWND hwndDlg);
 
47
static void EnableDriveListCtrls(BOOL bEnable = TRUE);
 
48
static BOOL SavePartitionInfo(BOOL bValidate);
 
49
static void ShowPartitionInfo();
 
50
static void CheckEnableButtons();
 
51
static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms);
 
52
static void CantMakePartition(UINT nMsgID);
 
53
static void MustMakePartition();
 
54
static void OnPartitionName();
 
55
 
 
56
 
 
57
/*
 
58
 * EXPORTED FUNCTIONS _________________________________________________________________
 
59
 *
 
60
 */
 
61
 
 
62
/*
 
63
 * Dialog Proc _________________________________________________________________
 
64
 *
 
65
 */
 
66
/*
 
67
 * WndProc for our subclass of the wizard's dialog.  We do this to detect
 
68
 * the WM_ACTIVATEAPP message, which we use as a trigger to refresh the
 
69
 * partition info that we display.
 
70
 */
 
71
static BOOL CALLBACK WizardDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
72
{
 
73
        if ((g_pWiz->GetState() == sidSTEP_EIGHT) && (uMsg == WM_ACTIVATEAPP) && wParam) {
 
74
                UpdateDriveList();
 
75
                ShowPartitionInfo();
 
76
        }               
 
77
 
 
78
        return CallWindowProc((WNDPROC)Subclass_FindNextHook(hwndDlg, WizardDlgProc), hwndDlg, uMsg, wParam, lParam);
 
79
}
 
80
 
 
81
BOOL CALLBACK PartitionPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
 
82
{
 
83
        if (WizStep_Common_DlgProc (hwndDlg, msg, wp, lp))
 
84
                return FALSE;
 
85
 
 
86
        switch (msg) {
 
87
                case WM_INITDIALOG:
 
88
                 OnInitDialog(hwndDlg);
 
89
                         CheckEnableButtons();
 
90
                     break;
 
91
 
 
92
                case WM_DESTROY_SHEET:  
 
93
                        Subclass_RemoveHook(g_pWiz->GetWindow(), WizardDlgProc);
 
94
                        break;
 
95
 
 
96
                case WM_COMMAND:
 
97
                        switch (LOWORD(wp)) {
 
98
                                case IDNEXT:
 
99
                                        if (SavePartitionInfo(TRUE))
 
100
                                            g_pWiz->SetState(sidSTEP_NINE);
 
101
                                        break;
 
102
 
 
103
                                case IDBACK:
 
104
                                        if (SavePartitionInfo(FALSE))
 
105
                                            g_pWiz->SetState(sidSTEP_SEVEN);
 
106
                                        break;
 
107
 
 
108
                                case IDC_CREATE_PARTITION:
 
109
                                        g_CfgData.configPartition = CS_CONFIGURE;
 
110
                                        CheckEnableButtons();
 
111
                                        EnableDriveListCtrls();
 
112
                                        break;
 
113
 
 
114
                                case IDC_DONT_CREATE_PARTITION:
 
115
                                        g_CfgData.configPartition = CS_DONT_CONFIGURE;
 
116
                                        CheckEnableButtons();
 
117
                                        EnableDriveListCtrls(FALSE);
 
118
                                        break;
 
119
 
 
120
                                case IDC_PARTITION_NAME:
 
121
                                        if (HIWORD(wp) == EN_CHANGE) {
 
122
                                                OnPartitionName();
 
123
                                                SetFocus((HWND)lp);
 
124
                                        }
 
125
                                        break;
 
126
                        }
 
127
                        break;
 
128
 
 
129
                case WM_NOTIFY: 
 
130
                        switch (((LPNMHDR)lp)->code) {
 
131
                                case FLN_ITEMSELECT:    OnListSelection((LPFLN_ITEMSELECT_PARAMS)lp);
 
132
                        }
 
133
                        break;
 
134
 
 
135
        }
 
136
 
 
137
        return FALSE;
 
138
}
 
139
 
 
140
 
 
141
 
 
142
/*
 
143
 * STATIC FUNCTIONS _________________________________________________________________
 
144
 *
 
145
 */
 
146
 
 
147
/*
 
148
 * Event Handler Functions _________________________________________________________________
 
149
 *
 
150
 */
 
151
static void OnInitDialog(HWND hwndDlg)
 
152
{
 
153
        HOURGLASS hg;
 
154
 
 
155
        hDlg = hwndDlg;
 
156
 
 
157
        hDriveList = GetDlgItem(hDlg, IDC_DRIVE_LIST);
 
158
 
 
159
        g_pWiz->SetButtonText(IDNEXT, IDS_NEXT);
 
160
        g_pWiz->SetDefaultControl(IDNEXT);
 
161
 
 
162
        if (g_CfgData.configPartition == CS_ALREADY_CONFIGURED) {
 
163
                CantMakePartition(IDS_PARTITION_ALREADY_CREATED);
 
164
                return;
 
165
        }
 
166
 
 
167
        // Should this step be disabled?  Yes, if this machine is
 
168
        // not configured as a file server.
 
169
        if (!ConfiguredOrConfiguring(g_CfgData.configFS)) {
 
170
                CantMakePartition(IDS_NOT_A_FS_SERVER);
 
171
                EnableStep(g_CfgData.configPartition, FALSE);
 
172
                return;
 
173
        }
 
174
 
 
175
        // Do this in case it was disabled the last time
 
176
        EnableStep(g_CfgData.configPartition);
 
177
 
 
178
        switch (g_CfgData.configPartition) {
 
179
                case CS_DONT_CONFIGURE:
 
180
                        SetCheck(hDlg, IDC_DONT_CREATE_PARTITION);
 
181
                        EnableDriveListCtrls(FALSE);
 
182
                        break;
 
183
 
 
184
                case CS_CONFIGURE:
 
185
                default:
 
186
                        SetCheck(hDlg, IDC_CREATE_PARTITION);
 
187
                        EnableDriveListCtrls();
 
188
                        break;
 
189
        }
 
190
 
 
191
        Subclass_AddHook(g_pWiz->GetWindow(), WizardDlgProc);
 
192
 
 
193
        SetupDriveList(hDriveList);
 
194
        UpdateDriveList();
 
195
        ShowPartitionInfo();
 
196
 
 
197
        if (g_CfgData.bFirstServer)
 
198
                MustMakePartition();
 
199
}       
 
200
 
 
201
static void OnPartitionName()
 
202
{
 
203
        TCHAR szBuf[MAX_PARTITION_NAME_LEN];
 
204
        GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
 
205
 
 
206
        bAutoSetPartitionName = szBuf[0] == 0;
 
207
        
 
208
        CheckEnableButtons();
 
209
}
 
210
 
 
211
static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms)
 
212
{
 
213
        ASSERT(pItemParms);
 
214
 
 
215
        hSelectedItem = 0;
 
216
 
 
217
        if (pItemParms->hItem) {
 
218
                LPARAM lParam = FastList_GetItemParam(hDriveList, pItemParms->hItem);
 
219
                if (lParam == 0) {
 
220
                        hSelectedItem = pItemParms->hItem;
 
221
 
 
222
                        if (bAutoSetPartitionName) {
 
223
                                LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
 
224
                                g_CfgData.szPartitionName[0] = _totlower(pDrive[0]);
 
225
                                g_CfgData.szPartitionName[1] = 0;
 
226
                                SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
 
227
 
 
228
                                // Must set this to true because the call to SetWndText will cause
 
229
                                // a call to OnPartitionName, which would incorrectly think that the
 
230
                                // Partition Name had been set by the user rather than by us, thus
 
231
                                // setting bAutoSetPartitionName to false.
 
232
                                bAutoSetPartitionName = TRUE;
 
233
                        }
 
234
                }
 
235
        }
 
236
 
 
237
        CheckEnableButtons();
 
238
}
 
239
 
 
240
 
 
241
/*
 
242
 * Utility Functions _________________________________________________________________
 
243
 *
 
244
 */
 
245
static void CantMakePartition(UINT nMsgID)
 
246
{
 
247
        TCHAR szMsg[cchRESOURCE];
 
248
 
 
249
        GetString(szMsg, nMsgID);
 
250
 
 
251
        ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
 
252
        ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
 
253
        ShowWnd(hDlg, IDC_ASK_CREATE_PARTITION, FALSE);
 
254
        ShowWnd(hDlg, IDC_SELECT_DRIVE, FALSE);
 
255
        ShowWnd(hDlg, IDC_DRIVE_LIST, FALSE);
 
256
        ShowWnd(hDlg, IDC_NAME_LABEL, FALSE);
 
257
        ShowWnd(hDlg, IDC_PARTITION_NAME, FALSE);
 
258
 
 
259
        ShowWnd(hDlg, IDC_PARTITION_COVER);
 
260
        HWND hMsg = GetDlgItem(hDlg, IDC_PARTITION_MSG);
 
261
        ShowWindow(hMsg, SW_SHOW);
 
262
        SetWindowText(hMsg, szMsg);
 
263
 
 
264
        bCantCreate = TRUE;
 
265
}
 
266
 
 
267
static void MustMakePartition()
 
268
{
 
269
        TCHAR szMsg[cchRESOURCE];
 
270
 
 
271
        GetString(szMsg, IDS_MUST_MAKE_PARTITION);
 
272
        
 
273
        ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
 
274
        ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
 
275
 
 
276
        SetWndText(hDlg, IDC_ASK_CREATE_PARTITION, szMsg);
 
277
}
 
278
 
 
279
static void EnableDriveListCtrls(BOOL bEnable)
 
280
{
 
281
        EnableWnd(hDlg, IDC_SELECT_DRIVE, bEnable);
 
282
        EnableWnd(hDlg, IDC_DRIVE_LIST, bEnable);
 
283
        EnableWnd(hDlg, IDC_NAME_LABEL, bEnable);
 
284
        EnableWnd(hDlg, IDC_PARTITION_NAME, bEnable);
 
285
}
 
286
 
 
287
static BOOL SavePartitionInfo(BOOL bValidate)
 
288
{
 
289
        if (bCantCreate)
 
290
                return TRUE;
 
291
 
 
292
    if (GetButtonState(hDlg, IDC_CREATE_PARTITION) != BST_CHECKED) {
 
293
            g_CfgData.szPartitionName[0] = 0;
 
294
            bAutoSetPartitionName = TRUE;
 
295
        } else {
 
296
            GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), g_CfgData.szPartitionName, MAX_PARTITION_NAME_LEN);
 
297
        if (bValidate && !Validation_IsValid(g_CfgData.szPartitionName, VALID_AFS_PARTITION_NAME))
 
298
            return FALSE;
 
299
    }
 
300
 
 
301
        if (hSelectedItem == 0)
 
302
                g_CfgData.chDeviceName = 0;
 
303
        else {
 
304
                LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
 
305
                g_CfgData.chDeviceName = pDrive[0];
 
306
        }
 
307
 
 
308
    return TRUE;
 
309
}
 
310
 
 
311
static void ShowPartitionInfo()
 
312
{
 
313
    // The SetWndText call below will mess up our bAutoSetPartitionName variable.
 
314
    // It will trigger the change event on the partition name field causing our 
 
315
    // OnPartitionName function to get called, and making it look to us like the 
 
316
    // user set the partition name.  Therefore, we will save the current value,
 
317
    // make the call, then restore the value.
 
318
    BOOL bAutoSet = bAutoSetPartitionName;      
 
319
    SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
 
320
    bAutoSetPartitionName = bAutoSet;
 
321
 
 
322
        if (g_CfgData.chDeviceName != 0) {
 
323
                HLISTITEM hItem = NULL;
 
324
                while ((hItem = FastList_FindNext(hDriveList, hItem)) != NULL) {
 
325
                        LPCTSTR pDrive = FastList_GetItemText(hDriveList, hItem, 0);
 
326
                        if (pDrive[0] == g_CfgData.chDeviceName) {
 
327
                                FastList_SelectItem(hDriveList, hItem, TRUE);
 
328
                                hSelectedItem = hItem;
 
329
                                break;
 
330
                        }
 
331
                }
 
332
        }
 
333
}
 
334
 
 
335
static void CheckEnableButtons()
 
336
{
 
337
        if (IsButtonChecked(hDlg, IDC_CREATE_PARTITION)) {
 
338
                TCHAR szBuf[MAX_PARTITION_NAME_LEN];
 
339
 
 
340
                GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
 
341
                if ((hSelectedItem == 0) || (szBuf[0] == 0)) {
 
342
                        g_pWiz->EnableButtons(BACK_BUTTON);
 
343
                        g_pWiz->SetDefaultControl(IDBACK);
 
344
                        return;
 
345
                }
 
346
        }
 
347
                
 
348
        g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
 
349
}
 
350