Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / ctl_elapsed.cpp
blobd566bc75cb9872d8bbb22e38c90886dbf3574d9f
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
15 #include <windows.h>
16 #include <windowsx.h>
17 #include <commctrl.h>
18 #include <WINNT/dialog.h>
19 #include <WINNT/resize.h> // for GetRectInParent()
20 #include <WINNT/subclass.h>
21 #include <WINNT/ctl_spinner.h>
22 #include <WINNT/ctl_elapsed.h>
23 #include <WINNT/TaLocale.h>
25 #ifndef cchRESOURCE
26 #define cchRESOURCE 256
27 #endif
31 * MISCELLANEOUS ______________________________________________________________
35 #ifndef REALLOC
36 #define REALLOC(_a,_c,_r,_i) ElapsedReallocFunction ((LPVOID*)&_a,sizeof(*_a),&_c,_r,_i)
37 BOOL ElapsedReallocFunction (LPVOID *ppTarget, size_t cbElement, size_t *pcTarget, size_t cReq, size_t cInc)
39 LPVOID pNew;
40 size_t cNew;
42 if (cReq <= *pcTarget)
43 return TRUE;
45 if ((cNew = cInc * ((cReq + cInc-1) / cInc)) <= 0)
46 return FALSE;
48 if ((pNew = (LPVOID)Allocate (cbElement * cNew)) == NULL)
49 return FALSE;
50 memset (pNew, 0x00, cbElement * cNew);
52 if (*pcTarget != 0)
54 memcpy (pNew, *ppTarget, cbElement * (*pcTarget));
55 Free (*ppTarget);
58 *ppTarget = pNew;
59 *pcTarget = cNew;
60 return TRUE;
62 #endif
67 * ELAPSEDS ___________________________________________________________________
71 typedef struct
73 HWND hElapsed;
74 HWND hHours;
75 HWND hSep1;
76 HWND hMinutes;
77 HWND hSep2;
78 HWND hSeconds;
79 HWND hSpinner;
80 HWND hSpinnerBuddy;
82 WORD idHours;
83 WORD idMinutes;
84 WORD idSeconds;
86 SYSTEMTIME timeMin; // only hour, minute, second fields are relevant
87 SYSTEMTIME timeNow; // only hour, minute, second fields are relevant
88 SYSTEMTIME timeMax; // only hour, minute, second fields are relevant
90 BOOL fCallingBack;
91 BOOL fCanCallBack;
92 } ElapsedInfo;
94 static CRITICAL_SECTION csElapsed;
95 static ElapsedInfo *aElapsed = NULL;
96 static size_t cElapsed = 0;
98 #define cszELAPSEDCLASS TEXT("Elapsed")
100 HRESULT CALLBACK ElapsedProc (HWND hElapsed, UINT msg, WPARAM wp, LPARAM lp);
101 HRESULT CALLBACK ElapsedEditProc (HWND hEdit, UINT msg, WPARAM wp, LPARAM lp);
102 HRESULT CALLBACK ElapsedDlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
104 void Elapsed_SendCallback (ElapsedInfo *pei, WORD eln, LPARAM lp);
106 void Elapsed_OnCreate (ElapsedInfo *psi);
107 void Elapsed_OnDestroy (ElapsedInfo *psi);
108 void Elapsed_OnButtonDown (ElapsedInfo *pei, UINT msg, WPARAM wp, LPARAM lp);
109 BOOL Elapsed_OnGetRange (ElapsedInfo *psi, WPARAM wp, LPARAM lp);
110 BOOL Elapsed_OnSetRange (ElapsedInfo *psi, WPARAM wp, LPARAM lp);
111 BOOL Elapsed_OnGetTime (ElapsedInfo *psi, WPARAM wp, LPARAM lp);
112 BOOL Elapsed_OnSetTime (ElapsedInfo *psi, WPARAM wp, LPARAM lp);
114 void Elapsed_Edit_OnSetFocus (ElapsedInfo *pei, HWND hEdit);
115 void Elapsed_Edit_GetSpinnerRange (ElapsedInfo *pei, HWND hEdit, DWORD *pdwMin, DWORD *pdwPos, DWORD *pdwMax);
116 void Elapsed_Edit_OnUpdate (ElapsedInfo *pei, HWND hEdit, DWORD dwNew);
117 void Elapsed_Edit_OnEnforceRange (ElapsedInfo *pei, HWND hEdit);
118 void Elapsed_Edit_SetText (ElapsedInfo *pei, HWND hEdit);
121 BOOL RegisterElapsedClass (void)
123 static BOOL fRegistered = FALSE;
125 if (!fRegistered)
127 InitializeCriticalSection (&csElapsed);
129 WNDCLASS wc;
130 memset (&wc, 0x00, sizeof(wc));
131 wc.style = CS_GLOBALCLASS;
132 wc.lpfnWndProc = (WNDPROC)ElapsedProc;
133 wc.hInstance = THIS_HINST;
134 wc.hCursor = LoadCursor (NULL, MAKEINTRESOURCE (IDC_ARROW));
135 wc.hbrBackground = CreateSolidBrush (GetSysColor (COLOR_BTNFACE));
136 wc.lpszClassName = cszELAPSEDCLASS;
138 if (RegisterClass (&wc))
139 fRegistered = TRUE;
142 return fRegistered;
146 void Elapsed_SendCallback (ElapsedInfo *pei, WORD eln, LPARAM lp)
148 if ((pei->fCanCallBack == TRUE) && !pei->fCallingBack)
150 pei->fCallingBack = TRUE;
152 SendMessage (GetParent (pei->hElapsed),
153 WM_COMMAND,
154 MAKELONG ((WORD)GetWindowLong (pei->hElapsed, GWL_ID), eln),
155 lp);
157 pei->fCallingBack = FALSE;
162 HRESULT CALLBACK ElapsedProc (HWND hElapsed, UINT msg, WPARAM wp, LPARAM lp)
164 ElapsedInfo *pei = NULL;
166 EnterCriticalSection (&csElapsed);
168 if (msg == WM_CREATE)
170 size_t iElapsed;
171 for (iElapsed = 0; iElapsed < cElapsed; ++iElapsed)
173 if (aElapsed[ iElapsed ].hElapsed == NULL)
174 break;
176 if (iElapsed >= cElapsed)
178 if (!REALLOC (aElapsed, cElapsed, 1+iElapsed, 4))
179 return FALSE;
182 memset (&aElapsed[ iElapsed ], 0x00, sizeof(ElapsedInfo));
183 aElapsed[ iElapsed ].hElapsed = hElapsed;
185 pei = &aElapsed[ iElapsed ];
187 else
189 for (size_t iElapsed = 0; !pei && iElapsed < cElapsed; ++iElapsed)
191 if (aElapsed[ iElapsed ].hElapsed == hElapsed)
192 pei = &aElapsed[ iElapsed ];
196 LeaveCriticalSection (&csElapsed);
198 if (pei != NULL)
200 switch (msg)
202 case WM_CREATE:
203 Elapsed_OnCreate (pei);
204 break;
206 case WM_DESTROY:
207 Elapsed_OnDestroy (pei);
208 break;
210 case WM_RBUTTONDOWN:
211 case WM_LBUTTONDOWN:
212 Elapsed_OnButtonDown (pei, msg, wp, lp);
213 break;
215 case WM_SETFOCUS:
216 PostMessage (GetParent(hElapsed), WM_NEXTDLGCTL, (WPARAM)pei->hHours, TRUE);
217 break;
219 case WM_ENABLE:
220 EnableWindow (pei->hHours, IsWindowEnabled (hElapsed));
221 EnableWindow (pei->hSep1, IsWindowEnabled (hElapsed));
222 EnableWindow (pei->hMinutes, IsWindowEnabled (hElapsed));
223 EnableWindow (pei->hSep2, IsWindowEnabled (hElapsed));
224 EnableWindow (pei->hSeconds, IsWindowEnabled (hElapsed));
225 EnableWindow (pei->hSpinner, IsWindowEnabled (hElapsed));
227 RECT rElapsed;
228 GetRectInParent (hElapsed, &rElapsed);
229 InvalidateRect (GetParent(hElapsed), &rElapsed, TRUE);
230 UpdateWindow (GetParent(hElapsed));
231 break;
233 case WM_SYSCHAR:
234 case WM_CHAR:
235 switch (wp)
237 case VK_UP:
238 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_LINEUP, (LPARAM)pei->hSpinner);
239 break;
241 case VK_DOWN:
242 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_LINEDOWN, (LPARAM)pei->hSpinner);
243 break;
245 case VK_PRIOR:
246 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_PAGEUP, (LPARAM)pei->hSpinner);
247 break;
249 case VK_NEXT:
250 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_PAGEDOWN, (LPARAM)pei->hSpinner);
251 break;
253 case VK_HOME:
254 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_TOP, (LPARAM)pei->hSpinner);
255 break;
257 case VK_END:
258 PostMessage (GetParent(pei->hSpinner), WM_VSCROLL, SB_BOTTOM, (LPARAM)pei->hSpinner);
259 break;
261 break;
263 case ELM_GETRANGE:
264 return Elapsed_OnGetRange (pei, wp, lp);
266 case ELM_SETRANGE:
267 return Elapsed_OnSetRange (pei, wp, lp);
269 case ELM_GETTIME:
270 return Elapsed_OnGetTime (pei, wp, lp);
272 case ELM_SETTIME:
273 return Elapsed_OnSetTime (pei, wp, lp);
277 return DefWindowProc (hElapsed, msg, wp, lp);
281 void Elapsed_OnCreate (ElapsedInfo *pei)
283 Subclass_AddHook (GetParent(pei->hElapsed), ElapsedDlgProc);
285 TCHAR szTimeSep[ cchRESOURCE ];
286 if (!GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szTimeSep, cchRESOURCE))
287 lstrcpy (szTimeSep, TEXT(":"));
289 RECT rElapsed;
290 GetClientRect (pei->hElapsed, &rElapsed);
292 POINT ptElapsed = {0,0};
293 ClientToScreen (pei->hElapsed, &ptElapsed);
294 ScreenToClient (GetParent (pei->hElapsed), &ptElapsed);
296 SIZE s88; // size of widest likely double-digit number
297 SIZE s888; // maximum width to which we'll go for second- and minute- fields
298 SIZE sTimeSep; // size of ":"
300 HDC hdc = GetDC (GetParent (pei->hElapsed));
301 GetTextExtentPoint (hdc, TEXT("88"), lstrlen(TEXT("88")), &s88);
302 GetTextExtentPoint (hdc, szTimeSep, lstrlen(szTimeSep), &sTimeSep);
303 ReleaseDC (GetParent (pei->hElapsed), hdc);
305 s888 = s88;
306 s888.cx = (LONG)( (double)(s88.cx) * 1.2 );
308 LONG cxNumbers = cxRECT(rElapsed) - (2 * sTimeSep.cx) - GetSystemMetrics (SM_CXVSCROLL);
309 LONG cxSeconds = min( max( cxNumbers/3, s88.cx ), s888.cx );
310 LONG cxMinutes = min( max( cxNumbers/3, s88.cx ), s888.cx );
311 LONG cxHours = cxNumbers - cxSeconds - cxMinutes;
312 LONG yy = ptElapsed.y;
313 LONG cy = cyRECT(rElapsed);
315 pei->idHours = 100+NextControlID (GetParent (pei->hElapsed));
316 pei->hHours = CreateWindow (
317 TEXT("EDIT"),
318 TEXT(""),
319 WS_CHILD | WS_TABSTOP | ES_RIGHT | ES_NUMBER,
320 ptElapsed.x, yy, cxHours, cy,
321 GetParent(pei->hElapsed),
322 (HMENU)pei->idHours,
323 THIS_HINST,
326 pei->hSep1 = CreateWindow (
327 TEXT("STATIC"),
328 szTimeSep,
329 WS_CHILD,
330 ptElapsed.x + cxHours, yy, sTimeSep.cx, cy,
331 GetParent(pei->hElapsed),
332 (HMENU)-1,
333 THIS_HINST,
336 pei->idMinutes = 100+NextControlID (GetParent (pei->hElapsed));
337 pei->hMinutes = CreateWindow (
338 TEXT("EDIT"),
339 TEXT(""),
340 WS_CHILD | WS_TABSTOP | ES_RIGHT | ES_NUMBER,
341 ptElapsed.x + cxHours + sTimeSep.cx, yy, cxMinutes, cy,
342 GetParent(pei->hElapsed),
343 (HMENU)pei->idMinutes,
344 THIS_HINST,
347 pei->hSep2 = CreateWindow (
348 TEXT("STATIC"),
349 szTimeSep,
350 WS_CHILD,
351 ptElapsed.x + cxHours + cxMinutes + sTimeSep.cx, yy, sTimeSep.cx, cy,
352 GetParent(pei->hElapsed),
353 (HMENU)-1,
354 THIS_HINST,
357 pei->idSeconds = 100+NextControlID (GetParent (pei->hElapsed));
358 pei->hSeconds = CreateWindow (
359 TEXT("EDIT"),
360 TEXT(""),
361 WS_CHILD | WS_TABSTOP | ES_RIGHT | ES_NUMBER,
362 ptElapsed.x + cxHours + cxMinutes + 2 * sTimeSep.cx, yy, cxSeconds, cy,
363 GetParent(pei->hElapsed),
364 (HMENU)pei->idSeconds,
365 THIS_HINST,
368 Subclass_AddHook (pei->hHours, ElapsedEditProc);
369 Subclass_AddHook (pei->hMinutes, ElapsedEditProc);
370 Subclass_AddHook (pei->hSeconds, ElapsedEditProc);
372 HFONT hf = (HFONT)SendMessage (GetParent (pei->hElapsed), WM_GETFONT, 0, 0);
373 SendMessage (pei->hHours, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
374 SendMessage (pei->hSep1, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
375 SendMessage (pei->hMinutes, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
376 SendMessage (pei->hSep2, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
377 SendMessage (pei->hSeconds, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
379 EnableWindow (pei->hHours, IsWindowEnabled (pei->hElapsed));
380 EnableWindow (pei->hSep1, IsWindowEnabled (pei->hElapsed));
381 EnableWindow (pei->hMinutes, IsWindowEnabled (pei->hElapsed));
382 EnableWindow (pei->hSep2, IsWindowEnabled (pei->hElapsed));
383 EnableWindow (pei->hSeconds, IsWindowEnabled (pei->hElapsed));
385 ShowWindow (pei->hHours, TRUE);
386 ShowWindow (pei->hSep1, TRUE);
387 ShowWindow (pei->hMinutes, TRUE);
388 ShowWindow (pei->hSep2, TRUE);
389 ShowWindow (pei->hSeconds, TRUE);
391 RECT rWindow;
392 GetWindowRect (pei->hElapsed, &rWindow);
393 rWindow.right += (cxHours + cxMinutes + cxSeconds + 2 * sTimeSep.cx) - cxRECT(rElapsed);
395 SetWindowPos (pei->hElapsed, NULL, 0, 0, cxRECT(rWindow), cyRECT(rWindow),
396 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
398 SET_ELAPSED_TIME(&pei->timeMin, 0, 0, 0);
399 SET_ELAPSED_TIME(&pei->timeMax, 24, 0, 0);
401 Elapsed_Edit_OnEnforceRange (pei, pei->hHours);
402 Elapsed_Edit_OnEnforceRange (pei, pei->hMinutes);
403 Elapsed_Edit_OnEnforceRange (pei, pei->hSeconds);
405 Elapsed_Edit_OnSetFocus (pei, pei->hHours);
407 pei->fCanCallBack = TRUE;
411 void Elapsed_OnDestroy (ElapsedInfo *pei)
413 Subclass_RemoveHook (GetParent(pei->hElapsed), ElapsedDlgProc);
414 pei->hElapsed = NULL;
418 void Elapsed_OnButtonDown (ElapsedInfo *pei, UINT msg, WPARAM wp, LPARAM lp)
420 DWORD dw = GetMessagePos();
421 POINT pt;
422 pt.x = LOWORD(dw);
423 pt.y = HIWORD(dw); // in screen coordinates
425 RECT rTarget;
426 HWND hTarget = 0;
428 GetWindowRect (pei->hHours, &rTarget);
429 if (PtInRect (&rTarget, pt))
430 hTarget = pei->hHours;
432 GetWindowRect (pei->hMinutes, &rTarget);
433 if (PtInRect (&rTarget, pt))
434 hTarget = pei->hMinutes;
436 GetWindowRect (pei->hSeconds, &rTarget);
437 if (PtInRect (&rTarget, pt))
438 hTarget = pei->hSeconds;
440 if (hTarget != 0)
442 PostMessage (hTarget, msg, wp, lp);
447 BOOL Elapsed_OnGetRange (ElapsedInfo *pei, WPARAM wp, LPARAM lp)
449 SYSTEMTIME *ptimeMin = (SYSTEMTIME*)wp;
450 SYSTEMTIME *ptimeMax = (SYSTEMTIME*)lp;
452 *ptimeMin = pei->timeMin;
453 *ptimeMax = pei->timeMax;
454 return TRUE;
458 BOOL Elapsed_OnSetRange (ElapsedInfo *pei, WPARAM wp, LPARAM lp)
460 SYSTEMTIME *ptimeMin = (SYSTEMTIME*)wp;
461 SYSTEMTIME *ptimeMax = (SYSTEMTIME*)lp;
463 pei->timeMin = *ptimeMin;
464 pei->timeMax = *ptimeMax;
466 Elapsed_Edit_OnEnforceRange (pei, pei->hHours);
467 Elapsed_Edit_OnEnforceRange (pei, pei->hMinutes);
468 Elapsed_Edit_OnEnforceRange (pei, pei->hSeconds);
470 return TRUE;
474 BOOL Elapsed_OnGetTime (ElapsedInfo *pei, WPARAM wp, LPARAM lp)
476 SYSTEMTIME *ptime = (SYSTEMTIME*)lp;
477 *ptime = pei->timeNow;
478 return TRUE;
482 BOOL Elapsed_OnSetTime (ElapsedInfo *pei, WPARAM wp, LPARAM lp)
484 SYSTEMTIME *ptime = (SYSTEMTIME*)lp;
485 pei->timeNow = *ptime;
486 Elapsed_Edit_SetText (pei, pei->hHours);
487 Elapsed_Edit_SetText (pei, pei->hMinutes);
488 Elapsed_Edit_SetText (pei, pei->hSeconds);
489 return TRUE;
493 HRESULT CALLBACK ElapsedDlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
495 PVOID oldProc = Subclass_FindNextHook (hDlg, ElapsedDlgProc);
496 size_t iElapsed;
498 switch (msg)
500 case WM_CTLCOLOREDIT:
501 case WM_CTLCOLORSTATIC:
502 for (iElapsed = 0; iElapsed < cElapsed; ++iElapsed)
504 if (aElapsed[ iElapsed ].hElapsed == NULL)
505 continue;
506 if ( (aElapsed[ iElapsed ].hHours == (HWND)lp) ||
507 (aElapsed[ iElapsed ].hSep1 == (HWND)lp) ||
508 (aElapsed[ iElapsed ].hMinutes == (HWND)lp) ||
509 (aElapsed[ iElapsed ].hSep2 == (HWND)lp) ||
510 (aElapsed[ iElapsed ].hSeconds == (HWND)lp) )
512 COLORREF clr;
513 if (IsWindowEnabled (aElapsed[ iElapsed ].hElapsed))
514 clr = GetSysColor (COLOR_WINDOW);
515 else
516 clr = GetSysColor (COLOR_BTNFACE);
517 SetBkColor ((HDC)wp, clr);
518 return (HRESULT)(INT_PTR)CreateSolidBrush (clr);
521 break;
523 case WM_COMMAND:
524 for (iElapsed = 0; iElapsed < cElapsed; ++iElapsed)
526 if (aElapsed[ iElapsed ].hElapsed == NULL)
527 continue;
528 if ( (aElapsed[ iElapsed ].idHours == LOWORD(wp)) ||
529 (aElapsed[ iElapsed ].idMinutes == LOWORD(wp)) ||
530 (aElapsed[ iElapsed ].idSeconds == LOWORD(wp)) )
532 if (HIWORD(wp) == SPN_UPDATE)
534 Elapsed_Edit_OnUpdate (&aElapsed[ iElapsed ], GetDlgItem (hDlg, LOWORD(wp)), (DWORD)lp);
536 break;
539 break;
542 if (oldProc)
543 return CallWindowProc ((WNDPROC)oldProc, hDlg, msg, wp, lp);
544 else
545 return DefWindowProc (hDlg, msg, wp, lp);
549 HRESULT CALLBACK ElapsedEditProc (HWND hEdit, UINT msg, WPARAM wp, LPARAM lp)
551 ElapsedInfo *pei = NULL;
553 EnterCriticalSection (&csElapsed);
555 for (size_t iElapsed = 0; !pei && iElapsed < cElapsed; ++iElapsed)
557 if ( (aElapsed[ iElapsed ].hHours == hEdit) ||
558 (aElapsed[ iElapsed ].hMinutes == hEdit) ||
559 (aElapsed[ iElapsed ].hSeconds == hEdit) )
561 pei = &aElapsed[ iElapsed ];
565 LeaveCriticalSection (&csElapsed);
567 if (pei)
569 switch (msg)
571 case WM_SETFOCUS:
572 Elapsed_Edit_OnSetFocus (pei, hEdit);
573 break;
577 PVOID oldProc = Subclass_FindNextHook (hEdit, ElapsedEditProc);
578 if (oldProc)
579 return CallWindowProc ((WNDPROC)oldProc, hEdit, msg, wp, lp);
580 else
581 return DefWindowProc (hEdit, msg, wp, lp);
585 void Elapsed_Edit_OnSetFocus (ElapsedInfo *pei, HWND hEdit)
587 pei->fCanCallBack --;
589 RECT rSpinner;
590 GetRectInParent (pei->hElapsed, &rSpinner);
591 rSpinner.left = rSpinner.right;
592 rSpinner.right = rSpinner.left + GetSystemMetrics (SM_CXVSCROLL);
593 rSpinner.bottom -= 2; // just like Win95 does
595 DWORD dwMin;
596 DWORD dwPos;
597 DWORD dwMax;
598 Elapsed_Edit_GetSpinnerRange (pei, hEdit, &dwMin, &dwPos, &dwMax);
600 CreateSpinner (hEdit, 10, FALSE, dwMin, dwPos, dwMax, &rSpinner);
601 if (pei->hSpinner)
602 DestroyWindow (pei->hSpinner);
604 if (hEdit == pei->hHours)
605 SP_SetFormat (hEdit, TEXT("%lu"));
606 else
607 SP_SetFormat (hEdit, TEXT("%02lu"));
609 pei->hSpinner = SP_GetSpinner (hEdit);
610 pei->hSpinnerBuddy = hEdit;
612 SendMessage (hEdit, EM_SETSEL, (WPARAM)0, (LPARAM)-1); // select all
614 pei->fCanCallBack ++;
618 void Elapsed_Edit_GetSpinnerRange (ElapsedInfo *pei, HWND hEdit, DWORD *pdwMin, DWORD *pdwNow, DWORD *pdwMax)
620 if (hEdit == pei->hHours)
622 *pdwMin = pei->timeMin.wHour + pei->timeMin.wDay * 24;
623 *pdwNow = pei->timeNow.wHour + pei->timeNow.wDay * 24;
624 *pdwMax = pei->timeMax.wHour + pei->timeMax.wDay * 24;
626 else if (hEdit == pei->hMinutes)
628 if ( (pei->timeNow.wDay == pei->timeMin.wDay) &&
629 (pei->timeNow.wHour == pei->timeMin.wHour) )
630 *pdwMin = pei->timeMin.wMinute;
631 else
632 *pdwMin = 0;
634 *pdwNow = pei->timeNow.wMinute;
636 if ( (pei->timeNow.wDay == pei->timeMax.wDay) &&
637 (pei->timeNow.wHour == pei->timeMax.wHour) )
638 *pdwMax = pei->timeMax.wMinute;
639 else
640 *pdwMax = 59;
642 else if (hEdit == pei->hSeconds)
644 if ( (pei->timeNow.wDay == pei->timeMin.wDay) &&
645 (pei->timeNow.wHour == pei->timeMin.wHour) &&
646 (pei->timeNow.wMinute == pei->timeMin.wMinute) )
647 *pdwMin = pei->timeMin.wSecond;
648 else
649 *pdwMin = 0;
651 *pdwNow = pei->timeNow.wSecond;
653 if ( (pei->timeNow.wDay == pei->timeMax.wDay) &&
654 (pei->timeNow.wHour == pei->timeMax.wHour) &&
655 (pei->timeNow.wMinute == pei->timeMax.wMinute) )
656 *pdwMax = pei->timeMax.wSecond;
657 else
658 *pdwMax = 59;
663 void Elapsed_Edit_OnUpdate (ElapsedInfo *pei, HWND hEdit, DWORD dwNew)
665 DWORD dwMin;
666 DWORD dwNow;
667 DWORD dwMax;
669 Elapsed_Edit_GetSpinnerRange (pei, hEdit, &dwMin, &dwNow, &dwMax);
671 dwNow = limit( dwMin, dwNew, dwMax );
673 if (hEdit == pei->hHours)
675 pei->timeNow.wDay = (WORD)dwNow / 24;
676 pei->timeNow.wHour = (WORD)dwNow % 24;
677 Elapsed_Edit_OnEnforceRange (pei, pei->hMinutes);
678 Elapsed_Edit_OnEnforceRange (pei, pei->hSeconds);
680 else if (hEdit == pei->hMinutes)
682 pei->timeNow.wMinute = (WORD)dwNow;
683 Elapsed_Edit_OnEnforceRange (pei, pei->hSeconds);
685 else if (hEdit == pei->hSeconds)
687 pei->timeNow.wSecond = (WORD)dwNow;
690 SYSTEMTIME st = pei->timeNow;
691 Elapsed_SendCallback (pei, ELN_UPDATE, (LPARAM)&st);
695 void Elapsed_Edit_OnEnforceRange (ElapsedInfo *pei, HWND hEdit)
697 DWORD dwMin;
698 DWORD dwNow;
699 DWORD dwMax;
700 Elapsed_Edit_GetSpinnerRange (pei, hEdit, &dwMin, &dwNow, &dwMax);
702 if (!inlimit( dwMin, dwNow, dwMax ))
704 dwNow = limit( dwMin, dwNow, dwMax );
706 if (hEdit == pei->hHours)
708 pei->timeNow.wDay = (WORD)dwNow / 24;
709 pei->timeNow.wHour = (WORD)dwNow % 24;
711 else if (hEdit == pei->hMinutes)
713 pei->timeNow.wMinute = (WORD)dwNow;
715 else if (hEdit == pei->hSeconds)
717 pei->timeNow.wSecond = (WORD)dwNow;
720 if (pei->hSpinnerBuddy == hEdit)
721 SP_SetRange (hEdit, dwMin, dwMax);
722 Elapsed_Edit_SetText (pei, hEdit);
724 else if (pei->hSpinnerBuddy == hEdit)
726 SP_SetRange (hEdit, dwMin, dwMax);
731 void Elapsed_Edit_SetText (ElapsedInfo *pei, HWND hEdit)
733 DWORD dwMin;
734 DWORD dwNow;
735 DWORD dwMax;
736 Elapsed_Edit_GetSpinnerRange (pei, hEdit, &dwMin, &dwNow, &dwMax);
738 if (pei->hSpinnerBuddy == hEdit)
740 SP_SetPos (hEdit, dwNow);
742 else
744 TCHAR szText[ cchRESOURCE ];
746 if (hEdit == pei->hHours)
747 wsprintf (szText, TEXT("%lu"), dwNow);
748 else
749 wsprintf (szText, TEXT("%02lu"), dwNow);
751 SetWindowText (hEdit, szText);