Windows: fix checked UNICODE build of talocale
[openafs.git] / src / WINNT / afssvrmgr / svr_prune.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 "svr_prune.h"
20 #include "propcache.h"
21
22 /*
23  * PROTOTYPES _________________________________________________________________
24  *
25  */
26
27 BOOL WINAPI Server_Prune_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
28
29 void Server_Prune_OnInitDialog (HWND hDlg, LPSVR_PRUNE_PARAMS lpp);
30 void Server_Prune_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_PRUNE_PARAMS lpp);
31 void Server_Prune_EnableOK (HWND hDlg);
32 void Server_Prune_OnOK (HWND hDlg);
33
34
35 /*
36  * ROUTINES ___________________________________________________________________
37  *
38  */
39
40 void Server_Prune (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore)
41 {
42    HWND hCurrent;
43
44    if ((hCurrent = PropCache_Search (pcSVR_PRUNE, NULL)) != NULL)
45       {
46       SetFocus (hCurrent);
47       }
48    else
49       {
50       LPSVR_PRUNE_PARAMS lpp = New (SVR_PRUNE_PARAMS);
51       lpp->lpiServer = lpiServer;
52       lpp->fBAK = fBAK;
53       lpp->fOLD = fOLD;
54       lpp->fCore = fCore;
55
56       HWND hDlg = ModelessDialogParam (IDD_SVR_PRUNE, NULL, (DLGPROC)Server_Prune_DlgProc, (LPARAM)lpp);
57       ShowWindow (hDlg, SW_SHOW);
58       }
59 }
60
61
62 BOOL WINAPI Server_Prune_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
63 {
64    if (AfsAppLib_HandleHelp (IDD_SVR_PRUNE, hDlg, msg, wp, lp))
65       return TRUE;
66
67    LPSVR_PRUNE_PARAMS lpp;
68
69    if (msg == WM_INITDIALOG)
70       SetWindowLongPtr (hDlg, DWLP_USER, lp);
71
72    if ((lpp = (LPSVR_PRUNE_PARAMS)GetWindowLongPtr(hDlg,DWLP_USER)) != NULL)
73       {
74       switch (msg)
75          {
76          case WM_INITDIALOG:
77             PropCache_Add (pcSVR_PRUNE, NULL, hDlg);
78             Server_Prune_OnInitDialog (hDlg, lpp);
79             break;
80
81          case WM_ENDTASK:
82             LPTASKPACKET ptp;
83             if ((ptp = (LPTASKPACKET)lp) != NULL)
84                {
85                if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
86                   Server_Prune_OnEndTask_InitDialog (hDlg, ptp, lpp);
87                FreeTaskPacket (ptp);
88                }
89             break;
90
91          case WM_COMMAND:
92             switch (LOWORD(wp))
93                {
94                case IDOK:
95                   Server_Prune_OnOK (hDlg);
96                   // fall through
97
98                case IDCANCEL:
99                   DestroyWindow (hDlg);
100                   break;
101
102                case IDC_OP_DELETE_BAK:
103                case IDC_OP_DELETE_OLD:
104                case IDC_OP_DELETE_CORE:
105                   Server_Prune_EnableOK (hDlg);
106                   break;
107                }
108             break;
109
110          case WM_DESTROY:
111             SetWindowLongPtr (hDlg, DWLP_USER, 0);
112             PropCache_Delete (pcSVR_PRUNE, NULL);
113             Delete (lpp);
114             break;
115          }
116       }
117
118    return FALSE;
119 }
120
121
122 void Server_Prune_OnInitDialog (HWND hDlg, LPSVR_PRUNE_PARAMS lpp)
123 {
124    CheckDlgButton (hDlg, IDC_OP_DELETE_BAK,  lpp->fBAK);
125    CheckDlgButton (hDlg, IDC_OP_DELETE_OLD,  lpp->fOLD);
126    CheckDlgButton (hDlg, IDC_OP_DELETE_CORE, lpp->fCore);
127
128    LPSVR_ENUM_TO_COMBOBOX_PACKET lppEnum = New (SVR_ENUM_TO_COMBOBOX_PACKET);
129    lppEnum->hCombo = GetDlgItem (hDlg, IDC_SERVER);
130    lppEnum->lpiSelect = lpp->lpiServer;
131    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lppEnum);
132
133    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
134    EnableWindow (GetDlgItem (hDlg, IDOK),       FALSE);
135 }
136
137
138 void Server_Prune_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_PRUNE_PARAMS lpp)
139 {
140    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), TRUE);
141
142    Server_Prune_EnableOK (hDlg);
143 }
144
145
146 void Server_Prune_EnableOK (HWND hDlg)
147 {
148    LPIDENT lpiServer = NULL;
149
150    if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SERVER)))
151       {
152       lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
153       }
154
155    BOOL fEnable = (lpiServer != NULL) ? TRUE : FALSE;
156
157    if ( !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_BAK) && 
158         !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_OLD) && 
159         !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_CORE) )
160       {
161       fEnable = FALSE;
162       }
163
164    EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
165 }
166
167
168 void Server_Prune_OnOK (HWND hDlg)
169 {
170    LPSVR_PRUNE_PARAMS lpp = New (SVR_PRUNE_PARAMS);
171    lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
172    lpp->fBAK = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_BAK);
173    lpp->fOLD = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_OLD);
174    lpp->fCore = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_CORE);
175
176    StartTask (taskSVR_PRUNE, NULL, lpp);
177 }
178