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