windows-64-bit-type-safety-20051105
[openafs.git] / src / WINNT / afssvrmgr / set_delete.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 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "svrmgr.h"
16 #include "set_delete.h"
17 #include "propcache.h"
18
19
20 /*
21  * PROTOTYPES _________________________________________________________________
22  *
23  */
24
25 BOOL CALLBACK Filesets_Delete_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
26 void Filesets_Delete_OnInitDialog (HWND hDlg, LPIDENT lpi);
27 void Filesets_Delete_OnCheckBoxes (HWND hDlg);
28 void Filesets_Delete_OnEndTask_FindGhost (HWND hDlg, LPTASKPACKET ptp, LPSET_DELETE_PARAMS psdp);
29 void Filesets_Delete_ShrinkWindow (HWND hDlg);
30
31
32 /*
33  * ROUTINES ___________________________________________________________________
34  *
35  */
36
37 void Filesets_Delete (LPIDENT lpiFileset)
38 {
39    HWND hCurrent;
40    if ((hCurrent = PropCache_Search (pcSET_DELETE, lpiFileset)) != NULL)
41       {
42       SetFocus (hCurrent);
43       }
44    else
45       {
46       LPSET_DELETE_PARAMS psdp = New (SET_DELETE_PARAMS);
47       memset (psdp, 0x00, sizeof(SET_DELETE_PARAMS));
48       psdp->lpiFileset = lpiFileset;
49       psdp->iddHelp = IDD_SET_DELETE;
50
51       ModelessDialogParam (IDD_SET_DELETE, NULL, (DLGPROC)Filesets_Delete_DlgProc, (LPARAM)psdp);
52       // NOTE: Don't show window!
53       }
54 }
55
56
57
58 BOOL CALLBACK Filesets_Delete_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
59 {
60    LPSET_DELETE_PARAMS psdp;
61    if (msg == WM_INITDIALOG)
62       SetWindowLongPtr (hDlg, DWLP_USER, lp);
63    if ((psdp = (LPSET_DELETE_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER)) != NULL)
64       {
65       if (AfsAppLib_HandleHelp (psdp->iddHelp, hDlg, msg, wp, lp))
66          return TRUE;
67
68       switch (msg)
69          {
70          case WM_INITDIALOG:
71             PropCache_Add (pcSET_DELETE, psdp->lpiFileset, hDlg);
72             Filesets_Delete_OnInitDialog (hDlg, psdp->lpiFileset);
73             StartTask (taskSET_FIND_GHOST, hDlg, psdp->lpiFileset);
74             break;
75
76          case WM_ENDTASK:
77             LPTASKPACKET ptp;
78             if ((ptp = (LPTASKPACKET)lp) != NULL)
79                {
80                if (ptp->idTask == taskSET_FIND_GHOST)
81                   Filesets_Delete_OnEndTask_FindGhost (hDlg, ptp, psdp);
82                FreeTaskPacket (ptp);
83                }
84             break;
85
86          case WM_COMMAND:
87             switch (LOWORD(wp))
88                {
89                case IDOK:
90                   psdp->fVLDB   = IsDlgButtonChecked (hDlg, IDC_DELSET_VLDB);
91                   psdp->fServer = IsDlgButtonChecked (hDlg, IDC_DELSET_SERVER);
92
93                   if (psdp->fVLDB || psdp->fServer)
94                      StartTask (taskSET_DELETE, NULL, psdp);
95                   else
96                      Delete (psdp);
97                   DestroyWindow (hDlg);
98                   break;
99
100                case IDCANCEL:
101                   Delete (psdp);
102                   DestroyWindow (hDlg);
103                   break;
104
105                case IDC_DELSET_VLDB:
106                case IDC_DELSET_SERVER:
107                   Filesets_Delete_OnCheckBoxes (hDlg);
108                   break;
109                }
110             break;
111
112          case WM_DESTROY:
113             PropCache_Delete (hDlg);
114             SetWindowLongPtr (hDlg, DWLP_USER, 0);
115             psdp = NULL;
116             break;
117          }
118       }
119
120    return FALSE;
121 }
122
123
124 void Filesets_Delete_OnInitDialog (HWND hDlg, LPIDENT lpi)
125 {
126    TCHAR szServer[ cchNAME ];
127    TCHAR szAggregate[ cchNAME ];
128    TCHAR szFileset[ cchNAME ];
129
130    lpi->GetServerName (szServer);
131    lpi->GetAggregateName (szAggregate);
132    lpi->GetFilesetName (szFileset);
133
134    TCHAR szOld[ cchRESOURCE ];
135
136    GetDlgItemText (hDlg, IDC_DELSET_DESC, szOld, cchRESOURCE);
137    LPTSTR pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
138    SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
139    FreeString (pszNew);
140
141    GetDlgItemText (hDlg, IDC_DELSET_SERVER, szOld, cchRESOURCE);
142    pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
143    SetDlgItemText (hDlg, IDC_DELSET_SERVER, pszNew);
144    FreeString (pszNew);
145
146    GetDlgItemText (hDlg, IDC_DELSET_VLDB, szOld, cchRESOURCE);
147    pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
148    SetDlgItemText (hDlg, IDC_DELSET_VLDB, pszNew);
149    FreeString (pszNew);
150
151    EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
152 }
153
154
155 void Filesets_Delete_OnEndTask_FindGhost (HWND hDlg, LPTASKPACKET ptp, LPSET_DELETE_PARAMS psdp)
156 {
157    TCHAR szServer[ cchNAME ];
158    TCHAR szAggregate[ cchNAME ];
159    TCHAR szFileset[ cchNAME ];
160    psdp->lpiFileset->GetServerName (szServer);
161    psdp->lpiFileset->GetAggregateName (szAggregate);
162    psdp->lpiFileset->GetFilesetName (szFileset);
163
164    if (!ptp->rc)
165       {
166       ErrorDialog (ptp->status, IDS_ERROR_REFRESH_FILESET_STATUS, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
167       DestroyWindow (hDlg);
168       }
169    else if ( (TASKDATA(ptp)->fs.Type == ftREADWRITE) && (TASKDATA(ptp)->fHasReplicas) )
170       {
171       ErrorDialog (ptp->status, IDS_ERROR_CANT_DELETE_REPLICATED_FILESET, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
172       DestroyWindow (hDlg);
173       }
174    else
175       {
176       if (TASKDATA(ptp)->fs.Type == ftREPLICA)
177          psdp->wGhost  = GHOST_HAS_SERVER_ENTRY;
178       else if (TASKDATA(ptp)->fs.Type == ftCLONE)
179          psdp->wGhost  = GHOST_HAS_SERVER_ENTRY;
180       else
181          psdp->wGhost  = TASKDATA(ptp)->wGhost;
182
183       psdp->fVLDB   = (psdp->wGhost & GHOST_HAS_VLDB_ENTRY)   ? TRUE : FALSE;
184       psdp->fServer = (psdp->wGhost & GHOST_HAS_SERVER_ENTRY) ? TRUE : FALSE;
185
186       CheckDlgButton (hDlg, IDC_DELSET_VLDB,   psdp->fVLDB);
187       CheckDlgButton (hDlg, IDC_DELSET_SERVER, psdp->fServer);
188
189       if (TASKDATA(ptp)->fs.Type == ftREPLICA)
190          {
191          psdp->iddHelp = IDD_SET_DELREP;
192
193          LPTSTR pszNew = FormatString (IDS_DELSET_REPLICA_DESC, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
194          SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
195          FreeString (pszNew);
196
197          Filesets_Delete_ShrinkWindow (hDlg);
198          }
199       else if (TASKDATA(ptp)->fs.Type == ftCLONE)
200          {
201          psdp->iddHelp = IDD_SET_DELCLONE;
202
203          LPTSTR pszNew = FormatString (IDS_DELSET_CLONE_DESC, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
204          SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
205          FreeString (pszNew);
206
207          Filesets_Delete_ShrinkWindow (hDlg);
208          }
209
210       if (!(psdp->wGhost & GHOST_HAS_SERVER_ENTRY))
211          EnableWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), FALSE);
212
213       if (!(psdp->wGhost & GHOST_HAS_VLDB_ENTRY))
214          EnableWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), FALSE);
215
216       Filesets_Delete_OnCheckBoxes (hDlg);
217
218       ShowWindow (hDlg, SW_SHOW);
219       }
220 }
221
222
223 void Filesets_Delete_OnCheckBoxes (HWND hDlg)
224 {
225    BOOL fEnableOK = TRUE;
226    if ( !IsDlgButtonChecked (hDlg, IDC_DELSET_VLDB) &&
227         !IsDlgButtonChecked (hDlg, IDC_DELSET_SERVER) )
228       fEnableOK = FALSE;
229
230    EnableWindow (GetDlgItem (hDlg, IDOK), fEnableOK);
231 }
232
233
234 void Filesets_Delete_ShrinkWindow (HWND hDlg)
235 {
236    RECT rDialog;
237    GetWindowRect (hDlg, &rDialog);
238
239    RECT rCheckbox;
240    GetRectInParent (GetDlgItem (hDlg, IDC_DELSET_VLDB), &rCheckbox);
241
242    RECT rButton;
243    GetRectInParent (GetDlgItem (hDlg, IDOK), &rButton);
244
245    LONG cy = rButton.top -rCheckbox.top; // shrink window by this much
246
247    EnableWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), FALSE);
248    ShowWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), SW_HIDE);
249
250    EnableWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), FALSE);
251    ShowWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), SW_HIDE);
252
253    GetRectInParent (GetDlgItem (hDlg, IDOK), &rButton);
254    SetWindowPos (GetDlgItem (hDlg, IDOK), NULL,
255                  rButton.left, rButton.top -cy, 0, 0,
256                  SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
257
258    GetRectInParent (GetDlgItem (hDlg, IDCANCEL), &rButton);
259    SetWindowPos (GetDlgItem (hDlg, IDCANCEL), NULL,
260                  rButton.left, rButton.top -cy, 0, 0,
261                  SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
262
263    GetRectInParent (GetDlgItem (hDlg, IDHELP), &rButton);
264    SetWindowPos (GetDlgItem (hDlg, IDHELP), NULL,
265                  rButton.left, rButton.top -cy, 0, 0,
266                  SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
267
268    SetWindowPos (hDlg, NULL,
269                  0, 0, cxRECT(rDialog), cyRECT(rDialog) -cy,
270                  SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
271 }
272