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 / FWPart.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  30.1 KB  |  1,037 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPart.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 FWPART_H
  13. #include "FWPart.h"
  14. #endif
  15.  
  16. #ifndef FWPART_K
  17. #include "FWPart.k"
  18. #endif
  19.  
  20. #ifndef FWCONTNT_H
  21. #include "FWContnt.h"
  22. #endif
  23.  
  24. #ifndef FWFRAME_H
  25. #include "FWFrame.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWPRESEN_H
  33. #include "FWPresen.h"
  34. #endif
  35.  
  36. #ifndef FWIDLE_H
  37. #include "FWIdle.h"
  38. #endif
  39.  
  40. #ifndef FWSELECT_H
  41. #include "FWSelect.h"
  42. #endif
  43.  
  44. #ifndef FWINTER_H
  45. #include "FWInter.h"
  46. #endif
  47.  
  48. #ifndef FWPRTITE_H
  49. #include "FWPrtIte.h"
  50. #endif
  51.  
  52. #ifndef FWLNKMGR_H
  53. #include "FWLnkMgr.h"
  54. #endif
  55.  
  56. #ifndef FWCMD_H
  57. #include "FWCmd.h"
  58. #endif
  59.  
  60. #ifndef FWMNUBAR_H
  61. #include "FWMnuBar.h"
  62. #endif
  63.  
  64. #ifndef FWMEMMGR_H
  65. #include "FWMemMgr.h"
  66. #endif
  67.  
  68. #ifndef FWEVENTD_H
  69. #include "FWEventD.h"
  70. #endif
  71.  
  72. #ifndef SLMIXOS_H
  73. #include "SLMixOS.h"
  74. #endif
  75.  
  76. #ifndef FWSEMINT_H
  77. #include "FWSemInt.h"
  78. #endif
  79.  
  80. #ifndef SLODFSTR_K
  81. #include "SLODFStr.k"
  82. #endif
  83.  
  84. #ifndef SLODFSTR_H
  85. #include "SLODFStr.h"
  86. #endif
  87.  
  88. #ifndef _STDTYPIO_
  89. #include "StdTypIO.h"
  90. #endif
  91.  
  92. // ----- OS Utilites -----
  93.  
  94. #ifndef FWCFMRES_H
  95. #include "FWCFMRes.h"
  96. #endif
  97.  
  98. #ifndef FWRESSIN_H
  99. #include "FWResSin.h"
  100. #endif
  101.  
  102. // ----- OpenDoc Utilites -----
  103.  
  104. #ifndef _INFOUTIL_
  105. #include "InfoUtil.h"
  106. #endif
  107.  
  108. // ----- OpenDoc Includes -----
  109.  
  110. #ifndef SOM_ODSession_xh
  111. #include <ODSessn.xh>
  112. #endif
  113.  
  114. #ifndef SOM_Module_OpenDoc_Foci_defined
  115. #include <Foci.xh>
  116. #endif
  117.  
  118. #ifndef SOM_Module_OpenDoc_StdProps_defined
  119. #include <StdProps.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODArbitrator_xh
  123. #include <Arbitrat.xh>
  124. #endif
  125.  
  126. #ifndef SOM_ODClipboard_xh
  127. #include <Clipbd.xh>
  128. #endif
  129.  
  130. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  131. #include <StdTypes.xh>
  132. #endif
  133.  
  134. #ifndef SOM_Module_OpenDoc_Commands_defined
  135. #include <CmdDefs.xh>
  136. #endif
  137.  
  138. #ifndef SOM_ODTranslation_xh
  139. #include <Translt.xh>
  140. #endif
  141.  
  142. //========================================================================================
  143. // Globals
  144. //========================================================================================
  145.  
  146. unsigned short FW_CPart::gSessionGlobalsCount = 0;
  147.  
  148. ODTypeToken FW_CPart::gSelectionFocusToken = 0;
  149. ODTypeToken FW_CPart::gMenuFocusToken = 0;
  150. ODTypeToken FW_CPart::gKeyFocusToken = 0;
  151. ODTypeToken FW_CPart::gModalFocusToken = 0;
  152. ODTypeToken FW_CPart::gClipboardFocusToken = 0;
  153. ODTypeToken FW_CPart::gScrollingFocusToken = 0;
  154. ODTypeToken FW_CPart::gViewAsFrameToken = 0;
  155. ODTypeToken FW_CPart::gViewAsSmallIconToken = 0;
  156. ODTypeToken FW_CPart::gViewAsLargeIconToken = 0;
  157. ODTypeToken FW_CPart::gViewAsThumbnailToken = 0;
  158.  
  159. #ifdef FW_BUILD_MAC
  160. ODType FW_CPart::gMacPICTDataType = NULL;
  161. ODType FW_CPart::gMacPICTFileType = NULL;
  162. ODType FW_CPart::gMachfsDataType = NULL;
  163. ODType FW_CPart::gMacTEXTFileType = NULL;
  164. ODType FW_CPart::gMacTEXTDataType = NULL;
  165. ODType FW_CPart::gMacMooVFileType = NULL;
  166. #endif
  167.  
  168. //========================================================================================
  169. // RunTime Info
  170. //========================================================================================
  171.  
  172. #ifdef FW_BUILD_MAC
  173. #pragma segment fwpart2
  174. #endif
  175.  
  176. FW_DEFINE_CLASS_M1(FW_CPart, FW_MEventHandler)
  177. FW_DEFINE_AUTO(FW_CPart)
  178.  
  179. //========================================================================================
  180. //    class FW_CPart
  181. //========================================================================================
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CPart::FW_CPart    
  185. //----------------------------------------------------------------------------------------
  186.  
  187. FW_CPart::FW_CPart(ODPart* odPart,
  188.                     FW_Instance partInstance,
  189.                     FW_ResourceId partInfoID) :
  190.     FW_MEventHandler(),
  191.     fODPart(odPart),
  192.     fMenuBar(NULL),
  193.     fEventDispatcher(NULL),
  194.     fLastActiveFrame(NULL),
  195.     fPresentations(NULL),
  196.     fDefaultPresentation(NULL),
  197.     fIdleCount(0),
  198.     fModalDialogCount(0),
  199.     fExtensionManager(NULL),
  200.     fSemanticInterface(NULL),
  201.     fPartInstance(partInstance),
  202.     fViewAsIconID(0),
  203.     fLinkManager(NULL),
  204.     fPrintInfo(NULL),
  205.     fIdler(NULL),
  206.     fContent(NULL),
  207.     fDataInterchange(NULL),
  208.     fPartInfoID(partInfoID),
  209.     fPartKind(NULL)
  210. {
  211.     FW_END_CONSTRUCTOR
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CPart::~FW_CPart    
  216. //----------------------------------------------------------------------------------------
  217.  
  218. FW_CPart::~FW_CPart()
  219. {    
  220.     FW_START_DESTRUCTOR
  221.     FW_ASSERT(fIdleCount == 0);
  222.     FW_ASSERT(fModalDialogCount == 0);
  223.     
  224.     FW_ASSERT(fIdler == NULL);    // Should be NULL by now
  225.     
  226.     // ----- Delete all the presentations
  227.     FW_CPresentation* presentation;
  228.     while ((presentation = (FW_CPresentation*)fPresentations->First()) != NULL)
  229.     {
  230.         PrivRemovePresentation(presentation);
  231.         delete presentation;
  232.     }        
  233.  
  234.     delete fPresentations;
  235.     fPresentations = NULL;
  236.  
  237.     // ----- Delete MenuBar
  238.     delete fMenuBar;
  239.     fMenuBar = NULL;
  240.     
  241.     // ----- Delete Event Dispatcher
  242.     delete fEventDispatcher;
  243.     fEventDispatcher = NULL;
  244.     
  245.     // ----- Delete Semantic Interface
  246.     delete fSemanticInterface;
  247.     fSemanticInterface = NULL;
  248.     
  249.     // ----- Delete Link Manager
  250.     delete fLinkManager;
  251.     fLinkManager = NULL;
  252.     
  253.     // ----- Delete Content
  254.     delete fContent;
  255.     fContent = NULL;
  256.     
  257.     // ----- Delete Data Interchange
  258.     delete fDataInterchange;
  259.     fDataInterchange = NULL;
  260.     
  261.     // ----- Release All the globals
  262.     PrivReleaseGlobals();
  263.     
  264.     // ----- Delete Part kind -----
  265.     if (fPartKind)
  266.         FW_PrimitiveFreeBlock(fPartKind);
  267.     fPartKind = NULL;
  268. }
  269.  
  270. //---------------------------------------------------------------------------------------
  271. //    FW_CPart::Initialize
  272. //---------------------------------------------------------------------------------------
  273. // Call inherited first when overriding
  274.  
  275. void FW_CPart::Initialize(Environment *ev)
  276. {
  277.     PrivInitGlobals(ev);
  278.     
  279.     // ----- Menu bar -----
  280.     fMenuBar = new FW_CMenuBar(ev, fODPart, fPartInstance);
  281.     
  282.     // ----- Create Event Dispatcher -----
  283.     fEventDispatcher = this->PrivNewEventDispatcher(ev);
  284.     
  285.     // ----- Presentation collection -----
  286.     fPresentations = FW_NEW(FW_TOrderedCollection<FW_CPresentation>, ());
  287.  
  288.     // ----- Data Interchage object -----
  289.     fDataInterchange = this->PrivNewDataInterchange(ev);
  290.  
  291.     // ----- Part Content object -----
  292.     fContent = this->NewPartContent(ev);
  293.  
  294.     // ----- Linking Support -----
  295.     fLinkManager = this->NewLinkManager(ev);
  296.     
  297.     // ----- Load Part Info Resource -----
  298.     FW_CSharedLibraryResourceFile resFile(ev, fPartInstance);
  299. #ifdef FW_DEBUG
  300.     if (!resFile->HasResource(ev, fPartInfoID, FW_kPartInfoResourceType))
  301.         FW_DEBUG_MESSAGE("The part info resource is missing");
  302. #endif    
  303.     FW_PResource resource(ev, resFile, fPartInfoID, FW_kPartInfoResourceType);
  304.     FW_PResourceSink sink(ev, resource);
  305.     FW_CReadableStream stream(sink);
  306.     stream >> fViewAsIconID;
  307.     stream >> fPartUserName;    
  308.     FW_CString partKind;
  309.     stream >> partKind;
  310.     
  311.     FW_ByteCount byteCount = partKind.GetByteLength();
  312.     fPartKind = (char*)FW_PrimitiveAllocateBlock(byteCount + 1);
  313.     FW_PrimitiveCopyMemory(partKind.RevealBuffer(), fPartKind, byteCount);
  314.     fPartKind[byteCount] = 0;
  315. }
  316.  
  317. //---------------------------------------------------------------------------------------
  318. //    FW_CPart::PrivInitGlobals
  319. //---------------------------------------------------------------------------------------
  320.  
  321. void FW_CPart::PrivInitGlobals(Environment *ev)
  322. {
  323.     if (gSessionGlobalsCount == 0)
  324.     {
  325.         // ----- Get the session -----
  326.         ODSession* session = GetSession(ev);
  327.  
  328.         FW_ASSERT(gSelectionFocusToken == 0);
  329.         gSelectionFocusToken = session->Tokenize(ev, kODSelectionFocus);
  330.         
  331.         FW_ASSERT(gMenuFocusToken == 0);
  332.         gMenuFocusToken = session->Tokenize(ev, kODMenuFocus);
  333.         
  334.         FW_ASSERT(gKeyFocusToken == 0);
  335.         gKeyFocusToken = session->Tokenize(ev, kODKeyFocus);
  336.         
  337.         FW_ASSERT(gClipboardFocusToken == 0);
  338.         gClipboardFocusToken = session->Tokenize(ev, kODClipboardFocus);
  339.         
  340.         FW_ASSERT(gModalFocusToken == 0);
  341.         gModalFocusToken = session->Tokenize(ev, kODModalFocus);
  342.         
  343.         FW_ASSERT(gScrollingFocusToken == 0);
  344.         gScrollingFocusToken = session->Tokenize(ev, kODScrollingFocus);
  345.         
  346.         FW_ASSERT(gViewAsFrameToken == 0);
  347.         gViewAsFrameToken = session->Tokenize(ev, kODViewAsFrame);
  348.         
  349.         FW_ASSERT(gViewAsSmallIconToken == 0);
  350.         gViewAsSmallIconToken = session->Tokenize(ev, kODViewAsSmallIcon);
  351.         
  352.         FW_ASSERT(gViewAsLargeIconToken == 0);
  353.         gViewAsLargeIconToken = session->Tokenize(ev, kODViewAsLargeIcon);
  354.         
  355.         FW_ASSERT(gViewAsThumbnailToken == 0);
  356.         gViewAsThumbnailToken = session->Tokenize(ev, kODViewAsThumbnail);
  357.  
  358. #ifdef FW_BUILD_MAC
  359.         ODTranslation *translate = session->GetTranslation(ev);
  360.         
  361.         FW_ASSERT(gMacPICTDataType == NULL);
  362.         gMacPICTDataType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
  363.         
  364.         FW_ASSERT(gMacPICTFileType == NULL);
  365.         gMacPICTFileType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformFileType);
  366.         
  367.         FW_ASSERT(gMachfsDataType == NULL);
  368.         gMachfsDataType = translate->GetISOTypeFromPlatformType(ev, 'hfs ', kODPlatformDataType);
  369.  
  370.         FW_ASSERT(gMacTEXTDataType == NULL);
  371.         gMacTEXTDataType = translate->GetISOTypeFromPlatformType(ev, 'TEXT', kODPlatformDataType);
  372.         
  373.         FW_ASSERT(gMacTEXTFileType == NULL);
  374.         gMacTEXTFileType = translate->GetISOTypeFromPlatformType(ev, 'TEXT', kODPlatformFileType);
  375.  
  376.         FW_ASSERT(gMacMooVFileType == NULL);
  377.         gMacMooVFileType = translate->GetISOTypeFromPlatformType(ev, 'MooV', kODPlatformFileType);
  378. #endif
  379.     }
  380.     
  381.     gSessionGlobalsCount++;
  382. }    
  383.  
  384. //---------------------------------------------------------------------------------------
  385. //    FW_CPart::PrivReleaseGlobals
  386. //---------------------------------------------------------------------------------------
  387.  
  388. void FW_CPart::PrivReleaseGlobals()
  389. {
  390.     gSessionGlobalsCount--;
  391.     FW_ASSERT(gSessionGlobalsCount >= 0);
  392.     
  393.     if (gSessionGlobalsCount == 0)
  394.     {
  395.         // I am resetting those globals to their default value
  396.         //    because if the DLL is not unloaded they wont be reinitialized
  397.         gSelectionFocusToken = 0;    
  398.         gMenuFocusToken = 0;        
  399.         gKeyFocusToken = 0;    
  400.         gClipboardFocusToken = 0;        
  401.         gModalFocusToken = 0;    
  402.         gScrollingFocusToken = 0;    
  403.         gViewAsFrameToken = 0;    
  404.         gViewAsSmallIconToken = 0;    
  405.         gViewAsLargeIconToken = 0;    
  406.         gViewAsThumbnailToken = 0;
  407.  
  408. #ifdef FW_BUILD_MAC
  409.         FW_ASSERT(gMacPICTDataType != NULL);
  410.         FW_CMemoryManager::FreeBlock(gMacPICTDataType);
  411.         gMacPICTDataType = NULL;
  412.         
  413.         FW_ASSERT(gMacPICTFileType != NULL);
  414.         FW_CMemoryManager::FreeBlock(gMacPICTFileType);
  415.         gMacPICTFileType = NULL;
  416.  
  417.         FW_ASSERT(gMacTEXTDataType != NULL);
  418.         FW_CMemoryManager::FreeBlock(gMacTEXTDataType);
  419.         gMacTEXTDataType = NULL;
  420.         
  421.         FW_ASSERT(gMacTEXTFileType != NULL);
  422.         FW_CMemoryManager::FreeBlock(gMacTEXTFileType);
  423.         gMacTEXTFileType = NULL;
  424.  
  425.         FW_ASSERT(gMacMooVFileType != NULL);
  426.         FW_CMemoryManager::FreeBlock(gMacMooVFileType);
  427.         gMacMooVFileType = NULL;
  428.  
  429.         FW_ASSERT(gMachfsDataType != NULL);
  430.         FW_CMemoryManager::FreeBlock(gMachfsDataType);
  431.         gMachfsDataType = NULL;
  432. #endif
  433.     }
  434. }
  435.  
  436. //---------------------------------------------------------------------------------------
  437. //    FW_CPart::AddProperties
  438. //---------------------------------------------------------------------------------------
  439. //    AddProperties can be called multiple times
  440.  
  441. void FW_CPart::AddProperties(Environment* ev, ODStorageUnit* storageUnit)
  442. {
  443.     //    FW_SUAddPropValue correctly tests whether the property and value exist before
  444.     //    trying to create them
  445.     FW_SUAddPropValue(ev, storageUnit, kODPropContents, this->GetPartKind(ev));
  446. }
  447.  
  448. //------------------------------------------------------------------------------
  449. // FW_CPart::IsValidContentValue
  450. //------------------------------------------------------------------------------
  451. //    You need to override this method it your are supporting more than one type.
  452. //    The default implementation only test for the part Kind
  453.  
  454. FW_Boolean FW_CPart::IsValidContentValue(Environment* ev, ODType type)
  455. {
  456.     return FW_PrimitiveStringEqual(type, this->GetPartKind(ev));
  457. }
  458.  
  459. //------------------------------------------------------------------------------
  460. // FW_CPart::PrivCleanseContentProperty
  461. //------------------------------------------------------------------------------
  462.  
  463. void FW_CPart::PrivCleanseContentProperty(Environment* ev, ODStorageUnit* storageUnit)
  464. {
  465.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
  466.     
  467.     unsigned long numValues = storageUnit->CountValues(ev);
  468.     
  469.     for (unsigned long index = numValues; index >= 1; index--)
  470.     {
  471.         // Index from 1 to n through the values.
  472.         storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
  473.  
  474.         FW_CAcquireODType valueType = storageUnit->GetType(ev);
  475.  
  476.         if (!IsValidContentValue(ev, valueType))
  477.             storageUnit->Remove(ev);
  478.     }
  479. }
  480.  
  481. //---------------------------------------------------------------------------------------
  482. //    FW_CPart::ClearPartStorage
  483. //---------------------------------------------------------------------------------------
  484.  
  485. void FW_CPart::ClearPartStorage(Environment* ev, ODStorageUnit* storageUnit)
  486. {
  487.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, this->GetPartKind(ev), 0, kODPosUndefined);
  488.     storageUnit->Remove(ev);
  489.     storageUnit->AddValue(ev, this->GetPartKind(ev));
  490. }
  491.  
  492. //---------------------------------------------------------------------------------------
  493. //    FW_CPart::PrivCloneInto
  494. //---------------------------------------------------------------------------------------
  495.  
  496. void FW_CPart::PrivCloneInto(Environment* ev,
  497.                             ODDraftKey key,
  498.                             ODStorageUnit* toSU,
  499.                             ODFrame* scope)
  500. {        
  501. FW_UNUSED(key);
  502. FW_UNUSED(scope);
  503.  
  504.     // ----- Only thing to do is to externalize my content -----
  505.     ExternalizeContent(ev, toSU, NULL);
  506. }
  507.  
  508. //---------------------------------------------------------------------------------------
  509. //    FW_CPart::InternalizeContent
  510. //---------------------------------------------------------------------------------------
  511.  
  512. void FW_CPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  513. {
  514.     // Simply forward to the content object
  515.     if (fContent)
  516.         fContent->Internalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
  517. }
  518.  
  519. //---------------------------------------------------------------------------------------
  520. //    FW_CPart::ExternalizeContent
  521. //---------------------------------------------------------------------------------------
  522.  
  523. void FW_CPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  524. {
  525.     if (fContent)
  526.     {
  527.         // By default, clear the part kind value from the storage unit
  528.         this->ClearPartStorage(ev, storageUnit);
  529.  
  530.         // Simply forward to the content object
  531.         fContent->Externalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
  532.     }
  533. }
  534.  
  535. //---------------------------------------------------------------------------------------
  536. //    FW_CPart::PrivNewEventDispatcher
  537. //---------------------------------------------------------------------------------------
  538.  
  539. FW_CEventDispatcher* FW_CPart::PrivNewEventDispatcher(Environment *ev)
  540. {
  541. FW_UNUSED(ev);
  542.  
  543.     return new FW_CEventDispatcher(this, fMenuBar);
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. //    FW_CPart::PrivNewPresentation    
  548. //----------------------------------------------------------------------------------------
  549.  
  550. FW_CPresentation* FW_CPart::PrivNewPresentation(Environment *ev, 
  551.                                             FW_CSelection* selection,
  552.                                             ODTypeToken presentationType)
  553. {
  554.     return new FW_CPresentation(ev, this, selection, presentationType);
  555. }
  556.  
  557. //----------------------------------------------------------------------------------------
  558. //    FW_CPart::RegisterPresentation    
  559. //----------------------------------------------------------------------------------------
  560. //    the selection object will be owned by the presentation
  561.  
  562. FW_CPresentation* FW_CPart::RegisterPresentation(Environment *ev, 
  563.                                                 ODType presentationType,
  564.                                                 FW_Boolean defaultPresentation,
  565.                                                 FW_CSelection* selection)
  566. {
  567.     FW_CPresentation* presentation = NULL;
  568.     FW_VOLATILE(presentation);
  569.     
  570.     FW_TRY
  571.     {
  572.         ODTypeToken token = this->GetSession(ev)->Tokenize(ev, presentationType);
  573.     
  574.         // ----- Test that we don't register a presentation twice -----
  575.         FW_ASSERT(FindPresentation(ev, token) == NULL);
  576.     
  577.         presentation = PrivNewPresentation(ev, selection, token);
  578.         
  579.         if (selection)
  580.             selection->PrivSetPresentation(presentation);
  581.         
  582.         PrivAddPresentation(presentation); 
  583.             
  584.         // ----- if flagged as default or first one -----
  585.         if (defaultPresentation || (fDefaultPresentation == NULL))
  586.             fDefaultPresentation = presentation;        
  587.     }
  588.     FW_CATCH_BEGIN
  589.     FW_CATCH_EVERYTHING()
  590.     {
  591.         if (presentation == NULL)
  592.             delete selection;        // Otherwise will be deleted by next line
  593.                 
  594.         delete presentation;
  595.         
  596.         FW_THROW_SAME();
  597.     }
  598.     FW_CATCH_END
  599.  
  600.     return presentation;
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    FW_CPart::FindPresentation    
  605. //----------------------------------------------------------------------------------------
  606.  
  607. FW_CPresentation* FW_CPart::FindPresentation(Environment *ev, ODTypeToken presentationType) const
  608. {
  609.     FW_CPartPresentationIterator ite(this);
  610.     for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
  611.     {
  612.         if (presentation->GetPresentationType(ev) == presentationType)
  613.             return presentation;
  614.     }
  615.     
  616.     return NULL;
  617. }
  618.  
  619. //----------------------------------------------------------------------------------------
  620. //    FW_CPart::CountDisplayFrame
  621. //----------------------------------------------------------------------------------------
  622.  
  623. unsigned long FW_CPart::CountDisplayFrame(Environment *ev) const
  624. {
  625.     unsigned long count = 0;
  626.     
  627.     FW_CPartPresentationIterator ite(this);
  628.     for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
  629.     {
  630.         count += presentation->CountFrame(ev);
  631.     }
  632.     
  633.     return count;
  634. }
  635.  
  636. //---------------------------------------------------------------------------------------
  637. //    FW_CPart::NewLinkManager
  638. //---------------------------------------------------------------------------------------
  639.  
  640. FW_CLinkManager* FW_CPart::NewLinkManager(Environment *ev)
  641. {
  642. FW_UNUSED(ev);
  643.     // Must be overridden if part creates Links
  644.     return NULL;
  645. }
  646.  
  647. //---------------------------------------------------------------------------------------
  648. //    FW_CPart::GetPartName
  649. //---------------------------------------------------------------------------------------
  650.  
  651. FW_Boolean FW_CPart::GetPartName(Environment *ev, FW_CString& partName) const
  652. {
  653.     ODName*     windowName = NULL;
  654.     FW_Boolean     nameIsProperty = FALSE;
  655.  
  656.     windowName = ODGetITextProp(ev, fODPart->GetStorageUnit(ev), kODPropName, kODMacIText, windowName);
  657. //    windowName = ODGetPOName(ev, fODPart, NULL);
  658.  
  659.     if (windowName != NULL && GetITextStringLength(windowName) != 0)
  660.     {
  661.         partName = GetCStringFromIText(windowName);
  662.         nameIsProperty = TRUE;
  663.     }
  664.     else
  665.         partName = fPartUserName;
  666.         
  667.     if (windowName)
  668.         DisposeIText(windowName);
  669.         
  670.     return nameIsProperty;
  671. }
  672.  
  673. //---------------------------------------------------------------------------------------
  674. //    FW_CPart::PrivEnableMenuBar
  675. //---------------------------------------------------------------------------------------
  676. // This is called when opening/closing a modal dialog.
  677. // We keep a count of nested modal dialogs so that we don't re-enable the menu-bar 
  678. // if a modal dialog is still up
  679.  
  680. void FW_CPart::PrivEnableMenuBar(Environment *ev, FW_Boolean enable, FW_Boolean appleMenu)
  681. {
  682.     if (enable == false)
  683.         fModalDialogCount += 1;
  684.     else
  685.     {    
  686.         fModalDialogCount -= 1;
  687.         if (fModalDialogCount > 0) return;
  688.     }
  689.     
  690. #ifdef FW_BUILD_MAC
  691.     GetMenuBar(ev)->MacEnableMenuBar(ev, enable);
  692.     // We keep the Apple menu enabled for moveable dialog boxes
  693.     if (enable == false && appleMenu == true)
  694.         GetMenuBar(ev)->EnableCommand(ev, kODCommandAppleMenu, true);
  695. #endif
  696.  
  697. #ifdef FW_BUILD_WIN
  698.     // Windows does this automatically?
  699. #endif
  700. }
  701.  
  702. //---------------------------------------------------------------------------------------
  703. //    FW_CPart::InstallMenus
  704. //---------------------------------------------------------------------------------------
  705.  
  706. void FW_CPart::InstallMenus(Environment *ev, FW_CMenuBar* menuBar)
  707. {
  708.     if (menuBar)
  709.         menuBar->PrivDisplay(ev);
  710. }
  711.  
  712. //---------------------------------------------------------------------------------------
  713. //    FW_CPart::Changed
  714. //---------------------------------------------------------------------------------------
  715. //    ODF API
  716.  
  717. void FW_CPart::Changed(Environment *ev)
  718. {
  719.     GetDraft(ev)->SetChangedFromPrev(ev);
  720. }
  721.  
  722. //---------------------------------------------------------------------------------------
  723. //    FW_CPart::PrivGetPresentation
  724. //---------------------------------------------------------------------------------------
  725.  
  726. FW_CPresentation* FW_CPart::PrivGetPresentation(Environment *ev, ODFrame* odFrame) const
  727. {
  728.     ODTypeToken    presDefault = GetSession(ev)->Tokenize(ev, kODPresDefault);
  729.     ODTypeToken token = presDefault;
  730.     FW_Boolean isRoot = TRUE;
  731.     
  732.     FW_CPresentation* presentation = NULL;
  733.  
  734.     if (odFrame != NULL)
  735.     {
  736.         token = odFrame->GetPresentation(ev);
  737.         isRoot = odFrame->IsRoot(ev);
  738.     }
  739.     
  740.     if (token == presDefault)
  741.         presentation = fDefaultPresentation;
  742.     else
  743.     {
  744.         presentation = FindPresentation(ev, token);
  745.         
  746.         if (presentation == NULL)
  747.             presentation = fDefaultPresentation;
  748.     }
  749.     
  750.     return ValidatePresentation(ev, presentation, isRoot);
  751. }
  752.  
  753. //---------------------------------------------------------------------------------------
  754. //    FW_CPart::ValidatePresentation
  755. //---------------------------------------------------------------------------------------
  756.  
  757. FW_CPresentation* FW_CPart::ValidatePresentation(Environment *ev, FW_CPresentation *presentation, FW_Boolean isRootFrame) const
  758. {
  759. FW_UNUSED(ev);
  760. FW_UNUSED(isRootFrame);
  761.  
  762.     return presentation;
  763. }
  764.  
  765. //----------------------------------------------------------------------------------------
  766. //    FW_CPart::HasSelectionFocus
  767. //----------------------------------------------------------------------------------------
  768.  
  769. FW_Boolean FW_CPart::HasSelectionFocus(Environment *ev) const
  770. {
  771.     if (fLastActiveFrame)
  772.     {
  773.         return fLastActiveFrame->HasSelectionFocus(ev);
  774.     }
  775.     else
  776.         return FALSE;
  777. }
  778.  
  779. //----------------------------------------------------------------------------------------
  780. //    FW_CPart::GetActiveFacet
  781. //----------------------------------------------------------------------------------------
  782.  
  783. ODFacet* FW_CPart::GetActiveFacet(Environment *ev) const
  784. {
  785.     return (fLastActiveFrame != NULL) ? fLastActiveFrame->GetActiveFacet(ev) : NULL;
  786. }
  787.  
  788. //----------------------------------------------------------------------------------------
  789. //    FW_CPart::GetSession
  790. //----------------------------------------------------------------------------------------
  791.  
  792. ODSession* FW_CPart::GetSession(Environment *ev) const
  793. {
  794.     return this->GetStorageUnit(ev)->GetSession(ev);
  795. }
  796.  
  797. //----------------------------------------------------------------------------------------
  798. //    FW_CPart::Release
  799. //----------------------------------------------------------------------------------------
  800. //    Call inherited first when overridden
  801.  
  802. void FW_CPart::Release(Environment *ev)
  803. {
  804.     unsigned long refcount = fODPart->GetRefCount(ev);
  805.  
  806.     // ------ The last refcount is caused by the register idle -----
  807.     if (refcount == 1 && fIdler != NULL)
  808.     {
  809.         FW_ASSERT(fIdleCount == 1);    // We should only have the part register by now
  810.         fIdler->UnregisterIdle(ev);
  811.     }
  812.     
  813.     if (refcount == 0)
  814.     {
  815.         GetDraft(ev)->ReleasePart(ev, fODPart);
  816.     }
  817. }
  818.  
  819. //----------------------------------------------------------------------------------------
  820. //    FW_CPart::ReleaseAll
  821. //----------------------------------------------------------------------------------------
  822. //    Call inherited first when overridden
  823.  
  824. void FW_CPart::ReleaseAll(Environment *ev)
  825. {
  826.     //     Will resolve or just delete my promises
  827.     fDataInterchange->ResolveAllPromises(ev);
  828.     
  829.     // ----- Release part content
  830.     if (fContent)
  831.         fContent->ReleaseAll(ev);
  832.  
  833.     // ----- Delete any and all links
  834.     if (fLinkManager)
  835.         fLinkManager->RemoveAllLinks(ev);
  836.     
  837.     // ----- Release all display Frames
  838.     FW_CPartPresentationIterator ite(this);
  839.     for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
  840.     {
  841.         presentation->ReleaseAll(ev);
  842.     }
  843.  
  844. }
  845.  
  846. //----------------------------------------------------------------------------------------
  847. //    FW_CPart::IsReadOnly
  848. //----------------------------------------------------------------------------------------
  849.  
  850. FW_Boolean FW_CPart::IsReadOnly(Environment *ev) const
  851. {
  852.     return GetDraft(ev)->GetPermissions(ev) < kODDPSharedWrite;
  853. }
  854.  
  855. //----------------------------------------------------------------------------------------
  856. //    FW_CPart::GetDraft
  857. //----------------------------------------------------------------------------------------
  858.  
  859. ODDraft* FW_CPart::GetDraft(Environment *ev) const
  860. {
  861.     return fODPart->GetStorageUnit(ev)->GetDraft(ev);
  862. }
  863.  
  864. //----------------------------------------------------------------------------------------
  865. //    FW_CPart::HandleAdjustMenus
  866. //----------------------------------------------------------------------------------------
  867. //    The part should have the last word in case it is readonly
  868.  
  869. FW_Boolean FW_CPart::HandleAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  870. {    
  871.     FW_Boolean result = FW_MEventHandler::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  872.  
  873.     // ------ Disable items we know have to be disabled ----- 
  874.     if (hasMenuFocus)
  875.     {
  876.         if (IsReadOnly(ev))
  877.         {
  878.             menuBar->EnableCommand(ev, kODCommandPaste, FALSE);
  879.             menuBar->EnableCommand(ev, kODCommandCut, FALSE);
  880.             menuBar->EnableCommand(ev, kODCommandClear, FALSE);
  881.             menuBar->EnableCommand(ev, kODCommandPasteAs, FALSE);
  882.         }
  883. #ifdef FW_BUILD_MAC
  884.         // Set the name in the about item 
  885.         FW_CString aboutString;
  886.         ::FW_PrivLoadODFString(ev, FW_kAboutString, aboutString);
  887.         aboutString += fPartUserName;
  888.         aboutString += "…";
  889.         menuBar->SetItemString(ev, kODCommandAbout, aboutString);
  890. #endif
  891.     }
  892.     
  893.     return result;
  894. }
  895.  
  896. //----------------------------------------------------------------------------------------
  897. //    FW_CPart::NewDocumentWindow
  898. //----------------------------------------------------------------------------------------
  899.  
  900. FW_CWindow* FW_CPart::NewDocumentWindow(Environment* ev)
  901. {
  902.     FW_CRect windRect;    
  903.     ::FW_GetMainScreenBounds(windRect);    
  904.  
  905.     FW_CPresentation* presentation = PrivGetPresentation(ev, NULL);    // NULL means root frame
  906.  
  907.     return new FW_CWindow(ev,
  908.                         this,
  909.                          FW_CPart::gViewAsFrameToken,
  910.                         presentation,
  911.                         windRect.Size(),            // I know it is too big but FW_CWindow::__ct will adjust it, 
  912.                         windRect.TopLeft(),
  913.                         FW_kDocumentWindow);
  914. }
  915.  
  916. //----------------------------------------------------------------------------------------
  917. //    FW_CPart::PrivCountIdleRegistering
  918. //----------------------------------------------------------------------------------------
  919.  
  920. void FW_CPart::PrivCountIdleRegistering(FW_Boolean registering)
  921. {
  922.     if (registering)
  923.         fIdleCount++;
  924.     else
  925.     {
  926.         FW_ASSERT(fIdleCount >= 1);
  927.         fIdleCount--;
  928.     }
  929. }
  930.  
  931. //---------------------------------------------------------------------------------------
  932. //    FW_CPart::IsValidDisplayFrame
  933. //---------------------------------------------------------------------------------------
  934.  
  935. FW_Boolean FW_CPart::IsValidDisplayFrame(Environment* ev, ODStorageUnitID displayFrameID) const
  936. {
  937.     FW_CPartFrameIterator ite(ev, this);
  938.     for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
  939.     {
  940.         if (frame->GetID(ev) == displayFrameID)
  941.             return TRUE;
  942.     }
  943.     
  944.     return FALSE;
  945. }
  946.  
  947. //---------------------------------------------------------------------------------------
  948. //    FW_CPart::PrivNewDataInterchange
  949. //---------------------------------------------------------------------------------------
  950.  
  951. FW_CDataInterchange* FW_CPart::PrivNewDataInterchange(Environment* ev)
  952. {
  953.     return new FW_CDataInterchange(ev, this);
  954. }
  955.  
  956. //---------------------------------------------------------------------------------------
  957. //    FW_CPart::LinkStatusChanged
  958. //---------------------------------------------------------------------------------------
  959.  
  960. void FW_CPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
  961. {
  962. FW_UNUSED(ev);
  963. FW_UNUSED(odFrame);
  964.     // Nothing to do. See FW_CEmbeddingPart::LinkStatusChanged
  965. }
  966.  
  967. //---------------------------------------------------------------------------------------
  968. //    FW_CPart::Purge
  969. //---------------------------------------------------------------------------------------
  970.  
  971. ODSize FW_CPart::Purge(Environment *ev, ODSize size)
  972. {
  973. FW_UNUSED(ev);
  974. FW_UNUSED(size);
  975.     return 0;
  976. }
  977.  
  978. //---------------------------------------------------------------------------------------
  979. // FW_CPart::SetPrintInfo
  980. //---------------------------------------------------------------------------------------
  981.  
  982. void FW_CPart::SetPrintInfo(FW_CPrintInfo* printInfo)
  983. {
  984.     fPrintInfo = printInfo;
  985. }
  986.  
  987. //---------------------------------------------------------------------------------------
  988. // FW_CPart::GetPrintInfo
  989. //---------------------------------------------------------------------------------------
  990.  
  991. FW_CPrintInfo* FW_CPart::GetPrintInfo() const
  992. {
  993.     return fPrintInfo;
  994. }
  995.  
  996. //---------------------------------------------------------------------------------------
  997. // FW_CPart::TranslateData
  998. //---------------------------------------------------------------------------------------
  999.  
  1000. ODTranslateResult FW_CPart::TranslateData(Environment* ev, ODStorageUnit* storageUnit,
  1001.                                           ODType translateKind,
  1002.                                           ODType desiredKind)
  1003. {
  1004.     // Translation was requested from translateKind to desiredKind
  1005.  
  1006.     //--- Add desiredKind and create the destination storage unit view
  1007.     ODSUForceFocus(ev, storageUnit, kODPropContents, desiredKind);
  1008.     FW_CAcquireODStorageUnitView toView(ev, storageUnit);
  1009.  
  1010.     //--- Create the source storage unit view
  1011.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, translateKind, 0, kODPosUndefined);
  1012.     FW_CAcquireODStorageUnitView fromView(ev, storageUnit);
  1013.  
  1014.     //--- Get the translation object and perform the translation
  1015.     ODTranslation* translation = this->GetSession(ev)->GetTranslation(ev);
  1016.     ODTranslateResult translateResult = translation->TranslateView(ev, fromView, toView);
  1017.  
  1018.     return translateResult;
  1019. }
  1020.  
  1021. //---------------------------------------------------------------------------------------
  1022. // FW_CPart::PrivAddPresentation
  1023. //---------------------------------------------------------------------------------------
  1024.  
  1025. void FW_CPart::PrivAddPresentation(FW_CPresentation* presentation)
  1026. {
  1027.     fPresentations->AddLast(presentation);
  1028. }
  1029.  
  1030. //---------------------------------------------------------------------------------------
  1031. // FW_CPart::PrivRemovePresentation
  1032. //---------------------------------------------------------------------------------------
  1033.  
  1034. void FW_CPart::PrivRemovePresentation(FW_CPresentation* presentation)
  1035. {
  1036.     fPresentations->Remove(presentation);
  1037. }