home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Container / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  8.0 KB  |  283 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef BINDING_K
  17. #include "Binding.k"
  18. #endif
  19.  
  20. #ifndef DEFINES_K
  21. #include "Defines.k"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef COMMANDS_H
  37. #include "Commands.h"
  38. #endif
  39.  
  40. #ifndef PROXY_H
  41. #include "Proxy.h"
  42. #endif
  43.  
  44. #ifndef VIEW_H
  45. #include "View.h"
  46. #endif
  47.  
  48. // ----- Part Layer -----
  49.  
  50. #ifndef FWABOUT_H
  51. #include "FWAbout.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWUTIL_H
  59. #include "FWUtil.h"
  60. #endif
  61.  
  62. #ifndef FWPRTITE_H
  63. #include "FWPrtIte.h"
  64. #endif
  65.  
  66. // ----- OS Layer -----
  67.  
  68. #ifndef FWRECT_H
  69. #include "FWRect.h"
  70. #endif
  71.  
  72. #ifndef FWMENU_H
  73. #include "FWMenu.h"
  74. #endif
  75.  
  76. #ifndef FWCFMRES_H
  77. #include "FWCFMRes.h"
  78. #endif
  79.  
  80. // ----- OpenDoc Includes -----
  81.  
  82. #ifndef SOM_ODSession_xh
  83. #include <ODSessn.xh>
  84. #endif
  85.  
  86. #ifndef SOM_Module_OpenDoc_StdProps_defined
  87. #include <StdProps.xh>
  88. #endif
  89.  
  90. //========================================================================================
  91. // Runtime Information
  92. //========================================================================================
  93.  
  94. #ifdef FW_BUILD_MAC
  95. #pragma segment odfcontainer
  96. #endif
  97.  
  98. //========================================================================================
  99. //    Globals
  100. //========================================================================================
  101.  
  102. FW_DEFINE_CLASS_M1(CContainerPart, FW_CEmbeddingPart)
  103. FW_DEFINE_AUTO(CContainerPart)
  104.  
  105. //========================================================================================
  106. //    class CContainerPart
  107. //========================================================================================
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    CContainerPart::CContainerPart
  111. //----------------------------------------------------------------------------------------
  112.  
  113. CContainerPart::CContainerPart(ODPart* odPart) :
  114.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID)
  115. {
  116.     fPartContent = NULL;
  117.     fMainPresentation = NULL;
  118.     
  119.     FW_END_CONSTRUCTOR
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CContainerPart::~CContainerPart
  124. //----------------------------------------------------------------------------------------
  125.  
  126. CContainerPart::~CContainerPart()
  127. {
  128.     FW_START_DESTRUCTOR
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    CContainerPart::Initialize
  133. //----------------------------------------------------------------------------------------
  134.  
  135. void CContainerPart::Initialize(Environment* ev)
  136. {
  137.     // ----- Call Inherited Initialize -----
  138.     FW_CEmbeddingPart::Initialize(ev);
  139.  
  140.     fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
  141.  
  142.     // ----- Initialize the menu bar
  143.     // We instantiate a submenu item from the stream so we must
  144.     // prevent it from being deadstripped.
  145.     FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
  146.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  147.  
  148.     // ----- Tokenize -----
  149.     fContainerSelection = FW_NEW(CContainerSelection, (ev, this));    // Attention I don't own the selection the presentation will
  150.     
  151.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fContainerSelection);
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    CContainerPart::NewPartContent
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_CContent* CContainerPart::NewPartContent(Environment* ev)
  159. {
  160.     fPartContent = FW_NEW(CPartContent, (ev, this));
  161.     return fPartContent;
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    CContainerPart::AddProxyToPart
  166. //----------------------------------------------------------------------------------------
  167.  
  168. void CContainerPart::AddProxyToPart(Environment* ev, CProxy* proxy)
  169. {
  170.     fPartContent->AddProxy(ev, proxy);
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    CContainerPart::DetachProxy
  175. //----------------------------------------------------------------------------------------
  176. //    At the end the embedded frames associated with 'proxy' will be in limbo
  177.  
  178. void CContainerPart::DetachProxy(Environment* ev, CProxy* proxy)
  179. {
  180.     fPartContent->RemoveProxy(ev, proxy);
  181.     proxy->DetachEmbeddedFrames(ev);        // Set embedded frames to in limbo state
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    CContainerPart::DeleteProxy
  186. //----------------------------------------------------------------------------------------
  187. //    At the end the embedded frames are completly gone
  188.  
  189. void CContainerPart::DeleteProxy(Environment* ev, CProxy* proxy)
  190. {
  191.     DetachProxy(ev, proxy);
  192.     delete proxy;
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. // CContainerPart::AttachProxy
  197. //----------------------------------------------------------------------------------------
  198. //    Put back (for example after Undo) a proxy that has been detached
  199.  
  200. void CContainerPart::AttachProxy(Environment* ev, CProxy* proxy)
  201. {
  202.     AddProxyToPart(ev, proxy);    
  203.     proxy->AttachEmbeddedFrames(ev);
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    CContainerPart::DoMenu
  208. //----------------------------------------------------------------------------------------
  209.  
  210. FW_Boolean CContainerPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  211. {
  212.     FW_Boolean result = TRUE;
  213.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  214.  
  215.     switch (commandID)
  216.     {
  217.         case kODCommandAbout:
  218.             ::FW_About(ev, this, kAbout);
  219.             break;
  220.         default:
  221.             result = false;        
  222.     }
  223.     
  224.     return result;
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    CContainerPart::NewFrame
  229. //----------------------------------------------------------------------------------------
  230.  
  231. FW_CFrame* CContainerPart::NewFrame(Environment* ev, 
  232.                                 ODFrame* odFrame, 
  233.                                 FW_CPresentation* presentation,
  234.                                 FW_Boolean fromStorage)
  235. {
  236.     return FW_NEW(CContainerFrame, (ev, odFrame, presentation, this, kContainerView));
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    CDrawPart::DoAdjustMenus
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_Boolean CContainerPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  244. {
  245.     if (hasMenuFocus)
  246.         menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountProxies() > 0);
  247.  
  248.     return false;
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. // CContainerPart::WhichProxy
  253. //----------------------------------------------------------------------------------------
  254.  
  255. CProxy* CContainerPart::WhichProxy(Environment* ev, FW_CGraphicContext& gc, 
  256.                 const FW_CPoint& where, FW_Boolean hasToBeSelected) const
  257. {
  258.     CContentProxyIterator ite(fPartContent);
  259.     for (CProxy* proxy = ite.Last(); ite.IsNotComplete(); proxy = ite.Previous())
  260.     {
  261.         FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && proxy->IsSelected());
  262.         if (test && proxy->HitTest(ev, gc, where))
  263.             return proxy;    
  264.     }
  265.     
  266.     return NULL;
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. // CContainerPart::EmbeddedFrameRemoved
  271. //----------------------------------------------------------------------------------------
  272.  
  273. void CContainerPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
  274. {
  275.     CProxy* theProxy = (CProxy*)proxy;
  276.     
  277.     FW_CAcquiredODShape updateShape = ::FW_NewODShape(ev);
  278.     theProxy->GetUpdateBox(ev, updateShape);    
  279.     theProxy->GetPresentation(ev)->Invalidate(ev, updateShape);
  280.     
  281.     DeleteProxy(ev, theProxy);
  282. }
  283.