-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguiconfig.cpp
401 lines (359 loc) · 14.7 KB
/
guiconfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// Copyright distributed.net 1997-2004 - All Rights Reserved
// For use in distributed.net projects only.
// Any other distribution or use of this source violates copyright.
#include "guiwin.h"
#if (!defined(lint) && defined(__showids__))
static char *id="@(#)$Id: guiconfig.cpp,v 1.7 2004/07/04 13:02:16 jlawson Exp $";
#endif
#define UNUSEDMBZ 0 // Unused, must be zero.
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
struct EventType
{
char *text;
time_t timestamp;
};
static EventType graphevents [] = {
{"Start of RC5-56", 854438400L}, // January 28, 1997 13:25 GMT
{"End of RC5-56", 877492800L}, // Wed Oct 22 00:00:00 EDT 1997
{"Start of RC5-64", 877492800L}, // Wed Oct 22 00:00:00 EDT 1997
{"Start of DESII-1", 884674800L}, // January 13, 1998 at 09:00 PST
{"End of DESII-1", 888197160L}, // February 23, 1998 at 02:26 PST
{"Start of DESII-2", 877260300L}, // Mon Jul 13 09:00:00 1998 PST
{"End of DESII-2", 900648000L}, // Fri Jul 17 00:00:00 EDT 1998
{"Start of DESIII", 916635600L}, // Mon Jan 18 00:00:00 EST 1999
{"End of DESIII", 916722000L}, // Tue Jan 19 00:00:00 EST 1999
{"Start of CSC", 943678800L}, // Sat Nov 27 00:00:00 EST 1999
{"End of CSC", 947912400L}, // Sat Jan 15 00:00:00 EST 2000
{"Start of OGR-24", 963460800L}, // Thu Jul 13 00:00:00 EDT 2000
{"Start of OGR-25", 965102400L}, // Tue Aug 1 00:00:00 EDT 2000
{"End of RC5-64", 1026619200L}, // Sun Jul 14 00:00:00 EDT 2002
{"Start of RC5-72", 1038891600L}, // Tue Dec 3 00:00:00 EST 2002
{"Start of OGR-P2", 1084665600L}, // 16-May-2004 00:00:00 UTC
{NULL, 0} };
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
static void SetDlgItemGMT(HWND hwndParent, int nID, time_t timestamp)
{
char buffer[50];
if (timestamp < 0)
{
buffer[0] = 0;
}
else
{
struct tm *gmt = gmtime(×tamp);
if (gmt)
strftime(buffer, sizeof(buffer), "%Y-%b-%d %H:%M", gmt);
else
buffer[0] = 0;
}
SetDlgItemText(hwndParent, nID, buffer);
}
static void CenterWindow(HWND hwndDlg)
{
WINDOWPLACEMENT ourplace, parentplace;
// center the dialog within our parent.
ourplace.length = sizeof(WINDOWPLACEMENT);
parentplace.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwndDlg, &ourplace);
GetWindowPlacement(GetParent(hwndDlg), &parentplace);
int parentw = (parentplace.rcNormalPosition.right - parentplace.rcNormalPosition.left);
int parenth = (parentplace.rcNormalPosition.bottom - parentplace.rcNormalPosition.top);
int ourw = (ourplace.rcNormalPosition.right - ourplace.rcNormalPosition.left);
int ourh = (ourplace.rcNormalPosition.bottom - ourplace.rcNormalPosition.top);
int newx = (parentw > ourw ? (parentw - ourw) / 2 : 0);
int newy = (parenth > ourh ? (parenth - ourh) / 2 : 0);
SetRect(&ourplace.rcNormalPosition,
parentplace.rcNormalPosition.left + newx,
parentplace.rcNormalPosition.top + newy,
parentplace.rcNormalPosition.left + newx + ourw,
parentplace.rcNormalPosition.top + newy + ourh);
SetWindowPlacement(hwndDlg, &ourplace);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
int MyGraphConfig::DoModal(HWND parent)
{
if (datastart == dataend) return FALSE;
return DialogBoxParam(
(HINSTANCE) GetWindowLong(parent, GWL_HINSTANCE),
MAKEINTRESOURCE(IDD_GRAPHCFG), parent,
(DLGPROC) MyGraphConfig::DialogProc, (LPARAM) this);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK MyGraphConfig::DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static MyGraphConfig *mgc = NULL;
switch (uMsg)
{
case WM_INITDIALOG:
mgc = (MyGraphConfig *) lParam;
return mgc->OnInitDialog(hwndDlg, (HWND) wParam, lParam);
case WM_COMMAND:
return mgc->OnCommand(hwndDlg, HIWORD(wParam),
LOWORD(wParam), (HWND) lParam);
};
return 0; // no need to call DefWindowProc or DefDlgProc!
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
#pragma argsused
int MyGraphConfig::OnInitDialog(HWND hwndDlg, HWND hWndFocus, LPARAM lParam)
{
// center the dialog inside our parent.
CenterWindow(hwndDlg);
// attach the range slider to the control
HWND rangeslider = GetDlgItem(hwndDlg, IDC_SLIDERRANGE);
// validate ranges.
while (datastart > dataend) dataend += 365*24*60*60;
if (starttime != (time_t) -1 && (starttime < datastart || starttime > dataend))
starttime = (time_t) -1;
if (endtime != (time_t) -1 && (endtime > dataend || endtime < datastart))
endtime = (time_t) -1;
if (endtime != (time_t) -1 && starttime != (time_t) -1 && endtime < starttime)
endtime = (time_t) -1;
// combo start box
HWND combostart = GetDlgItem(hwndDlg, IDC_COMBOSTART);
SendMessage(combostart, CB_ADDSTRING, UNUSEDMBZ, (LPARAM) "Start of logfile");
SendMessage(combostart, CB_ADDSTRING, UNUSEDMBZ, (LPARAM) "User specified date");
if (starttime == (time_t) -1 || dataend == datastart)
{
userstart = 0;
SendMessage(combostart, CB_SETCURSEL, 0, UNUSEDMBZ);
SendMessage(rangeslider, SRM_SETLEFT, UNUSEDMBZ, 0);
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, datastart);
} else {
userstart = starttime;
SendMessage(combostart, CB_SETCURSEL, 1, UNUSEDMBZ);
double percent = (double) (starttime - datastart) /
(double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETLEFT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, userstart);
}
for (int i = 0; graphevents[i].text; i++)
if (graphevents[i].timestamp >= datastart &&
graphevents[i].timestamp <= dataend)
{
int newindex = SendMessage(combostart, CB_ADDSTRING, UNUSEDMBZ,
(LPARAM) graphevents[i].text);
if (graphevents[i].timestamp == starttime)
SendMessage(combostart, CB_SETCURSEL, newindex, UNUSEDMBZ);
}
// combo end box
HWND comboend = GetDlgItem(hwndDlg, IDC_COMBOEND);
SendMessage(comboend, CB_ADDSTRING, UNUSEDMBZ, (LPARAM) "End of logfile");
SendMessage(comboend, CB_ADDSTRING, UNUSEDMBZ, (LPARAM) "User specified date");
if (endtime == (time_t) -1 || dataend == datastart)
{
userend = 0;
SendMessage(comboend, CB_SETCURSEL, 0, UNUSEDMBZ);
SendMessage(rangeslider, SRM_SETRIGHT, UNUSEDMBZ, (int)
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ) );
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, dataend);
} else {
userend = endtime;
SendMessage(comboend, CB_SETCURSEL, 1, UNUSEDMBZ);
double percent = (double) (userend - datastart) / (double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETRIGHT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, userend);
}
for (int j = 0; graphevents[j].text; j++)
if (graphevents[j].timestamp >= datastart &&
graphevents[j].timestamp <= dataend)
{
int newindex = SendMessage(comboend, CB_ADDSTRING, UNUSEDMBZ,
(LPARAM) graphevents[j].text);
if (graphevents[j].timestamp == endtime)
SendMessage(comboend, CB_SETCURSEL, newindex, UNUSEDMBZ);
}
return TRUE; // allow focus to go to first control.
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
#pragma argsused
int MyGraphConfig::OnCommand(
HWND hwndDlg,
WORD wNotifyCode,
WORD wID,
HWND hWndControl)
{
HWND combostart = GetDlgItem(hwndDlg, IDC_COMBOSTART);
HWND comboend = GetDlgItem(hwndDlg, IDC_COMBOEND);
HWND rangeslider = GetDlgItem(hwndDlg, IDC_SLIDERRANGE);
if (wID == IDOK)
{
if (!OnOK(hwndDlg))
EndDialog(hwndDlg, IDOK);
return FALSE;
}
else if (wID == IDCANCEL)
{
EndDialog(hwndDlg, IDCANCEL);
return FALSE;
}
else if (wID == IDC_SLIDERRANGE)
{
// compute the new user-entered values
double maxval = (double) SendMessage(rangeslider,
SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ);
if (maxval == 0) return FALSE;
if (wNotifyCode == SRN_LEFTCHANGED)
{
if (maxval)
{
double percent = (double) SendMessage(rangeslider, SRM_GETLEFT,
UNUSEDMBZ, UNUSEDMBZ) / maxval;
userstart = (time_t) (percent * (dataend - datastart) + datastart);
SendMessage(combostart, CB_SETCURSEL, 1, UNUSEDMBZ);
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, userstart);
SetFocus(combostart);
}
}
else if (wNotifyCode == SRN_RIGHTCHANGED)
{
if (maxval)
{
double percent = (double) SendMessage(rangeslider, SRM_GETRIGHT,
UNUSEDMBZ, UNUSEDMBZ) / maxval;
userend = (time_t) (percent * (dataend - datastart) + datastart);
SendMessage(comboend, CB_SETCURSEL, 1, UNUSEDMBZ);
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, userend);
SetFocus(comboend);
}
}
return FALSE;
}
// ---------------------
else if (wID == IDC_COMBOSTART && wNotifyCode == CBN_SELCHANGE)
{
int newchoice = (int) SendMessage(combostart, CB_GETCURSEL,
UNUSEDMBZ, UNUSEDMBZ);
if (dataend == datastart) return FALSE;
if (newchoice == 0) // start of log
{
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, datastart);
SendMessage(rangeslider, SRM_SETLEFT, UNUSEDMBZ, 0);
return FALSE;
}
else if (newchoice == 1) // user specified
{
if (userstart == 0) userstart = datastart;
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, userstart);
double percent = (double) (userstart - datastart) / (double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETLEFT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
return FALSE;
}
else for (int i = 0; graphevents[i].text; i++) // drop down choices
{
char buffer[50];
SendMessage(combostart, CB_GETLBTEXT, i, (LPARAM) buffer);
if (strcmp(buffer, graphevents[i].text) == 0)
{
SetDlgItemGMT(hwndDlg, IDS_STARTDATE, graphevents[i].timestamp);
double percent = (double) (graphevents[i].timestamp - datastart) / (double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETLEFT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
return FALSE;
}
}
SetDlgItemText(hwndDlg, IDS_STARTDATE, "unknown");
}
// ---------------------
else if (wID == IDC_COMBOEND && wNotifyCode == CBN_SELCHANGE)
{
int newchoice = SendMessage(comboend, CB_GETCURSEL, UNUSEDMBZ, UNUSEDMBZ);
if (dataend == datastart) return FALSE;
if (newchoice == 0) // end of log
{
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, dataend);
SendMessage(rangeslider, SRM_SETRIGHT, UNUSEDMBZ,
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ));
return FALSE;
}
else if (newchoice == 1) // user specified
{
if (userend == 0) userend = dataend;
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, userend);
double percent = (double) (userend - datastart) / (double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETRIGHT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
return FALSE;
}
else for (int i = 0; graphevents[i].text; i++) // drop down choice
{
char buffer[50];
SendMessage(combostart, CB_GETLBTEXT, i, (LPARAM) buffer);
if (strcmp(buffer, graphevents[i].text) == 0)
{
SetDlgItemGMT(hwndDlg, IDS_ENDDATE, graphevents[i].timestamp);
double percent = (double) (graphevents[i].timestamp - datastart) /
(double) (dataend - datastart);
SendMessage(rangeslider, SRM_SETRIGHT, UNUSEDMBZ, (int) (percent *
SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ)) );
return FALSE;
}
}
SetDlgItemText(hwndDlg, IDS_ENDDATE, "unknown");
}
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
#pragma argsused
BOOL MyGraphConfig::OnOK(HWND hwndDlg)
{
HWND combostart = GetDlgItem(hwndDlg, IDC_COMBOSTART);
HWND comboend = GetDlgItem(hwndDlg, IDC_COMBOEND);
HWND rangeslider = GetDlgItem(hwndDlg, IDC_SLIDERRANGE);
// starting time
int newchoice = SendMessage(combostart, CB_GETCURSEL, UNUSEDMBZ, UNUSEDMBZ);
if (newchoice == 0) // start of log
{
starttime = (time_t) -1;
}
else // user specified or drop down
{
int maxval = SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ);
if (maxval != 0) {
double percent = (double) SendMessage(rangeslider, SRM_GETLEFT,
UNUSEDMBZ, UNUSEDMBZ) / maxval;
starttime = datastart + (time_t) (percent * (dataend - datastart));
} else starttime = (time_t) -1;
}
// ending time
newchoice = SendMessage(comboend, CB_GETCURSEL, UNUSEDMBZ, UNUSEDMBZ);
if (newchoice == 0) // end of log
{
endtime = (time_t) -1;
}
else // user specified or drop down
{
int maxval = SendMessage(rangeslider, SRM_GETMAXRANGE, UNUSEDMBZ, UNUSEDMBZ);
if (maxval != 0) {
double percent = (double) SendMessage(rangeslider, SRM_GETRIGHT,
UNUSEDMBZ, UNUSEDMBZ) / maxval;
endtime = datastart + (time_t) (percent * (dataend - datastart));
} else endtime = (time_t) -1;
}
return FALSE; // allow closure.
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////