-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguiwind.cpp
More file actions
369 lines (318 loc) · 12.5 KB
/
Copy pathguiwind.cpp
File metadata and controls
369 lines (318 loc) · 12.5 KB
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
// 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: guiwind.cpp,v 1.20 2004/07/04 20:58:28 jlawson Exp $";
#endif
bool bShowIdleDrops = true;
MyGraphWindow graphwin;
static char __currentlogfilename[200] = {0};
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
const char *LogGetCurrentLogFilename(void)
{
return __currentlogfilename;
}
void LogSetCurrentLogFilename(const char *filename, bool removeQuotes)
{
// copy the string.
lstrcpyn(__currentlogfilename, filename, sizeof(__currentlogfilename));
__currentlogfilename[sizeof(__currentlogfilename) - 1] = 0;
// remove leading and trailing quotes, if needed.
int len = strlen(__currentlogfilename);
if (removeQuotes && len >= 2 &&
(__currentlogfilename[0] == '"') &&
(__currentlogfilename[len - 1] == '"') )
{
memmove(__currentlogfilename, __currentlogfilename + 1, len - 2);
__currentlogfilename[len - 2] = 0;
}
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK Main_WindowProc(
HWND hwnd, // handle of window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch (uMsg)
{
case WM_CREATE:
{
// Allow normal window creation to finish.
LRESULT result = DefWindowProc(hwnd, uMsg, wParam, lParam);
// Create the status window.
CreateStatusWindow((SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE),
"Ready", hwnd, IDC_STATUSBAR);
// Accept drag-and-dropped files.
DragAcceptFiles(hwnd, TRUE);
return result;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_DROPFILES:
{
// get the filename of the dropped item.
DragQueryFile((HDROP) wParam, 0,
__currentlogfilename, sizeof(__currentlogfilename));
DragFinish((HDROP) wParam);
// trigger the reload to occur in the background.
graphwin.LogRereadNeeded(hwnd);
Main_UpdateTitlebar(hwnd);
break;
}
case WM_INITMENU:
{
// This event is triggered each time just before a menu is going to be displayed.
HMENU hPopup = (HMENU) wParam;
// Enable or disable the menu items that are not valid without a logfile.
DWORD dwEnabledWithLogAndData = (graphwin.IsDataAvailable() ? MF_ENABLED : MF_GRAYED);
DWORD dwEnabledWithLog = (graphwin.GetStatusValue() != MyGraphWindow::nologloaded ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(hPopup, IDM_REFRESHLOGFILE, MF_BYCOMMAND | dwEnabledWithLog);
EnableMenuItem(hPopup, IDM_GRAPHCONFIG, MF_BYCOMMAND | dwEnabledWithLogAndData);
EnableMenuItem(hPopup, IDM_PROJECT_RC5, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_RC5) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_PROJECT_RC5_72, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_RC5_72) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_PROJECT_DES, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_DES) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_PROJECT_CSC, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_CSC) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_PROJECT_OGR, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_OGR) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_PROJECT_OGR_P2, MF_BYCOMMAND | (graphwin.IsDataAvailable(MyGraphWindow::PROJECT_OGR_P2) ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(hPopup, IDM_SHOWIDLE, MF_BYCOMMAND | dwEnabledWithLogAndData);
EnableMenuItem(hPopup, IDM_EXPORT_CSV, MF_BYCOMMAND | dwEnabledWithLogAndData);
// Enable the "full zoom" menu item only when there is data and zoomed in.
time_t zoomleft, zoomright;
graphwin.GetRange(zoomleft, zoomright);
DWORD dwEnabledWithPartialZoom = (zoomleft != (time_t) -1 || zoomright != (time_t) -1) ? MF_ENABLED : MF_GRAYED;
EnableMenuItem(hPopup, IDM_ZOOMFULL, MF_BYCOMMAND | dwEnabledWithLogAndData | dwEnabledWithPartialZoom);
// Check or uncheck the drop menu item.
CheckMenuItem(hPopup, IDM_SHOWIDLE, MF_BYCOMMAND |
(bShowIdleDrops ? MF_CHECKED : MF_UNCHECKED));
// Set the radio button on whichever project is currently selected.
UINT radioselect = graphwin.GetViewedProjectMenuId();
CheckMenuRadioItem(hPopup, IDM_PROJECT_RC5, IDM_PROJECT_OGR_P2,
radioselect, MF_BYCOMMAND);
return FALSE;
}
case WM_SIZE:
SendMessage(GetDlgItem(hwnd, IDC_STATUSBAR), WM_SIZE, wParam, lParam);
InvalidateRect(hwnd, NULL, TRUE);
break;
case WM_PAINT:
{
PAINTSTRUCT m_ps;
RECT clientrect, statusrect;
int savedcontext;
// Repaint the window.
if (BeginPaint(hwnd, &m_ps))
{
if ((savedcontext = SaveDC(m_ps.hdc)) != 0)
{
// Compute the rectangle of the client paint area,
// not including the status bar and the window borders.
// This is probably not the best way to do it, but this
// is the easiest way I could manage it.
GetClientRect(hwnd, &clientrect);
GetClientRect(GetDlgItem(hwnd, IDC_STATUSBAR), &statusrect);
clientrect.bottom -= (statusrect.bottom - statusrect.top);
clientrect.left += GetSystemMetrics(SM_CXFRAME);
clientrect.right -= GetSystemMetrics(SM_CXFRAME);
// actually perform the repaint operation.
graphwin.DoRedraw(m_ps.hdc, clientrect);
}
RestoreDC(m_ps.hdc, savedcontext);
EndPaint(hwnd, &m_ps);
}
// Update the status bar
if (graphwin.HasStatusChanged())
SendMessage(GetDlgItem(hwnd, IDC_STATUSBAR), SB_SETTEXT,
0, (LPARAM) graphwin.GetStatusString());
return FALSE;
}
case WM_COMMAND:
{
WORD wNotifyCode = HIWORD(wParam); // notification code
WORD wID = LOWORD(wParam); // control identifier
if (wNotifyCode == 0)
{
if (wID == IDM_EXIT)
{
PostMessage(hwnd, WM_CLOSE, 0, 0);
return FALSE;
}
else if (wID == IDM_ABOUT)
{
Main_CmAbout(hwnd);
return FALSE;
}
else if (wID == IDM_OPENLOGFILE)
{
Main_CmOpenLogfile(hwnd);
return FALSE;
}
else if (wID == IDM_REFRESHLOGFILE)
{
graphwin.LogRereadNeeded(hwnd);
return FALSE;
}
else if (wID == IDM_EXPORT_CSV)
{
Main_CmExportCSV(hwnd);
return FALSE;
}
else if (wID == IDM_GRAPHCONFIG)
{
// require that a logfile is already loaded.
if (graphwin.IsDataAvailable())
{
// bring up the configuration dialog
MyGraphConfig config;
graphwin.GetDataRange(config.datastart, config.dataend);
graphwin.GetRange(config.starttime, config.endtime);
config.DoModal(hwnd);
graphwin.SetRange(config.starttime, config.endtime);
// force a redraw
InvalidateRect(hwnd, NULL, TRUE);
}
return FALSE;
}
else if (wID == IDM_PROJECT_RC5 ||
wID == IDM_PROJECT_RC5_72 ||
wID == IDM_PROJECT_DES ||
wID == IDM_PROJECT_CSC ||
wID == IDM_PROJECT_OGR ||
wID == IDM_PROJECT_OGR_P2)
{
if (graphwin.SetViewedProjectByMenuId(wID)) {
// now trigger a reload from the log file.
graphwin.LogRereadNeeded(hwnd);
}
return FALSE;
}
else if (wID == IDM_SHOWIDLE)
{
bShowIdleDrops = !bShowIdleDrops;
// force a redraw
InvalidateRect(hwnd, NULL, TRUE);
}
else if (wID == IDM_ZOOMFULL)
{
// set zoom window to actual beginning and end of logfile.
graphwin.SetRange((time_t) -1, (time_t) -1);
// force a redraw
InvalidateRect(hwnd, NULL, TRUE);
}
}
break;
}
case WM_RBUTTONDOWN:
{
// require that a logfile is already loaded.
if (graphwin.IsDataAvailable())
{
// bring up the configuration dialog
MyGraphConfig config;
graphwin.GetDataRange(config.datastart, config.dataend);
graphwin.GetRange(config.starttime, config.endtime);
config.DoModal(hwnd);
graphwin.SetRange(config.starttime, config.endtime);
// force a redraw
InvalidateRect(hwnd, NULL, TRUE);
}
return FALSE;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
void Main_CmOpenLogfile(HWND hwnd)
{
OPENFILENAME ofn;
char filterarray[] = { "Log files (*.LOG)\0" "*.LOG\0"
"All files (*.*)\0" "*.*\0" "\0\0" };
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = filterarray;
ofn.lpstrFile = __currentlogfilename;
ofn.nMaxFile = sizeof(__currentlogfilename);
ofn.lpstrTitle = "Select distributed.net logfile to load";
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "LOG";
if (GetOpenFileName(&ofn))
{
// trigger the reload to occur in the background.
graphwin.LogRereadNeeded(hwnd);
Main_UpdateTitlebar(hwnd);
}
}
void Main_CmExportCSV(HWND hwnd)
{
OPENFILENAME ofn;
char filterarray[] = { "CSV (Comma delimited) (*.CSV)\0" "*.CSV\0"
"All files (*.*)\0" "*.*\0" "\0\0" };
char exportfilename[512] = { '\0' };
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = filterarray;
ofn.lpstrFile = exportfilename;
ofn.nMaxFile = sizeof(exportfilename);
ofn.lpstrTitle = "Select new file to export to";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = "CSV";
if (GetSaveFileName(&ofn))
{
int retval = graphwin.ExportCSV(exportfilename);
if (retval != 0) {
MessageBox(hwnd, "Failed to write exported data to file.",
NULL, MB_ICONERROR | MB_OK);
}
}
}
void Main_UpdateTitlebar(HWND hwnd)
{
char buff[sizeof(PROG_DESC_LONG) + sizeof(__currentlogfilename) + 10];
// display the file name in the titlebar.
#ifdef HAVE_SNPRINTF
_snprintf(buff, sizeof(buff),
#else
sprintf(buff,
#endif
"%s - [%s]", PROG_DESC_LONG, __currentlogfilename);
SetWindowText(hwnd, buff);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
void Main_CmAbout(HWND hwnd)
{
const char *buffer =
PROG_DESC_LONG ", " PROG_VERSION_STR "\n"
"Distributed Computing Technologies, Inc.\n"
"http://www.distributed.net/\n\n"
"Programmed by Jeff \"Bovine\" Lawson <bovine@distributed.net>\n"
"Other work by Yang You <yang_you@yahoo.com>\n\n"
"Please send questions about this program to <help@distributed.net>";
MSGBOXPARAMS msgbox;
msgbox.cbSize = sizeof(MSGBOXPARAMS);
msgbox.hwndOwner = hwnd;
msgbox.hInstance = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
msgbox.lpszText = buffer;
msgbox.lpszCaption = "About this Program";
msgbox.dwStyle = MB_USERICON | MB_OK;
msgbox.lpszIcon = MAKEINTRESOURCE(IDI_ICON_MAIN);
msgbox.dwContextHelpId = 0;
msgbox.lpfnMsgBoxCallback = NULL;
msgbox.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
MessageBoxIndirect(&msgbox);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////