home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Bitmap / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.7 KB  |  276 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Bitmap.hpp"
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef BINDING_K
  19. #include "Binding.k"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef SELECT_H
  27. #include "Select.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. #ifndef DEFINES_K
  35. #include "Defines.k"
  36. #endif
  37.  
  38. // ----- Part Layer -----
  39.  
  40. #ifndef FWUTIL_H
  41. #include "FWUtil.h"
  42. #endif
  43.  
  44. #ifndef FWPRTITE_H
  45. #include "FWPrtIte.h"
  46. #endif
  47.  
  48. #ifndef FWITERS_H
  49. #include "FWIters.h"
  50. #endif
  51.  
  52. #ifndef FWABOUT_H
  53. #include "FWAbout.h"
  54. #endif
  55.  
  56. #ifndef FWPRESEN_H
  57. #include "FWPresen.h"
  58. #endif
  59.  
  60. // ----- OS Layer -----
  61.  
  62. #ifndef FWSUSINK_H
  63. #include "FWSUSink.h"
  64. #endif
  65.  
  66. #ifndef FWPICTUR_H
  67. #include "FWPictur.h"
  68. #endif
  69.  
  70. #ifndef FWEVENT_H
  71. #include "FWEvent.h"
  72. #endif
  73.  
  74. #ifndef FWBARRAY_H
  75. #include "FWBArray.h"
  76. #endif
  77.  
  78. #ifndef FWFILEAC_H
  79. #include "FWFileAc.h"
  80. #endif
  81.  
  82. #ifndef SLMixOS_H
  83. #include "SLMixOS.h"
  84. #endif
  85.  
  86. // ----- Foundation Layer -----
  87.  
  88. #ifndef FWSTREAM_H
  89. #include "FWStream.h"
  90. #endif
  91.  
  92. #ifndef FWMEMORY_H
  93. #include "FWMemory.h"
  94. #endif
  95.  
  96. #ifndef FWSUSINK_H
  97. #include "FWSUSink.h"
  98. #endif
  99.  
  100. // ----- OpenDoc Includes -----
  101.  
  102. #ifndef SOM_Module_OpenDoc_StdProps_defined
  103. #include <StdProps.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODTranslation_xh
  107. #include <Translt.xh>
  108. #endif
  109.  
  110. #ifndef SOM_ODSession_xh
  111. #include <ODSessn.xh>
  112. #endif
  113.  
  114. // ----- Macintosh Includes -----
  115.  
  116. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  117. #include <Drag.h>
  118. #endif
  119.  
  120. //========================================================================================
  121. //    Runtime Information
  122. //========================================================================================
  123.  
  124. #ifdef FW_BUILD_MAC
  125. #pragma segment odfbitmap
  126. #endif
  127.  
  128. //========================================================================================
  129. //    class CBitmapPart
  130. //========================================================================================
  131.  
  132. FW_DEFINE_AUTO(CBitmapPart)
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    CBitmapPart::CBitmapPart
  136. //----------------------------------------------------------------------------------------
  137. //    CBitmapPart constructor
  138.  
  139. CBitmapPart::CBitmapPart(ODPart* odPart) :
  140.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  141.     fBitmapContent(NULL),
  142.     fBitmapPresentation(NULL)
  143. {
  144.     FW_END_CONSTRUCTOR
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    CBitmapPart::~CBitmapPart
  149. //----------------------------------------------------------------------------------------
  150. // CBitmapPart destructor
  151.  
  152. CBitmapPart::~CBitmapPart()
  153. {
  154.     FW_START_DESTRUCTOR
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    CBitmapPart::Initialize
  159. //----------------------------------------------------------------------------------------
  160. //    ODF Method
  161.  
  162. void CBitmapPart::Initialize(Environment* ev)
  163. {
  164.     // ----- Call first inherited -----
  165.     FW_CPart::Initialize(ev);
  166.     
  167.     // ----- Initialize my menu -----
  168.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  169.         
  170.     // ----- Register our Presentations
  171.     fBitmapPresentation = RegisterPresentation(ev, "Apple:Presentation:ODFBitmap", TRUE, FW_NEW(CBitmapSelection, (ev, this, fBitmapContent)));
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    CBitmapPart::NewDocumentWindow
  176. //----------------------------------------------------------------------------------------
  177.  
  178. FW_CWindow* CBitmapPart::NewDocumentWindow(Environment* ev)
  179. {    
  180.     FW_CRect bitmapRect;
  181.     fBitmapContent->GetBitmap(ev).GetBitmapBounds(bitmapRect);    // return in 72 dpi
  182. #ifdef FW_BUILD_MAC
  183.     // Leave some room for the grow box
  184.     bitmapRect.Inset(FW_IntToFixed(-16), FW_IntToFixed(-16));
  185. #endif
  186.     
  187.     FW_CRect screenBounds;
  188.     ::FW_GetMainScreenBounds(screenBounds);
  189.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  190.     
  191.     return new FW_CWindow(ev,
  192.                         this,
  193.                          FW_CPart::gViewAsFrameToken,
  194.                         fBitmapPresentation,
  195.                         bitmapRect.Size(),
  196.                         screenBounds.TopLeft(),
  197.                         FW_kDocumentWindow);
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CBitmapPart::NewPartContent
  202. //----------------------------------------------------------------------------------------
  203. //    ODF Method
  204.  
  205. FW_CContent* CBitmapPart::NewPartContent(Environment* ev)
  206. {
  207.     fBitmapContent = FW_NEW(CBitmapContent, (ev, this));
  208.     return fBitmapContent;
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. //    CBitmapPart::DoMenu
  213. //----------------------------------------------------------------------------------------
  214. // ODF method
  215.  
  216. FW_Boolean CBitmapPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  217. {
  218.     FW_Boolean result = TRUE;
  219.     
  220.     if (theMenuEvent.GetCommandID(ev) == kODCommandAbout)
  221.         ::FW_About(ev, this, kAbout);
  222.     else
  223.         result = FALSE;
  224.         
  225.     return result;
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. // CBitmapPart::PartChanged
  230. //----------------------------------------------------------------------------------------
  231.  
  232. void CBitmapPart::PartChanged(Environment* ev)
  233. {
  234.     // ----- Mark the document's draft as changed so it can be saved
  235.     this->Changed(ev);
  236.  
  237.     // ----- Mark the display frames as changed, so that containing parts can update links
  238.     fBitmapPresentation->ContentUpdated(ev);
  239.  
  240.     // ----- Force all display frames to be redrawn
  241.     fBitmapPresentation->Invalidate(ev);
  242.     
  243.     // ----- Force thumbnail to be recalculated -----
  244.     fBitmapPresentation->UpdateViewAs(ev);
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    CBitmapPart::NewFrame
  249. //----------------------------------------------------------------------------------------
  250. // ODF Method
  251.  
  252. FW_CFrame* CBitmapPart::NewFrame(Environment* ev,
  253.                                  ODFrame* odFrame, 
  254.                                  FW_CPresentation* presentation,
  255.                                     FW_Boolean fromStorage)
  256. {
  257.     FW_UNUSED(fromStorage);
  258.     FW_ASSERT(presentation == fBitmapPresentation);
  259.  
  260.     return FW_NEW(CBitmapFrame, (ev, odFrame, presentation, this, fBitmapContent));
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    CBitmapPart::AdjustFramesSize
  265. //----------------------------------------------------------------------------------------
  266. //    Bitmap Part Method
  267.  
  268. void CBitmapPart::AdjustFramesSize(Environment* ev)
  269. {
  270.     FW_CPartFrameIterator ite(ev, this);
  271.     for (CBitmapFrame* frame = (CBitmapFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (CBitmapFrame*)ite.Next(ev))
  272.     {
  273.         frame->AdjustFrameSize(ev);
  274.     }
  275. }
  276.