ticket-2618-patches-20031207
[openafs.git] / src / WINNT / afssvrcfg / get_pw_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 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afscfg.h"             // Main header for this application
20 #include "resource.h"
21 #include "get_pw_dlg.h"
22
23
24 /*
25  * DEFINITIONS _________________________________________________________________
26  *
27  */
28 static HWND hDlg = 0;                                           // HWND for this page's dialog
29
30
31 /*
32  * PROTOTYPES _________________________________________________________________
33  *
34  */
35 static void OnInitDialog(HWND hwndDlg);
36 static void CheckEnableButtons();
37 static void SaveDlgInfo();
38 static void ShowPageInfo();
39
40 BOOL CALLBACK GetPwDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
41
42
43 /*
44  * EXPORTED FUNCTIONS _________________________________________________________
45  *
46  */
47 BOOL GetAfsPrincipalPassword(HWND hParent, TCHAR *&pszServerPW)
48 {       
49         int nResult = ModalDialog(IDD_GET_PW, hParent, (DLGPROC)GetPwDlgProc);
50     if (nResult == IDOK) {
51         pszServerPW = g_CfgData.szServerPW;
52         return TRUE;
53     }
54
55     pszServerPW = 0;
56
57         return FALSE;
58 }
59
60
61 /*
62  * Dialog Proc _________________________________________________________________
63  *
64  */
65 BOOL CALLBACK GetPwDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
66 {
67         if (AfsAppLib_HandleHelp(IDD_GET_PW, hwndDlg, msg, wp, lp))
68                 return TRUE;
69
70         switch (msg) {
71                 case WM_INITDIALOG:
72                         OnInitDialog(hwndDlg);
73                         break;
74
75                 case WM_COMMAND:
76                         switch (LOWORD(wp)) {
77                                 case IDC_PW:
78                                         if (HIWORD(wp) == EN_CHANGE)
79                                                 CheckEnableButtons();
80                                         break;
81
82                                 case IDCANCEL:
83                                         EndDialog(hDlg, IDCANCEL);
84                                         break;
85                                         
86
87                                 case IDOK:
88                                         SaveDlgInfo();
89                                         EndDialog(hDlg, IDOK);
90                                         break;
91                         }
92                 break;
93     }
94
95     return FALSE;
96 }
97
98
99 /*
100  * STATIC FUNCTIONS _________________________________________________________________
101  *
102  */
103
104 /*
105  * Event Handler Functions _________________________________________________________________
106  *
107  */
108 static void OnInitDialog(HWND hwndDlg)
109 {
110         hDlg = hwndDlg;
111 }
112
113
114 /*
115  * Utility Functions _________________________________________________________________
116  *
117  */
118 static void CheckEnableButtons()
119 {
120         BOOL bDisable = FALSE;
121
122         TCHAR szDummy[cchRESOURCE];
123
124         bDisable |= lstrlen(GetWndText(hDlg, IDC_PW, szDummy)) == 0;
125
126         SetEnable(hDlg, IDOK, (ENABLE_STATE)!bDisable);
127 }
128
129 static void SaveDlgInfo()
130 {
131         TCHAR szText[cchRESOURCE];
132         
133         lstrncpy(g_CfgData.szServerPW, GetWndText(hDlg, IDC_PW, szText), MAX_SERVER_PW_LEN);
134 }
135
136 static void ShowPageInfo()
137 {
138         SetWndText(hDlg, IDC_PW, g_CfgData.szServerPW);
139 }
140