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