Windows: AFSTearDownExtents may experience active extents
[openafs.git] / src / WINNT / afssvrcfg / admin_info_dlg.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 <afsconfig.h>
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 #include <roken.h>
18 }
19
20
21 /*
22  * INCLUDES ___________________________________________________________________
23  *
24  */
25 #include "afscfg.h"             // Main header for this application
26 #include "resource.h"
27 #include "admin_info_dlg.h"
28
29
30 /*
31  * DEFINITIONS _________________________________________________________________
32  *
33  */
34 static HWND hDlg = 0;                                           // HWND for this page's dialog
35 static GET_ADMIN_INFO_OPTIONS eOptions;         // Are we asking user for another server?
36
37
38 /*
39  * PROTOTYPES _________________________________________________________________
40  *
41  */
42 static void OnInitDialog(HWND hwndDlg);
43 static void CheckEnableButtons();
44 static void SaveDlgInfo();
45 static void ShowPageInfo();
46
47 BOOL CALLBACK AdminInfoDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
48
49
50 /*
51  * EXPORTED FUNCTIONS _________________________________________________________
52  *
53  */
54 BOOL GetAdminInfo(HWND hParent, GET_ADMIN_INFO_OPTIONS options)
55 {
56     eOptions = options;
57
58     int nResult = ModalDialog(IDD_ADMIN_INFO, hParent, (DLGPROC)AdminInfoDlgProc);
59
60     return (nResult == IDOK);
61 }
62
63
64 /*
65  * Dialog Proc _________________________________________________________________
66  *
67  */
68 BOOL CALLBACK AdminInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
69 {
70     if (AfsAppLib_HandleHelp(IDD_ADMIN_INFO, hwndDlg, msg, wp, lp))
71         return TRUE;
72
73     switch (msg) {
74     case WM_INITDIALOG:
75         OnInitDialog(hwndDlg);
76         break;
77
78     case WM_COMMAND:
79         switch (LOWORD(wp)) {
80         case IDC_ADMIN_NAME:
81         case IDC_ADMIN_PW:
82         case IDC_HOSTNAME:
83         case IDC_SCS:
84             if (HIWORD(wp) == EN_CHANGE)
85                 CheckEnableButtons();
86             break;
87
88         case IDCANCEL:
89             EndDialog(hDlg, IDCANCEL);
90             break;
91
92         case IDOK:
93             SaveDlgInfo();
94             EndDialog(hDlg, IDOK);
95             break;
96         }
97         break;
98     }
99
100     return FALSE;
101 }
102
103
104 /*
105  * STATIC FUNCTIONS _________________________________________________________________
106  *
107  */
108
109 /*
110  * Event Handler Functions _________________________________________________________________
111  *
112  */
113 static void OnInitDialog(HWND hwndDlg)
114 {
115     static int nOffset = 0;
116
117     hDlg = hwndDlg;
118
119     // Hide the additional server stuff if we don't need it
120     if (eOptions == GAIO_LOGIN_ONLY) {
121         HideAndDisable(hDlg, IDC_HOSTNAME_FRAME);
122         HideAndDisable(hDlg, IDC_HOSTNAME_PROMPT);
123         HideAndDisable(hDlg, IDC_HOSTNAME_LABEL);
124         HideAndDisable(hDlg, IDC_HOSTNAME);
125
126         if (nOffset == 0) {
127             // Get dimensions of the frame containing the things we will hide or show
128             RECT rectFrame;
129             GetWindowRect(GetDlgItem(hDlg, IDC_HOSTNAME_FRAME), &rectFrame);
130
131             // Get original position of the buttons
132             RECT rectButton;
133             GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &rectButton);
134
135             // Figure out how far the buttons will have to move to be at the top
136             // of the frame.
137             nOffset = rectButton.top - rectFrame.top;
138         }
139
140         // Move the buttons
141         MoveWnd(hDlg, IDOK, 0, -nOffset);
142         MoveWnd(hDlg, IDCANCEL, 0, -nOffset);
143         MoveWnd(hDlg, IDHELP, 0, -nOffset);
144
145         // Resize the dialog
146         RECT rectDlg;
147         GetWindowRect(hDlg, &rectDlg);
148         MoveWindow(hDlg, rectDlg.left, rectDlg.top, rectDlg.right - rectDlg.left + 1, rectDlg.bottom - rectDlg.top - nOffset, TRUE);
149     }
150
151     ShowPageInfo();
152 }
153
154 /*
155  * Utility Functions _________________________________________________________________
156  *
157  */
158 static void CheckEnableButtons()
159 {
160     BOOL bDisable = FALSE;
161
162     TCHAR szDummy[cchRESOURCE];
163
164     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_NAME, szDummy)) == 0;
165     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_PW, szDummy)) == 0;
166
167     SetEnable(hDlg, IDOK, (ENABLE_STATE)!bDisable);
168 }
169
170 static void SaveDlgInfo()
171 {
172     TCHAR szText[cchRESOURCE];
173
174     lstrncpy(g_CfgData.szAdminName, GetWndText(hDlg, IDC_ADMIN_NAME, szText), MAX_ADMIN_NAME_LEN);
175     lstrncpy(g_CfgData.szAdminPW, GetWndText(hDlg, IDC_ADMIN_PW, szText), MAX_ADMIN_PW_LEN);
176
177     if (eOptions == GAIO_GET_SCS)
178         lstrncpy(g_CfgData.szSysControlMachine, GetWndText(hDlg, IDC_HOSTNAME, szText), MAX_MACHINE_NAME_LEN);
179 }
180
181 static void ShowPageInfo()
182 {
183     SetWndText(hDlg, IDC_ADMIN_NAME, g_CfgData.szAdminName);
184     SetWndText(hDlg, IDC_ADMIN_PW, g_CfgData.szAdminPW);
185
186     if (eOptions == GAIO_GET_SCS)
187         SetWndText(hDlg, IDC_HOSTNAME, g_CfgData.szSysControlMachine);
188 }
189