home *** CD-ROM | disk | FTP | other *** search
- #include <LowMem.h>
- #include <ControlStrip.h>
- #include <DCon.h>
-
- #include "DockStrip.h"
-
-
- static Boolean moduleHandlesIdleDelay = true;
- static RgnHandle wideRgn = nil;
- static RgnHandle alreadySaved = nil;
-
- unsigned long BeforeModule (
- SDockStripGlobals* globals,
- UInt32 index,
- unsigned long message,
- Handle prefsHandle,
- Rect* statusRect,
- GrafPtr statusPort,
- Boolean* runModule)
- {
- UInt32 iindex;
-
- if (wideRgn == nil) {
- Rect rect = {-32768, -32768, 32767, 32767};
- wideRgn = NewRgn ();
- RectRgn (wideRgn, &rect);
- }
-
- globals -> someRunning = false;
- for (iindex = 0; iindex < StubListSize; iindex++) {
- if (globals -> moduleList [iindex].stub.handle != nil) {
- if ((globals -> moduleList [iindex].goingUp) || (globals -> moduleList [iindex].amountWider != 0)) {
- globals -> someRunning = true;
- break;
- }
- }
- }
-
- if (globals -> lastUpdate + 60 < LMGetTicks ()) {
- globals -> needUpdate = true;
- }
-
- if (globals -> someRunning) {
- globals -> needUpdate = true;
- } else if (globals -> needUpdate) {
- GrafPtr srcP = (GrafPtr) &globals -> ourPort;
- GrafPtr destP = (GrafPtr) globals -> updatePort;
- Rect src = {-200, 0, 0, 1024};
- LocalToGlobal (&topLeft (src));
- LocalToGlobal (&botRight (src));
-
- CopyRgn (wideRgn, destP -> visRgn);
- SetClip (wideRgn);
- SetPort (destP);
-
- dprintf ("Noone running - updating\n");
-
- CopyBits (&srcP -> portBits, &destP -> portBits, &src, &src, srcCopy, nil);
- globals -> needUpdate = false;
- globals -> lastUpdate = LMGetTicks ();
- }
-
- SetPort ((GrafPtr) globals -> offscreenGWorld);
-
- if (message == sdevDrawStatus) {
- Rect erase = *statusRect;
- RGBColor saveBack;
- RGBColor gray = {0xC000, 0xC000, 0xC000};
- GetBackColor (&saveBack);
- RGBBackColor (&gray);
-
- InsetRect (&erase, -10, -10);
- EraseRect (&erase);
- RGBBackColor (&saveBack);
- // fix the rect
- statusRect->right -= globals -> moduleList [index].amountWider;
- }
-
- if (message == 9) {
- // dprintf ("Handling message 9 for %d\n", index);
- *runModule = false;
- return 1;
- }
-
- *runModule = true;
- return 0;
- }
-
-
- long AfterModule (
- SDockStripGlobals* globals,
- UInt32 index,
- unsigned long message,
- Handle prefsHandle,
- Rect* statusRect,
- GrafPtr statusPort,
- long result)
- {
-
- // if (index <= 4) {
- // dprintf ("Message %d to %d: returned %d, ", message, index, result);
- // }
-
- switch (message) {
- case sdevGetDisplayWidth: {
- Boolean newGoingUp;
- Point mouse = LMGetMouseLocation ();
- Rect iconRect = (*(statusPort -> clipRgn)) -> rgnBBox;
-
- if (result <= 0)
- result = 25;
-
- CallSetPortProc (globals -> saveSetPort, statusPort);
- // SetPort (statusPort);
- GlobalToLocal (&mouse);
- iconRect.top -= iconRect.right - iconRect.left;
- iconRect.bottom += iconRect.right - iconRect.left;
- newGoingUp = PtInRect (mouse, &iconRect);
- /* if (newGoingUp)
- result *= 2;*/
- if (!globals -> moduleList [index].goingUp && newGoingUp)
- globals -> moduleList [index].startingUp = true;
- else
- globals -> moduleList [index].startingUp = false;
- globals -> moduleList [index].goingUp = newGoingUp;
-
- if (globals -> moduleList [index].goingUp) {
- if ((globals -> moduleList [index].amountWider + result) < (result * kMagnificationFactor)) {
- int difference = (result * kMagnificationFactor) -
- (globals -> moduleList [index].amountWider + result);
- int increment = difference > 1 ? difference/2 : 1;
- globals -> moduleList [index].amountWider += increment;
- }
- } else {
- if (globals -> moduleList [index].amountWider > 0) {
- int difference = (result * kMagnificationFactor) -
- (globals -> moduleList [index].amountWider + result);
- int increment = difference > 1 ? difference/2 : 1;
-
- globals -> moduleList [index].amountWider -= increment;
- if (globals -> moduleList [index].amountWider < 0)
- globals -> moduleList [index].amountWider = 0;
- }
- }
- result += globals -> moduleList [index].amountWider;
-
- /* Bogon strip returns negative widths */
- globals -> moduleList [index].width = result;
-
- break;
- }
-
- case 9:
- dprintf ("Index %d got message 9 and returned %d\n", index, result);
- break;
-
- case sdevFeatures:
- if ((result & 0x10) == 0) {
- result |= 0x10;
- moduleHandlesIdleDelay = false;
- }
- break;
-
- case sdevPeriodicTickle:
- result |= 1 << sdevResizeDisplay;
- break;
-
- case sdevDrawStatus: {
- Rect srcRect = *statusRect;
- Rect destRect = *statusRect;
- Rect updateRect;
- Rect curRect;
-
- GrafPtr savePort;
- GrafPtr srcPort;
- GrafPtr destPort;
-
- // RgnHandle destRgn = NewRgn (), saveRgn = NewRgn (), updateRgn = NewRgn (), justAboveRgn = NewRgn ();
- // Rect justAbove;
-
- GetPort (&savePort);
-
- srcRect = *statusRect;
- destRect = *statusRect;
-
- destRect.right += globals -> moduleList [index].amountWider;
- destRect.top = destRect.bottom - (srcRect.bottom - srcRect.top) * (destRect.right - destRect.left) / (srcRect.right - srcRect.left);
-
- // justAbove = destRect;
- // justAbove.bottom = 0;
-
- updateRect = destRect;
- updateRect.bottom = 0;
- updateRect.left -= 2;
- updateRect.right += 40;
- updateRect.top -= 40;
-
- CallSetPortProc (globals -> saveSetPort, statusPort);
- LocalToGlobal (&topLeft(destRect));
- LocalToGlobal (&botRight(destRect));
- LocalToGlobal (&topLeft(updateRect));
- LocalToGlobal (&botRight(updateRect));
- // LocalToGlobal (&((Point*)(&justAbove))[0]);
- // LocalToGlobal (&((Point*)(&justAbove))[1]);
-
- /* Before drawing the bigger status to the screen, copy out the data already there */
- /* if (alreadySaved == nil) {
- alreadySaved = NewRgn ();
- }
- if (globals -> moduleList [index].startingUp) {
- RectRgn (alreadySaved, &destRect);
- }
-
- RectRgn (destRgn, &destRect);
- RectRgn (justAboveRgn, &justAbove);
- DiffRgn (destRgn, alreadySaved, saveRgn);
- SectRgn (saveRgn, justAboveRgn, saveRgn);
-
- srcPort = (GrafPtr) &globals -> ourPort;
- destPort = (GrafPtr) globals -> updatePort;
- CallSetPortProc (globals -> saveSetPort, destPort);
- CopyRgn (wideRgn, destPort -> visRgn);
- SetClip (wideRgn);
- CopyBits (&srcPort -> portBits, &destPort -> portBits, &(*saveRgn)->rgnBBox, &(*saveRgn)->rgnBBox, srcCopy, saveRgn);
-
- UnionRgn (alreadySaved, saveRgn, alreadySaved);
-
- DiffRgn (alreadySaved, destRgn, updateRgn);
- SectRgn (updateRgn, justAboveRgn, updateRgn);
-
- destPort = (GrafPtr) &globals -> ourPort;
- srcPort = (GrafPtr) globals -> updatePort;
- CallSetPortProc (globals -> saveSetPort, destPort);
- CopyRgn (wideRgn, destPort -> visRgn);
- SetClip (wideRgn);
- CopyBits (&srcPort -> portBits, &destPort -> portBits, &(*updateRgn)->rgnBBox, &(*updateRgn)->rgnBBox, srcCopy, updateRgn);
-
- DisposeRgn (destRgn);
- DisposeRgn (saveRgn);
- DisposeRgn (updateRgn);
- DisposeRgn (justAboveRgn);*/
-
- srcPort = (GrafPtr) globals -> updatePort;
- destPort = (GrafPtr) &globals -> ourPort;
- CallSetPortProc (globals -> saveSetPort, destPort);
- CopyRgn (wideRgn, destPort -> visRgn);
- SetClip (wideRgn);
- CopyBits (&srcPort -> portBits, &destPort -> portBits, &updateRect, &updateRect, srcCopy, nil);
-
- /* Draw the updated frob */
- srcPort = (GrafPtr) globals -> offscreenGWorld;
- destPort = (GrafPtr) &globals -> ourPort;
- CallSetPortProc (globals -> saveSetPort, destPort);
- CopyBits (&srcPort -> portBits, &destPort -> portBits, &srcRect, &destRect, srcCopy, nil);
- SetPort (savePort);
-
- break;
- }
- }
-
- // if (index <= 4){
- // dprintf ("actually returned %d\n", result);
- // }
-
- return result;
- }
-