home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / AppWannabe / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-20  |  5.5 KB  |  203 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file is where you place various definitions and constant values for
  20. ** DTS.Lib..framework's use.  You will also add some code within the two
  21. ** functions to handle the various document types. */
  22.  
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28.  
  29. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  30. #include "App.defs.h"        /* Get various application definitions.            */
  31. #include "App.protos.h"        /* Get the prototypes for application.            */
  32.  
  33. #ifndef __ERRORS__
  34. #include <Errors.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /* In this file, we first set some global values.  This allows the application and
  44. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  45.  
  46.  
  47. short        gTypeListLen = 1;
  48. SFTypeList    gTypeList = {kDocFileType};
  49.     /* Here we declare the various document types that Wannabe can support.
  50.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  51.  
  52.  
  53.  
  54. /* Some DTS.Lib..framework gTypeList usage notes:
  55. **
  56. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  57. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  58. **     The index at which the match is found (+1) is used as the string number in the
  59. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  60. **     resource, then the last string is used.
  61. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  62. **     can be selected. */
  63.  
  64.  
  65.  
  66. #ifdef powerc
  67. #pragma options align=mac68k
  68. #endif
  69. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  70.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  71.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  72.     TheDoc            doc;            /* will place on the end of each.                            */
  73. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  74. #ifdef powerc
  75. #pragma options align=reset
  76. #endif
  77.  
  78.  
  79.  
  80. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  81. ** application.  The first 16 are reserved for the framework.  Our application-specific
  82. ** objects start at 16. */
  83.  
  84. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  85. /* 1  */                                         TRootObj,
  86. /* 2  */                                         TUndoObj,
  87. /* 3  */                                         TUndoTaskObj,
  88. /* 4  */                                         TUndoPartObj,
  89. /* 5  */                                         nil,
  90. /* 6  */                                         nil,
  91. /* 7  */                                         nil,
  92. /* 8  */                                         nil,
  93. /* 9  */                                         nil,
  94. /* 10 */                                         nil,
  95. /* 11 */                                         nil,
  96. /* 12 */                                         nil,
  97. /* 13 */                                         nil,
  98. /* 14 */                                         nil,
  99. /* 15 */                                         nil};
  100. /* 16 Start of app-specific procs. */
  101.  
  102.  
  103.  
  104. /* The framework needs to know the minimum object sizes.  This table is used by the
  105. ** framework to make sure that the object is created at least minimally. */
  106.  
  107. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  108. /* 1  */                                         sizeof(RootObj),
  109. /* 2  */                                         sizeof(UndoObj),
  110. /* 3  */                                         sizeof(UndoTaskObj),
  111. /* 4  */                                         sizeof(UndoPartObj),
  112. /* 5  */                                         0,
  113. /* 6  */                                         0,
  114. /* 7  */                                         0,
  115. /* 8  */                                         0,
  116. /* 9  */                                         0,
  117. /* 10 */                                         0,
  118. /* 11 */                                         0,
  119. /* 12 */                                         0,
  120. /* 13 */                                         0,
  121. /* 14 */                                         0,
  122. /* 15 */                                         0};
  123. /* 16 Start of app-specific sizes. */
  124.  
  125.  
  126.  
  127. /*****************************************************************************/
  128. /*****************************************************************************/
  129.  
  130.  
  131.  
  132. /* •• Called by DTS.Lib..framework. •• */
  133.  
  134. /* Do any additional document initialization here.  All fields not specifically set
  135. ** are already initialized to 0. */
  136.  
  137. #pragma segment File
  138. OSErr    InitDocument(FileRecHndl frHndl)
  139. {
  140.     OSErr    err;
  141.  
  142.     err = noErr;
  143.  
  144.     switch ((*frHndl)->fileState.sfType) {
  145.         case kDocFileType:
  146.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  147.             if (!err) {
  148.                 /* Any additional document initialization could go here. */
  149.             }
  150.             break;
  151. #ifndef powerc
  152.         case '6hlp':
  153.             err = HelpInitDocument(frHndl);
  154.             break;
  155. #endif
  156. #if VH_VERSION
  157.         case kViewHierFileType:
  158.             return(VHInitDocument(frHndl));
  159.             break;
  160. #endif
  161.         default:
  162.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  163.             if (!err) {
  164.                 (*frHndl)->fileState.readDocumentProc  = nil;
  165.                 (*frHndl)->fileState.writeDocumentProc = nil;
  166.             }
  167.             break;
  168.     }
  169.  
  170.     return(err);
  171. }
  172.  
  173.  
  174.  
  175. /*****************************************************************************/
  176.  
  177.  
  178.  
  179. /* •• Called by DTS.Lib..framework. •• */
  180.  
  181. /* Return the initial size of the primary document handle, based on the OSType. */
  182.  
  183. #pragma segment File
  184. long    InitDocumentSize(OSType sftype)
  185. {
  186.     switch (sftype) {
  187.         case kDocFileType:
  188.             return(sizeof(DocFileTypeRec));
  189.             break;
  190. #if VH_VERSION
  191.         case kViewHierFileType:
  192.             return(VHFileTypeSize());
  193.             break;
  194. #endif
  195.         default:
  196.             return(sizeof(DocFileTypeRec));
  197.             break;
  198.     }
  199. }
  200.  
  201.  
  202.  
  203.