remove-extraneous-code-20040312
[openafs.git] / src / WINNT / client_config / dlg_diag.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 nBUFSIZE_MIN            3000
24 #define nBUFSIZE_MAX            32000
25
26 // Our dialog data
27 static BOOL fFirstTime = TRUE;
28 static DWORD nTraceBufSize;
29 static BOOL fTrapOnPanic;
30 static BOOL fReportSessionStartups;
31
32
33 /*
34  * PROTOTYPES _________________________________________________________________
35  *
36  */
37
38 void Diag_OnInitDialog (HWND hDlg);
39 void Diag_OnOK(HWND hDlg);
40 void Diag_OnCancel(HWND hDlg);
41 BOOL Diag_OnApply();
42
43
44 /*
45  * ROUTINES ___________________________________________________________________
46  *
47  */
48
49 BOOL CALLBACK Diag_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
50 {
51    switch (msg)
52       {
53       case WM_INITDIALOG:
54          Diag_OnInitDialog (hDlg);
55          break;
56
57       case WM_CTLCOLORSTATIC:
58          if ((HWND)lp == GetDlgItem (hDlg, IDC_CHUNK_SIZE))
59             {
60             if (IsWindowEnabled ((HWND)lp))
61                {
62                static HBRUSH hbrStatic = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
63                SetTextColor ((HDC)wp, GetSysColor (COLOR_WINDOWTEXT));
64                SetBkColor ((HDC)wp, GetSysColor (COLOR_WINDOW));
65                return (BOOL)hbrStatic;
66                }
67             }
68          break;
69
70       case WM_COMMAND:
71          switch (LOWORD(wp))
72             {
73             case IDHELP:
74                Diag_DlgProc (hDlg, WM_HELP, 0, 0);
75                break;
76
77             case IDOK:
78                 Diag_OnOK(hDlg);
79                 break;
80                 
81             case IDCANCEL:
82                 Diag_OnCancel(hDlg);
83                 break;
84             }
85          break;
86
87       case WM_HELP:
88          WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_ADVANCED_DIAG);
89          break;
90       }
91
92    return FALSE;
93 }
94
95 static void SetUpYesNoCombo(HWND hDlg, UINT nCtrlID, BOOL fInitialSetting)
96 {
97    static TCHAR szYes[10] = TEXT("");
98    static TCHAR szNo[10] = TEXT("");
99
100    if (!*szYes) {
101         GetString (szYes, IDS_YES);
102         GetString (szNo, IDS_NO);
103    }
104
105    HWND hCombo = GetDlgItem(hDlg, nCtrlID);
106
107    // Always add szNo first so it has index 0 and szYes has index 1
108    CB_AddItem (hCombo, szNo, 0);
109    CB_AddItem (hCombo, szYes, 0);
110
111    CB_SetSelected (hCombo, fInitialSetting);
112 }
113
114 void Diag_OnInitDialog (HWND hDlg)
115 {
116    if (fFirstTime) {
117       Config_GetTraceBufferSize(&g.Configuration.nTraceBufSize);
118       Config_GetTrapOnPanic(&g.Configuration.fTrapOnPanic);
119       Config_GetReportSessionStartups(&g.Configuration.fReportSessionStartups);
120       
121       nTraceBufSize = g.Configuration.nTraceBufSize;
122       fTrapOnPanic = g.Configuration.fTrapOnPanic;
123       fReportSessionStartups = g.Configuration.fReportSessionStartups;
124       
125       fFirstTime = FALSE;
126    }
127
128    CreateSpinner (GetDlgItem (hDlg, IDC_TRACE_LOG_BUF_SIZE), 10, FALSE, nBUFSIZE_MIN, nTraceBufSize, nBUFSIZE_MAX);
129
130    SetUpYesNoCombo(hDlg, IDC_TRAP_ON_PANIC, fTrapOnPanic);
131    SetUpYesNoCombo(hDlg, IDC_REPORT_SESSION_STARTUPS, fReportSessionStartups);
132 }
133
134
135 void Diag_OnOK (HWND hDlg)
136 {
137    nTraceBufSize = SP_GetPos (GetDlgItem (hDlg, IDC_TRACE_LOG_BUF_SIZE));
138    fTrapOnPanic = CB_GetSelected (GetDlgItem (hDlg, IDC_TRAP_ON_PANIC));
139    fReportSessionStartups = CB_GetSelected (GetDlgItem (hDlg, IDC_REPORT_SESSION_STARTUPS));
140
141    EndDialog(hDlg, IDOK);
142 }
143
144
145 BOOL Diag_OnApply()
146 {
147    if (fFirstTime)
148       return TRUE;
149
150    if (nTraceBufSize != g.Configuration.nTraceBufSize) {
151       if (!Config_SetTraceBufferSize (nTraceBufSize))
152          return FALSE;
153       g.Configuration.nTraceBufSize = nTraceBufSize;
154    }
155    
156    if (fTrapOnPanic != g.Configuration.fTrapOnPanic) {
157       if (!Config_SetTrapOnPanic (fTrapOnPanic))
158          return FALSE;
159       g.Configuration.fTrapOnPanic = fTrapOnPanic;
160    }
161    
162    if (fReportSessionStartups != g.Configuration.fReportSessionStartups) {
163       if (!Config_SetReportSessionStartups (fReportSessionStartups))
164          return FALSE;
165       g.Configuration.fReportSessionStartups = fReportSessionStartups;
166    }
167
168    return TRUE;
169 }
170
171
172 void Diag_OnCancel(HWND hDlg)
173 {
174    fFirstTime = TRUE;
175
176    EndDialog(hDlg, IDCANCEL);
177 }