home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 47.1 KB | 1,569 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPart.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWEVENTD_H
- #include "FWEventD.h"
- #endif
-
- #ifndef FWSEMINT_H
- #include "FWSemInt.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWCONTNT_H
- #include "FWContnt.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWPART_K
- #include "FWPart.k"
- #endif
-
- #ifndef FWRESSIN_H
- #include "FWResSin.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWIDLE_H
- #include "FWIdle.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef SLMIXOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- OD Utils -----
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- // ----- OpenDoc -----
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- unsigned short FW_CPart::fgSessionGlobalsCount = 0;
-
- ODTypeToken FW_CPart::fgSelectionFocusToken = 0;
- ODTypeToken FW_CPart::fgMenuFocusToken = 0;
- ODTypeToken FW_CPart::fgKeyFocusToken = 0;
- ODTypeToken FW_CPart::fgModalFocusToken = 0;
- ODTypeToken FW_CPart::fgClipboardFocusToken = 0;
- ODTypeToken FW_CPart::fgScrollingFocusToken = 0;
- ODTypeToken FW_CPart::fgMouseFocusToken = 0;
- ODTypeToken FW_CPart::fgViewAsFrameToken = 0;
- ODTypeToken FW_CPart::fgViewAsSmallIconToken = 0;
- ODTypeToken FW_CPart::fgViewAsLargeIconToken = 0;
- ODTypeToken FW_CPart::fgViewAsThumbnailToken = 0;
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CPart, FW_MEventHandler)
- FW_DEFINE_AUTO(FW_CPart)
-
- //========================================================================================
- // class FW_CPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::FW_CPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart::FW_CPart(ODPart* odPart,
- FW_Instance partInstance,
- FW_ResourceID partInfoID) :
- FW_MEventHandler(),
- fODPart(odPart),
- fMenuBar(NULL),
- fEventDispatcher(NULL),
- fLastActiveFrame(NULL),
- fPresentations(NULL),
- fDefaultPresentation(NULL),
- fIdleCount(0),
- fModalDialogCount(0),
- fExtensionManager(NULL),
- fSemanticInterface(NULL),
- fPartInstance(partInstance),
- fViewAsIconID(0),
- fDocumentWindowID(0),
- fLinkManager(NULL),
- fPrintInfo(NULL),
- fIdler(NULL),
- fContent(NULL),
- fDataInterchange(NULL),
- fPartInfoID(partInfoID),
- fNeedPrepping(TRUE),
- fPartKind(NULL),
- fPreferredKind(NULL),
- fPartWindowFrame(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::~FW_CPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart::~FW_CPart()
- {
- FW_START_DESTRUCTOR
- FW_ASSERT(fIdleCount == 0);
- FW_ASSERT(fModalDialogCount == 0);
-
- FW_ASSERT(fIdler == NULL); // Should be NULL by now
-
- // ----- Delete all the presentations
- if (fPresentations)
- {
- FW_CPresentation* presentation;
- while ((presentation = fPresentations->First()) != NULL)
- {
- PrivRemovePresentation(presentation);
- delete presentation;
- }
- }
-
- delete fPresentations;
- fPresentations = NULL;
-
- // ----- Delete MenuBar
- delete fMenuBar;
- fMenuBar = NULL;
-
- // ----- Delete Event Dispatcher
- delete fEventDispatcher;
- fEventDispatcher = NULL;
-
- // ----- Delete Semantic Interface
- delete fSemanticInterface;
- fSemanticInterface = NULL;
-
- // ----- Delete Link Manager
- delete fLinkManager;
- fLinkManager = NULL;
-
- // ----- Delete Content
- delete fContent;
- fContent = NULL;
-
- // ----- Delete Data Interchange
- delete fDataInterchange;
- fDataInterchange = NULL;
-
- // ----- Release All the globals
- PrivReleaseGlobals();
-
- // ----- Delete all the kinds
- if (fKinds)
- {
- FW_CKind* kind;
- while ((kind = fKinds->First()) != NULL)
- {
- fKinds->Remove(kind);
- delete kind;
- }
-
- delete fKinds;
- fKinds = NULL;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Initialize
- //---------------------------------------------------------------------------------------
- // Call inherited first when overriding
-
- void FW_CPart::Initialize(Environment *ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
-
- PrivInitGlobals(ev, storageUnit);
-
- // ----- Menu bar -----
- fMenuBar = FW_NEW(FW_CMenuBar, (ev, fODPart, fPartInstance));
-
- // ----- Create Event Dispatcher -----
- fEventDispatcher = this->NewEventDispatcher(ev);
-
- // ----- Presentation collection -----
- fPresentations = FW_NEW(FW_TOrderedCollection<FW_CPresentation>, ());
-
- // ----- Data Interchage object -----
- fDataInterchange = this->NewDataInterchange(ev);
-
- // ----- Part Content object -----
- fContent = this->NewPartContent(ev);
-
- // ----- Linking Support -----
- fLinkManager = this->NewLinkManager(ev);
-
- // ----- Kinds -----
- fKinds = FW_NEW(FW_TOrderedCollection<FW_CKind>, ());
-
- // ----- Load Part Info Resource -----
- FW_PSharedLibraryResourceFile resFile(ev, fPartInstance);
- #ifdef FW_DEBUG
- if (!resFile->HasResource(ev, fPartInfoID, FW_kPartInfoResourceType))
- FW_DEBUG_MESSAGE("The part info resource is missing");
- #endif
- FW_PResource resource(ev, resFile, fPartInfoID, FW_kPartInfoResourceType);
- FW_PResourceSink sink(ev, resource);
- FW_CReadableStream stream(sink);
-
- stream >> fViewAsIconID;
-
- FW_ResourceID menuBarID;
- stream >> menuBarID;
-
- stream >> fDocumentWindowID;
-
- stream >> fPartUserName;
-
- FW_CAcquireODISOStr partKind = FW_ReadODValueTypeFromStream(ev, stream);
- fPartKind = RegisterKind(ev, partKind, FW_kAllStorage, FW_kImportExportEnabled);
- fPartKind->PrivSetAsPartKind(ev);
- fPartKind->PrivSetAsPreferredKind(ev, TRUE);
- fPreferredKind = fPartKind;
-
- // ----- If was called from InitPart, write out the preferred kind (in this case the part kind)
- if (!fromStorage)
- ODSetISOStrProp(ev, storageUnit, kODPropPreferredKind, kODISOStr, fPreferredKind->GetType(ev));
-
- // ----- Initialize MenuBar if menuBarID != 0 -----
- if (menuBarID != 0)
- {
- fMenuBar->InitializeFromResource(ev, menuBarID);
- fAboutString = fMenuBar->GetAboutString(ev); // About string read in from menuBar resource
- }
- if (fAboutString.IsEmpty()) // user didn't supply an About string, so get the default one
- ::FW_PrivLoadODFString(ev, FW_kAboutString, fAboutString);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InstallScripingCallbacks
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::InstallScriptingCallbacks(Environment* ev)
- {
- FW_UNUSED(ev);
- // Scriptable parts that require custom AEDesc coercion functions or custom
- // AEDesc comparison functions should override this method and call the following
- // static functions to install custom handlers:
- // FW_CDescCoercionCallbacks::RegisterHandler
- // FW_CDescComparisonCallbacks::RegisterHandler
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivInitGlobals
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivInitGlobals(Environment *ev, ODStorageUnit* storageUnit)
- {
- if (FW_CSession::fgSession == NULL)
- FW_CSession::fgSession = storageUnit->GetSession(ev);
-
- if (fgSessionGlobalsCount == 0)
- {
- FW_ASSERT(fgSelectionFocusToken == 0);
- fgSelectionFocusToken = FW_CSession::Tokenize(ev, kODSelectionFocus);
-
- FW_ASSERT(fgMenuFocusToken == 0);
- fgMenuFocusToken = FW_CSession::Tokenize(ev, kODMenuFocus);
-
- FW_ASSERT(fgKeyFocusToken == 0);
- fgKeyFocusToken = FW_CSession::Tokenize(ev, kODKeyFocus);
-
- FW_ASSERT(fgClipboardFocusToken == 0);
- fgClipboardFocusToken = FW_CSession::Tokenize(ev, kODClipboardFocus);
-
- FW_ASSERT(fgModalFocusToken == 0);
- fgModalFocusToken = FW_CSession::Tokenize(ev, kODModalFocus);
-
- FW_ASSERT(fgScrollingFocusToken == 0);
- fgScrollingFocusToken = FW_CSession::Tokenize(ev, kODScrollingFocus);
-
- FW_ASSERT(fgMouseFocusToken == 0);
- fgMouseFocusToken = FW_CSession::Tokenize(ev, kODMouseFocus);
-
- FW_ASSERT(fgViewAsFrameToken == 0);
- fgViewAsFrameToken = FW_CSession::Tokenize(ev, kODViewAsFrame);
-
- FW_ASSERT(fgViewAsSmallIconToken == 0);
- fgViewAsSmallIconToken = FW_CSession::Tokenize(ev, kODViewAsSmallIcon);
-
- FW_ASSERT(fgViewAsLargeIconToken == 0);
- fgViewAsLargeIconToken = FW_CSession::Tokenize(ev, kODViewAsLargeIcon);
-
- FW_ASSERT(fgViewAsThumbnailToken == 0);
- fgViewAsThumbnailToken = FW_CSession::Tokenize(ev, kODViewAsThumbnail);
-
- InstallScriptingCallbacks(ev);
- }
-
- fgSessionGlobalsCount++;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivReleaseGlobals
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivReleaseGlobals()
- {
- fgSessionGlobalsCount--;
- FW_ASSERT(fgSessionGlobalsCount >= 0);
-
- if (fgSessionGlobalsCount == 0)
- {
- // I am resetting those globals to their default value
- // because if the DLL is not unloaded they wont be reinitialized
- fgSelectionFocusToken =
- fgMenuFocusToken =
- fgKeyFocusToken =
- fgClipboardFocusToken =
- fgModalFocusToken =
- fgScrollingFocusToken =
- fgMouseFocusToken =
- fgViewAsFrameToken =
- fgViewAsSmallIconToken =
- fgViewAsLargeIconToken =
- fgViewAsThumbnailToken = 0;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::AddAnnotationProperties
- //---------------------------------------------------------------------------------------
- // Attention - AddAnnotationProperties can be called multiple times
-
- void FW_CPart::AddAnnotationProperties(Environment* ev, ODStorageUnit* storageUnit, FW_StorageKinds storageKind)
- {
- FW_UNUSED(ev);
- FW_UNUSED(storageUnit);
- FW_UNUSED(storageKind);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ChangeKind
- //---------------------------------------------------------------------------------------
- // 1) convert kind to a FW_CKind
- // 2) Change my preferred kind
- // 3) if there is a change (ChangePreferredKind sets the fNeedPrep to true)
- // 4) change the kODPreferredKind property
- // 5) Externalize my content
- void FW_CPart::ChangeKind(Environment* ev, ODType kind)
- {
- FW_CKind* newPreferredKind = GetKind(ev, kind);
- if (newPreferredKind == NULL)
- {
- FW_DEBUG_MESSAGE("This kind is not supported. Did you forget to call RegisterKind?");
- return;
- }
- if (!newPreferredKind->ExportSupported(ev, FW_kPartStorage))
- {
- FW_DEBUG_MESSAGE("This part cannot export this kind.");
- return;
- }
-
- // ----- Change the preferred kind -----
- if (ChangePreferredKind(ev, newPreferredKind))
- {
- ODStorageUnit* su = GetStorageUnit(ev);
-
- // ----- Write the new preferred kind in the preferred kind property -----
- ODSetISOStrProp(ev, su, kODPropPreferredKind, kODISOStr, newPreferredKind->GetType(ev));
-
- // ----- Externalize with the new preferred kind -----
- ExternalizeContent(ev, su, NULL);
- }
- }
-
- //------------------------------------------------------------------------------
- // FW_RemoveUnsupportedValues
- //------------------------------------------------------------------------------
- // Common method for PrepContentProperty and ExternalizeKinds
-
- static void FW_RemoveUnsupportedValues(Environment* ev, unsigned long numValues, ODStorageUnit* storageUnit, FW_Boolean* toKeep)
- {
- for (unsigned long index = numValues; index >= 1; index--)
- {
- if (!toKeep[index-1])
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
- storageUnit->Remove(ev);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // FW_CPart::PrepContentProperty
- //------------------------------------------------------------------------------
-
- void FW_CPart::PrepContentProperty(Environment* ev, ODStorageUnit* storageUnit, FW_StorageKinds storageKind, FW_Boolean allSupportedKinds)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
-
- // ----- First look at all the values I have to remove ------
- // There is no API to insert a value
- FW_CKind* currentKind = fKinds->First();
-
- unsigned long numValues = storageUnit->CountValues(ev);
-
- if (numValues != 0)
- {
- #if 0 // [MH]
- // This code is to preserve any supported values. Problem is that any values that contain su-refs
- // must be removed and replaced. Since we have no idea about which ones those might be, we will
- // just remove all values, then add all the supported ones back.
-
- FW_CAcquireTemporaryMemory tempMemory(numValues * sizeof(FW_Boolean));
- FW_Boolean* toKeep = (FW_Boolean*)tempMemory.GetPointer();
-
- for (unsigned long index = 0; index < numValues ; index++)
- {
- toKeep[index] = FALSE;
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index+1, kODPosUndefined);
-
- if (currentKind != NULL)
- {
- FW_CAcquireODISOStr valueType = storageUnit->GetType(ev);
- if (currentKind->IsEqual(ev, valueType)) {
- // ----- When saving the document to the part storage I need to always save it in the
- // ----- preferred part kind
- FW_Boolean supported;
- if (allSupportedKinds)
- supported = currentKind->ExportSupported(ev, storageKind);
- else
- supported = currentKind->ToBeExported(ev, storageKind);
-
- toKeep[index] = supported || (currentKind->IsPreferredKind(ev) && storageKind == FW_kPartStorage);
- currentKind = fKinds->After(currentKind);
- }
- }
- }
-
- // ----- Now we can really remove them going backward -----
- FW_RemoveUnsupportedValues(ev, numValues, storageUnit, toKeep);
- #endif
-
- // just remove all the values
- for (unsigned long index = numValues; index >= 1; index--)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
- storageUnit->Remove(ev);
- }
- }
-
- // ----- Add all the other kinds ----- [MH] Now always adds all kinds!
- while (currentKind)
- {
- FW_Boolean supported;
- if (allSupportedKinds)
- supported = currentKind->ExportSupported(ev, storageKind);
- else
- supported = currentKind->ToBeExported(ev, storageKind);
-
- if (supported)
- {
- FW_ASSERT(!storageUnit->Exists(ev, kODPropContents, currentKind->GetType(ev), 0)); // It should not exist
- storageUnit->AddValue(ev, currentKind->GetType(ev));
- currentKind->PrivSetDirty(ev, TRUE, storageKind); // If it doesn't exist it will have to be externalize
- }
-
- currentKind = fKinds->After(currentKind);
- }
-
- AddAnnotationProperties(ev, storageUnit, storageKind);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ExternalizeKinds
- //---------------------------------------------------------------------------------------
- // A content object is necessary to support this API
-
- void FW_CPart::ExternalizeKinds(Environment *ev, ODTypeList* kindset)
- {
- if (fContent == NULL)
- return;
-
- ODStorageUnit* storageUnit = GetStorageUnit(ev);
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
-
- // ----- First look at all the value I have to remove ------
- // There is no API to insert a value
- FW_CKind* currentKind = fKinds->First();
-
- unsigned long numValues = storageUnit->CountValues(ev);
-
- if (numValues != 0)
- {
- FW_CAcquireTemporaryMemory tempMemory(numValues * sizeof(FW_Boolean));
- FW_Boolean* toKeep = (FW_Boolean*)tempMemory.GetPointer();
-
- for (unsigned long index = 0; index < numValues ; index++)
- {
- toKeep[index] = FALSE;
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index+1, kODPosUndefined);
-
- if (currentKind != NULL)
- {
- FW_CAcquireODISOStr valueType = storageUnit->GetType(ev);
- if (currentKind->IsEqual(ev, valueType)) {
- // ----- I Don't keep it if it is not in the kinset but I still keep it if it is the preferred kind
- // I use ExportSupported and not ToBeExported
- if (currentKind->ExportSupported(ev, FW_kPartStorage))
- toKeep[index] = kindset->Contains(ev, valueType) || currentKind->IsPreferredKind(ev);
-
- currentKind = fKinds->After(currentKind);
- }
- }
- }
-
- // ----- Now we can really remove them going backward -----
- FW_RemoveUnsupportedValues(ev, numValues, storageUnit, toKeep);
- }
-
- // ----- Add all the other kinds -----
- while (currentKind)
- {
- // I use ExportSupported and not ToBeExported
- if (currentKind->ExportSupported(ev, FW_kPartStorage) && (kindset->Contains(ev, currentKind->GetType(ev)) || currentKind->IsPreferredKind(ev)))
- {
- FW_ASSERT(!storageUnit->Exists(ev, kODPropContents, currentKind->GetType(ev), 0)); // It should not exist
- storageUnit->AddValue(ev, currentKind->GetType(ev));
- currentKind->PrivSetDirty(ev, TRUE, FW_kPartStorage); // If it doesn't exist it will have to be externalize
- }
-
- currentKind = fKinds->After(currentKind);
- }
-
- // ----- Now I can call FW_CContent::ExternalizeKind on each existing value
- fContent->PrivExternalizeAllValues(ev, storageUnit, FW_kPartStorage, NULL, NULL);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::CloneInto
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::CloneInto(Environment* ev,
- ODDraftKey key,
- ODStorageUnit* toSU,
- ODFrame* scope)
- {
- ODStorageUnit* su = GetStorageUnit(ev);
- ODDraft* fromDraft = su->GetDraft(ev);
- ODDraft* toDraft = toSU->GetDraft(ev);
-
- FW_ASSERT((scope == NULL) || (scope != NULL && IsValidDisplayFrame(ev, scope->GetID(ev))));
-
- FW_CFrame *frame = scope == NULL ? NULL : FW_CFrame::ODtoFWFrame(ev, scope);
- FW_ASSERT((scope == NULL) || (scope != NULL && frame != NULL));
-
- FW_CCloneInfo cloneInfo(ev, key, fromDraft, frame, 0); // fromDraft->GetCloneKind(ev)
-
- FW_ASSERT(toDraft->GetPermissions(ev) >= kODDPSharedWrite);
-
- // [MH] As far as I know this has never been attempted before! We need to know what we are cloning to
- // in order to determine the correct behavior, and also to allow the use of promises in cloneInto
-
- FW_StorageKinds storageKind = 0;
-
- // We should never be asked to CloneInto the part's storage unit
- FW_ASSERT(!toSU->IsEqualTo(ev, su));
-
- if (toDraft->IsEqualTo(ev, fromDraft)) // if not the part, only a link uses the part draft.
- {
- storageKind = FW_kLinkStorage;
- }
- else if (toDraft->IsEqualTo(ev, FW_CSession::GetClipboard(ev)->GetContentStorageUnit(ev)->GetDraft(ev)))
- {
- storageKind = FW_kClipboardStorage;
- }
-
- // Craig Carper suspects that simply asking the d&d for its su may create a new draft, so
- // just assume that if it's none of the above, it must be d&d.
-
- else // if (toDraft->IsEqualTo->(ev, FW_CSession::GetDragAndDrop(ev)->GetContentStorageUnit(ev)->GetDraft(ev)))
- {
- storageKind = FW_kDragAndDropStorage;
- }
-
-
- FW_ASSERT(storageKind != 0);
-
- PrepContentProperty(ev, toSU, storageKind, TRUE);
- if (fContent)
- fContent->Externalize(ev, toSU, storageKind, &cloneInfo);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InternalizeContent
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_Boolean result = TRUE;
-
- // ----- Simply forward to the content object if there is one -----
- if (fContent)
- result = fContent->Internalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
-
- PrivSetDirty(ev, !result);
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivDeterminePreferredKind
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivDeterminePreferredKind(Environment* ev, ODStorageUnit* storageUnit)
- {
- // ----- Read in the preferred Kind -----
- ODULong size;
- FW_CAcquireODISOStr preferredKindISOStr = ODGetISOStrProp(ev, storageUnit, kODPropPreferredKind, kODISOStr, NULL, &size);
-
- // ----- Set the preferred kind -----
- FW_CKind* preferredKind = NULL;
- if ((const void*)preferredKindISOStr != NULL)
- preferredKind = GetKind(ev, preferredKindISOStr);
-
- // ----- If I don't support the preferred kind or there is no preferred kind property use the first kind I support
- // ----- as the preferred kind
- if (preferredKind == NULL)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
- unsigned long numValues = storageUnit->CountValues(ev);
- for (unsigned long index = 1; index <= numValues ; index++)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
- FW_CAcquireODISOStr valueType = storageUnit->GetType(ev);
- preferredKind = GetKind(ev, valueType);
- if (preferredKind != NULL)
- break;
- }
- }
-
- FW_ASSERT(preferredKind != NULL); // Otherwise why was I bound to this part?
- ChangePreferredKind(ev, preferredKind);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ExternalizeContent
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::ExternalizeContent(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- if (storageUnit->GetDraft(ev)->GetPermissions(ev) >= kODDPSharedWrite)
- {
- // [MH] we always need prepping because unless existing values are removed and replaced
- // we can run into trouble with su ref's.
-
- //if (fNeedPrepping)
- {
- PrepContentProperty(ev, storageUnit, FW_kPartStorage, FALSE);
- fNeedPrepping = FALSE;
- }
-
- // ----- Externalize part specific data -----
- // Simply forward to the content object
- if (fContent)
- fContent->Externalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::NewEventDispatcher
- //---------------------------------------------------------------------------------------
-
- FW_CEventDispatcher* FW_CPart::NewEventDispatcher(Environment *ev)
- {
- FW_UNUSED(ev);
-
- return new FW_CEventDispatcher(this, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::NewPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::NewPresentation(Environment *ev,
- FW_CSelection* selection,
- ODTypeToken presentationType,
- FW_ResourceID viewResourceID,
- FW_ResourceID rootViewResourceID)
- {
- return new FW_CPresentation(ev, this, selection, presentationType, viewResourceID, rootViewResourceID);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::RegisterPresentation
- //----------------------------------------------------------------------------------------
- // the selection object will be owned by the presentation
-
- FW_CPresentation* FW_CPart::RegisterPresentation(Environment *ev,
- ODType presentationType,
- FW_Boolean defaultPresentation,
- FW_ResourceID viewResourceID,
- FW_ResourceID rootViewResourceID,
- FW_CSelection* selection)
- {
- FW_CPresentation* presentation = NULL;
- FW_VOLATILE(presentation);
-
- FW_TRY
- {
- ODTypeToken token = FW_CSession::Tokenize(ev, presentationType);
-
- // ----- Test that we don't register a presentation twice -----
- FW_ASSERT(FindPresentation(ev, token) == NULL);
-
- presentation = NewPresentation(ev, selection, token, viewResourceID, rootViewResourceID);
-
- if (selection)
- selection->PrivSetPresentation(presentation);
-
- PrivAddPresentation(presentation);
-
- // ----- if flagged as default or first one -----
- if (defaultPresentation || (fDefaultPresentation == NULL))
- fDefaultPresentation = presentation;
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (presentation == NULL)
- delete selection; // Otherwise will be deleted by next line
-
- delete presentation;
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- return presentation;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::FindPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::FindPresentation(Environment *ev, ODTypeToken presentationType) const
- {
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- if (presentation->GetPresentationType(ev) == presentationType)
- return presentation;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::CountDisplayFrame
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CPart::CountDisplayFrame(Environment *ev) const
- {
- unsigned long count = 0;
-
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- count += presentation->CountFrame(ev);
- }
-
- return count;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::NewLinkManager
- //---------------------------------------------------------------------------------------
-
- FW_CLinkManager* FW_CPart::NewLinkManager(Environment *ev)
- {
- FW_UNUSED(ev);
- // Must be overridden if part creates Links
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::GetPartName
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::GetPartName(Environment *ev, FW_CString& partName) const
- {
- ODName* windowName = NULL;
- FW_Boolean nameIsProperty = FALSE;
-
- windowName = ODGetITextProp(ev, fODPart->GetStorageUnit(ev), kODPropName, kODMacIText, windowName);
- // windowName = ODGetPOName(ev, fODPart, NULL);
-
- if (windowName != NULL && GetITextStringLength(windowName) != 0)
- {
- partName = GetCStringFromIText(windowName);
- nameIsProperty = TRUE;
- }
- else
- partName = fPartUserName;
-
- if (windowName)
- DisposeIText(windowName);
-
- return nameIsProperty;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivEnableMenuBar
- //---------------------------------------------------------------------------------------
- // This is called when opening/closing a modal dialog.
- // We keep a count of nested modal dialogs so that we don't re-enable the menu-bar
- // if a modal dialog is still up
-
- void FW_CPart::PrivEnableMenuBar(Environment *ev, FW_Boolean enable, FW_Boolean appleMenu)
- {
- if (enable == false)
- fModalDialogCount += 1;
- else
- {
- fModalDialogCount -= 1;
- if (fModalDialogCount > 0) return;
- }
-
- #ifdef FW_BUILD_MAC
- GetMenuBar(ev)->MacEnableMenuBar(ev, enable);
- // We keep the Apple menu enabled for moveable dialog boxes
- if (enable == false && appleMenu == true)
- GetMenuBar(ev)->EnableCommand(ev, kODCommandAppleMenu, true);
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows does this automatically?
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InstallMenus
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::InstallMenus(Environment *ev, FW_CMenuBar* menuBar)
- {
- if (menuBar)
- menuBar->PrivDisplay(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::DoAbout
- //---------------------------------------------------------------------------------------
-
- FW_Handled FW_CPart::DoAbout(Environment *ev)
- {
- FW_UNUSED(ev);
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::HandleMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CPart::HandleMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- if (theMenuEvent.GetCommandID(ev) == kODCommandAbout)
- return DoAbout(ev);
- else
- return FW_MEventHandler::HandleMenu(ev, theMenuEvent);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Changed
- //---------------------------------------------------------------------------------------
- // ODF API
-
- void FW_CPart::Changed(Environment *ev)
- {
- GetDraft(ev)->SetChangedFromPrev(ev);
-
- PrivSetDirty(ev, TRUE);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivSetDirty
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivSetDirty(Environment *ev, FW_Boolean state)
- {
- // ----- Flag all kind as dirty -----
- FW_CPartKindIterator ite(this);
- for (FW_CKind* kind = ite.First(); ite.IsNotComplete(); kind = ite.Next())
- if (kind->ToBeExported(ev, FW_kPartStorage))
- kind->PrivSetDirty(ev, state, FW_kPartStorage);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivGetPresentation
- //---------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::PrivGetPresentation(Environment *ev, ODFrame* odFrame) const
- {
- ODTypeToken presDefault = FW_CSession::Tokenize(ev, kODPresDefault);
- ODTypeToken token = presDefault;
-
- FW_CPresentation* presentation = NULL;
-
- if (odFrame != NULL)
- token = odFrame->GetPresentation(ev);
-
- if (token == presDefault)
- presentation = fDefaultPresentation;
- else
- {
- presentation = FindPresentation(ev, token);
-
- if (presentation == NULL)
- presentation = fDefaultPresentation;
- }
-
- return ValidatePresentation(ev, odFrame, presentation);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ValidatePresentation
- //---------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::ValidatePresentation(Environment *ev, ODFrame* odFrame, FW_CPresentation *proposedPresentation) const
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFrame);
-
- return proposedPresentation;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::HasSelectionFocus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::HasSelectionFocus(Environment *ev) const
- {
- if (fLastActiveFrame)
- {
- return fLastActiveFrame->HasSelectionFocus(ev);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetActiveFacet
- //----------------------------------------------------------------------------------------
-
- ODFacet* FW_CPart::GetActiveFacet(Environment *ev) const
- {
- return (fLastActiveFrame != NULL) ? fLastActiveFrame->GetActiveFacet(ev) : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::Release
- //----------------------------------------------------------------------------------------
- // Call inherited first when overridden
-
- void FW_CPart::Release(Environment *ev)
- {
- unsigned long refcount = fODPart->GetRefCount(ev);
-
- // ------ The last refcount is caused by the register idle -----
- if (refcount == 1 && fIdler != NULL)
- {
- FW_ASSERT(fIdleCount == 1); // We should only have the part register by now
- fIdler->UnregisterIdle(ev);
- }
-
- if (refcount == 0)
- {
- GetDraft(ev)->ReleasePart(ev, fODPart);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::ReleaseAll
- //----------------------------------------------------------------------------------------
- // Call inherited first when overridden
-
- void FW_CPart::ReleaseAll(Environment *ev)
- {
- // Will resolve or just delete my promises
- if (fDataInterchange)
- fDataInterchange->ResolveAllPromises(ev);
-
- // ----- Release part content
- if (fContent)
- fContent->ReleaseAll(ev);
-
- // ----- Delete any and all links
- if (fLinkManager)
- fLinkManager->RemoveAllLinks(ev);
-
- // ----- Release all display Frames
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- presentation->ReleaseAll(ev);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::IsReadOnly
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::IsReadOnly(Environment *ev) const
- {
- return GetDraft(ev)->GetPermissions(ev) < kODDPSharedWrite;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetDraft
- //----------------------------------------------------------------------------------------
-
- ODDraft* FW_CPart::GetDraft(Environment *ev) const
- {
- return fODPart->GetStorageUnit(ev)->GetDraft(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::HandleAdjustMenus
- //----------------------------------------------------------------------------------------
- // The part should have the last word in case it is readonly
-
- FW_Handled FW_CPart::HandleAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_Handled result = FW_MEventHandler::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
-
- // ------ Disable items we know have to be disabled -----
- if (hasMenuFocus)
- {
- if (IsReadOnly(ev))
- {
- menuBar->EnableCommand(ev, kODCommandPaste, FALSE);
- menuBar->EnableCommand(ev, kODCommandCut, FALSE);
- menuBar->EnableCommand(ev, kODCommandClear, FALSE);
- menuBar->EnableCommand(ev, kODCommandPasteAs, FALSE);
- }
-
- // Set the name in the About item
- menuBar->SetItemString(ev, kODCommandAbout, fAboutString);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::NewDocumentWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* FW_CPart::NewDocumentWindow(Environment* ev)
- {
- FW_CPoint windSize(FW_kZeroPoint), windPos(FW_kZeroPoint);
- FW_CPresentation* presentation;
- FW_WindowStyle style;
-
- if (fDocumentWindowID != 0)
- {
- FW_PSharedLibraryResourceFile resFile(ev, fPartInstance);
- FW_PResource resource(ev, resFile, fDocumentWindowID, FW_kDocumentWindowResourceType);
- FW_PResourceSink sink(ev, resource);
- FW_CReadableStream stream(sink);
-
- stream >> windSize;
- stream >> windPos;
- stream >> style;
-
- ODTypeToken presentationToken = FW_ReadODTypeTokenFromStream(ev, stream);
- presentation = FindPresentation(ev, presentationToken);
- }
- else
- {
- presentation = PrivGetPresentation(ev, NULL); // NULL means default presentation
- style = FW_kDocumentWindow;
- }
-
- FW_ASSERT(presentation);
-
- FW_CRect windRect;
- ::FW_GetMainScreenBounds(windRect);
-
- if (windSize == FW_kZeroPoint)
- windSize = windRect.Size(); // I know it is too big but FW_CWindow::__ct will adjust it
-
- if (windPos == FW_kZeroPoint)
- windPos = windRect.TopLeft();
-
- return new FW_CWindow(ev,
- this,
- FW_CPart::fgViewAsFrameToken,
- presentation,
- windSize,
- windPos,
- style);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::PrivCountIdleRegistering
- //----------------------------------------------------------------------------------------
-
- void FW_CPart::PrivCountIdleRegistering(FW_Boolean registering)
- {
- if (registering)
- fIdleCount++;
- else
- {
- FW_ASSERT(fIdleCount >= 1);
- fIdleCount--;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::IsValidDisplayFrame
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::IsValidDisplayFrame(Environment* ev, ODStorageUnitID displayFrameID) const
- {
- FW_CPartFrameIterator ite(ev, this);
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- if (frame->GetID(ev) == displayFrameID)
- return TRUE;
- }
-
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::NewDataInterchange
- //---------------------------------------------------------------------------------------
-
- FW_CDataInterchange* FW_CPart::NewDataInterchange(Environment* ev)
- {
- return new FW_CDataInterchange(ev, this);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::LinkStatusChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFrame);
- // Nothing to do. See FW_CEmbeddingPart::LinkStatusChanged
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Purge
- //---------------------------------------------------------------------------------------
-
- ODSize FW_CPart::Purge(Environment *ev, ODSize size)
- {
- FW_UNUSED(ev);
- FW_UNUSED(size);
- return 0;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::SetPrintInfo
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::SetPrintInfo(FW_CPrintInfo* printInfo)
- {
- fPrintInfo = printInfo;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::GetPrintInfo
- //---------------------------------------------------------------------------------------
-
- FW_CPrintInfo* FW_CPart::GetPrintInfo() const
- {
- return fPrintInfo;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrintInfoChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrintInfoChanged(Environment *ev, FW_CPrintInfo* printInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(printInfo);
- // Nothing to do.
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::RegisterKind
- //---------------------------------------------------------------------------------------
-
- FW_CKind* FW_CPart::RegisterKind(Environment *ev,
- ODValueType kind,
- FW_StorageKinds storageKind,
- FW_ImportExport importExport)
- {
- FW_CKind* theKind = new FW_CKind(ev, this, kind, storageKind, importExport);
- fKinds->AddLast(theKind);
- return theKind;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::RegisterKind
- //---------------------------------------------------------------------------------------
-
- FW_CKind* FW_CPart::RegisterKind(Environment *ev,
- ODPlatformType platformType,
- ODPlatformTypeSpace typeSpace,
- FW_StorageKinds storageKind,
- FW_ImportExport importExport)
- {
- // [HLX] I need to do some checking on the typeSpace/storageKind
- ODTranslation *translate = FW_CSession::GetTranslation(ev);
- FW_CAcquireODISOStr type = translate->GetISOTypeFromPlatformType(ev, platformType, typeSpace);
- return RegisterKind(ev, type, storageKind, importExport);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetSupportedKind
- //----------------------------------------------------------------------------------------
- // Tests and returns that a storage unit has a supported kind for import
-
- FW_CKind* FW_CPart::GetSupportedKind(Environment *ev,
- ODStorageUnit *su,
- FW_StorageKinds storageKind) const
- {
- FW_CPartKindIterator ite(this);
- for (FW_CKind* kind = ite.First(); ite.IsNotComplete(); kind = ite.Next())
- {
- if (kind->ImportSupported(ev, storageKind))
- if (su->Exists(ev, kODPropContents, kind->GetType(ev), 0))
- return kind;
- }
-
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ChangePreferredKind
- //---------------------------------------------------------------------------------------
- // Returns true if the preferred kind has really been changed
-
- FW_Boolean FW_CPart::ChangePreferredKind(Environment *ev, FW_CKind* newPreferredKind)
- {
- if (fPreferredKind != newPreferredKind)
- {
- fPreferredKind->PrivSetAsPreferredKind(ev, FALSE);
- newPreferredKind->PrivSetAsPreferredKind(ev, TRUE);
- fPreferredKind = newPreferredKind;
- fNeedPrepping = TRUE; // I changed the preferred kind. I need to reprep the storage unit
- return TRUE;
- }
-
- return FALSE; // nothing has changed
- }
-
- //------------------------------------------------------------------------------
- // FW_CPart::GetKind
- //------------------------------------------------------------------------------
-
- FW_CKind* FW_CPart::GetKind(Environment* ev, ODType type) const
- {
- FW_CPartKindIterator ite(this);
- for (FW_CKind* kind = ite.First(); ite.IsNotComplete(); kind = ite.Next())
- {
- if (kind->IsEqual(ev, type))
- return kind;
- }
-
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivAddPresentation
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivAddPresentation(FW_CPresentation* presentation)
- {
- fPresentations->AddLast(presentation);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivRemovePresentation
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivRemovePresentation(FW_CPresentation* presentation)
- {
- fPresentations->Remove(presentation);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivShowErrorAlert
- //---------------------------------------------------------------------------------------
- void FW_CPart::PrivShowErrorAlert(Environment* ev, short stringResID, short messageID)
- {
- FW_CFrame* frame = this->GetLastActiveFrame(ev);
- FW_ASSERT(frame);
-
- FW_CWindow* window = frame->GetWindow(ev);
- FW_ASSERT(window);
-
-
- // ----- Activate the frame's window -----
- if (!window->IsActive(ev))
- window->Select(ev);
-
- FW_ASSERT(window->IsActive(ev));
-
- if (window->IsActive(ev))
- {
- FW_CString partName;
- this->GetPartName(ev, partName);
-
- FW_CString message;
- ::FW_PrivLoadMessageString(ev, stringResID, messageID, message);
-
- ::FW_ErrorAlert(partName, message);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::SetAboutString
- //----------------------------------------------------------------------------------------
-
- void FW_CPart::SetAboutString(const FW_CString& string)
- {
- fAboutString = string;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetPartWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* FW_CPart::GetPartWindow(Environment* ev) const
- {
- return fPartWindowFrame ? fPartWindowFrame->GetWindow(ev) : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::OpenPartWindow
- //----------------------------------------------------------------------------------------
-
- ODID FW_CPart::OpenPartWindow(Environment* ev, FW_CFrame* sourceFrame, ODFacet* sourceFacet)
- {
- FW_ASSERT(sourceFrame);
-
- FW_CWindow* window = NULL;
-
- if (fPartWindowFrame != NULL)
- {
- window = fPartWindowFrame->GetWindow(ev);
- }
- else
- {
- if (sourceFacet == NULL)
- {
- FW_CFrameFacetIterator ite(ev, sourceFrame);
- sourceFacet = ite.First(ev);
- }
- FW_ASSERT(sourceFacet != NULL);
-
- // ----- Invalid all my frames if iconized -----
- PrivInvalidateIconizedFrames(ev);
-
- // ----- Calculate suggested WindowRect and WindowTitle -----
- FW_CRect frameBounds = sourceFrame->GetBounds(ev);
- FW_FrameToWindow(ev, sourceFacet, frameBounds);
-
- sourceFrame->GetWindow(ev)->WindowToScreen(ev, frameBounds);
- #ifdef FW_BUILD_MAC
- FW_PlatformRect sourceRect = frameBounds.AsPlatformRect();
- #endif
- frameBounds.Offset(FW_IntToFixed(20), FW_IntToFixed(20));
- #ifdef FW_BUILD_MAC
- FW_PlatformRect toRect = frameBounds.AsPlatformRect();
- #endif
-
- FW_CString255 partName;
- sourceFrame->GetPart(ev)->GetPartName(ev, partName);
-
- window = sourceFrame->NewPartWindow(ev, frameBounds, partName);
-
- #ifdef FW_BUILD_MAC
- ::ZoomRects(&sourceRect, &toRect, 12, zoomAccelerate);
- #endif
-
- window->Show(ev); // ATTENTION: Show should be before Select
-
- FW_CAcquiredODWindow odWindow = window->AcquireODWindow(ev);
-
- fPartWindowFrame = FW_CFrame::ODtoFWFrame(ev, odWindow->GetRootFacet(ev)->GetFrame(ev));
- FW_ASSERT(fPartWindowFrame != NULL);
- }
-
- window->Select(ev);
-
- return window->GetID(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::PrivDisplayFrameRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CPart::PrivDisplayFrameRemoved(Environment *ev, ODFrame* frame, FW_Boolean toStorage)
- {
- FW_CFrame* fwFrame = FW_CFrame::ODtoFWFrame(ev, frame);
- FW_ASSERT(fwFrame != NULL);
-
- // ----- if this frame was the "Open in Window" frame then ....
- if (fwFrame == fPartWindowFrame)
- {
- fPartWindowFrame = NULL;
- PrivInvalidateIconizedFrames(ev);
- }
-
- // ----- Notify the presentation that a frame is going away
- fwFrame->GetPresentation(ev)->PrivFrameRemoved(ev, fwFrame, toStorage);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::PrivInvalidateIconizedFrames
- //----------------------------------------------------------------------------------------
-
- void FW_CPart::PrivInvalidateIconizedFrames(Environment *ev)
- {
- FW_CPartFrameIterator ite(ev, this);
- for (FW_CFrame* aFrame = ite.First(ev); ite.IsNotComplete(ev); aFrame = ite.Next(ev))
- {
- ODTypeToken viewType = aFrame->GetViewType(ev);
- if (viewType == FW_CPart::fgViewAsLargeIconToken || viewType == FW_CPart::fgViewAsSmallIconToken)
- aFrame->GetODFrame(ev)->Invalidate(ev, NULL, NULL);
- }
- }
-