home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: IdleTasks.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* This function is called when a null event is received. Do appropriate tasks
- ** for null event situations, such as handling balloon help for window. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DoIdleTasks(EventRecord *event)
- {
- #ifndef __MWERKS__
- #pragma unused (event)
- #endif
-
- EventRecord evt;
- WindowPtr window;
- FileRecHndl frHndl;
- TreeObjHndl root;
- ControlHandle ctl;
- short lr, rs;
- long timer, tick, t1, t2;
- Handle snd;
- KeyMap kk;
- short mm;
-
- if (TSMTEAvailable()) TSMEvent(event);
-
- GetKeys(kk);
- mm = (kk[1] & 0x8000) ? (cmdKey ) : 0;
- mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
- mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
- mm |= (kk[1] & 0x0001) ? (shiftKey ) : 0;
- evt.what = nullEvent; /* Make valid null event, with modifiers. */
- evt.modifiers = mm;
-
- IsCtlEvent(nil, &evt, nil, nil);
-
- /* •••• All of the code below here was added for pbClock. */
-
- for (window = nil; ((window = GetNextWindow(window, 'pbCk')) != nil);) {
- if (!ClocksPaused(window)) {
- frHndl = (FileRecHndl)GetWRefCon(window);
- root = (*frHndl)->d.doc.root;
- timer = (*frHndl)->d.doc.timer;
- if (!timer) {
- (*frHndl)->d.doc.timer = TickCount();
- continue;
- }
- tick = ((*frHndl)->d.doc.timer = TickCount()) - timer;
- if (tick < 1) continue;
- rs = mDerefRoot(root)->rightStart;
- if (rs > -1) {
- if (mDerefRoot(root)->timeRemaining[0]) {
- if (mDerefRoot(root)->timeRemaining[1]) {
- lr = mDerefRoot(root)->numMoves[0];
- lr += mDerefRoot(root)->numMoves[1];
- lr += rs;
- lr &= 0x01;
- t1 = mDerefRoot(root)->timeRemaining[lr];
- t2 = t1 - tick;
- if (t2 < 60) t2 = 0;
- mDerefRoot(root)->timeRemaining[lr] = t2;
- if ((t1 / 60) != (t2 / 60)) {
- DrawClock(frHndl, lr);
- PostEvent(nullEvent, 0L); /* Don't let PB100 rest. */
- }
- if (!t2) {
- snd = GetResource('snd ', 500);
- if (snd) SndPlay(nil, snd, false);
- CNum2Ctl(window, kTabButton, &ctl);
- UseControlStyle(ctl);
- HiliteControl(ctl, 255);
- UseControlStyle(nil);
- CNum2Ctl(window, kReturnButton, &ctl);
- UseControlStyle(ctl);
- HiliteControl(ctl, 255);
- UseControlStyle(nil);
- CNum2Ctl(window, kPauseClocks, &ctl);
- UseControlStyle(ctl);
- HiliteControl(ctl, 255);
- UseControlStyle(nil);
- }
- }
- }
- }
- }
- }
- }
-
-
-
-