Windows: remove trailing whitespace
[openafs.git] / src / WINNT / afssvrmgr / set_create.cpp
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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "svrmgr.h"
19 #include "set_create.h"
20 #include "set_general.h"
21 #include "propcache.h"
22 #include "columns.h"
23 #include "svr_window.h"
24 #include "display.h"
25
26
27 /*
28  * PROTOTYPES _________________________________________________________________
29  *
30  */
31
32 BOOL CALLBACK Filesets_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
33 void Filesets_Create_OnInitDialog (HWND hDlg, LPSET_CREATE_PARAMS pscp);
34 void Filesets_Create_OnSelectServer (HWND hDlg, LPIDENT *plpiTarget);
35 void Filesets_Create_OnEndTask_FindQuotaLimits (HWND hDlg, LPTASKPACKET ptp, LPSET_CREATE_PARAMS pscp);
36 void Filesets_Create_OnEndTask_EnumAggregates (HWND hDlg);
37 void Filesets_Create_StartDisplay_Aggregates (HWND hDlg, LPIDENT *plpiTarget);
38 void Filesets_Create_EnableOK (HWND hDlg, LPSET_CREATE_PARAMS pscp);
39
40
41 /*
42  * ROUTINES ___________________________________________________________________
43  *
44  */
45
46 void Filesets_Create (LPIDENT lpiParent)
47 {
48    LPSET_CREATE_PARAMS pscp = New (SET_CREATE_PARAMS);
49    memset (pscp, 0x00, sizeof(SET_CREATE_PARAMS));
50    pscp->lpiParent = lpiParent;
51    pscp->szName[0] = TEXT('\0');
52    pscp->fCreateClone = FALSE;
53    pscp->ckQuota = ckQUOTA_DEFAULT;
54
55    // Show the Create dialog.
56    //
57    INT_PTR rc = ModalDialogParam (IDD_SET_CREATE, GetActiveWindow(), (DLGPROC)Filesets_Create_DlgProc, (LPARAM)pscp);
58
59    if (rc != IDOK)
60       {
61       Delete (pscp);
62       }
63    else if (!ASSERT( pscp->lpiParent && pscp->lpiParent->fIsAggregate() ))
64       {
65       Delete (pscp);
66       }
67    else if (!ASSERT( pscp->szName[0] != TEXT('\0') ))
68       {
69       Delete (pscp);
70       }
71    else
72       {
73       StartTask (taskSET_CREATE, NULL, pscp);
74       }
75 }
76
77
78 BOOL CALLBACK Filesets_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
79 {
80    static LPSET_CREATE_PARAMS pscp = NULL;
81    if (msg == WM_INITDIALOG)
82       pscp = (LPSET_CREATE_PARAMS)lp;
83
84    if (HandleColumnNotify (hDlg, msg, wp, lp, &gr.viewAggCreate))
85       return FALSE;
86
87    if (AfsAppLib_HandleHelp (IDD_SET_CREATE, hDlg, msg, wp, lp))
88       return TRUE;
89
90    if (pscp != NULL)
91       {
92       switch (msg)
93          {
94          case WM_INITDIALOG:
95             FastList_SetTextCallback (GetDlgItem (hDlg, IDC_AGG_LIST), GetItemText, &gr.viewAggCreate);
96             Filesets_Create_OnInitDialog (hDlg, pscp);
97             break;
98
99          case WM_CONTEXTMENU:
100             HWND hList;
101             hList = GetDlgItem (hDlg, IDC_AGG_LIST);
102
103             POINT ptScreen;
104             POINT ptClient;
105             ptScreen.x = LOWORD(lp);
106             ptScreen.y = HIWORD(lp);
107
108             ptClient = ptScreen;
109             ScreenToClient (hList, &ptClient);
110
111             if (FL_HitTestForHeaderBar (hList, ptClient))
112                {
113                HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
114                DisplayContextMenu (hm, ptScreen, hList);
115                }
116             break;
117
118          case WM_ENDTASK:
119             LPTASKPACKET ptp;
120             if ((ptp = (LPTASKPACKET)lp) != NULL)
121                {
122                if (ptp->idTask == taskAGG_FIND_QUOTA_LIMITS)
123                   Filesets_Create_OnEndTask_FindQuotaLimits (hDlg, ptp, pscp);
124                else if (ptp->idTask == taskAGG_ENUM_TO_LISTVIEW)
125                   Filesets_Create_OnEndTask_EnumAggregates (hDlg);
126                else if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
127                   {
128                   EnableWindow (GetDlgItem (hDlg, IDC_SET_SERVER), TRUE);
129                   Filesets_Create_StartDisplay_Aggregates (hDlg, &pscp->lpiParent);
130                   }
131                FreeTaskPacket (ptp);
132                }
133             break;
134
135          case WM_COLUMNS_CHANGED:
136             LPARAM lpSel;
137             lpSel = FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST));
138             FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggCreate);
139             Filesets_Create_OnSelectServer (hDlg, (LPIDENT*)&lpSel);
140             break;
141
142          case WM_COMMAND:
143             switch (LOWORD(wp))
144                {
145                case IDOK:
146                   if (pscp->lpiParent && pscp->lpiParent->fIsAggregate() && pscp->szName[0])
147                      EndDialog (hDlg, LOWORD(wp));
148                   break;
149
150                case IDCANCEL:
151                   EndDialog (hDlg, LOWORD(wp));
152                   break;
153
154                case IDC_SET_SERVER:
155                   if (HIWORD(wp) == CBN_SELCHANGE)
156                      Filesets_Create_OnSelectServer (hDlg, &pscp->lpiParent);
157                   break;
158
159                case IDC_SET_NAME:
160                   GetDlgItemText (hDlg, IDC_SET_NAME, pscp->szName, cchNAME);
161                   Filesets_Create_EnableOK (hDlg, pscp);
162                   break;
163
164                case IDC_SET_QUOTA:
165                   if (HIWORD(wp) == SPN_UPDATE)
166                      {
167                      pscp->ckQuota = SP_GetPos (GetDlgItem (hDlg, IDC_SET_QUOTA));
168                      if (gr.cbQuotaUnits == cb1MB)
169                         pscp->ckQuota *= ck1MB;
170                      }
171                   break;
172
173                case IDC_SET_QUOTA_UNITS:
174                   if (HIWORD(wp) == CBN_SELCHANGE)
175                      {
176                      gr.cbQuotaUnits = (size_t)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SET_QUOTA_UNITS));
177                      StartTask (taskAGG_FIND_QUOTA_LIMITS, hDlg, pscp->lpiParent);
178                      }
179                   break;
180
181                case IDC_SET_CLONE:
182                   pscp->fCreateClone = IsDlgButtonChecked (hDlg, IDC_SET_CLONE);
183                   break;
184                }
185             break;
186
187          case WM_DESTROY:
188             FL_StoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggCreate);
189             pscp = NULL;
190             break;
191
192          case WM_NOTIFY:
193             switch (((LPNMHDR)lp)->code)
194                {
195                case FLN_ITEMSELECT:
196                   LPIDENT lpi;
197                   if ((lpi = (LPIDENT)FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST))) != NULL)
198                      {
199                      pscp->lpiParent = lpi;
200
201                      StartTask (taskAGG_FIND_QUOTA_LIMITS, hDlg, pscp->lpiParent);
202                      Filesets_Create_EnableOK (hDlg, pscp);
203                      }
204                   break;
205                }
206             break;
207          }
208       }
209
210    return FALSE;
211 }
212
213
214 static LONG_PTR procFilesetsCreateList = 0;
215
216 LRESULT CALLBACK Filesets_Create_SubclassListProc (HWND hList, UINT msg, WPARAM wp, LPARAM lp)
217 {
218    LRESULT rc;
219
220    if (procFilesetsCreateList == 0)
221       rc = DefWindowProc (hList, msg, wp, lp);
222    else
223       rc = CallWindowProc ((WNDPROC)procFilesetsCreateList, hList, msg, wp, lp);
224
225    switch (msg)
226       {
227       case WM_DESTROY:
228          if (procFilesetsCreateList != 0)
229             SetWindowLongPtr (hList, GWLP_WNDPROC, procFilesetsCreateList);
230          break;
231
232       case WM_COMMAND:
233          switch (LOWORD(wp))
234             {
235             case M_COLUMNS:
236                ShowColumnsDialog (GetParent (hList), &gr.viewAggCreate);
237                break;
238             }
239          break;
240       }
241
242    return rc;
243 }
244
245
246 void Filesets_Create_OnInitDialog (HWND hDlg, LPSET_CREATE_PARAMS pscp)
247 {
248    HWND hList = GetDlgItem (hDlg, IDC_AGG_LIST);
249    if (procFilesetsCreateList == 0)
250       procFilesetsCreateList = GetWindowLongPtr (hList, GWLP_WNDPROC);
251    SetWindowLongPtr (hList, GWLP_WNDPROC, (LONG_PTR)Filesets_Create_SubclassListProc);
252
253    if (gr.viewAggCreate.lvsView == 0)  // never initialized this?
254       {
255       if (gr.viewAggMove.lvsView == 0)
256          memcpy (&gr.viewAggCreate, &gr.viewAgg, sizeof(VIEWINFO));
257       else
258          memcpy (&gr.viewAggCreate, &gr.viewAggMove, sizeof(VIEWINFO));
259       }
260    FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggCreate);
261
262    SetDlgItemText (hDlg, IDC_SET_NAME, pscp->szName);
263
264    CB_StartChange (GetDlgItem (hDlg, IDC_SET_QUOTA_UNITS), TRUE);
265    CB_AddItem (GetDlgItem (hDlg, IDC_SET_QUOTA_UNITS), IDS_QUOTAUNITS_KB, (LPARAM)cb1KB);
266    CB_AddItem (GetDlgItem (hDlg, IDC_SET_QUOTA_UNITS), IDS_QUOTAUNITS_MB, (LPARAM)cb1MB);
267    CB_EndChange (GetDlgItem (hDlg, IDC_SET_QUOTA_UNITS), (LPARAM)gr.cbQuotaUnits);
268
269    CheckDlgButton (hDlg, IDC_SET_CLONE, pscp->fCreateClone);
270
271    // Create a spinner, and give it an appropriate min/max range.  We'll
272    // have to *find* that range in a separate thread, 'cause it involves
273    // getting the status of an aggregate.
274    //
275    StartTask (taskAGG_FIND_QUOTA_LIMITS, hDlg, pscp->lpiParent);
276
277    // Fill in the Servers combobox, and select the default server
278    // (if one was specified).
279    //
280    LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
281    lpp->hCombo = GetDlgItem (hDlg, IDC_SET_SERVER);
282    lpp->lpiSelect = (pscp->lpiParent) ? pscp->lpiParent->GetServer() : NULL;
283    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);
284
285    EnableWindow (GetDlgItem (hDlg, IDC_SET_SERVER), FALSE);
286    EnableWindow (GetDlgItem (hDlg, IDC_AGG_LIST), FALSE);
287    EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
288 }
289
290
291 void Filesets_Create_OnSelectServer (HWND hDlg, LPIDENT *plpiTarget)
292 {
293    EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
294
295    Filesets_Create_StartDisplay_Aggregates (hDlg, plpiTarget);
296 }
297
298
299 void Filesets_Create_StartDisplay_Aggregates (HWND hDlg, LPIDENT *plpiTarget)
300 {
301    LPIDENT lpiServerNew = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SET_SERVER));
302
303    if (*plpiTarget && (*plpiTarget)->fIsServer())
304       *plpiTarget = NULL;
305    if (*plpiTarget && ((*plpiTarget)->GetServer() != lpiServerNew))
306       *plpiTarget = NULL;
307
308    SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)lpiServerNew);
309
310    LPAGG_ENUM_TO_LISTVIEW_PACKET lpp = New (AGG_ENUM_TO_LISTVIEW_PACKET);
311    lpp->lpiServer = lpiServerNew;
312    lpp->hList = GetDlgItem (hDlg, IDC_AGG_LIST);
313    lpp->lpiSelect = *plpiTarget;
314    lpp->lpvi = &gr.viewAggCreate;
315    StartTask (taskAGG_ENUM_TO_LISTVIEW, hDlg, lpp);
316 }
317
318
319 void Filesets_Create_OnEndTask_EnumAggregates (HWND hDlg)
320 {
321    EnableWindow (GetDlgItem (hDlg, IDC_AGG_LIST), TRUE);
322 }
323
324
325 void Filesets_Create_EnableOK (HWND hDlg, LPSET_CREATE_PARAMS pscp)
326 {
327    if (pscp->lpiParent && pscp->lpiParent->fIsAggregate() && pscp->szName[0])
328       EnableWindow (GetDlgItem (hDlg, IDOK), TRUE);
329    else
330       EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
331 }
332
333
334 void Filesets_Create_OnEndTask_FindQuotaLimits (HWND hDlg, LPTASKPACKET ptp, LPSET_CREATE_PARAMS pscp)
335 {
336    size_t cMin = TASKDATA(ptp)->ckMin;
337    size_t cNow = pscp->ckQuota;
338    size_t cMax = TASKDATA(ptp)->ckMax;
339
340    if (gr.cbQuotaUnits == cb1MB)
341       {
342       cMin /= ck1MB;
343       cNow /= ck1MB;
344       cMax /= ck1MB;
345       }
346
347    HWND hQuota = GetDlgItem (hDlg, IDC_SET_QUOTA);
348    if (!fHasSpinner (hQuota))
349       {
350       CreateSpinner (hQuota, 10, FALSE, (DWORD)cMin, (DWORD)cNow, (DWORD)cMax);
351       }
352    else
353       {
354       SP_SetRange (hQuota, cMin, cMax);
355       SP_SetPos (hQuota, cNow);
356       }
357 }
358