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

  1. //========================================================================================
  2. //
  3. //    File:                FWPrmise.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 FWPRMISE_H
  13. #include "FWPrmise.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWCLNINF_H
  25. #include "FWClnInf.h"
  26. #endif
  27.  
  28. #ifndef FWINTER_H
  29. #include "FWInter.h"
  30. #endif
  31.  
  32. #ifndef FWLNKSRC_H
  33. #include "FWLnkSrc.h"
  34. #endif
  35.  
  36. #ifndef FWSESION_H
  37. #include "FWSesion.h"
  38. #endif
  39.  
  40. // ----- OS Layer Includes -----
  41.  
  42. #ifndef FWBARRAY_H
  43. #include "FWBArray.h"
  44. #endif
  45.  
  46. #ifndef FWSUUTIL_H
  47. #include "FWSUUtil.h"
  48. #endif
  49.  
  50. // ----- Foundation Layer Includes -----
  51.  
  52. #ifndef FWMEMORY_H
  53. #include "FWMemory.h"
  54. #endif
  55.  
  56. #ifndef FWSOMENV_H
  57. #include "FWSOMEnv.h"
  58. #endif
  59.  
  60. #ifndef SLPRISTR_H
  61. #include "SLPriStr.h"
  62. #endif
  63.  
  64. // ----- OpenDoc Includes -----
  65.  
  66. #ifndef SOM_ODClipboard_xh
  67. #include <Clipbd.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODStorageUnitView_xh
  71. #include <SUView.xh>
  72. #endif
  73.  
  74. #ifndef SOM_Module_OpenDoc_StdProps_defined
  75. #include <StdProps.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  79. #include <StdTypes.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODDraft_xh
  83. #include <Draft.xh>
  84. #endif
  85.  
  86. //========================================================================================
  87. // RunTime Info
  88. //========================================================================================
  89.  
  90. #ifdef FW_BUILD_MAC
  91. #pragma segment fwpart2
  92. #endif
  93.  
  94. //========================================================================================
  95. //    Template Instantiations
  96. //========================================================================================
  97.  
  98. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CPromise)
  99. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CPromise)
  100.  
  101. #ifdef FW_USE_TEMPLATE_PRAGMAS
  102.  
  103. #pragma template_access public
  104. #pragma template FW_TOrderedCollection<FW_CPromise>
  105. #pragma template FW_TOrderedCollectionIterator<FW_CPromise>
  106.  
  107. #endif
  108.  
  109. //========================================================================================
  110. //    class FW_CPromise
  111. //========================================================================================
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    FW_CPromise::FW_CPromise
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_CPromise::FW_CPromise(Environment*ev, FW_StorageKinds storageKind, FW_CCloneInfo* cloneInfo, FW_CLinkSource* linkSrc) :
  118.     fScopeFrame(cloneInfo->GetScopeFrame(ev)),
  119.     fDataInterchange(cloneInfo->GetDataInterchange(ev)),
  120.     fStorageKind(storageKind),
  121.     fUpdateID(0),
  122.     fPromiseCount(0),
  123.     fLinkSource(linkSrc)
  124. {
  125.     FW_ASSERT(fStorageKind != FW_kPartStorage);    // can't promise on the part storage
  126.     FW_ASSERT(fStorageKind != FW_kFileStorage);    // can't promise on a file storage
  127.  
  128.     fUpdateID = FW_CSession::GetClipboard(ev)->GetUpdateID(ev);    
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CPromise::~FW_CPromise
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CPromise::~FW_CPromise()
  136. {
  137.     FW_SOMEnvironment ev;
  138.     
  139.     fDataInterchange->PrivPromiseDeleted(ev, this);
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CPromise::Promise
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CPromise::Promise(Environment* ev, ODStorageUnit* storageUnit, ODPropertyName propertyName, ODValueType valueType)
  147. {    
  148.     fDataInterchange->PrivPromise(ev, this, storageUnit, propertyName, valueType);
  149.     fPromiseCount++;
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CPromise::PrivHandleFulfillPromise
  154. //----------------------------------------------------------------------------------------
  155.  
  156. long FW_CPromise::PrivHandleFulfillPromise(Environment* ev, FW_CPart* part, ODStorageUnitView* promiseSUView)
  157. {
  158.     ODDraft* fromDraft = fScopeFrame->GetPart(ev)->GetDraft(ev);
  159.     ODDraft* dstDraft = promiseSUView->GetStorageUnit(ev)->GetDraft(ev);
  160.  
  161.     // Get the cloneKind from the kODPropCloneKindUsed property, if it's available
  162.     ODCloneKind cloneKind;
  163.     if (FW_SUExistsThenFocus(ev, promiseSUView->GetStorageUnit(ev), kODPropCloneKindUsed, kODCloneKind) )
  164.     {
  165.         FW_CByteArray byteArray;
  166.         promiseSUView->GetStorageUnit(ev)->GetValue(ev, sizeof(ODCloneKind), byteArray);
  167.         byteArray.CopyBuffer(&cloneKind, sizeof(ODCloneKind));
  168.     }
  169.     else
  170.         cloneKind = (fStorageKind == FW_kLinkStorage) ? kODCloneToLink : kODCloneCopy;
  171.  
  172.     FW_CAcquireODPropertyName propertyName(ev, promiseSUView);
  173.     FW_CAcquireODISOStr valueType = promiseSUView->GetType(ev);    
  174.  
  175.     FW_CCloneInfo cloneInfo(ev, fromDraft, fScopeFrame, cloneKind);    
  176.     cloneInfo.BeginClone(ev, dstDraft);
  177.  
  178.     FulfillPromise(ev, part, promiseSUView, propertyName, valueType, &cloneInfo);
  179.  
  180.     cloneInfo.EndClone(ev);
  181.     
  182.     return --fPromiseCount;
  183. }
  184.