per-user-registry-20040320
[openafs.git] / src / WINNT / client_config / dlg_logon.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 #include "afs_config.h"
16
17
18 /*
19  * DEFINITIONS ________________________________________________________________
20  *
21  */
22
23 #define nRETRY_MIN            5
24 #define nRETRY_MAX            180
25
26 static TCHAR szYes[10] = TEXT("Yes");
27 static TCHAR szNo[10] = TEXT("No");
28
29 // Our dialog data
30 static BOOL fFirstTime = TRUE;
31 static DWORD nLoginRetryInterval;
32 static BOOL fFailLoginsSilently;
33
34
35 /*
36  * PROTOTYPES _________________________________________________________________
37  *
38  */
39
40 void Logon_OnInitDialog (HWND hDlg);
41 void Logon_OnOK (HWND hDlg);
42 void Logon_OnCancel(HWND hDlg);
43 BOOL Logon_OnApply();
44
45
46 /*
47  * ROUTINES ___________________________________________________________________
48  *
49  */
50
51 BOOL CALLBACK Logon_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
52 {
53    switch (msg)
54       {
55       case WM_INITDIALOG:
56          Logon_OnInitDialog (hDlg);
57          break;
58
59       case WM_CTLCOLORSTATIC:
60          if ((HWND)lp == GetDlgItem (hDlg, IDC_CHUNK_SIZE))
61             {
62             if (IsWindowEnabled ((HWND)lp))
63                {
64                static HBRUSH hbrStatic = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
65                SetTextColor ((HDC)wp, GetSysColor (COLOR_WINDOWTEXT));
66                SetBkColor ((HDC)wp, GetSysColor (COLOR_WINDOW));
67                return (BOOL)hbrStatic;
68                }
69             }
70          break;
71
72       case WM_COMMAND:
73          switch (LOWORD(wp))
74             {
75             case IDHELP:
76                Logon_DlgProc (hDlg, WM_HELP, 0, 0);
77                break;
78
79             case IDOK:
80                 Logon_OnOK(hDlg);
81                 break;
82                 
83             case IDCANCEL:
84                 Logon_OnCancel(hDlg);
85                 break;
86             }
87          break;
88
89       case WM_HELP:
90          WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_ADVANCED_LOGON);
91          break;
92       }
93
94    return FALSE;
95 }
96
97
98 void Logon_OnInitDialog (HWND hDlg)
99 {
100    if (fFirstTime) {
101       Config_GetLoginRetryInterval(&g.Configuration.nLoginRetryInterval);
102       Config_GetFailLoginsSilently(&g.Configuration.fFailLoginsSilently);
103
104       nLoginRetryInterval = g.Configuration.nLoginRetryInterval;
105       fFailLoginsSilently = g.Configuration.fFailLoginsSilently;
106
107       fFirstTime = FALSE;
108    }
109
110    CreateSpinner (GetDlgItem (hDlg, IDC_LOGIN_RETRY_INTERVAL), 10, FALSE, nRETRY_MIN, nLoginRetryInterval, nRETRY_MAX);
111
112    GetString (szYes, IDS_YES);
113    GetString (szNo, IDS_NO);
114
115    HWND hCombo = GetDlgItem(hDlg, IDC_FAIL_SILENTLY);
116
117    // Always add szNo first so it has index 0 and szYes has index 1
118    CB_AddItem (hCombo, szNo, 0);
119    CB_AddItem (hCombo, szYes, 0);
120   
121    CB_SetSelected (hCombo, fFailLoginsSilently);
122 }
123
124
125 void Logon_OnOK (HWND hDlg)
126 {
127    nLoginRetryInterval = SP_GetPos (GetDlgItem (hDlg, IDC_LOGIN_RETRY_INTERVAL));
128    fFailLoginsSilently = CB_GetSelected (GetDlgItem (hDlg, IDC_FAIL_SILENTLY));
129
130    EndDialog(hDlg, IDOK);
131 }
132
133
134 BOOL Logon_OnApply()
135 {
136    if (fFirstTime)
137       return TRUE;
138    
139    if (nLoginRetryInterval != g.Configuration.nLoginRetryInterval) {
140       if (!Config_SetLoginRetryInterval (nLoginRetryInterval))
141          return FALSE;
142       g.Configuration.nLoginRetryInterval = nLoginRetryInterval;
143    }
144    
145    if (fFailLoginsSilently != g.Configuration.fFailLoginsSilently) {
146       if (!Config_SetFailLoginsSilently (fFailLoginsSilently))
147          return FALSE;
148       g.Configuration.fFailLoginsSilently = fFailLoginsSilently;
149    }
150
151    return TRUE;
152 }
153
154
155 void Logon_OnCancel(HWND hDlg)
156 {
157    fFirstTime = TRUE;
158
159    EndDialog(hDlg, IDCANCEL);
160 }