home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWPartng.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  12.2 KB  |  441 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPartng.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPARTNG_H
  13. #include "FWPartng.h"
  14. #endif
  15.  
  16. #ifndef FWUTIL_H
  17. #include "FWUtil.h"
  18. #endif
  19.  
  20. #ifndef FWPRTITE_H
  21. #include "FWPrtIte.h"
  22. #endif
  23.  
  24. #ifndef FWSELECT_H
  25. #include "FWSelect.h"
  26. #endif
  27.  
  28. #ifndef FWITERS_H
  29. #include "FWIters.h"
  30. #endif
  31.  
  32. #ifndef FWFRMING_H
  33. #include "FWFrming.h"
  34. #endif
  35.  
  36. #ifndef FWCNTPRP_H
  37. #include "FWCntPrp.h"
  38. #endif
  39.  
  40. #ifndef FWPXYFRM_H
  41. #include "FWPxyFrm.h"
  42. #endif
  43.  
  44. #ifndef FWLNKMGR_H
  45. #include "FWLnkMgr.h"
  46. #endif
  47.  
  48. #ifndef FWCMD_H
  49. #include "FWCmd.h"
  50. #endif
  51.  
  52. #ifndef FWPROXY_H
  53. #include "FWProxy.h"
  54. #endif
  55.  
  56. #ifndef FWPRMISE_H
  57. #include "FWPrmise.h"
  58. #endif
  59.  
  60. #ifndef FWMNUBAR_H
  61. #include "FWMnuBar.h"
  62. #endif
  63.  
  64. #ifndef FWACQUIR_H
  65. #include "FWAcquir.h"
  66. #endif
  67.  
  68. #ifndef FWCLNINF_H
  69. #include "FWClnInf.h"
  70. #endif
  71.  
  72. #ifndef FWINTRNG_H
  73. #include "FWIntrng.h"
  74. #endif
  75.  
  76. #ifndef FWCONTNT_H
  77. #include "FWContnt.h"
  78. #endif
  79.  
  80. // ----- OD Utils -----
  81.  
  82. #ifndef _STDTYPIO_
  83. #include "StdTypIO.h"
  84. #endif
  85.  
  86. // ----- OpenDoc Includes -----
  87.  
  88. #ifndef SOM_Module_OpenDoc_Commands_defined
  89. #include <CmdDefs.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODSession_xh
  93. #include <ODSessn.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODStorageUnitView_xh
  97. #include <SUView.xh>
  98. #endif
  99.  
  100. #ifndef SOM_Module_OpenDoc_Foci_defined
  101. #include <Foci.xh>
  102. #endif
  103.  
  104. #ifndef SOM_Module_OpenDoc_StdProps_defined
  105. #include <StdProps.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODDraft_xh
  109. #include <Draft.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODClipboard_xh
  113. #include <Clipbd.xh>
  114. #endif
  115.  
  116. #ifndef SOM_ODArbitrator_xh
  117. #include <Arbitrat.xh>
  118. #endif
  119.  
  120. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  121. #include <StdTypes.xh>
  122. #endif
  123.  
  124. #ifdef FW_BUILD_WIN
  125.  
  126. #include <plfmdef.h>
  127. #include <t_regist.h>
  128.  
  129. #endif
  130.  
  131. //========================================================================================
  132. // RunTime Info
  133. //========================================================================================
  134.  
  135. #ifdef FW_BUILD_MAC
  136. #pragma segment fw_embedding
  137. #endif
  138.  
  139. FW_DEFINE_CLASS_M1(FW_CEmbeddingPart, FW_CPart)
  140.  
  141. //========================================================================================
  142. //    class FW_CEmbeddingPart
  143. //========================================================================================
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CEmbeddingPart::FW_CEmbeddingPart    
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CEmbeddingPart::FW_CEmbeddingPart(ODPart* odPart, 
  150.                                     FW_Instance partInstance,
  151.                                     FW_ResourceID partInfoID) :
  152.     FW_CPart(odPart, partInstance, partInfoID),
  153.     fProxys(NULL),
  154.     fNextFrameGroup(0)
  155. #ifdef FW_BUILD_WIN
  156.     ,fWinEmbedMenu(NULL)
  157. #endif
  158. {
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_CEmbeddingPart::~FW_CEmbeddingPart    
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CEmbeddingPart::~FW_CEmbeddingPart()
  166. {    
  167. }
  168.  
  169. //---------------------------------------------------------------------------------------
  170. //    FW_CEmbeddingPart::LinkStatusChanged
  171. //---------------------------------------------------------------------------------------
  172.  
  173. void FW_CEmbeddingPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
  174. {
  175.     // The following code is default behavior for parts that don't create links.
  176.  
  177.     FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
  178.     if (frame)
  179.     {
  180.         ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
  181.  
  182.         // You only need to propagate linkStatus to embedded frames that don't participate in
  183.         // any of this part's links; otherwise their local link status takes precedence.
  184.  
  185.         FW_CPartEmbeddedFrameIterator iter(ev, this);
  186.         for (ODFrame* odEmbeddedFrame = iter.First(ev); iter.IsNotComplete(ev); odEmbeddedFrame = iter.Next(ev))
  187.             odEmbeddedFrame->ChangeLinkStatus(ev, linkStatus);
  188.     }
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    FW_CEmbeddingPart::ReleaseAll
  193. //----------------------------------------------------------------------------------------
  194. //    Call inherited first when overrided
  195.  
  196. void FW_CEmbeddingPart::ReleaseAll(Environment *ev)
  197. {
  198.     // ----- Release all display Frames
  199.     if (fProxys)
  200.     {
  201.         FW_CPartProxyIterator ite(this);
  202.         for (FW_MProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  203.         {
  204.             proxy->ReleaseAll(ev);
  205.         }
  206.     }
  207.  
  208.     FW_CPart::ReleaseAll(ev);
  209. }
  210.  
  211. //---------------------------------------------------------------------------------------
  212. //    FW_CEmbeddingPart::GetProxy
  213. //---------------------------------------------------------------------------------------
  214.  
  215. FW_MProxy* FW_CEmbeddingPart::GetProxy(Environment* ev, ODFrame* embeddedFrame) const
  216. {
  217.     FW_ASSERT(embeddedFrame != NULL);
  218.     
  219.     ODID embeddedFrameID = embeddedFrame->GetID(ev);
  220.     
  221.     FW_CPartProxyFrameIterator ite(this);
  222.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  223.     {
  224.         if (proxyFrame->GetFrameID(ev) == embeddedFrameID)
  225.             return proxyFrame->GetProxy(ev);
  226.     }
  227.     
  228.     return NULL;
  229. }
  230.  
  231. //---------------------------------------------------------------------------------------
  232. //    FW_CEmbeddingPart::CloneInto
  233. //---------------------------------------------------------------------------------------
  234.  
  235. void FW_CEmbeddingPart::CloneInto(Environment *ev,
  236.                                     ODDraftKey key,
  237.                                     ODStorageUnit* toSU,
  238.                                     ODFrame* scope)
  239. {
  240.     // avoid changing the header for now, if it works, then delete this method
  241.     FW_CPart::CloneInto(ev, key, toSU, scope);
  242.  
  243. #ifdef DEADCODE 
  244.     ODStorageUnit* su = GetStorageUnit(ev);
  245.     ODDraft* fromDraft = su->GetDraft(ev);
  246.  
  247.     FW_ASSERT((scope == NULL) || (scope != NULL && IsValidDisplayFrame(ev, scope->GetID(ev))));
  248.  
  249.     FW_CFrame *frame = scope == NULL ? NULL : FW_CFrame::ODtoFWFrame(ev, scope);
  250.     FW_ASSERT((scope == NULL) || (scope != NULL && frame != NULL));
  251.     
  252.     FW_CCloneInfo cloneInfo(ev, key, fromDraft, frame, 0);        // fromDraft->GetCloneKind(ev)
  253.     
  254.     // ----- Prepare the storage Unit and Externalize the content -----
  255.     FW_ASSERT(toSU->GetDraft(ev)->GetPermissions(ev) >= kODDPSharedWrite);
  256.     PrepContentProperty(ev, toSU, FW_kPartStorage, TRUE);
  257.     FW_CContent* content = GetContent(ev);
  258.     if (content)
  259.         content->Externalize(ev, toSU, FW_kPartStorage, &cloneInfo);
  260. #endif
  261. }
  262.  
  263. //---------------------------------------------------------------------------------------
  264. //    FW_CEmbeddingPart::PrivAddProxy
  265. //---------------------------------------------------------------------------------------
  266.  
  267. void FW_CEmbeddingPart::PrivAddProxy(Environment* ev, FW_MProxy* proxy)
  268. {
  269. FW_UNUSED(ev);
  270.     if (fProxys == NULL)
  271.         fProxys = FW_NEW(FW_TOrderedCollection<FW_MProxy>, ());
  272.  
  273.     fProxys->AddLast(proxy);
  274. }
  275.  
  276. //---------------------------------------------------------------------------------------
  277. //    FW_CEmbeddingPart::PrivRemoveProxy
  278. //---------------------------------------------------------------------------------------
  279.  
  280. void FW_CEmbeddingPart::PrivRemoveProxy(Environment* ev, FW_MProxy* proxy)
  281. {
  282. FW_UNUSED(ev);
  283.     FW_ASSERT(fProxys);
  284.     
  285.     fProxys->Remove(proxy);
  286.     if (fProxys->Count() == 0)
  287.     {
  288.         delete fProxys;
  289.         fProxys = NULL;
  290.     }    
  291. }
  292.  
  293. //---------------------------------------------------------------------------------------
  294. //    FW_CEmbeddingPart::NewDataInterchange
  295. //---------------------------------------------------------------------------------------
  296.  
  297. FW_CDataInterchange* FW_CEmbeddingPart::NewDataInterchange(Environment* ev)
  298. {
  299.     return new FW_CEmbeddingDataInterchange(ev, this);
  300. }
  301.  
  302. //---------------------------------------------------------------------------------------
  303. //    FW_CEmbeddingPart::Purge
  304. //---------------------------------------------------------------------------------------
  305.  
  306. ODSize FW_CEmbeddingPart::Purge(Environment *ev, ODSize size)
  307. {
  308.     ODSize freedSize = FW_CPart::Purge(ev, size);
  309.     
  310.     // ----- Try purging all purgeable embedded frames -----
  311.     FW_CPartProxyIterator ite(this);
  312.     for (FW_MProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  313.     {
  314.         freedSize += proxy->Purge(ev);
  315.     }
  316.     
  317.     return freedSize;
  318. }
  319.  
  320. //---------------------------------------------------------------------------------------
  321. //    FW_CEmbeddingPart::AcquireContainingPartProperties
  322. //---------------------------------------------------------------------------------------
  323.  
  324. ODStorageUnit* FW_CEmbeddingPart::AcquireContainingPartProperties(Environment* ev, 
  325.                                                                 ODFrame* embeddedFrame)
  326. {
  327.     ODStorageUnit *su = NULL;
  328.     
  329.     FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  330.     FW_CEmbeddingFrame* embeddingFrame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, aqContainingFrame);
  331.  
  332.     FW_MContainingPropertiesFrame* containingProps = FW_DYNAMIC_CAST(FW_MContainingPropertiesFrame, embeddingFrame);
  333.     
  334.     if (containingProps != NULL)
  335.         su = containingProps->AcquirePropertiesStorage(ev, GetDraft(ev));
  336.         
  337.     return su;
  338. }
  339.  
  340. //---------------------------------------------------------------------------------------
  341. //    FW_CEmbeddingPart::EmbeddedFrameRemoved
  342. //---------------------------------------------------------------------------------------
  343.  
  344. void FW_CEmbeddingPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
  345. {
  346. FW_UNUSED(ev);
  347. FW_UNUSED(proxy);
  348.     FW_DEBUG_MESSAGE("Your part needs to implement FW_CEmbeddingPart::EmbeddedFrameRemoved");
  349. }
  350.                     
  351. //---------------------------------------------------------------------------------------
  352. //    FW_CEmbeddingPart::PrivSetNextFrameGroup
  353. //---------------------------------------------------------------------------------------
  354. // Call by FW_MProxy::Internalize
  355.  
  356. void FW_CEmbeddingPart::PrivSetNextFrameGroup(Environment *ev, ODID frameGroup)
  357. {
  358. FW_UNUSED(ev);
  359.     if (frameGroup > fNextFrameGroup)
  360.         fNextFrameGroup = frameGroup;
  361. }
  362.  
  363. #ifdef FW_BUILD_WIN
  364. //------------------------------------------------------------------------------
  365. //    FW_CEmbeddingPart::WinAddEmbedMenu
  366. //------------------------------------------------------------------------------
  367.  
  368. void FW_CEmbeddingPart::WinAddEmbedMenu(Environment *ev, FW_CMenuBar *menuBar)
  369. {
  370.     ODPartRegistryIterator    iter;
  371.     ODPartRegistryData        data;
  372.     char                     partString[50];
  373.     LPSTR                    partPtr, tmpPtr;
  374.  
  375.     unsigned short partCount = -1;     //TAG - this will increment the 1st time to 0 to
  376.                                     //        exclude the omnipresent IDM_DRAW part...
  377.                                     
  378.     unsigned short stringIndex = 0;    //    This indexes into part type string buffer.
  379.     fWinFirstPartID = FW_kFirstUserCommandID + 0x8000;
  380.     
  381.     fWinEmbedMenu = new FW_CPullDownMenu(ev, FW_CString32("Embed"));
  382.  
  383.     for (iter.First(kODTrue,&data);iter.IsNotComplete();iter.Next(&data)) 
  384.     {
  385.         partCount++;
  386.  
  387.         //    Keep the last word of the partKind
  388.         FW_PrimitiveStringCopy(data.partKind, partPtr=partString);
  389.         tmpPtr = partPtr;
  390.         while (tmpPtr != NULL)
  391.         {
  392.             tmpPtr = FW_PrimitiveStringFindCharacter(partPtr, ':');
  393.             if (tmpPtr != NULL)
  394.                 partPtr = ++tmpPtr;
  395.         }
  396.         
  397.         FW_CString255 name(partPtr);
  398.         fWinEmbedMenu->AppendTextItem(ev, name, fWinFirstPartID + partCount);
  399.         
  400.         fTypePtr[partCount] = &(fTypeString[stringIndex]);
  401.         FW_PrimitiveStringCopy(data.partKind, fTypePtr[partCount]);
  402.         stringIndex += FW_PrimitiveStringLength(fTypePtr[partCount]) + 1;
  403.     }
  404.     fWinLastPartID = fWinFirstPartID + partCount;
  405.  
  406.     menuBar->AdoptMenuLast(ev, fWinEmbedMenu);
  407. }
  408. #endif
  409.  
  410. #ifdef FW_BUILD_WIN
  411. //----------------------------------------------------------------------------------------
  412. //    FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand
  413. //----------------------------------------------------------------------------------------
  414.  
  415. ODPart* FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand(Environment* ev, ODCommandID commandID)
  416. {
  417.     if ((commandID >= fWinFirstPartID) && (commandID <= fWinLastPartID))
  418.     {
  419.         return GetDraft(ev)->CreatePart(ev, fTypePtr[commandID - fWinFirstPartID], NULL);
  420.     }
  421.     
  422.     return NULL;
  423. }
  424. #endif
  425.  
  426. #ifdef FW_BUILD_WIN
  427. //----------------------------------------------------------------------------------------
  428. //    FW_CEmbeddingPart::WinEnableEmbedMenu
  429. //----------------------------------------------------------------------------------------
  430.  
  431. void FW_CEmbeddingPart::WinEnableEmbedMenu(Environment* ev, FW_CMenuBar* menuBar)
  432. {
  433.     if (fWinEmbedMenu != NULL && fWinEmbedMenu->GetMenuBar(ev) == menuBar)
  434.     {
  435.         fWinEmbedMenu->EnableAll(ev);
  436.     }
  437. }
  438. #endif
  439.  
  440.  
  441.