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