/* Based on: ** BackgroundeR XCMD ** Written by Brendon Cheves and Jeff Winters ** Copyright (c) 1994 California State University, Long Beach */ /* Chopped and renamed to Cover.XCMD ** by Andrew Boyer ** aboyer.web@tobark.org ** December, 1999 */ /* It now does only black. I wanted to keep it simple. If you were using it for another ** color and want to be able to do that, let me know; I can put it back in. ** ** It is also now multiple-display aware - it blacks every pixel of every attached GDevice. ** It ignores the menu bar and the control strip. */ /* Testing: ** 12/15/99 Works on single-monitor and dual-monitor PowerPC's under MacOS 9. ** 12/15/99 Works on single-monitor PowerPC's under MacOS 8.1 & 8.6 ** 12/16/99 Works on single-monitor 68k's under MacOS 8.1 */ #include #include #include /* ** Prototypes */ void theXCMD (XCmdPtr paramPtr); void Draw( WindowPtr myWindowPtr ); void Fail(XCmdPtr paramPtr,char *str); // Return debug string to HyperCard /* ************ Main ************ */ pascal void main( XCmdPtr paramPtr ) { #ifndef powerc long oldA4 = SetCurrentA4(); //A4 must be set up for globals, strings, and inter-segment calls #endif theXCMD( paramPtr ); /* entry point; call the xcmd routine */ #ifndef powerc SetA4( oldA4 ); #endif } /* ************ theXCMD ************ */ void theXCMD ( XCmdPtr paramPtr ) { WindowPtr HCWinPtr, myWinPtr; XWEventInfoPtr myXWindowPtr; Rect myRect; GrafPtr origPort; GDHandle theDevice; // Check for proper number of parameters if (paramPtr->paramCount > 0) { Fail(paramPtr,"ERROR, No parameters required."); paramPtr->passFlag = 0; // Don't pass this command up HyperCard's hierarchy return; } // Must be an event... else if (paramPtr->paramCount == -1) { myXWindowPtr = (XWEventInfoPtr)paramPtr->params[0]; GetPort( &origPort ); SetPort( myXWindowPtr->eventWindow ); switch( myXWindowPtr->event.what ) { case xCursorWithin: // Set the cursor to the arrow // InitCursor(); // Disabled because I think it might be a processor drain break; case xOpenEvt: case updateEvt: // Draw the black window Draw( myXWindowPtr->eventWindow ); break; case xCloseEvt: // Set passFlag to true to allow HC to close this window paramPtr->passFlag = 1; break; default: break; } SetPort( origPort ); } else { // Remember the front-most window HCWinPtr = FrontDocWindow( paramPtr ); if ( !HCWinPtr ) { Fail(paramPtr,"Error, no window is open."); return; } theDevice = GetDeviceList(); while ( theDevice ) { myRect = (*theDevice)->gdRect; myWinPtr = NewXWindow( paramPtr, &myRect, "\pxCover", 1, plainDBox, 1, 0 ); Draw( myWinPtr ); theDevice = GetNextDevice( theDevice ); } // Don't pass this command up HyperCard's hierarchy paramPtr->passFlag = 0; // Restore the front-most window SelectWindow ( HCWinPtr ); } } /* ************ Draw ************ */ void Draw( WindowPtr myWinPtr ) { Rect bgRect; RGBColor myColor; GrafPtr origPort; GetPort( &origPort ); SetPort( myWinPtr ); bgRect = myWinPtr->portRect; myColor.red = 0; // Make the black myColor.green = 0; myColor.blue = 0; RGBForeColor( &myColor ); // Set foreground color to black BeginUpdate( myWinPtr ); PaintRect( &bgRect ); // Fill with black EndUpdate( myWinPtr ); ValidRect( &bgRect ); // Don't update background SetPort( origPort ); } /* ************ Fail ************ */ void Fail( XCmdPtr paramPtr, char *str ) { Handle newHndl = NewHandle( (long)strlen(str) + 1 ); strcpy( (char *)*newHndl, str ); paramPtr->returnValue = newHndl; return; }