home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / APISample / APISampleCW / Source / UDoc.cp < prev    next >
Encoding:
Text File  |  1994-03-13  |  3.5 KB  |  154 lines  |  [TEXT/MPS ]

  1. // Copyright ©1994 Apple Computer, Inc.
  2. // Author: John Powers
  3. // Date:   04-Aug-93
  4.  
  5. // UDoc.cp
  6. // This file contains the documents and the objects that go
  7. // into the document window.
  8.  
  9. #ifndef __UDOC__
  10.     #include "UDoc.h"
  11. #endif
  12.  
  13. // Segment
  14.  
  15. #pragma segment MoG1
  16.  
  17. // =========================================================================
  18. // TDoc : TDocument
  19. // ------------------------------------------------------------------------
  20. // TDoc::TDoc
  21. // Document object constructor.
  22. // The base class creates the Window Manager window pointer.
  23. // The resID is used by the base class constructor.
  24. TDoc::TDoc(short resID) : TDocument(resID)
  25. {
  26.             // The TDocument constructor makes a NewWindow,
  27.             // but we need a NewCWindow.  Replace it with
  28.             // our own NewCWindow.  This lets us leave the
  29.             // DTS TDocument class unmodified.
  30.     DisposeWindow(this->fDocWindow);
  31.     this->fDocWindow = GetNewCWindow( resID, nil, (WindowPtr) -1 );
  32.     SetPort(this->fDocWindow);
  33. }
  34.  
  35. // ------------------------------------------------------------------------
  36. // TDoc::~TDoc
  37. // Document window destructor.
  38. // The window pointer is disposed in the document destructor.
  39. TDoc::~TDoc()
  40. {
  41. }
  42.  
  43. // ------------------------------------------------------------------------
  44. // TDoc::DoUpdate
  45. // Document object.
  46. // Entry for update event action.
  47. void
  48. TDoc::DoUpdate()
  49. {
  50.     BeginUpdate(this->fDocWindow);
  51.     this->Draw();
  52.     EndUpdate(this->fDocWindow);
  53. }
  54.  
  55. // ------------------------------------------------------------------------
  56. // TDoc::Erase
  57. // Erase the window.
  58. void
  59. TDoc::Erase()
  60. {
  61.     SetPort(this->fDocWindow);
  62.     EraseRect(&this->fDocWindow->portRect);
  63. };
  64.  
  65. // ------------------------------------------------------------------------
  66. // TDoc::Hide
  67. // Hide the window.
  68. void
  69. TDoc::Hide()
  70. {
  71.     HideWindow(this->fDocWindow);
  72. };
  73.  
  74. // ------------------------------------------------------------------------
  75. // TDoc::Invalidate
  76. // Invalidate the window.
  77. void
  78. TDoc::Invalidate()
  79. {
  80.     SetPort(this->fDocWindow);
  81.     InvalRect(&this->fDocWindow->portRect);
  82. }
  83.  
  84. //--------------------------------------------------------------------------
  85. // TDoc::IsThisKeyDown
  86. // Return true if theKey is down.
  87. // Adapted from MacApp 3.0.1, UMacAppUtilities.cp.
  88. Boolean
  89. TDoc::IsThisKeyDown(const short theKey)
  90. {
  91.     union
  92.     {
  93.         KeyMap asMap;
  94.         Byte asBytes[16];
  95.     };
  96.  
  97.     GetKeys(asMap);
  98.     return asBytes[theKey >> 3] & (1 << (theKey & 0x07)) ? true : false;
  99. }
  100.  
  101. // ------------------------------------------------------------------------
  102. // TDoc::IsWindowVisible
  103. // Return true if the window is visible.
  104. Boolean
  105. TDoc::IsWindowVisible()
  106. {
  107.     if(this->fDocWindow)
  108.         return ((WindowPeek)this->fDocWindow)->visible;
  109.     else
  110.         return false;
  111. }
  112.  
  113. // ------------------------------------------------------------------------
  114. // TDoc::Show
  115. // Show the window and bring it to the front.
  116. void
  117. TDoc::Show()
  118. {
  119.     ShowWindow(this->fDocWindow);
  120.     SelectWindow(this->fDocWindow);
  121.     SetPort(this->fDocWindow);
  122. };
  123.  
  124. // ------------------------------------------------------------------------
  125. // TDoc::Toggle
  126. // Show/Hide the window.
  127. void
  128. TDoc::Toggle()
  129. {
  130.     if(this->IsWindowVisible())
  131.         this->Hide();
  132.     else
  133.         this->Show();
  134. };
  135.  
  136. // =========================================================================
  137. // TDocClip : TDoc : TDocument
  138. // ------------------------------------------------------------------------
  139. // TDocClip::TDocClip
  140. // Document window constructor.
  141. TDocClip::TDocClip(short resID) : TDoc(resID)
  142. {
  143.     this->fScrap = nil;
  144. }
  145.  
  146. // ------------------------------------------------------------------------
  147. void
  148. TDocClip::Draw()
  149. {
  150.     if(this->fScrap)
  151.         this->fScrap->Draw(this->fDocWindow);
  152. }
  153.  
  154.