home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Better Apple Event Coding / Code Samples / SCN.014.TESample < prev    next >
Encoding:
Text File  |  1992-10-16  |  5.5 KB  |  119 lines  |  [TEXT/MPS ]

  1. Macintosh
  2. Sample Code Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. #14:    CPlusTESample
  7.  
  8. Written by:    Andrew Shebanow
  9.  
  10. Versions:           2.0                           May 1990
  11.  
  12. Components:         AppLib.h                      May 1, 1990
  13.                     AppLib.r                      May 1, 1990
  14.                     Application.cp                May 1, 1990
  15.                     Application.h                 May 1, 1990
  16.                     Document.cp                   May 1, 1990
  17.                     Document.h                    May 1, 1990
  18.                     Exceptions.cp                 May 1, 1990
  19.                     Exceptions.h                  May 1, 1990
  20.                     List.h                        May 1, 1990
  21.                     List.cp                       May 1, 1990
  22.                     TECommon.h                    May 1, 1990
  23.                     TEDocument.cp                 May 1, 1990
  24.                     TEDocument.h                  May 1, 1990
  25.                     TESample.cp                   May 1, 1990
  26.                     TESample.make                 May 1, 1990
  27.                     TESample.h                    May 1, 1990
  28.                     TESample.r                    May 1, 1990
  29.                     TESampleGlue.a                May 1, 1990
  30.  
  31. From MacApp 2.0:    UMAFailure.a                  May 1, 1990
  32.                     UMAFailure.h                  May 1, 1990
  33.                     UMAFailure.inc1.p             May 1, 1990
  34.                     UMAFailure.p                  May 1, 1990
  35.  
  36. _______________________________________________________________________________
  37.  
  38. This program requires C, C++, and Asm from MPW 3.1 or greater to build.  It
  39. also uses the Failure handling routines, provided here, from MacApp 2.0.
  40.  
  41. For use with MPW 3.2, follow the instructions in the "TESample.make" file.
  42. _______________________________________________________________________________
  43.  
  44. This version of TESample has been substantially reworked in C++ to show how a
  45. "typical" object-oriented program could be written.  To this end, what was
  46. once a single source code file has been restructured into a set of classes
  47. which demonstrate the advantages of object-oriented programming.
  48.  
  49. There are four main classes in this program.  Each of these classes has a
  50. definition (.h) file and an implementation (.cp) file.
  51.  
  52. The TApplication class does all of the basic event handling and
  53. initialization necessary for Macintosh toolbox applications.  It maintains a
  54. list of TDocument objects and passes events to the correct TDocument class
  55. when appropriate.
  56.  
  57. The TDocument class does all of the basic document handling work.  TDocument
  58. objects are objects that are associated with a window.  Methods are provided
  59. to deal with update, activate, mouse-click, key down, and other events.  Some
  60. additional classes which implement a linked list of TDocument objects are
  61. provided.
  62.  
  63. The TApplication and TDocument classes together define a basic framework for
  64. Macintosh applications, without having any specific knowledge about the type
  65. of data being displayed by the application's documents.  They are a (very)
  66. crude implementation of the MacApp application model, without the
  67. sophisticated view hierarchy.
  68.  
  69. The TESample class is a subclass of TApplication.  It overrides several
  70. TApplication methods, including those for handling menu commands and cursor
  71. adjustment, and it does some necessary initialization.  Note that we only
  72. need to override a few basic routines--the rest of the work is done in a
  73. generic way by TApplication (isn't OOP great?).
  74.  
  75. The TEDocument class is a subclass of TDocument.  This class contains most
  76. of the special-purpose code for text editing.  In addition to overriding
  77. most of the TDocument methods, it defines a number of additional methods
  78. which are used by the TESample class to get information on the document
  79. state.
  80.  
  81. The UMAFailure files are a hacked up version of MacApp 2.0's UFailure unit.
  82. The Exceptions files are a set of C++ macros that make recovering from errors
  83. easier.
  84.  
  85. Segmentation Strategy
  86. _____________________
  87.  
  88. This program has only one segment, since it isn't really big enough to make
  89. multiple segments worthwhile.  We do unload the data initialization segment
  90. at start time, which frees up some memory.
  91.  
  92. _SetPort Strategy
  93. _________________
  94.  
  95. Toolbox routines do not change the current port.  In spite of this, in this
  96. program we use a strategy of calling _SetPort whenever we want to draw or
  97. make calls which depend upon the current port.  This makes us less vulnerable
  98. to bugs in other software which might alter the current port (such as the
  99. bug (feature?) in many desk accessories which change the port on
  100. _OpenDeskAcc).  Hopefully, this also makes the routines from this program
  101. more self-contained, since they don't depend on the current port setting.
  102.  
  103. Clipboard Strategy
  104. __________________
  105.  
  106. This program does not maintain a private scrap.  Whenever a Cut, Copy, or
  107. Paste occurs, we import or export from the public scrap to TextEdit's scrap
  108. immediately, using the TEToScrap and TEFromScrap routines.  If we did use a
  109. private scrap, the import or export would be in the activate or deactivate
  110. event and suspend or resume event routines, respectively.
  111.  
  112. Version 2.0 Changes
  113. ___________________
  114.  
  115. Version 2.0 adds the ability to open and save documents.  It also allows
  116. the user to open multiple documents.  For error checking, it uses the
  117. Failure unit now instead of the previous if-then-else method.
  118.  
  119.