home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / MacDP 1.3 / MacDP2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-31  |  22.4 KB  |  1,113 lines  |  [TEXT/CWIE]

  1. /*
  2.  * MacDP2.c
  3.  *
  4.  * (c)1990-1997 SPDsoft <MacSPD@ivo.cps.unizar.es>
  5.  * Part of a batch VTR Frame-By-Frame recorder
  6.  * Version 1.3
  7.  *
  8.  * Grupo de Informatica Grafica, CPSUZ
  9.  *
  10.  */
  11.  
  12.  
  13. #ifndef __QUICKDRAW__
  14.     /* if MacHeaders has been included, __QUICKDRAW__ should be defined */
  15. #    include <Types.h>
  16. #    include <Quickdraw.h>
  17. #    include <Fonts.h>
  18. #    include <Events.h>
  19. #    include <Menus.h>
  20. #    include <Windows.h>
  21. #    include <TextEdit.h>
  22. #    include <Dialogs.h>
  23. #    include <Packages.h>
  24. #    include <StandardFile.h>
  25. #    include <ToolUtils.h>
  26. #    ifdef THINK_C
  27. #        include <OSEvents.h>
  28. #        include <BDC.h>
  29. #    else /* MW C */
  30. #        include <TextUtils.h>
  31. #    endif
  32. #    include <Desk.h>
  33. #    include <SegLoad.h>
  34. #endif /* MacHeaders */
  35.  
  36. #ifndef THINK_C
  37. #    include <AppleEvents.h>
  38. #    include <GestaltEqu.h>
  39. #    include <Scrap.h>
  40. #endif
  41.  
  42. #include <PictUtil.h>
  43. #include <Packages.h>
  44. #include <ImageCompression.h>
  45. #ifdef THINK_C
  46. #    include <PrintTraps.h>
  47. #endif
  48. /*
  49.  * From HideMenuBar.c, Edgar Lee Apple Computer, Inc. Developer Technical Support, DTS
  50.  */
  51. #define MBarHeight (*((short *)0xbaa))
  52.  
  53. #include "MacDP2.h"
  54.  
  55. /*
  56.  * Prototypes
  57.  */
  58.  
  59. void InitTheMac(void);
  60. void FlushTheMac(void);
  61. void CatString( Str255 StrIO, Str255 Str );
  62.  
  63. extern PicHandle
  64. ConvertFromJFIF(StringPtr name,short originalFile, CWindowPtr window);
  65. extern PicHandle
  66. ConvertFromPict(StringPtr name,short originalFile,CWindowPtr window);
  67.  
  68. /*
  69.  * Constants
  70.  */
  71.  
  72. #define keyOrMouse mDownMask+keyDownMask
  73. #define NIL 0L
  74.  
  75. #define CopyString(a,b)        BlockMove(a, b, *(a) + 1 )
  76.  
  77.  
  78. /*
  79.  * Globals
  80.  */
  81.  
  82. TPrint        myTPrint;
  83. TPPrint        myTPPrint = &myTPrint;
  84. THPrint        ghPtrRec = &myTPPrint;
  85.  
  86. WindowPtr     gMyWindow = nil;
  87. Str63        gTheName = "\p File";
  88. Rect        PackORects[7];
  89. char        LastMonitorID=0;
  90. int            theMonitorID;
  91. Boolean        CanOpenJFIF = false;
  92.  
  93. static short    oldMBarHeight;
  94. static int        oldTop;
  95.  
  96. Boolean        quitting = false;
  97. #define        update                ( gMyWindow != nil )
  98. Boolean        HiddenMenu=false;
  99. Boolean        BlackBack=true;
  100.  
  101. MenuHandle            myMenus[4];
  102. static PicHandle    thePic=nil;
  103. HFileInfo            gpb;
  104. short                globalRef;
  105.  
  106. /*
  107.  * AE
  108.  */
  109. Boolean AppleEventsInstalled (void)
  110. {
  111.     OSErr err;
  112.     long  result;
  113.  
  114.     err = Gestalt (gestaltAppleEventsAttr, &result);
  115.     return (!err && ((result >> gestaltAppleEventsPresent) & 0x0001));
  116. }
  117.  
  118. OSErr MyGotRequiredParams (AppleEvent *theAppleEvent)
  119. {
  120.     DescType    returnedType;
  121.     Size    actualSize;
  122.     OSErr    err;
  123.  
  124.     err = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr,
  125.                                     typeWildCard, &returnedType, nil, 0,
  126.                                     &actualSize);
  127.     if (err == errAEDescNotFound)    // you got all the required parameters
  128.             return noErr;
  129.     else if (!err)                // you missed a required parameter
  130.             return errAEEventNotHandled;
  131.     else                        // the call to AEGetAttributePtr failed
  132.             return err;
  133. }
  134. /******************************************************************************/
  135.  
  136.  
  137. pascal OSErr  MyHandleODoc (AppleEvent *theAppleEvent, AppleEvent* reply, long
  138.                                                         handlerRefCon)
  139. {
  140. #pragma unused(reply)
  141. #pragma unused(handlerRefCon)
  142.  
  143.     FSSpec    myFSS;
  144.     AEDescList    docList;
  145.     OSErr    err;
  146.     long    index,
  147.             itemsInList;
  148.     Size    actualSize;
  149.     AEKeyword    keywd;
  150.     DescType    returnedType;
  151.  
  152.  
  153.     // get the direct parameter--a descriptor list--and put it into a docList
  154.     err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
  155.             &docList);
  156.     if (err)
  157.             return err;
  158.  
  159.     
  160.     // check for missing parameters
  161.     err = MyGotRequiredParams (theAppleEvent);
  162.     if (err)
  163.             return err;
  164.  
  165.     
  166.     // count the number of descriptor records in the list
  167.     err = AECountItems (&docList, &itemsInList);
  168.  
  169.     // now get each descriptor record from the list, coerce the returned
  170.     // data to an FSSpec record, and open the associated file
  171.  
  172.     for (index = 1; index <= itemsInList; index++) {
  173.  
  174.             err = AEGetNthPtr (&docList, index, typeFSS, &keywd,
  175.                     &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
  176.             if (err)
  177.                     return err;
  178.  
  179.             
  180.     }
  181.     DoOpen(&myFSS);
  182.     
  183.     err = AEDisposeDesc (&docList);
  184.     return noErr;
  185. }
  186.  
  187. pascal OSErr  MyHandlePDoc (AppleEvent *theAppleEvent, AppleEvent *reply, long
  188.                                                         handlerRefCon)
  189. {
  190. #pragma unused(reply)
  191. #pragma unused(handlerRefCon)
  192.  
  193.     FSSpec    myFSS;
  194.     AEDescList    docList;
  195.     OSErr    err;
  196.     long    index,
  197.             itemsInList;
  198.     Size    actualSize;
  199.     AEKeyword    keywd;
  200.     DescType    returnedType;
  201.  
  202.  
  203.     // get the direct parameter--a descriptor list--and put it into a docList
  204.     err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
  205.             &docList);
  206.     if (err)
  207.             return err;
  208.  
  209.     // check for missing parameters
  210.     err = MyGotRequiredParams (theAppleEvent);
  211.     if (err)
  212.             return err;
  213.  
  214.     // count the number of descriptor records in the list
  215.     err = AECountItems (&docList, &itemsInList);
  216.  
  217.     // now get each descriptor record from the list, coerce the returned
  218.     // data to an FSSpec record, and open the associated file
  219.  
  220.  
  221.  
  222.     for (index = 1; index <= itemsInList; index++) {
  223.  
  224.             err = AEGetNthPtr (&docList, index, typeFSS, &keywd,
  225.                     &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
  226.             if (err)
  227.                     return err;
  228.             
  229.             DoOpen(&myFSS);
  230.             UpdateWindow(gMyWindow);
  231.             DoFile(fmPrint);
  232.             
  233.     }
  234.     
  235.     err = AEDisposeDesc (&docList);
  236.     return noErr;
  237. }
  238.  
  239. pascal OSErr
  240. MyHandleOApp (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
  241. {
  242. #pragma unused(reply)
  243. #pragma unused(handlerRefCon)
  244.  
  245.     OSErr    err;
  246.  
  247.     if ( err = MyGotRequiredParams (theAppleEvent))
  248.             return err;
  249.             
  250.     return ( noErr );
  251. }
  252.  
  253. pascal    OSErr
  254. MyHandleQuit (AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
  255. {
  256. #pragma unused(reply)
  257. #pragma unused(handlerRefcon)
  258.  
  259.     OSErr    err;
  260.     extern Boolean quitting;
  261.     
  262.     if (err = MyGotRequiredParams(theAppleEvent)) {
  263.         // an error occurred:  do the necessary error handling
  264.         return    err;
  265.     }
  266.     
  267.     
  268.     DoFile(fmQuit);
  269.     
  270.     return ( noErr );
  271. }
  272. /******************************************************************************/
  273.  
  274.  
  275. void InitTheMac(void)
  276. {
  277.     SysEnvRec    theWorld;
  278.     GDHandle    GDHdl;
  279.     long        resp;
  280.     OSErr        err;
  281.  
  282.     AEEventHandlerUPP    gMyHandleODoc;
  283.     AEEventHandlerUPP    gMyHandleOApp;
  284.     AEEventHandlerUPP    gMyHandlePDoc;
  285.     AEEventHandlerUPP    gMyHandleQuit;
  286.  
  287.     MaxApplZone();
  288.     FlushEvents(everyEvent, 0);
  289.     InitGraf(&qd.thePort);
  290.     InitFonts();
  291.     InitWindows();
  292.     InitMenus();
  293.     TEInit();
  294.     InitDialogs(NIL);
  295.     InitCursor();
  296.  
  297.     oldMBarHeight=GetMBarHeight();;
  298.     
  299.     if (SysEnvirons(curSysEnvVers, &theWorld) != noErr)
  300.     {
  301.         ParamText("\pSorry, SysEnvirons failed","\p(System too old?)","\p","\p");
  302.         StopAlert(WarningDlg ,NULL);
  303.         ExitToShell();
  304.     }
  305.     
  306.     if(theWorld.hasColorQD)
  307.     {
  308.         GDHdl = GetDeviceList();
  309.         
  310.         do
  311.         {
  312.             BlockMove(&(**GDHdl).gdRect, &PackORects[LastMonitorID], sizeof(Rect));
  313.             LastMonitorID++;
  314.         }while((GDHdl = GetNextDevice(GDHdl))!=NIL);
  315.     }
  316.     else
  317.     {
  318.         ParamText("\pSorry, Color QuickDraw not found","\p(System too old?)","\p","\p");
  319.         StopAlert(WarningDlg ,NULL);
  320.         ExitToShell();
  321.  
  322.     }
  323.     if (AppleEventsInstalled())
  324.     {
  325.         gMyHandleODoc = NewAEEventHandlerProc (MyHandleODoc);
  326.         gMyHandleOApp = NewAEEventHandlerProc (MyHandleOApp);
  327.         gMyHandlePDoc = NewAEEventHandlerProc (MyHandlePDoc);
  328.         gMyHandleQuit = NewAEEventHandlerProc (MyHandleQuit);
  329.         
  330.         if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gMyHandleODoc,0, FALSE) ))
  331.         if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gMyHandleOApp,0, FALSE) ))
  332.         if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gMyHandlePDoc,0, FALSE) ))
  333.             err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gMyHandleQuit,0, FALSE);
  334.     
  335.         if ( err != noErr )
  336.         {
  337.             ParamText("\pSorry, AEInstall Fail","\p :P","\p","\p");
  338.             StopAlert(WarningDlg ,NULL);
  339.             ExitToShell();
  340.         }
  341.     }
  342.     else
  343.     {
  344.         ParamText("\pSorry, AppleEvents not found","\p(System too old?)","\p","\p");
  345.         StopAlert(WarningDlg ,NULL);
  346.         ExitToShell();
  347.     }
  348.     
  349.     theMonitorID=LastMonitorID;
  350.     thePic=nil;
  351.  
  352.  
  353. /*
  354.  * For PowerPC make sure we can actually call QuickTime if its there...
  355.  * This piece of code is incredibly screwed up because we link to QuickTime
  356.  * weakly. Meaning that if the library is not there, undefined externals
  357.  * referencing that library do not keep us from running. However, there
  358.  * seems to be a case where the library is there, but cannot be loaded due
  359.  * to a lack of memory. In this case, the gestalt call says its there, but
  360.  * the routines we call are still NULL. So what the hell, I just check one
  361.  * of the routines that is supposed to be in that library.
  362.  */
  363.  
  364.     CanOpenJFIF =
  365. #ifdef __powerc
  366.     (
  367.         (Gestalt (gestaltCompressionMgr, &resp) == noErr) &&
  368.         (Gestalt(gestaltQuickTimeFeatures, &resp) == noErr) &&
  369.         (resp & (1 << gestaltPPCQuickTimeLibPresent)) &&
  370.         (&CustomGetFilePreview != NULL)
  371.     );
  372. #else
  373.     !( Gestalt(gestaltCompressionMgr, &resp) != noErr || resp < 15 );
  374. #endif
  375.  
  376.  
  377.     PrOpen();
  378.         PrintDefault(ghPtrRec);
  379.     PrClose();
  380.     
  381. #ifdef SHRINKWINDOWFORDEBUG
  382.     PackORects[0].top+= 100;
  383.     PackORects[0].bottom-= 100;
  384. #endif    
  385. }
  386.  
  387. void FlushTheMac(void)
  388. {
  389.     MBarHeight=oldMBarHeight;
  390. }
  391.  
  392. void main( void )
  393.  
  394. { /* main program */
  395.     InitTheMac();
  396.     SetUpMenus();
  397.     
  398.     while( !quitting )
  399.         MainEvent();
  400.  
  401.     FlushTheMac();
  402. }
  403.  
  404.  
  405. void MainEvent(void)
  406. {
  407.     EventRecord    myEvent;
  408.     WindowPtr    whichWindow;
  409.     short        windowPart;
  410.     Rect        tmpRect;
  411.  
  412.     SystemTask();
  413.     if( GetNextEvent(everyEvent, &myEvent) ) {
  414.         switch( myEvent.what ) {
  415.             case mouseDown:
  416.                 windowPart = FindWindow(myEvent.where, &whichWindow);
  417.                 DoMouseDown(windowPart, whichWindow, &myEvent);
  418.                 break;
  419.                 
  420.             case keyDown:
  421.             case autoKey: 
  422.             {
  423.                 register char theChar;
  424.     
  425.                 theChar = myEvent.message & charCodeMask;
  426.                 if ((myEvent.modifiers & cmdKey) != 0) 
  427.                     DoCommand( MenuKey(theChar) );
  428.                 else
  429.                     if ((theChar=='\t')&&(update))
  430.                     {
  431.                         if (HiddenMenu)
  432.                         {
  433.                             (**(*gMyWindow).visRgn).rgnBBox.top=oldTop;
  434.                             
  435.                             SetRect(&tmpRect,
  436.                                 qd.thePort->portRect.left,
  437.                                 qd.thePort->portRect.top,
  438.                                 qd.thePort->portRect.right,
  439.                                 qd.thePort->portRect.top + oldMBarHeight
  440.                             );
  441.                             
  442.                             InvalRect( &tmpRect );
  443.  
  444.                             HiddenMenu=false;
  445.                             MBarHeight=oldMBarHeight;
  446.                             ShowCursor();
  447.                             DrawMenuBar();
  448.  
  449.                         }
  450.                         else
  451.                         {
  452.                             oldTop=(**(*gMyWindow).visRgn).rgnBBox.top;
  453.                             RectRgn( (*gMyWindow).visRgn, &(*qd.thePort).portRect );
  454.                             
  455.                             
  456.                             SetRect(&tmpRect,
  457.                                 qd.thePort->portRect.left,
  458.                                 qd.thePort->portRect.top,
  459.                                 qd.thePort->portRect.right,
  460.                                 qd.thePort->portRect.top + oldMBarHeight
  461.                             );
  462.                             
  463.                             InvalRect( &tmpRect );
  464.                             
  465.                             MBarHeight=0;
  466.                             HiddenMenu=true;
  467.                             HideCursor();
  468.  
  469.                         }
  470.                     }
  471.                     else if ((theChar==' ')&&(update))
  472.                     {
  473.                         if ( BlackBack=!BlackBack )
  474.                                 BackPat(&qd.black);
  475.                         else
  476.                                 BackPat(&qd.white);
  477.  
  478.                         InvalRect( &(*qd.thePort).portRect );
  479.                     }
  480.                     
  481.                 break;
  482.             }
  483.             case osEvt:
  484.                 switch ((myEvent.message >> 24) & 0x0ff)
  485.                 {
  486.                     case suspendResumeMessage:
  487.                         
  488.                         SetCursor(&qd.arrow);
  489.                     
  490.                         if ((myEvent.message & resumeFlag) == 0) // suspend 
  491.                         {
  492.                             if (HiddenMenu)
  493.                             {
  494.                                 (**(*gMyWindow).visRgn).rgnBBox.top=oldTop;
  495.                                 MBarHeight=oldMBarHeight;
  496.                                 ShowCursor();
  497.                                 DrawMenuBar();
  498.     
  499.                             }
  500.                         }
  501.                         else
  502.                         {                                        // resume
  503.                             if (HiddenMenu)
  504.                             {
  505.                                 oldTop=(**(*gMyWindow).visRgn).rgnBBox.top;
  506.                                 RectRgn( (*gMyWindow).visRgn, &(*qd.thePort).portRect );
  507.                                 InvalRect( &(*qd.thePort).portRect );
  508.                                 MBarHeight=0;
  509.                                 HideCursor();
  510.                             }
  511.                         }
  512.                         break;
  513.                         
  514.                     case mouseMovedMessage:
  515.                         break;
  516.                 }
  517.                 break;
  518.             case activateEvt:
  519.                 break;
  520.  
  521.             case updateEvt: 
  522.                 UpdateWindow((WindowPtr)myEvent.message);
  523.                 break;
  524.  
  525.             case kHighLevelEvent:
  526.                 AEProcessAppleEvent (&myEvent);
  527.                 break;
  528.  
  529.  
  530.         }
  531.     }
  532. }
  533. void UpdateWindow(WindowPtr theWindow)
  534. {
  535.     GrafPtr savePort;
  536.     Rect    destRect;    
  537.     short    pw, ph, ww, wh, dw, dh;
  538.     
  539.     GetPort(&savePort);
  540.     SetPort(theWindow);
  541.  
  542.     BeginUpdate(theWindow);
  543.     DrawControls(theWindow);
  544.  
  545.     EraseRect(&theWindow->portRect);
  546.  
  547.     if( thePic != nil )
  548.     {
  549.         BlockMove(&(*thePic)->picFrame, &destRect, sizeof(Rect));
  550.         ww = theWindow->portRect.right - theWindow->portRect.left;
  551.         wh = theWindow->portRect.bottom - theWindow->portRect.top;
  552.         pw = destRect.right - destRect.left;
  553.         ph = destRect.bottom - destRect.top;
  554.         
  555.         dw = (ww - pw)/2;
  556.         dh = (wh - ph)/2;
  557.                 
  558.         OffsetRect( &destRect, dw, dh );
  559.  
  560.         if (( dw < dh ) && ( dw < 0 ))
  561.             InsetRect( &destRect, -dw, -dw * (float) ph / (float) pw );
  562.         else if (( dh < dw ) && ( dh < 0 ))
  563.             InsetRect( &destRect, -dh * (float) pw / (float) ph, -dh );
  564.             
  565.         DrawPicture( thePic, &destRect);
  566.     }
  567.     
  568.     EndUpdate(theWindow);
  569.  
  570.     SetPort(savePort);
  571. }
  572.  
  573. void SetUpMenus(void)
  574. {
  575.     short index;
  576.     Str255 stmp, snum;
  577.  
  578.     myMenus[appleM] = GetMenu(appleID);
  579.     AddResMenu(myMenus[appleM], 'DRVR');
  580.     myMenus[fileM] = GetMenu(fileID);
  581.     myMenus[editM] = GetMenu(editID);
  582.     myMenus[monitorM] = GetMenu(monitorID);
  583.  
  584.     
  585.     for( index=(short)LastMonitorID-1;index>=0;index--)
  586.     {
  587.         *stmp=0x00;
  588.         CatString(stmp,"\pSlot ");
  589.         NumToString((long)(LastMonitorID-index),snum);
  590.         CatString(stmp,snum);
  591.         CatString(stmp,"\p/");
  592.         CatString(stmp,snum);
  593.         AppendMenu(myMenus[monitorM],stmp);
  594.     }
  595.     
  596.  
  597.     for(index=appleM; index <= monitorM; index++)
  598.         InsertMenu(myMenus[index], 0) ;
  599.     CheckItem( myMenus[monitorM], theMonitorID, true);
  600.     
  601.     DisableItem(myMenus[editM],emUndo);
  602.     DisableItem(myMenus[editM],emClear);
  603.     DisableItem(myMenus[editM],emCut);
  604.     DisableItem(myMenus[editM],emPaste);
  605.     
  606.     DisableItem(myMenus[editM],emCopy);
  607.     
  608.     DrawMenuBar();
  609. }
  610.  
  611. void DoCommand(long mResult)
  612. {
  613.     short    theItem;
  614.     Str255    name;
  615.  
  616.     theItem = LoWord(mResult);
  617.     switch( HiWord(mResult) ) {
  618.         case appleID:
  619.             if( theItem > 2 ) {
  620.                 GrafPtr savePort;
  621.                 GetItem(myMenus[appleM], theItem, name);
  622.                 GetPort(&savePort);
  623.                 OpenDeskAcc(name);
  624.                 SetPort(savePort);
  625.             }
  626.             else
  627.             {
  628.                 ParamText("\p©SPDsoft 90-97: Dump a Pict 1.3 ("
  629.  
  630. #ifndef THINK_C
  631.     "mw/"
  632. #else
  633.     "tc/"
  634. #endif
  635.  
  636. #if defined (__powerc)
  637.     "PPC)"
  638. #else
  639.     "68k)"
  640. #endif
  641.                 ,                
  642.                 "\p<Tab>=Full Screen; <Spc>=B/W",
  643.                 "\pe-mail: MacSPD@ivo.cps.unizar.es","\p");
  644.                 NoteAlert(AboutDlg,NULL);
  645.             }
  646.  
  647.             break;
  648.  
  649.         case fileID:
  650.             DoFile(theItem);
  651.             break;
  652.  
  653.         case editID:
  654.         
  655.             if( SystemEdit(theItem-1) == FALSE )
  656.             {
  657.                 if (( theItem == emCopy ) && (thePic != nil ))
  658.                 {
  659.                     ZeroScrap();
  660.                     HLock((Handle)thePic);
  661.                     PutScrap(
  662.                         (long) GetHandleSize((Handle)thePic),
  663.                         (ResType)'PICT',
  664.                         (Ptr) *thePic
  665.                     );
  666.                     HUnlock((Handle)thePic);
  667.                 }
  668.             }
  669.             break;
  670.             
  671.         case monitorID:
  672.         
  673.             CheckItem( myMenus[monitorM], theMonitorID, false);
  674.             theMonitorID=( (theItem>LastMonitorID)?LastMonitorID:theItem);
  675.             CheckItem( myMenus[monitorM], theMonitorID, true);
  676.             
  677.             
  678.             if(gMyWindow!=nil)
  679.             {
  680.             MoveWindow(gMyWindow,
  681.                 PackORects[theMonitorID-1].left,
  682.                 PackORects[theMonitorID-1].top,
  683.                 TRUE);
  684.             SizeWindow(gMyWindow,
  685.                 PackORects[theMonitorID-1].right - PackORects[theMonitorID-1].left,
  686.                 PackORects[theMonitorID-1].bottom - PackORects[theMonitorID-1].top,
  687.                 TRUE);
  688.             InvalRect( &(*qd.thePort).portRect );
  689.             }
  690. /*            
  691.             if (HiddenMenu)
  692.             {
  693.                 MBarHeight=oldMBarHeight;
  694.                 DrawMenuBar();
  695.                 (**(*gMyWindow).visRgn).rgnBBox.top=oldTop;
  696.                 InvalRect( &(*qd.thePort).portRect );
  697.  
  698.                 HiddenMenu=false;
  699.                 MBarHeight=oldMBarHeight;
  700.                 ShowCursor();
  701.                 DrawMenuBar();
  702.                 
  703.                 oldTop=(**(*gMyWindow).visRgn).rgnBBox.top;
  704.                 RectRgn( (*gMyWindow).visRgn, &(*qd.thePort).portRect );
  705.                 InvalRect( &(*qd.thePort).portRect );
  706.                 MBarHeight=0;
  707.                 HiddenMenu=true;
  708.                 HideCursor();
  709.             }
  710. */                
  711.             break;
  712.     }
  713.  
  714.     HiliteMenu(0);
  715. }
  716.  
  717. void DoFile(short item)
  718. {
  719.     OSErr                result;
  720.     short compressedFile = 0;
  721.     SFReply        sfr;    
  722.     Point        pt = {100,100};
  723.     char        zero=0;
  724.     long        l;
  725.     short        i;
  726.     
  727.     switch( item ) {
  728.  
  729.         case fmOpen:
  730.         
  731.             DoOpen((FSSpec *)nil);
  732.             break;
  733.  
  734.         case fmClose:
  735.  
  736.             if (update) DoClose();
  737.             DisableItem(myMenus[fileM],fmClose);
  738.             break;
  739.  
  740.         case fmSaveAs:
  741.             
  742.             /*
  743.              * code for 'fmSaveAs' is from
  744.              * JPEGtoPICT.c, Written by:    Mark Krueger, Apple Computer, Inc.
  745.              *
  746.              */
  747.              
  748.             if (thePic!=nil)
  749.             {
  750.                 SFPutFile(pt,"\pSave PICT:",gTheName,NULL,&sfr);
  751.                 if ( !sfr.good )  {
  752.                     goto done;
  753.                 }
  754.                 
  755.                 /************************************************
  756.                  *
  757.                  *    Create the new file, if we can.
  758.                  *
  759.                  ************************************************/
  760.                 
  761.                 FSDelete(sfr.fName,sfr.vRefNum);
  762.                 if ( (result=Create(sfr.fName,sfr.vRefNum,'MCDJ','PICT')) != noErr ) {
  763.                     goto done;
  764.                 }
  765.                 if ( (result=FSOpen(sfr.fName,sfr.vRefNum,&compressedFile)) != noErr ) {
  766.                     goto done;
  767.                 }
  768.         
  769.                 /************************************************
  770.                  *
  771.                  * write the silly 512 bytes of zero needed at the start of a PICT file
  772.                  *
  773.                  ************************************************/
  774.                     
  775.                 SetFPos(compressedFile,fsFromStart,512);
  776.                 l = 1;
  777.                 for ( i=0; i < 512; i++) {
  778.                     if ( (result=FSWrite(compressedFile,&l,&zero)) )
  779.                         break;
  780.                 }
  781.     
  782.                 /************************************************
  783.                  *
  784.                  * write the QuickTime picture data.
  785.                  *
  786.                  ************************************************/
  787.                 
  788.                 l = GetHandleSize((Handle)thePic);
  789.                     
  790.                 HLock((Handle)thePic);
  791.                 result=FSWrite(compressedFile,&l,*thePic);
  792.                 HUnlock((Handle)thePic);
  793.                 
  794. done:    
  795.                 if ( compressedFile )
  796.                 {
  797.                     FSClose(compressedFile);
  798.                     if ( result != noErr )
  799.                         FSDelete(sfr.fName,sfr.vRefNum);
  800.                     FlushVol(nil,sfr.vRefNum);
  801.                 }
  802.  
  803.             }
  804.             break;
  805.  
  806.         case fmPageSetUp:
  807.         
  808.                 PrOpen();
  809.                     PrintDefault(ghPtrRec);
  810.                     PrStlDialog(ghPtrRec);
  811.                 PrClose();
  812.  
  813.             break;
  814.  
  815.         case fmPrint:
  816.             {
  817.                 TPPrPort    myPrtPort;
  818.                 Rect        destRect;
  819.                 TPrStatus    myPrStatus;
  820.                 GrafPtr        savePort;
  821.  
  822.                 
  823.                 if( thePic == nil )
  824.                     break;
  825.                     
  826.                 GetPort(&savePort);
  827.                 
  828.                 PrOpen();
  829.                 if(PrJobDialog(ghPtrRec))
  830.                 {
  831.                     
  832.                     myPrtPort = PrOpenDoc( ghPtrRec, 0,0 );
  833.                     PrOpenPage( myPrtPort , 0 );
  834.                     if ( PrError() )
  835.                         goto done_pr;
  836.                     
  837.                             
  838.  
  839.                     if( thePic != nil )
  840.                     {
  841.                         BlockMove(&(*thePic)->picFrame, &destRect, sizeof(Rect));
  842.         
  843.                         OffsetRect(
  844.                             &destRect,
  845.                 
  846.                             ((myPrtPort->gPort.portRect.right-myPrtPort->gPort.portRect.left) -
  847.                             (destRect.right - destRect.left)) / 2
  848.                             ,
  849.                             
  850.                             ((myPrtPort->gPort.portRect.bottom-myPrtPort->gPort.portRect.top) -
  851.                             (destRect.bottom - destRect.top)) / 2
  852.                             );
  853.  
  854.                         DrawPicture( thePic, &destRect);
  855.                     }
  856.                     
  857.                     PrClosePage( myPrtPort );
  858.                     
  859.                     PrCloseDoc( myPrtPort );
  860.                     
  861.                     if ( (*ghPtrRec)->prJob.bJDocLoop == bSpoolLoop )
  862.                     {
  863.                         PrPicFile( ghPtrRec, 0,0,0, &myPrStatus );
  864.                     }
  865.                 }
  866. done_pr:
  867.                 
  868.                 PrClose();
  869.                 SetPort(savePort);
  870.             }
  871.             break;
  872.  
  873.  
  874.         case fmQuit:
  875.         
  876.             DoFile(fmClose);
  877.             quitting = true;
  878.             break;
  879.     }
  880. }
  881.  
  882. void DoMouseDown(short windowPart, WindowPtr whichWindow, EventRecord *myEvent)
  883. {
  884.     switch( windowPart ) {
  885.         case inGoAway:
  886.             if( TrackGoAway(whichWindow, myEvent->where) )
  887.                 DoFile(fmClose);
  888.             break;
  889.  
  890.         case inMenuBar:
  891.             DoCommand( MenuSelect(myEvent->where) );
  892.             break;
  893.  
  894.         case inSysWindow:
  895.             SystemClick(myEvent, whichWindow);
  896.             break;
  897.  
  898.         case inDrag:
  899.             break;
  900.  
  901.         case inGrow:
  902.             break;
  903.  
  904.         case inContent:
  905.             if( whichWindow != FrontWindow() )
  906.                 SelectWindow(whichWindow);
  907.             break;
  908.     }
  909. }
  910. /********************************************************************************/
  911.  
  912. void    DoClose(void)
  913. {
  914.     if (HiddenMenu)
  915.     {
  916.         HiddenMenu=false;
  917.         MBarHeight=oldMBarHeight;
  918.         ShowCursor();
  919.         DrawMenuBar();
  920.     }
  921.  
  922.     if (( gMyWindow == FrontWindow() ) && ( gMyWindow != nil ))
  923.     {
  924.         DisposeWindow(gMyWindow);
  925.         gMyWindow = nil;
  926.     }
  927.     
  928.     if (thePic)
  929.     {
  930.         KillPicture(thePic);
  931.         thePic = nil;
  932.     }
  933.     DisableItem(myMenus[editM],emCopy);
  934.     DisableItem(myMenus[fileM],fmSaveAs);
  935.     DisableItem(myMenus[fileM],fmPrint);
  936. }
  937.  
  938. void    DoOpen( FSSpec *myFSSpec )
  939. {
  940.     StandardFileReply    mySFR;
  941. #ifdef DO_FOLDERS
  942.     HFileInfo            pb;
  943.     OSErr                error;
  944. #endif
  945.     
  946.     SFTypeList        typeList={ 'PICT','JFIF','JPEG','\?\?\?\?' };
  947.  
  948.  
  949.  
  950.     if ( myFSSpec == nil )
  951.     {
  952.         if(CanOpenJFIF)
  953.         {
  954.             StandardGetFilePreview( nil, 3, typeList, &mySFR);
  955.         }
  956.         else
  957.         {    
  958.             StandardGetFile( nil, 1, typeList, &mySFR);
  959.         }
  960.  
  961.  
  962.         if( !mySFR.sfGood ) return;
  963.         
  964.         myFSSpec = &(mySFR.sfFile);
  965.     }
  966.         
  967.  
  968. #ifdef DO_FOLDERS
  969.     pb.ioNamePtr    = myFSSpec->name;
  970.     pb.ioVRefNum    = myFSSpec->vRefNum;
  971.     pb.ioFDirIndex    = 0;                    /* query 1 item */
  972.     pb.ioDirID        = myFSSpec->parID;
  973.     
  974.     PBGetCatInfo( (CInfoPBPtr)&pb, 0 );
  975.     if (((pb.ioFlAttrib>>4) & 0x01) == 1)
  976.     {
  977.         /* Is a Dir */
  978.         gpb.ioNamePtr = myFSSpec->name;
  979.         gpb.ioVRefNum = myFSSpec->vRefNum;
  980.  
  981.         RecurseDir(pb.ioDirID);
  982.     }
  983.     else
  984.     {
  985. #endif
  986.         /* Is a File */
  987.         
  988.         OpenFile( myFSSpec );
  989.     
  990. #ifdef DO_FOLDERS
  991.     }
  992. #endif
  993.  
  994. }
  995.  
  996. void    OpenFile( FSSpec *myFSSpec )
  997. {
  998.     short            fRefNum;
  999.     FInfo            finfo;
  1000.  
  1001.  
  1002.     if (thePic)
  1003.         KillPicture(thePic);
  1004.         
  1005.     thePic = nil;
  1006.     
  1007.     if ( FSpOpenDF(myFSSpec, fsCurPerm, &fRefNum) == noErr )
  1008.     {
  1009.         if ( gMyWindow == nil)
  1010.         {
  1011.             gMyWindow = NewCWindow(
  1012.                             nil, &PackORects[theMonitorID-1],
  1013.                             "\p", TRUE, 2, (WindowPtr)(-1L), FALSE, 0L
  1014.                         );
  1015.         }
  1016.         else
  1017.         {
  1018.             InvalRect( &(*qd.thePort).portRect );
  1019.         }
  1020.  
  1021.         if ( gMyWindow == nil)
  1022.         {
  1023.             SysBeep(1);
  1024.             ExitToShell();
  1025.         }
  1026.     
  1027.         SetPort(gMyWindow);
  1028.         
  1029.         PenPat(&qd.white);
  1030.         BackPat(BlackBack ? &qd.black:&qd.white);
  1031.     
  1032.         
  1033.         FSpGetFInfo(myFSSpec, &finfo);
  1034.         
  1035.         if ( finfo.fdType == 'PICT' )
  1036.         {
  1037.             thePic=ConvertFromPict(myFSSpec->name, fRefNum, (CWindowPtr)gMyWindow);
  1038.         }
  1039.         else if ( ( finfo.fdType == 'JPEG' ) || ( finfo.fdType == 'JFIF' ))
  1040.         {
  1041.             if(CanOpenJFIF)
  1042.             thePic=ConvertFromJFIF(myFSSpec->name, fRefNum, (CWindowPtr)gMyWindow);
  1043.         }
  1044.     }
  1045.     
  1046.     if (thePic==nil)
  1047.     {
  1048.         DoClose();
  1049.     }
  1050.     else
  1051.     {    
  1052.         CopyString( myFSSpec->name, gTheName );
  1053.         EnableItem(myMenus[fileM],fmClose);
  1054.         EnableItem(myMenus[editM],emCopy);
  1055.         EnableItem(myMenus[fileM],fmSaveAs);
  1056.         EnableItem(myMenus[fileM],fmPrint);
  1057.     }
  1058. }
  1059.  
  1060.  
  1061. void RecurseDir(long dirIDToSearch)
  1062. {
  1063. #ifdef DO_FOLDERS
  1064.     short int    index=1;      /* for ioFDirIndex */
  1065.     OSErr        err;          /* the usual */
  1066.     FSSpec        myFSSpec;
  1067.  
  1068.     do
  1069.     {
  1070.          gpb.ioDirID        = dirIDToSearch;     
  1071.          gpb.ioFDirIndex    = index;        /* set up the index */
  1072.                                             /* we need to do this every time through,
  1073.                                              * since GetCatInfo returns ioFlNum
  1074.                                              * in this field
  1075.                                              */
  1076.          err= PBGetCatInfo((CInfoPBPtr)&gpb,false);
  1077.  
  1078.          if (err == noErr) 
  1079.          {
  1080.              /* check the file attributes for folderhood */
  1081.              if (((gpb.ioFlAttrib>>4) & 0x01) == 1)
  1082.              {
  1083.                   RecurseDir(gpb.ioDirID);
  1084.                   err = 0;
  1085.              }
  1086.              else 
  1087.              {
  1088.                      FSMakeFSSpec(
  1089.                          0,
  1090.                          dirIDToSearch,
  1091.                          gpb.ioNamePtr,
  1092.                          &myFSSpec
  1093.                          );
  1094.                          
  1095.                     OpenFile( &myFSSpec );
  1096.             
  1097.              }
  1098.              
  1099.         index += 1;    /* increment the index for GetCatInfo */
  1100.         }
  1101.     } while ((err == noErr)&&(!Button()));
  1102. #else
  1103. #pragma unused(dirIDToSearch)
  1104. #endif   
  1105. }
  1106.  
  1107. void CatString( Str255 StrIO, Str255 Str )
  1108. {
  1109.     BlockMove(&Str[1], (Str255 *)(StrIO+(int)*StrIO+1), (int) *Str);
  1110.     (*StrIO) += (unsigned int)*Str;
  1111. }
  1112.  
  1113.