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 / FWScpPrp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  12.5 KB  |  400 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSemPrp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSCPPRP_H
  11. #include "FWScpPrp.h"
  12. #endif
  13.  
  14. // ----- Framework Includes -----
  15.  
  16. #ifndef FWAPLEVT_H
  17. #include "FWAplEvt.h"
  18. #endif
  19.  
  20. #ifndef FWSCPTBL_H
  21. #include "FWScptbl.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWPSTR_H
  27. #include "FWPStr.h"
  28. #endif
  29.  
  30. #ifndef __AEOBJECTS__
  31. #include <AEObjects.h>
  32. #endif
  33.  
  34. //========================================================================================
  35. //    Runtime Information
  36. //========================================================================================
  37.  
  38. #ifdef FW_BUILD_MAC    
  39. #pragma segment fwsemevt
  40. #endif
  41.  
  42. FW_DEFINE_AUTO(FW_CPropertyDesignator)
  43. FW_DEFINE_AUTO(FW_CSetPropertyCommand)
  44.  
  45. //========================================================================================
  46. //    class FW_CPropertyDesignator
  47. //========================================================================================
  48.  
  49. FW_DEFINE_CLASS_M1(FW_CPropertyDesignator, FW_MScriptable)
  50.  
  51. //---------------------------------------------------------------------------------------
  52. //    FW_CPropertyDesignator::FW_CPropertyDesignator
  53. //---------------------------------------------------------------------------------------
  54.  
  55. FW_CPropertyDesignator::FW_CPropertyDesignator(FW_CPart* part,
  56.                                             FW_MScriptable* whichObject,
  57.                                             ODDescType whichProperty) :
  58.     FW_MScriptable(),
  59.     fObject(whichObject),
  60.     fPart(part),
  61.     fWhichProperty(whichProperty),
  62.     fRefCount(1)
  63. {
  64.     FW_ASSERT(fPart);
  65.  
  66.     if (fObject)
  67.     {
  68.         fObject->AcquireScriptable();
  69.         whichObject->AddDependent(this);
  70.     }
  71.  
  72.     FW_END_CONSTRUCTOR
  73. }
  74.  
  75. //---------------------------------------------------------------------------------------
  76. //    FW_CPropertyDesignator::~FW_CPropertyDesignator
  77. //---------------------------------------------------------------------------------------
  78.  
  79. FW_CPropertyDesignator::~FW_CPropertyDesignator()
  80. {
  81.     FW_START_DESTRUCTOR
  82.     
  83.     FW_ASSERT(fRefCount == 0);
  84.     
  85.     if (fObject)
  86.     {
  87.         fObject->RemoveDependent(this);
  88.         fObject->ReleaseScriptable();
  89.     }
  90. }
  91.  
  92. //---------------------------------------------------------------------------------------
  93. //    FW_CPropertyDesignator::AcquireScriptable
  94. //---------------------------------------------------------------------------------------
  95.  
  96. long FW_CPropertyDesignator::AcquireScriptable()
  97. {
  98.     return ++fRefCount;
  99. }
  100.  
  101. //---------------------------------------------------------------------------------------
  102. //    FW_CPropertyDesignator::ReleaseScriptable
  103. //---------------------------------------------------------------------------------------
  104.  
  105. long FW_CPropertyDesignator::ReleaseScriptable()
  106. {
  107.     FW_ASSERT(fRefCount > 0);
  108.     
  109.     long result = --fRefCount;
  110.     
  111.     if (result == 0)
  112.         delete this;
  113.     
  114.     return result;
  115. }
  116.  
  117. //---------------------------------------------------------------------------------------
  118. //    FW_CPropertyDesignator::GetObjectClass
  119. //---------------------------------------------------------------------------------------
  120.  
  121. ODDescType FW_CPropertyDesignator::GetObjectClass() const
  122. {
  123.     return cProperty;
  124. }
  125.  
  126. //---------------------------------------------------------------------------------------
  127. //    FW_CPropertyDesignator::GetSpecifierForm
  128. //---------------------------------------------------------------------------------------
  129.  
  130. ODDescType FW_CPropertyDesignator::GetSpecifierForm() const
  131. {
  132.     return formPropertyID;
  133. }
  134.  
  135. //---------------------------------------------------------------------------------------
  136. //    FW_CPropertyDesignator::BuildObjectSpecifier
  137. //---------------------------------------------------------------------------------------
  138.  
  139. void FW_CPropertyDesignator::BuildObjectSpecifier(Environment* ev,
  140.                                                 FW_CPart* part,
  141.                                                 const FW_CFrame* frame,
  142.                                                 FW_CDesc& specifier,
  143.                                                 ODDescType preferredForm) const
  144. {
  145.     if (preferredForm != formPropertyID)
  146.     {
  147.         FW_MScriptable::BuildObjectSpecifier(ev, part, frame, specifier, preferredForm);
  148.     }
  149.     else
  150.     {
  151.         if (!fObject)
  152.             FW_Failure(errAEEventNotHandled);
  153.  
  154.         fObject->GetPropertySpecifier(ev, part, fWhichProperty, specifier);
  155.     }
  156. }
  157.  
  158. //---------------------------------------------------------------------------------------
  159. //    FW_CPropertyDesignator::GetDesignateValue
  160. //---------------------------------------------------------------------------------------
  161.  
  162. FW_Boolean FW_CPropertyDesignator::GetDesignateValue(Environment* ev, 
  163.                                             FW_CDesc& propertyValue,
  164.                                             ODDescType desiredType) const
  165. {
  166.     if (!fObject)
  167.         FW_Failure(errAEEventNotHandled);
  168.         
  169.     return (fObject->GetProperty(ev, fPart, propertyValue, fWhichProperty, desiredType));
  170. }
  171.  
  172. //---------------------------------------------------------------------------------------
  173. //    FW_CPropertyDesignator::SaveDesignateValue
  174. //---------------------------------------------------------------------------------------
  175.  
  176. void FW_CPropertyDesignator::SaveDesignateValue(Environment* ev,
  177.                                             FW_CDesc& propertyValue,
  178.                                             ODDescType desiredType) const
  179. {
  180.     if (!fObject)
  181.         FW_Failure(errAEEventNotHandled);
  182.         
  183.     fObject->SaveProperty(ev, fPart, propertyValue, fWhichProperty, desiredType);
  184. }
  185.  
  186. //---------------------------------------------------------------------------------------
  187. //    FW_CPropertyDesignator::SetDesignateValue
  188. //---------------------------------------------------------------------------------------
  189.  
  190. void FW_CPropertyDesignator::SetDesignateValue(Environment* ev, FW_CDesc& propertyValue)
  191. {
  192.     if (!fObject)
  193.         FW_Failure(errAEEventNotHandled);
  194.  
  195.     fObject->SetProperty(ev, fPart, propertyValue, fWhichProperty);
  196. }
  197.  
  198. //---------------------------------------------------------------------------------------
  199. //    FW_CPropertyDesignator::RestoreDesignateValue
  200. //---------------------------------------------------------------------------------------
  201.  
  202. void FW_CPropertyDesignator::RestoreDesignateValue(Environment* ev, FW_CDesc& propertyValue)
  203. {
  204.     if (!fObject)
  205.         FW_Failure(errAEEventNotHandled);
  206.     fObject->RestoreProperty(ev, fPart, propertyValue, fWhichProperty);
  207. }
  208.  
  209. //---------------------------------------------------------------------------------------
  210. //    FW_CPropertyDesignator::GetDesignateFrame
  211. //---------------------------------------------------------------------------------------
  212.  
  213. FW_CFrame* FW_CPropertyDesignator::GetDesignateFrame(Environment* ev, FW_CPart* part)
  214. {
  215.     if (!fObject)
  216.         FW_Failure(errAEEventNotHandled);
  217.     return (fObject->GetFrame(ev, part));
  218. }
  219.  
  220. //---------------------------------------------------------------------------------------
  221. //    FW_CPropertyDesignator::GetDesignateInfo
  222. //---------------------------------------------------------------------------------------
  223.  
  224. void FW_CPropertyDesignator::GetDesignateInfo(Environment* ev,
  225.                                             FW_Boolean& canUndo,
  226.                                             FW_Boolean& causesChange)
  227. {
  228.     if (!fObject)
  229.         FW_Failure(errAEEventNotHandled);
  230.     fObject->GetPropertyInfo(ev, fPart, canUndo, causesChange);
  231. }
  232.  
  233. //---------------------------------------------------------------------------------------
  234. //    FW_CPropertyDesignator::GetDesignateUndoStrings
  235. //---------------------------------------------------------------------------------------
  236.  
  237. void FW_CPropertyDesignator::GetDesignateUndoStrings(Environment* ev,
  238.                                                     FW_CPart* part,
  239.                                                     FW_CString& undoString,
  240.                                                     FW_CString& redoString)
  241. {
  242.     if (!fObject)
  243.         FW_Failure(errAEEventNotHandled);
  244.     fObject->GetUndoStrings(ev, part, fWhichProperty, undoString, redoString);
  245. }
  246.  
  247. //---------------------------------------------------------------------------------------
  248. //    FW_CPropertyDesignator::HandlePrimaryDeleted
  249. //---------------------------------------------------------------------------------------
  250.  
  251. void FW_CPropertyDesignator::HandlePrimaryDeleted(FW_MScriptable* primary)
  252. {
  253. FW_UNUSED(primary);
  254.  
  255.     FW_ASSERT(primary == fObject);
  256.     fObject = NULL;
  257. }
  258.  
  259. //---------------------------------------------------------------------------------------
  260. //    FW_CPropertyDesignator::Compare
  261. //---------------------------------------------------------------------------------------
  262.  
  263. FW_Boolean FW_CPropertyDesignator::CompareScriptableObjects(Environment* ev,
  264.                                                             FW_CPart* part,
  265.                                                             ODDescType operation,
  266.                                                             const FW_CDesc& other) const
  267. {
  268. FW_UNUSED(part);
  269.     FW_CDesc value;
  270.  
  271.         // Try to get the designated value as the same type as the descriptor
  272.         // to be compared against. If that doesn't work, get it as whatever
  273.         // type is available, and give FW_CDesc::Compare a chance to coerce
  274.         // the values into a common type.
  275.     
  276.     if (!GetDesignateValue(ev, value, other.DescriptorType()))
  277.         GetDesignateValue(ev, value, typeWildCard);
  278.     
  279.     return value.Compare(operation, other);
  280. }
  281.  
  282. //---------------------------------------------------------------------------------------
  283. //    FW_CPropertyDesignator::DoAEGetData
  284. //---------------------------------------------------------------------------------------
  285.  
  286. void FW_CPropertyDesignator::DoAEGetData(Environment* ev,
  287.                                         FW_CPart* part,
  288.                                         const FW_CAppleEvent& event,
  289.                                         FW_CAppleEvent& reply)
  290. {
  291. FW_UNUSED(part);
  292.     FW_CDesc    propertyValue;
  293.     ODDescType     desiredType = typeWildCard;
  294.     
  295.     if (event.HasDataKey(keyAERequestedType))
  296.         event.GetDataByPtr(typeWildCard, &desiredType, NULL, sizeof(ODDescType), keyAERequestedType);
  297.  
  298.     if (!GetDesignateValue(ev, propertyValue, desiredType))
  299.         FW_Failure(errAEEventNotHandled);
  300.         
  301.     reply.PutDataByDesc(propertyValue, keyAEResult);
  302. }
  303.  
  304. //---------------------------------------------------------------------------------------
  305. //    FW_CPropertyDesignator::DoAESetData
  306. //---------------------------------------------------------------------------------------
  307.  
  308. void FW_CPropertyDesignator::DoAESetData(Environment* ev,
  309.                                         FW_CPart* part,
  310.                                         const FW_CAppleEvent& event,
  311.                                         FW_CAppleEvent& reply)
  312. {
  313. FW_UNUSED(reply);
  314.     FW_CDesc     propertyValue;
  315.  
  316.     FW_Boolean canUndo;
  317.     FW_Boolean causesChange;
  318.     
  319.     event.GetDataByDesc(propertyValue, keyAEData);
  320.     GetDesignateInfo(ev, canUndo, causesChange);
  321.     
  322.     FW_CSetPropertyCommand* cmd = FW_NEW(FW_CSetPropertyCommand, (ev, GetDesignateFrame(ev, part), canUndo, this, propertyValue));
  323.     cmd->SetCausesChange(ev, causesChange);        
  324.     cmd->Execute(ev);
  325. }
  326.  
  327. //========================================================================================
  328. //    class FW_SetPropertyCommand
  329. //========================================================================================
  330.  
  331. //---------------------------------------------------------------------------------------
  332. //    FW_CSetPropertyCommand::SetPropertyCommand
  333. //---------------------------------------------------------------------------------------
  334.  
  335. FW_CSetPropertyCommand::FW_CSetPropertyCommand(Environment* ev,
  336.                                             FW_CFrame* frame,
  337.                                             FW_Boolean canUndo,
  338.                                             FW_CPropertyDesignator* propDesignator,
  339.                                             FW_CDesc& newValue) :
  340.     FW_CCommand(ev, -1, frame, TRUE),
  341.     fPropDesignator(propDesignator),
  342.     fOldValue(),
  343.     fNewValue(newValue)
  344. {
  345. FW_UNUSED(canUndo);
  346.     if (propDesignator)
  347.         propDesignator->AcquireScriptable();
  348.         
  349.     FW_END_CONSTRUCTOR
  350. }
  351.  
  352. //---------------------------------------------------------------------------------------
  353. //    FW_CSetPropertyCommand::~SetPropertyCommand
  354. //---------------------------------------------------------------------------------------
  355.  
  356. FW_CSetPropertyCommand::~FW_CSetPropertyCommand()
  357. {
  358.     FW_START_DESTRUCTOR
  359.     
  360.     if (fPropDesignator)
  361.         fPropDesignator->ReleaseScriptable();
  362. }
  363.  
  364. //---------------------------------------------------------------------------------------
  365. //    FW_CSetPropertyCommand::DoIt
  366. //---------------------------------------------------------------------------------------
  367.  
  368. void FW_CSetPropertyCommand::DoIt(Environment* ev)
  369. {
  370.     if (GetCanUndo(ev))
  371.     {
  372.         FW_CString    undoString;
  373.         FW_CString    redoString;
  374.         
  375.         fPropDesignator->GetDesignateUndoStrings(ev, GetPart(ev), undoString, redoString);
  376.         SetMenuStrings(ev, undoString, redoString);
  377.     }
  378.  
  379.     fPropDesignator->SaveDesignateValue(ev, fOldValue, typeWildCard);
  380.     fPropDesignator->SetDesignateValue(ev, fNewValue);
  381. }
  382.  
  383. //---------------------------------------------------------------------------------------
  384. //    FW_CSetPropertyCommand::UndoIt
  385. //---------------------------------------------------------------------------------------
  386.  
  387. void FW_CSetPropertyCommand::UndoIt(Environment* ev)
  388. {
  389.     fPropDesignator->RestoreDesignateValue(ev, fOldValue);
  390. }
  391.  
  392. //---------------------------------------------------------------------------------------
  393. //    FW_CSetPropertyCommand::RedoIt
  394. //---------------------------------------------------------------------------------------
  395.  
  396. void FW_CSetPropertyCommand::RedoIt(Environment* ev)
  397. {
  398.     fPropDesignator->SetDesignateValue(ev, fNewValue);
  399. }
  400.