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