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 / ODF / Framewrk / FWSemEvt / Sources / FWSemInt.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  23.3 KB  |  749 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSemInt.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSEMINT_H
  11. #include "FWSemInt.h"
  12. #endif
  13.  
  14. // ----- Framework Includes -----
  15.  
  16. #ifndef FWEXTMGR_H
  17. #include "FWExtMgr.h"
  18. #endif
  19.  
  20. #ifndef FWPART_H
  21. #include "FWPart.h"
  22. #endif
  23.  
  24. #ifndef PRSIGLUE_H
  25. #include "PRSIGlue.h"
  26. #endif
  27.  
  28. #ifndef FWAPLEVT_H
  29. #include "FWAplEvt.h"
  30. #endif
  31.  
  32. #ifndef FWDSCOPR_H
  33. #include "FWDscOpr.h"
  34. #endif
  35.  
  36. #ifndef FWSCPCOL_H
  37. #include "FWScpCol.h"
  38. #endif
  39.  
  40. #ifndef FWSCPTBL_H
  41. #include "FWScptbl.h"
  42. #endif
  43.  
  44. #ifndef FWPRTSCP_H
  45. #include "FWPrtScp.h"
  46. #endif
  47.  
  48. #ifndef FWSCPPRP_H
  49. #include "FWScpPrp.h"
  50. #endif
  51.  
  52. #ifndef FWITERS_H
  53. #include "FWIters.h"
  54. #endif
  55.  
  56. #ifndef FWCONTXT_H
  57. #include "FWContxt.h"
  58. #endif
  59.  
  60. #ifndef FWEVENTU_H
  61. #include "FWEventU.h"
  62. #endif
  63.  
  64. #ifndef FWINK_H
  65. #include "FWInk.h"
  66. #endif
  67.  
  68. #ifndef FWOVLSHP_H
  69. #include "FWOvlShp.h"
  70. #endif
  71.  
  72. #ifndef SOM_FW_OSemanticInterface_xh
  73. #include "SLSemInt.xh"
  74. #endif
  75.  
  76. #ifndef FWSOMENV_H
  77. #include "FWSOMEnv.h"
  78. #endif
  79.  
  80. // ----- OpenDoc Includes -----
  81.  
  82. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  83. #include <StdExts.xh>
  84. #endif
  85.  
  86. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  87. #include <ODRgstry.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODNameResolver_xh
  91. #include <NamRslvr.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODObjectSpec_xh
  95. #include <ODObjSpc.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODOSLToken_xh
  99. #include <ODOSLTkn.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODSession_xh
  103. #include <ODSessn.xh>
  104. #endif
  105.  
  106. // ----- Macintosh Includes -----
  107.  
  108. #ifndef __AEOBJECTS__
  109. #include <AEObjects.h>
  110. #endif
  111.  
  112. #ifndef __APPLEEVENTS__
  113. #include <AppleEvents.h>
  114. #endif
  115.  
  116. #if defined(__MWERKS__) && GENERATING68K
  117. // A hack to work around a bug
  118. #pragma import list somNewObjectInstance
  119. #endif
  120.  
  121. //========================================================================================
  122. //    Runtime Information
  123. //========================================================================================
  124.  
  125. #ifdef FW_BUILD_MAC    
  126. #pragma segment fwsemevt
  127. #endif
  128.  
  129. FW_DEFINE_AUTO(FW_CSemanticInterface)
  130.  
  131. //========================================================================================
  132. //    Key Matching Proc
  133. //========================================================================================
  134.  
  135. static int FW_PrivCompareODDescTypes(void* p1, void* p2)
  136. {
  137.     const ODDescType key1 = ((FW_CPrivDescTypeToFunctionPair*)p1)->fKey;
  138.     const ODDescType key2 = ((FW_CPrivDescTypeToFunctionPair*)p2)->fKey;
  139.     
  140.     if (key1 == key2)
  141.         return 0;
  142.     else if (key1 > key2)
  143.         return 1;
  144.     else
  145.         return -1;
  146. }
  147.  
  148. //========================================================================================
  149. //    class FW_CSemanticInterface
  150. //========================================================================================
  151.  
  152. //---------------------------------------------------------------------------------------
  153. //    FW_CSemanticInterface::FW_CSemanticInterface
  154. //---------------------------------------------------------------------------------------
  155.  
  156. FW_CSemanticInterface::FW_CSemanticInterface(Environment* ev, FW_CPart* part) :
  157.     fDefaultContainer(FW_DYNAMIC_CAST(FW_MPartScriptable, part)),
  158.     fPart(part),
  159.     fResolver(part->GetSession(ev)->GetNameResolver(ev)),
  160.     fOSLFlags(kAEIDoMinimum),
  161.     fUsingPredispatchProc(FALSE),
  162.     fCoercionFuncMap(NULL)
  163. {
  164.     FW_END_CONSTRUCTOR
  165.     
  166.     // OpenDoc 1.0 and 1.02 have a bug that prevents marking from working correctly.
  167.     // The bug causes OpenDoc to look at the OSL flags of the part's containing
  168.     // part when determining whether or not a part marks. This means that if a part
  169.     // says it does marking, OpenDoc will treat it as if it does not, but will
  170.     // treat all parts contained by that part as if they do.
  171. }
  172.  
  173. //---------------------------------------------------------------------------------------
  174. //    FW_CSemanticInterface::~FW_CSemanticInterface
  175. //---------------------------------------------------------------------------------------
  176.  
  177. FW_CSemanticInterface::~FW_CSemanticInterface()
  178. {
  179.     FW_START_DESTRUCTOR
  180.     
  181.     delete fCoercionFuncMap;
  182. }
  183.  
  184. //---------------------------------------------------------------------------------------
  185. //    FW_CSemanticInterface::RegisterCoercionFunction
  186. //---------------------------------------------------------------------------------------
  187.  
  188. void FW_CSemanticInterface::RegisterCoercionFunction(Environment* ev,
  189.                                                     ODDescType toType,
  190.                                                     CoercionFunc func)
  191. {
  192. FW_UNUSED(ev);
  193.     if (!fCoercionFuncMap)
  194.         fCoercionFuncMap = new FW_CPrivDescTypeToFunctionMap(FW_PrivCompareODDescTypes);
  195.         
  196.     FW_ASSERT(!fCoercionFuncMap->Find(toType));
  197.     fCoercionFuncMap->Add(toType, func);
  198. }
  199.                                                     
  200. //---------------------------------------------------------------------------------------
  201. //    FW_CSemanticInterface::RegisterCallbacks
  202. //---------------------------------------------------------------------------------------
  203.  
  204. void FW_CSemanticInterface::RegisterCallbacks(Environment* ev)
  205. {
  206.     RegisterCoercionFunction(ev, typeODFSemanticObject, FW_CSemanticInterface::PrivCoerceToSemanticObject);
  207. }
  208.  
  209. //---------------------------------------------------------------------------------------
  210. //    FW_CSemanticInterface::CreateSOMInterface
  211. //---------------------------------------------------------------------------------------
  212.  
  213. FW_OSemanticInterface* FW_CSemanticInterface::CreateSOMInterface(Environment *ev, 
  214.                                                                 FW_CPart *part, 
  215.                                                                 const char *name,
  216.                                                                 void* refCon)
  217. {    
  218. FW_UNUSED(name);
  219. FW_UNUSED(refCon);
  220.     FW_OSemanticInterface* semInt = new FW_OSemanticInterface;
  221.     semInt->InitODFSemanticInterface(ev, part->GetODPart(ev), part->GetSession(ev), this,  FW_PrivGetSemanticInterfaceGlue());
  222.     
  223.     semInt->SetOSLSupportFlags(ev, fOSLFlags);
  224.     semInt->UsingPredispatchProc(ev, fUsingPredispatchProc);
  225.     
  226.     return semInt;
  227. }
  228.  
  229. //---------------------------------------------------------------------------------------
  230. //    FW_CSemanticInterface::AcquireSOMInterface
  231. //---------------------------------------------------------------------------------------
  232.  
  233. FW_OSemanticInterface* FW_CSemanticInterface::AcquireSOMInterface(Environment* ev)
  234. {
  235.     return (FW_OSemanticInterface*)fPart->GetExtensionManager(ev)->AcquireExtension(ev, kODExtSemanticInterface, FW_kDontCreateExtension);
  236. }
  237.  
  238. //========================================================================================
  239. //  Begin Callbacks
  240. //========================================================================================
  241.  
  242. //---------------------------------------------------------------------------------------
  243. //    FW_CSemanticInterface::CallEventHandler
  244. //---------------------------------------------------------------------------------------
  245.  
  246. void FW_CSemanticInterface::CallEventHandler(Environment* ev, 
  247.                                             FW_CAppleEvent& event, 
  248.                                             FW_CAppleEvent& reply)
  249. {
  250.     FW_MScriptable* targetObject = GetTargetObject(ev, event);;
  251.  
  252.     AEKeyword eventClass = event.GetEventClass();
  253.     AEKeyword eventID = event.GetEventID();
  254.         
  255.     targetObject->HandleSemanticEvent(ev, fPart, eventClass, eventID, event, reply);
  256.     targetObject->ReleaseScriptable();
  257. }
  258.     
  259. //---------------------------------------------------------------------------------------
  260. //    FW_CSemanticInterface::CallCoercionHandler
  261. //---------------------------------------------------------------------------------------
  262.  
  263. void FW_CSemanticInterface::CallCoercionHandler(Environment* ev,
  264.                                                 const FW_CDesc& theDesc,
  265.                                                 ODDescType toType,
  266.                                                 FW_CDesc& theResult)
  267. {
  268.     FW_CPrivDescTypeToFunctionPair* pair = fCoercionFuncMap ? fCoercionFuncMap->Find(toType) : NULL;
  269.     CoercionFunc func = pair ? pair->fValue : NULL;
  270.     
  271.     if (func)
  272.         (func)(ev, this, theDesc, toType, theResult);
  273.     else
  274.         FW_THROW(FW_XException(errAECoercionFail));
  275. }
  276.                                             
  277. //---------------------------------------------------------------------------------------
  278. //    FW_CSemanticInterface::CallPredispatchProc
  279. //---------------------------------------------------------------------------------------
  280.  
  281. void FW_CSemanticInterface::CallPredispatchProc(Environment* ev, 
  282.                                                 FW_CAppleEvent& event,
  283.                                                 FW_CAppleEvent& reply)
  284. {
  285. FW_UNUSED(ev);
  286. FW_UNUSED(event);
  287. FW_UNUSED(reply);
  288.     FW_THROW(FW_XException(errAEEventNotHandled));
  289. }
  290.  
  291. //---------------------------------------------------------------------------------------
  292. //    FW_CSemanticInterface::CallObjectAccessor
  293. //---------------------------------------------------------------------------------------
  294.  
  295. void FW_CSemanticInterface::CallObjectAccessor(Environment* ev,
  296.                                                 ODDescType desiredClass,
  297.                                                 ODOSLToken* container,
  298.                                                 ODDescType containerClass,
  299.                                                 ODDescType form,
  300.                                                 FW_CDesc& selectionData,
  301.                                                 ODOSLToken* value)
  302. {
  303.     FW_CDesc containedObjectToken(GetDescFromToken(ev, value));
  304.     FW_CDesc containerToken(GetDescFromToken(ev, container));
  305.     
  306.             // OpenDoc 1.0 doesn't handle OSLSupportFlags correctly.
  307.             // Instead of respecting our request for object marking,
  308.             // we get a container token here that is a list built
  309.             // by the OD OSL. For now, we'll simulate marking by
  310.             // building generating a collection of marked objects ourselves.
  311.             
  312.     if (containerToken.IsList() && desiredClass == cProperty)
  313.     {
  314.         ODDescType whichProperty;
  315.         
  316.         selectionData >> whichProperty;
  317.         FW_MScriptable* collection = CreateCollectionFromList(ev, fPart, containerToken, whichProperty);
  318.         ::FW_InsertScriptableIntoDesc(collection, containedObjectToken);
  319.     }
  320.     else
  321.     {
  322.         FW_Boolean gotObject;
  323.  
  324.         if (containerClass == cPart)
  325.         {
  326.             FW_MPartScriptable* part = GetDefaultContainer();
  327.             gotObject = part->GetObjectContainedInPart(ev, desiredClass, form, selectionData, containedObjectToken);
  328.         }
  329.         else
  330.         {
  331.             FW_MScriptable* containerObject;
  332.             
  333.             if (containerToken.IsNullDescriptor())
  334.                 containerObject = GetDefaultContainer();
  335.             else
  336.                 containerObject = ::FW_ExtractScriptableFromDesc(containerToken);
  337.         
  338.             gotObject = containerObject->GetContainedObject(ev, fPart, desiredClass, form, selectionData, containedObjectToken);
  339.         }
  340.         
  341.         if (!gotObject)
  342.             FW_THROW(FW_XException(errAEEventNotHandled));
  343.     }
  344. }
  345.                                                     
  346. //---------------------------------------------------------------------------------------
  347. //    FW_CSemanticInterface::CallCompareProc
  348. //---------------------------------------------------------------------------------------
  349.  
  350. void FW_CSemanticInterface::CallCompareProc(Environment* ev,
  351.                                             ODDescType oper,
  352.                                             ODOSLToken* obj1,
  353.                                             ODOSLToken* obj2,
  354.                                             ODBoolean* result)
  355. {
  356.     FW_CDesc desc1(GetDescFromToken(ev, obj1));
  357.     FW_CDesc desc2(GetDescFromToken(ev, obj2));
  358.         
  359.     if (TypeIsSemanticObject(ev, desc1.DescriptorType()))
  360.     {
  361.         FW_MScriptable* semanticObject = ::FW_ExtractScriptableFromDesc(desc1);
  362.         *result = semanticObject->CompareScriptableObjects(ev, fPart, oper, desc2);
  363.     }
  364.     else
  365.         FW_THROW(FW_XException(errAEEventNotHandled));
  366. }
  367.                                                     
  368. //---------------------------------------------------------------------------------------
  369. //    FW_CSemanticInterface::CallCountProc
  370. //---------------------------------------------------------------------------------------
  371. void FW_CSemanticInterface::CallCountProc(Environment* ev,
  372.                                         ODDescType desiredClass,
  373.                                         ODDescType containerClass,
  374.                                         ODOSLToken* container,
  375.                                         ODSLong* result)
  376. {
  377.     FW_CDesc containerToken(GetDescFromToken(ev, container));
  378.     
  379.     long                elementCount = 0;
  380.  
  381.     if (containerClass == cPart)
  382.     {
  383.         elementCount = GetDefaultContainer()->CountElementsInPart(ev, desiredClass);
  384.     }
  385.     else
  386.     {
  387.         FW_MScriptable*    containerObject = NULL;
  388.  
  389.         if (containerToken.IsNullDescriptor())
  390.             containerObject = GetDefaultContainer();
  391.         else
  392.             containerObject = ::FW_ExtractScriptableFromDesc(containerToken);
  393.         
  394.         elementCount = containerObject->CountElements(ev, fPart, desiredClass);
  395.     }
  396.     
  397.     *result = elementCount;
  398. }
  399.  
  400. //---------------------------------------------------------------------------------------
  401. //    FW_CSemanticInterface::CallDisposeTokenProc
  402. //---------------------------------------------------------------------------------------
  403. void FW_CSemanticInterface::CallDisposeTokenProc(Environment* ev, ODOSLToken* unneededToken)
  404. {
  405.     FW_CDesc token(GetDescFromToken(ev, unneededToken));
  406.     
  407.     if (TypeIsSemanticObject(ev, token.DescriptorType()))
  408.     {
  409.         FW_MScriptable* scriptableObject = ::FW_ExtractScriptableFromDesc(token);
  410.         scriptableObject->ReleaseScriptable();
  411.         token.Clear();
  412.     }
  413.     else
  414.         FW_THROW(FW_XException(errAEEventNotHandled));
  415. }
  416.                                                         
  417. //---------------------------------------------------------------------------------------
  418. //    FW_CSemanticInterface::CallGetErrDescProc
  419. //---------------------------------------------------------------------------------------
  420. void FW_CSemanticInterface::CallGetErrDescProc(Environment* ev, ODDesc** errDesc)
  421. {
  422. FW_UNUSED(ev);
  423. FW_UNUSED(errDesc);
  424.     FW_THROW(FW_XException(errAEEventNotHandled));
  425. }
  426.                                                     
  427. //---------------------------------------------------------------------------------------
  428. //    FW_CSemanticInterface::CallGetMarkTokenProc
  429. //---------------------------------------------------------------------------------------
  430. void FW_CSemanticInterface::CallGetMarkTokenProc(Environment* ev,
  431.                                                 ODOSLToken* dContainerToken,
  432.                                                 ODDescType    containerClass,
  433.                                                 ODOSLToken* result)
  434. {
  435. FW_UNUSED(dContainerToken);
  436. FW_UNUSED(containerClass);
  437.     
  438.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBBlue);
  439.     
  440.     FW_CDesc collectionToken(GetDescFromToken(ev, result));
  441.  
  442.     FW_CScriptableCollection* collection = FW_NEW(FW_CScriptableCollection, ());
  443.     ::FW_InsertScriptableIntoDesc(collection, collectionToken);
  444. }
  445.                                                         
  446. //---------------------------------------------------------------------------------------
  447. //    FW_CSemanticInterface::CallMarkProc
  448. //---------------------------------------------------------------------------------------
  449. void FW_CSemanticInterface::CallMarkProc(Environment* ev,
  450.                                         ODOSLToken* objectToMarkToken,
  451.                                         ODOSLToken* markingListToken,
  452.                                         ODSLong index)
  453. {
  454. FW_UNUSED(index);
  455.  
  456.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBRed);
  457.     
  458.     FW_CDesc objectToMarkDesc(GetDescFromToken(ev, objectToMarkToken));
  459.     FW_CDesc markingListDesc(GetDescFromToken(ev, markingListToken));
  460.     
  461.     FW_MScriptable* objectToMark = ::FW_ExtractScriptableFromDesc(objectToMarkDesc);
  462.     FW_CScriptableCollection* collection = 
  463.         FW_DYNAMIC_CAST(FW_CScriptableCollection, ::FW_ExtractScriptableFromDesc(markingListDesc));
  464.     
  465.     collection->Add(objectToMark);
  466. }
  467.     
  468. //---------------------------------------------------------------------------------------
  469. //    FW_CSemanticInterface::CallAdjustMarksProc
  470. //---------------------------------------------------------------------------------------
  471. void FW_CSemanticInterface::CallAdjustMarksProc(Environment* ev,
  472.                                                 ODSLong newStart,
  473.                                                 ODSLong newStop,
  474.                                                 ODOSLToken* markToken)
  475. {
  476.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBGreen);
  477.     
  478.     FW_CDesc markingListDesc(GetDescFromToken(ev, markToken));
  479.     FW_CScriptableCollection* collection = 
  480.         FW_DYNAMIC_CAST(FW_CScriptableCollection, ::FW_ExtractScriptableFromDesc(markingListDesc));
  481.     
  482.     collection->AdjustMarks(ev, newStart, newStop);
  483. }
  484.     
  485. //---------------------------------------------------------------------------------------
  486. //    FW_CSemanticInterface::GetOSLSupportFlags
  487. //---------------------------------------------------------------------------------------
  488.  
  489. ODSShort FW_CSemanticInterface::GetOSLSupportFlags(Environment* ev)
  490. {
  491. FW_UNUSED(ev);
  492.     return fOSLFlags;
  493.  
  494. //---------------------------------------------------------------------------------------
  495. //    FW_CSemanticInterface::SetOSLSupportFlags
  496. //---------------------------------------------------------------------------------------
  497.  
  498. void FW_CSemanticInterface::SetOSLSupportFlags(Environment* ev, ODSShort flags)
  499. {
  500.     fOSLFlags = flags;
  501.     
  502.     FW_OSemanticInterface* semInt = AcquireSOMInterface(ev);
  503.     if (semInt)
  504.     {
  505.         semInt->SetOSLSupportFlags(ev, flags);
  506.         semInt->Release(ev);
  507.     }
  508. }
  509.                                                     
  510. //---------------------------------------------------------------------------------------
  511. //    FW_CSemanticInterface::UsingPredispatchProc
  512. //---------------------------------------------------------------------------------------
  513.  
  514. void FW_CSemanticInterface::UsingPredispatchProc(Environment* ev, ODBoolean usingNotUsing)
  515. {
  516.     fUsingPredispatchProc = usingNotUsing;
  517.     
  518.     ODSemanticInterface* semInt = AcquireSOMInterface(ev);
  519.     if (semInt)
  520.     {
  521.         semInt->UsingPredispatchProc(ev, usingNotUsing);
  522.         semInt->Release(ev);
  523.     }
  524. }
  525.  
  526. //---------------------------------------------------------------------------------------
  527. //    FW_CSemanticInterface::CreateCollectionFromList
  528. //---------------------------------------------------------------------------------------
  529.  
  530. FW_MScriptable* FW_CSemanticInterface::CreateCollectionFromList(Environment* ev,
  531.                                                                     FW_CPart* part,
  532.                                                                     const FW_CDesc& objectList,
  533.                                                                     ODDescType whichProperty) const
  534. {
  535.     FW_ASSERT(objectList.IsList());
  536.     
  537.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBPurple);
  538.     
  539.     FW_CScriptableCollection* collection = FW_NEW(FW_CScriptableCollection, ());
  540.     
  541.     FW_CDesc     currentODToken;
  542.     FW_CDesc    currentToken;
  543.     long         itemsInList = objectList.GetItemCount();
  544.     
  545.     for (long index = 1; index <= itemsInList; index++)
  546.     {
  547.         currentODToken.Clear();
  548.         currentToken.Clear();
  549.         
  550.         objectList.GetDescFromList(index, currentODToken);
  551.         currentToken = GetDescFromToken(ev, currentODToken);
  552.         
  553.         FW_MScriptable* semObj = ::FW_ExtractScriptableFromDesc(currentToken);
  554.         
  555.         if (whichProperty != keyNoKey)
  556.         {
  557.             FW_CPropertyDesignator* propDesignator;
  558.  
  559.             propDesignator = FW_NEW(FW_CPropertyDesignator, (part, semObj, whichProperty));
  560.             collection->Add(propDesignator);
  561.         }
  562.         else
  563.             collection->Add(semObj);
  564.     }
  565.     return collection;
  566. }
  567.  
  568. //---------------------------------------------------------------------------------------
  569. //    FW_CSemanticInterface::TypeIsSemanticObject
  570. //---------------------------------------------------------------------------------------
  571.  
  572. FW_Boolean FW_CSemanticInterface::TypeIsSemanticObject(Environment* ev, ODDescType type) const
  573. {
  574. FW_UNUSED(ev);
  575.     FW_Boolean result;
  576.     
  577.     switch (type)
  578.     {
  579.         case typeODFSemanticObject:
  580.         case typeODFPropertyDesignator:
  581.         case typeODFSemObjCollection:
  582.             result = TRUE;
  583.             break;
  584.             
  585.         default:
  586.             result = FALSE;
  587.             break;
  588.     }
  589.     return result;
  590. }
  591.  
  592. //---------------------------------------------------------------------------------------
  593. //    FW_CSemanticInterface::GetDescFromToken
  594. //---------------------------------------------------------------------------------------
  595.  
  596. ODDesc* FW_CSemanticInterface::GetDescFromToken(Environment* ev, ODOSLToken* token) const
  597. {
  598.     return (fResolver->IsODToken(ev, token) ? fResolver->GetUserToken(ev, token) : token);
  599. }
  600.  
  601. //---------------------------------------------------------------------------------------
  602. //    FW_CSemanticInterface::GetTargetObject
  603. //---------------------------------------------------------------------------------------
  604.  
  605. FW_MScriptable* FW_CSemanticInterface::GetTargetObject(Environment* ev,
  606.                                                     FW_CAppleEvent& event)
  607. {
  608.     FW_CDesc targetObjectDesc;
  609.     
  610.     if (event.HasDataKey(keyDirectObject))
  611.     {
  612.         FW_CDesc directObjectToken;
  613.         
  614.         event.GetDataByDesc(directObjectToken, keyDirectObject);
  615.         targetObjectDesc = GetDescFromToken(ev, directObjectToken);
  616.     }
  617.     else
  618.     {
  619.         FW_CDesc subjectDesc;
  620.         
  621.         if (event.HasSubject())
  622.         {
  623.             event.GetSubject(subjectDesc);
  624.             Resolve(ev, subjectDesc, targetObjectDesc);
  625.         }
  626.     }
  627.     
  628.     return GetScriptableFromToken(ev, targetObjectDesc);
  629. }
  630.  
  631. //---------------------------------------------------------------------------------------
  632. //    FW_CSemanticInterface::Resolve
  633. //---------------------------------------------------------------------------------------
  634.  
  635. void FW_CSemanticInterface::Resolve(Environment* ev,
  636.                                     const FW_CDesc& objectSpec,
  637.                                     FW_CDesc& odfToken,
  638.                                     ODPart* contextPart) const
  639. {
  640.     if (objectSpec.IsNullDescriptor())
  641.     {
  642.         odfToken.Clear();
  643.     }
  644.     else
  645.     {    
  646.         FW_CDesc resolveToken;
  647.         
  648.         FW_TRY
  649.         {
  650.             fResolver->Resolve(ev, objectSpec, resolveToken, contextPart);
  651.             resolveToken.SetOwnsODData(FALSE);
  652.             odfToken = GetDescFromToken(ev, resolveToken);
  653.             fResolver->DisposeToken(ev, resolveToken);
  654.         }
  655.         FW_CATCH_BEGIN
  656.         FW_CATCH_EVERYTHING()
  657.         {
  658.             if (!resolveToken.IsNullDescriptor())
  659.                 fResolver->DisposeToken(ev, resolveToken);
  660.             FW_THROW_SAME();
  661.         }
  662.         FW_CATCH_END
  663.     }
  664. }
  665.  
  666. //---------------------------------------------------------------------------------------
  667. //    FW_CSemanticInterface::GetScriptableFromToken
  668. //---------------------------------------------------------------------------------------
  669.  
  670. FW_MScriptable* FW_CSemanticInterface::GetScriptableFromToken(Environment* ev,
  671.                                                             const FW_CDesc& odfToken) const
  672. {    
  673.     FW_MScriptable* scriptable = NULL;
  674.     ODDescType        tokenType = odfToken.DescriptorType();
  675.     
  676.     if (tokenType == kODStandardPartTokenType || odfToken.IsNullDescriptor())
  677.     {
  678.         scriptable = GetDefaultContainer();
  679.         scriptable->AcquireScriptable();
  680.     }
  681.     else if (TypeIsSemanticObject(ev, tokenType))
  682.         scriptable = ::FW_ExtractScriptableFromDesc(odfToken);
  683.     else if (odfToken.IsList())
  684.         scriptable = CreateCollectionFromList(ev, fPart, odfToken);
  685.     else
  686.         FW_THROW(FW_XException(errAEEventNotHandled));
  687.         
  688.     return scriptable;
  689. }
  690.  
  691. //---------------------------------------------------------------------------------------
  692. //    FW_DebugIdentifyPart:
  693. //    This utility method is for debugging semantic event handling in nested parts.
  694. //    A circle of the specified color will be briefly displayed in the top left
  695. //    corner of the first facet of the specified frame. This method does not attempt 
  696. //  to redraw or invalidate the content area obscured by the circle.
  697. //
  698. //    Note: This method may not be a permanent part of the ODF API.
  699. //---------------------------------------------------------------------------------------
  700.  
  701. void FW_DebugIdentifyPart(Environment* ev, FW_CFrame* frame, const FW_CColor& color)
  702. {
  703.     FW_CFrameFacetIterator iter(ev, frame);
  704.     FW_CViewContext vc(ev, frame, iter.First(ev), NULL);
  705.     FW_CRect rect(FW_kFixed0, FW_kFixed0, FW_IntToFixed(10), FW_IntToFixed(10));
  706.     
  707.     FW_CInk ink;
  708.     ink.SetForeColor(color);
  709.     ink.SetTransferMode(FW_kCopy);
  710.     FW_COvalShape::RenderOval(vc, rect, FW_kFill, ink);
  711.     FW_WaitFor(20);
  712.     ink.SetTransferMode(FW_kErase);
  713.     FW_COvalShape::RenderOval(vc, rect, FW_kFill, ink);
  714. }
  715.                                                     
  716. //========================================================================================
  717. //  End Callbacks
  718. //========================================================================================
  719.  
  720. //---------------------------------------------------------------------------------------
  721. //    FW_CSemanticInterface::PrivCreate
  722. //---------------------------------------------------------------------------------------
  723.  
  724. ODExtension* FW_CSemanticInterface::PrivCreate(Environment* ev, FW_CPart* part, const char* name, void* refCon)
  725. {
  726.     return (part->GetSemanticInterface(ev)->CreateSOMInterface(ev, part, name, refCon));        
  727. }
  728.  
  729. //---------------------------------------------------------------------------------------
  730. //    FW_CSemanticInterface::PrivCoerceToSemanticObject
  731. //---------------------------------------------------------------------------------------
  732.  
  733. void FW_CSemanticInterface::PrivCoerceToSemanticObject(Environment* ev,
  734.                                                     const FW_CSemanticInterface* semInt,
  735.                                                     const FW_CDesc& theDesc,
  736.                                                     ODDescType toType,
  737.                                                     FW_CDesc& theResult)
  738. {
  739.         // built in up-cast to our basic event handler
  740.     if (semInt->TypeIsSemanticObject(ev, theDesc.DescriptorType()))
  741.     {
  742.         theResult = theDesc;
  743.         theResult.SetDescriptorType(toType);
  744.     }
  745.     else
  746.         FW_THROW(FW_XException(errAECoercionFail));
  747. }
  748.