afssvrcfg-updates-20031206
[openafs.git] / src / WINNT / afssvrcfg / info_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;                           // HWND for this page's dialog
28
29
30 /*
31  * PROTOTYPES _________________________________________________________________
32  *
33  */
34 static void OnInitDialog(HWND hwndDlg);
35 static void CheckEnableButtons();
36 static BOOL SavePageInfo();
37 static void ShowPageInfo();
38 static void IsFirstServer(BOOL bIs = TRUE);
39
40
41 /*
42  * EXPORTED FUNCTIONS _________________________________________________________________
43  *
44  */
45
46 /*
47  * Dialog Procs _________________________________________________________________
48  *
49  */
50 BOOL CALLBACK InfoPageDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp)
51 {
52     if (WizStep_Common_DlgProc (hRHS, msg, wp, lp))
53         return FALSE;
54
55         switch (msg) {
56                 case WM_INITDIALOG:
57                         OnInitDialog(hRHS);
58                         break;
59
60                 case WM_COMMAND:
61                         switch (LOWORD(wp)) {
62                         case IDNEXT:
63                                 if (SavePageInfo())
64                                         g_pWiz->SetState (sidSTEP_THREE);
65                                 break;
66
67                         case IDBACK:
68                                 if (SavePageInfo())
69                                         g_pWiz->SetState (sidSTEP_ONE);
70                                 break;
71
72                         case IDC_FIRST_SERVER:
73                                 IsFirstServer();
74                                 break;
75
76                         case IDC_JOIN_EXISTING_CELL:
77                                 IsFirstServer(FALSE);
78                                 break;
79
80                         case IDC_CELL_NAME:
81                         case IDC_SERVER_PW:
82                         case IDC_VERIFY_PW:
83                                 if (HIWORD(wp) == EN_CHANGE)
84                                         CheckEnableButtons();
85                                 break;
86
87                         }
88                 break;
89     }
90
91     return FALSE;
92 }
93
94 /*
95  * STATIC FUNCTIONS ________________________________________________________________________
96  *
97  */
98
99 /*
100  * Event Handler Functions _________________________________________________________________
101  *
102  */
103 static void OnInitDialog(HWND hwndDlg)
104 {
105         hDlg = hwndDlg;
106
107         g_pWiz->EnableButtons(BACK_BUTTON);
108
109         ShowPageInfo();
110
111         if (g_CfgData.bFirstServer)
112                 IsFirstServer();
113
114         g_pWiz->SetDefaultControl(IDC_CELL_NAME);
115 }
116
117
118 /*
119  * Utility Functions _________________________________________________________________
120  *
121  */
122 static void CheckEnableButtons()
123 {
124         BOOL bDisable = FALSE;
125
126         TCHAR szCellName[cchRESOURCE];
127         TCHAR szPW[cchRESOURCE];
128         TCHAR szVerifyPW[cchRESOURCE];
129
130         bDisable = lstrlen(GetWndText(hDlg, IDC_CELL_NAME, szCellName)) == 0;
131
132         GetWndText(hDlg, IDC_SERVER_PW, szPW);
133         GetWndText(hDlg, IDC_VERIFY_PW, szVerifyPW);
134
135         if (IsButtonChecked(hDlg, IDC_FIRST_SERVER))
136                 bDisable |= !lstrlen(szPW) || !lstrlen(szVerifyPW) || lstrcmp(szPW, szVerifyPW);
137
138         if (bDisable)
139                 g_pWiz->EnableButtons(BACK_BUTTON);
140         else
141                 g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
142 }
143
144 static BOOL SavePageInfo()
145 {
146         TCHAR szText[cchRESOURCE];
147         
148         GetWndText(hDlg, IDC_CELL_NAME, szText);
149         if (lstrlen(szText) > MAX_CELL_NAME_LEN) {
150                 MsgBox(hDlg, IDS_CELL_NAME_LEN_ERROR, GetAppTitleID(), MB_ICONSTOP | MB_OK);
151                 return FALSE;
152         }
153
154         lstrcpy(g_CfgData.szCellName, szText);
155         lstrncpy(g_CfgData.szServerPW, GetWndText(hDlg, IDC_SERVER_PW, szText), MAX_SERVER_PW_LEN);
156         g_CfgData.bFirstServer = IsButtonChecked(hDlg, IDC_FIRST_SERVER);
157
158         return TRUE;
159 }
160
161 static void ShowPageInfo()
162 {
163         SetWndText(hDlg, IDC_CELL_NAME, g_CfgData.szCellName);
164         SetWndText(hDlg, IDC_SERVER_PW, g_CfgData.szServerPW);
165         SetWndText(hDlg, IDC_VERIFY_PW, g_CfgData.szServerPW);
166
167         if (g_CfgData.bFirstServer)
168                 SetCheck(hDlg, IDC_FIRST_SERVER);
169         else
170                 SetCheck(hDlg, IDC_JOIN_EXISTING_CELL);
171 }
172
173 static void IsFirstServer(BOOL bIs)
174 {
175         ENABLE_STATE es;
176
177         if (bIs)
178                 es = ES_ENABLE;
179         else
180                 es = ES_DISABLE;
181
182         SetEnable(hDlg, IDC_PRINCIPAL_LABEL, es);
183         SetEnable(hDlg, IDC_PRINCIPAL, es);
184         
185         SetEnable(hDlg, IDC_SERVER_PW_FRAME, es);
186         SetEnable(hDlg, IDC_SERVER_PW_LABEL, es);
187         SetEnable(hDlg, IDC_SERVER_PW_PROMPT, es);
188         SetEnable(hDlg, IDC_SERVER_PW, es);
189         SetEnable(hDlg, IDC_VERIFY_PW_LABEL, es);
190         SetEnable(hDlg, IDC_VERIFY_PW, es);
191         
192         CheckEnableButtons();
193 }
194