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 / ODF / Framewrk / FWPart / Sources / FWPartng.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.9 KB  |  401 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPartng.cpp
  4. //    Release Version:    $ ODF 1 $
  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 FWPRSTNG_H
  21. #include "FWPrstng.h"
  22. #endif
  23.  
  24. #ifndef FWPRTITE_H
  25. #include "FWPrtIte.h"
  26. #endif
  27.  
  28. #ifndef FWSELECT_H
  29. #include "FWSelect.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWFRMING_H
  37. #include "FWFrming.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. // ----- OpenDoc Utilites -----
  77.  
  78. #ifndef _INFOUTIL_
  79. #include "InfoUtil.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_Commands_defined
  85. #include <CmdDefs.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODSession_xh
  89. #include <ODSessn.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODStorageUnitView_xh
  93. #include <SUView.xh>
  94. #endif
  95.  
  96. #ifndef SOM_Module_OpenDoc_Foci_defined
  97. #include <Foci.xh>
  98. #endif
  99.  
  100. #ifndef SOM_Module_OpenDoc_StdProps_defined
  101. #include <StdProps.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODDraft_xh
  105. #include <Draft.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODClipboard_xh
  109. #include <Clipbd.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODArbitrator_xh
  113. #include <Arbitrat.xh>
  114. #endif
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  117. #include <StdTypes.xh>
  118. #endif
  119.  
  120. #ifdef FW_BUILD_WIN
  121.  
  122. #include <plfmdef.h>
  123. #include <t_regist.h>
  124.  
  125. #endif
  126.  
  127. //========================================================================================
  128. // RunTime Info
  129. //========================================================================================
  130.  
  131. #ifdef FW_BUILD_MAC
  132. #pragma segment fw_embedding
  133. #endif
  134.  
  135. FW_DEFINE_CLASS_M1(FW_CEmbeddingPart, FW_CPart)
  136.  
  137. //========================================================================================
  138. //    class FW_CEmbeddingPart
  139. //========================================================================================
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    FW_CEmbeddingPart::FW_CEmbeddingPart    
  143. //----------------------------------------------------------------------------------------
  144.  
  145. FW_CEmbeddingPart::FW_CEmbeddingPart(ODPart* odPart, 
  146.                                     FW_Instance partInstance,
  147.                                     FW_ResourceId partInfoID) :
  148.     FW_CPart(odPart, partInstance, partInfoID),
  149.     fProxys(NULL),
  150.     fNextFrameGroup(0)
  151. #ifdef FW_BUILD_WIN
  152.     ,fWinEmbedMenu(NULL)
  153. #endif
  154. {
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    FW_CEmbeddingPart::~FW_CEmbeddingPart    
  159. //----------------------------------------------------------------------------------------
  160.  
  161. FW_CEmbeddingPart::~FW_CEmbeddingPart()
  162. {    
  163. }
  164.  
  165. //---------------------------------------------------------------------------------------
  166. //    FW_CEmbeddingPart::LinkStatusChanged
  167. //---------------------------------------------------------------------------------------
  168.  
  169. void FW_CEmbeddingPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
  170. {
  171.     // The following code is default behavior for parts that don't create links.
  172.  
  173.     FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
  174.     if (frame)
  175.     {
  176.         ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
  177.  
  178.         // You only need to propagate linkStatus to embedded frames that don't participate in
  179.         // any of this part's links; otherwise their local link status takes precedence.
  180.  
  181.         FW_CPartEmbeddedFrameIterator iter(ev, this);
  182.         for (ODFrame* odEmbeddedFrame = iter.First(ev); iter.IsNotComplete(ev); odEmbeddedFrame = iter.Next(ev))
  183.             odEmbeddedFrame->ChangeLinkStatus(ev, linkStatus);
  184.     }
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    FW_CEmbeddingPart::ReleaseAll
  189. //----------------------------------------------------------------------------------------
  190. //    Call inherited first when overrided
  191.  
  192. void FW_CEmbeddingPart::ReleaseAll(Environment *ev)
  193. {
  194.     // ----- Release all display Frames
  195.     if (fProxys)
  196.     {
  197.         FW_CPartProxyIterator ite(this);
  198.         for (FW_MProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  199.         {
  200.             proxy->ReleaseAll(ev);
  201.         }
  202.     }
  203.  
  204.     FW_CPart::ReleaseAll(ev);
  205. }
  206.  
  207. //---------------------------------------------------------------------------------------
  208. //    FW_CEmbeddingPart::GetProxy
  209. //---------------------------------------------------------------------------------------
  210.  
  211. FW_MProxy* FW_CEmbeddingPart::GetProxy(Environment* ev, ODFrame* embeddedFrame) const
  212. {
  213.     FW_ASSERT(embeddedFrame != NULL);
  214.     
  215.     ODID embeddedFrameID = embeddedFrame->GetID(ev);
  216.     
  217.     FW_CPartProxyFrameIterator ite(this);
  218.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  219.     {
  220.         if (proxyFrame->GetFrameID(ev) == embeddedFrameID)
  221.             return proxyFrame->GetProxy(ev);
  222.     }
  223.     
  224.     return NULL;
  225. }
  226.  
  227. //---------------------------------------------------------------------------------------
  228. //    FW_CEmbeddingPart::PrivAddProxy
  229. //---------------------------------------------------------------------------------------
  230.  
  231. void FW_CEmbeddingPart::PrivAddProxy(Environment* ev, FW_MProxy* proxy)
  232. {
  233. FW_UNUSED(ev);
  234.     if (fProxys == NULL)
  235.         fProxys = FW_NEW(FW_TOrderedCollection<FW_MProxy>, ());
  236.  
  237.     fProxys->AddLast(proxy);
  238. }
  239.  
  240. //---------------------------------------------------------------------------------------
  241. //    FW_CEmbeddingPart::PrivRemoveProxy
  242. //---------------------------------------------------------------------------------------
  243.  
  244. void FW_CEmbeddingPart::PrivRemoveProxy(Environment* ev, FW_MProxy* proxy)
  245. {
  246. FW_UNUSED(ev);
  247.     FW_ASSERT(fProxys);
  248.     
  249.     fProxys->Remove(proxy);
  250.     if (fProxys->Count() == 0)
  251.     {
  252.         delete fProxys;
  253.         fProxys = NULL;
  254.     }    
  255. }
  256.  
  257. //---------------------------------------------------------------------------------------
  258. //    FW_CEmbeddingPart::CloneInto
  259. //---------------------------------------------------------------------------------------
  260.  
  261. void FW_CEmbeddingPart::PrivCloneInto(Environment *ev,
  262.                                     ODDraftKey key,
  263.                                     ODStorageUnit* toSU,
  264.                                     ODFrame* scope)
  265. {
  266.     ODStorageUnit* su = GetStorageUnit(ev);
  267.     ODDraft* fromDraft = su->GetDraft(ev);
  268.  
  269.     FW_ASSERT((scope == NULL) || (scope != NULL && IsValidDisplayFrame(ev, scope->GetID(ev))));
  270.  
  271.     FW_CFrame *frame = scope == NULL ? NULL : FW_CFrame::ODtoFWFrame(ev, scope);
  272.     FW_ASSERT((scope == NULL) || (scope != NULL && frame != NULL));
  273.     
  274.     FW_CCloneInfo cloneInfo(ev, key, fromDraft, frame, 0);        // fromDraft->GetCloneKind(ev)
  275.     
  276.     // ----- Externalize the content -----
  277.     ExternalizeContent(ev, toSU, &cloneInfo);
  278. }
  279.  
  280. //----------------------------------------------------------------------------------------
  281. //    FW_CEmbeddingPart::PrivNewPresentation    
  282. //----------------------------------------------------------------------------------------
  283.  
  284. FW_CPresentation* FW_CEmbeddingPart::PrivNewPresentation(Environment* ev, 
  285.                                                     FW_CSelection* selection,
  286.                                                     ODTypeToken presentationType)
  287. {
  288.     return new FW_CEmbeddingPresentation(ev, this, selection, presentationType);
  289. }
  290.  
  291. //---------------------------------------------------------------------------------------
  292. //    FW_CEmbeddingPart::PrivNewDataInterchange
  293. //---------------------------------------------------------------------------------------
  294.  
  295. FW_CDataInterchange* FW_CEmbeddingPart::PrivNewDataInterchange(Environment* ev)
  296. {
  297.     return new FW_CEmbeddingDataInterchange(ev, this);
  298. }
  299.  
  300. //---------------------------------------------------------------------------------------
  301. //    FW_CEmbeddingPart::EmbeddedFrameRemoved
  302. //---------------------------------------------------------------------------------------
  303.  
  304. void FW_CEmbeddingPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
  305. {
  306. FW_UNUSED(ev);
  307. FW_UNUSED(proxy);
  308.     FW_DEBUG_MESSAGE("Your part needs to implement FW_CEmbeddingPart::EmbeddedFrameRemoved");
  309. }
  310.                     
  311. //---------------------------------------------------------------------------------------
  312. //    FW_CEmbeddingPart::PrivSetNextFrameGroup
  313. //---------------------------------------------------------------------------------------
  314. // Call by FW_MProxy::Internalize
  315.  
  316. void FW_CEmbeddingPart::PrivSetNextFrameGroup(Environment *ev, ODID frameGroup)
  317. {
  318. FW_UNUSED(ev);
  319.     if (frameGroup > fNextFrameGroup)
  320.         fNextFrameGroup = frameGroup;
  321. }
  322.  
  323. #ifdef FW_BUILD_WIN
  324. //------------------------------------------------------------------------------
  325. //    FW_CEmbeddingPart::WinAddEmbedMenu
  326. //------------------------------------------------------------------------------
  327.  
  328. void FW_CEmbeddingPart::WinAddEmbedMenu(Environment *ev, FW_CMenuBar *menuBar)
  329. {
  330.     ODPartRegistryIterator    iter;
  331.     ODPartRegistryData        data;
  332.     char                     partString[50];
  333.     LPSTR                    partPtr, tmpPtr;
  334.  
  335.     unsigned short partCount = -1;     //TAG - this will increment the 1st time to 0 to
  336.                                     //        exclude the omnipresent IDM_DRAW part...
  337.                                     
  338.     unsigned short stringIndex = 0;    //    This indexes into part type string buffer.
  339.     fWinFirstPartID = FW_kFirstUserCommandID + 0x8000;
  340.     
  341.     fWinEmbedMenu = new FW_CPullDownMenu(ev, FW_CString32("Embed"));
  342.  
  343.     for (iter.First(kODTrue,&data);iter.IsNotComplete();iter.Next(&data)) 
  344.     {
  345.         partCount++;
  346.  
  347.         //    Keep the last word of the partKind
  348.         FW_PrimitiveStringCopy(data.partKind, partPtr=partString);
  349.         tmpPtr = partPtr;
  350.         while (tmpPtr != NULL)
  351.         {
  352.             tmpPtr = FW_PrimitiveStringFindCharacter(partPtr, ':');
  353.             if (tmpPtr != NULL)
  354.                 partPtr = ++tmpPtr;
  355.         }
  356.         
  357.         FW_CString255 name(partPtr);
  358.         fWinEmbedMenu->AppendTextItem(ev, name, fWinFirstPartID + partCount);
  359.         
  360.         fTypePtr[partCount] = &(fTypeString[stringIndex]);
  361.         FW_PrimitiveStringCopy(data.partKind, fTypePtr[partCount]);
  362.         stringIndex += FW_PrimitiveStringLength(fTypePtr[partCount]) + 1;
  363.     }
  364.     fWinLastPartID = fWinFirstPartID + partCount;
  365.  
  366.     menuBar->AdoptMenuLast(ev, fWinEmbedMenu);
  367. }
  368. #endif
  369.  
  370. #ifdef FW_BUILD_WIN
  371. //----------------------------------------------------------------------------------------
  372. //    FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand
  373. //----------------------------------------------------------------------------------------
  374.  
  375. ODPart* FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand(Environment* ev, ODCommandID commandID)
  376. {
  377.     if ((commandID >= fWinFirstPartID) && (commandID <= fWinLastPartID))
  378.     {
  379.         return GetDraft(ev)->CreatePart(ev, fTypePtr[commandID - fWinFirstPartID], NULL);
  380.     }
  381.     
  382.     return NULL;
  383. }
  384. #endif
  385.  
  386. #ifdef FW_BUILD_WIN
  387. //----------------------------------------------------------------------------------------
  388. //    FW_CEmbeddingPart::WinEnableEmbedMenu
  389. //----------------------------------------------------------------------------------------
  390.  
  391. void FW_CEmbeddingPart::WinEnableEmbedMenu(Environment* ev, FW_CMenuBar* menuBar)
  392. {
  393.     if (fWinEmbedMenu != NULL && fWinEmbedMenu->GetMenuBar(ev) == menuBar)
  394.     {
  395.         fWinEmbedMenu->EnableAll(ev);
  396.     }
  397. }
  398. #endif
  399.  
  400.  
  401.