home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-11 | 4.1 KB | 216 lines | [TEXT/MPCC] |
- // LifeFile.c
- // Handle the file operation of Mike's Life
- // Copyright ©1995 Michael D. Crawford. All Rights Reserved.
- // 11 Jun 95 Mike Crawford crawford@scruznet.com
- //
- // Revision History:
- // 11 Jun 95 MDC New today
-
- #include <QDOffScreen.h>
- #include "LifeFile.h"
- #include "Control.h"
- #include "LifeModules.h"
-
- //#ifndef kCurrentISA // I just have ThinkC 6
- //#include <LoMem.h>
- //#define LMGetMBarHeight() MBarHeight
- //#endif
-
- #define rLifeWindowID 128
-
- WindowPtr GetLifeWindow( long height, long width, StringPtr title );
- Boolean GetDimensions( long *heightPtr, long *widthPtr, short *modNumPtr );
-
- OSErr DoNewWindow( void )
- {
- long height;
- long width;
- Boolean isOK;
- WindowPtr win;
- tLifeWorldPtr worldPtr;
- OSErr err;
- GDHandle mainDev;
- short moduleNumber;
- tLongRect boundsRect;
-
-
- worldPtr = NewLifeWorld();
- if (!worldPtr)
- return memFullErr;
-
- isOK = GetDimensions( &height, &width, &moduleNumber );
-
- // STUB We can't do more than -32767 to 32768 because of QuickDraw. Later we'll do
- // sparse matrices and so on, to increase the size.
-
- if ( height > 32768L )
- height = 32768L;
-
- if ( width > 32768L )
- width = 32768L;
-
- win = GetLifeWindow( height, width, "\pUntitled" );
- if ( !win )
- return memFullErr;
-
- worldPtr->win = win;
- worldPtr->height = height;
- worldPtr->width = width;
-
- worldPtr->lifeModuleProcs = GetModuleProcs( moduleNumber );
-
- err = AllocLifeWorld( worldPtr, height, width );
- if ( err ){
- DisposeWindow( win );
- FreeLifeWorld( worldPtr );
- return err;
- }
-
- boundsRect.left = 0;
- boundsRect.top = 0;
- boundsRect.right = width;
- boundsRect.bottom = height;
-
- // ClearCells( worldPtr, &boundsRect );
-
- SetPort( win );
-
- ShowWindow( win );
-
- return noErr;
- }
-
- void CloseLifeWindow( WindowPtr win )
- {
- tLifeWorldPtr worldPtr;
-
- worldPtr = WinToLifeWorld( win );
- if ( !worldPtr )
- return;
- /*
- DisposeWindow( worldPtr->win );
- DisposeGWorld( worldPtr->hip );
- DisposeGWorld( worldPtr->hop );
- */
- FreeLifeWorld( worldPtr );
-
- return;
- }
-
- WindowPtr GetLifeWindow( long height, long width, StringPtr title )
- {
- WindowPtr win;
- GDHandle mainDev;
- Rect r;
- short screenHeight;
- short screenWidth;
- short maxHeight;
- short maxWidth;
- short winHeight;
- short winWidth;
-
- win = GetNewWindow( rLifeWindowID, (WindowPtr)NULL, (WindowPtr)-1 );
- if ( !win )
- return (WindowPtr)NULL;
-
- // STUB add controls
-
- SetWTitle( win, title );
-
- // Peg to smaller of dimensions or screen size
- mainDev = GetMainDevice();
-
- r = (*mainDev)->gdRect;
-
- screenHeight = r.bottom - r.top;
- screenWidth = r.right - r.left;
-
- #define kScrollBarWidth 16
-
- maxHeight = screenHeight - LMGetMBarHeight() - kScrollBarWidth;
- maxWidth = screenWidth - kScrollBarWidth;
-
- winHeight = height < maxHeight? height : maxHeight;
- winWidth = width < maxWidth? width : maxWidth;
-
- winWidth += kScrollBarWidth;
- winHeight += kScrollBarWidth;
-
- SizeWindow( win, winWidth, winHeight, false );
-
- return win;
- }
-
- #define rDimensionDlgID 129
- enum{
- kDDOkButton = 1,
- kDDDefUser,
- kDDCancelButton,
- kDDPromptTitle,
- kDDHeightLabel,
- kDDWidthLabel,
- kDDHeightText,
- kDDWidthText
- };
-
- Boolean GetDimensions( long *heightPtr, long *widthPtr, short *modNumPtr )
- {
- DialogPtr dlg;
- Boolean result;
- Str255 valStr;
- Handle h;
- Rect r;
- short kind;
- short item;
-
- dlg = GetNewDialog( rDimensionDlgID, (DialogPtr)NULL, (WindowPtr)-1 );
- if ( !dlg )
- return false;
-
- // STUB Set user items
- // STUB Default dimensions to the main screen size, less borders
-
- SelIText( dlg, kDDHeightText, 0, 32000 );
-
- ShowWindow( dlg );
-
- do{
- ModalDialog( (ModalFilterUPP)NULL, &item );
- }while ( item != kDDOkButton && item != kDDCancelButton );
-
- result = false;
-
- if ( item == kDDOkButton ){
- result = true;
-
- GetDItem( dlg, kDDHeightText, &kind, &h, &r );
- GetIText( h, valStr );
- StringToNum( valStr, heightPtr );
-
- GetDItem( dlg, kDDWidthText, &kind, &h, &r );
- GetIText( h, valStr );
- StringToNum( valStr, widthPtr );
-
- *modNumPtr = 0; // STUB get this from popup menu state - note this is 0 based
- }
-
- DisposeDialog( dlg );
-
- return result;
- }
-
- OSErr DoSave( void )
- {
- WindowPtr win;
-
- win = FrontWindow();
-
- if ( !win )
- return noErr;
-
- // STUB save the file
-
- return noErr;
- }
-
-