home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / EMBL Search / Sources / checkapp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-04  |  3.2 KB  |  144 lines  |  [TEXT/KAHL]

  1. /*
  2. *********************************************************************
  3. *    
  4. *    CheckApp.c
  5. *    If EMBL-Search is started by opening an EMBL-Search document from
  6. *    the Finder
  7. *    
  8. *    Rainer Fuchs
  9. *    EMBL Data Library
  10. *    Postfach 10.2209
  11. *    D-6900 Heidelberg, FRG
  12. *    E-mail: fuchs@embl-heidelberg.de
  13. *
  14. *    Copyright Â© 1992 EMBL Data Library
  15. *
  16. *********************************************************************
  17. *    
  18. */ 
  19.  
  20. /*
  21. ****************************** Include files *************************
  22. */
  23.  
  24. #include "EMBL-Search.h"
  25. #include "EMBL-Search.rsrc.h"
  26.  
  27. /*
  28. ******************************* Prototypes ***************************
  29. */
  30.  
  31. #include "checkapp.h"
  32. #include "results.h"
  33. #include "print.h"
  34. #include "window.h"
  35. #include "util.h"
  36. #include "query.h"
  37.  
  38. /*
  39. ******************************** Global variables ******************
  40. */
  41.  
  42. extern Boolean gHasAppleEvents;
  43. extern WDRec gWindows[MAXWIN];
  44. extern Boolean gQuitApplication;
  45.  
  46.  
  47. /**************************************
  48. *    Handle information passed by Finder of Systems < 7.0
  49. *    Return value:    none
  50. */
  51.  
  52. void CheckAppFiles()
  53. {
  54.     short        message,count;
  55.     short        index;
  56.     AppFile    theFile;
  57.     WDPtr        dummy;
  58.  
  59.     if(gHasAppleEvents)                    /* Apple Events do everything for us */
  60.         return;
  61.         
  62.     CountAppFiles(&message,&count);    /* check startup information */
  63.     if(message == appPrint)    {            /* print files */
  64.         for(index=1;index<=count;index++) {    /* print files, one by one */
  65.             GetAppFiles(index,&theFile);
  66.             if(!DoDocPrint(theFile.fType,theFile.vRefNum,theFile.fName))
  67.                 break;
  68.             ClrAppFiles(index);
  69.         }
  70.       }
  71.     else {
  72.         for(index=1;index<=count;index++) {    /* open files, one by one */
  73.             GetAppFiles(index,&theFile);
  74.             if(!DoDocOpen(theFile.fType,theFile.vRefNum,theFile.fName,&dummy))
  75.                 break;
  76.             ClrAppFiles(index);
  77.        }
  78.    }
  79.     /* should we ExitToShell if application was started from the Finder to
  80.         print a document!? Couldn't find any clear interface guidelines… */
  81. }
  82.  
  83.  
  84. /**************************************
  85. *    Open document
  86. *    Return value:    TRUE, if sucessful
  87. *                        FALSE, if an error occurred
  88. *    By side-effect a WDPtr in wdpPtr, if a window was opened
  89. */
  90.  
  91. Boolean DoDocOpen(OSType fType,short vRefNum,StringPtr fName, WDPtr *wdpPtr)
  92. {
  93.     char        fullPath[256];
  94.     short        w;
  95.     Boolean    ret = TRUE;
  96.  
  97.     *wdpPtr = NULL;
  98.     if( (w=GetFreeWindow()) == -1) {        /* find a free window */
  99.         return(ErrorMsg(ERR_MAXWIN));
  100.     }
  101.  
  102.       StartWaitCursor();
  103.     switch(fType) {
  104.         case kQryFileType:
  105.            if ( (ret=LoadQuery(w,fName,vRefNum)) )
  106.                *wdpPtr = &gWindows[w];
  107.            break;
  108.         case kPrefFileType:        /* no special action required */
  109.             break;
  110.         case kResFileType:
  111.            if( (ret=Load1Results(w,fName,vRefNum)) )
  112.                *wdpPtr = &gWindows[w];
  113.            break;
  114.     }
  115.     InitCursor();
  116.     
  117.     return(ret);
  118. }
  119.  
  120. /**************************************
  121. *    Print document
  122. *    Return value:    TRUE, if sucessful
  123. *                        FALSE, if an error occurred
  124. */
  125.  
  126. Boolean DoDocPrint(OSType fType, short vRefNum, StringPtr fName)
  127. {
  128.     WDPtr wdp = NULL;
  129.     
  130.     if(fType == kQryFileType)
  131.         return(TRUE);
  132.  
  133.     if(DoDocOpen(fType,vRefNum,fName,&wdp)) {    /* open window */
  134.         if(wdp) {
  135.             PrintIt(wdp);
  136.             CloseMyWindow(wdp,TRUE);
  137.         }
  138.     
  139.         /* See above: should we set gQuitApplication to TRUE if application was
  140.         started from the Finder to print a document */
  141.         return(TRUE);
  142.     }
  143.     else return(FALSE);
  144. }