global-mapping-20040325
[openafs.git] / src / WINNT / client_config / dlg_misc.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 #include <stdio.h>
15 #include "afs_config.h"
16
17
18 /*
19  * DEFINITIONS ________________________________________________________________
20  *
21  */
22
23 #define nLANA_MIN             0
24 #define nLANA_MAX             10
25
26 #define csecPROBE_MIN         1
27 #define csecPROBE_MAX         600
28
29 #define cTHREADS_MIN          1
30 #define cTHREADS_MAX          128
31
32 #define cDAEMONS_MIN          1
33 #define cDAEMONS_MAX          128
34
35
36 // Our dialog data
37 BOOL fFirstTime = TRUE;
38 #if undef
39 DWORD nLanAdapter;
40 #endif
41 DWORD csecProbe;
42 DWORD nThreads;
43 DWORD nDaemons;
44 TCHAR szSysName[ MAX_PATH ];
45 TCHAR szRootVolume[ MAX_PATH ];
46 TCHAR szMountDir[ MAX_PATH ];
47
48
49 /*
50  * PROTOTYPES _________________________________________________________________
51  *
52  */
53
54 void Misc_OnInitDialog (HWND hDlg);
55 void Misc_OnOK(HWND hDlg);
56 void Misc_OnCancel(HWND hDlg);
57 BOOL Misc_OnApply();
58
59
60 /*
61  * ROUTINES ___________________________________________________________________
62  *
63  */
64
65 BOOL CALLBACK Misc_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
66 {
67    switch (msg)
68       {
69       case WM_INITDIALOG:
70          Misc_OnInitDialog (hDlg);
71          break;
72
73       case WM_CTLCOLORSTATIC:
74          if ((HWND)lp == GetDlgItem (hDlg, IDC_CHUNK_SIZE))
75             {
76             if (IsWindowEnabled ((HWND)lp))
77                {
78                static HBRUSH hbrStatic = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
79                SetTextColor ((HDC)wp, GetSysColor (COLOR_WINDOWTEXT));
80                SetBkColor ((HDC)wp, GetSysColor (COLOR_WINDOW));
81                return (BOOL)hbrStatic;
82                }
83             }
84          break;
85
86       case WM_COMMAND:
87          switch (LOWORD(wp))
88             {
89             case IDHELP:
90                Misc_DlgProc (hDlg, WM_HELP, 0, 0);
91                break;
92
93             case IDOK:
94                 Misc_OnOK(hDlg);
95                 break;
96                 
97             case IDCANCEL:
98                 Misc_OnCancel(hDlg);
99                 break;
100 #if undef
101                         case IDC_AUTOLANA:
102                                 if (IsDlgButtonChecked(hDlg,IDC_AUTOLANA))
103                                         nLanAdapter=-1;
104                                 else
105                                         nLanAdapter=0;
106                                 SP_SetPos (GetDlgItem (hDlg, IDC_LAN_ADAPTER),nLanAdapter);
107                                 EnableWindow(GetDlgItem(hDlg,IDC_LAN_ADAPTER),(nLanAdapter!=-1));
108 #endif
109             }
110          break;
111
112       case WM_HELP:
113          WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_ADVANCED_MISC);
114          break;
115       }
116
117    return FALSE;
118 }
119
120
121 void Misc_OnInitDialog (HWND hDlg)
122 {
123    if (fFirstTime) {
124 #if undef
125       Config_GetLanAdapter(&g.Configuration.nLanAdapter);
126 #endif
127       Config_GetProbeInt (&g.Configuration.csecProbe);
128       Config_GetNumThreads (&g.Configuration.nThreads);
129       Config_GetNumDaemons (&g.Configuration.nDaemons);
130       Config_GetSysName (g.Configuration.szSysName);
131       Config_GetRootVolume (g.Configuration.szRootVolume);
132       Config_GetMountRoot (g.Configuration.szMountDir);
133
134 #if undef
135       nLanAdapter = g.Configuration.nLanAdapter;
136 #endif
137       csecProbe = g.Configuration.csecProbe;
138       nThreads = g.Configuration.nThreads;
139       nDaemons = g.Configuration.nDaemons;
140       lstrcpy(szSysName, g.Configuration.szSysName);
141       lstrcpy(szRootVolume, g.Configuration.szRootVolume);
142       lstrcpy(szMountDir, g.Configuration.szMountDir);
143
144       fFirstTime = FALSE;
145    }
146
147 #if undef
148    CreateSpinner (GetDlgItem (hDlg, IDC_LAN_ADAPTER), 99, FALSE, nLANA_MIN, nLanAdapter, nLANA_MAX);
149 #endif
150    CreateSpinner (GetDlgItem (hDlg, IDC_PROBE), 10, FALSE, csecPROBE_MIN, csecProbe, csecPROBE_MAX);
151    CreateSpinner (GetDlgItem (hDlg, IDC_THREADS), 10, FALSE, cTHREADS_MIN, nThreads, cTHREADS_MAX);
152    CreateSpinner (GetDlgItem (hDlg, IDC_DAEMONS), 10, FALSE, cDAEMONS_MIN, nDaemons, cDAEMONS_MAX);
153    
154    SetDlgItemText (hDlg, IDC_SYSNAME, szSysName);
155    SetDlgItemText (hDlg, IDC_ROOTVOLUME, szRootVolume);
156    SetDlgItemText (hDlg, IDC_MOUNTDIR, szMountDir);
157 #if undef
158    CheckDlgButton (hDlg, IDC_AUTOLANA, (nLanAdapter==-1));
159    EnableWindow(GetDlgItem(hDlg,IDC_LAN_ADAPTER),(nLanAdapter!=-1));
160 #endif
161 }
162
163 void Misc_OnOK (HWND hDlg)
164 {
165 #if undef
166         nLanAdapter =  (IsDlgButtonChecked(hDlg,IDC_AUTOLANA))?-1
167                 :SP_GetPos (GetDlgItem (hDlg, IDC_LAN_ADAPTER));
168 #endif
169    csecProbe = SP_GetPos (GetDlgItem (hDlg, IDC_PROBE));
170   
171    nThreads = SP_GetPos (GetDlgItem (hDlg, IDC_THREADS));
172    
173    nDaemons = SP_GetPos (GetDlgItem (hDlg, IDC_DAEMONS));
174    
175    GetDlgItemText (hDlg, IDC_SYSNAME, szSysName, sizeof(szSysName));
176    GetDlgItemText (hDlg, IDC_ROOTVOLUME, szRootVolume, sizeof(szRootVolume));
177    GetDlgItemText (hDlg, IDC_MOUNTDIR, szMountDir, sizeof(szMountDir));
178    
179    EndDialog(hDlg, IDOK);
180 }
181
182
183 BOOL Misc_OnApply()
184 {
185    if (fFirstTime)
186       return TRUE;
187
188 #if undef
189    if (nLanAdapter != g.Configuration.nLanAdapter) {
190       if (!Config_SetLanAdapter (nLanAdapter))
191          return FALSE;
192       g.Configuration.nLanAdapter = nLanAdapter;
193    }
194 #endif
195
196    if (csecProbe != g.Configuration.csecProbe) {
197       if (!Config_SetProbeInt (csecProbe))
198          return FALSE;
199       g.Configuration.csecProbe = csecProbe;
200    }
201    
202    if (nThreads != g.Configuration.nThreads) {
203       if (!Config_SetNumThreads (nThreads))
204          return FALSE;
205       g.Configuration.nThreads = nThreads;
206    }
207    
208    if (nDaemons != g.Configuration.nDaemons) {
209       if (!Config_SetNumDaemons (nDaemons))
210          return FALSE;
211       g.Configuration.nDaemons = nDaemons;
212    }
213    
214    if (lstrcmp(szSysName, g.Configuration.szSysName) != 0) {
215       if (!Config_SetSysName (szSysName))
216          return FALSE;
217       lstrcpy(g.Configuration.szSysName, szSysName);
218    }
219    
220    if (lstrcmp(szRootVolume, g.Configuration.szRootVolume) != 0) {
221       if (!Config_SetRootVolume (szRootVolume))
222          return FALSE;
223       lstrcpy(g.Configuration.szRootVolume, szRootVolume);
224    }
225    
226    if (lstrcmp(szMountDir, g.Configuration.szMountDir) != 0) {
227       if (!Config_SetMountRoot (szMountDir))
228          return FALSE;
229       lstrcpy(g.Configuration.szMountDir, szMountDir);
230    }
231
232    return TRUE;
233 }
234
235 void Misc_OnCancel(HWND hDlg)
236 {
237    fFirstTime = TRUE;
238
239    EndDialog(hDlg, IDCANCEL);
240 }
241