Windows: AFSTearDownExtents may experience active extents
[openafs.git] / src / WINNT / afssvrcfg / sys_control_page.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 /*
11  * INCLUDES _________________________________________________________________
12  *
13  */
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
16
17 extern "C" {
18 #include <afsconfig.h>
19 #include <afs/param.h>
20 #include <afs/stds.h>
21 #include <roken.h>
22 }
23
24 #include "afscfg.h"
25 #include "resource.h"
26
27
28 /*
29  * DEFINITIONS _________________________________________________________________
30  *
31  */
32 static HWND hDlg = 0;
33 extern int nOptionButtonSeparationHeight;   // Comes from backup_server_page.cpp
34
35
36 /*
37  * PROTOTYPES _________________________________________________________________
38  *
39  */
40 static void OnInitDialog(HWND hwndDlg);
41 static void CantConfig(UINT nMsgID);
42 static void EnableSysControlMachine(BOOL bEnable);
43 static void ShowSysControlMachine(TCHAR *pszSysControlMachine);
44 static void CheckEnableNextButton();
45
46
47 /*
48  * EXPORTED FUNCTIONS _________________________________________________________________
49  *
50  */
51
52 /*
53  * Dialog Proc _________________________________________________________________
54  *
55  */
56 BOOL CALLBACK SysControlPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
57 {
58     if (WizStep_Common_DlgProc (hwndDlg, msg, wp, lp))
59         return FALSE;
60
61     switch (msg) {
62     case WM_INITDIALOG:
63         OnInitDialog(hwndDlg);
64         break;
65
66     case WM_COMMAND:
67         switch (LOWORD(wp)) {
68         case IDNEXT:
69             g_pWiz->SetState(sidSTEP_TWELVE);
70             break;
71
72         case IDBACK:
73             g_pWiz->SetState(sidSTEP_TEN);
74             break;
75
76         case IDC_SYS_CONTROL_SERVER:
77             g_CfgData.configSCS = CS_CONFIGURE;
78             g_CfgData.configSCC = CS_DONT_CONFIGURE;
79             EnableSysControlMachine(FALSE);
80             break;
81
82         case IDC_SYS_CONTROL_CLIENT:
83             g_CfgData.configSCS = CS_DONT_CONFIGURE;
84             g_CfgData.configSCC = CS_CONFIGURE;
85             EnableSysControlMachine(TRUE);
86             SetFocus(GetDlgItem(hDlg, IDC_SYS_CONTROL_MACHINE));
87             break;
88
89         case IDC_DONT_CONFIGURE:
90             g_CfgData.configSCS = CS_DONT_CONFIGURE;
91             g_CfgData.configSCC = CS_DONT_CONFIGURE;
92             EnableSysControlMachine(FALSE);
93             break;
94
95         case IDC_SYS_CONTROL_MACHINE:
96             if (HIWORD(wp) == EN_CHANGE)
97                 CheckEnableNextButton();
98             break;
99         }
100         break;
101     }
102
103     return FALSE;
104 }
105
106 /*
107  * STATIC FUNCTIONS _________________________________________________________________
108  *
109  */
110
111 /*
112  * Event Handler Functions _________________________________________________________________
113  *
114  */
115 static void OnInitDialog(HWND hwndDlg)
116 {
117     hDlg = hwndDlg;
118
119     g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
120     g_pWiz->SetButtonText(IDNEXT, IDS_NEXT);
121     g_pWiz->SetDefaultControl(IDNEXT);
122
123     if (g_CfgData.configSCS == CS_ALREADY_CONFIGURED) {
124         CantConfig(IDS_ALREADY_A_SYS_CONTROL_SERVER);
125         return;
126     } else if (g_CfgData.configSCC == CS_ALREADY_CONFIGURED) {
127         CantConfig(IDS_ALREADY_A_SYS_CONTROL_CLIENT);
128         return;
129     }
130
131     // Should this step be disabled?  Yes, if this machine
132     // is not configured as a database or file server.
133     if (!ConfiguredOrConfiguring(g_CfgData.configFS) && !ConfiguredOrConfiguring(g_CfgData.configDB)) {
134         CantConfig(IDS_SC_NOT_A_DB_OR_FS_SERVER);
135         EnableStep(g_CfgData.configSCS, FALSE);
136         EnableStep(g_CfgData.configSCC, FALSE);
137         return;
138     }
139
140     // Do this in case they were disabled on the last run through
141     EnableStep(g_CfgData.configSCS);
142     EnableStep(g_CfgData.configSCC);
143
144     // If this is the first server, then it can't be a SCC
145     if (g_CfgData.bFirstServer) {
146         // Disable the SCC step
147         EnableStep(g_CfgData.configSCC, FALSE);
148
149         // Hide the SCC controls
150         ShowWnd(hDlg, IDC_SYS_CONTROL_CLIENT_DESC, FALSE);
151         ShowWnd(hDlg, IDC_SYS_CONTROL_CLIENT, FALSE);
152         ShowWnd(hDlg, IDC_SYS_CONTROL_MACHINE_LABEL, FALSE);
153         ShowWnd(hDlg, IDC_SYS_CONTROL_MACHINE, FALSE);
154
155         // Move remaining controls to fill the holes left from
156         // hiding the SCC controls
157
158         // Get position of the "Do not configure" option button; we will position
159         // the other controls relative to this one
160         RECT rectDNC;
161         GetWindowRect(GetDlgItem(hDlg, IDC_DONT_CONFIGURE), &rectDNC);
162
163         // Get position of the SCS option button
164         RECT rectSCS;
165         GetWindowRect(GetDlgItem(hDlg, IDC_SYS_CONTROL_SERVER), &rectSCS);
166
167         // Calc offset between the two
168         int nOffset = rectDNC.top - rectSCS.top;
169
170         // Separate the two option controls
171         nOffset -= nOptionButtonSeparationHeight;
172
173         // Move the controls
174         MoveWnd(hDlg, IDC_SYS_CONTROL_MACHINE_QUESTION, 0, nOffset);
175         MoveWnd(hDlg, IDC_SYS_CONTROL_SERVER, 0, nOffset);
176
177         SetWndText(hDlg, IDC_TITLE, IDS_CONFIG_SCS);
178         SetWndText(hDlg, IDC_SYS_CONTROL_MACHINE_QUESTION, IDS_SYS_CONTROL_SERVER_ONLY_MSG);
179         SetWndText(hDlg, IDC_DONT_CONFIGURE, IDS_DONT_CONFIG_SYS_CONTROL_SERVER_MSG);
180     }
181
182     if (g_CfgData.configSCS == CS_CONFIGURE)
183         SetCheck(hDlg, IDC_SYS_CONTROL_SERVER);
184     else if (g_CfgData.configSCC == CS_CONFIGURE) {
185         SetCheck(hDlg, IDC_SYS_CONTROL_CLIENT);
186         EnableSysControlMachine(TRUE);
187     } else
188         SetCheck(hDlg, IDC_DONT_CONFIGURE);
189 }
190
191 /*
192  * Utility Functions _________________________________________________________________
193  *
194  */
195 static void CantConfig(UINT nMsgID)
196 {
197     TCHAR szMsg[cchRESOURCE];
198
199     GetString(szMsg, nMsgID);
200
201     ShowWnd(hDlg, IDC_SYS_CONTROL_MACHINE_QUESTION, FALSE);
202     ShowWnd(hDlg, IDC_SYS_CONTROL_SERVER, FALSE);
203     ShowWnd(hDlg, IDC_SYS_CONTROL_CLIENT, FALSE);
204     ShowWnd(hDlg, IDC_SYS_CONTROL_MACHINE_LABEL, FALSE);
205     ShowWnd(hDlg, IDC_SYS_CONTROL_MACHINE, FALSE);
206     ShowWnd(hDlg, IDC_DONT_CONFIGURE, FALSE);
207
208     ShowWnd(hDlg, IDC_CANT_CONFIG_MSG);
209     SetWndText(hDlg, IDC_CANT_CONFIG_MSG, szMsg);
210 }
211
212 static void EnableSysControlMachine(BOOL bEnable)
213 {
214     EnableWnd(hDlg, IDC_SYS_CONTROL_MACHINE_LABEL, bEnable);
215     EnableWnd(hDlg, IDC_SYS_CONTROL_MACHINE, bEnable);
216
217     if (bEnable)
218         ShowSysControlMachine(g_CfgData.szSysControlMachine);
219     else
220         ShowSysControlMachine(TEXT(""));
221
222     CheckEnableNextButton();
223 }
224
225 static void ShowSysControlMachine(TCHAR *pszSysControlMachine)
226 {
227     SetWndText(hDlg, IDC_SYS_CONTROL_MACHINE, pszSysControlMachine);
228 }
229
230 static void CheckEnableNextButton()
231 {
232     BOOL bEnable = TRUE;
233
234     if (IsButtonChecked(hDlg, IDC_SYS_CONTROL_CLIENT)) {
235         GetWndText(hDlg, IDC_SYS_CONTROL_MACHINE, g_CfgData.szSysControlMachine, MAX_MACHINE_NAME_LEN);
236
237         if (lstrlen(g_CfgData.szSysControlMachine) == 0)
238             bEnable = FALSE;
239     }
240
241     if (bEnable)
242         g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
243     else
244         g_pWiz->EnableButtons(BACK_BUTTON);
245 }
246