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 / FWSemEvt / FWPrtScp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.8 KB  |  351 lines  |  [TEXT/MPS ]

  1.  
  2. //========================================================================================
  3. //
  4. //    File:                FWSemPrt.cpp
  5. //    Release Version:    $ ODF 2 $
  6. //
  7. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  8. //
  9. //========================================================================================
  10.  
  11. #ifndef FWPRTSCP_H
  12. #include "FWPrtScp.h"
  13. #endif
  14.  
  15. // ----- Framework Includes -----
  16.  
  17. #ifndef FWPART_H
  18. #include "FWPart.h"
  19. #endif
  20.  
  21. #ifndef FWDESC_H
  22. #include "FWDesc.h"
  23. #endif
  24.  
  25. #ifndef FWDSCOPR_H
  26. #include "FWDscOpr.h"
  27. #endif
  28.  
  29. #ifndef FWFRAME_H
  30. #include "FWFrame.h"
  31. #endif
  32.  
  33. #ifndef FWOBJSPC_H
  34. #include "FWObjSpc.h"
  35. #endif
  36.  
  37. #ifndef FWPRTITE_H
  38. #include "FWPrtIte.h"
  39. #endif
  40.  
  41. // ----- Foundation Includes -----
  42.  
  43. #ifndef FWPSTR_H
  44. #include "FWPStr.h"
  45. #endif
  46.  
  47. // ----- OpenDoc Includes -----
  48.  
  49. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  50. #include <ODRgstry.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODObjectSpec_xh
  54. #include <ODObjSpc.xh>
  55. #endif
  56.  
  57. // ----- Macintosh Includes -----
  58.  
  59. #ifndef __AEOBJECTS__
  60. #include <AEObjects.h>
  61. #endif
  62.  
  63. #ifndef __AEPACKOBJECT__
  64. #include <AEPackObject.h>
  65. #endif
  66.  
  67. //========================================================================================
  68. //    Runtime Information
  69. //========================================================================================
  70.  
  71. #ifdef FW_BUILD_MAC    
  72. #pragma segment fwsemevt
  73. #endif
  74.  
  75. FW_DEFINE_AUTO(FW_MPartScriptable)
  76. FW_DEFINE_AUTO(FW_MEmbeddingPartScriptable)
  77.  
  78. //========================================================================================
  79. //    class FW_MPartScriptable
  80. //========================================================================================
  81.  
  82. FW_DEFINE_CLASS_M1(FW_MPartScriptable, FW_MScriptable)
  83.  
  84. //---------------------------------------------------------------------------------------
  85. //    FW_MPartScriptable::FW_MPartScriptable
  86. //---------------------------------------------------------------------------------------
  87.  
  88. FW_MPartScriptable::FW_MPartScriptable() :
  89.     FW_MScriptable()
  90. {
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //---------------------------------------------------------------------------------------
  95. //    FW_MPartScriptable::~FW_MPartScriptable
  96. //---------------------------------------------------------------------------------------
  97.  
  98. FW_MPartScriptable::~FW_MPartScriptable()
  99. {
  100.     FW_START_DESTRUCTOR
  101. }                                                
  102.  
  103. //---------------------------------------------------------------------------------------
  104. //    FW_MPartScriptable::GetObjectClass
  105. //---------------------------------------------------------------------------------------
  106.  
  107. ODDescType FW_MPartScriptable::GetObjectClass() const
  108. {
  109.     return cPart;
  110. };
  111.  
  112. //---------------------------------------------------------------------------------------
  113. //    FW_MPartScriptable::GetSpecifierForm
  114. //---------------------------------------------------------------------------------------
  115.  
  116. ODDescType FW_MPartScriptable::GetSpecifierForm() const
  117. {
  118.     return formUniqueID;
  119. }
  120.  
  121. //---------------------------------------------------------------------------------------
  122. //    FW_MPartScriptable::EmbeddedFrameSpec
  123. //---------------------------------------------------------------------------------------
  124.  
  125. void FW_MPartScriptable::EmbeddedFrameSpec(Environment* ev,
  126.                                         FW_CPart* part,
  127.                                         FW_CFrame* embeddedFrame,
  128.                                         FW_CDesc& objectSpec)
  129. {
  130.     FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  131.     if (aqContainingFrame != NULL)
  132.     {
  133.         FW_CDesc containerSpec;
  134.         
  135.         FW_CAcquiredODPart aqContainingPart = aqContainingFrame->AcquirePart(ev);
  136.         aqContainingPart->EmbeddedFrameSpec(ev, aqContainingFrame, containerSpec);
  137.     
  138.         FW_CPartFrameIterator iter(ev, part);
  139.         FW_CDesc mySpecData;
  140.     
  141.         FW_Boolean gotData = FALSE;
  142.     
  143.         long index = 1;
  144.         
  145.         for (FW_CFrame* frame = iter.First(ev); iter.IsNotComplete(ev) && !gotData; iter.Next(ev), index++)
  146.         {
  147.             if (frame == embeddedFrame)
  148.             {
  149.                 mySpecData << index;
  150.                 gotData = TRUE;
  151.             }
  152.         }
  153.         
  154.         if (gotData)
  155.             ::FW_CreateObjSpecifier(cPart, containerSpec, formAbsolutePosition, mySpecData, objectSpec);
  156.         else
  157.             FW_Failure(kODErrCannotEmbed);
  158.     }
  159.     else
  160.         objectSpec.Clear();
  161. }
  162.  
  163. //---------------------------------------------------------------------------------------
  164. //    FW_MPartScriptable::AcquireContainingObject
  165. //---------------------------------------------------------------------------------------
  166.  
  167. FW_MScriptable* FW_MPartScriptable::AcquireContainingObject(Environment* ev,
  168.                                                             FW_CPart* part) const
  169. {
  170. FW_UNUSED(ev);
  171. FW_UNUSED(part);
  172.     FW_Failure(errAEEventNotHandled);
  173.     return NULL;    // return statement to satisfy compiler
  174. }
  175.  
  176. //---------------------------------------------------------------------------------------
  177. //    FW_MPartScriptable::AcquireObjectContainedInPart
  178. //---------------------------------------------------------------------------------------
  179.  
  180. FW_MScriptable* FW_MPartScriptable::AcquireObjectContainedInPart(Environment* ev,
  181.                                                                 ODDescType desiredClass,
  182.                                                                 ODDescType form,
  183.                                                                 FW_CDesc& selectionData)
  184. {
  185. FW_UNUSED(ev);
  186. FW_UNUSED(desiredClass);
  187. FW_UNUSED(form);
  188. FW_UNUSED(selectionData);
  189.     return NULL;
  190. }
  191.  
  192. //---------------------------------------------------------------------------------------
  193. //    FW_MPartScriptable::CountElementsInPart
  194. //---------------------------------------------------------------------------------------
  195.  
  196. long FW_MPartScriptable::CountElementsInPart(Environment* ev,
  197.                                         ODDescType desiredClass)
  198. {
  199. FW_UNUSED(ev);
  200. FW_UNUSED(desiredClass);
  201.     FW_Failure(errAEEventNotHandled);
  202.     return 0;    // return statement to satisfy compiler
  203. }
  204.  
  205. //---------------------------------------------------------------------------------------
  206. //    FW_MPartScriptable::BuildObjectSpecifier
  207. //---------------------------------------------------------------------------------------
  208.  
  209. void FW_MPartScriptable::BuildObjectSpecifier(Environment* ev,
  210.                                             FW_CPart* part,
  211.                                             const FW_CFrame* frame,
  212.                                             FW_CDesc& specifier,
  213.                                             ODDescType preferredForm) const
  214. {
  215.     volatile FW_Boolean gotFrameSpec = FALSE;
  216.     
  217.     FW_TRY
  218.     {
  219.         ODPart* odPart = part->GetODPart(ev);
  220.         odPart->EmbeddedFrameSpec(ev, frame->GetODFrame(ev), specifier);
  221.         
  222.         gotFrameSpec = TRUE;
  223.     }
  224.     FW_CATCH_BEGIN
  225.     FW_CATCH_EVERYTHING()
  226.     {
  227.         gotFrameSpec = FALSE;
  228.     }
  229.     FW_CATCH_END
  230.     
  231.     if (!gotFrameSpec)
  232.     {
  233.         if (preferredForm == formUniqueID)
  234.         {
  235.             FW_CDesc nullDesc;
  236.             FW_CDesc mySpecifier;
  237.             
  238.             ODPersistentObjectID id = part->GetDraft(ev)->GetPersistentObjectID(ev, frame->GetODFrame(ev), kODFrameObject);
  239.             mySpecifier.PutLongInteger(id);
  240.             
  241.             ::FW_CreateObjSpecifier(GetObjectClass(), nullDesc, preferredForm, mySpecifier, specifier);
  242.         }
  243.         else
  244.             FW_Failure(errAECantSupplyType);
  245.     }
  246. }
  247.  
  248. //---------------------------------------------------------------------------------------
  249. //    FW_MPartScriptable::HasProperty
  250. //---------------------------------------------------------------------------------------
  251.  
  252. FW_Boolean FW_MPartScriptable::HasProperty(ODDescType whichProperty) const
  253. {
  254.     return (whichProperty == pUniqueID);
  255. }
  256.  
  257. //---------------------------------------------------------------------------------------
  258. //    FW_MPartScriptable::GetProperty
  259. //---------------------------------------------------------------------------------------
  260.  
  261. FW_Boolean FW_MPartScriptable::GetProperty(Environment* ev,
  262.                                         FW_CPart* part,
  263.                                         FW_CDesc& propertyValue,
  264.                                         ODDescType whichProperty,
  265.                                         ODDescType desiredType) const
  266. {    
  267. FW_UNUSED(desiredType);
  268.     if (whichProperty == pUniqueID)
  269.     {    
  270.             // the part is being asked to provide a uniqueID, but there is no way
  271.             // to associate the id with any frame other than the last active frame.
  272.             // It is possible to get a persistent ID for the kODPartObject, but
  273.             // OpenDoc doesn't expect persistent part ID's when resolving object
  274.             // specifiers.
  275.             
  276.         ODFrame* frame = part->GetLastActiveFrame(ev)->GetODFrame(ev);
  277.         ODPersistentObjectID id = part->GetDraft(ev)->GetPersistentObjectID(ev,frame, kODFrameObject);
  278.         
  279.         propertyValue.PutLongInteger(id);
  280.         
  281.         return TRUE;
  282.     }
  283.     else
  284.         return FALSE;
  285. }
  286.  
  287. //---------------------------------------------------------------------------------------
  288. //    FW_MPartScriptable::EmbeddedFrameSpecGlue
  289. //---------------------------------------------------------------------------------------
  290.  
  291. void FW_MPartScriptable::EmbeddedFrameSpecGlue(Environment* ev,
  292.                                             FW_CPart* part,
  293.                                             ODFrame* embeddedFrame,
  294.                                             ODObjectSpec* spec)
  295. {
  296.     FW_TRY
  297.     {
  298.         FW_MPartScriptable* semanticPart = FW_DYNAMIC_CAST(FW_MPartScriptable, part);
  299.         
  300.         if (semanticPart)
  301.         {
  302.             FW_CDesc     objectSpec(spec);
  303.             FW_CFrame*     embeddedFWFrame = FW_CFrame::ODtoFWFrame(ev, embeddedFrame);
  304.             
  305.             semanticPart->EmbeddedFrameSpec(ev, part, embeddedFWFrame, objectSpec);
  306.         }
  307.         else
  308.             FW_SetEvError(ev, kODErrCannotEmbed);
  309.     }
  310.     FW_CATCH_BEGIN
  311.     FW_CATCH_REFERENCE(FW_XException, exception)
  312.     {
  313.         // kODErrCannotEmbed
  314.         FW_SetException(ev, exception);
  315.     }
  316. #ifdef FW_DEBUG
  317.     FW_CATCH_EVERYTHING()
  318.     {
  319.         // FW_DEBUG_MESSAGE(FW_kInvalidException);
  320.         FW_SetEvError(ev, kODErrUndefined);
  321.     }
  322. #endif
  323.     FW_CATCH_END
  324. }
  325. //========================================================================================
  326. //    class FW_MEmbeddingPartScriptable
  327. //========================================================================================
  328.  
  329. FW_DEFINE_CLASS_M1(FW_MEmbeddingPartScriptable, FW_MPartScriptable);
  330.  
  331. //---------------------------------------------------------------------------------------
  332. //    FW_MEmbeddingPartScriptable::FW_MEmbeddingPartScriptable
  333. //---------------------------------------------------------------------------------------
  334.  
  335. FW_MEmbeddingPartScriptable::FW_MEmbeddingPartScriptable() :
  336.     FW_MPartScriptable()
  337. {
  338.     FW_END_CONSTRUCTOR
  339. }
  340.  
  341. //---------------------------------------------------------------------------------------
  342. //    FW_MEmbeddingPartScriptable::~FW_MEmbeddingPartScriptable
  343. //---------------------------------------------------------------------------------------
  344.  
  345. FW_MEmbeddingPartScriptable::~FW_MEmbeddingPartScriptable()
  346. {
  347.     FW_START_DESTRUCTOR
  348. }
  349.  
  350.  
  351.